20 #include "itksys/SystemTools.hxx"
21 #include <vtkMatrix4x4.h>
46 std::vector<itk::SmartPointer<mitk::BaseData> > result;
49 std::string ext = itksys::SystemTools::GetFilenameLastExtension(location);
50 ext = itksys::SystemTools::LowerCase(ext);
56 else if (ext ==
".cnf")
62 TiXmlDocument doc( location );
63 bool loadOkay = doc.LoadFile();
66 mitkThrow() <<
"Could not open file " << location <<
" for reading.";
69 TiXmlHandle hDoc(&doc);
73 pElem = hDoc.FirstChildElement().Element();
76 hRoot = TiXmlHandle(pElem);
79 std::string version(
"");
96 geometry->SetOrigin(origin);
106 geometry->SetSpacing(spacing);
111 m->SetElement(0,0,temp);
113 m->SetElement(1,0,temp);
115 m->SetElement(2,0,temp);
117 m->SetElement(0,1,temp);
119 m->SetElement(1,1,temp);
121 m->SetElement(2,1,temp);
123 m->SetElement(0,2,temp);
125 m->SetElement(1,2,temp);
127 m->SetElement(2,2,temp);
129 m->SetElement(0,3,origin[0]);
130 m->SetElement(1,3,origin[1]);
131 m->SetElement(2,3,origin[2]);
132 m->SetElement(3,3,1);
133 geometry->SetIndexToWorldTransformByVtkMatrix(m);
135 geometry->SetImageGeometry(
true);
136 outputNetwork->SetGeometry(geometry);
139 std::map< int, mitk::ConnectomicsNetwork::VertexDescriptorType > idToVertexMap;
144 TiXmlElement* vertexElement = pElem->FirstChildElement();
146 for( ; vertexElement; vertexElement=vertexElement->NextSiblingElement())
148 std::vector< float > pos;
162 outputNetwork->SetLabel( newVertex, label );
163 outputNetwork->SetCoordinates( newVertex, pos );
165 if ( idToVertexMap.count( vertexID ) > 0 )
167 MITK_ERROR <<
"Aborting network creation, duplicate vertex ID in file.";
170 idToVertexMap.insert( std::pair< int, mitk::ConnectomicsNetwork::VertexDescriptorType >( vertexID, newVertex) );
178 TiXmlElement* edgeElement = pElem->FirstChildElement();
180 for( ; edgeElement; edgeElement=edgeElement->NextSiblingElement())
182 int edgeID(0), edgeSourceID(0), edgeTargetID(0), edgeWeight(0);
183 double edgeDoubleWeight(0.0);
192 edgeDoubleWeight = 1.0;
201 outputNetwork->AddEdge( source, target, edgeSourceID, edgeTargetID, edgeWeight, edgeDoubleWeight);
205 outputNetwork->UpdateBounds();
206 result.push_back(outputNetwork.GetPointer());
215 MITK_ERROR <<
"Unknown error occured while trying to read file.";
static const char * XML_EDGES
static const char * XML_MATRIX_ZX
static const char * XML_MATRIX_ZY
static const char * XML_MATRIX_XX
static const char * XML_EDGE_DOUBLE_WEIGHT_ID
DataCollection - Class to facilitate loading/accessing structured data.
static const char * XML_MATRIX_YY
static const char * XML_ORIGIN_X
static const char * XML_MATRIX_XZ
static const char * XML_VERTEX_Z
static const char * XML_MATRIX_ZZ
static const char * XML_VERTEX_ID
static const char * XML_VERTEX_X
static const char * XML_ORIGIN_Y
The reader for connectomics network files (.cnf)
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
static const char * XML_VERTEX_LABEL
static const char * XML_FILE_VERSION
us::ServiceRegistration< IFileReader > RegisterService(us::ModuleContext *context=us::GetModuleContext())
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
static const char * XML_EDGE_TARGET_ID
static const char * XML_VERTICES
ConnectomicsNetworkReader()
static const char * XML_MATRIX_YX
boost::graph_traits< NetworkType >::vertex_descriptor VertexDescriptorType
virtual ~ConnectomicsNetworkReader()
static const char * XML_MATRIX_YZ
static const char * XML_VERTEX_Y
static const char * XML_GEOMETRY
static const char * XML_SPACING_Y
static const char * XML_SPACING_X
static const char * XML_EDGE_WEIGHT_ID
Base class for creating mitk::BaseData objects from files or streams.
static const char * XML_EDGE_ID
static const char * XML_ORIGIN_Z
static const char * XML_SPACING_Z
virtual std::string GetInputLocation() const override
Get the current input location.
static const char * XML_EDGE_SOURCE_ID
static const char * XML_MATRIX_XY
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.