This example shows how to use the PST SDK to adjust the PST Tracker reference system. The reference system defines the Cartesian coordinate system in which tracking results are reported. The example shows how to set the reference system by supplying a 4x4 homogeneous transformation matrix. It also shows how to check if the reference system was set successfully.
When compiling and running this example, please make sure that the required dependencies can be found by the executable (e.g. by copying the Redist
directory into the build directory. When the PST SDK has been installed through the PST Software Suite installer the Redist folder can be found in the Development folder.).
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
static void Exithandler(int sig);
#ifdef WIN32
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
Exithandler(CEvent);
return TRUE;
}
#endif
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#include <signal.h>
static inline void PrintMatrix(float mat[16])
{
for (int y = 0; y < 4; ++y)
{
for (int x = 0; x < 4; ++x)
{
printf("%f \t", mat[x + y * 4]);
}
printf("\n");
}
}
static sig_atomic_t running = 1;
static const uint32_t numberOfSamplesToGrab = 1000;
{
static uint32_t samplesGrabbed = 0;
if (samplesGrabbed++ >= numberOfSamplesToGrab)
running = 0;
}
static void Exithandler(int sig)
{
running = 0;
}
void PrintLastErrorMessage()
{
char* last_error_message = NULL;
{
last_error_message = "Failed to allocate memory error.";
}
printf("last error message: %s \n", last_error_message);
}
{
{
PrintLastErrorMessage();
exit(status);
}
}
bool IsEqual(float get_reference[16], float set_reference[16])
{
float eps = 1e-4f;
bool references_are_equal = true;
for (size_t i = 0; i < 16; ++i)
{
references_are_equal = references_are_equal && (fabs(get_reference[i] - set_reference[i]) < eps);
}
return references_are_equal;
}
int main(int argc, char *argv[])
{
#ifdef WIN32
SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE);
#else
signal(SIGTERM, Exithandler);
signal(SIGKILL, Exithandler);
signal(SIGQUIT, Exithandler);
signal(SIGINT, Exithandler);
#endif
#ifdef WIN32
#else
CheckErrorCode(
pst_tracker_init4(&ctracker,
"",
"config.cfg",
"models.db", argv[1]));
#endif
char* version_string;
printf("Running PST Server version %s \n", version_string);
double fps;
printf("Frame rate set to %f\n\n", fps);
printf("*******************\n\n");
printf("Current reference system transformation matrix:\n");
float reference[16];
PrintMatrix(reference);
printf("\n\n*******************\n\n");
float set_reference[16] = { -1.0f, 0.0f, 0.0f, 0.1f,
0.0f, 0.0f, 1.0f, -0.5f,
0.0f, 1.0f, 0.0f, 0.5f,
0.0f, 0.0f, 0.0f, 1.0f };
printf("New reference system transformation matrix:\n");
float get_reference[16];
PrintMatrix(get_reference);
if (!IsEqual(get_reference, set_reference))
{
printf("Reference not set correctly!\n");
}
else
{
printf("Reference set correctly!\n");
}
printf("\n\n*******************\n\n");
float non_orthonormal_set_reference[16] = { -1.0f, 1.0f, 0.0f, 0.1f,
0.0f, 0.0f, -1.0f, -0.5f,
0.0f, -1.0f, 0.0f, 0.5f,
0.0f, 0.0f, 0.0f, 1.0f };
{
printf("Reference input correctly ignored!\n");
PrintLastErrorMessage();
}
else
{
printf("Reference input incorrectly applied!\n");
}
printf("New reference system after applying non-orthonormal transformation:\n");
float non_orthonormal_get_reference[16];
PrintMatrix(non_orthonormal_get_reference);
printf("\n\n*******************\n\n");
float relative_set_reference[16] = { 0.0f, -1.0f, 0.0f, 0.5f,
1.0f, 0.0f, 0.0f, 0.4f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
printf("New reference system after applying relative transformation:\n");
float relative_get_reference[16];
PrintMatrix(relative_get_reference);
printf("\n\n*******************\n\n");
printf("Reset default reference system:\n");
float get_default_reference[16];
PrintMatrix(get_default_reference);
while (running == 1)
{
#ifdef WIN32
Sleep(100);
#else
usleep(100000);
#endif
}
printf("Press enter to continue...\n");
getchar();
return 0;
}