PST SDK  5.0.1.0-acae3ae
trackingtarget.cpp

This example can be found in Development\trackingtarget\trackingtarget.cpp.

This example shows how to work with tracking targets using the PST SDK. Note that at this moment tracking targets can not be trained or imported using the PST SDK. In order to add new tracking targets, please use trhe PST Client together with the PSTech::pstsdk::Tracker::EnableSharedMemory() fuction, or use the stand-alone PST Server to configure the tracking targets.

#ifdef WIN32
#include <windows.h>
#endif
/*
* Define handler functions required to ensure a clean shutdown of the PST Tracker when the
* application is terminated.
*/
static void Exithandler(int sig);
#ifdef WIN32
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
Exithandler(CEvent);
return TRUE;
}
#endif
/* End of handler functions */
#include <memory>
#include <iostream>
#include "pst-sdk.h"
/* Control variable for main loop */
static bool running = true;
/* Number of data points to grab before application termination */
static const uint32_t numberOfSamplesToGrab = 100;
/*
* Implementation of the PSTech::pstsdk::Listener class to receive tracking data.
* The OnTrackerData() callback function receives the data as soon as it becomes
* available and prints the tracking target name to the command line.
*/
class MyListener : public PSTech::pstsdk::Listener
{
{
static uint32_t samplesGrabbed = 0;
if (samplesGrabbed++ >= numberOfSamplesToGrab)
running = false;
std::cout << "Detected " << pose.name << "\n";
}
} listener;
/*
* Create a shared pointer for storing the PSTech::pstsdk::Tracker object instance.
* By making use of a shared pointer, proper destruction of the PST Tracker connection
* is ensured in case the application is shut down.
*/
std::shared_ptr<PSTech::pstsdk::Tracker> pst;
/*
* Implement the exit handler to shut-down the PST Tracker connection on application terrmination.
*/
static void Exithandler(int sig)
{
pst->Shutdown();
}
int main(int argc, char *argv[])
{
// Register the exit handler with the application
#ifdef WIN32
SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE);
#else
signal(SIGTERM, Exithandler);
signal(SIGKILL, Exithandler);
signal(SIGQUIT, Exithandler);
signal(SIGINT, Exithandler);
#endif
// Implement error handling of PSTech::TrackerException exceptions to prevent
// improper PST Tracker shutdown on errors.
try
{
// Create an instance of the Tracker object using the default configuration path and file names.
pst = std::make_shared<PSTech::pstsdk::Tracker>();
// Print version number of the tracker server being used.
std::cout << "Running PST Server version " << pst->GetVersionInfo() << "\n";
// Register the listener object to the tracker server.
pst->AddTrackerListener(&listener);
// Start the tracker server.
pst->Start();
// Perform a system check to see if the tracker server is running OK and print the result.
std::cout << "System check: " << (int)pst->Systemcheck() << "\n";
// Retrieve the list of registered tracking targets and print their names and current status (active or not).
PSTech::pstsdk::TargetStatuses targets = pst->GetTargetList();
std::cout << "Found " << targets.size() << " tracking targets:\n";
for (PSTech::pstsdk::TargetStatus& t : targets)
std::cout << t.name << "\t" << t.status << "\n";
std::cout << "\n";
// Enable the Reference target. Note that this will cause a PSTech::TrackerException in case the Reference
// target has not been created. The Reference target can be created usign the PST Client.
pst->SetTargetStatus("Reference", true);
// Get the 3D marker positions making up the Reference device and display them.
// Note that this will cause a PSTech::TrackerException in case the Reference target has not been created.
PSTech::pstsdk::MarkerList markers = pst->GetTargetMarkers("Reference");
std::cout << "3D marker positions making up the Reference target:\n";
for (auto& marker : markers)
std::cout << "x: " << marker[0] << "\t" << "y: " << marker[1] << "\t" << "z: " << marker[2] << "\n";
std::cout << "\n";
// Main loop, wait for auto-termination.
while (running)
{
Sleep(100);
}
}
{
// Catch PSTech::TrackerException exceptions and print error messages.
std::cout << e.full_description() << "\n";
}
// Pause command line to see results.
std::cout << "Press enter to continue...\n";
std::cin.get();
// Make sure that the connection to the PST Tracker is shut down properly.
pst->Shutdown();
return 0;
}