diff --git a/Modules/ContourModel/Algorithms/mitkContourObjectFactory.cpp b/Modules/ContourModel/Algorithms/mitkContourObjectFactory.cpp index 7f57475483..c028162db7 100644 --- a/Modules/ContourModel/Algorithms/mitkContourObjectFactory.cpp +++ b/Modules/ContourModel/Algorithms/mitkContourObjectFactory.cpp @@ -1,149 +1,154 @@ /*=================================================================== 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 "mitkContourObjectFactory.h" #include "mitkProperties.h" #include "mitkBaseRenderer.h" #include "mitkDataNode.h" #include "mitkCoreObjectFactory.h" #include "mitkContourModel.h" #include "mitkContourModelIOFactory.h" #include "mitkContourModelWriterFactory.h" #include "mitkContourModelWriter.h" #include "mitkContourModelMapper2D.h" #include "mitkContourModelGLMapper2D.h" #include "mitkContourModelMapper3D.h" mitk::ContourObjectFactory::ContourObjectFactory() -:CoreObjectFactoryBase() +: CoreObjectFactoryBase() +, m_ContourModelIOFactory(mitk::ContourModelIOFactory::New().GetPointer()) { static bool alreadyDone = false; if (!alreadyDone) { MITK_DEBUG << "ContourObjectFactory c'tor" << std::endl; - RegisterIOFactories(); + itk::ObjectFactoryBase::RegisterFactory( m_ContourModelIOFactory ); + + mitk::ContourModelWriterFactory::RegisterOneFactory(); + + this->m_FileWriters.push_back(mitk::ContourModelWriter::New().GetPointer()); + + CreateFileExtensionsMap(); alreadyDone = true; } } +mitk::ContourObjectFactory::~ContourObjectFactory() +{ + mitk::ContourModelWriterFactory::UnRegisterOneFactory(); + itk::ObjectFactoryBase::UnRegisterFactory(m_ContourModelIOFactory); +} + mitk::Mapper::Pointer mitk::ContourObjectFactory::CreateMapper(mitk::DataNode* node, MapperSlotId id) { mitk::Mapper::Pointer newMapper=NULL; mitk::BaseData *data = node->GetData(); if ( id == mitk::BaseRenderer::Standard2D ) { std::string classname("ContourModel"); if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::ContourModelGLMapper2D::New(); newMapper->SetDataNode(node); } } else if ( id == mitk::BaseRenderer::Standard3D ) { std::string classname("ContourModel"); if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::ContourModelMapper3D::New(); newMapper->SetDataNode(node); } } return newMapper; } void mitk::ContourObjectFactory::SetDefaultProperties(mitk::DataNode* node) { if(node==NULL) return; mitk::DataNode::Pointer nodePointer = node; std::string classname("ContourModel"); if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { mitk::ContourModelGLMapper2D::SetDefaultProperties(node); mitk::ContourModelMapper3D::SetDefaultProperties(node); } } const char* mitk::ContourObjectFactory::GetFileExtensions() { std::string fileExtension; this->CreateFileExtensions(m_FileExtensionsMap, fileExtension); return fileExtension.c_str(); }; mitk::CoreObjectFactoryBase::MultimapType mitk::ContourObjectFactory::GetFileExtensionsMap() { return m_FileExtensionsMap; } mitk::CoreObjectFactoryBase::MultimapType mitk::ContourObjectFactory::GetSaveFileExtensionsMap() { return m_SaveFileExtensionsMap; } void mitk::ContourObjectFactory::CreateFileExtensionsMap() { m_SaveFileExtensionsMap.insert(std::pair("*.cnt", "Contour Files")); m_FileExtensionsMap.insert(std::pair("*.cnt", "Contour File")); } const char* mitk::ContourObjectFactory::GetSaveFileExtensions() { std::string fileExtension; this->CreateFileExtensions(m_SaveFileExtensionsMap, fileExtension); return fileExtension.c_str(); } void mitk::ContourObjectFactory::RegisterIOFactories() { - //register io classes of mitkContourModel - mitk::ContourModelIOFactory::RegisterOneFactory(); - - mitk::ContourModelWriterFactory::RegisterOneFactory(); - - this->m_FileWriters.push_back(mitk::ContourModelWriter::New().GetPointer()); - - CreateFileExtensionsMap(); } struct RegisterContourObjectFactory{ RegisterContourObjectFactory() : m_Factory( mitk::ContourObjectFactory::New() ) { mitk::CoreObjectFactory::GetInstance()->RegisterExtraFactory( m_Factory ); } ~RegisterContourObjectFactory() { mitk::CoreObjectFactory::GetInstance()->UnRegisterExtraFactory( m_Factory ); } mitk::ContourObjectFactory::Pointer m_Factory; }; static RegisterContourObjectFactory registerContourObjectFactory; diff --git a/Modules/ContourModel/Algorithms/mitkContourObjectFactory.h b/Modules/ContourModel/Algorithms/mitkContourObjectFactory.h index eaa718858d..3f8096fc85 100644 --- a/Modules/ContourModel/Algorithms/mitkContourObjectFactory.h +++ b/Modules/ContourModel/Algorithms/mitkContourObjectFactory.h @@ -1,46 +1,50 @@ /*=================================================================== 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 SEGMENTATIONOBJECTFACTORY_H_INCLUDED #define SEGMENTATIONOBJECTFACTORY_H_INCLUDED #include "mitkCoreObjectFactoryBase.h" #include "ContourModelExports.h" namespace mitk { class ContourModel_EXPORT ContourObjectFactory : public CoreObjectFactoryBase { public: mitkClassMacro(ContourObjectFactory,CoreObjectFactoryBase); itkNewMacro(ContourObjectFactory); virtual Mapper::Pointer CreateMapper(mitk::DataNode* node, MapperSlotId slotId); virtual void SetDefaultProperties(mitk::DataNode* node); virtual const char* GetFileExtensions(); virtual mitk::CoreObjectFactoryBase::MultimapType GetFileExtensionsMap(); virtual const char* GetSaveFileExtensions(); virtual mitk::CoreObjectFactoryBase::MultimapType GetSaveFileExtensionsMap(); void RegisterIOFactories(); protected: ContourObjectFactory(); + ~ContourObjectFactory(); void CreateFileExtensionsMap(); MultimapType m_FileExtensionsMap; MultimapType m_SaveFileExtensionsMap; + + private: + itk::ObjectFactoryBase::Pointer m_ContourModelIOFactory; }; } #endif diff --git a/Modules/ContourModel/IO/mitkContourModelWriterFactory.cpp b/Modules/ContourModel/IO/mitkContourModelWriterFactory.cpp index 6cbbd16e6b..d20d387bfa 100644 --- a/Modules/ContourModel/IO/mitkContourModelWriterFactory.cpp +++ b/Modules/ContourModel/IO/mitkContourModelWriterFactory.cpp @@ -1,75 +1,94 @@ /*=================================================================== 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 "mitkContourModelWriterFactory.h" #include "itkCreateObjectFunction.h" #include "itkVersion.h" #include namespace mitk { template class CreateContourModelWriter : public itk::CreateObjectFunctionBase { public: /** Standard class typedefs. */ typedef CreateContourModelWriter 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: CreateContourModelWriter() {} ~CreateContourModelWriter() {} private: CreateContourModelWriter(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented }; ContourModelWriterFactory::ContourModelWriterFactory() { this->RegisterOverride("IOWriter", "ContourModelWriter", "ContourModel xml Writer", 1, mitk::CreateContourModelWriter::New()); } ContourModelWriterFactory::~ContourModelWriterFactory() { } +void ContourModelWriterFactory::RegisterOneFactory(void) +{ + if ( GetInstance()->GetReferenceCount() == 1 ) + { + ObjectFactoryBase::RegisterFactory( GetInstance().GetPointer() ); + } +} + +void ContourModelWriterFactory::UnRegisterOneFactory(void) +{ + ObjectFactoryBase::UnRegisterFactory( GetInstance().GetPointer() ); +} + +itk::ObjectFactoryBase::Pointer ContourModelWriterFactory::GetInstance() +{ + static itk::ObjectFactoryBase::Pointer factory(mitk::ContourModelWriterFactory::New().GetPointer()); + return factory; +} + const char* ContourModelWriterFactory::GetITKSourceVersion() const { return ITK_SOURCE_VERSION; } const char* ContourModelWriterFactory::GetDescription() const { return "ContourModelWriterFactory"; } } // end namespace mitk diff --git a/Modules/ContourModel/IO/mitkContourModelWriterFactory.h b/Modules/ContourModel/IO/mitkContourModelWriterFactory.h index 5e427c5af4..b38f476684 100644 --- a/Modules/ContourModel/IO/mitkContourModelWriterFactory.h +++ b/Modules/ContourModel/IO/mitkContourModelWriterFactory.h @@ -1,61 +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 CONTOURMODELWRITERFACTORY_H_HEADER_INCLUDED #define CONTOURMODELWRITERFACTORY_H_HEADER_INCLUDED #include "ContourModelExports.h" #include "itkObjectFactoryBase.h" #include "mitkBaseData.h" namespace mitk { class ContourModel_EXPORT ContourModelWriterFactory : public itk::ObjectFactoryBase { public: mitkClassMacro( mitk::ContourModelWriterFactory, 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); /** Register one factory of this type */ - static void RegisterOneFactory(void) - { - static bool IsRegistered = false; - if ( !IsRegistered ) - { - ContourModelWriterFactory::Pointer contourModelWriterFactory = ContourModelWriterFactory::New(); - ObjectFactoryBase::RegisterFactory( contourModelWriterFactory ); - IsRegistered = true; - } - } + static void RegisterOneFactory(void); + + /** UnRegister one factory of this type */ + static void UnRegisterOneFactory(void); + protected: ContourModelWriterFactory(); ~ContourModelWriterFactory(); private: ContourModelWriterFactory(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented + static itk::ObjectFactoryBase::Pointer GetInstance(); }; } #endif //CONTOURMODELWRITERFACTORY_H_HEADER_INCLUDED