7 #include "PlusConfigure.h" 10 #include "igsioTrackedFrame.h" 11 #include "vtkCommand.h" 13 #include "vtkMatrix4x4.h" 14 #include "vtkIGSIOSequenceIO.h" 15 #include "vtkSmartPointer.h" 16 #include "vtkIGSIOTrackedFrameList.h" 17 #include "vtkTransform.h" 18 #include "vtksys/CommandLineArguments.hxx" 24 int main (
int argc,
char* argv[])
26 std::string inputSequenceMetafile;
27 std::string inputTransformName;
28 std::string outputWirePositionFile(
"./SegmentedWirePositions.txt");
30 std::string inputBaselineFileName;
31 double inputTranslationErrorThreshold(0);
32 double inputRotationErrorThreshold(0);
34 int verboseLevel=vtkPlusLogger::LOG_LEVEL_UNDEFINED;
36 vtksys::CommandLineArguments cmdargs;
37 cmdargs.Initialize(argc, argv);
39 cmdargs.AddArgument(
"--image-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputSequenceMetafile,
"Image sequence metafile");
40 cmdargs.AddArgument(
"--image-position-transform", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputTransformName,
"Transform name used for image position display");
41 cmdargs.AddArgument(
"--output-wire-position-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &outputWirePositionFile,
"Result wire position file name (Default: ./SegmentedWirePositions.txt)");
43 cmdargs.AddArgument(
"--baseline", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputBaselineFileName,
"Name of file storing baseline calibration results");
44 cmdargs.AddArgument(
"--translation-error-threshold", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputTranslationErrorThreshold,
"Translation error threshold in mm.");
45 cmdargs.AddArgument(
"--rotation-error-threshold", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputRotationErrorThreshold,
"Rotation error threshold in degrees.");
46 cmdargs.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
48 if ( !cmdargs.Parse() )
50 std::cerr <<
"Problem parsing arguments" << std::endl;
51 std::cout <<
"Help: " << cmdargs.GetHelp() << std::endl;
57 if ( inputSequenceMetafile.empty() )
59 std::cerr <<
"image-seq-file argument required" << std::endl << std::endl;
60 std::cout <<
"Help: " << cmdargs.GetHelp() << std::endl;
65 LOG_INFO(
"Reading sequence meta file");
66 vtkSmartPointer<vtkIGSIOTrackedFrameList> trackedFrameList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
67 if( vtkIGSIOSequenceIO::Read(inputSequenceMetafile, trackedFrameList) !=
PLUS_SUCCESS )
69 LOG_ERROR(
"Failed to read sequence metafile: " << inputSequenceMetafile);
73 std::ofstream positionInfo;
74 positionInfo.open (outputWirePositionFile.c_str(), ios::out );
76 LOG_INFO(
"Segmenting frames...");
78 for (
unsigned int frameIndex = 0; frameIndex < trackedFrameList->GetNumberOfTrackedFrames(); frameIndex++ )
80 vtkPlusLogger::PrintProgressbar( (100.0 * frameIndex) / trackedFrameList->GetNumberOfTrackedFrames() );
89 if (trackedFrameList->GetTrackedFrame(frameIndex)->GetImageData()->GetVTKScalarPixelType() != VTK_UNSIGNED_CHAR)
91 LOG_ERROR(
"patternRecognition.RecognizePattern only works on unsigned char images");
95 patternRecognition.RecognizePattern( trackedFrameList->GetTrackedFrame(frameIndex), segResults, error, frameIndex );
100 LOG_ERROR(
"SegmentImage: The segmentation has failed due to UNKNOWN exception thrown, the image is ignored");
104 igsioTransformName transformName;
105 if ( transformName.SetTransformName(inputTransformName.c_str()) !=
PLUS_SUCCESS )
107 LOG_ERROR(
"Invalid transform name: " << inputTransformName );
113 double defaultTransform[16]={0};
114 if ( trackedFrameList->GetTrackedFrame(frameIndex)->GetFrameTransform(transformName, defaultTransform) !=
PLUS_SUCCESS )
116 LOG_ERROR(
"Failed to get default frame transform from tracked frame #" << frameIndex);
120 vtkSmartPointer<vtkTransform> frameTransform = vtkSmartPointer<vtkTransform>::New();
121 frameTransform->SetMatrix(defaultTransform);
123 double posZ = frameTransform->GetPosition()[2];
124 double rotZ = frameTransform->GetOrientation()[2];
127 positionInfo << dataType <<
"\t\t" << posZ <<
"\t" << rotZ <<
"\t\t";
134 positionInfo << std::endl;
139 positionInfo.close();
140 vtkPlusLogger::PrintProgressbar(100);
141 std::cout << std::endl;
143 std::cout <<
"Exit success!!!" << std::endl;
std::vector< std::vector< double > > & GetFoundDotsCoordinateValue()
int main(int argc, char *argv[])
static vtkIGSIOLogger * Instance()