Index: Modules/MitkExt/Interactions/mitkToolFactoryMacro.h =================================================================== --- Modules/MitkExt/Interactions/mitkToolFactoryMacro.h (revision 28728) +++ Modules/MitkExt/Interactions/mitkToolFactoryMacro.h (working copy) @@ -81,8 +81,16 @@ CLASS_NAME ## RegistrationMethod() \ { \ /*MITK_INFO("tools") << "Registered " #CLASS_NAME; */ \ - itk::ObjectFactoryBase::RegisterFactory( CLASS_NAME ## Factory::New() ); \ + m_Factory = CLASS_NAME ## Factory::New(); \ + itk::ObjectFactoryBase::RegisterFactory( m_Factory ); \ } \ + ~CLASS_NAME ## RegistrationMethod() \ + { \ + /*MITK_INFO("tools") << "UnRegistered " #CLASS_NAME; */ \ + itk::ObjectFactoryBase::UnRegisterFactory( m_Factory ); \ + } \ + private: \ + CLASS_NAME ## Factory::Pointer m_Factory; \ }; \ \ static mitk::CLASS_NAME ## RegistrationMethod somestaticinitializer_ ## CLASS_NAME ; Index: Modules/MitkExt/Algorithms/mitkCoreExtObjectFactory.h =================================================================== --- Modules/MitkExt/Algorithms/mitkCoreExtObjectFactory.h (revision 28728) +++ Modules/MitkExt/Algorithms/mitkCoreExtObjectFactory.h (working copy) @@ -36,8 +36,12 @@ virtual mitk::CoreObjectFactoryBase::MultimapType GetSaveFileExtensionsMap(); void RegisterIOFactories(); protected: - CoreExtObjectFactory(); + CoreExtObjectFactory(); + ~CoreExtObjectFactory(); void CreateFileExtensionsMap(); + typedef std::list FactoriesList; + FactoriesList m_Factories; + static bool alreadyDone; MultimapType m_FileExtensionsMap; MultimapType m_SaveFileExtensionsMap; }; Index: Modules/MitkExt/Algorithms/mitkCoreExtObjectFactory.cpp =================================================================== --- Modules/MitkExt/Algorithms/mitkCoreExtObjectFactory.cpp (revision 28728) +++ Modules/MitkExt/Algorithms/mitkCoreExtObjectFactory.cpp (working copy) @@ -53,21 +53,32 @@ #include "mitkVolumeDataVtkMapper3D.h" +bool mitk::CoreExtObjectFactory::alreadyDone = false; mitk::CoreExtObjectFactory::CoreExtObjectFactory() :CoreObjectFactoryBase() { - static bool alreadyDone = false; if (!alreadyDone) { MITK_INFO << "CoreExtObjectFactory c'tor" << std::endl; RegisterIOFactories(); - itk::ObjectFactoryBase::RegisterFactory( ParRecFileIOFactory::New() ); - itk::ObjectFactoryBase::RegisterFactory( ObjFileIOFactory::New() ); - itk::ObjectFactoryBase::RegisterFactory( VtkUnstructuredGridIOFactory::New() ); - itk::ObjectFactoryBase::RegisterFactory( StlVolumeTimeSeriesIOFactory::New() ); - itk::ObjectFactoryBase::RegisterFactory( VtkVolumeTimeSeriesIOFactory::New() ); + ParRecFileIOFactory::Pointer parRecFileIOFactory = ParRecFileIOFactory::New(); + m_Factories.push_back( parRecFileIOFactory.GetPointer( ) ); + ObjFileIOFactory::Pointer objFileIOFactory = ObjFileIOFactory::New(); + m_Factories.push_back( objFileIOFactory.GetPointer( ) ); + VtkUnstructuredGridIOFactory::Pointer vtkUnstructuredGridIOFactory = VtkUnstructuredGridIOFactory::New(); + m_Factories.push_back( vtkUnstructuredGridIOFactory.GetPointer( ) ); + StlVolumeTimeSeriesIOFactory::Pointer stlVolumeTimeSeriesIOFactory = StlVolumeTimeSeriesIOFactory::New(); + m_Factories.push_back( stlVolumeTimeSeriesIOFactory.GetPointer( ) ); + VtkVolumeTimeSeriesIOFactory::Pointer vtkVolumeTimeSeriesIOFactory = VtkVolumeTimeSeriesIOFactory::New(); + m_Factories.push_back( vtkVolumeTimeSeriesIOFactory.GetPointer( ) ); + + FactoriesList::iterator it; + for ( it = m_Factories.begin() ; it != m_Factories.end() ; it++ ) + { + itk::ObjectFactoryBase::RegisterFactory( *it ); + } mitk::UnstructuredGridVtkWriterFactory::RegisterOneFactory(); @@ -81,6 +92,22 @@ } } +mitk::CoreExtObjectFactory::~CoreExtObjectFactory() +{ + if (alreadyDone) + { + FactoriesList::iterator it; + for ( it = m_Factories.begin() ; it != m_Factories.end() ; it++ ) + { + itk::ObjectFactoryBase::UnRegisterFactory( *it ); + } + m_Factories.clear(); + + mitk::UnstructuredGridVtkWriterFactory::UnRegisterOneFactory(); + } + +} + mitk::Mapper::Pointer mitk::CoreExtObjectFactory::CreateMapper(mitk::DataNode* node, MapperSlotId id) { mitk::Mapper::Pointer newMapper=NULL; Index: Modules/MitkExt/IO/mitkUnstructuredGridVtkWriterFactory.cpp =================================================================== --- Modules/MitkExt/IO/mitkUnstructuredGridVtkWriterFactory.cpp (revision 28728) +++ Modules/MitkExt/IO/mitkUnstructuredGridVtkWriterFactory.cpp (working copy) @@ -25,6 +25,9 @@ namespace mitk { +bool SurfaceVtkWriterFactory::IsRegistered = false; +UnstructuredGridVtkWriterFactory::Pointer UnstructuredGridVtkWriterFactory::ugVtkWriterFactory; + template class CreateUnstructuredGridWriter : public itk::CreateObjectFunctionBase { Index: Modules/MitkExt/IO/mitkUnstructuredGridVtkWriterFactory.h =================================================================== --- Modules/MitkExt/IO/mitkUnstructuredGridVtkWriterFactory.h (revision 28728) +++ Modules/MitkExt/IO/mitkUnstructuredGridVtkWriterFactory.h (working copy) @@ -41,15 +41,25 @@ /** Register one factory of this type */ static void RegisterOneFactory(void) { - static bool IsRegistered = false; if ( !IsRegistered ) { - UnstructuredGridVtkWriterFactory::Pointer ugVtkWriterFactory = UnstructuredGridVtkWriterFactory::New(); + ugVtkWriterFactory = UnstructuredGridVtkWriterFactory::New(); ObjectFactoryBase::RegisterFactory( ugVtkWriterFactory ); IsRegistered = true; } } + /** UnRegister one factory of this type */ + static void UnRegisterOneFactory( ) + { + if ( IsRegistered ) + { + ObjectFactoryBase::UnRegisterFactory( ugVtkWriterFactory ); + ugVtkWriterFactory = NULL; + IsRegistered = false; + } + } + protected: UnstructuredGridVtkWriterFactory(); ~UnstructuredGridVtkWriterFactory(); @@ -58,6 +68,8 @@ UnstructuredGridVtkWriterFactory(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented + static bool IsRegistered; + static UnstructuredGridVtkWriterFactory::Pointer ugVtkWriterFactory; }; } // end namespace mitk Index: Core/Code/Algorithms/mitkCoreObjectFactory.cpp =================================================================== --- Core/Code/Algorithms/mitkCoreObjectFactory.cpp (revision 28728) +++ Core/Code/Algorithms/mitkCoreObjectFactory.cpp (working copy) @@ -73,6 +73,21 @@ m_ExtraFactories.push_back(CoreObjectFactoryBase::Pointer(factory)); } +void mitk::CoreObjectFactory::UnRegisterExtraFactory( CoreObjectFactoryBase* factory ) +{ + for ( ExtraFactoriesList::iterator i = + m_ExtraFactories.begin(); + i != m_ExtraFactories.end(); ++i ) + { + if ( factory == *i ) + { + m_ExtraFactories.remove(factory); + return; + } + } + +} + mitk::CoreObjectFactory::Pointer mitk::CoreObjectFactory::GetInstance() { static mitk::CoreObjectFactory::Pointer instance; if (instance.IsNull()) @@ -118,19 +133,32 @@ mitk::CoreObjectFactory::CoreObjectFactory() { - static bool alreadyDone = false; if (!alreadyDone) { MITK_INFO << "CoreObjectFactory c'tor" << std::endl; - itk::ObjectFactoryBase::RegisterFactory( PicFileIOFactory::New() ); - itk::ObjectFactoryBase::RegisterFactory( PointSetIOFactory::New() ); - itk::ObjectFactoryBase::RegisterFactory( STLFileIOFactory::New() ); - itk::ObjectFactoryBase::RegisterFactory( VtkSurfaceIOFactory::New() ); - itk::ObjectFactoryBase::RegisterFactory( VtkImageIOFactory::New() ); - itk::ObjectFactoryBase::RegisterFactory( VtiFileIOFactory::New() ); - itk::ObjectFactoryBase::RegisterFactory( ItkImageFileIOFactory::New() ); - itk::ObjectFactoryBase::RegisterFactory( PicVolumeTimeSeriesIOFactory::New() ); + PicFileIOFactory::Pointer picFileIOFactory = PicFileIOFactory::New(); + m_Factories.push_back( picFileIOFactory.GetPointer( ) ); + PointSetIOFactory::Pointer pointSetIOFactory = PointSetIOFactory::New( ); + m_Factories.push_back( pointSetIOFactory.GetPointer( ) ); + STLFileIOFactory::Pointer sTLFileIOFactory = STLFileIOFactory::New( ); + m_Factories.push_back( sTLFileIOFactory.GetPointer( ) ); + VtkSurfaceIOFactory::Pointer vtkSurfaceIOFactory = VtkSurfaceIOFactory::New(); + m_Factories.push_back( vtkSurfaceIOFactory.GetPointer( ) ); + VtkImageIOFactory::Pointer vtkImageIOFactory = VtkImageIOFactory::New(); + m_Factories.push_back( vtkImageIOFactory.GetPointer() ); + VtiFileIOFactory::Pointer vtiFileIOFactory = VtiFileIOFactory::New(); + m_Factories.push_back( vtiFileIOFactory.GetPointer( ) ); + ItkImageFileIOFactory::Pointer itkImageFileIOFactory = ItkImageFileIOFactory::New(); + m_Factories.push_back( itkImageFileIOFactory.GetPointer( ) ); + PicVolumeTimeSeriesIOFactory::Pointer picVolumeTimeSeriesIOFactory = PicVolumeTimeSeriesIOFactory::New(); + m_Factories.push_back( picVolumeTimeSeriesIOFactory.GetPointer( ) ); + + FactoriesList::iterator it; + for ( it = m_Factories.begin() ; it != m_Factories.end() ; it++ ) + { + itk::ObjectFactoryBase::RegisterFactory( *it ); + } mitk::SurfaceVtkWriterFactory::RegisterOneFactory(); mitk::PointSetWriterFactory::RegisterOneFactory(); @@ -142,6 +170,23 @@ } } +mitk::CoreObjectFactory::~CoreObjectFactory() +{ + if (alreadyDone) + { + FactoriesList::iterator it; + for ( it = m_Factories.begin() ; it != m_Factories.end() ; it++ ) + { + itk::ObjectFactoryBase::UnRegisterFactory( *it ); + } + m_Factories.clear(); + + mitk::SurfaceVtkWriterFactory::UnRegisterOneFactory(); + mitk::PointSetWriterFactory::UnRegisterOneFactory(); + mitk::ImageWriterFactory::UnRegisterOneFactory(); + } +} + mitk::Mapper::Pointer mitk::CoreObjectFactory::CreateMapper(mitk::DataNode* node, MapperSlotId id) { mitk::Mapper::Pointer newMapper = NULL; Index: Core/Code/Algorithms/mitkCoreObjectFactory.h =================================================================== --- Core/Code/Algorithms/mitkCoreObjectFactory.h (revision 28728) +++ Core/Code/Algorithms/mitkCoreObjectFactory.h (working copy) @@ -41,14 +41,19 @@ virtual FileWriterList GetFileWriters(); virtual void MapEvent(const mitk::Event* event, const int eventID); virtual void RegisterExtraFactory(CoreObjectFactoryBase* factory); + virtual void UnRegisterExtraFactory(CoreObjectFactoryBase* factory); static Pointer GetInstance(); protected: CoreObjectFactory(); + ~CoreObjectFactory(); void MergeFileExtensions(MultimapType& fileExtensionsMap, MultimapType inputMap); void CreateFileExtensionsMap(); void CreateSaveFileExtensions(); typedef std::list ExtraFactoriesList; ExtraFactoriesList m_ExtraFactories; + typedef std::list FactoriesList; + FactoriesList m_Factories; + static bool alreadyDone; static FileWriterList m_FileWriters; std::string m_FileExtensions; MultimapType m_FileExtensionsMap; Index: Core/Code/IO/mitkSurfaceVtkWriterFactory.cpp =================================================================== --- Core/Code/IO/mitkSurfaceVtkWriterFactory.cpp (revision 28728) +++ Core/Code/IO/mitkSurfaceVtkWriterFactory.cpp (working copy) @@ -26,6 +26,9 @@ namespace mitk { +bool SurfaceVtkWriterFactory::IsRegistered = false; +SurfaceVtkWriterFactory::Pointer SurfaceVtkWriterFactory::surfaceVtkWriterFactory; + template class CreateSurfaceWriter : public itk::CreateObjectFunctionBase { Index: Core/Code/IO/mitkImageWriterFactory.cpp =================================================================== --- Core/Code/IO/mitkImageWriterFactory.cpp (revision 28728) +++ Core/Code/IO/mitkImageWriterFactory.cpp (working copy) @@ -25,6 +25,9 @@ namespace mitk { +bool ImageWriterFactory::IsRegistered = false; +ImageWriterFactory::Pointer ImageWriterFactory::imageWriterFactory; + template class CreateImageWriter : public itk::CreateObjectFunctionBase { Index: Core/Code/IO/mitkImageWriterFactory.h =================================================================== --- Core/Code/IO/mitkImageWriterFactory.h (revision 28728) +++ Core/Code/IO/mitkImageWriterFactory.h (working copy) @@ -40,15 +40,25 @@ /** Register one factory of this type */ static void RegisterOneFactory(void) { - static bool IsRegistered = false; if ( !IsRegistered ) { - ImageWriterFactory::Pointer imageWriterFactory = ImageWriterFactory::New(); + imageWriterFactory = ImageWriterFactory::New(); ObjectFactoryBase::RegisterFactory( imageWriterFactory ); IsRegistered = true; } } + /** UnRegister one factory of this type */ + static void UnRegisterOneFactory( ) + { + if ( IsRegistered ) + { + ObjectFactoryBase::UnRegisterFactory( imageWriterFactory ); + imageWriterFactory = NULL; + IsRegistered = false; + } + } + protected: ImageWriterFactory(); ~ImageWriterFactory(); @@ -57,6 +67,9 @@ ImageWriterFactory(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented + static bool IsRegistered; + static ImageWriterFactory::Pointer imageWriterFactory; + }; } // end namespace mitk Index: Core/Code/IO/mitkPointSetWriterFactory.h =================================================================== --- Core/Code/IO/mitkPointSetWriterFactory.h (revision 28728) +++ Core/Code/IO/mitkPointSetWriterFactory.h (working copy) @@ -40,15 +40,25 @@ /** Register one factory of this type */ static void RegisterOneFactory(void) { - static bool IsRegistered = false; if ( !IsRegistered ) { - PointSetWriterFactory::Pointer pointSetWriterFactory = PointSetWriterFactory::New(); + pointSetWriterFactory = PointSetWriterFactory::New(); ObjectFactoryBase::RegisterFactory( pointSetWriterFactory ); IsRegistered = true; } } + /** UnRegister one factory of this type */ + static void UnRegisterOneFactory( ) + { + if ( IsRegistered ) + { + ObjectFactoryBase::UnRegisterFactory( pointSetWriterFactory ); + pointSetWriterFactory = NULL; + IsRegistered = false; + } + } + protected: PointSetWriterFactory(); ~PointSetWriterFactory(); @@ -57,6 +67,9 @@ PointSetWriterFactory(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented + static bool IsRegistered; + static PointSetWriterFactory::Pointer pointSetWriterFactory; + }; } // end namespace mitk Index: Core/Code/IO/mitkSurfaceVtkWriterFactory.h =================================================================== --- Core/Code/IO/mitkSurfaceVtkWriterFactory.h (revision 28728) +++ Core/Code/IO/mitkSurfaceVtkWriterFactory.h (working copy) @@ -40,15 +40,25 @@ /** Register one factory of this type */ static void RegisterOneFactory(void) { - static bool IsRegistered = false; if ( !IsRegistered ) { - SurfaceVtkWriterFactory::Pointer surfaceVtkWriterFactory = SurfaceVtkWriterFactory::New(); + surfaceVtkWriterFactory = SurfaceVtkWriterFactory::New(); ObjectFactoryBase::RegisterFactory( surfaceVtkWriterFactory ); IsRegistered = true; } } + /** UnRegister one factory of this type */ + static void UnRegisterOneFactory( ) + { + if ( IsRegistered ) + { + ObjectFactoryBase::UnRegisterFactory( surfaceVtkWriterFactory ); + surfaceVtkWriterFactory = NULL; + IsRegistered = false; + } + } + protected: SurfaceVtkWriterFactory(); ~SurfaceVtkWriterFactory(); @@ -57,6 +67,8 @@ SurfaceVtkWriterFactory(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented + static bool IsRegistered; + static SurfaceVtkWriterFactory::Pointer surfaceVtkWriterFactory; }; } // end namespace mitk Index: Core/Code/IO/mitkPointSetWriterFactory.cpp =================================================================== --- Core/Code/IO/mitkPointSetWriterFactory.cpp (revision 28728) +++ Core/Code/IO/mitkPointSetWriterFactory.cpp (working copy) @@ -24,6 +24,8 @@ namespace mitk { +bool PointSetWriterFactory::IsRegistered = false; +PointSetWriterFactory::Pointer PointSetWriterFactory::pointSetWriterFactory; template class CreatePointSetWriter : public itk::CreateObjectFunctionBase