18 #include <vtkErrorCode.h> 19 #include <vtkSmartPointer.h> 20 #include <vtkXMLPolyDataReader.h> 21 #include <vtkXMLPolyDataWriter.h> 25 class VtkXMLPolyDataReader :
public ::vtkXMLPolyDataReader
28 static VtkXMLPolyDataReader *New() {
return new VtkXMLPolyDataReader(); }
29 vtkTypeMacro(VtkXMLPolyDataReader, vtkXMLPolyDataReader)
31 void SetStream(std::istream *is)
35 std::istream *GetStream()
const {
return this->Stream; }
38 class VtkXMLPolyDataWriter :
public ::vtkXMLPolyDataWriter
41 static VtkXMLPolyDataWriter *New() {
return new VtkXMLPolyDataWriter(); }
42 vtkTypeMacro(VtkXMLPolyDataWriter, vtkXMLPolyDataWriter)
44 void SetStream(std::ostream *os)
48 std::ostream *GetStream()
const {
return this->Stream; }
61 vtkSmartPointer<VtkXMLPolyDataReader> reader = vtkSmartPointer<VtkXMLPolyDataReader>::New();
72 if (reader->GetOutput() !=
nullptr)
74 output->SetVtkPolyData(reader->GetOutput());
78 mitkThrow() <<
"vtkXMLPolyDataReader error: " << vtkErrorCode::GetStringFromErrorCode(reader->GetErrorCode());
81 std::vector<BaseData::Pointer> result;
82 result.push_back(output.GetPointer());
93 vtkSmartPointer<VtkXMLPolyDataReader> xmlReader = vtkSmartPointer<VtkXMLPolyDataReader>::New();
94 if (xmlReader->CanReadFile(this->GetInputLocation().c_str()) != 0)
112 for (
unsigned int t = 0; t < timesteps; ++t)
114 std::string fileName;
115 vtkSmartPointer<vtkPolyData> polyData = this->
GetPolyData(t, fileName);
116 if (polyData.Get() ==
nullptr)
118 mitkThrow() <<
"Cannot write empty surface";
121 vtkSmartPointer<VtkXMLPolyDataWriter> writer = vtkSmartPointer<VtkXMLPolyDataWriter>::New();
122 writer->SetInputData(polyData);
126 if (input->GetTimeGeometry()->CountTimeSteps() > 1)
128 MITK_WARN <<
"Writing multiple time-steps to output streams is not supported. " 129 <<
"Only the first time-step will be written";
135 writer->SetFileName(fileName.c_str());
138 if (writer->Write() == 0 || writer->GetErrorCode() != 0)
140 mitkThrow() <<
"Error during surface writing" 141 << (writer->GetErrorCode() ?
142 std::string(
": ") + vtkErrorCode::GetStringFromErrorCode(writer->GetErrorCode()) :
std::vector< BaseData::Pointer > Read() override
Reads a path or stream and creates a list of BaseData objects.
Class for storing surfaces (vtkPolyData).
virtual TimeStepType CountTimeSteps() const =0
Returns the number of time steps.
ConfidenceLevel GetReaderConfidenceLevel() const override
std::istream * GetInputStream() const override
Get the input stream.
DataCollection - Class to facilitate loading/accessing structured data.
vtkSmartPointer< vtkPolyData > GetPolyData(unsigned int t, std::string &fileName)
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
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())
void Write() override
Write the base data to the specified location or output stream.
const BaseData * GetInput() const override
Get the input data set via SetInput().
void ValidateOutputLocation() const
std::ostream * GetOutputStream() const override
Get the output stream.
std::string GetInputLocation() const override
Get the current input location.
ConfidenceLevel GetReaderConfidenceLevel() const override