1 #include "PlusConfigure.h" 2 #include "igsioTrackedFrame.h" 3 #include "vtkImageCast.h" 4 #include "vtkImageData.h" 5 #include "vtkSmartPointer.h" 9 #include <vtkIGSIOTrackedFrameList.h> 10 #include <vtkIGSIOMetaImageSequenceIO.h> 12 #include "vtksys/CommandLineArguments.hxx" 16 int main(
int argc,
char **argv)
18 bool printHelp =
false;
19 vtksys::CommandLineArguments args;
21 std::string inputFileName;
22 std::string outputFileName;
23 std::string configFileName;
24 bool saveIntermediateResults =
false;
25 int verboseLevel=vtkPlusLogger::LOG_LEVEL_UNDEFINED;
27 args.Initialize(argc, argv);
28 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help");
29 args.AddArgument(
"--input-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputFileName,
"The filename for the input ultrasound sequence to process.");
30 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &configFileName,
"The filename for input config file.");
31 args.AddArgument(
"--output-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &outputFileName,
"The filename to write the processed sequence to.");
32 args.AddArgument(
"--save-intermediate-images", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &saveIntermediateResults,
"If intermediate images should be saved to output files");
33 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
37 LOG_ERROR(
"Error parsing arguments");
38 LOG_ERROR(
"Help: " << args.GetHelp());
46 std::cout << args.GetHelp() << std::endl;
52 if (inputFileName.empty())
55 LOG_ERROR(
"--input-seq-file not found!");
59 if (configFileName.empty())
62 LOG_ERROR(
"--config-file not found!");
66 if (outputFileName.empty())
69 LOG_ERROR(
"--output-seq-file not found!");
75 LOG_DEBUG(
"Reading config file...")
76 vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
79 LOG_ERROR(
"Unable to read configuration from file " << configFileName.c_str());
82 LOG_DEBUG(
"Reading config file finished.");
84 vtkXMLDataElement* dataCollectionElement = configRootElement->FindNestedElementWithName(
"DataCollection");
85 if (dataCollectionElement == NULL)
87 LOG_ERROR(
"Cannot find device set in XML tree element: " << ((*configRootElement).GetName()));
91 vtkXMLDataElement* boneEnhancerElement = dataCollectionElement->FindNestedElementWithNameAndAttribute(
"Device",
"Type",
"ImageProcessor");
92 if (boneEnhancerElement == NULL)
94 LOG_ERROR(
"Cannot find BoneEnhancer element in XML tree element: " << ((*dataCollectionElement).GetName()));
98 vtkXMLDataElement* processorElement = boneEnhancerElement->FindNestedElementWithNameAndAttribute(
"Processor",
"Type",
"vtkPlusTransverseProcessEnhancer");
99 if (processorElement == NULL)
101 LOG_ERROR(
"Cannot find image Processor vtkPlusTransverseProcessEnhancer config in XML element: " << ((*boneEnhancerElement).GetName()));
107 vtkSmartPointer<vtkIGSIOTrackedFrameList> trackedFrameList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
110 vtkSmartPointer<vtkImageCast> castToUchar = vtkSmartPointer<vtkImageCast>::New();
111 castToUchar->SetOutputScalarTypeToUnsignedChar();
114 int numberOfFrames = trackedFrameList->GetNumberOfTrackedFrames();
115 LOG_INFO(
"Number of frames in input: " << numberOfFrames);
119 vtkSmartPointer<vtkPlusTransverseProcessEnhancer> boneFilter = vtkSmartPointer<vtkPlusTransverseProcessEnhancer>::New();
121 boneFilter->SetInputFrames(trackedFrameList);
122 boneFilter->ReadConfiguration(processorElement);
124 PlusStatus filterStatus = boneFilter->Update();
127 LOG_ERROR(
"Failed processing frames");
131 LOG_INFO(
"Writing output to file");
133 if (saveIntermediateResults)
136 int startInputFileNameIndex = 0;
137 if (inputFileName.find(
"/") != std::string::npos)
139 startInputFileNameIndex = inputFileName.rfind(
"/") + 1;
141 if (inputFileName.find(
"\\") != std::string::npos)
143 startInputFileNameIndex = inputFileName.rfind(
"\\") + 1;
145 int startOutputFileNameIndex = 0;
146 if (outputFileName.find(
"/") != std::string::npos)
148 startOutputFileNameIndex = outputFileName.rfind(
"/") + 1;
150 if (outputFileName.find(
"\\") != std::string::npos)
152 startOutputFileNameIndex = outputFileName.rfind(
"\\") + 1;
156 boneFilter->SetIntermediateImageFileName(
157 outputFileName.substr(0, startOutputFileNameIndex) + inputFileName.substr(startInputFileNameIndex, inputFileName.find(
".") - startInputFileNameIndex) );
158 boneFilter->SaveAllIntermediateResultsToFile();
163 LOG_ERROR(
"Could not save output sequence to the file: " << outputFileName);
static igsioStatus Write(const std::string &filename, igsioTrackedFrame *frame, US_IMAGE_ORIENTATION orientationInFile=US_IMG_ORIENT_MF, bool useCompression=true, bool EnableImageDataWrite=true)
static igsioStatus Read(const std::string &filename, vtkIGSIOTrackedFrameList *frameList)
static vtkIGSIOLogger * Instance()
int main(int argc, char **argv)
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)