23 #include <vtkCleanPolyData.h>
24 #include <vtkErrorCode.h>
25 #include <vtkPolyDataNormals.h>
26 #include <vtkSTLReader.h>
27 #include <vtkSTLWriter.h>
28 #include <vtkSmartPointer.h>
29 #include <vtkTriangleFilter.h>
33 std::string SurfaceStlIO::OPTION_MERGE_POINTS()
35 static std::string s =
"Merge points";
39 std::string SurfaceStlIO::OPTION_TAG_SOLIDS()
41 static std::string s =
"Tag solids";
45 std::string SurfaceStlIO::OPTION_CLEAN()
47 static std::string s =
"Clean poly data";
56 defaultOptions[OPTION_MERGE_POINTS()] =
us::Any(
true);
57 defaultOptions[OPTION_TAG_SOLIDS()] =
us::Any(
false);
58 defaultOptions[OPTION_CLEAN()] =
us::Any(
true);
76 bool mergePoints =
true;
77 bool tagSolids =
false;
78 bool cleanData =
true;
82 mergePoints =
us::any_cast<
bool>(options[OPTION_MERGE_POINTS()]);
83 tagSolids =
us::any_cast<
bool>(options[OPTION_TAG_SOLIDS()]);
91 stlReader->SetMerging(mergePoints);
92 stlReader->SetScalarTags(tagSolids);
95 normalsGenerator->SetInputConnection(stlReader->GetOutputPort());
97 vtkSmartPointer<vtkPolyDataAlgorithm> algo = normalsGenerator;
101 cleanPolyDataFilter->SetInputConnection(normalsGenerator->GetOutputPort());
102 cleanPolyDataFilter->PieceInvariantOff();
103 cleanPolyDataFilter->ConvertLinesToPointsOff();
104 cleanPolyDataFilter->ConvertPolysToLinesOff();
105 cleanPolyDataFilter->ConvertStripsToPolysOff();
108 cleanPolyDataFilter->PointMergingOn();
110 algo = cleanPolyDataFilter;
114 if (algo->GetOutput() != NULL)
116 vtkSmartPointer<vtkPolyData> surfaceWithNormals = algo->GetOutput();
117 output->SetVtkPolyData(surfaceWithNormals);
120 std::vector<BaseData::Pointer> result;
121 result.push_back(output.GetPointer());
132 const unsigned int timesteps = input->
GetTimeGeometry()->CountTimeSteps();
133 for (
unsigned int t = 0; t < timesteps; ++t)
135 std::string fileName;
136 vtkSmartPointer<vtkPolyData> polyData = this->
GetPolyData(t, fileName);
138 triangleFilter->SetInputData(polyData);
140 writer->SetInputConnection(triangleFilter->GetOutputPort());
144 writer->SetFileName(localFile.
GetFileName().c_str());
146 if (writer->Write() == 0 || writer->GetErrorCode() != 0)
148 mitkThrow() <<
"Error during surface writing"
149 << (writer->GetErrorCode() ?
150 std::string(
": ") + vtkErrorCode::GetStringFromErrorCode(writer->GetErrorCode()) :
156 MITK_WARN <<
"Writing multiple time-steps to output streams is not supported. "
157 <<
"Only the first time-step will be written";
Class for storing surfaces (vtkPolyData).
virtual const char * what() const override
std::string GetFileName()
DataCollection - Class to facilitate loading/accessing structured data.
ValueType * any_cast(Any *operand)
void ValidateOutputLocation() const
void SetDefaultReaderOptions(const Options &defaultOptions)
vtkSmartPointer< vtkPolyData > GetPolyData(unsigned int t, std::string &fileName)
Options GetReaderOptions() const
std::map< std::string, us::Any > Options
Options for reading or writing data.
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
std::string GetLocalFileName() const
Get a local file name for reading.
virtual void Write() override
Write the base data to the specified location or output stream.
virtual std::vector< itk::SmartPointer< BaseData > > Read() override
Reads a path or stream and creates a list of BaseData objects.
Convenience class to temporarily change the current locale.
std::pair< us::ServiceRegistration< IFileReader >, us::ServiceRegistration< IFileWriter > > RegisterService(us::ModuleContext *context=us::GetModuleContext())
virtual const BaseData * GetInput() const override
Get the input data set via SetInput().
static const char * GetStaticNameOfClass()
A local file representation for streams.
virtual std::ostream * GetOutputStream() const override
Get the output stream.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.