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 the PST Client with PSTech::pstsdk::Tracker::EnableSharedMemory(), or use the stand-alone PST Server to configure the tracking targets.
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.). On Windows, the Visual Studio project files are configured to use a relative path to the Redist directory as the working directory. If the examples have been copied, please ensure the working directory is still valid.
#ifdef WIN32
#include <windows.h>
#else
#include <csignal>
#endif
static void Exithandler(int sig);
#ifdef WIN32
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
Exithandler(CEvent);
return TRUE;
}
#endif
#include <iostream>
#include <thread>
#include <chrono>
#include <atomic>
static std::atomic<bool> running(true);
static const uint32_t numberOfSamplesToGrab = 100;
{
{
static uint32_t samplesGrabbed = 0;
if (samplesGrabbed++ >= numberOfSamplesToGrab)
running = false;
std::cout <<
"Detected " << pose.
name <<
"\n";
}
public:
virtual ~MyListener() override
{
}
} listener;
static void Exithandler(int sig)
{
running = false;
}
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
try
{
#ifdef WIN32
#else
#endif
std::cout <<
"Running PST Server version " << pst.
GetVersionInfo() <<
"\n";
std::cout << "Put the Reference card in front of the PST in order to see tracking results.\n\n";
std::cout <<
"System check: " << (int)pst.
Systemcheck() <<
"\n";
std::cout <<
"Found " << targets.
size() <<
" tracking targets:\n";
std::cout << t.name << "\t" << t.status << "\n";
std::cout << "\n";
std::cout << "3D marker positions making up the Reference target:\n";
for (const auto& marker : markers)
std::cout << "x: " << marker[0] << "\t" << "y: " << marker[1] << "\t" << "z: " << marker[2] << "\n";
std::cout << "\n";
while (running)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
{
}
std::cout << "Press enter to continue...\n";
std::cin.get();
return 0;
}
virtual const char * full_description() const
Definition TrackerExceptions.h:54
Abstract listener class for receiving tracking information and tracking mode updates.
Definition pstsdk_cpp.h:38
virtual void OnTrackerData(const TrackerData &data)
Callback function receiving tracking information from the tracker.
Definition pstsdk_cpp.h:49
Main PST SDK class implementing tracker communication.
Definition pstsdk_cpp.h:101
void Start()
Start tracking.
Utils::PstString GetVersionInfo() const
Get version information of the SDK.
StatusMessage Systemcheck() const
Check if the tracker is running correctly.
MarkerList GetTargetMarkers(const Utils::PstString &name) const
Get 3D marker positions of stored tracking Target.
static void Shutdown()
Shutdown the tracking system, stopping tracking.
static void AddTrackerListener(Listener *listener)
Add a listener for receiving tracker data and tracking mode updates.
static void RemoveTrackerListener(Listener *listener)
Remove a listener for receiving tracker data and tracking mode updates.
void SetTargetStatus(const Utils::PstString &name, bool active)
Set status of a single tracking Target.
TargetStatuses GetTargetList() const
Get TargetStatuses object containing all tracking targets and their status.
Utils::PstVector< TargetStatus > TargetStatuses
Vector of TargetStatus objects.
Definition PstTypes.h:81
Utils::PstVector< Utils::PstArray< float, 3 > > MarkerList
Vector of 3D marker positions of a tracking Target.
Definition PstTypes.h:158
Utils::PstString name
Definition PstTypes.h:43
Estimated tracking target pose and detected 3D markers.
Definition PstTypes.h:136
Tracking target status.
Definition PstTypes.h:70
Tracking information retrieved from tracker.
Definition PstTypes.h:173
TargetPoses targetlist
Definition PstTypes.h:176