8 #include "PlusConfigure.h" 11 #include "vtkImageData.h" 12 #include "vtkImageDifference.h" 13 #include "vtkImageExtractComponents.h" 15 #include "vtkSmartPointer.h" 16 #include "vtksys/CommandLineArguments.hxx" 17 #include "vtksys/SystemTools.hxx" 20 #include "igsioVideoFrame.h" 21 #include "igsioTrackedFrame.h" 22 #include "vtkIGSIOSequenceIO.h" 23 #include "vtkIGSIOTrackedFrameList.h" 29 int main (
int argc,
char* argv[] )
31 bool printHelp(
false );
32 std::string inputFileName;
33 std::string inputBaselineName;
34 int inputFrameNumber( -1 );
35 std::string outputFileName;
37 vtksys::CommandLineArguments args;
38 args.Initialize( argc, argv );
40 int verboseLevel = vtkPlusLogger::LOG_LEVEL_ERROR;
42 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help." );
43 args.AddArgument(
"--volume-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputFileName,
"The file name of the Sonix volume." );
44 args.AddArgument(
"--output-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &outputFileName,
"Sequence meta file name to save (save only if defined)" );
45 args.AddArgument(
"--frame-number", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputFrameNumber,
"The frame number to compare with baseline." );
46 args.AddArgument(
"--baseline", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputBaselineName,
"The file name of the baseline image." );
47 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (Default: 1; 1=error only, 2=warning, 3=info, 4=debug)" );
51 std::cerr <<
"Problem parsing arguments" << std::endl;
52 std::cout <<
"\n\nvtkPlusICCapturingSourceTest1 help:" << args.GetHelp() << std::endl;
60 std::cout <<
"\n\nvtkPlusICCapturingSourceTest1 help:" << args.GetHelp() << std::endl;
65 if ( inputFileName.empty() )
67 LOG_ERROR(
"The input-file-name parameter is required!" );
72 vtkSmartPointer<vtkIGSIOTrackedFrameList> sonixVolumeData = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
76 LOG_ERROR(
"Failed to generate tracked frame from sonix volume: " << inputFileName );
80 if ( !outputFileName.empty() )
83 LOG_INFO(
"Save tracked frames to " << path );
84 if( vtkIGSIOSequenceIO::Write( path, sonixVolumeData, sonixVolumeData->GetImageOrientation(), false ) !=
PLUS_SUCCESS )
86 LOG_ERROR(
"Failed to save sonix volume to " << path );
90 vtkSmartPointer<vtkImageDifference> imgDiff = vtkSmartPointer<vtkImageDifference>::New();
91 imgDiff->AllowShiftOff();
93 igsioVideoFrame baselineVideoFrame;
94 if ( igsioVideoFrame::ReadImageFromFile( baselineVideoFrame, inputBaselineName.c_str() ) !=
PLUS_SUCCESS )
96 LOG_ERROR(
"Failed to read baseline image from file: " << inputBaselineName );
100 vtkSmartPointer<vtkImageExtractComponents> imageExtractorBase = vtkSmartPointer<vtkImageExtractComponents>::New();
101 imageExtractorBase->SetInputData( baselineVideoFrame.GetImage() );
102 imageExtractorBase->SetComponents( 0, 0, 0 );
103 imageExtractorBase->Update();
104 vtkImageData* baselineRGB = imageExtractorBase->GetOutput();
106 if ( inputFrameNumber < 0 )
108 inputFrameNumber = 0;
110 unsigned int inputFrameNumberUint = static_cast<unsigned int>( inputFrameNumber );
111 if ( sonixVolumeData->GetNumberOfTrackedFrames() < inputFrameNumberUint )
113 LOG_ERROR(
"Unable to get tracked frame from list, frame number (" << inputFrameNumberUint
114 <<
") is larger than tracked frame list size (" << sonixVolumeData->GetNumberOfTrackedFrames() <<
")!" );
115 exit( EXIT_FAILURE );
118 igsioVideoFrame* videoFrame = sonixVolumeData->GetTrackedFrame( inputFrameNumberUint )->GetImageData();
120 if ( !videoFrame->IsImageValid() )
122 LOG_ERROR(
"Video frame is not valid!" );
123 exit( EXIT_FAILURE );
126 vtkSmartPointer<vtkImageExtractComponents> imageExtractorInput = vtkSmartPointer<vtkImageExtractComponents>::New();
127 imageExtractorInput->SetInputData( videoFrame->GetImage() );
128 imageExtractorInput->SetComponents( 0, 0, 0 );
130 imgDiff->SetImageData( baselineRGB );
132 imgDiff->SetInputConnection( imageExtractorInput->GetOutputPort() );
135 double error = imgDiff->GetError();
139 std::cout <<
"Error = " << error << std::endl;
std::string GetOutputPath(const std::string &subPath)
static vtkPlusConfig * GetInstance()
static PlusStatus GenerateTrackedFrameFromSonixVolume(const char *volumeFileName, vtkIGSIOTrackedFrameList *trackedFrameList, double acquisitionFrameRate=10)
int main(int argc, char *argv[])
static vtkIGSIOLogger * Instance()