12 #include "PlusConfigure.h" 17 #include "vtkImageCast.h" 18 #include <vtkSmartPointer.h> 19 #include <vtksys/CommandLineArguments.hxx> 22 #include <igsioTrackedFrame.h> 23 #include <vtkIGSIOTrackedFrameList.h> 26 int main(
int argc,
char** argv)
29 bool printHelp =
false;
30 vtksys::CommandLineArguments args;
33 std::string inputFileName;
34 std::string inputConfigFileName;
35 std::string outputConfigFileName;
36 std::string outputFileName;
37 bool saveIntermediateResults =
false;
38 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
41 args.Initialize(argc, argv);
42 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help");
43 args.AddArgument(
"--input-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputFileName,
"The filename for the input ultrasound sequence to process.");
44 args.AddArgument(
"--input-config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"The filename for input config file.");
45 args.AddArgument(
"--output-config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &outputConfigFileName,
"Optional filename for output config file. Creates new config file with paramaters used during this test");
46 args.AddArgument(
"--output-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &outputFileName,
"The filename to write the processed sequence to.");
47 args.AddArgument(
"--save-intermediate-images", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &saveIntermediateResults,
"If intermediate images should be saved to output files");
48 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
52 LOG_ERROR(
"Problem parsing arguments");
53 LOG_INFO(
"Help: " << args.GetHelp());
60 int commandCheckStatus = EXIT_SUCCESS;
62 if (inputFileName.empty())
64 LOG_ERROR(
"The argument --input-seq-file is required");
65 commandCheckStatus = EXIT_FAILURE;
67 if (inputConfigFileName.empty())
69 LOG_ERROR(
"The argument --input-config-file is required");
70 commandCheckStatus = EXIT_FAILURE;
72 if (outputFileName.empty())
74 LOG_ERROR(
"The argument --output-seq-file is required");
75 commandCheckStatus = EXIT_FAILURE;
78 if (commandCheckStatus == EXIT_FAILURE)
83 vtkSmartPointer<vtkPlusTransverseProcessEnhancer> enhancer = vtkSmartPointer<vtkPlusTransverseProcessEnhancer>::New();
86 vtkSmartPointer<vtkIGSIOTrackedFrameList> trackedFrameList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
91 vtkSmartPointer<vtkImageCast> castToUchar = vtkSmartPointer<vtkImageCast>::New();
92 castToUchar->SetOutputScalarTypeToUnsignedChar();
94 int numberOfFrames = trackedFrameList->GetNumberOfTrackedFrames();
95 LOG_INFO(
"Number of frames in input: " << numberOfFrames);
97 enhancer->SetInputFrames(trackedFrameList);
99 LOG_INFO(
"Reading Config file");
100 vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
103 LOG_ERROR(
"Unable to read configuration from file " << inputConfigFileName);
107 vtkSmartPointer<vtkXMLDataElement> elementToUse;
110 vtkSmartPointer<vtkXMLDataElement> processorElement = configRootElement->FindNestedElementWithName(
"ScanConversion");
111 if (processorElement == NULL)
113 processorElement = configRootElement->LookupElementWithName(
"Processor");
114 if (processorElement != NULL){
115 vtkSmartPointer<vtkXMLDataElement> scanConversionElement = processorElement->FindNestedElementWithName(
"ScanConversion");
116 if (scanConversionElement == NULL){
117 LOG_ERROR(
"Cannot find device set in XML tree element: ScanConversion");
122 elementToUse = processorElement;
128 LOG_ERROR(
"Cannot find device set in XML tree: Processor");
134 elementToUse = configRootElement;
137 if (enhancer->ReadConfiguration(elementToUse) ==
PLUS_FAIL)
139 LOG_ERROR(
"Unable to read configuration from file " << inputConfigFileName);
142 LOG_INFO(
"Reading config file finished");
145 enhancer->SetSaveIntermediateResults(saveIntermediateResults);
146 LOG_INFO(
"Processing frames...");
150 LOG_ERROR(
"Processing frames failed!");
154 LOG_INFO(
"Processing frames successful");
155 if (saveIntermediateResults)
158 int startInputFileNameIndex = 0;
159 if (inputFileName.find(
"/") != std::string::npos)
161 startInputFileNameIndex = inputFileName.rfind(
"/") + 1;
163 if (inputFileName.find(
"\\") != std::string::npos)
165 startInputFileNameIndex = inputFileName.rfind(
"\\") + 1;
167 int startOutputFileNameIndex = 0;
168 if (outputFileName.find(
"/") != std::string::npos)
170 startOutputFileNameIndex = outputFileName.rfind(
"/") + 1;
172 if (outputFileName.find(
"\\") != std::string::npos)
174 startOutputFileNameIndex = outputFileName.rfind(
"\\") + 1;
178 enhancer->SetIntermediateImageFileName(
179 outputFileName.substr(0, startOutputFileNameIndex) + inputFileName.substr(startInputFileNameIndex, inputFileName.find(
".") - startInputFileNameIndex));
180 enhancer->SaveAllIntermediateResultsToFile();
185 LOG_ERROR(
"Could not save output sequence to the file: " << outputFileName);
190 if (!outputConfigFileName.empty())
193 vtkSmartPointer<vtkXMLDataElement> processorWriteData = vtkSmartPointer<vtkXMLDataElement>::New();
194 processorWriteData->SetName(
"Processor");
197 LOG_INFO(
"Writing to config file.");
198 if (enhancer->WriteConfiguration(processorWriteData) ==
PLUS_FAIL)
200 LOG_ERROR(
"Unable to write to config file.");
203 if (igsioCommon::XML::PrintXML(outputConfigFileName, processorWriteData) ==
PLUS_FAIL)
205 LOG_ERROR(
"An error occured when trying to save to the config file " << outputConfigFileName);
208 LOG_INFO(
"Writing to config file finished successfully.");
211 LOG_INFO(
"Completed Test Successfully.");
static igsioStatus Write(const std::string &filename, igsioTrackedFrame *frame, US_IMAGE_ORIENTATION orientationInFile=US_IMG_ORIENT_MF, bool useCompression=true, bool EnableImageDataWrite=true)
int main(int argc, char **argv)
static igsioStatus Read(const std::string &filename, vtkIGSIOTrackedFrameList *frameList)
static vtkIGSIOLogger * Instance()
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)