8 #include "PlusConfigure.h" 13 #include <vtkImageFlip.h> 14 #include <vtkObjectFactory.h> 15 #include <vtkPNGReader.h> 32 this->Superclass::PrintSelf(os, indent);
44 vtkSmartPointer<vtkImageData> volumeToSave = vtkSmartPointer<vtkImageData>::New();
47 if (this->ExtractAccumulation(volumeToSave) !=
PLUS_SUCCESS)
49 LOG_ERROR(
"Extracting accumulation buffer failed!");
55 if (this->ExtractGrayLevels(volumeToSave) !=
PLUS_SUCCESS)
57 LOG_ERROR(
"Extracting gray channel failed!");
67 if (volumeToSave == NULL)
69 LOG_ERROR(
"vtkPlusVolumeReconstructor::SaveReconstructedVolumeToMetafile: invalid input image");
74 volumeToSave->GetDimensions(dims);
75 FrameSizeType frameSize = { static_cast<unsigned int>(dims[0]), static_cast<unsigned int>(dims[1]), static_cast<unsigned int>(dims[2]) };
77 vtkNew<vtkIGSIOTrackedFrameList> list;
78 igsioTrackedFrame frame;
79 igsioVideoFrame image;
80 image.AllocateFrame(frameSize, volumeToSave->GetScalarType(), volumeToSave->GetNumberOfScalarComponents());
81 image.GetImage()->DeepCopy(volumeToSave);
82 image.SetImageOrientation(US_IMG_ORIENT_MFA);
83 image.SetImageType(US_IMG_BRIGHTNESS);
84 frame.SetImageData(image);
85 list->AddTrackedFrame(&frame);
86 if (customFields !=
nullptr && customValues !=
nullptr)
88 for (
unsigned i=0;
i < customFields->size(); ++
i)
90 list->SetCustomString(customFields->at(
i), customValues->at(
i));
95 LOG_ERROR(
"Failed to save reconstructed volume in sequence metafile!");
105 if (this->ImportanceMaskFilename == this->ImportanceMaskFilenameInReconstructor)
110 this->ImportanceMaskFilenameInReconstructor = this->ImportanceMaskFilename;
112 if (!this->ImportanceMaskFilename.empty())
114 std::string importanceMaskFilePath;
117 LOG_ERROR(
"Cannot get importance mask from file: " << this->ImportanceMaskFilename);
120 vtkSmartPointer<vtkPNGReader> reader = vtkSmartPointer<vtkPNGReader>::New();
121 reader->SetFileName(importanceMaskFilePath.c_str());
123 if (reader->GetOutput() == NULL)
125 LOG_ERROR(
"Failed to read importance image from file: " << importanceMaskFilePath);
128 vtkSmartPointer<vtkImageFlip> flipYFilter = vtkSmartPointer<vtkImageFlip>::New();
129 flipYFilter->SetFilteredAxis(1);
130 flipYFilter->SetInputConnection(reader->GetOutputPort());
131 flipYFilter->Update();
132 this->Reconstructor->SetImportanceMask(flipYFilter->GetOutput());
136 this->Reconstructor->SetImportanceMask(NULL);
virtual PlusStatus SaveReconstructedVolumeToFile(const std::string &filename, bool accumulation=false, bool useCompression=true) override
static vtkPlusConfig * GetInstance()
virtual PlusStatus UpdateImportanceMask() override
static igsioStatus Write(const std::string &filename, igsioTrackedFrame *frame, US_IMAGE_ORIENTATION orientationInFile=US_IMG_ORIENT_MF, bool useCompression=true, bool EnableImageDataWrite=true)
PlusStatus FindImagePath(const std::string &aImagePath, std::string &aFoundAbsolutePath)
vtkPlusVolumeReconstructor()
Reconstructs a volume from tracked frames.
virtual void PrintSelf(ostream &os, vtkIndent indent) override
virtual ~vtkPlusVolumeReconstructor()
vtkStandardNewMacro(vtkPlusVolumeReconstructor)