13 #include "PlusConfigure.h" 15 #include "igsioTrackedFrame.h" 19 #include "vtkMatrix4x4.h" 22 #include "vtkSmartPointer.h" 23 #include "vtkIGSIOTrackedFrameList.h" 24 #include "vtkTransform.h" 25 #include "vtkIGSIOTransformRepository.h" 26 #include "vtkXMLDataElement.h" 27 #include "vtkXMLUtilities.h" 28 #include "vtksys/CommandLineArguments.hxx" 29 #include "vtksys/SystemTools.hxx" 38 int main(
int argc,
char* argv[])
40 std::string inputConfigFileName;
41 std::string inputBaselineFileName;
43 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
45 vtksys::CommandLineArguments cmdargs;
46 cmdargs.Initialize(argc, argv);
48 cmdargs.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Configuration file name");
49 cmdargs.AddArgument(
"--baseline-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputBaselineFileName,
"Name of file storing baseline calibration results");
50 cmdargs.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
54 std::cerr <<
"Problem parsing arguments" << std::endl;
55 std::cout <<
"Help: " << cmdargs.GetHelp() << std::endl;
61 LOG_INFO(
"Initialize");
64 vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
67 LOG_ERROR(
"Unable to read configuration from file " << inputConfigFileName.c_str());
74 vtkSmartPointer<vtkPlusDataCollector> dataCollector = vtkSmartPointer<vtkPlusDataCollector>::New();
75 if (dataCollector->ReadConfiguration(configRootElement) !=
PLUS_SUCCESS)
77 LOG_ERROR(
"Unable to parse configuration from file " << inputConfigFileName.c_str());
83 LOG_ERROR(
"Data collector was unable to connect to devices!");
88 LOG_ERROR(
"Unable to start data collection!");
93 if (dataCollector->GetDevice(aDevice, std::string(
"TrackerDevice")) !=
PLUS_SUCCESS)
95 LOG_ERROR(
"Unable to locate device by ID: \'TrackerDevice\'");
100 LOG_ERROR(
"Unable to locate channel by ID: \'TrackerStream\'");
105 LOG_ERROR(
"Channel \'" << aChannel->
GetChannelId() <<
"\' is not tracking!");
110 LOG_ERROR(
"Data collector is not tracking!");
115 vtkSmartPointer<vtkIGSIOTransformRepository> transformRepository = vtkSmartPointer<vtkIGSIOTransformRepository>::New();
116 if (transformRepository->ReadConfiguration(configRootElement) !=
PLUS_SUCCESS)
118 LOG_ERROR(
"Failed to read CoordinateDefinitions!");
123 vtkSmartPointer<vtkPlusPhantomLandmarkRegistrationAlgo> phantomRegistration = vtkSmartPointer<vtkPlusPhantomLandmarkRegistrationAlgo>::New();
124 if (phantomRegistration == NULL)
126 LOG_ERROR(
"Unable to instantiate phantom registration algorithm class!");
129 if (phantomRegistration->ReadConfiguration(configRootElement) !=
PLUS_SUCCESS)
131 LOG_ERROR(
"Unable to read phantom definition!");
135 int numberOfLandmarks = phantomRegistration->GetDefinedLandmarks_Phantom()->GetNumberOfPoints();
136 if (numberOfLandmarks != 8)
138 LOG_ERROR(
"Number of defined landmarks should be 8 instead of " << numberOfLandmarks <<
"!");
144 if (fakeTracker == NULL)
146 LOG_ERROR(
"Invalid tracker object!");
151 igsioTrackedFrame trackedFrame;
152 igsioTransformName stylusTipToReferenceTransformName(phantomRegistration->GetStylusTipCoordinateFrame(), phantomRegistration->GetReferenceCoordinateFrame());
154 for (
int landmarkCounter = 0; landmarkCounter < numberOfLandmarks; ++landmarkCounter)
159 vtkSmartPointer<vtkMatrix4x4> stylusTipToReferenceMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
162 transformRepository->SetTransforms(trackedFrame);
164 ToolStatus status(TOOL_INVALID);
165 if (transformRepository->GetTransform(stylusTipToReferenceTransformName, stylusTipToReferenceMatrix, &status) !=
PLUS_SUCCESS || status != TOOL_OK)
167 LOG_ERROR(
"No valid transform found between stylus tip to reference!");
172 double stylusTipPosition[3] = {stylusTipToReferenceMatrix->GetElement(0, 3), stylusTipToReferenceMatrix->GetElement(1, 3), stylusTipToReferenceMatrix->GetElement(2, 3) };
175 phantomRegistration->GetRecordedLandmarks_Reference()->InsertPoint(landmarkCounter, stylusTipPosition);
176 phantomRegistration->GetRecordedLandmarks_Reference()->Modified();
178 vtkPlusLogger::PrintProgressbar((100.0 * landmarkCounter) / numberOfLandmarks);
181 if (phantomRegistration->LandmarkRegister(transformRepository) !=
PLUS_SUCCESS)
183 LOG_ERROR(
"Phantom registration failed!");
187 vtkPlusLogger::PrintProgressbar(100);
189 LOG_INFO(
"Registration error = " << phantomRegistration->GetRegistrationErrorMm());
192 if (transformRepository->WriteConfiguration(configRootElement) !=
PLUS_SUCCESS)
194 LOG_ERROR(
"Failed to write phantom registration result to configuration element!");
198 std::string registrationResultFileName =
"PhantomRegistrationTest.xml";
199 vtksys::SystemTools::RemoveFile(registrationResultFileName.c_str());
200 igsioCommon::XML::PrintXML(registrationResultFileName.c_str(), configRootElement);
204 LOG_ERROR(
"Comparison of calibration data to baseline failed");
205 std::cout <<
"Exit failure!!!" << std::endl;
209 std::cout <<
"Exit success!!!" << std::endl;
218 if (baselineFileName == NULL)
220 LOG_ERROR(
"Unable to read the baseline configuration file - filename is NULL");
224 if (currentResultFileName == NULL)
226 LOG_ERROR(
"Unable to read the current configuration file - filename is NULL");
230 igsioTransformName tnPhantomToPhantomReference(phantomCoordinateFrame, referenceCoordinateFrame);
233 vtkSmartPointer<vtkXMLDataElement> currentRootElem = vtkSmartPointer<vtkXMLDataElement>::Take(
234 vtkXMLUtilities::ReadElementFromFile(currentResultFileName));
235 if (currentRootElem == NULL)
237 LOG_ERROR(
"Unable to read the current configuration file: " << currentResultFileName);
241 vtkSmartPointer<vtkIGSIOTransformRepository> currentTransformRepository = vtkSmartPointer<vtkIGSIOTransformRepository>::New();
242 if (currentTransformRepository->ReadConfiguration(currentRootElem) !=
PLUS_SUCCESS)
244 LOG_ERROR(
"Unable to read the current CoordinateDefinitions from configuration file: " << currentResultFileName);
248 vtkSmartPointer<vtkMatrix4x4> currentMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
249 if (currentTransformRepository->GetTransform(tnPhantomToPhantomReference, currentMatrix) !=
PLUS_SUCCESS)
251 std::string strTransformName;
252 tnPhantomToPhantomReference.GetTransformName(strTransformName);
253 LOG_ERROR(
"Unable to get '" << strTransformName <<
"' coordinate definition from configuration file: " << currentResultFileName);
258 vtkSmartPointer<vtkXMLDataElement> baselineRootElem = vtkSmartPointer<vtkXMLDataElement>::Take(
259 vtkXMLUtilities::ReadElementFromFile(baselineFileName));
260 if (baselineFileName == NULL)
262 LOG_ERROR(
"Unable to read the baseline configuration file: " << baselineFileName);
266 vtkSmartPointer<vtkIGSIOTransformRepository> baselineTransformRepository = vtkSmartPointer<vtkIGSIOTransformRepository>::New();
267 if (baselineTransformRepository->ReadConfiguration(baselineRootElem) !=
PLUS_SUCCESS)
269 LOG_ERROR(
"Unable to read the baseline CoordinateDefinitions from configuration file: " << baselineFileName);
273 vtkSmartPointer<vtkMatrix4x4> baselineMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
274 if (baselineTransformRepository->GetTransform(tnPhantomToPhantomReference, baselineMatrix) !=
PLUS_SUCCESS)
276 std::string strTransformName;
277 tnPhantomToPhantomReference.GetTransformName(strTransformName);
278 LOG_ERROR(
"Unable to get '" << strTransformName <<
"' coordinate definition from configuration file: " << baselineFileName);
283 double posDiff = igsioMath::GetPositionDifference(currentMatrix, baselineMatrix);
284 double orientDiff = igsioMath::GetOrientationDifference(currentMatrix, baselineMatrix);
288 LOG_ERROR(
"Transform mismatch (position difference: " << posDiff <<
" orientation difference: " << orientDiff);
Abstract interface for tracker and video devices.
PlusStatus CompareRegistrationResultsWithBaseline(const char *baselineFileName, const char *currentResultFileName, const char *phantomCoordinateFrame, const char *referenceCoordinateFrame)
const double ERROR_THRESHOLD
virtual PlusStatus GetTrackedFrame(double timestamp, igsioTrackedFrame &trackedFrame, bool enableImageData=true)
virtual void SetTransformRepository(vtkIGSIOTransformRepository *)
bool GetTrackingDataAvailable()
Represents a fake tracking system as a simulator.
static vtkPlusConfig * GetInstance()
virtual double GetAcquisitionRate() const
PlusStatus GetOutputChannelByName(vtkPlusChannel *&aChannel, const char *aChannelId)
virtual char * GetChannelId()
static vtkIGSIOLogger * Instance()
Contains an optional timestamped circular buffer containing the video images and a number of timestam...
int main(int argc, char *argv[])
virtual void SetCounter(int)
void SetDeviceSetConfigurationData(vtkXMLDataElement *deviceSetConfigurationData)
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)