1 #include "PlusConfigure.h" 2 #include "igsioTrackedFrame.h" 3 #include "vtkImageCast.h" 4 #include "vtkImageData.h" 5 #include "vtkIGSIOMetaImageSequenceIO.h" 6 #include "vtkSmartPointer.h" 7 #include "vtkIGSIOTrackedFrameList.h" 13 #include "vtksys/CommandLineArguments.hxx" 19 int lineLengthPx = linesImageExtent[1] - linesImageExtent[0] + 1;
20 int numScanLines = linesImageExtent[3] - linesImageExtent[2] + 1;
22 float inputPixelValue = 0.0;
24 int* inputExtent = inputImageData->GetExtent();
25 for (
int scanLine = 0; scanLine < numScanLines; scanLine ++ )
27 double start[4] = {0};
31 double directionVectorX = static_cast<double>(end[0]-
start[0])/(lineLengthPx-1);
32 double directionVectorY = static_cast<double>(end[1]-
start[1])/(lineLengthPx-1);
33 for (
int pointIndex=0; pointIndex<lineLengthPx; ++pointIndex)
35 int pixelCoordX =
start[0] + directionVectorX * pointIndex;
36 int pixelCoordY =
start[1] + directionVectorY * pointIndex;
37 if ( pixelCoordX<inputExtent[0] || pixelCoordX>inputExtent[1] || pixelCoordY<inputExtent[2] || pixelCoordY>inputExtent[3] )
39 outputImageData->SetScalarComponentFromFloat(pointIndex, scanLine, 0, 0, 0);
42 inputPixelValue = inputImageData->GetScalarComponentAsFloat(pixelCoordX, pixelCoordY, 0, 0);
43 outputImageData->SetScalarComponentFromFloat(pointIndex, scanLine, 0, 0, inputPixelValue);
49 int main(
int argc,
char** argv)
51 bool printHelp =
false;
52 vtksys::CommandLineArguments args;
54 std::string inputFileName;
55 std::string outputFileName;
56 std::string configFileName;
57 int verboseLevel=vtkPlusLogger::LOG_LEVEL_UNDEFINED;
59 args.Initialize(argc, argv);
60 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help");
61 args.AddArgument(
"--input-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputFileName,
"The filename for the input ultrasound sequence to process.");
62 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &configFileName,
"The filename for input config file.");
63 args.AddArgument(
"--output-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &outputFileName,
"The filename to write the processed sequence to.");
64 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
68 std::cerr <<
"Error parsing arguments" << std::endl;
69 std::cout <<
"Help: " << args.GetHelp() << std::endl;
75 std::cout << args.GetHelp() << std::endl;
81 if (inputFileName.empty())
83 std::cerr <<
"--input-seq-file not found!" << std::endl;
87 if (configFileName.empty())
89 std::cerr <<
"--config-file not found!" << std::endl;
93 if (outputFileName.empty())
95 std::cerr <<
"--output-seq-file not found!" << std::endl;
101 vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
104 LOG_ERROR(
"Unable to read configuration from file " << configFileName.c_str());
108 vtkXMLDataElement* scanConversionElement = configRootElement->FindNestedElementWithName(
"ScanConversion");
109 if (scanConversionElement == NULL)
111 LOG_ERROR(
"Cannot find ScanConversion element in XML tree!");
115 const char* transducerGeometry = scanConversionElement->GetAttribute(
"TransducerGeometry");
116 if (transducerGeometry == NULL)
118 LOG_ERROR(
"Scan converter TransducerGeometry is undefined!");
122 int numberOfScanLines = 100;
123 int numberOfSamplesPerScanLine = 200;
126 XML_READ_SCALAR_ATTRIBUTE_NONMEMBER_OPTIONAL(
int, NumberOfScanLines, numberOfScanLines, scanConversionElement)
127 XML_READ_SCALAR_ATTRIBUTE_NONMEMBER_OPTIONAL(
int, NumberOfSamplesPerScanLine, numberOfSamplesPerScanLine, scanConversionElement)
129 if ( scanConversionElement->GetAttribute(
"NumberOfScanLines") == NULL )
131 LOG_WARNING(
"NumberOfScanLines attribute not specified. Using default value.")
133 if ( scanConversionElement->GetAttribute(
"NumberOfSamplesPerScanLine") == NULL )
135 LOG_WARNING(
"NumberOfSamplesPerScanLine attribute not specified. Using default value.")
140 vtkSmartPointer<vtkPlusUsScanConvert> scanConverter;
141 if (STRCASECMP(transducerGeometry,
"CURVILINEAR")==0)
145 else if (STRCASECMP(transducerGeometry,
"LINEAR")==0)
151 LOG_ERROR(
"Invalid scan converter TransducerGeometry: " << transducerGeometry);
154 scanConverter->ReadConfiguration(scanConversionElement);
158 vtkSmartPointer<vtkIGSIOTrackedFrameList> inputFrameList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
160 int numberOfFrames = inputFrameList->GetNumberOfTrackedFrames();
164 int linesImageExtent[6]= {0, numberOfSamplesPerScanLine-1, 0, numberOfScanLines-1, 0, 0};
165 scanConverter->SetInputImageExtent(linesImageExtent);
167 vtkSmartPointer<vtkImageData> linesImage = vtkSmartPointer<vtkImageData>::New();
168 linesImage->SetExtent(linesImageExtent);
169 linesImage->AllocateScalars(VTK_UNSIGNED_CHAR, 1);
172 vtkSmartPointer<vtkIGSIOTrackedFrameList> linesFrameList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
173 vtkSmartPointer<vtkIGSIOTrackedFrameList> outputFrameList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
176 for (
int frameIndex = 0; frameIndex < numberOfFrames; frameIndex ++ )
178 igsioTrackedFrame* inputFrame = inputFrameList->GetTrackedFrame(frameIndex);
180 linesFrameList->AddTrackedFrame(inputFrame);
181 igsioTrackedFrame* linesFrame = linesFrameList->GetTrackedFrame(linesFrameList->GetNumberOfTrackedFrames()-1);
182 linesFrame->GetImageData()->DeepCopyFrom(linesImage);
185 extractScanLines(scanConverter, inputFrame->GetImageData()->GetImage(), linesFrame->GetImageData()->GetImage() );
188 std::cout <<
"Writing output to file. Setting log level to 1, regardless of user specified verbose level." << std::endl;
virtual PlusStatus GetScanLineEndPoints(int scanLineIndex, double scanlineStartPoint_OutputImage[4], double scanlineEndPoint_OutputImage[4])=0
static vtkPlusUsScanConvertLinear * New()
virtual int * GetInputImageExtent()
static igsioStatus Write(const std::string &filename, igsioTrackedFrame *frame, US_IMAGE_ORIENTATION orientationInFile=US_IMG_ORIENT_MF, bool useCompression=true, bool EnableImageDataWrite=true)
static vtkPlusUsScanConvertCurvilinear * New()
static igsioStatus Read(const std::string &filename, vtkIGSIOTrackedFrameList *frameList)
static vtkIGSIOLogger * Instance()
This is a base class for defining a common scan conversion algorithm interface for all kinds of probe...
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)