diff --git a/Modules/DiffusionImaging/DiffusionIO/files.cmake b/Modules/DiffusionImaging/DiffusionIO/files.cmake index 799fea6ad8..92e14187be 100644 --- a/Modules/DiffusionImaging/DiffusionIO/files.cmake +++ b/Modules/DiffusionImaging/DiffusionIO/files.cmake @@ -1,42 +1,40 @@ set(CPP_FILES mitkDiffusionModuleActivator.cpp mitkNrrdTbssImageWriterFactory.cpp #mitkFiberBundleXIOFactory.cpp - mitkConnectomicsNetworkIOFactory.cpp mitkConnectomicsNetworkReader.cpp mitkConnectomicsNetworkWriter.cpp mitkConnectomicsNetworkSerializer.cpp mitkConnectomicsNetworkDefinitions.cpp mitkNrrdTbssRoiImageIOFactory.cpp #mitkFiberBundleXWriterFactory.cpp - mitkConnectomicsNetworkWriterFactory.cpp mitkNrrdTbssRoiImageWriterFactory.cpp mitkNrrdTensorImageReader.cpp mitkNrrdTensorImageWriter.cpp mitkTensorImageSerializer.cpp mitkTensorImageSource.cpp mitkFiberTrackingObjectFactory.cpp mitkConnectomicsObjectFactory.cpp mitkQuantificationObjectFactory.cpp mitkNrrdTbssImageIOFactory.cpp mitkDiffusionCoreObjectFactory.cpp mitkDiffusionIOMimeTypes.cpp mitkNrrdDiffusionImageReader.cpp # mitkNrrdDiffusionImageIOFactory.cpp mitkNrrdDiffusionImageWriterFactory.cpp mitkDiffusionImageSerializer.cpp mitkNrrdQBallImageReader.cpp mitkNrrdQBallImageWriter.cpp mitkQBallImageSerializer.cpp mitkFiberBundleXReader.cpp mitkFiberBundleXWriter.cpp mitkFiberBundleXSerializer.cpp mitkFiberBundleXMapper2D.cpp mitkFiberBundleXMapper3D.cpp mitkCompositeMapper.cpp ) diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkIOFactory.cpp b/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkIOFactory.cpp deleted file mode 100644 index 98c49d5b01..0000000000 --- a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkIOFactory.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -#include "mitkConnectomicsNetworkIOFactory.h" -#include "mitkIOAdapter.h" -#include "mitkConnectomicsNetworkReader.h" - -#include "itkVersion.h" - - -namespace mitk -{ - -ConnectomicsNetworkIOFactory::ConnectomicsNetworkIOFactory() -{ - typedef ConnectomicsNetworkReader ConnectomicsNetworkReaderType; - this->RegisterOverride("mitkIOAdapter", //beibehalten - "mitkConnectomicsNetworkReader", //umbenennen - "Connectomics Network IO", //angezeigter name - 1, - itk::CreateObjectFunction >::New()); -} - -ConnectomicsNetworkIOFactory::~ConnectomicsNetworkIOFactory() -{ -} - -const char* ConnectomicsNetworkIOFactory::GetITKSourceVersion() const -{ - return ITK_SOURCE_VERSION; -} - -const char* ConnectomicsNetworkIOFactory::GetDescription() const -{ - return "ConnectomicsNetworkIOFactory, allows the loading of Connectomics Networks"; -} - -} // end namespace mitk diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkIOFactory.h b/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkIOFactory.h deleted file mode 100644 index 89476ea29f..0000000000 --- a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkIOFactory.h +++ /dev/null @@ -1,63 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ -#ifndef __MITK_CONNECTOMICS_NETWORK_IO_FACTORY_H_HEADER__ -#define __MITK_CONNECTOMICS_NETWORK_IO_FACTORY_H_HEADER__ - -#ifdef _MSC_VER -#pragma warning ( disable : 4786 ) -#endif - -#include "itkObjectFactoryBase.h" -#include "mitkBaseData.h" - -namespace mitk -{ - /** - * \brief Create instances of ConnectomicsNetwork objects using an object factory. - */ -class ConnectomicsNetworkIOFactory : public itk::ObjectFactoryBase -{ -public: - /** Standard class typedefs. */ - typedef ConnectomicsNetworkIOFactory Self; - typedef itk::ObjectFactoryBase Superclass; - typedef itk::SmartPointer Pointer; - typedef itk::SmartPointer ConstPointer; - - /** Class methods used to interface with the registered factories. */ - virtual const char* GetITKSourceVersion(void) const; - virtual const char* GetDescription(void) const; - - /** Method for class instantiation. */ - itkFactorylessNewMacro(Self); - static ConnectomicsNetworkIOFactory* FactoryNew() { return new ConnectomicsNetworkIOFactory;} - /** Run-time type information (and related methods). */ - itkTypeMacro(ConnectomicsNetworkIOFactory, ObjectFactoryBase); - -protected: - ConnectomicsNetworkIOFactory(); - ~ConnectomicsNetworkIOFactory(); - -private: - ConnectomicsNetworkIOFactory(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - -}; - - -} // end namespace mitk - -#endif // __MITK_CONNECTOMICS_NETWORK_IO_FACTORY_H_HEADER__ diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkReader.cpp b/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkReader.cpp index ac302f1fee..8b1465d9d2 100644 --- a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkReader.cpp +++ b/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkReader.cpp @@ -1,276 +1,214 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkConnectomicsNetworkReader.h" #include "mitkConnectomicsNetworkDefinitions.h" #include #include "itksys/SystemTools.hxx" #include #include "mitkGeometry3D.h" +#include +#include "mitkDiffusionIOMimeTypes.h" -void mitk::ConnectomicsNetworkReader::GenerateData() +namespace mitk { - MITK_INFO << "Reading connectomics network"; - if ( ( ! m_OutputCache ) ) + + ConnectomicsNetworkReader::ConnectomicsNetworkReader(const ConnectomicsNetworkReader& other) + : mitk::AbstractFileReader(other) { - Superclass::SetNumberOfRequiredOutputs(0); - this->GenerateOutputInformation(); } - if (!m_OutputCache) + ConnectomicsNetworkReader::ConnectomicsNetworkReader() + : mitk::AbstractFileReader( CustomMimeType( mitk::DiffusionIOMimeTypes::CONNECTOMICS_MIMETYPE_NAME() ), mitk::DiffusionIOMimeTypes::CONNECTOMICS_MIMETYPE_DESCRIPTION ) { - itkWarningMacro("Tree cache is empty!"); + m_ServiceReg = this->RegisterService(); } - - Superclass::SetNumberOfRequiredOutputs(1); - Superclass::SetNthOutput(0, m_OutputCache.GetPointer()); -} - -void mitk::ConnectomicsNetworkReader::GenerateOutputInformation() -{ - m_OutputCache = OutputType::New(); - - std::string ext = itksys::SystemTools::GetFilenameLastExtension(m_FileName); - ext = itksys::SystemTools::LowerCase(ext); - - if ( m_FileName == "") + ConnectomicsNetworkReader::~ConnectomicsNetworkReader() { - MITK_ERROR << "No file name specified."; } - else if (ext == ".cnf") + + std::vector > ConnectomicsNetworkReader::Read() { - try + std::vector > result; + std::string location = GetInputLocation(); + + std::string ext = itksys::SystemTools::GetFilenameLastExtension(location); + ext = itksys::SystemTools::LowerCase(ext); + + if ( location == "") { - TiXmlDocument doc( m_FileName ); - bool loadOkay = doc.LoadFile(); - if(!loadOkay) + MITK_ERROR << "No file name specified."; + } + else if (ext == ".cnf") + { + try { - mitkThrow() << "Could not open file " << m_FileName << " for reading."; - } + mitk::ConnectomicsNetwork::Pointer outputNetwork = mitk::ConnectomicsNetwork::New(); - TiXmlHandle hDoc(&doc); - TiXmlElement* pElem; - TiXmlHandle hRoot(0); - - pElem = hDoc.FirstChildElement().Element(); - - // save this for later - hRoot = TiXmlHandle(pElem); - - pElem = hRoot.FirstChildElement(mitk::ConnectomicsNetworkDefinitions::XML_GEOMETRY).Element(); - - // read geometry - mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New(); - - // read origin - mitk::Point3D origin; - double temp = 0; - pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_ORIGIN_X, &temp); - origin[0] = temp; - pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_ORIGIN_Y, &temp); - origin[1] = temp; - pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_ORIGIN_Z, &temp); - origin[2] = temp; - geometry->SetOrigin(origin); - - // read spacing - ScalarType spacing[3]; - pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_SPACING_X, &temp); - spacing[0] = temp; - pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_SPACING_Y, &temp); - spacing[1] = temp; - pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_SPACING_Z, &temp); - spacing[2] = temp; - geometry->SetSpacing(spacing); - - // read transform - vtkMatrix4x4* m = vtkMatrix4x4::New(); - pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_XX, &temp); - m->SetElement(0,0,temp); - pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_XY, &temp); - m->SetElement(1,0,temp); - pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_XZ, &temp); - m->SetElement(2,0,temp); - pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_YX, &temp); - m->SetElement(0,1,temp); - pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_YY, &temp); - m->SetElement(1,1,temp); - pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_YZ, &temp); - m->SetElement(2,1,temp); - pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_ZX, &temp); - m->SetElement(0,2,temp); - pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_ZY, &temp); - m->SetElement(1,2,temp); - pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_ZZ, &temp); - m->SetElement(2,2,temp); - - m->SetElement(0,3,origin[0]); - m->SetElement(1,3,origin[1]); - m->SetElement(2,3,origin[2]); - m->SetElement(3,3,1); - geometry->SetIndexToWorldTransformByVtkMatrix(m); - - geometry->SetImageGeometry(true); - m_OutputCache->SetGeometry(geometry); - - // read network - std::map< int, mitk::ConnectomicsNetwork::VertexDescriptorType > idToVertexMap; - // read vertices - pElem = hRoot.FirstChildElement(mitk::ConnectomicsNetworkDefinitions::XML_VERTICES).Element(); - { - // walk through the vertices - TiXmlElement* vertexElement = pElem->FirstChildElement(); + TiXmlDocument doc( location ); + bool loadOkay = doc.LoadFile(); + if(!loadOkay) + { + mitkThrow() << "Could not open file " << location << " for reading."; + } - for( ; vertexElement; vertexElement=vertexElement->NextSiblingElement()) + TiXmlHandle hDoc(&doc); + TiXmlElement* pElem; + TiXmlHandle hRoot(0); + + pElem = hDoc.FirstChildElement().Element(); + + // save this for later + hRoot = TiXmlHandle(pElem); + + pElem = hRoot.FirstChildElement(mitk::ConnectomicsNetworkDefinitions::XML_GEOMETRY).Element(); + + // read geometry + mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New(); + + // read origin + mitk::Point3D origin; + double temp = 0; + pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_ORIGIN_X, &temp); + origin[0] = temp; + pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_ORIGIN_Y, &temp); + origin[1] = temp; + pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_ORIGIN_Z, &temp); + origin[2] = temp; + geometry->SetOrigin(origin); + + // read spacing + ScalarType spacing[3]; + pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_SPACING_X, &temp); + spacing[0] = temp; + pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_SPACING_Y, &temp); + spacing[1] = temp; + pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_SPACING_Z, &temp); + spacing[2] = temp; + geometry->SetSpacing(spacing); + + // read transform + vtkMatrix4x4* m = vtkMatrix4x4::New(); + pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_XX, &temp); + m->SetElement(0,0,temp); + pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_XY, &temp); + m->SetElement(1,0,temp); + pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_XZ, &temp); + m->SetElement(2,0,temp); + pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_YX, &temp); + m->SetElement(0,1,temp); + pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_YY, &temp); + m->SetElement(1,1,temp); + pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_YZ, &temp); + m->SetElement(2,1,temp); + pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_ZX, &temp); + m->SetElement(0,2,temp); + pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_ZY, &temp); + m->SetElement(1,2,temp); + pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_ZZ, &temp); + m->SetElement(2,2,temp); + + m->SetElement(0,3,origin[0]); + m->SetElement(1,3,origin[1]); + m->SetElement(2,3,origin[2]); + m->SetElement(3,3,1); + geometry->SetIndexToWorldTransformByVtkMatrix(m); + + geometry->SetImageGeometry(true); + outputNetwork->SetGeometry(geometry); + + // read network + std::map< int, mitk::ConnectomicsNetwork::VertexDescriptorType > idToVertexMap; + // read vertices + pElem = hRoot.FirstChildElement(mitk::ConnectomicsNetworkDefinitions::XML_VERTICES).Element(); { - std::vector< float > pos; - std::string label; - int vertexID(0); - - vertexElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_X, &temp); - pos.push_back(temp); - vertexElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_Y, &temp); - pos.push_back(temp); - vertexElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_Z, &temp); - pos.push_back(temp); - vertexElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_ID, &vertexID); - vertexElement->QueryStringAttribute(mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_LABEL, &label); - - mitk::ConnectomicsNetwork::VertexDescriptorType newVertex = m_OutputCache->AddVertex( vertexID ); - m_OutputCache->SetLabel( newVertex, label ); - m_OutputCache->SetCoordinates( newVertex, pos ); - - if ( idToVertexMap.count( vertexID ) > 0 ) + // walk through the vertices + TiXmlElement* vertexElement = pElem->FirstChildElement(); + + for( ; vertexElement; vertexElement=vertexElement->NextSiblingElement()) { - MITK_ERROR << "Aborting network creation, duplicate vertex ID in file."; - return; + std::vector< float > pos; + std::string label; + int vertexID(0); + + vertexElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_X, &temp); + pos.push_back(temp); + vertexElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_Y, &temp); + pos.push_back(temp); + vertexElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_Z, &temp); + pos.push_back(temp); + vertexElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_ID, &vertexID); + vertexElement->QueryStringAttribute(mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_LABEL, &label); + + mitk::ConnectomicsNetwork::VertexDescriptorType newVertex = outputNetwork->AddVertex( vertexID ); + outputNetwork->SetLabel( newVertex, label ); + outputNetwork->SetCoordinates( newVertex, pos ); + + if ( idToVertexMap.count( vertexID ) > 0 ) + { + MITK_ERROR << "Aborting network creation, duplicate vertex ID in file."; + return result; + } + idToVertexMap.insert( std::pair< int, mitk::ConnectomicsNetwork::VertexDescriptorType >( vertexID, newVertex) ); } - idToVertexMap.insert( std::pair< int, mitk::ConnectomicsNetwork::VertexDescriptorType >( vertexID, newVertex) ); } - } - // read edges - pElem = hRoot.FirstChildElement(mitk::ConnectomicsNetworkDefinitions::XML_EDGES).Element(); - { - // walk through the edges - TiXmlElement* edgeElement = pElem->FirstChildElement(); - - for( ; edgeElement; edgeElement=edgeElement->NextSiblingElement()) + // read edges + pElem = hRoot.FirstChildElement(mitk::ConnectomicsNetworkDefinitions::XML_EDGES).Element(); { - int edgeID(0), edgeSourceID(0), edgeTargetID(0), edgeWeight(0); + // walk through the edges + TiXmlElement* edgeElement = pElem->FirstChildElement(); + + for( ; edgeElement; edgeElement=edgeElement->NextSiblingElement()) + { + int edgeID(0), edgeSourceID(0), edgeTargetID(0), edgeWeight(0); - edgeElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_EDGE_ID, &edgeID); - edgeElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_EDGE_SOURCE_ID, &edgeSourceID); - edgeElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_EDGE_TARGET_ID, &edgeTargetID); - edgeElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_EDGE_WEIGHT_ID, &edgeWeight); + edgeElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_EDGE_ID, &edgeID); + edgeElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_EDGE_SOURCE_ID, &edgeSourceID); + edgeElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_EDGE_TARGET_ID, &edgeTargetID); + edgeElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_EDGE_WEIGHT_ID, &edgeWeight); - mitk::ConnectomicsNetwork::VertexDescriptorType source = idToVertexMap.find( edgeSourceID )->second; - mitk::ConnectomicsNetwork::VertexDescriptorType target = idToVertexMap.find( edgeTargetID )->second; - m_OutputCache->AddEdge( source, target, edgeSourceID, edgeTargetID, edgeWeight); + mitk::ConnectomicsNetwork::VertexDescriptorType source = idToVertexMap.find( edgeSourceID )->second; + mitk::ConnectomicsNetwork::VertexDescriptorType target = idToVertexMap.find( edgeTargetID )->second; + outputNetwork->AddEdge( source, target, edgeSourceID, edgeTargetID, edgeWeight); + } } - } - m_OutputCache->UpdateBounds(); - MITK_INFO << "Network read"; - } - catch (mitk::Exception e) - { - MITK_ERROR << e.GetDescription(); - } - catch(...) - { - MITK_ERROR << "Unknown error occured while trying to read file."; + outputNetwork->UpdateBounds(); + result.push_back(outputNetwork.GetPointer()); + MITK_INFO << "Network read"; + } + catch (mitk::Exception e) + { + MITK_ERROR << e.GetDescription(); + } + catch(...) + { + MITK_ERROR << "Unknown error occured while trying to read file."; + } } - } -} -void mitk::ConnectomicsNetworkReader::Update() -{ - this->GenerateData(); -} - -const char* mitk::ConnectomicsNetworkReader::GetFileName() const -{ - return m_FileName.c_str(); -} - - -void mitk::ConnectomicsNetworkReader::SetFileName(const char* aFileName) -{ - m_FileName = aFileName; -} - - -const char* mitk::ConnectomicsNetworkReader::GetFilePrefix() const -{ - return m_FilePrefix.c_str(); -} - - -void mitk::ConnectomicsNetworkReader::SetFilePrefix(const char* aFilePrefix) -{ - m_FilePrefix = aFilePrefix; -} - - -const char* mitk::ConnectomicsNetworkReader::GetFilePattern() const -{ - return m_FilePattern.c_str(); -} - - -void mitk::ConnectomicsNetworkReader::SetFilePattern(const char* aFilePattern) -{ - m_FilePattern = aFilePattern; -} - - -bool mitk::ConnectomicsNetworkReader::CanReadFile( - const std::string filename, const std::string /*filePrefix*/, - const std::string /*filePattern*/) -{ - // First check the extension - if( filename == "" ) - { - return false; + return result; } - std::string ext = itksys::SystemTools::GetFilenameLastExtension(filename); - ext = itksys::SystemTools::LowerCase(ext); - if (ext == ".cnf") - { - return true; - } - return false; -} +} //namespace MITK -mitk::BaseDataSource::DataObjectPointer mitk::ConnectomicsNetworkReader::MakeOutput(const DataObjectIdentifierType &name) +mitk::ConnectomicsNetworkReader* mitk::ConnectomicsNetworkReader::Clone() const { - itkDebugMacro("MakeOutput(" << name << ")"); - if( this->IsIndexedOutputName(name) ) - { - return this->MakeOutput( this->MakeIndexFromOutputName(name) ); - } - return static_cast(OutputType::New().GetPointer()); + return new ConnectomicsNetworkReader(*this); } - -mitk::BaseDataSource::DataObjectPointer mitk::ConnectomicsNetworkReader::MakeOutput(DataObjectPointerArraySizeType /*idx*/) -{ - return OutputType::New().GetPointer(); -} - diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkReader.h b/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkReader.h index 00218ee23a..f8e550746c 100644 --- a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkReader.h +++ b/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkReader.h @@ -1,74 +1,53 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef __mitkConnectomicsNetworkReader_h #define __mitkConnectomicsNetworkReader_h #include "mitkCommon.h" -#include "mitkFileReader.h" +#include +#include +#include #include "mitkConnectomicsNetwork.h" namespace mitk { /** \brief The reader for connectomics network files (.cnf) */ - class ConnectomicsNetworkReader : public FileReader, public BaseDataSource + class ConnectomicsNetworkReader : public mitk::AbstractFileReader { public: - typedef mitk::ConnectomicsNetwork OutputType; - mitkClassMacro( ConnectomicsNetworkReader, BaseDataSource ); - itkFactorylessNewMacro(Self) - itkCloneMacro(Self) - - const char* GetFileName() const; - void SetFileName(const char* aFileName); - const char* GetFilePrefix() const; - void SetFilePrefix(const char* aFilePrefix); - const char* GetFilePattern() const; - void SetFilePattern(const char* aFilePattern); - - static bool CanReadFile(const std::string filename, const std::string filePrefix, const std::string filePattern); - - virtual void Update(); - - BaseDataSource::DataObjectPointer MakeOutput(const DataObjectIdentifierType &name); + ConnectomicsNetworkReader(const ConnectomicsNetworkReader& other); + ConnectomicsNetworkReader(); + virtual ~ConnectomicsNetworkReader(); - BaseDataSource::DataObjectPointer MakeOutput( DataObjectPointerArraySizeType idx); - - protected: - - /** Does the real work. */ - virtual void GenerateData(); - virtual void GenerateOutputInformation(); - - OutputType::Pointer m_OutputCache; - - std::string m_FileName; - std::string m_FilePrefix; - std::string m_FilePattern; + using AbstractFileReader::Read; + virtual std::vector > Read(); private: - void operator=(const Self&); //purposely not implemented + ConnectomicsNetworkReader* Clone() const; + + us::ServiceRegistration m_ServiceReg; }; } //namespace MITK #endif // __mitkConnectomicsNetworkReader_h diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkSerializer.cpp b/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkSerializer.cpp index c06d8f1b77..0a53f86f09 100644 --- a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkSerializer.cpp +++ b/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkSerializer.cpp @@ -1,74 +1,74 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkConnectomicsNetworkSerializer.h" #include "mitkConnectomicsNetwork.h" #include "mitkConnectomicsNetworkWriter.h" #include MITK_REGISTER_SERIALIZER(ConnectomicsNetworkSerializer) mitk::ConnectomicsNetworkSerializer::ConnectomicsNetworkSerializer() { } mitk::ConnectomicsNetworkSerializer::~ConnectomicsNetworkSerializer() { } std::string mitk::ConnectomicsNetworkSerializer::Serialize() { const ConnectomicsNetwork* conNet = dynamic_cast( m_Data.GetPointer() ); if (conNet == NULL) { MITK_ERROR << " Object at " << (const void*) this->m_Data << " is not an mitk::ConnectomicsNetwork. Cannot serialize as ConnectomicsNetwork."; return ""; } std::string filename( this->GetUniqueFilenameInWorkingDirectory() ); filename += "_"; filename += m_FilenameHint; filename += ".cnf"; std::string fullname(m_WorkingDirectory); fullname += "/"; fullname += itksys::SystemTools::ConvertToOutputPath(filename.c_str()); try { - ConnectomicsNetworkWriter::Pointer writer = ConnectomicsNetworkWriter::New(); - writer->SetFileName(fullname); - writer->SetInputConnectomicsNetwork(const_cast(conNet)); - writer->Write(); + ConnectomicsNetworkWriter writer; + writer.SetOutputLocation(fullname); + writer.SetInput(const_cast(conNet)); + writer.Write(); } catch (std::exception& e) { MITK_ERROR << " Error serializing object at " << (const void*) this->m_Data << " to " << fullname << ": " << e.what(); return ""; } return filename; } diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkWriter.cpp b/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkWriter.cpp index c082c6d90c..87dae9b2d3 100644 --- a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkWriter.cpp +++ b/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkWriter.cpp @@ -1,162 +1,136 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkConnectomicsNetworkWriter.h" #include "mitkConnectomicsNetworkDefinitions.h" #include #include "itksys/SystemTools.hxx" +#include "mitkDiffusionIOMimeTypes.h" mitk::ConnectomicsNetworkWriter::ConnectomicsNetworkWriter() -: m_FileName(""), m_FilePrefix(""), m_FilePattern(""), m_Success(false) + : AbstractFileWriter(mitk::ConnectomicsNetwork::GetStaticNameOfClass(), CustomMimeType( mitk::DiffusionIOMimeTypes::CONNECTOMICS_MIMETYPE_NAME() ), mitk::DiffusionIOMimeTypes::CONNECTOMICS_MIMETYPE_DESCRIPTION ) +{ + RegisterService(); +} + +mitk::ConnectomicsNetworkWriter::ConnectomicsNetworkWriter(const mitk::ConnectomicsNetworkWriter& other) + : AbstractFileWriter(other) { - this->SetNumberOfRequiredInputs( 1 ); } mitk::ConnectomicsNetworkWriter::~ConnectomicsNetworkWriter() {} +mitk::ConnectomicsNetworkWriter* mitk::ConnectomicsNetworkWriter::Clone() const +{ + return new ConnectomicsNetworkWriter(*this); +} -void mitk::ConnectomicsNetworkWriter::GenerateData() +void mitk::ConnectomicsNetworkWriter::Write() { MITK_INFO << "Writing connectomics network"; - m_Success = false; - InputType* input = this->GetInput(); - if (input == NULL) + InputType::ConstPointer input = dynamic_cast(this->GetInput()); + if (input.IsNull() ) { - itkWarningMacro(<<"Sorry, input to ConnectomicsNetworkWriter is NULL!"); + MITK_ERROR <<"Sorry, input to ConnectomicsNetworkWriter is NULL!"; return; } - if ( m_FileName == "" ) + if ( this->GetOutputLocation().c_str() == "" ) { - itkWarningMacro( << "Sorry, filename has not been set!" ); + MITK_ERROR << "Sorry, filename has not been set!" ; return ; } - std::string ext = itksys::SystemTools::GetFilenameLastExtension(m_FileName); + std::string ext = itksys::SystemTools::GetFilenameLastExtension(this->GetOutputLocation()); ext = itksys::SystemTools::LowerCase(ext); if (ext == ".cnf") { // Get geometry of the network mitk::BaseGeometry* geometry = input->GetGeometry(); // Create XML document TiXmlDocument documentXML; { // begin document TiXmlDeclaration* declXML = new TiXmlDeclaration( "1.0", "", "" ); // TODO what to write here? encoding? etc.... documentXML.LinkEndChild( declXML ); TiXmlElement* mainXML = new TiXmlElement(mitk::ConnectomicsNetworkDefinitions::XML_CONNECTOMICS_FILE); mainXML->SetAttribute(mitk::ConnectomicsNetworkDefinitions::XML_FILE_VERSION, mitk::ConnectomicsNetworkDefinitions::VERSION_STRING); documentXML.LinkEndChild(mainXML); TiXmlElement* geometryXML = new TiXmlElement(mitk::ConnectomicsNetworkDefinitions::XML_GEOMETRY); { // begin geometry geometryXML->SetDoubleAttribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_XX, geometry->GetMatrixColumn(0)[0]); geometryXML->SetDoubleAttribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_XY, geometry->GetMatrixColumn(0)[1]); geometryXML->SetDoubleAttribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_XZ, geometry->GetMatrixColumn(0)[2]); geometryXML->SetDoubleAttribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_YX, geometry->GetMatrixColumn(1)[0]); geometryXML->SetDoubleAttribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_YY, geometry->GetMatrixColumn(1)[1]); geometryXML->SetDoubleAttribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_YZ, geometry->GetMatrixColumn(1)[2]); geometryXML->SetDoubleAttribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_ZX, geometry->GetMatrixColumn(2)[0]); geometryXML->SetDoubleAttribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_ZY, geometry->GetMatrixColumn(2)[1]); geometryXML->SetDoubleAttribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_ZZ, geometry->GetMatrixColumn(2)[2]); geometryXML->SetDoubleAttribute(mitk::ConnectomicsNetworkDefinitions::XML_ORIGIN_X, geometry->GetOrigin()[0]); geometryXML->SetDoubleAttribute(mitk::ConnectomicsNetworkDefinitions::XML_ORIGIN_Y, geometry->GetOrigin()[1]); geometryXML->SetDoubleAttribute(mitk::ConnectomicsNetworkDefinitions::XML_ORIGIN_Z, geometry->GetOrigin()[2]); geometryXML->SetDoubleAttribute(mitk::ConnectomicsNetworkDefinitions::XML_SPACING_X, geometry->GetSpacing()[0]); geometryXML->SetDoubleAttribute(mitk::ConnectomicsNetworkDefinitions::XML_SPACING_Y, geometry->GetSpacing()[1]); geometryXML->SetDoubleAttribute(mitk::ConnectomicsNetworkDefinitions::XML_SPACING_Z, geometry->GetSpacing()[2]); } // end geometry mainXML->LinkEndChild(geometryXML); TiXmlElement* verticesXML = new TiXmlElement(mitk::ConnectomicsNetworkDefinitions::XML_VERTICES); { // begin vertices section - VertexVectorType vertexVector = this->GetInput()->GetVectorOfAllNodes(); + VertexVectorType vertexVector = dynamic_cast(this->GetInput())->GetVectorOfAllNodes(); for( unsigned int index = 0; index < vertexVector.size(); index++ ) { // not localized as of yet TODO TiXmlElement* vertexXML = new TiXmlElement(mitk::ConnectomicsNetworkDefinitions::XML_VERTEX ); vertexXML->SetAttribute( mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_ID , vertexVector[ index ].id ); vertexXML->SetAttribute( mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_LABEL , vertexVector[ index ].label ); vertexXML->SetDoubleAttribute( mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_X , vertexVector[ index ].coordinates[0] ); vertexXML->SetDoubleAttribute( mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_Y , vertexVector[ index ].coordinates[1] ); vertexXML->SetDoubleAttribute( mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_Z , vertexVector[ index ].coordinates[2] ); verticesXML->LinkEndChild(vertexXML); } } // end vertices section mainXML->LinkEndChild(verticesXML); TiXmlElement* edgesXML = new TiXmlElement(mitk::ConnectomicsNetworkDefinitions::XML_EDGES); { // begin edges section - EdgeVectorType edgeVector = this->GetInput()->GetVectorOfAllEdges(); + EdgeVectorType edgeVector = dynamic_cast(this->GetInput())->GetVectorOfAllEdges(); for(unsigned int index = 0; index < edgeVector.size(); index++ ) { TiXmlElement* edgeXML = new TiXmlElement(mitk::ConnectomicsNetworkDefinitions::XML_EDGE ); edgeXML->SetAttribute( mitk::ConnectomicsNetworkDefinitions::XML_EDGE_ID , index ); edgeXML->SetAttribute( mitk::ConnectomicsNetworkDefinitions::XML_EDGE_SOURCE_ID , edgeVector[ index ].second.sourceId ); edgeXML->SetAttribute( mitk::ConnectomicsNetworkDefinitions::XML_EDGE_TARGET_ID , edgeVector[ index ].second.targetId ); edgeXML->SetAttribute( mitk::ConnectomicsNetworkDefinitions::XML_EDGE_WEIGHT_ID , edgeVector[ index ].second.weight ); edgesXML->LinkEndChild(edgeXML); } } // end edges section mainXML->LinkEndChild(edgesXML); } // end document - documentXML.SaveFile( m_FileName ); - - m_Success = true; - + documentXML.SaveFile( this->GetOutputLocation().c_str() ); MITK_INFO << "Connectomics network written"; } } - - -void mitk::ConnectomicsNetworkWriter::SetInputConnectomicsNetwork( InputType* conNetwork ) -{ - this->ProcessObject::SetNthInput( 0, conNetwork ); -} - - -mitk::ConnectomicsNetwork* mitk::ConnectomicsNetworkWriter::GetInput() -{ - if ( this->GetNumberOfInputs() < 1 ) - { - return NULL; - } - else - { - return dynamic_cast ( this->ProcessObject::GetInput( 0 ) ); - } -} - - -std::vector mitk::ConnectomicsNetworkWriter::GetPossibleFileExtensions() -{ - std::vector possibleFileExtensions; - possibleFileExtensions.push_back(".cnf"); - return possibleFileExtensions; -} - -std::string mitk::ConnectomicsNetworkWriter::GetSupportedBaseData() const -{ - return InputType::GetStaticNameOfClass(); -} diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkWriter.h b/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkWriter.h index 2116f19aff..74cbf74258 100644 --- a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkWriter.h +++ b/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkWriter.h @@ -1,159 +1,57 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef __mitkConnectomicsNetworkWriter_h #define __mitkConnectomicsNetworkWriter_h -#include -#include +#include #include "mitkConnectomicsNetwork.h" #include namespace mitk { /** * Writes connectomics networks to a file * @ingroup Process */ - class ConnectomicsNetworkWriter : public mitk::FileWriterWithInformation + class ConnectomicsNetworkWriter : public mitk::AbstractFileWriter { public: - - mitkClassMacro( ConnectomicsNetworkWriter, mitk::FileWriterWithInformation ); - - //mitkWriterMacro; - - virtual void Write() - { - if ( this->GetInput() == NULL ) - { - itkExceptionMacro(<<"Write:Please specify an input!"); - return; - } - /* Fill in image information.*/ - this->UpdateOutputInformation(); - (*(this->GetInputs().begin()))->SetRequestedRegionToLargestPossibleRegion(); - this->PropagateRequestedRegion(NULL); - this->UpdateOutputData(NULL); - } - - virtual void Update() - { - Write(); - } - - itkFactorylessNewMacro(Self) - itkCloneMacro(Self) - typedef mitk::ConnectomicsNetwork InputType; typedef std::vector< std::pair< std::pair< mitk::ConnectomicsNetwork::NetworkNode, mitk::ConnectomicsNetwork::NetworkNode > , mitk::ConnectomicsNetwork::NetworkEdge > > EdgeVectorType; typedef std::vector< mitk::ConnectomicsNetwork::NetworkNode > VertexVectorType; - /** - * Sets the filename of the file to write. - * @param _arg the name of the file to write. - */ - itkSetStringMacro( FileName ); - - /** - * @returns the name of the file to be written to disk. - */ - itkGetStringMacro( FileName ); - - /** - * @warning multiple write not (yet) supported - */ - itkSetStringMacro( FilePrefix ); - - /** - * @warning multiple write not (yet) supported - */ - itkGetStringMacro( FilePrefix ); - - /** - * @warning multiple write not (yet) supported - */ - itkSetStringMacro( FilePattern ); - - /** - * @warning multiple write not (yet) supported - */ - itkGetStringMacro( FilePattern ); - - /** - * Sets the input object for the filter. - * @param input the diffusion volumes to write to file. - */ - void SetInputConnectomicsNetwork( InputType* input ); - - /** - * @returns the 0'th input object of the filter. - */ - InputType* GetInput(); - - /** - * Returns false if an error happened during writing - */ - itkGetMacro( Success, bool ); - - /** - * @return possible file extensions for the data type associated with the writer - */ - virtual std::vector GetPossibleFileExtensions(); - - std::string GetSupportedBaseData() const; - - // FileWriterWithInformation methods - virtual const char * GetDefaultFilename() { return "ConnectomicsNetwork.cnf"; } - virtual const char * GetFileDialogPattern() { return "ConnectomicsNetwork (*.cnf)"; } - virtual const char * GetDefaultExtension() { return ".cnf"; } - virtual bool CanWriteBaseDataType(BaseData::Pointer data) { - return (dynamic_cast(data.GetPointer()) != NULL); } - - virtual void DoWrite(BaseData::Pointer data) { - if (CanWriteBaseDataType(data)) { - this->SetInputConnectomicsNetwork(dynamic_cast(data.GetPointer())); - this->Update(); - } - } - - - protected: - ConnectomicsNetworkWriter(); - virtual ~ConnectomicsNetworkWriter(); - virtual void GenerateData(); + using AbstractFileWriter::Write; + virtual void Write(); - std::string m_FileName; - - std::string m_FilePrefix; - - std::string m_FilePattern; + protected: - bool m_Success; + ConnectomicsNetworkWriter(const ConnectomicsNetworkWriter& other); + virtual mitk::ConnectomicsNetworkWriter* Clone() const; }; } // end of namespace mitk #endif //__mitkConnectomicsNetworkWriter_h diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkWriterFactory.cpp b/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkWriterFactory.cpp deleted file mode 100644 index 279a379bf3..0000000000 --- a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkWriterFactory.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -#include "mitkConnectomicsNetworkWriterFactory.h" - -#include "itkCreateObjectFunction.h" -#include "itkVersion.h" - -#include "mitkConnectomicsNetworkWriter.h" - -namespace mitk -{ - -template -class CreateConnectomicsNetworkWriter : public itk::CreateObjectFunctionBase -{ -public: - - /** Standard class typedefs. */ - typedef CreateConnectomicsNetworkWriter Self; - typedef itk::SmartPointer Pointer; - - /** Methods from itk:LightObject. */ - itkFactorylessNewMacro(Self); - LightObject::Pointer CreateObject() { typename T::Pointer p = T::New(); - p->Register(); - return p.GetPointer(); - } - -protected: - CreateConnectomicsNetworkWriter() {} - ~CreateConnectomicsNetworkWriter() {} - -private: - CreateConnectomicsNetworkWriter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented -}; - -ConnectomicsNetworkWriterFactory::ConnectomicsNetworkWriterFactory() -{ - this->RegisterOverride("IOWriter", - "ConnectomicsNetworkWriter", - "ConnectomicsNetwork Writer", - 1, - mitk::CreateConnectomicsNetworkWriter< mitk::ConnectomicsNetworkWriter >::New()); -} - -ConnectomicsNetworkWriterFactory::~ConnectomicsNetworkWriterFactory() -{ -} - -const char* ConnectomicsNetworkWriterFactory::GetITKSourceVersion() const -{ - return ITK_SOURCE_VERSION; -} - -const char* ConnectomicsNetworkWriterFactory::GetDescription() const -{ - return "ConnectomicsNetworkWriterFactory"; -} - -} // end namespace mitk diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkWriterFactory.h b/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkWriterFactory.h deleted file mode 100644 index 0662c7c957..0000000000 --- a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsNetworkWriterFactory.h +++ /dev/null @@ -1,54 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -#ifndef ConnectomicsNetwork_WRITERFACTORY_H_HEADER_INCLUDED -#define ConnectomicsNetwork_WRITERFACTORY_H_HEADER_INCLUDED - -#include "itkObjectFactoryBase.h" -#include "mitkBaseData.h" - -namespace mitk -{ - -class ConnectomicsNetworkWriterFactory : public itk::ObjectFactoryBase -{ -public: - - mitkClassMacro( mitk::ConnectomicsNetworkWriterFactory, itk::ObjectFactoryBase ) - - /** Class methods used to interface with the registered factories. */ - virtual const char* GetITKSourceVersion(void) const; - virtual const char* GetDescription(void) const; - - /** Method for class instantiation. */ - itkFactorylessNewMacro(Self); - -protected: - ConnectomicsNetworkWriterFactory(); - ~ConnectomicsNetworkWriterFactory(); - -private: - ConnectomicsNetworkWriterFactory(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - -}; - -} // end namespace mitk - -#endif // ConnectomicsNetwork_WRITERFACTORY_H_HEADER_INCLUDED - - - diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsObjectFactory.cpp b/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsObjectFactory.cpp index 93b82a9b03..23918b4413 100644 --- a/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsObjectFactory.cpp +++ b/Modules/DiffusionImaging/DiffusionIO/mitkConnectomicsObjectFactory.cpp @@ -1,128 +1,110 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkConnectomicsObjectFactory.h" #include "mitkConnectomicsNetwork.h" -#include "mitkConnectomicsNetworkIOFactory.h" -#include "mitkConnectomicsNetworkWriter.h" -#include "mitkConnectomicsNetworkWriterFactory.h" #include "mitkConnectomicsNetworkMapper3D.h" mitk::ConnectomicsObjectFactory::ConnectomicsObjectFactory() : CoreObjectFactoryBase() - , m_ConnectomicsNetworkIOFactory(mitk::ConnectomicsNetworkIOFactory::New().GetPointer()) - , m_ConnectomicsNetworkWriterFactory(mitk::ConnectomicsNetworkWriterFactory::New().GetPointer()) { static bool alreadyDone = false; if (!alreadyDone) { MITK_DEBUG << "ConnectomicsObjectFactory c'tor" << std::endl; - itk::ObjectFactoryBase::RegisterFactory(m_ConnectomicsNetworkIOFactory); - - itk::ObjectFactoryBase::RegisterFactory(m_ConnectomicsNetworkWriterFactory); - - m_FileWriters.push_back( mitk::ConnectomicsNetworkWriter::New().GetPointer() ); - - CreateFileExtensionsMap(); - alreadyDone = true; } } mitk::ConnectomicsObjectFactory::~ConnectomicsObjectFactory() { - itk::ObjectFactoryBase::UnRegisterFactory(m_ConnectomicsNetworkIOFactory); - itk::ObjectFactoryBase::UnRegisterFactory(m_ConnectomicsNetworkWriterFactory); } mitk::Mapper::Pointer mitk::ConnectomicsObjectFactory::CreateMapper(mitk::DataNode* node, MapperSlotId id) { mitk::Mapper::Pointer newMapper=NULL; if ( id == mitk::BaseRenderer::Standard3D ) { std::string classname("ConnectomicsNetwork"); if (node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::ConnectomicsNetworkMapper3D::New(); newMapper->SetDataNode(node); } } return newMapper; } void mitk::ConnectomicsObjectFactory::SetDefaultProperties(mitk::DataNode* node) { std::string classname("ConnectomicsNetwork"); if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { mitk::ConnectomicsNetworkMapper3D::SetDefaultProperties(node); } } const char* mitk::ConnectomicsObjectFactory::GetFileExtensions() { std::string fileExtension; this->CreateFileExtensions(m_FileExtensionsMap, fileExtension); return fileExtension.c_str(); }; mitk::CoreObjectFactoryBase::MultimapType mitk::ConnectomicsObjectFactory::GetFileExtensionsMap() { return m_FileExtensionsMap; } const char* mitk::ConnectomicsObjectFactory::GetSaveFileExtensions() { std::string fileExtension; this->CreateFileExtensions(m_SaveFileExtensionsMap, fileExtension); return fileExtension.c_str(); }; mitk::CoreObjectFactoryBase::MultimapType mitk::ConnectomicsObjectFactory::GetSaveFileExtensionsMap() { return m_SaveFileExtensionsMap; } void mitk::ConnectomicsObjectFactory::CreateFileExtensionsMap() { - m_FileExtensionsMap.insert(std::pair("*.cnf", "Connectomics Network File")); - - m_SaveFileExtensionsMap.insert(std::pair("*.cnf", "Connectomics Network File")); } struct RegisterConnectomicsObjectFactory{ RegisterConnectomicsObjectFactory() : m_Factory( mitk::ConnectomicsObjectFactory::New() ) { mitk::CoreObjectFactory::GetInstance()->RegisterExtraFactory( m_Factory ); } ~RegisterConnectomicsObjectFactory() { mitk::CoreObjectFactory::GetInstance()->UnRegisterExtraFactory( m_Factory ); } mitk::ConnectomicsObjectFactory::Pointer m_Factory; }; static RegisterConnectomicsObjectFactory registerDiffusionCoreObjectFactory; diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkDiffusionModuleActivator.cpp b/Modules/DiffusionImaging/DiffusionIO/mitkDiffusionModuleActivator.cpp index 8d449c2105..b68efb772b 100644 --- a/Modules/DiffusionImaging/DiffusionIO/mitkDiffusionModuleActivator.cpp +++ b/Modules/DiffusionImaging/DiffusionIO/mitkDiffusionModuleActivator.cpp @@ -1,87 +1,95 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include #include #include #include +#include #include #include #include +#include #include "mitkDiffusionIOMimeTypes.h" namespace mitk { /** \brief Registers services for segmentation module. */ class DiffusionModuleActivator : public us::ModuleActivator { public: void Load(us::ModuleContext* context) { us::ServiceProperties props; props[ us::ServiceConstants::SERVICE_RANKING() ] = 10; std::vector mimeTypes = mitk::DiffusionIOMimeTypes::Get(); for (std::vector::const_iterator mimeTypeIter = mimeTypes.begin(), iterEnd = mimeTypes.end(); mimeTypeIter != iterEnd; ++mimeTypeIter) { context->RegisterService(*mimeTypeIter, props); } m_NrrdDiffusionImageReader = new NrrdDiffusionImageReader(); m_NrrdTensorImageReader = new NrrdTensorImageReader(); m_NrrdQBallImageReader = new NrrdQBallImageReader(); m_FiberBundleXReader = new FiberBundleXReader(); + m_ConnectomicsNetworkReader = new ConnectomicsNetworkReader(); m_NrrdTensorImageWriter = new NrrdTensorImageWriter(); m_NrrdQBallImageWriter = new NrrdQBallImageWriter(); m_FiberBundleXWriter = new FiberBundleXWriter(); + m_ConnectomicsNetworkWriter = new ConnectomicsNetworkWriter(); } void Unload(us::ModuleContext*) { delete m_NrrdDiffusionImageReader; delete m_NrrdTensorImageReader; delete m_NrrdQBallImageReader; delete m_FiberBundleXReader; + delete m_ConnectomicsNetworkReader; delete m_NrrdTensorImageWriter; delete m_NrrdQBallImageWriter; delete m_FiberBundleXWriter; + delete m_ConnectomicsNetworkWriter; } private: NrrdDiffusionImageReader * m_NrrdDiffusionImageReader; NrrdTensorImageReader * m_NrrdTensorImageReader; NrrdQBallImageReader * m_NrrdQBallImageReader; FiberBundleXReader * m_FiberBundleXReader; + ConnectomicsNetworkReader * m_ConnectomicsNetworkReader; NrrdTensorImageWriter * m_NrrdTensorImageWriter; NrrdQBallImageWriter * m_NrrdQBallImageWriter; FiberBundleXWriter * m_FiberBundleXWriter; + ConnectomicsNetworkWriter * m_ConnectomicsNetworkWriter; }; } US_EXPORT_MODULE_ACTIVATOR(mitk::DiffusionModuleActivator)