19 #include <vtkErrorCode.h> 20 #include <vtkImageData.h> 21 #include <vtkSmartPointer.h> 22 #include <vtkXMLImageDataReader.h> 23 #include <vtkXMLImageDataWriter.h> 27 class VtkXMLImageDataReader :
public ::vtkXMLImageDataReader
30 static VtkXMLImageDataReader *New() {
return new VtkXMLImageDataReader(); }
31 vtkTypeMacro(VtkXMLImageDataReader, vtkXMLImageDataReader)
33 void SetStream(std::istream *is)
37 std::istream *GetStream()
const {
return this->Stream; }
40 class VtkXMLImageDataWriter :
public ::vtkXMLImageDataWriter
43 static VtkXMLImageDataWriter *New() {
return new VtkXMLImageDataWriter(); }
44 vtkTypeMacro(VtkXMLImageDataWriter, vtkXMLImageDataWriter)
46 void SetStream(std::ostream *os)
50 std::ostream *GetStream()
const {
return this->Stream; }
61 vtkSmartPointer<VtkXMLImageDataReader> reader = vtkSmartPointer<VtkXMLImageDataReader>::New();
72 if (reader->GetOutput() !=
nullptr)
75 output->Initialize(reader->GetOutput());
76 output->SetVolume(reader->GetOutput()->GetScalarPointer());
77 std::vector<BaseData::Pointer> result;
78 result.push_back(output.GetPointer());
83 mitkThrow() <<
"vtkXMLImageDataReader error: " << vtkErrorCode::GetStringFromErrorCode(reader->GetErrorCode());
94 vtkSmartPointer<VtkXMLImageDataReader> xmlReader = vtkSmartPointer<VtkXMLImageDataReader>::New();
95 if (xmlReader->CanReadFile(this->GetInputLocation().c_str()) != 0)
110 const auto *input =
dynamic_cast<const Image *
>(this->
GetInput());
112 vtkSmartPointer<VtkXMLImageDataWriter> writer = vtkSmartPointer<VtkXMLImageDataWriter>::New();
123 writer->SetInputData(const_cast<vtkImageData *>(vtkReadAccessor.GetVtkImageData()));
125 if (writer->Write() == 0 || writer->GetErrorCode() != 0)
127 mitkThrow() <<
"vtkXMLImageDataWriter error: " << vtkErrorCode::GetStringFromErrorCode(writer->GetErrorCode());
135 const auto *input =
static_cast<const Image *
>(this->
GetInput());
136 if (input->GetDimension() == 3)
138 else if (input->GetDimension() < 3)
ConfidenceLevel GetReaderConfidenceLevel() const override
std::istream * GetInputStream() const override
Get the input stream.
DataCollection - Class to facilitate loading/accessing structured data.
ConfidenceLevel GetReaderConfidenceLevel() const override
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
std::pair< us::ServiceRegistration< IFileReader >, us::ServiceRegistration< IFileWriter > > RegisterService(us::ModuleContext *context=us::GetModuleContext())
const BaseData * GetInput() const override
Get the input data set via SetInput().
Image class for storing images.
void ValidateOutputLocation() const
ConfidenceLevel GetWriterConfidenceLevel() const override
void Write() override
Write the base data to the specified location or output stream.
ImageVtkReadAccessor class provides any image read access which is required by Vtk methods...
std::ostream * GetOutputStream() const override
Get the output stream.
std::string GetOutputLocation() const override
Get the current output location.
ConfidenceLevel GetWriterConfidenceLevel() const override
std::vector< BaseData::Pointer > Read() override
Reads a path or stream and creates a list of BaseData objects.
std::string GetInputLocation() const override
Get the current input location.
Abstract class for implementing a reader and writer.