12 #include "PlusConfigure.h" 13 #include "igsioTrackedFrame.h" 16 #include "vtkImageData.h" 17 #include "vtkImageHistogramStatistics.h" 18 #include "vtkMatrix4x4.h" 23 #include "vtkIGSIOTrackedFrameList.h" 25 #include "vtkXMLUtilities.h" 26 #include "vtksys/CommandLineArguments.hxx" 30 int main(
int argc,
char **argv)
32 std::string inputConfigFileName;
33 double minExpected(-1.0), maxExpected(-1.0), meanExpected(-1.0), stdDevExpected(-1.0), medianExpected(-1.0);
34 double xDimension(-1.0), yDimension(-1.0), zDimension(-1.0);
35 int verboseLevel=vtkPlusLogger::LOG_LEVEL_UNDEFINED;
37 vtksys::CommandLineArguments args;
38 args.Initialize(argc, argv);
40 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Name of the input configuration file.");
41 args.AddArgument(
"--minimum", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &minExpected,
"Minimum pixel value expected.");
42 args.AddArgument(
"--maximum", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &maxExpected,
"Maximum pixel value expected.");
43 args.AddArgument(
"--mean", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &meanExpected,
"Mean pixel value expected.");
44 args.AddArgument(
"--standard-deviation", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &stdDevExpected,
"Standard deviation from the mean expected.");
45 args.AddArgument(
"--median", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &medianExpected,
"Median pixel value expected.");
46 args.AddArgument(
"--xDimension", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &xDimension,
"Expected size of the data in the X dimension.");
47 args.AddArgument(
"--yDimension", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &yDimension,
"Expected size of the data in the Y dimension.");
48 args.AddArgument(
"--zDimension", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &zDimension,
"Expected size of the data in the Z dimension.");
49 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
53 std::cerr <<
"Problem parsing arguments" << std::endl;
54 std::cout <<
"Help: " << args.GetHelp() << std::endl;
60 if (inputConfigFileName.empty())
62 LOG_ERROR(
"input-config-file-name is required");
66 if( minExpected == -1.0 )
68 LOG_ERROR(
"minimum is required");
71 if( maxExpected == -1.0 )
73 LOG_ERROR(
"maximum is required");
76 if( meanExpected == -1.0 )
78 LOG_ERROR(
"mean is required");
81 if( stdDevExpected == -1.0 )
83 LOG_ERROR(
"standard-deviation is required");
86 if( medianExpected == -1.0 )
88 LOG_ERROR(
"median is required");
91 if( xDimension == -1.0 )
93 LOG_ERROR(
"xDimension is required");
96 if( yDimension == -1.0 )
98 LOG_ERROR(
"yDimension is required");
101 if( zDimension == -1.0 )
103 LOG_ERROR(
"zDimension is required");
109 vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
112 LOG_ERROR(
"Unable to read configuration from file " << inputConfigFileName.c_str());
118 vtkSmartPointer<vtkPlusDataCollector> dataCollector = vtkSmartPointer<vtkPlusDataCollector>::New();
120 if( dataCollector->ReadConfiguration( configRootElement ) !=
PLUS_SUCCESS )
122 LOG_ERROR(
"Configuration incorrect for vtkPlusDataCollectorTest1.");
123 exit( EXIT_FAILURE );
129 if( dataCollector->GetDevice(videoDevice,
"VideoDevice") !=
PLUS_SUCCESS )
131 LOG_ERROR(
"Unable to locate the device with Id=\"VideoDevice\". Check config file.");
135 if ( videoSource == NULL )
137 LOG_ERROR(
"Unable to cast video source to vtkPlusSavedDataSource." );
138 exit( EXIT_FAILURE );
141 if( dataCollector->GetDevice(trackerDevice,
"TrackerDevice") !=
PLUS_SUCCESS )
143 LOG_ERROR(
"Unable to locate the device with Id=\"TrackerDevice\". Check config file.");
147 if ( tracker == NULL )
149 LOG_ERROR(
"Unable to cast tracker to vtkPlusSavedDataSource" );
150 exit( EXIT_FAILURE );
153 if( dataCollector->GetDevice(trackedVideoDevice,
"TrackedVideoDevice") !=
PLUS_SUCCESS )
155 LOG_ERROR(
"Unable to locate the device with Id=\"TrackedVideoDevice\". Check config file.");
161 LOG_ERROR(
"Unable to cast tracked video device to vtkPlusVirtualMixer" );
162 exit( EXIT_FAILURE );
167 LOG_ERROR(
"Failed to connect to devices!" );
168 exit( EXIT_FAILURE );
173 LOG_ERROR(
"Failed to start data collection!" );
174 exit( EXIT_FAILURE );
184 vtkSmartPointer<vtkIGSIOTrackedFrameList> frameList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
189 LOG_ERROR(
"Unable to retrieve frames from virtual mixer.");
190 exit( EXIT_FAILURE );
193 vtkImageData*
data = frameList->GetTrackedFrame(9)->GetImageData()->GetImage();
196 data->GetDimensions(dimensions);
198 if( xDimension != dimensions[0] || yDimension != dimensions[1] || zDimension != dimensions[2] )
200 LOG_ERROR(
"Dimensions don't match. Got [" << dimensions[0] <<
"," << dimensions[1] <<
"," << dimensions[2] <<
"]. Expected [" << xDimension <<
"," << yDimension <<
"," << zDimension <<
"]");
205 vtkSmartPointer<vtkImageHistogramStatistics> stats = vtkSmartPointer<vtkImageHistogramStatistics>::New();
206 stats->SetInputData(
data);
207 stats->GenerateHistogramImageOff();
210 double minVal = stats->GetMinimum();
211 double maxVal = stats->GetMaximum();
212 double meanVal = stats->GetMean();
213 double median = stats->GetMedian();
214 double stdDev = stats->GetStandardDeviation();
219 LOG_ERROR(
"Min values don't match. Got: " << minVal <<
". Expected: " << minExpected);
223 if( !itk::Math::FloatAlmostEqual<double>(maxVal, maxExpected, 4, 5.0) )
225 LOG_ERROR(
"Max values don't match. Got: " << maxVal <<
". Expected: " << maxExpected);
229 if( !itk::Math::FloatAlmostEqual<double>(meanVal, meanExpected, 4, 0.3) )
231 LOG_ERROR(
"Mean values don't match. Got: " << meanVal <<
". Expected: " << meanExpected);
237 LOG_ERROR(
"Median values don't match. Got: " << median <<
". Expected: " << medianExpected);
241 if( !itk::Math::FloatAlmostEqual<double>(stdDev, stdDevExpected, 4, 0.2) )
243 LOG_ERROR(
"Standard deviation values don't match. Got: " << stdDev <<
". Expected: " << stdDevExpected);
247 dataCollector->Disconnect();
254 LOG_INFO(
"vtk3DDataCollectorTest1 completed successfully!");
Abstract interface for tracker and video devices.
static vtkPlusConfig * GetInstance()
PlusStatus GetTrackedFrameList(double &aTimestampOfLastFrameAlreadyGot, vtkIGSIOTrackedFrameList *aTrackedFrameList, int aMaxNumberOfFramesToAdd)
vtkPlusChannel * GetChannel() const
static const double FLOAT_COMPARISON_TOLERANCE
int main(int argc, char **argv)
virtual PlusStatus GetOldestTimestamp(double &ts)
Class for providing VTK video input interface from sequence fileAttributes:
static vtkIGSIOLogger * Instance()
void SetDeviceSetConfigurationData(vtkXMLDataElement *deviceSetConfigurationData)
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)