7 #include "PlusConfigure.h" 8 #include "igsioVideoFrame.h" 9 #include "igsioTrackedFrame.h" 11 #include "vtkImageCast.h" 12 #include "vtkImageData.h" 13 #include "vtkMetaImageReader.h" 14 #include "vtkMetaImageWriter.h" 15 #include "vtkIGSIOSequenceIO.h" 16 #include "vtkSmartPointer.h" 17 #include "vtkIGSIOTrackedFrameList.h" 18 #include "vtkXMLUtilities.h" 19 #include "vtksys/CommandLineArguments.hxx" 22 int main(
int argc,
char** argv)
25 bool printHelp(
false);
26 std::string inputImgSeqFileName;
27 std::string outputImgSeqFileName;
28 std::string inputConfigFileName;
29 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
31 vtksys::CommandLineArguments args;
32 args.Initialize(argc, argv);
34 args.AddArgument(
"--source-seq-file",vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputImgSeqFileName,
"The ultrasound sequence to draw the scanlines on.");
35 args.AddArgument(
"--output-seq-file",vtksys::CommandLineArguments::EQUAL_ARGUMENT, &outputImgSeqFileName,
"The output ultrasound sequence with scanlines overlaid on the images.");
36 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
37 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
42 std::cerr <<
"Error parsing arguments." << std::endl;
43 std::cout <<
"Help: " << args.GetHelp() << std::endl;
49 std::cout << args.GetHelp() << std::endl;
56 if (inputImgSeqFileName.empty())
58 LOG_ERROR(
"--seq-file required");
63 vtkSmartPointer<vtkIGSIOTrackedFrameList> trackedFrameList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
64 if( vtkIGSIOSequenceIO::Read(inputImgSeqFileName, trackedFrameList) !=
PLUS_SUCCESS )
66 LOG_ERROR(
"Unable to read sequence file: " << inputImgSeqFileName);
70 vtkSmartPointer<vtkImageCast> castToDouble = vtkSmartPointer<vtkImageCast>::New();
71 castToDouble->SetOutputScalarTypeToDouble();
73 vtkSmartPointer<vtkPlusForoughiBoneSurfaceProbability> boneSurfaceFilter = vtkSmartPointer<vtkPlusForoughiBoneSurfaceProbability>::New();
74 boneSurfaceFilter->SetInputConnection(castToDouble->GetOutputPort());
76 vtkSmartPointer<vtkImageCast> castToUnsignedChar = vtkSmartPointer<vtkImageCast>::New();
77 castToUnsignedChar->SetOutputScalarTypeToUnsignedChar();
78 castToUnsignedChar->SetInputConnection(boneSurfaceFilter->GetOutputPort());
80 int numberOfFrames = trackedFrameList->GetNumberOfTrackedFrames();
81 LOG_INFO(
"Processing "<<numberOfFrames<<
" frames...");
82 for (
int frameIndex = 0; frameIndex < numberOfFrames; frameIndex++)
84 TrackedFrame* frame = trackedFrameList->GetTrackedFrame(frameIndex);
85 vtkImageData* imageData = frame->GetImageData()->GetImage();
87 castToDouble->SetInputData(imageData);
88 castToUnsignedChar->Update();
91 frame->GetImageData()->DeepCopyFrom(castToUnsignedChar->GetOutput());
95 LOG_INFO(
"Writing new sequence to file...");
96 if (outputImgSeqFileName.empty())
98 int extensionDot = inputImgSeqFileName.find_last_of(
".");
99 if (extensionDot != std::string::npos)
101 inputImgSeqFileName = inputImgSeqFileName.substr(0,extensionDot);
103 outputImgSeqFileName = inputImgSeqFileName +
"-Bones.nrrd";
105 if( vtkIGSIOSequenceIO::Write(outputImgSeqFileName, trackedFrameList) !=
PLUS_SUCCESS )
107 LOG_ERROR(
"Failed to save output volume to " << outputImgSeqFileName);
110 LOG_INFO(
"Writing to "<<outputImgSeqFileName<<
" complete.");
int main(int argc, char **argv)
static vtkIGSIOLogger * Instance()