18 #include <vtkSmartPointer.h>
19 #include <vtkCleanPolyData.h>
20 #include <itksys/SystemTools.hxx>
23 #include <vtkFloatArray.h>
24 #include <vtkCellData.h>
25 #include <vtkPointData.h>
28 #include <vtkXMLPolyDataWriter.h>
35 defaultOptions[
"Save as binary file"] =
true;
36 defaultOptions[
"Save as xml file (vtp style)"] =
false;
37 defaultOptions[
"Save color information"] =
false;
38 defaultOptions[
"Save fiber weights"] =
true;
59 std::ofstream outStream;
61 if( this->GetOutputStream() )
63 out = this->GetOutputStream();
65 outStream.open( this->GetOutputLocation().c_str() );
76 const std::string& locale =
"C";
77 const std::string& currLocale = setlocale( LC_ALL, NULL );
78 setlocale(LC_ALL, locale.c_str());
80 std::locale previousLocale(out->getloc());
84 std::string
filename = this->GetOutputLocation().c_str();
87 std::string ext = itksys::SystemTools::GetFilenameLastExtension(this->GetOutputLocation().c_str());
88 Options options = this->GetOptions();
90 vtkSmartPointer<vtkPolyData> fibPoly = input->GetFiberPolyData();
91 if (us::any_cast<bool>(options[
"Save fiber weights"]))
93 MITK_INFO <<
"Adding fiber weight information";
94 fibPoly->GetCellData()->AddArray(input->GetFiberWeights());
96 else if (fibPoly->GetCellData()->HasArray(
"FIBER_WEIGHTS"))
97 fibPoly->GetCellData()->RemoveArray(
"FIBER_WEIGHTS");
98 if (us::any_cast<bool>(options[
"Save color information"]))
101 fibPoly->GetPointData()->AddArray(input->GetFiberColors());
103 else if (fibPoly->GetPointData()->HasArray(
"FIBER_COLORS"))
104 fibPoly->GetPointData()->RemoveArray(
"FIBER_COLORS");
110 this->SetOutputLocation(this->GetOutputLocation() + ext);
113 if (us::any_cast<bool>(options[
"Save as xml file (vtp style)"]))
116 writer->SetInputData(fibPoly);
117 writer->SetFileName(filename.c_str());
118 if (us::any_cast<bool>(options[
"Save as binary file"]))
120 MITK_INFO <<
"Writing fiber bundle as vtk binary file";
121 writer->SetDataModeToBinary();
125 MITK_INFO <<
"Writing fiber bundle as vtk ascii file";
126 writer->SetDataModeToAscii();
133 writer->SetInputData(fibPoly);
134 writer->SetFileName(filename.c_str());
135 if (us::any_cast<bool>(options[
"Save as binary file"]))
137 MITK_INFO <<
"Writing fiber bundle as vtk binary file";
138 writer->SetFileTypeToBinary();
142 MITK_INFO <<
"Writing fiber bundle as vtk ascii file";
143 writer->SetFileTypeToASCII();
148 setlocale(LC_ALL, currLocale.c_str());
virtual void Write() override
Write the base data to the specified location or output stream.
DataCollection - Class to facilitate loading/accessing structured data.
std::map< std::string, us::Any > Options
Options for reading or writing data.
void SetDefaultOptions(const Options &defaultOptions)
static const std::string filename
Base Class for Fiber Bundles;.
static const char * GetStaticNameOfClass()
virtual FiberBundleVtkWriter * Clone() const override
virtual ~FiberBundleVtkWriter()
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
Base class for writing mitk::BaseData objects to files or streams.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.