diff --git a/Core/Code/Controllers/mitkCoreActivator.cpp b/Core/Code/Controllers/mitkCoreActivator.cpp index 8ba45c2870..005cd1a23c 100644 --- a/Core/Code/Controllers/mitkCoreActivator.cpp +++ b/Core/Code/Controllers/mitkCoreActivator.cpp @@ -1,232 +1,238 @@ /*=================================================================== 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. ===================================================================*/ // Rendering #include "mitkRenderingManager.h" #include "mitkPlanePositionManager.h" #include #include #include #include #include #include // File IO #include #include #include #include #include // Microservices #include #include #include #include #include #include #include +#include + void HandleMicroServicesMessages(us::MsgType type, const char* msg) { switch (type) { case us::DebugMsg: MITK_DEBUG << msg; break; case us::InfoMsg: MITK_INFO << msg; break; case us::WarningMsg: MITK_WARN << msg; break; case us::ErrorMsg: MITK_ERROR << msg; break; } } void AddMitkAutoLoadPaths(const std::string& programPath) { us::ModuleSettings::AddAutoLoadPath(programPath); #ifdef __APPLE__ // Walk up three directories since that is where the .dylib files are located // for build trees. std::string additionalPath = programPath; bool addPath = true; for(int i = 0; i < 3; ++i) { std::size_t index = additionalPath.find_last_of('/'); if (index != std::string::npos) { additionalPath = additionalPath.substr(0, index); } else { addPath = false; break; } } if (addPath) { us::ModuleSettings::AddAutoLoadPath(additionalPath); } #endif } /* * This is the module activator for the "Mitk" module. It registers core services * like ... */ class MitkCoreActivator : public us::ModuleActivator { public: void Load(us::ModuleContext* context) { // Handle messages from CppMicroServices us::installMsgHandler(HandleMicroServicesMessages); // Add the current application directory to the auto-load paths. // This is useful for third-party executables. std::string programPath = mitk::IOUtil::GetProgramPath(); if (programPath.empty()) { MITK_WARN << "Could not get the program path."; } else { AddMitkAutoLoadPaths(programPath); } //m_RenderingManager = mitk::RenderingManager::New(); //context->RegisterService(renderingManager.GetPointer()); m_PlanePositionManager.reset(new mitk::PlanePositionManagerService); context->RegisterService(m_PlanePositionManager.get()); m_ShaderRepository.reset(new mitk::ShaderRepository); context->RegisterService(m_ShaderRepository.get()); m_PropertyAliases.reset(new mitk::PropertyAliases); context->RegisterService(m_PropertyAliases.get()); m_PropertyDescriptions.reset(new mitk::PropertyDescriptions); context->RegisterService(m_PropertyDescriptions.get()); m_PropertyExtensions.reset(new mitk::PropertyExtensions); context->RegisterService(m_PropertyExtensions.get()); m_PropertyFilters.reset(new mitk::PropertyFilters); context->RegisterService(m_PropertyFilters.get()); m_MimeTypeProvider.reset(new mitk::MimeTypeProvider); m_MimeTypeProvider->Start(); m_MimeTypeProviderReg = context->RegisterService(m_MimeTypeProvider.get()); context->AddModuleListener(this, &MitkCoreActivator::HandleModuleEvent); + // Explicitly load the LegacyIO module + us::SharedLibrary legacyIOLib(programPath, "LegacyIO"); + legacyIOLib.Load(); + // Add Reader / Writer Services mitk::IFileReader* reader; // mitk::IFileWriter* writer; reader = new mitk::PointSetReaderService(); m_FileReaders.push_back(reader); /* There IS an option to exchange ALL vtkTexture instances against vtkNeverTranslucentTextureFactory. This code is left here as a reminder, just in case we might need to do that some time. vtkNeverTranslucentTextureFactory* textureFactory = vtkNeverTranslucentTextureFactory::New(); vtkObjectFactory::RegisterFactory( textureFactory ); textureFactory->Delete(); */ } void Unload(us::ModuleContext* ) { // The mitk::ModuleContext* argument of the Unload() method // will always be 0 for the Mitk library. It makes no sense // to use it at this stage anyway, since all libraries which // know about the module system have already been unloaded. // we need to close the internal service tracker of the // MimeTypeProvider class here. Otherwise it // would hold on to the ModuleContext longer than it is // actually valid. m_MimeTypeProviderReg.Unregister(); m_MimeTypeProvider->Stop(); } private: void HandleModuleEvent(const us::ModuleEvent moduleEvent); std::map > moduleIdToShaderIds; //mitk::RenderingManager::Pointer m_RenderingManager; std::auto_ptr m_PlanePositionManager; std::auto_ptr m_ShaderRepository; std::auto_ptr m_PropertyAliases; std::auto_ptr m_PropertyDescriptions; std::auto_ptr m_PropertyExtensions; std::auto_ptr m_PropertyFilters; std::auto_ptr m_MimeTypeProvider; // File IO std::vector m_FileReaders; std::vector m_FileWriters; us::ServiceRegistration m_MimeTypeProviderReg; }; void MitkCoreActivator::HandleModuleEvent(const us::ModuleEvent moduleEvent) { if (moduleEvent.GetType() == us::ModuleEvent::LOADED) { // search and load shader files std::vector shaderResoruces = moduleEvent.GetModule()->FindResources("Shaders", "*.xml", true); for (std::vector::iterator i = shaderResoruces.begin(); i != shaderResoruces.end(); ++i) { if (*i) { us::ModuleResourceStream rs(*i); int id = m_ShaderRepository->LoadShader(rs, i->GetBaseName()); if (id >= 0) { moduleIdToShaderIds[moduleEvent.GetModule()->GetModuleId()].push_back(id); } } } } else if (moduleEvent.GetType() == us::ModuleEvent::UNLOADED) { std::map >::iterator shaderIdsIter = moduleIdToShaderIds.find(moduleEvent.GetModule()->GetModuleId()); if (shaderIdsIter != moduleIdToShaderIds.end()) { for (std::vector::iterator idIter = shaderIdsIter->second.begin(); idIter != shaderIdsIter->second.end(); ++idIter) { m_ShaderRepository->UnloadShader(*idIter); } moduleIdToShaderIds.erase(shaderIdsIter); } } } US_EXPORT_MODULE_ACTIVATOR(Mitk, MitkCoreActivator) diff --git a/Modules/LegacyIO/files.cmake b/Modules/LegacyIO/files.cmake index 5790303f08..aacea1ec18 100644 --- a/Modules/LegacyIO/files.cmake +++ b/Modules/LegacyIO/files.cmake @@ -1,30 +1,31 @@ set(H_FILES ) set(CPP_FILES + mitkActivator.cpp mitkBaseDataIOFactory.cpp mitkDataNodeFactory.cpp mitkFileSeriesReader.cpp mitkImageWriter.cpp mitkImageWriterFactory.cpp mitkItkImageFileIOFactory.cpp mitkItkImageFileReader.cpp mitkItkPictureWrite.cpp mitkPointSetIOFactory.cpp mitkPointSetReader.cpp mitkPointSetWriter.cpp mitkPointSetWriterFactory.cpp mitkRawImageFileReader.cpp mitkSTLFileIOFactory.cpp mitkSTLFileReader.cpp mitkSurfaceVtkWriter.cpp mitkSurfaceVtkWriterFactory.cpp mitkVtiFileIOFactory.cpp mitkVtiFileReader.cpp mitkVtkImageIOFactory.cpp mitkVtkImageReader.cpp mitkVtkSurfaceIOFactory.cpp mitkVtkSurfaceReader.cpp vtkPointSetXMLParser.cpp ) diff --git a/Modules/LegacyIO/mitkActivator.cpp b/Modules/LegacyIO/mitkActivator.cpp index 096c2b320e..584dc6da3a 100644 --- a/Modules/LegacyIO/mitkActivator.cpp +++ b/Modules/LegacyIO/mitkActivator.cpp @@ -1,70 +1,121 @@ /*=================================================================== 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 "mitkSurfaceVtkWriterFactory.h" +#include "mitkPointSetIOFactory.h" #include "mitkPointSetWriterFactory.h" +#include "mitkSTLFileIOFactory.h" +#include "mitkVtkSurfaceIOFactory.h" +#include "mitkVtkImageIOFactory.h" +#include "mitkVtiFileIOFactory.h" +#include "mitkItkImageFileIOFactory.h" #include "mitkImageWriterFactory.h" +#include "mitkSimpleMimeType.h" + +#include +#include class US_ABI_LOCAL Activator : public us::ModuleActivator { public: void Load(us::ModuleContext* context) { - m_CoreDataNodeReader.reset(new mitk::CoreDataNodeReader); - context->RegisterService(m_CoreDataNodeReader.get()); + //m_CoreDataNodeReader.reset(new mitk::CoreDataNodeReader); + //context->RegisterService(m_CoreDataNodeReader.get()); + this->m_Context = context; + + // Register some mime-types + + // 3D Images + std::vector mimeTypeExtensions; + mimeTypeExtensions.push_back("dc3"); + mimeTypeExtensions.push_back("dcm"); + RegisterMimeType("application/dicom", "Images", "Dicom Images", mimeTypeExtensions); + RegisterMimeType("application/vnd.mitk.pic", "Images", "DKFZ PIC Format", "pic"); + RegisterMimeType("application/vnd.mitk.pic+gz", "Images", "DKFZ Compressed PIC Format", "pic.gz"); + + // REMOVE: Test multiple mime types for same extension + RegisterMimeType("application/vnd.fancy", "Images", "Fancy Compressed PIC Format", "pic.gz"); - m_ObjectFactories.push_back(PointSetIOFactory::New()); - m_ObjectFactories.push_back(STLFileIOFactory::New()); - m_ObjectFactories.push_back(VtkSurfaceIOFactory::New()); - m_ObjectFactories.push_back(VtkImageIOFactory::New()); - m_ObjectFactories.push_back(VtiFileIOFactory::New()); - m_ObjectFactories.push_back(ItkImageFileIOFactory::New()); + // 2D Images + RegisterMimeType("image/bmp", "2D Images", "Bitmap Image", "bmp"); + + m_ObjectFactories.push_back(mitk::PointSetIOFactory::New().GetPointer()); + m_ObjectFactories.push_back(mitk::STLFileIOFactory::New().GetPointer()); + m_ObjectFactories.push_back(mitk::VtkSurfaceIOFactory::New().GetPointer()); + m_ObjectFactories.push_back(mitk::VtkImageIOFactory::New().GetPointer()); + m_ObjectFactories.push_back(mitk::VtiFileIOFactory::New().GetPointer()); + m_ObjectFactories.push_back(mitk::ItkImageFileIOFactory::New().GetPointer()); for(std::vector::const_iterator iter = m_ObjectFactories.begin(), end = m_ObjectFactories.end(); iter != end; ++iter) { itk::ObjectFactoryBase::RegisterFactory(*iter); } mitk::SurfaceVtkWriterFactory::RegisterOneFactory(); mitk::PointSetWriterFactory::RegisterOneFactory(); mitk::ImageWriterFactory::RegisterOneFactory(); } void Unload(us::ModuleContext* ) { for(std::vector::const_iterator iter = m_ObjectFactories.begin(), end = m_ObjectFactories.end(); iter != end; ++iter) { itk::ObjectFactoryBase::UnRegisterFactory(*iter); } // FIXME: There is no "UnRegisterOneFactory" method } + void RegisterMimeType(const std::string& id, const std::string& category, const std::string& description, + const std::string& extension) + { + std::vector extensions; + extensions.push_back(extension); + this->RegisterMimeType(id, category, description, extensions); + } + + void RegisterMimeType(const std::string& id, const std::string& category, const std::string& description, + const std::vector& extensions) + { + us::ServiceProperties mimeTypeProps; + mimeTypeProps[mitk::IMimeType::PROP_ID()] = id; + mimeTypeProps[mitk::IMimeType::PROP_CATEGORY()] = category; + mimeTypeProps[mitk::IMimeType::PROP_DESCRIPTION()] = description; + mimeTypeProps[mitk::IMimeType::PROP_EXTENSIONS()] = extensions; + mimeTypeProps[us::ServiceConstants::SERVICE_RANKING()] = -100; + m_Context->RegisterService(&m_MimeType, mimeTypeProps); + } + private: - std::auto_ptr m_CoreDataNodeReader; + //std::auto_ptr m_CoreDataNodeReader; + + us::ModuleContext* m_Context; std::vector m_ObjectFactories; + + mitk::SimpleMimeType m_MimeType; }; US_EXPORT_MODULE_ACTIVATOR(LegacyIO, Activator)