12 #include "PlusConfigure.h" 13 #include "igsioTrackedFrame.h" 15 #include "vtkMatrix4x4.h" 18 #include "vtkSmartPointer.h" 19 #include "vtkIGSIOTransformRepository.h" 20 #include "vtkXMLUtilities.h" 21 #include "vtksys/CommandLineArguments.hxx" 25 PlusStatus CompareTransform(igsioTransformName& transformName, vtkIGSIOTransformRepository* transformRepository,
double xExpected,
double yExpected,
double zExpected)
27 vtkSmartPointer<vtkMatrix4x4> transformMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
28 ToolStatus toolStatus(TOOL_INVALID);
29 if (transformRepository->GetTransform(transformName, transformMatrix, &toolStatus) !=
PLUS_SUCCESS || toolStatus != TOOL_OK)
31 std::string transformNameStr;
32 transformName.GetTransformName(transformNameStr);
33 LOG_ERROR(
"Unable to get transform " << transformNameStr);
37 std::string transformNameStr;
38 transformName.GetTransformName(transformNameStr);
39 double actualValue = transformMatrix ->GetElement(0, 3);
42 LOG_ERROR(
"Transform " << transformNameStr <<
" x translation does not match (actual=" << actualValue <<
", expected=" << xExpected <<
")");
45 actualValue = transformMatrix ->GetElement(1, 3);
48 LOG_ERROR(
"Transform " << transformNameStr <<
" y translation does not match (actual=" << actualValue <<
", expected=" << yExpected <<
")");
51 actualValue = transformMatrix ->GetElement(2, 3);
54 LOG_ERROR(
"Transform " << transformNameStr <<
" z translation does not match (actual=" << actualValue <<
", expected=" << zExpected <<
")");
60 int main(
int argc,
char** argv)
64 std::string inputConfigFileName;
65 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
67 vtksys::CommandLineArguments args;
68 args.Initialize(argc, argv);
70 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Name of the input configuration file.");
71 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug 5=trace)");
75 std::cerr <<
"Problem parsing arguments." << std::endl;
76 std::cout <<
"Help: " << args.GetHelp() << std::endl;
83 vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
86 LOG_ERROR(
"Unable to read configuration from file " << inputConfigFileName.c_str());
92 vtkSmartPointer<vtkPlusDataCollector> dataCollector = vtkSmartPointer<vtkPlusDataCollector>::New();
94 if (dataCollector->ReadConfiguration(configRootElement) !=
PLUS_SUCCESS)
96 LOG_ERROR(
"Reading configuration file failed " << inputConfigFileName);
100 LOG_DEBUG(
"Initializing data collector... ");
101 dataCollector->Connect();
102 dataCollector->Start();
104 if (!dataCollector->GetConnected())
106 LOG_ERROR(
"Unable to start data collection!");
111 igsioTrackedFrame trackedFrame;
113 igsioTransformName referenceToTrackerTransformName(
"Reference",
"Tracker");
114 igsioTransformName probeToTrackerTransformName(
"Probe",
"Tracker");
115 igsioTransformName stylusToTrackerTransformName(
"Stylus",
"Tracker");
117 vtkSmartPointer<vtkIGSIOTransformRepository> transformRepository = vtkSmartPointer<vtkIGSIOTransformRepository>::New();
121 vtkIGSIOAccurateTimer::Delay(5.0);
130 if (dataCollector->GetDevice(aDevice,
"TrackedVideoDevice") !=
PLUS_SUCCESS)
132 LOG_ERROR(
"Unable to locate device \'TrackedVideoDevice\'");
137 LOG_ERROR(
"Unable to locate channel \'TrackedVideoStream\'");
143 double timestampOfFirstFrameInFile = 2572.905343;
144 double timeOffset = timestampOfFirstFrameInFile - recordingStartTime;
148 transformRepository->SetTransforms(trackedFrame);
152 LOG_ERROR(
"Test failed on frame 1");
157 LOG_ERROR(
"Test failed on frame 1");
161 vtkSmartPointer<vtkMatrix4x4> stylusToTrackerTransformMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
162 ToolStatus toolStatus(TOOL_INVALID);
163 if (transformRepository->GetTransform(stylusToTrackerTransformName, stylusToTrackerTransformMatrix, &toolStatus) !=
PLUS_SUCCESS)
165 std::string transformNameStr;
166 stylusToTrackerTransformName.GetTransformName(transformNameStr);
167 LOG_ERROR(
"Test failed on frame 1: unable to get transform " << transformNameStr);
169 if (toolStatus != TOOL_OK)
171 std::string transformNameStr;
172 stylusToTrackerTransformName.GetTransformName(transformNameStr);
173 LOG_ERROR(
"Test failed on frame 1: Invalid transform received, while valid transform was expected for " << transformNameStr);
178 transformRepository->SetTransforms(trackedFrame);
182 LOG_ERROR(
"Test failed on frame 13");
187 LOG_ERROR(
"Test failed on frame 13");
190 toolStatus = TOOL_INVALID;
191 if (transformRepository->GetTransform(stylusToTrackerTransformName, stylusToTrackerTransformMatrix, &toolStatus) !=
PLUS_SUCCESS)
193 std::string transformNameStr;
194 stylusToTrackerTransformName.GetTransformName(transformNameStr);
195 LOG_ERROR(
"Test failed on frame 13: unable to get transform " << transformNameStr);
197 if (toolStatus != TOOL_OK)
199 std::string transformNameStr;
200 stylusToTrackerTransformName.GetTransformName(transformNameStr);
201 LOG_ERROR(
"Test failed on frame 13: Invalid transform received, while valid transform was expected for " << transformNameStr);
204 dataCollector->Stop();
205 dataCollector->Disconnect();
static const int COMPARE_TRANSFORM_TOLERANCE
Abstract interface for tracker and video devices.
virtual PlusStatus GetTrackedFrame(double timestamp, igsioTrackedFrame &trackedFrame, bool enableImageData=true)
static vtkPlusConfig * GetInstance()
PlusStatus GetOutputChannelByName(vtkPlusChannel *&aChannel, const char *aChannelId)
int main(int argc, char **argv)
virtual double GetStartTime()
PlusStatus CompareTransform(igsioTransformName &transformName, vtkIGSIOTransformRepository *transformRepository, double xExpected, double yExpected, double zExpected)
static vtkIGSIOLogger * Instance()
Contains an optional timestamped circular buffer containing the video images and a number of timestam...
PlusStatus GetVideoSource(vtkPlusDataSource *&aVideoSource) const
void SetDeviceSetConfigurationData(vtkXMLDataElement *deviceSetConfigurationData)
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)
Interface to a 3D positioning tool, video source, or generalized data stream.