18 #include <vtkErrorCode.h> 19 #include <vtkPolyDataReader.h> 20 #include <vtkPolyDataWriter.h> 21 #include <vtkSmartPointer.h> 22 #include <vtkXMLPolyDataReader.h> 23 #include <vtkXMLPolyDataWriter.h> 31 defaultOptions[
"Save as binary file"] =
false;
42 vtkSmartPointer<vtkPolyDataReader> reader = vtkSmartPointer<vtkPolyDataReader>::New();
43 reader->SetFileName(fileName.c_str());
46 if (reader->GetOutput() !=
nullptr)
48 output->SetVtkPolyData(reader->GetOutput());
52 mitkThrow() <<
"vtkPolyDataReader error: " << vtkErrorCode::GetStringFromErrorCode(reader->GetErrorCode());
55 std::vector<BaseData::Pointer> result;
56 result.push_back(output.GetPointer());
64 vtkSmartPointer<vtkPolyDataReader> reader = vtkSmartPointer<vtkPolyDataReader>::New();
66 if (reader->IsFilePolyData())
68 if (std::strcmp(reader->GetHeader(),
"vtk output") == 0)
85 for (
unsigned int t = 0; t < timesteps; ++t)
88 vtkSmartPointer<vtkPolyData> polyData = this->
GetPolyData(t, fileName);
89 vtkSmartPointer<vtkPolyDataWriter> writer = vtkSmartPointer<vtkPolyDataWriter>::New();
90 writer->SetInputData(polyData);
93 writer->SetFileTypeToBinary();
97 writer->SetFileName(localFile.
GetFileName().c_str());
99 if (writer->Write() == 0 || writer->GetErrorCode() != 0)
101 mitkThrow() <<
"Error during surface writing" 102 << (writer->GetErrorCode() ?
103 std::string(
": ") + vtkErrorCode::GetStringFromErrorCode(writer->GetErrorCode()) :
107 if (this->
GetOutputStream() && input->GetTimeGeometry()->CountTimeSteps() > 1)
109 MITK_WARN <<
"Writing multiple time-steps to output streams is not supported. " 110 <<
"Only the first time-step will be written";
Class for storing surfaces (vtkPolyData).
virtual TimeStepType CountTimeSteps() const =0
Returns the number of time steps.
std::vector< BaseData::Pointer > Read() override
Reads a path or stream and creates a list of BaseData objects.
ConfidenceLevel GetReaderConfidenceLevel() const override
std::string GetFileName()
DataCollection - Class to facilitate loading/accessing structured data.
vtkSmartPointer< vtkPolyData > GetPolyData(unsigned int t, std::string &fileName)
std::map< std::string, us::Any > Options
Options for reading or writing data.
us::Any GetWriterOption(const std::string &name) const
std::string GetLocalFileName() const
Get a local file name for reading.
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())
const BaseData * GetInput() const override
Get the input data set via SetInput().
void Write() override
Write the base data to the specified location or output stream.
A local file representation for streams.
void ValidateOutputLocation() const
std::ostream * GetOutputStream() const override
Get the output stream.
ConfidenceLevel GetReaderConfidenceLevel() const override
void SetDefaultWriterOptions(const Options &defaultOptions)