7 #include "PlusConfigure.h" 8 #include "igsioTrackedFrame.h" 9 #include "vtkImageData.h" 12 #include "vtkSmartPointer.h" 13 #include "vtkIGSIOTrackedFrameList.h" 14 #include "vtkTransform.h" 15 #include "vtkXMLUtilities.h" 16 #include "vtksys/CommandLineArguments.hxx" 17 #include "vtksys/SystemTools.hxx" 23 int main(
int argc,
char **argv)
26 std::string inputRfFile;
27 std::string inputConfigFileName;
28 std::string outputImgFile;
29 std::string operation=
"BRIGHTNESS_SCAN_CONVERT";
30 bool useCompression(
true);
32 int verboseLevel=vtkPlusLogger::LOG_LEVEL_UNDEFINED;
34 vtksys::CommandLineArguments args;
35 args.Initialize(argc, argv);
37 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
38 args.AddArgument(
"--rf-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputRfFile,
"File name of input RF image data");
39 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Config file containing processing parameters");
40 args.AddArgument(
"--output-img-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &outputImgFile,
"File name of the generated output brightness image");
41 args.AddArgument(
"--use-compression", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &useCompression,
"Use compression when outputting data");
42 args.AddArgument(
"--operation", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &operation,
"Processing operation to be applied on the input file (BRIGHTNESS_CONVERT, BRIGHTNESS_SCAN_CONVERT, default: BRIGHTNESS_SCAN_CONVERT");
43 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
49 std::cerr <<
"Problem parsing arguments" << std::endl;
50 std::cout <<
"Help: " << args.GetHelp() << std::endl;
56 std::cout << args.GetHelp() << std::endl;
62 if (inputConfigFileName.empty())
64 std::cerr <<
"--config-file required " << std::endl;
67 if (inputRfFile.empty())
69 std::cerr <<
"--rf-file required" << std::endl;
72 if (outputImgFile.empty())
74 std::cerr <<
"Missing --output-img-file parameter. Specification of the output image file name is required." << std::endl;
79 LOG_DEBUG(
"Reading input meta file...");
81 vtkSmartPointer< vtkIGSIOTrackedFrameList > frameList = vtkSmartPointer< vtkIGSIOTrackedFrameList >::New();
84 LOG_ERROR(
"Unable to load input sequences file.");
87 LOG_DEBUG(
"Reading input RF file completed");
90 LOG_DEBUG(
"Reading config file...")
91 vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
94 LOG_ERROR(
"Unable to read configuration from file " << inputConfigFileName.c_str());
97 LOG_DEBUG(
"Reading config file finished.");
99 vtkXMLDataElement* dataCollectionConfig = configRootElement->FindNestedElementWithName(
"DataCollection");
100 if (dataCollectionConfig == NULL)
102 LOG_ERROR(
"Cannot find DataCollection element in XML tree!");
105 vtkXMLDataElement* deviceConfig = dataCollectionConfig->FindNestedElementWithName(
"Device");
106 if (deviceConfig == NULL)
108 LOG_ERROR(
"Cannot find DataCollection/ImageAcquisition element in XML tree!");
111 vtkXMLDataElement* outputChannelsElement = deviceConfig->FindNestedElementWithName(
"OutputChannels");
112 if (outputChannelsElement == NULL)
114 LOG_ERROR(
"Cannot find OutputChannels element in device tag tree!");
118 for (
int i = 0;
i < outputChannelsElement->GetNumberOfNestedElements(); ++
i )
120 vtkXMLDataElement* outputChannelElement = outputChannelsElement->GetNestedElement(
i);
122 if (STRCASECMP(outputChannelElement->GetName(),
"OutputChannel") != 0 )
127 vtkXMLDataElement* rfProcesingElement = outputChannelElement->FindNestedElementWithName(
"RfProcessing");
128 if (rfProcesingElement == NULL)
130 LOG_ERROR(
"Cannot find RfProcessing element in channel tag!");
135 vtkSmartPointer<vtkPlusRfProcessor> rfProcessor = vtkSmartPointer<vtkPlusRfProcessor>::New();
136 if ( rfProcessor->ReadConfiguration(rfProcesingElement) !=
PLUS_SUCCESS )
138 LOG_ERROR(
"Failed to read conversion parameters from the configuration file");
143 for (
unsigned int j = 0; j < frameList->GetNumberOfTrackedFrames(); j++)
145 igsioTrackedFrame* rfFrame = frameList->GetTrackedFrame(j);
148 rfProcessor->SetRfFrame(rfFrame->GetImageData()->GetImage(), rfFrame->GetImageData()->GetImageType());
150 if (STRCASECMP(operation.c_str(),
"BRIGHTNESS_CONVERT")==0)
153 vtkImageData* brightnessImage = rfProcessor->GetBrightnessConvertedImage();
155 rfFrame->GetImageData()->DeepCopyFrom(brightnessImage);
156 rfFrame->GetImageData()->SetImageType(US_IMG_BRIGHTNESS);
158 else if (STRCASECMP(operation.c_str(),
"BRIGHTNESS_SCAN_CONVERT")==0)
161 vtkImageData* brightnessImage = rfProcessor->GetBrightnessScanConvertedImage();
163 rfFrame->GetImageData()->DeepCopyFrom(brightnessImage);
164 rfFrame->GetImageData()->SetImageOrientation(US_IMG_ORIENT_MF);
165 rfFrame->GetImageData()->SetImageType(US_IMG_BRIGHTNESS);
169 LOG_ERROR(
"Unknown operation: "<<operation);
174 std::ostringstream ss;
175 std::string path = vtksys::SystemTools::GetFilenamePath(outputImgFile);
180 if( outputChannelElement->GetAttribute(
"Id") != NULL )
182 ss << vtksys::SystemTools::GetFilenameWithoutExtension(outputImgFile) <<
"_OutputChannel_" << outputChannelElement->GetAttribute(
"Id") << vtksys::SystemTools::GetFilenameExtension(outputImgFile);
186 ss << vtksys::SystemTools::GetFilenameWithoutExtension(outputImgFile) <<
"_OutputChannel_" <<
i << vtksys::SystemTools::GetFilenameExtension(outputImgFile);
int main(int argc, char **argv)
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()
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)