18 #include <itkMetaDataObject.h>
19 #include <vtkPolyData.h>
20 #include <vtkDataReader.h>
21 #include <vtkPolyDataReader.h>
22 #include <vtkMatrix4x4.h>
23 #include <vtkPolyLine.h>
24 #include <vtkCellArray.h>
25 #include <vtkDataArray.h>
26 #include <vtkFloatArray.h>
27 #include <vtkCellData.h>
28 #include <vtkPointData.h>
29 #include <itksys/SystemTools.hxx>
31 #include <vtkCleanPolyData.h>
34 #include <vtkXMLPolyDataReader.h>
35 #include <vtkXMLDataReader.h>
59 std::vector<itk::SmartPointer<mitk::BaseData> > result;
61 const std::string& locale =
"C";
62 const std::string& currLocale = setlocale( LC_ALL, NULL );
63 setlocale(LC_ALL, locale.c_str());
65 std::string
filename = this->GetInputLocation();
67 std::string ext = itksys::SystemTools::GetFilenameLastExtension(filename);
68 ext = itksys::SystemTools::LowerCase(ext);
72 MITK_INFO <<
"Trying to load fiber file as VTK format.";
74 reader->SetFileName( this->GetInputLocation().c_str() );
76 if (reader->IsFilePolyData())
80 if ( reader->GetOutput() != NULL )
82 vtkSmartPointer<vtkPolyData> fiberPolyData = reader->GetOutput();
85 vtkSmartPointer<vtkFloatArray> weights = vtkFloatArray::SafeDownCast(fiberPolyData->GetCellData()->GetArray(
"FIBER_WEIGHTS"));
89 for (
int i=0; i<weights->GetSize(); i++)
90 if (!
mitk::Equal(weights->GetValue(i),weight,0.00001))
92 MITK_INFO <<
"Weight: " << weights->GetValue(i);
93 weight = weights->GetValue(i);
95 fiberBundle->SetFiberWeights(weights);
98 vtkSmartPointer<vtkUnsignedCharArray> fiberColors = vtkUnsignedCharArray::SafeDownCast(fiberPolyData->GetPointData()->GetArray(
"FIBER_COLORS"));
99 if (fiberColors!=NULL)
100 fiberBundle->SetFiberColors(fiberColors);
102 result.push_back(fiberBundle.GetPointer());
116 MITK_INFO <<
"Trying to load fiber file as VTP format.";
118 reader->SetFileName( this->GetInputLocation().c_str() );
120 if ( reader->CanReadFile(this->GetInputLocation().c_str()) )
124 if ( reader->GetOutput() != NULL )
126 vtkSmartPointer<vtkPolyData> fiberPolyData = reader->GetOutput();
129 vtkSmartPointer<vtkFloatArray> weights = vtkFloatArray::SafeDownCast(fiberPolyData->GetCellData()->GetArray(
"FIBER_WEIGHTS"));
140 fiberBundle->SetFiberWeights(weights);
143 vtkSmartPointer<vtkUnsignedCharArray> fiberColors = vtkUnsignedCharArray::SafeDownCast(fiberPolyData->GetPointData()->GetArray(
"FIBER_COLORS"));
144 if (fiberColors!=NULL)
145 fiberBundle->SetFiberColors(fiberColors);
147 result.push_back(fiberBundle.GetPointer());
161 MITK_INFO <<
"Trying to load fiber file as deprecated XML format.";
165 TiXmlDocument doc( this->GetInputLocation().c_str() );
168 TiXmlHandle hDoc(&doc);
170 TiXmlHandle hRoot(0);
171 pElem = hDoc.FirstChildElement().Element();
173 hRoot = TiXmlHandle(pElem);
174 pElem = hRoot.FirstChildElement(
"geometry").Element();
180 pElem->Attribute(
"origin_x", &temp);
182 pElem->Attribute(
"origin_y", &temp);
184 pElem->Attribute(
"origin_z", &temp);
186 geometry->SetOrigin(origin);
189 pElem->Attribute(
"spacing_x", &temp);
191 pElem->Attribute(
"spacing_y", &temp);
193 pElem->Attribute(
"spacing_z", &temp);
195 geometry->SetSpacing(spacing);
198 pElem->Attribute(
"xx", &temp);
199 m->SetElement(0,0,temp);
200 pElem->Attribute(
"xy", &temp);
201 m->SetElement(1,0,temp);
202 pElem->Attribute(
"xz", &temp);
203 m->SetElement(2,0,temp);
204 pElem->Attribute(
"yx", &temp);
205 m->SetElement(0,1,temp);
206 pElem->Attribute(
"yy", &temp);
207 m->SetElement(1,1,temp);
208 pElem->Attribute(
"yz", &temp);
209 m->SetElement(2,1,temp);
210 pElem->Attribute(
"zx", &temp);
211 m->SetElement(0,2,temp);
212 pElem->Attribute(
"zy", &temp);
213 m->SetElement(1,2,temp);
214 pElem->Attribute(
"zz", &temp);
215 m->SetElement(2,2,temp);
216 m->SetElement(0,3,origin[0]);
217 m->SetElement(1,3,origin[1]);
218 m->SetElement(2,3,origin[2]);
219 m->SetElement(3,3,1);
220 geometry->SetIndexToWorldTransformByVtkMatrix(m);
222 float bounds[] = {0, 0, 0, 0, 0, 0};
223 pElem->Attribute(
"size_x", &temp);
225 pElem->Attribute(
"size_y", &temp);
227 pElem->Attribute(
"size_z", &temp);
229 geometry->SetFloatBounds(bounds);
230 geometry->SetImageGeometry(
true);
231 pElem = hRoot.FirstChildElement(
"fiber_bundle").FirstChild().Element();
232 for( ; pElem ; pElem=pElem->NextSiblingElement())
234 TiXmlElement* pElem2 = pElem->FirstChildElement();
236 for( ; pElem2; pElem2=pElem2->NextSiblingElement())
239 pElem2->Attribute(
"pos_x", &temp);
241 pElem2->Attribute(
"pos_y", &temp);
243 pElem2->Attribute(
"pos_z", &temp);
245 geometry->IndexToWorld(point, point);
246 vtkIdType
id = points->InsertNextPoint(point.GetDataPointer());
247 container->GetPointIds()->InsertNextId(
id);
249 cellArray->InsertNextCell(container);
251 fiberPolyData->SetPoints(points);
252 fiberPolyData->SetLines(cellArray);
254 cleaner->SetInputData(fiberPolyData);
256 fiberPolyData = cleaner->GetOutput();
258 result.push_back(image.GetPointer());
263 MITK_INFO <<
"File is not deprectaed XML format.";
266 setlocale(LC_ALL, currLocale.c_str());
274 throw "Selected file is no vtk readable fiber format (binary or ascii vtk or vtp file).";
DataCollection - Class to facilitate loading/accessing structured data.
us::ServiceRegistration< IFileReader > RegisterService(us::ModuleContext *context=us::GetModuleContext())
static const std::string filename
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
Base class for creating mitk::BaseData objects from files or streams.
virtual FiberBundleVtkReader * Clone() const override
virtual std::vector< itk::SmartPointer< BaseData > > Read() override
Reads a path or stream and creates a list of BaseData objects.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.