13 #include "PlusConfigure.h" 14 #ifdef PLUS_RENDERING_ENABLED 19 #include "vtkIGSIOSequenceIO.h" 20 #include "vtkIGSIOTrackedFrameList.h" 23 #include <vtksys/CommandLineArguments.hxx> 24 #include <vtksys/SystemTools.hxx> 28 int main(
int argc,
char** argv)
30 int numberOfErrors(0);
32 bool printHelp(
false);
33 std::string inputMetafile;
34 std::string inputBaselineReportFilePath(
"");
35 int inputAveragedItemsForFiltering(20);
36 double inputMaxTimestampDifference(0.080);
37 double inputMinStdevReductionFactor(3.0);
38 std::string inputTransformName;
40 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
42 vtksys::CommandLineArguments args;
43 args.Initialize(argc, argv);
45 args.AddArgument(
"--transform", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputTransformName,
"Transform name used for generating timestamp filtering");
46 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
47 args.AddArgument(
"--source-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputMetafile,
"Input sequence metafile.");
48 args.AddArgument(
"--averaged-items-for-filtering", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputAveragedItemsForFiltering,
"Number of averaged items used for filtering (Default: 20).");
49 args.AddArgument(
"--max-timestamp-difference", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputMaxTimestampDifference,
"The maximum difference between the filtered and nonfiltered timestamps for each frame (Default: 0.08s).");
50 args.AddArgument(
"--min-stdev-reduction-factor", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputMinStdevReductionFactor,
"Minimum factor that the filtering should reduces the standard deviation of the frame periods on filtered data (Default: 3.0 ).");
51 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
55 std::cerr <<
"Problem parsing arguments" << std::endl;
56 std::cout <<
"Help: " << args.GetHelp() << std::endl;
62 std::cout << args.GetHelp() << std::endl;
68 if (inputMetafile.empty())
70 std::cerr <<
"input-metafile argument required!" << std::endl;
71 std::cout <<
"Help: " << args.GetHelp() << std::endl;
75 igsioTransformName transformName;
76 if (transformName.SetTransformName(inputTransformName.c_str()) !=
PLUS_SUCCESS)
78 LOG_ERROR(
"Invalid transform name: " << inputTransformName);
83 LOG_INFO(
"Reading meta file...");
84 vtkSmartPointer<vtkIGSIOTrackedFrameList> trackerFrameList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
85 if (vtkIGSIOSequenceIO::Read(inputMetafile, trackerFrameList) !=
PLUS_SUCCESS)
87 LOG_ERROR(
"Failed to read sequence metafile from file: " << inputMetafile);
90 LOG_INFO(
"Copy buffer to tracker buffer...");
91 vtkSmartPointer<vtkPlusBuffer> trackerBuffer = vtkSmartPointer<vtkPlusBuffer>::New();
92 trackerBuffer->SetTimeStampReporting(
true);
96 LOG_ERROR(
"CopyDefaultTrackerDataToBuffer failed");
104 double maxTimestampDifference(0);
105 for (
BufferItemUidType item = trackerBuffer->GetOldestItemUidInBuffer(); item <= trackerBuffer->GetLatestItemUidInBuffer(); ++item)
108 if (trackerBuffer->GetStreamBufferItem(item, &bufferItem) !=
ITEM_OK)
110 LOG_WARNING(
"Failed to get buffer item with UID: " << item);
116 if (timestampDifference > maxTimestampDifference)
118 maxTimestampDifference = timestampDifference;
120 if (timestampDifference > inputMaxTimestampDifference)
122 LOG_ERROR(
"Difference between the filtered and nonfiltered timestamps are higher than the threshold (UID: " << item
125 <<
", timestamp diference: " << timestampDifference <<
", threshold: " << inputMaxTimestampDifference <<
")");
130 LOG_INFO(
"Maximum filtered and unfiltered timestamp difference: " << maxTimestampDifference * 1000 <<
"ms");
133 vnl_vector<double>unfilteredFramePeriods(trackerBuffer->GetNumberOfItems() - 1);
134 vnl_vector<double>filteredFramePeriods(trackerBuffer->GetNumberOfItems() - 1);
136 for (
BufferItemUidType item = trackerBuffer->GetOldestItemUidInBuffer(); item < trackerBuffer->GetLatestItemUidInBuffer(); ++item)
139 if (trackerBuffer->GetStreamBufferItem(item, &bufferItem_1) !=
ITEM_OK)
141 LOG_WARNING(
"Failed to get buffer item with UID: " << item);
147 if (trackerBuffer->GetStreamBufferItem(item + 1, &bufferItem_2) !=
ITEM_OK)
149 LOG_WARNING(
"Failed to get buffer item with UID: " << item + 1);
160 double unfilteredFramePeriodsMean = unfilteredFramePeriods.mean();
161 double filteredFramePeriodsMean = filteredFramePeriods.mean();
164 vnl_vector<double> diffFromMeanUnfilteredFramePeriods = unfilteredFramePeriods - unfilteredFramePeriodsMean;
165 double unfilteredFramePeriodsStd = sqrt(diffFromMeanUnfilteredFramePeriods.squared_magnitude() / diffFromMeanUnfilteredFramePeriods.size());
167 LOG_INFO(
"Unfiltered frame periods mean: " << std::fixed << unfilteredFramePeriodsMean * 1000 <<
"ms stdev: " << unfilteredFramePeriodsStd * 1000 <<
"ms");
169 vnl_vector<double> diffFromMeanFilteredFramePeriods = filteredFramePeriods - filteredFramePeriodsMean;
170 double filteredFramePeriodsStd = sqrt(diffFromMeanFilteredFramePeriods.squared_magnitude() / diffFromMeanFilteredFramePeriods.size());
172 LOG_INFO(
"Filtered frame periods mean: " << std::fixed << filteredFramePeriodsMean * 1000 <<
"ms stdev: " << filteredFramePeriodsStd * 1000 <<
"ms");
174 LOG_INFO(
"Filtered data frame period reduction factor: " << std::fixed << unfilteredFramePeriodsStd / filteredFramePeriodsStd);
176 if (unfilteredFramePeriodsStd / filteredFramePeriodsStd < inputMinStdevReductionFactor)
178 LOG_ERROR(
"Filtered data frame period reduction factor is smaller than the threshold (factor: " << std::fixed << unfilteredFramePeriodsStd / filteredFramePeriodsStd <<
", threshold: " << inputMinStdevReductionFactor <<
")");
183 vtkSmartPointer<vtkTable> timestampReportTable = vtkSmartPointer<vtkTable>::New();
184 if (trackerBuffer->GetTimeStampReportTable(timestampReportTable) !=
PLUS_SUCCESS)
186 LOG_ERROR(
"Failed to get time stamp report table!");
190 std::string reportFile = vtksys::SystemTools::GetCurrentWorkingDirectory() + std::string(
"/TimestampReport.txt");
192 #ifdef PLUS_RENDERING_ENABLED 195 LOG_ERROR(
"Failed to write table to file");
202 timestampReportTable->Dump();
205 if (numberOfErrors != 0)
207 LOG_INFO(
"Test failed!");
211 LOG_INFO(
"Test completed successfully!");
static PlusStatus WriteTableToFile(vtkTable &table, const std::string &filename)
double GetFilteredTimestamp(double localTimeOffsetSec)
int main(int argc, char **argv)
double GetUnfilteredTimestamp(double localTimeOffsetSec)
static vtkIGSIOLogger * Instance()
unsigned long long BufferItemUidType