diff --git a/Modules/Simulation/Documentation/doxygen/Manual.dox b/Modules/Simulation/Documentation/doxygen/Manual.dox index 283292abf0..06b217c3af 100644 --- a/Modules/Simulation/Documentation/doxygen/Manual.dox +++ b/Modules/Simulation/Documentation/doxygen/Manual.dox @@ -1,103 +1,126 @@ /** \page SimulationManualPage The MITK Simulation Module -The MITK Simulation Module provides medical simulation capabilities by integrating the Simulation Open Framework Architecture (SOFA) into MITK. +The MITK simulation module provides medical simulation capabilities by integrating the Simulation Open Framework Architecture (SOFA) into MITK. \section SimulationManualBuildInstructions Build Instructions -Activate the %CMake option MITK_USE_SOFA to automatically download and build SOFA as well as the MITK Simulation Module during the superbuild process. -Afterwards you can activate simulation-enabled plugins during the MITK build configuration, e.g. MITK_BUILD_org.mitk.gui.qt.simulation. +Activate the %CMake option MITK_USE_SOFA when configuring the MITK superbuild. +SOFA is automatically downloaded and built during the superbuild (as well as the MITK simulation module, which depends on SOFA). +Simulation-related plugins can be activated when configuring the MITK build, i.e. activate MITK_BUILD_org.mitk.gui.qt.simulation, which will automatically activate MITK_BUILD_org.mitk.simulation in turn. -\section SimulationManualIntroduction Introduction +\subsection SimulationManualSOFAPluginBuildInstructions SOFA Plugins + +SOFA plugins are built automatically during the MITK superbuild if they are located in the right directory and contain a %CMake script to build them. + +SOFA build configuration is originally qmake-based. However, for seamless MITK superbuild integration a %CMake-based build script is used instead. +After you activated the %CMake option MITK_USE_SOFA, SOFA complete with the %CMake-based build script is downloaded during the superbuild. +Following the MITK superbuild convention for external projects, it is located in the SOFA-src directory right beneath the top-level MITK build directory. +Following the SOFA convention for plugins, they should be located in applications/plugins. +Hence, create an applications/plugins directory in SOFA-src and place your plugin here, i.e. SOFA-src/applications/plugins/myplugin. + +The second and last step is to create a CMakeLists.txt file inside your plugin directory. +Use the %CMake function add_sofa_library() to easily set up your plugin build script. +Below is an example of a CMakeLists.txt file for a fictional plugin named "myplugin": + +\code +set(MYPLUGIN_SOURES + Topologies/MyTopology.cpp + MyInteraction.cpp +) -It is strongly recommended that you are at least familiar with the basic concepts of SOFA before you proceed reading. +set(MYPLUGIN_LIBS + sofa_base_topology + sofa_user_interaction +) -SOFA is intended to be used as a framework by itself. It is split into the following three parts: +add_sofa_library(myplugin NO_PREFIX) +\endcode + +The naming of MYPLUGIN_SOURCES and MYPLUGIN_LIBS is crucial for add_sofa_library(myplugin) to find the sources and libraries. +For more information see SOFA-src/CMake/AddSOFALibrary.cmake. + +Once your plugin is placed in the right directory and provides a CMakeLists.txt file it is built during the MITK superbuild. +Binaries of your plugin are placed in SOFA-build/bin. + +SOFA plugins can be loaded at runtime via the simulation preferences by clicking the Add... button. + +\image html SimulationPreferences.png The simulation preferences dialog box. + +\section SimulationManualIntroduction Introduction + +SOFA is split into the following three parts: -While the former two parts make up the actual framework, the latter part is built on top of them and provides end user applications, e.g. runSofa. +While the former two parts make up the actual framework functionality, the applications part provides end user applications, e.g. runSofa. +The MITK simulation module and plugins replace the applications part of SOFA and make use of the framework and modules parts in terms of a toolkit. -To be able to integrate SOFA into MITK, the MITK Simulation Module conceptionally replaces the application layer and solely uses the framework and module layer as a toolkit. +\image html SOFA_MITK.png Conceptional layers and dependencies of SOFA and the MITK simulation module. -\section SimulationManualHowToUpdate How to update SOFA +\remark While the framework and modules parts of SOFA are LGPL-licensed, the applications part, which is not used by MITK, is GPL-licensed. -SOFA is deployed to the MITK superbuild in three ZIP archives, namely +\section SimulationManualHowToUpdate How to supply SOFA to the MITK Superbuild - +\remark If you are not a member of the MITK staff you can safely skip this section. + +SOFA build configuration is originally qmake-based. However, for seamless MITK superbuild integration a %CMake-based build script is used instead. +To maintain this script and to ensure that it matches the right revision of SOFA we set up a Git repository at %git\@mitk.org:MITK-SOFA. -where [rev] is a substitute for the SVN revision of SOFA, e.g. 8935. -The follwing process was proven suitable to create these ZIP archives out of a certain SOFA revision. -Since it is a very time-consuming task you should only update SOFA if it is really necessary! - -
    -
  1. Follow the instructions of the SOFA framework download website to check out a recent revsion of the trunk form their SVN server into a newly created directory named SOFA-svn (check the dashboard first to see if that revision is likely to compile properly on all supported platforms). -
  2. To get rid of all SVN files in the source directory use SVN export to export the source code to a separate directory named SOFA-rev[rev]. -
  3. Delete all irrelevant directories and files in SOFA-rev[rev]. Relevant directories and files are: - -
  4. Create sofa-rev[rev].zip out of the SOFA-rev[rev] directory. -
  5. Download the old sofa-rev[old_rev].zip and extract it to SOFA-rev[old_rev]. -
  6. Download the old sofa-rev[old_rev]-cmake.zip and extract it to SOFA-CMake. -
  7. Download the old sofa-rev[old_rev]-gl.zip and extract it to SOFA-GL. -
  8. Download a directory diff tool like DirDiff for Windows and compare sofa-rev[old_rev] with sofa_rev[rev] to get an overview of what has changed. Note that you have to look at the .pro files to see which files were added or removed to the projects. Just looking at the files in a project directory is not sufficient! -
  9. Adapt the CMake files in SOFA-CMake to the changes. -
  10. Copy SOFA-rev[rev] to SOFA-rev[rev]-Test and also copy SOFA-CMake and SOFA-GL into that directory. -
  11. Manually apply the patch for SOFA you find in the MITK source tree (MITK/CMakeExternals/PatchSOFA-rev[old_rev].cmake. -
  12. Try to build SOFA-rev[rev]-Test. Make changes to SOFA-CMake and SOFA-GL files (don't forget to reapply the patch or even change the patch if necessary) until you can build everything successfully. -
  13. Create sofa-rev[rev]-cmake.zip out of SOFA-CMake and sofa-rev[rev]-gl.zip out of SOFA-GL. -
  14. Upload all three ZIP archives to a easily accessible location like your public DropBox folder. -
  15. Update MITK/CMakeExternals/SOFA.cmake to point to the temporary locations and don't forget to update the MD5 hashes and to use an up-to-date patch file, i.e. PatchSOFA-rev[rev].cmake. -
  16. Try to build MITK. Repeat any of the above steps until you are able to compile and use MITK with SOFA on every supprted plattform. -
  17. Upload the new SOFA archives to mitk.org and adapt the URLs in MITK/CMakeExternals/SOFA.cmake. -
+When the repository was updated a package named SOFA_.tar.gz must be created and uploaded to %http://mitk.org/download/thirdparty/. + consists of the last eight digits of the SHA1 ID of the commit. +To use the new package for the MITK superbuild, the URL and MD5 of the package must be updated in CMakeExternals/SOFA.cmake. + +If you need to patch SOFA sources you must append your patch to CMakeExternals/PatchSOFA-rev.cmake. +Make sure that you keep the filename up to date regarding the revision of SOFA and update the filename for the patch command in CMakeExternals/SOFA.cmake too. + +The commit messages of the MITK-SOFA repository contain valuable information on which parts of SOFA must be stripped from a newly checked out revision. +Please continue writing detailed commit messages when updating the repository. + +Updating the repository to a new SOFA revision can be a time-consuming task. +The best way to keep track of changes and additions to the SOFA sources is to use a free folder comparing tool (e.g. dirdiff). +Especially look at .pro files which describe the individual SOFA projects. \section SimulationManualDrawing Drawing +It is recommended that you are at least familiar with the basic concepts of SOFA, e.g. scene graphs and visitors, before you proceed reading. + Drawing is done by SOFA at three different places: These cases are handled by the MITK Simulation Module as follows. \subsection SimulationManualDrawingVisualModel sofa::component::visualmodel One of the most important drawing classes is OglModel since it makes up most of the visual part of a simulation scene. It inherits from VisualModel (which encapsulates all API-independent drawing code) and contains OpenGL-related code to draw the visual model. To hook into the drawing of visual models, the MITK Simulation Module creates an alias in the SOFA object system so that every OglModel and VisualModel node found in a scene file is used to instantiate a MITK SimulationModel class instead. This class creates VTK actors that contain the visual model rather than drawing it directly. The simulation mapper, which is responsible for drawing a simulation scene, utilizes the visitor mechanism of SOFA to collect all VTK actors of the scene tree and finally draws them. \subsection SimulationManualDrawingDrawToolGL sofa::core::visual::DrawTool The abstract class DrawTool and its default OpenGL implementation DrawToolGL provide the interface to draw basic primitives, e.g. points, lines, spheres, arrows, and so forth. It is usually set by a call to sofa::core::visual::VisualParams::defaultInstance()->drawTool() at application initialization. The MITK Simulation Module provide its own VTK-based implementation of DrawTool, namely SimulationDrawTool. This class creates VTK actors instead of drawing anything directly. There is one SimulationDrawTool per simulation scene and the simulation mapper draws all current VTK actors according to which simulation scene is drawn. \subsection SimulationManualDrawingGL sofa::helper::gl Classes and functions in this namespace are problematic since they don't support the SOFA object system and therefore cannot be easily replaced by own implementations. Currently they are not handled by MITK at all and an OpenGL stub is injected into SOFA so that all draw related methods and functions in this namespace do practically nothing. This stub is automatically downloaded during the MITK superbuild process (sofa-rev[rev]-gl.zip). However, a patch is additionally applied by the superbuild script to SOFA which alters a few header files to include the stub header files instead of the original OpenGL/GLUT/GLEW ones. */ \ No newline at end of file diff --git a/Modules/Simulation/Documentation/doxygen/SOFA_MITK.png b/Modules/Simulation/Documentation/doxygen/SOFA_MITK.png new file mode 100644 index 0000000000..e2b4acf44e Binary files /dev/null and b/Modules/Simulation/Documentation/doxygen/SOFA_MITK.png differ diff --git a/Modules/Simulation/Documentation/doxygen/SimulationPreferences.png b/Modules/Simulation/Documentation/doxygen/SimulationPreferences.png new file mode 100644 index 0000000000..ee82e3ef41 Binary files /dev/null and b/Modules/Simulation/Documentation/doxygen/SimulationPreferences.png differ diff --git a/Modules/Simulation/files.cmake b/Modules/Simulation/files.cmake index 92064e233b..4284af92e6 100644 --- a/Modules/Simulation/files.cmake +++ b/Modules/Simulation/files.cmake @@ -1,10 +1,13 @@ set(CPP_FILES mitkSimulation.cpp mitkSimulationDrawTool.cpp - mitkSimulationPropAssemblyVisitor.cpp mitkSimulationIOFactory.cpp mitkSimulationMapper3D.cpp - mitkSimulationReader.cpp - mitkSimulationObjectFactory.cpp mitkSimulationModel.cpp + mitkSimulationObjectFactory.cpp + mitkSimulationPropAssemblyVisitor.cpp + mitkSimulationReader.cpp + mitkSimulationTemplate.cpp + mitkSimulationTemplateIOFactory.cpp + mitkSimulationTemplateReader.cpp ) diff --git a/Modules/Simulation/mitkSimulation.cpp b/Modules/Simulation/mitkSimulation.cpp index c499c7b059..17e3bded61 100644 --- a/Modules/Simulation/mitkSimulation.cpp +++ b/Modules/Simulation/mitkSimulation.cpp @@ -1,238 +1,245 @@ /*=================================================================== 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 "mitkSimulation.h" #include "mitkSimulationPropAssemblyVisitor.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include -const float mitk::Simulation::ScaleFactor = 1000.0f; +const float mitk::Simulation::ScaleFactor = 1.0f; // 1000.0f static sofa::simulation::Simulation::SPtr CreateSimulation(mitk::Simulation::SimulationType type = mitk::Simulation::Tree) { if (type == mitk::Simulation::DAG) return sofa::core::objectmodel::New(); else if (type == mitk::Simulation::Bgl) return sofa::core::objectmodel::New(); else return sofa::core::objectmodel::New(); } void mitk::Simulation::SetActiveSimulation(mitk::Simulation* simulation) { if (simulation == NULL) { sofa::simulation::setSimulation(NULL); sofa::core::visual::VisualParams::defaultInstance()->drawTool() = NULL; } else { sofa::simulation::Simulation* sofaSimulation = simulation->m_Simulation.get(); if (sofa::simulation::getSimulation() != sofaSimulation) { sofa::simulation::setSimulation(sofaSimulation); sofa::core::visual::VisualParams::defaultInstance()->drawTool() = &simulation->m_DrawTool; } } } mitk::Simulation::Simulation() : m_Simulation(CreateSimulation()), m_DefaultDT(0.0) { } mitk::Simulation::~Simulation() { if (m_Simulation != NULL) { if (m_RootNode != NULL) m_Simulation->unload(m_RootNode); if (sofa::simulation::getSimulation() == m_Simulation.get()) SetActiveSimulation(NULL); } } -void mitk::Simulation::AppendSnapshot(mitk::Surface::Pointer surface) const +bool mitk::Simulation::AppendSnapshot(mitk::Surface::Pointer surface) const { - if (surface.IsNull()) - return; + if (surface.IsNotNull()) + { + vtkSmartPointer snapshot = this->CreateSnapshot(); - vtkSmartPointer snapshot = this->CreateSnapshot(); + if (snapshot != NULL) + { + unsigned int timeStep = surface->GetSizeOfPolyDataSeries(); - if (snapshot != NULL) - { - unsigned int timeStep = surface->GetSizeOfPolyDataSeries(); + if (timeStep != 0 && surface->GetVtkPolyData(timeStep - 1) == NULL) + --timeStep; - if (timeStep != 0 && surface->GetVtkPolyData(timeStep - 1) == NULL) - --timeStep; + surface->SetVtkPolyData(snapshot, timeStep); - surface->SetVtkPolyData(snapshot, timeStep); + return true; + } } + + return false; } vtkSmartPointer mitk::Simulation::CreateSnapshot() const { if (m_RootNode == NULL) return NULL; vtkSmartPointer propAssembly = vtkSmartPointer::New(); SimulationPropAssemblyVisitor propAssemblyVisitor(propAssembly); m_RootNode->executeVisitor(&propAssemblyVisitor); vtkSmartPointer appendFilter = vtkSmartPointer::New(); vtkPropCollection* propCollection = propAssembly->GetParts(); vtkProp* prop = NULL; + if (propCollection->GetNumberOfItems() == 0) + return NULL; + for (propCollection->InitTraversal(); (prop = propCollection->GetNextProp()) != NULL; ) { vtkActor* actor = vtkActor::SafeDownCast(prop); vtkPolyData* polyData = vtkPolyData::SafeDownCast(actor->GetMapper()->GetInput()); appendFilter->AddInput(polyData); } vtkSmartPointer scaleTransform = vtkSmartPointer::New(); scaleTransform->Scale(ScaleFactor, ScaleFactor, ScaleFactor); vtkSmartPointer transformFilter = vtkSmartPointer::New(); transformFilter->SetInputConnection(appendFilter->GetOutputPort()); transformFilter->SetTransform(scaleTransform); transformFilter->Update(); vtkSmartPointer snapshot = vtkSmartPointer::New(); snapshot->ShallowCopy(transformFilter->GetOutputDataObject(0)); return snapshot; } double mitk::Simulation::GetDefaultDT() const { return m_DefaultDT; } mitk::SimulationDrawTool* mitk::Simulation::GetDrawTool() { return &m_DrawTool; } sofa::simulation::Node::SPtr mitk::Simulation::GetRootNode() const { return m_RootNode; } sofa::simulation::Simulation::SPtr mitk::Simulation::GetSimulation() const { return m_Simulation; } bool mitk::Simulation::RequestedRegionIsOutsideOfTheBufferedRegion() { return false; } void mitk::Simulation::SetAsActiveSimulation() { SetActiveSimulation(this); } void mitk::Simulation::SetDefaultDT(double dt) { m_DefaultDT = std::max(0.0, dt); } void mitk::Simulation::SetRequestedRegion(itk::DataObject*) { } void mitk::Simulation::SetRequestedRegionToLargestPossibleRegion() { } void mitk::Simulation::SetRootNode(sofa::simulation::Node* rootNode) { m_RootNode.reset(rootNode); } mitk::Surface::Pointer mitk::Simulation::TakeSnapshot() const { vtkSmartPointer snapshot = this->CreateSnapshot(); if (snapshot == NULL) return NULL; Surface::Pointer surface = Surface::New(); surface->SetVtkPolyData(snapshot); return surface; } void mitk::Simulation::UpdateOutputInformation() { if (this->GetSource().IsNotNull()) this->GetSource()->UpdateOutputInformation(); if (m_RootNode != NULL) { const sofa::defaulttype::BoundingBox& boundingBox = m_RootNode->f_bbox.getValue(); const sofa::defaulttype::Vector3& min = boundingBox.minBBox(); const sofa::defaulttype::Vector3& max = boundingBox.maxBBox(); mitk::Geometry3D::BoundsArrayType bounds; bounds[0] = static_cast(min.x() * ScaleFactor); bounds[1] = static_cast(max.x() * ScaleFactor); bounds[2] = static_cast(min.y() * ScaleFactor); bounds[3] = static_cast(max.y() * ScaleFactor); bounds[4] = static_cast(min.z() * ScaleFactor); bounds[5] = static_cast(max.z() * ScaleFactor); if(this->GetGeometry() != NULL) { this->GetGeometry()->SetBounds(bounds); } else { Geometry3D::Pointer geometry = Geometry3D::New(); geometry->SetBounds(bounds); this->SetGeometry(geometry); } } this->GetTimeSlicedGeometry()->UpdateInformation(); } bool mitk::Simulation::VerifyRequestedRegion() { return true; } diff --git a/Modules/Simulation/mitkSimulation.h b/Modules/Simulation/mitkSimulation.h index d58c61a614..5c67c54911 100644 --- a/Modules/Simulation/mitkSimulation.h +++ b/Modules/Simulation/mitkSimulation.h @@ -1,77 +1,77 @@ /*=================================================================== 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 mitkSimulation_h #define mitkSimulation_h #include "mitkSimulationDrawTool.h" #include #include #include #include #include namespace mitk { class Simulation_EXPORT Simulation : public BaseData { public: enum SimulationType { Tree, DAG, Bgl }; mitkClassMacro(Simulation, BaseData); itkNewMacro(Self); static void SetActiveSimulation(Self* simulation); static const float ScaleFactor; - void AppendSnapshot(Surface::Pointer surface) const; + bool AppendSnapshot(Surface::Pointer surface) const; double GetDefaultDT() const; SimulationDrawTool* GetDrawTool(); sofa::simulation::Node::SPtr GetRootNode() const; sofa::simulation::Simulation::SPtr GetSimulation() const; bool RequestedRegionIsOutsideOfTheBufferedRegion(); void SetAsActiveSimulation(); void SetDefaultDT(double dt); void SetRequestedRegion(itk::DataObject* data); void SetRequestedRegionToLargestPossibleRegion(); void SetRootNode(sofa::simulation::Node* rootNode); Surface::Pointer TakeSnapshot() const; void UpdateOutputInformation(); bool VerifyRequestedRegion(); private: Simulation(); ~Simulation(); Simulation(Self&); Self& operator=(const Self&); vtkSmartPointer CreateSnapshot() const; sofa::simulation::Simulation::SPtr m_Simulation; sofa::simulation::Node::SPtr m_RootNode; SimulationDrawTool m_DrawTool; double m_DefaultDT; }; } #endif diff --git a/Modules/Simulation/mitkSimulationObjectFactory.cpp b/Modules/Simulation/mitkSimulationObjectFactory.cpp index ff1c0cef4b..0e70e52e6e 100644 --- a/Modules/Simulation/mitkSimulationObjectFactory.cpp +++ b/Modules/Simulation/mitkSimulationObjectFactory.cpp @@ -1,128 +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 "mitkSimulation.h" #include "mitkSimulationMapper3D.h" -#include "mitkSimulationObjectFactory.h" #include "mitkSimulationModel.h" +#include "mitkSimulationObjectFactory.h" +#include "mitkSimulationTemplate.h" #include #include #include #include +static void InitializeSOFA() +{ + sofa::component::init(); + sofa::simulation::xml::initXml(); + + int SimulationModelClass = sofa::core::RegisterObject("").add(); + sofa::core::ObjectFactory::AddAlias("OglModel", "SimulationModel", true); + sofa::core::ObjectFactory::AddAlias("VisualModel", "SimulationModel", true); +} + mitk::SimulationObjectFactory::SimulationObjectFactory() - : m_SimulationIOFactory(SimulationIOFactory::New()) + : m_SimulationIOFactory(SimulationIOFactory::New()), + m_SimulationTemplateIOFactory(SimulationTemplateIOFactory::New()) { itk::ObjectFactoryBase::RegisterFactory(m_SimulationIOFactory); + itk::ObjectFactoryBase::RegisterFactory(m_SimulationTemplateIOFactory); - const std::string description = "SOFA Scene Files"; + std::string description = "SOFA Scene Files"; m_FileExtensionsMap.insert(std::pair("*.scn", description)); m_FileExtensionsMap.insert(std::pair("*.xml", description)); - sofa::component::init(); - sofa::simulation::xml::initXml(); + description = "SOFA Scene File Templates"; + m_FileExtensionsMap.insert(std::pair("*.scn.template", description)); + m_FileExtensionsMap.insert(std::pair("*.xml.template", description)); - int SimulationModelClass = sofa::core::RegisterObject("").add(); - sofa::core::ObjectFactory::AddAlias("OglModel", "SimulationModel", true); - sofa::core::ObjectFactory::AddAlias("VisualModel", "SimulationModel", true); + InitializeSOFA(); } mitk::SimulationObjectFactory::~SimulationObjectFactory() { + itk::ObjectFactoryBase::UnRegisterFactory(m_SimulationTemplateIOFactory); itk::ObjectFactoryBase::UnRegisterFactory(m_SimulationIOFactory); } mitk::Mapper::Pointer mitk::SimulationObjectFactory::CreateMapper(mitk::DataNode* node, MapperSlotId slotId) { mitk::Mapper::Pointer mapper; if (dynamic_cast(node->GetData()) != NULL) { if (slotId == mitk::BaseRenderer::Standard3D) mapper = mitk::SimulationMapper3D::New(); if (mapper.IsNotNull()) mapper->SetDataNode(node); } return mapper; } const char* mitk::SimulationObjectFactory::GetDescription() const { return "mitk::SimulationObjectFactory"; } const char* mitk::SimulationObjectFactory::GetFileExtensions() { std::string fileExtensions; this->CreateFileExtensions(m_FileExtensionsMap, fileExtensions); return fileExtensions.c_str(); } mitk::CoreObjectFactoryBase::MultimapType mitk::SimulationObjectFactory::GetFileExtensionsMap() { return m_FileExtensionsMap; } const char* mitk::SimulationObjectFactory::GetITKSourceVersion() const { return ITK_SOURCE_VERSION; } const char* mitk::SimulationObjectFactory::GetSaveFileExtensions() { std::string saveFileExtensions; this->CreateFileExtensions(m_FileExtensionsMap, saveFileExtensions); return saveFileExtensions.c_str(); } mitk::CoreObjectFactoryBase::MultimapType mitk::SimulationObjectFactory::GetSaveFileExtensionsMap() { return m_SaveFileExtensionsMap; } void mitk::SimulationObjectFactory::SetDefaultProperties(mitk::DataNode* node) { if (node != NULL) { if (dynamic_cast(node->GetData()) != NULL) + { SimulationMapper3D::SetDefaultProperties(node); + } + else if (dynamic_cast(node->GetData()) != NULL) + { + SimulationTemplate* simulationTemplate = static_cast(node->GetData()); + simulationTemplate->SetProperties(node); + } } } -class RegisterSimulationObjectFactory +void mitk::RegisterSimulationObjectFactory() { -public: - RegisterSimulationObjectFactory() - : m_Factory(mitk::SimulationObjectFactory::New()) - { - mitk::CoreObjectFactory::GetInstance()->RegisterExtraFactory(m_Factory); - } + static bool alreadyRegistered = false; - ~RegisterSimulationObjectFactory() + if (!alreadyRegistered) { - mitk::CoreObjectFactory::GetInstance()->UnRegisterExtraFactory(m_Factory); + mitk::CoreObjectFactory::GetInstance()->RegisterExtraFactory(mitk::SimulationObjectFactory::New()); + alreadyRegistered = true; } - -private: - RegisterSimulationObjectFactory(const RegisterSimulationObjectFactory&); - RegisterSimulationObjectFactory& operator=(const RegisterSimulationObjectFactory&); - - mitk::SimulationObjectFactory::Pointer m_Factory; -}; - -static RegisterSimulationObjectFactory registerSimulationObjectFactory; +} diff --git a/Modules/Simulation/mitkSimulationObjectFactory.h b/Modules/Simulation/mitkSimulationObjectFactory.h index 501eb21f84..c07742ed6b 100644 --- a/Modules/Simulation/mitkSimulationObjectFactory.h +++ b/Modules/Simulation/mitkSimulationObjectFactory.h @@ -1,53 +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 mitkSimulationObjectFactory_h #define mitkSimulationObjectFactory_h #include "mitkSimulationIOFactory.h" +#include "mitkSimulationTemplateIOFactory.h" #include namespace mitk { class Simulation_EXPORT SimulationObjectFactory : public CoreObjectFactoryBase { public: mitkClassMacro(SimulationObjectFactory, CoreObjectFactoryBase); itkFactorylessNewMacro(Self); Mapper::Pointer CreateMapper(DataNode* node, MapperSlotId slotId); const char* GetDescription() const; const char* GetFileExtensions(); MultimapType GetFileExtensionsMap(); const char* GetITKSourceVersion() const; const char* GetSaveFileExtensions(); MultimapType GetSaveFileExtensionsMap(); void SetDefaultProperties(DataNode* node); private: SimulationObjectFactory(); ~SimulationObjectFactory(); SimulationObjectFactory(const Self&); Self& operator=(const Self&); SimulationIOFactory::Pointer m_SimulationIOFactory; + SimulationTemplateIOFactory::Pointer m_SimulationTemplateIOFactory; MultimapType m_FileExtensionsMap; MultimapType m_SaveFileExtensionsMap; }; + + Simulation_EXPORT void RegisterSimulationObjectFactory(); } #endif diff --git a/Modules/Simulation/mitkSimulationReader.h b/Modules/Simulation/mitkSimulationReader.h index 8d8783ac6a..e8f32059f9 100644 --- a/Modules/Simulation/mitkSimulationReader.h +++ b/Modules/Simulation/mitkSimulationReader.h @@ -1,59 +1,60 @@ /*=================================================================== 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 mitkSimulationReader_h #define mitkSimulationReader_h #include #include +#include namespace mitk { class Simulation_EXPORT SimulationReader : public BaseProcess, FileReader { public: static bool CanReadFile(const std::string& filename, const std::string& filePrefix, const std::string& filePattern); mitkClassMacro(SimulationReader, BaseProcess); itkNewMacro(Self); const char* GetFileName() const; void SetFileName(const char* aFileName); const char* GetFilePattern() const; void SetFilePattern(const char* aFilePattern); const char* GetFilePrefix() const; void SetFilePrefix(const char* aFilePrefix); protected: void GenerateData(); void GenerateOutputInformation(); private: SimulationReader(); ~SimulationReader(); SimulationReader(const Self &); Self & operator=(const Self &); std::string m_FileName; std::string m_FilePattern; std::string m_FilePrefix; }; } #endif diff --git a/Modules/Simulation/mitkSimulationTemplate.cpp b/Modules/Simulation/mitkSimulationTemplate.cpp new file mode 100644 index 0000000000..238ddd3e26 --- /dev/null +++ b/Modules/Simulation/mitkSimulationTemplate.cpp @@ -0,0 +1,316 @@ +/*=================================================================== + +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 "mitkSimulationTemplate.h" +#include +#include + +typedef std::vector > TemplateIndex; +typedef std::vector > VariableContents; + +static TemplateIndex CreateTemplateIndex(const std::string& contents) +{ + TemplateIndex templateIndex; + + std::string::size_type begin = 0; + begin = contents.find_first_of('{', 0); + + while (begin != std::string::npos) + { + std::string::size_type end = contents.find_first_of('}', begin); + + if (end == std::string::npos) + mitkThrow() << "Expected closing brace before end of file!"; + + templateIndex.push_back(std::make_pair(begin, ++end - begin)); + + begin = contents.find_first_of('{', end); + } + + if (templateIndex.empty()) + mitkThrow() << "No templates found!"; + + return templateIndex; +} + +static std::vector ParseStaticContents(const std::string& contents, const TemplateIndex& templateIndex) +{ + std::vector staticContents; + std::string::size_type index = 0; + + for (TemplateIndex::const_iterator it = templateIndex.begin(); it != templateIndex.end(); ++it) + { + staticContents.push_back(contents.substr(index, it->first - index)); + index = it->first + it->second; + } + + staticContents.push_back(contents.substr(index)); + + return staticContents; +} + +static std::string ParseValue(const std::string& templ, const std::string& valueName) +{ + const char* spaces = " \t\n"; + std::string::size_type index = templ.find(valueName); + + if (index != std::string::npos) + { + index += valueName.length(); + index = templ.find_first_not_of(spaces, index); + + if (index != std::string::npos && templ[index] == '=') + { + ++index; + index = templ.find_first_not_of(spaces, index); + + if (index != std::string::npos && templ[index] == '\'') + { + ++index; + std::string::size_type length = templ.find_first_of('\'', index); + + if (length != std::string::npos) + { + length -= index; + return templ.substr(index, length); + } + } + } + } + + return ""; +} + +template T FromString(const std::string& string) +{ + std::istringstream stream(string); + + T value; + stream >> value; + + return value; +} + +static std::pair ParseReference(const std::string& ref) +{ + std::string id = "{ref}"; + mitk::StringProperty::Pointer property = mitk::StringProperty::New(ref.substr(2, ref.length() - 4)); + + return std::make_pair(id, property); +} + +static std::pair ParseTemplate(const std::string& templ) +{ + if (templ.length() > 4 && templ[1] == '\'') + { + return ParseReference(templ); + } + else + { + std::string id = ParseValue(templ, "id"); + + if (!id.empty()) + { + std::string type = ParseValue(templ, "type"); + + if (type.empty()) + type = "string"; + + mitk::BaseProperty::Pointer property; + std::string defaultValue = ParseValue(templ, "default"); + + if (type == "float") + { + float value = !defaultValue.empty() + ? FromString(defaultValue) + : 0.0; + + property = mitk::FloatProperty::New(value); + } + else if (type == "int") + { + int value = !defaultValue.empty() + ? FromString(defaultValue) + : 0.0; + + property = mitk::IntProperty::New(value); + } + else if (type == "string") + { + std::string value = !defaultValue.empty() + ? defaultValue + : ""; + + property = mitk::StringProperty::New(value); + } + + if (property.IsNotNull()) + return std::make_pair(id, property); + } + } + + std::string emptyString; + mitk::BaseProperty::Pointer nullPointer; + + return std::make_pair(emptyString, nullPointer); +} + +static VariableContents ParseVariableContents(const std::string& contents, const TemplateIndex& templateIndex) +{ + VariableContents variableContents; + + for (TemplateIndex::const_iterator it = templateIndex.begin(); it != templateIndex.end(); ++it) + { + std::string templ = contents.substr(it->first, it->second); + std::pair variableContent = ParseTemplate(templ); + + if (variableContent.first.empty() || variableContent.second.IsNull()) + mitkThrow() << "Could not parse " << templ << "!"; + + variableContents.push_back(variableContent); + } + + return variableContents; +} + +template +class FirstEqualTo +{ +public: + FirstEqualTo(const T1& value) + : m_Value(value) + { + } + + bool operator()(const std::pair& pair) const + { + return pair.first == m_Value; + } + +private: + T1 m_Value; +}; + +mitk::SimulationTemplate::SimulationTemplate() + : m_IsInitialized(false) +{ +} + +mitk::SimulationTemplate::~SimulationTemplate() +{ +} + +std::string mitk::SimulationTemplate::Bake() const +{ + if (!m_IsInitialized) + { + MITK_ERROR << "Simulation template is not initialized!"; + return ""; + } + + std::string contents; + + for (VariableContents::size_type i = 0; i < m_VariableContents.size(); ++i) + { + contents += m_StaticContents[i]; + + if (m_VariableContents[i].first == "{ref}") + { + VariableContents::const_iterator it = std::find_if(m_VariableContents.begin(), m_VariableContents.end(), + FirstEqualTo(m_VariableContents[i].second->GetValueAsString())); + + if (it == m_VariableContents.end()) + { + MITK_ERROR << "Template '" << m_VariableContents[i].second << "' not found!"; + return ""; + } + + contents += it->second->GetValueAsString(); + } + else + { + contents += m_VariableContents[i].second->GetValueAsString(); + } + } + + contents += m_StaticContents.back(); + + return contents; +} + +bool mitk::SimulationTemplate::Parse(const std::string& contents) +{ + if (m_IsInitialized) + return false; + + TemplateIndex templateIndex = CreateTemplateIndex(contents); + std::vector staticContents = ParseStaticContents(contents, templateIndex); + VariableContents variableContents = ParseVariableContents(contents, templateIndex); + + std::swap(m_StaticContents, staticContents); + std::swap(m_VariableContents, variableContents); + m_IsInitialized = true; + + return true; +} + +bool mitk::SimulationTemplate::RequestedRegionIsOutsideOfTheBufferedRegion() +{ + return false; +} + +void mitk::SimulationTemplate::SetProperties(mitk::DataNode::Pointer dataNode) const +{ + if (dataNode.IsNull()) + return; + + if (!m_IsInitialized) + { + MITK_ERROR << "Simulation template is not initialized!"; + return; + } + + if (dynamic_cast(dataNode->GetData()) != this) + { + MITK_ERROR << "Data node does not own this simulation template!"; + return; + } + + for(VariableContents::const_iterator it = m_VariableContents.begin(); it != m_VariableContents.end(); ++it) + { + if (it->first != "{ref}") + dataNode->SetProperty(it->first.c_str(), it->second.GetPointer()); + } +} + +void mitk::SimulationTemplate::SetRequestedRegion(itk::DataObject*) +{ +} + +void mitk::SimulationTemplate::SetRequestedRegionToLargestPossibleRegion() +{ +} + +void mitk::SimulationTemplate::UpdateOutputInformation() +{ + if (this->GetSource().IsNotNull()) + this->GetSource()->UpdateOutputInformation(); +} + +bool mitk::SimulationTemplate::VerifyRequestedRegion() +{ + return true; +} diff --git a/Modules/Simulation/mitkSimulationTemplate.h b/Modules/Simulation/mitkSimulationTemplate.h new file mode 100644 index 0000000000..75f9f81e9b --- /dev/null +++ b/Modules/Simulation/mitkSimulationTemplate.h @@ -0,0 +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 mitkSimulationTemplate_h +#define mitkSimulationTemplate_h + +#include +#include +#include +#include +#include +#include + +namespace mitk +{ + class Simulation_EXPORT SimulationTemplate : public BaseData + { + public: + mitkClassMacro(SimulationTemplate, BaseData); + itkNewMacro(Self); + + std::string Bake() const; + bool Parse(const std::string& contents); + bool RequestedRegionIsOutsideOfTheBufferedRegion(); + void SetProperties(DataNode::Pointer dataNode) const; + void SetRequestedRegion(itk::DataObject* data); + void SetRequestedRegionToLargestPossibleRegion(); + void UpdateOutputInformation(); + bool VerifyRequestedRegion(); + + private: + SimulationTemplate(); + ~SimulationTemplate(); + + SimulationTemplate(Self&); + Self& operator=(const Self&); + + bool m_IsInitialized; + std::vector m_StaticContents; + std::vector > m_VariableContents; + }; +} + +#endif diff --git a/Modules/Simulation/mitkSimulationTemplateIOFactory.cpp b/Modules/Simulation/mitkSimulationTemplateIOFactory.cpp new file mode 100644 index 0000000000..67ddfd2373 --- /dev/null +++ b/Modules/Simulation/mitkSimulationTemplateIOFactory.cpp @@ -0,0 +1,45 @@ +/*=================================================================== + +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 "mitkSimulationTemplateIOFactory.h" +#include "mitkSimulationTemplateReader.h" +#include +#include + +mitk::SimulationTemplateIOFactory::SimulationTemplateIOFactory() +{ + + this->RegisterOverride( + "mitkIOAdapter", + "mitkSimulationTemplateReader", + "Simulation Template IO", + true, + itk::CreateObjectFunction >::New()); +} + +mitk::SimulationTemplateIOFactory::~SimulationTemplateIOFactory() +{ +} + +const char* mitk::SimulationTemplateIOFactory::GetDescription() const +{ + return "mitk::SimulationTemplateIOFactory"; +} + +const char* mitk::SimulationTemplateIOFactory::GetITKSourceVersion() const +{ + return ITK_SOURCE_VERSION; +} diff --git a/Modules/Simulation/mitkSimulationTemplateIOFactory.h b/Modules/Simulation/mitkSimulationTemplateIOFactory.h new file mode 100644 index 0000000000..b616a1001e --- /dev/null +++ b/Modules/Simulation/mitkSimulationTemplateIOFactory.h @@ -0,0 +1,44 @@ +/*=================================================================== + +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 mitkSimulationTemplateIOFactory_h +#define mitkSimulationTemplateIOFactory_h + +#include +#include +#include + +namespace mitk +{ + class Simulation_EXPORT SimulationTemplateIOFactory : public itk::ObjectFactoryBase + { + public: + mitkClassMacro(SimulationTemplateIOFactory, itk::ObjectFactoryBase); + itkFactorylessNewMacro(Self); + + const char* GetDescription() const; + const char* GetITKSourceVersion() const; + + private: + SimulationTemplateIOFactory(); + ~SimulationTemplateIOFactory(); + + SimulationTemplateIOFactory(const Self&); + Self& operator=(const Self&); + }; +}; + +#endif diff --git a/Modules/Simulation/mitkSimulationTemplateReader.cpp b/Modules/Simulation/mitkSimulationTemplateReader.cpp new file mode 100644 index 0000000000..83fb4e1cbf --- /dev/null +++ b/Modules/Simulation/mitkSimulationTemplateReader.cpp @@ -0,0 +1,113 @@ +/*=================================================================== + +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 "mitkSimulationTemplate.h" +#include "mitkSimulationTemplateReader.h" +#include +#include +#include + +static std::string ReadFile(const std::string& fileName) +{ + std::ifstream file(fileName); + + if (!file.is_open()) + mitkThrow() << "Could not load '" << fileName << "'!"; + + std::string contents; + + file.seekg(0, std::ios::end); + contents.resize(file.tellg()); + file.seekg(0, std::ios::beg); + file.read(&contents[0], contents.size()); + + file.close(); + + if (contents.empty()) + mitkThrow() << fileName << " is empty!"; + + return contents; +} + +bool mitk::SimulationTemplateReader::CanReadFile(const std::string& filename, const std::string&, const std::string&) +{ + std::string::size_type length = filename.length(); + + if (length < 14) + return false; + + std::string ext = filename.substr(length - 13); + std::transform(ext.begin(), ext.end(), ext.begin(), tolower); + + if (ext == ".scn.template" || ext == ".xml.template") + return true; + + return false; +} + +mitk::SimulationTemplateReader::SimulationTemplateReader() +{ + mitk::SimulationTemplate::Pointer output = mitk::SimulationTemplate::New(); + + this->SetNumberOfRequiredOutputs(1); + this->SetNthOutput(0, output.GetPointer()); +} + +mitk::SimulationTemplateReader::~SimulationTemplateReader() +{ +} + +void mitk::SimulationTemplateReader::GenerateData() +{ + SimulationTemplate::Pointer simulationTemplate = dynamic_cast(this->GetOutput(0)); + + std::string contents = ReadFile(m_FileName); + simulationTemplate->Parse(contents); +} + +void mitk::SimulationTemplateReader::GenerateOutputInformation() +{ +} + +const char* mitk::SimulationTemplateReader::GetFileName() const +{ + return m_FileName.c_str(); +} + +void mitk::SimulationTemplateReader::SetFileName(const char* aFileName) +{ + m_FileName = aFileName; +} + +const char* mitk::SimulationTemplateReader::GetFilePattern() const +{ + return m_FilePattern.c_str(); +} + +void mitk::SimulationTemplateReader::SetFilePattern(const char* aFilePattern) +{ + m_FilePattern = aFilePattern; +} + +const char* mitk::SimulationTemplateReader::GetFilePrefix() const +{ + return m_FilePrefix.c_str(); +} + +void mitk::SimulationTemplateReader::SetFilePrefix(const char* aFilePrefix) +{ + m_FilePrefix = aFilePrefix; +} diff --git a/Modules/Simulation/mitkSimulationReader.h b/Modules/Simulation/mitkSimulationTemplateReader.h similarity index 77% copy from Modules/Simulation/mitkSimulationReader.h copy to Modules/Simulation/mitkSimulationTemplateReader.h index 8d8783ac6a..0cbb8d7100 100644 --- a/Modules/Simulation/mitkSimulationReader.h +++ b/Modules/Simulation/mitkSimulationTemplateReader.h @@ -1,59 +1,60 @@ /*=================================================================== 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 mitkSimulationReader_h -#define mitkSimulationReader_h +#ifndef mitkSimulationTemplateReader_h +#define mitkSimulationTemplateReader_h #include #include +#include namespace mitk { - class Simulation_EXPORT SimulationReader : public BaseProcess, FileReader + class Simulation_EXPORT SimulationTemplateReader : public BaseProcess, FileReader { public: static bool CanReadFile(const std::string& filename, const std::string& filePrefix, const std::string& filePattern); - mitkClassMacro(SimulationReader, BaseProcess); + mitkClassMacro(SimulationTemplateReader, BaseProcess); itkNewMacro(Self); const char* GetFileName() const; void SetFileName(const char* aFileName); const char* GetFilePattern() const; void SetFilePattern(const char* aFilePattern); const char* GetFilePrefix() const; void SetFilePrefix(const char* aFilePrefix); protected: void GenerateData(); void GenerateOutputInformation(); private: - SimulationReader(); - ~SimulationReader(); + SimulationTemplateReader(); + ~SimulationTemplateReader(); - SimulationReader(const Self &); + SimulationTemplateReader(const Self &); Self & operator=(const Self &); std::string m_FileName; std::string m_FilePattern; std::string m_FilePrefix; }; } #endif diff --git a/Plugins/PluginList.cmake b/Plugins/PluginList.cmake index e4a3dbea38..0ee96249d6 100644 --- a/Plugins/PluginList.cmake +++ b/Plugins/PluginList.cmake @@ -1,47 +1,48 @@ # Plug-ins must be ordered according to their dependencies set(MITK_EXT_PLUGINS org.mitk.core.services:ON org.mitk.gui.common:ON org.mitk.planarfigure:ON org.mitk.core.ext:OFF org.mitk.core.jobs:OFF org.mitk.diffusionimaging:OFF + org.mitk.simulation:OFF org.mitk.gui.qt.application:ON org.mitk.gui.qt.coreapplication:OFF org.mitk.gui.qt.ext:OFF org.mitk.gui.qt.extapplication:OFF org.mitk.gui.qt.common:ON org.mitk.gui.qt.stdmultiwidgeteditor:ON org.mitk.gui.qt.common.legacy:OFF org.mitk.gui.qt.cmdlinemodules:OFF org.mitk.gui.qt.diffusionimagingapp:OFF org.mitk.gui.qt.datamanager:ON org.mitk.gui.qt.datamanagerlight:OFF org.mitk.gui.qt.properties:OFF org.mitk.gui.qt.basicimageprocessing:OFF org.mitk.gui.qt.dicom:OFF org.mitk.gui.qt.diffusionimaging:OFF org.mitk.gui.qt.dtiatlasapp:OFF org.mitk.gui.qt.examples:OFF org.mitk.gui.qt.examplesopencv:OFF org.mitk.gui.qt.igtexamples:OFF org.mitk.gui.qt.igttracking:OFF org.mitk.gui.qt.imagecropper:OFF org.mitk.gui.qt.imagenavigator:ON org.mitk.gui.qt.materialeditor:OFF org.mitk.gui.qt.measurementtoolbox:OFF org.mitk.gui.qt.meshdecimation:OFF org.mitk.gui.qt.moviemaker:OFF org.mitk.gui.qt.pointsetinteraction:OFF org.mitk.gui.qt.python:OFF org.mitk.gui.qt.registration:OFF org.mitk.gui.qt.segmentation:OFF org.mitk.gui.qt.simulation:OFF org.mitk.gui.qt.toftutorial:OFF org.mitk.gui.qt.tofutil:OFF org.mitk.gui.qt.ugvisualization:OFF org.mitk.gui.qt.ultrasound:OFF org.mitk.gui.qt.volumevisualization:OFF ) diff --git a/Plugins/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.cpp b/Plugins/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.cpp index e451201301..1559bf6db5 100644 --- a/Plugins/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.cpp +++ b/Plugins/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.cpp @@ -1,946 +1,950 @@ /*=================================================================== 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 "QmitkDataManagerView.h" #include //# Own Includes //## mitk #include "mitkDataStorageEditorInput.h" #include "mitkIDataStorageReference.h" #include "mitkNodePredicateDataType.h" #include "mitkCoreObjectFactory.h" #include "mitkPACSPlugin.h" #include "mitkDataNodeFactory.h" #include "mitkColorProperty.h" #include "mitkCommon.h" #include "mitkDelegateManager.h" #include "mitkNodePredicateData.h" #include "mitkNodePredicateNot.h" #include "mitkNodePredicateProperty.h" #include "mitkEnumerationProperty.h" #include "mitkProperties.h" #include #include #include #include //## Qmitk #include #include #include #include #include #include #include #include "src/internal/QmitkNodeTableViewKeyFilter.h" #include "src/internal/QmitkInfoDialog.h" //## Berry #include #include #include #include #include #include //# Toolkit Includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "mitkDataNodeObject.h" #include "mitkIContextMenuAction.h" #include "berryIExtensionPointService.h" const std::string QmitkDataManagerView::VIEW_ID = "org.mitk.views.datamanager"; QmitkDataManagerView::QmitkDataManagerView() : m_GlobalReinitOnNodeDelete(true) { } QmitkDataManagerView::~QmitkDataManagerView() { //Remove all registered actions from each descriptor for (std::vector< std::pair< QmitkNodeDescriptor*, QAction* > >::iterator it = m_DescriptorActionList.begin();it != m_DescriptorActionList.end(); it++) { // first== the NodeDescriptor; second== the registered QAction (it->first)->RemoveAction(it->second); } } void QmitkDataManagerView::CreateQtPartControl(QWidget* parent) { m_CurrentRowCount = 0; m_Parent = parent; //# Preferences berry::IPreferencesService::Pointer prefService = berry::Platform::GetServiceRegistry() .GetServiceById(berry::IPreferencesService::ID); berry::IBerryPreferences::Pointer prefs = (prefService->GetSystemPreferences()->Node(VIEW_ID)) .Cast(); assert( prefs ); prefs->OnChanged.AddListener( berry::MessageDelegate1( this , &QmitkDataManagerView::OnPreferencesChanged ) ); //# GUI m_NodeTreeModel = new QmitkDataStorageTreeModel(this->GetDataStorage()); m_NodeTreeModel->setParent( parent ); m_NodeTreeModel->SetPlaceNewNodesOnTop( prefs->GetBool("Place new nodes on top", true) ); m_NodeTreeModel->SetShowHelperObjects( prefs->GetBool("Show helper objects", false) ); m_NodeTreeModel->SetShowNodesContainingNoData( prefs->GetBool("Show nodes containing no data", false) ); m_SurfaceDecimation = prefs->GetBool("Use surface decimation", false); //# Tree View (experimental) m_NodeTreeView = new QTreeView; m_NodeTreeView->setSelectionMode( QAbstractItemView::ExtendedSelection ); m_NodeTreeView->setSelectionBehavior( QAbstractItemView::SelectRows ); m_NodeTreeView->setAlternatingRowColors(true); m_NodeTreeView->setDragEnabled(true); m_NodeTreeView->setDropIndicatorShown(true); m_NodeTreeView->setAcceptDrops(true); m_NodeTreeView->setContextMenuPolicy(Qt::CustomContextMenu); m_NodeTreeView->setModel(m_NodeTreeModel); m_NodeTreeView->setTextElideMode(Qt::ElideMiddle); m_NodeTreeView->installEventFilter(new QmitkNodeTableViewKeyFilter(this)); QObject::connect( m_NodeTreeView, SIGNAL(customContextMenuRequested(const QPoint&)) , this, SLOT(NodeTableViewContextMenuRequested(const QPoint&)) ); QObject::connect( m_NodeTreeModel, SIGNAL(rowsInserted (const QModelIndex&, int, int)) , this, SLOT(NodeTreeViewRowsInserted ( const QModelIndex&, int, int )) ); QObject::connect( m_NodeTreeModel, SIGNAL(rowsRemoved (const QModelIndex&, int, int)) , this, SLOT(NodeTreeViewRowsRemoved( const QModelIndex&, int, int )) ); QObject::connect( m_NodeTreeView->selectionModel() , SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection & ) ) , this , SLOT( NodeSelectionChanged ( const QItemSelection &, const QItemSelection & ) ) ); //# m_NodeMenu m_NodeMenu = new QMenu(m_NodeTreeView); // # Actions berry::IEditorRegistry* editorRegistry = berry::PlatformUI::GetWorkbench()->GetEditorRegistry(); std::list editors = editorRegistry->GetEditors("*.mitk"); if (editors.size() > 1) { m_ShowInMapper = new QSignalMapper(this); foreach(berry::IEditorDescriptor::Pointer descriptor, editors) { QAction* action = new QAction(QString::fromStdString(descriptor->GetLabel()), this); m_ShowInActions << action; m_ShowInMapper->connect(action, SIGNAL(triggered()), m_ShowInMapper, SLOT(map())); m_ShowInMapper->setMapping(action, QString::fromStdString(descriptor->GetId())); } connect(m_ShowInMapper, SIGNAL(mapped(QString)), this, SLOT(ShowIn(QString))); } QmitkNodeDescriptor* unknownDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetUnknownDataNodeDescriptor(); QmitkNodeDescriptor* imageDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("Image"); QmitkNodeDescriptor* surfaceDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("Surface"); QAction* globalReinitAction = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/Refresh_48.png"), "Global Reinit", this); QObject::connect( globalReinitAction, SIGNAL( triggered(bool) ) , this, SLOT( GlobalReinit(bool) ) ); unknownDataNodeDescriptor->AddAction(globalReinitAction); m_DescriptorActionList.push_back(std::pair(unknownDataNodeDescriptor, globalReinitAction)); QAction* saveAction = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/Save_48.png"), "Save...", this); QObject::connect( saveAction, SIGNAL( triggered(bool) ) , this, SLOT( SaveSelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(saveAction); m_DescriptorActionList.push_back(std::pair(unknownDataNodeDescriptor,saveAction)); QAction* removeAction = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/Remove_48.png"), "Remove", this); QObject::connect( removeAction, SIGNAL( triggered(bool) ) , this, SLOT( RemoveSelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(removeAction); m_DescriptorActionList.push_back(std::pair(unknownDataNodeDescriptor,removeAction)); QAction* reinitAction = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/Refresh_48.png"), "Reinit", this); QObject::connect( reinitAction, SIGNAL( triggered(bool) ) , this, SLOT( ReinitSelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(reinitAction); m_DescriptorActionList.push_back(std::pair(unknownDataNodeDescriptor,reinitAction)); // find contextMenuAction extension points and add them to the node descriptor berry::IExtensionPointService::Pointer extensionPointService = berry::Platform::GetExtensionPointService(); berry::IConfigurationElement::vector cmActions( extensionPointService->GetConfigurationElementsFor("org.mitk.gui.qt.datamanager.contextMenuActions") ); berry::IConfigurationElement::vector::iterator cmActionsIt; std::string cmNodeDescriptorName; std::string cmLabel; std::string cmIcon; std::string cmClass; QmitkNodeDescriptor* tmpDescriptor; QAction* contextMenuAction; QVariant cmActionDataIt; m_ConfElements.clear(); int i=1; for (cmActionsIt = cmActions.begin() ; cmActionsIt != cmActions.end() ; ++cmActionsIt) { cmIcon.erase(); if((*cmActionsIt)->GetAttribute("nodeDescriptorName", cmNodeDescriptorName) && (*cmActionsIt)->GetAttribute("label", cmLabel) && (*cmActionsIt)->GetAttribute("class", cmClass)) { (*cmActionsIt)->GetAttribute("icon", cmIcon); // create context menu entry here tmpDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor(QString::fromStdString(cmNodeDescriptorName)); if(!tmpDescriptor) { MITK_WARN << "cannot add action \"" << cmLabel << "\" because descriptor " << cmNodeDescriptorName << " does not exist"; continue; } contextMenuAction = new QAction( QString::fromStdString(cmLabel), parent); tmpDescriptor->AddAction(contextMenuAction); m_DescriptorActionList.push_back(std::pair(tmpDescriptor,contextMenuAction)); m_ConfElements[contextMenuAction] = *cmActionsIt; cmActionDataIt.setValue(i); contextMenuAction->setData( cmActionDataIt ); connect( contextMenuAction, SIGNAL( triggered(bool) ) , this, SLOT( ContextMenuActionTriggered(bool) ) ); ++i; } } m_OpacitySlider = new QSlider; m_OpacitySlider->setMinimum(0); m_OpacitySlider->setMaximum(100); m_OpacitySlider->setOrientation(Qt::Horizontal); QObject::connect( m_OpacitySlider, SIGNAL( valueChanged(int) ) , this, SLOT( OpacityChanged(int) ) ); QLabel* _OpacityLabel = new QLabel("Opacity: "); QHBoxLayout* _OpacityWidgetLayout = new QHBoxLayout; _OpacityWidgetLayout->setContentsMargins(4,4,4,4); _OpacityWidgetLayout->addWidget(_OpacityLabel); _OpacityWidgetLayout->addWidget(m_OpacitySlider); QWidget* _OpacityWidget = new QWidget; _OpacityWidget->setLayout(_OpacityWidgetLayout); QWidgetAction* opacityAction = new QWidgetAction(this); opacityAction ->setDefaultWidget(_OpacityWidget); QObject::connect( opacityAction , SIGNAL( changed() ) , this, SLOT( OpacityActionChanged() ) ); unknownDataNodeDescriptor->AddAction(opacityAction , false); m_DescriptorActionList.push_back(std::pair(unknownDataNodeDescriptor,opacityAction)); m_ColorButton = new QPushButton; m_ColorButton->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum); //m_ColorButton->setText("Change color"); QObject::connect( m_ColorButton, SIGNAL( clicked() ) , this, SLOT( ColorChanged() ) ); QLabel* _ColorLabel = new QLabel("Color: "); _ColorLabel->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); QHBoxLayout* _ColorWidgetLayout = new QHBoxLayout; _ColorWidgetLayout->setContentsMargins(4,4,4,4); _ColorWidgetLayout->addWidget(_ColorLabel); _ColorWidgetLayout->addWidget(m_ColorButton); QWidget* _ColorWidget = new QWidget; _ColorWidget->setLayout(_ColorWidgetLayout); QWidgetAction* colorAction = new QWidgetAction(this); colorAction->setDefaultWidget(_ColorWidget); QObject::connect( colorAction, SIGNAL( changed() ) , this, SLOT( ColorActionChanged() ) ); unknownDataNodeDescriptor->AddAction(colorAction, false); m_DescriptorActionList.push_back(std::pair(unknownDataNodeDescriptor,colorAction)); m_TextureInterpolation = new QAction("Texture Interpolation", this); m_TextureInterpolation->setCheckable ( true ); QObject::connect( m_TextureInterpolation, SIGNAL( changed() ) , this, SLOT( TextureInterpolationChanged() ) ); QObject::connect( m_TextureInterpolation, SIGNAL( toggled(bool) ) , this, SLOT( TextureInterpolationToggled(bool) ) ); imageDataNodeDescriptor->AddAction(m_TextureInterpolation, false); m_DescriptorActionList.push_back(std::pair(imageDataNodeDescriptor,m_TextureInterpolation)); m_SurfaceRepresentation = new QAction("Surface Representation", this); m_SurfaceRepresentation->setMenu(new QMenu); QObject::connect( m_SurfaceRepresentation->menu(), SIGNAL( aboutToShow() ) , this, SLOT( SurfaceRepresentationMenuAboutToShow() ) ); surfaceDataNodeDescriptor->AddAction(m_SurfaceRepresentation, false); m_DescriptorActionList.push_back(std::pair(surfaceDataNodeDescriptor, m_SurfaceRepresentation)); QAction* showOnlySelectedNodes = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/ShowSelectedNode_48.png") , "Show only selected nodes", this); QObject::connect( showOnlySelectedNodes, SIGNAL( triggered(bool) ) , this, SLOT( ShowOnlySelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(showOnlySelectedNodes); m_DescriptorActionList.push_back(std::pair(unknownDataNodeDescriptor, showOnlySelectedNodes)); QAction* toggleSelectedVisibility = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/InvertShowSelectedNode_48.png") , "Toggle visibility", this); QObject::connect( toggleSelectedVisibility, SIGNAL( triggered(bool) ) , this, SLOT( ToggleVisibilityOfSelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(toggleSelectedVisibility); m_DescriptorActionList.push_back(std::pair(unknownDataNodeDescriptor,toggleSelectedVisibility)); QAction* actionShowInfoDialog = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/ShowDataInfo_48.png") , "Details...", this); QObject::connect( actionShowInfoDialog, SIGNAL( triggered(bool) ) , this, SLOT( ShowInfoDialogForSelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(actionShowInfoDialog); m_DescriptorActionList.push_back(std::pair(unknownDataNodeDescriptor,actionShowInfoDialog)); //obsolete... //QAction* otsuFilterAction = new QAction("Apply Otsu Filter", this); //QObject::connect( otsuFilterAction, SIGNAL( triggered(bool) ) // , this, SLOT( OtsuFilter(bool) ) ); // //Otsu filter does not work properly, remove it temporarily // imageDataNodeDescriptor->AddAction(otsuFilterAction); // m_DescriptorActionList.push_back(std::pair(imageDataNodeDescriptor,otsuFilterAction)); QGridLayout* _DndFrameWidgetLayout = new QGridLayout; _DndFrameWidgetLayout->addWidget(m_NodeTreeView, 0, 0); _DndFrameWidgetLayout->setContentsMargins(0,0,0,0); m_DndFrameWidget = new QmitkDnDFrameWidget(m_Parent); m_DndFrameWidget->setLayout(_DndFrameWidgetLayout); QVBoxLayout* layout = new QVBoxLayout(parent); layout->addWidget(m_DndFrameWidget); layout->setContentsMargins(0,0,0,0); m_Parent->setLayout(layout); } void QmitkDataManagerView::SetFocus() { } void QmitkDataManagerView::ContextMenuActionTriggered( bool ) { QAction* action = qobject_cast ( sender() ); std::map::iterator it = m_ConfElements.find( action ); if( it == m_ConfElements.end() ) { MITK_WARN << "associated conf element for action " << action->text().toStdString() << " not found"; return; } berry::IConfigurationElement::Pointer confElem = it->second; mitk::IContextMenuAction* contextMenuAction = confElem->CreateExecutableExtension("class"); std::string className; std::string smoothed; confElem->GetAttribute("class", className); confElem->GetAttribute("smoothed", smoothed); if(className == "QmitkThresholdAction") { contextMenuAction->SetDataStorage(this->GetDataStorage()); } else if(className == "QmitkOtsuAction") { contextMenuAction->SetDataStorage(this->GetDataStorage()); } else if(className == "QmitkCreatePolygonModelAction") { contextMenuAction->SetDataStorage(this->GetDataStorage()); if(smoothed == "false") { contextMenuAction->SetSmoothed(false); } else { contextMenuAction->SetSmoothed(true); } contextMenuAction->SetDecimated(m_SurfaceDecimation); } else if(className == "QmitkStatisticsAction") { contextMenuAction->SetFunctionality(this); } + else if(className == "QmitkCreateSimulationAction") + { + contextMenuAction->SetDataStorage(this->GetDataStorage()); + } contextMenuAction->Run( this->GetCurrentSelection() ); // run the action } void QmitkDataManagerView::OnPreferencesChanged(const berry::IBerryPreferences* prefs) { if( m_NodeTreeModel->GetPlaceNewNodesOnTopFlag() != prefs->GetBool("Place new nodes on top", true) ) m_NodeTreeModel->SetPlaceNewNodesOnTop( !m_NodeTreeModel->GetPlaceNewNodesOnTopFlag() ); if( m_NodeTreeModel->GetShowHelperObjectsFlag()!= prefs->GetBool("Show helper objects", false) ) m_NodeTreeModel->SetShowHelperObjects( !m_NodeTreeModel->GetShowHelperObjectsFlag() ); if( m_NodeTreeModel->GetShowNodesContainingNoDataFlag()!= prefs->GetBool("Show nodes containing no data", false) ) m_NodeTreeModel->SetShowNodesContainingNoData( !m_NodeTreeModel->GetShowNodesContainingNoDataFlag() ); m_GlobalReinitOnNodeDelete = prefs->GetBool("Call global reinit if node is deleted", true); m_NodeTreeView->expandAll(); m_SurfaceDecimation = prefs->GetBool("Use surface decimation", false); this->GlobalReinit(); } void QmitkDataManagerView::NodeTableViewContextMenuRequested( const QPoint & pos ) { QModelIndex selected = m_NodeTreeView->indexAt ( pos ); mitk::DataNode::Pointer node = m_NodeTreeModel->GetNode(selected); QList selectedNodes = this->GetCurrentSelection(); if(!selectedNodes.isEmpty()) { m_NodeMenu->clear(); QList actions; if(selectedNodes.size() == 1 ) { actions = QmitkNodeDescriptorManager::GetInstance()->GetActions(node); for(QList::iterator it = actions.begin(); it != actions.end(); ++it) { (*it)->setData(QVariant::fromValue(node.GetPointer())); } } else actions = QmitkNodeDescriptorManager::GetInstance()->GetActions(selectedNodes); if (!m_ShowInActions.isEmpty()) { QMenu* showInMenu = m_NodeMenu->addMenu("Show In"); showInMenu->addActions(m_ShowInActions); } m_NodeMenu->addActions(actions); m_NodeMenu->popup(QCursor::pos()); } } void QmitkDataManagerView::OpacityChanged(int value) { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { float opacity = static_cast(value)/100.0f; node->SetFloatProperty("opacity", opacity); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkDataManagerView::OpacityActionChanged() { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { float opacity = 0.0; if(node->GetFloatProperty("opacity", opacity)) { m_OpacitySlider->setValue(static_cast(opacity*100)); } } } void QmitkDataManagerView::ColorChanged() { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { QColor color = QColorDialog::getColor(); m_ColorButton->setAutoFillBackground(true); node->SetProperty("color",mitk::ColorProperty::New(color.red()/255.0,color.green()/255.0,color.blue()/255.0)); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkDataManagerView::ColorActionChanged() { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { mitk::Color color; mitk::ColorProperty::Pointer colorProp; node->GetProperty(colorProp,"color"); if(colorProp.IsNull()) return; color = colorProp->GetValue(); QString styleSheet = "background-color:rgb("; styleSheet.append(QString::number(color[0]*255)); styleSheet.append(","); styleSheet.append(QString::number(color[1]*255)); styleSheet.append(","); styleSheet.append(QString::number(color[2]*255)); styleSheet.append(")"); m_ColorButton->setStyleSheet(styleSheet); } } void QmitkDataManagerView::TextureInterpolationChanged() { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { bool textureInterpolation = false; node->GetBoolProperty("texture interpolation", textureInterpolation); m_TextureInterpolation->setChecked(textureInterpolation); } } void QmitkDataManagerView::TextureInterpolationToggled( bool checked ) { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { node->SetBoolProperty("texture interpolation", checked); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkDataManagerView::SurfaceRepresentationMenuAboutToShow() { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(!node) return; mitk::EnumerationProperty* representationProp = dynamic_cast (node->GetProperty("material.representation")); if(!representationProp) return; // clear menu m_SurfaceRepresentation->menu()->clear(); QAction* tmp; // create menu entries for(mitk::EnumerationProperty::EnumConstIterator it=representationProp->Begin(); it!=representationProp->End() ; it++) { tmp = m_SurfaceRepresentation->menu()->addAction(QString::fromStdString(it->second)); tmp->setCheckable(true); if(it->second == representationProp->GetValueAsString()) { tmp->setChecked(true); } QObject::connect( tmp, SIGNAL( triggered(bool) ) , this, SLOT( SurfaceRepresentationActionToggled(bool) ) ); } } void QmitkDataManagerView::SurfaceRepresentationActionToggled( bool /*checked*/ ) { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(!node) return; mitk::EnumerationProperty* representationProp = dynamic_cast (node->GetProperty("material.representation")); if(!representationProp) return; QAction* senderAction = qobject_cast ( QObject::sender() ); if(!senderAction) return; std::string activatedItem = senderAction->text().toStdString(); if ( activatedItem != representationProp->GetValueAsString() ) { if ( representationProp->IsValidEnumerationValue( activatedItem ) ) { representationProp->SetValue( activatedItem ); representationProp->InvokeEvent( itk::ModifiedEvent() ); representationProp->Modified(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } } void QmitkDataManagerView::SaveSelectedNodes( bool ) { QModelIndexList indexesOfSelectedRows = m_NodeTreeView->selectionModel()->selectedRows(); mitk::DataNode* node = 0; unsigned int indexesOfSelectedRowsSize = indexesOfSelectedRows.size(); for (unsigned int i = 0; iGetNode(indexesOfSelectedRows.at(i)); // if node is not defined or if the node contains geometry data do not remove it if ( node != 0 ) { mitk::BaseData::Pointer data = node->GetData(); if (data.IsNotNull()) { QString error; try { mitk::QmitkIOUtil::SaveBaseDataWithDialog( data.GetPointer(), node->GetName().c_str(), m_Parent ); } catch(std::exception& e) { error = e.what(); } catch(...) { error = "Unknown error occured"; } if( !error.isEmpty() ) QMessageBox::critical( m_Parent, "Error saving...", error ); } } } } void QmitkDataManagerView::ReinitSelectedNodes( bool ) { mitk::IRenderWindowPart* renderWindow = this->GetRenderWindowPart(); if (renderWindow == NULL) renderWindow = this->OpenRenderWindowPart(false); QList selectedNodes = this->GetCurrentSelection(); foreach(mitk::DataNode::Pointer node, selectedNodes) { mitk::BaseData::Pointer basedata = node->GetData(); if ( basedata.IsNotNull() && basedata->GetTimeSlicedGeometry()->IsValid() ) { renderWindow->GetRenderingManager()->InitializeViews( basedata->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); renderWindow->GetRenderingManager()->RequestUpdateAll(); } } } void QmitkDataManagerView::RemoveSelectedNodes( bool ) { QModelIndexList indexesOfSelectedRows = m_NodeTreeView->selectionModel()->selectedRows(); if(indexesOfSelectedRows.size() < 1) { return; } std::vector selectedNodes; mitk::DataNode* node = 0; QString question = tr("Do you really want to remove "); for (QModelIndexList::iterator it = indexesOfSelectedRows.begin() ; it != indexesOfSelectedRows.end(); it++) { node = m_NodeTreeModel->GetNode(*it); // if node is not defined or if the node contains geometry data do not remove it if ( node != 0 /*& strcmp(node->GetData()->GetNameOfClass(), "Geometry2DData") != 0*/ ) { selectedNodes.push_back(node); question.append(QString::fromStdString(node->GetName())); question.append(", "); } } // remove the last two characters = ", " question = question.remove(question.size()-2, 2); question.append(" from data storage?"); QMessageBox::StandardButton answerButton = QMessageBox::question( m_Parent , tr("DataManager") , question , QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if(answerButton == QMessageBox::Yes) { for (std::vector::iterator it = selectedNodes.begin() ; it != selectedNodes.end(); it++) { node = *it; this->GetDataStorage()->Remove(node); if (m_GlobalReinitOnNodeDelete) this->GlobalReinit(false); } } } void QmitkDataManagerView::MakeAllNodesInvisible( bool ) { QList nodes = m_NodeTreeModel->GetNodeSet(); foreach(mitk::DataNode::Pointer node, nodes) { node->SetVisibility(false); } mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkDataManagerView::ShowOnlySelectedNodes( bool ) { QList selectedNodes = this->GetCurrentSelection(); QList allNodes = m_NodeTreeModel->GetNodeSet(); foreach(mitk::DataNode::Pointer node, allNodes) { node->SetVisibility(selectedNodes.contains(node)); } mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkDataManagerView::ToggleVisibilityOfSelectedNodes( bool ) { QList selectedNodes = this->GetCurrentSelection(); bool isVisible = false; foreach(mitk::DataNode::Pointer node, selectedNodes) { isVisible = false; node->GetBoolProperty("visible", isVisible); node->SetVisibility(!isVisible); } mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkDataManagerView::ShowInfoDialogForSelectedNodes( bool ) { QList selectedNodes = this->GetCurrentSelection(); QmitkInfoDialog _QmitkInfoDialog(selectedNodes, this->m_Parent); _QmitkInfoDialog.exec(); } void QmitkDataManagerView::Load( bool ) { QStringList fileNames = QFileDialog::getOpenFileNames(NULL, "Load data", "", mitk::CoreObjectFactory::GetInstance()->GetFileExtensions()); for ( QStringList::Iterator it = fileNames.begin(); it != fileNames.end(); ++it ) { FileOpen((*it).toAscii(), 0); } } void QmitkDataManagerView::FileOpen( const char * fileName, mitk::DataNode* parentNode ) { mitk::DataNodeFactory::Pointer factory = mitk::DataNodeFactory::New(); try { factory->SetFileName( fileName ); QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) ); factory->Update(); for ( unsigned int i = 0 ; i < factory->GetNumberOfOutputs( ); ++i ) { mitk::DataNode::Pointer node = factory->GetOutput( i ); if ( ( node.IsNotNull() ) && ( node->GetData() != NULL ) ) { this->GetDataStorage()->Add(node, parentNode); mitk::BaseData::Pointer basedata = node->GetData(); mitk::RenderingManager::GetInstance()->InitializeViews( basedata->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); //mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } } catch ( itk::ExceptionObject & ex ) { itkGenericOutputMacro( << "Exception during file open: " << ex ); } QApplication::restoreOverrideCursor(); } QItemSelectionModel *QmitkDataManagerView::GetDataNodeSelectionModel() const { return m_NodeTreeView->selectionModel(); } void QmitkDataManagerView::GlobalReinit( bool ) { mitk::IRenderWindowPart* renderWindow = this->GetRenderWindowPart(); if (renderWindow == NULL) renderWindow = this->OpenRenderWindowPart(false); // no render window available if (renderWindow == NULL) return; // get all nodes that have not set "includeInBoundingBox" to false mitk::NodePredicateNot::Pointer pred = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox" , mitk::BoolProperty::New(false))); mitk::DataStorage::SetOfObjects::ConstPointer rs = this->GetDataStorage()->GetSubset(pred); // calculate bounding geometry of these nodes mitk::TimeSlicedGeometry::Pointer bounds = this->GetDataStorage()->ComputeBoundingGeometry3D(rs, "visible"); // initialize the views to the bounding geometry renderWindow->GetRenderingManager()->InitializeViews(bounds); } void QmitkDataManagerView::OtsuFilter( bool ) { QList selectedNodes = this->GetCurrentSelection(); mitk::Image::Pointer mitkImage = 0; foreach(mitk::DataNode::Pointer node, selectedNodes) { mitkImage = dynamic_cast( node->GetData() ); if(mitkImage.IsNull()) continue; try { // get selected mitk image const unsigned short dim = 3; typedef short InputPixelType; typedef unsigned char OutputPixelType; typedef itk::Image< InputPixelType, dim > InputImageType; typedef itk::Image< OutputPixelType, dim > OutputImageType; typedef itk::OtsuThresholdImageFilter< InputImageType, OutputImageType > FilterType; FilterType::Pointer filter = FilterType::New(); filter->SetOutsideValue( 1 ); filter->SetInsideValue( 0 ); InputImageType::Pointer itkImage; mitk::CastToItkImage(mitkImage, itkImage); filter->SetInput( itkImage ); filter->Update(); mitk::DataNode::Pointer resultNode = mitk::DataNode::New(); std::string nameOfResultImage = node->GetName(); nameOfResultImage.append("Otsu"); resultNode->SetProperty("name", mitk::StringProperty::New(nameOfResultImage) ); resultNode->SetProperty("binary", mitk::BoolProperty::New(true) ); resultNode->SetData( mitk::ImportItkImage ( filter->GetOutput() ) ); this->GetDataStorage()->Add(resultNode, node); } catch( std::exception& err ) { MITK_ERROR(this->GetClassName()) << err.what(); } } } void QmitkDataManagerView::NodeTreeViewRowsRemoved ( const QModelIndex & /*parent*/, int /*start*/, int /*end*/ ) { m_CurrentRowCount = m_NodeTreeModel->rowCount(); } void QmitkDataManagerView::NodeTreeViewRowsInserted( const QModelIndex & parent, int, int ) { m_NodeTreeView->setExpanded(parent, true); // a new row was inserted if( m_CurrentRowCount == 0 && m_NodeTreeModel->rowCount() == 1 ) { this->OpenRenderWindowPart(); m_CurrentRowCount = m_NodeTreeModel->rowCount(); /* std::vector nodes = m_NodeTreeModel->GetNodeSet(); if(nodes.size() == 1) { QModelIndex treeIndex = m_NodeTreeModel->GetIndex(nodes.front()); m_NodeTreeView->selectionModel()->setCurrentIndex( treeIndex, QItemSelectionModel::ClearAndSelect ); } */ } } void QmitkDataManagerView::NodeSelectionChanged( const QItemSelection & /*selected*/, const QItemSelection & /*deselected*/ ) { QList nodes = m_NodeTreeModel->GetNodeSet(); foreach(mitk::DataNode::Pointer node, nodes) { if ( node.IsNotNull() ) node->SetBoolProperty("selected", false); } nodes.clear(); nodes = this->GetCurrentSelection(); foreach(mitk::DataNode::Pointer node, nodes) { if ( node.IsNotNull() ) node->SetBoolProperty("selected", true); } //changing the selection does NOT require any rendering processes! //mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkDataManagerView::ShowIn(const QString &editorId) { berry::IWorkbenchPage::Pointer page = this->GetSite()->GetPage(); berry::IEditorInput::Pointer input(new mitk::DataStorageEditorInput(this->GetDataStorageReference())); page->OpenEditor(input, editorId.toStdString(), false, berry::IWorkbenchPage::MATCH_ID); } mitk::IRenderWindowPart* QmitkDataManagerView::OpenRenderWindowPart(bool activatedEditor) { if (activatedEditor) { return this->GetRenderWindowPart(QmitkAbstractView::ACTIVATE | QmitkAbstractView::OPEN); } else { return this->GetRenderWindowPart(QmitkAbstractView::BRING_TO_FRONT | QmitkAbstractView::OPEN); } } diff --git a/Plugins/org.mitk.gui.qt.simulation/CMakeLists.txt b/Plugins/org.mitk.gui.qt.simulation/CMakeLists.txt index 84195b260a..e075434c20 100644 --- a/Plugins/org.mitk.gui.qt.simulation/CMakeLists.txt +++ b/Plugins/org.mitk.gui.qt.simulation/CMakeLists.txt @@ -1,7 +1,7 @@ project(org_mitk_gui_qt_simulation) MACRO_CREATE_MITK_CTK_PLUGIN( EXPORT_DIRECTIVE SIMULATION_EXPORT EXPORTED_INCLUDE_SUFFIXES src - MODULE_DEPENDENCIES Simulation Qmitk + MODULE_DEPENDENCIES Qmitk Simulation ) diff --git a/Plugins/org.mitk.gui.qt.simulation/files.cmake b/Plugins/org.mitk.gui.qt.simulation/files.cmake index 342a0f859e..3be5b42edf 100644 --- a/Plugins/org.mitk.gui.qt.simulation/files.cmake +++ b/Plugins/org.mitk.gui.qt.simulation/files.cmake @@ -1,39 +1,41 @@ set(SRC_CPP_FILES ) set(INTERNAL_CPP_FILES org_mitk_gui_qt_simulation_Activator.cpp + QmitkCreateSimulationAction.cpp QmitkSimulationPreferencePage.cpp QmitkSimulationView.cpp ) set(UI_FILES src/internal/QmitkSimulationPreferencePageControls.ui src/internal/QmitkSimulationViewControls.ui ) set(MOC_H_FILES src/internal/org_mitk_gui_qt_simulation_Activator.h + src/internal/QmitkCreateSimulationAction.h src/internal/QmitkSimulationPreferencePage.h src/internal/QmitkSimulationView.h ) set(CACHED_RESOURCE_FILES resources/icon.png plugin.xml ) set(QRC_FILES resources/Simulation.qrc ) set(CPP_FILES ) foreach(file ${SRC_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/${file}) endforeach() foreach(file ${INTERNAL_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/internal/${file}) endforeach() diff --git a/Plugins/org.mitk.gui.qt.simulation/manifest_headers.cmake b/Plugins/org.mitk.gui.qt.simulation/manifest_headers.cmake index 912e7b0cf4..8ff31cfca6 100644 --- a/Plugins/org.mitk.gui.qt.simulation/manifest_headers.cmake +++ b/Plugins/org.mitk.gui.qt.simulation/manifest_headers.cmake @@ -1,5 +1,5 @@ set(Plugin-Name "MITK Simulation") set(Plugin-Version "0.1") set(Plugin-Vendor "DKFZ, Medical and Biological Informatics") set(Plugin-ContactAddress "http://www.mitk.org") -set(Require-Plugin org.mitk.gui.qt.common) +set(Require-Plugin org.mitk.simulation org.mitk.gui.qt.datamanager) diff --git a/Plugins/org.mitk.gui.qt.simulation/plugin.xml b/Plugins/org.mitk.gui.qt.simulation/plugin.xml index b16639779a..fe22cf383a 100644 --- a/Plugins/org.mitk.gui.qt.simulation/plugin.xml +++ b/Plugins/org.mitk.gui.qt.simulation/plugin.xml @@ -1,14 +1,20 @@ + + + diff --git a/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkCreateSimulationAction.cpp b/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkCreateSimulationAction.cpp new file mode 100644 index 0000000000..aa4ed07156 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkCreateSimulationAction.cpp @@ -0,0 +1,118 @@ +/*=================================================================== + +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 "QmitkCreateSimulationAction.h" +#include +#include +#include +#include +#include +#include + +static std::string CreateFileName(mitk::DataNode::Pointer dataNode) +{ + std::string path; + dataNode->GetStringProperty("path", path); + + std::string name; + dataNode->GetStringProperty("name", name); + + if (name.length() < 5) + { + name += ".scn"; + } + else + { + std::string ext = name.substr(name.length() - 4); + std::transform(ext.begin(), ext.end(), ext.begin(), tolower); + + if (ext != ".scn" && ext != ".xml") + name += ".scn"; + } + + return path + "/" + name; +} + +static void InitializeViews(mitk::DataStorage::Pointer dataStorage) +{ + mitk::NodePredicateNot::Pointer predicate = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox", mitk::BoolProperty::New(false))); + mitk::DataStorage::SetOfObjects::ConstPointer subset = dataStorage->GetSubset(predicate); + mitk::TimeSlicedGeometry::Pointer geometry = dataStorage->ComputeBoundingGeometry3D(subset); + + mitk::RenderingManager::GetInstance()->InitializeViews(geometry); +} + +QmitkCreateSimulationAction::QmitkCreateSimulationAction() +{ +} + +QmitkCreateSimulationAction::~QmitkCreateSimulationAction() +{ +} + +void QmitkCreateSimulationAction::Run(const QList& selectedNodes) +{ + mitk::DataNode::Pointer dataNode; + + foreach(dataNode, selectedNodes) + { + if (dynamic_cast(dataNode->GetData()) != NULL) + { + mitk::SimulationTemplate* simulationTemplate = static_cast(dataNode->GetData()); + std::string contents = simulationTemplate->Bake(); + + if (contents.empty()) + { + MITK_ERROR << "Could not bake simulation template '" << dataNode->GetName() << "'!"; + continue; + } + + std::string fileName = CreateFileName(dataNode); + + std::ofstream file(fileName); + file << contents; + file.close(); + + std::vector fileNames; + fileNames.push_back(fileName); + + mitk::DataNode::Pointer simulationNode = mitk::IOUtil::LoadDataNode(fileName); + + if (simulationNode.IsNotNull()) + { + m_DataStorage->Add(simulationNode, dataNode); + InitializeViews(m_DataStorage); + } + } + } +} + +void QmitkCreateSimulationAction::SetDataStorage(mitk::DataStorage* dataStorage) +{ + m_DataStorage = dataStorage; +} + +void QmitkCreateSimulationAction::SetFunctionality(berry::QtViewPart*) +{ +} + +void QmitkCreateSimulationAction::SetDecimated(bool) +{ +} + +void QmitkCreateSimulationAction::SetSmoothed(bool) +{ +} diff --git a/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkCreateSimulationAction.h b/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkCreateSimulationAction.h new file mode 100644 index 0000000000..e5817552eb --- /dev/null +++ b/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkCreateSimulationAction.h @@ -0,0 +1,45 @@ +/*=================================================================== + +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 QmitkCreateSimulationAction_h +#define QmitkCreateSimulationAction_h + +#include +#include + +class QmitkCreateSimulationAction : public QObject, public mitk::IContextMenuAction +{ + Q_OBJECT + Q_INTERFACES(mitk::IContextMenuAction) + +public: + QmitkCreateSimulationAction(); + ~QmitkCreateSimulationAction(); + + void Run(const QList& selectedNodes); + void SetDataStorage(mitk::DataStorage* dataStorage); + void SetFunctionality(berry::QtViewPart* functionality); + void SetDecimated(bool decimated); + void SetSmoothed(bool smoothed); + +private: + QmitkCreateSimulationAction(const QmitkCreateSimulationAction&); + QmitkCreateSimulationAction& operator=(const QmitkCreateSimulationAction&); + + mitk::DataStorage::Pointer m_DataStorage; +}; + +#endif diff --git a/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationPreferencePage.cpp b/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationPreferencePage.cpp index d22ca55d04..b8d857a62f 100644 --- a/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationPreferencePage.cpp +++ b/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationPreferencePage.cpp @@ -1,244 +1,207 @@ /*=================================================================== 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 "QmitkSimulationPreferencePage.h" -#include -#include +#include #include #include -#include +#include typedef sofa::helper::system::Plugin Plugin; typedef sofa::helper::system::PluginManager PluginManager; typedef sofa::helper::system::PluginManager::PluginIterator PluginIterator; typedef sofa::helper::system::PluginManager::PluginMap PluginMap; -berry::IPreferences::Pointer getSimulationPreferences() -{ - berry::ServiceRegistry& serviceRegistry = berry::Platform::GetServiceRegistry(); - berry::IPreferencesService::Pointer preferencesService = serviceRegistry.GetServiceById(berry::IPreferencesService::ID); - berry::IPreferences::Pointer preferences = preferencesService->GetSystemPreferences(); - return preferences->Node("/org.mitk.views.simulation"); -} - -void initSOFAPlugins(berry::IPreferences::Pointer preferences) -{ - if (preferences.IsNull()) - return; - - QString pluginPaths = preferences->GetByteArray(QmitkSimulationPreferencePage::PLUGIN_PATHS, "").c_str(); - - if (pluginPaths.isEmpty()) - return; - - QStringList pluginPathList = pluginPaths.split(';', QString::SkipEmptyParts); - QStringListIterator it(pluginPathList); - - typedef sofa::helper::system::PluginManager PluginManager; - PluginManager& pluginManager = PluginManager::getInstance(); - - while (it.hasNext()) - { - std::string path = it.next().toStdString(); - std::ostringstream errlog; - - pluginManager.loadPlugin(path, &errlog); - - if (errlog.str().empty()) - pluginManager.getPluginMap()[path].initExternalModule(); - } -} - -const std::string QmitkSimulationPreferencePage::PLUGIN_PATHS = "plugin paths"; - QmitkSimulationPreferencePage::QmitkSimulationPreferencePage() - : m_Preferences(getSimulationPreferences()), + : m_Preferences(mitk::GetSimulationPreferences()), m_Control(NULL) { - initSOFAPlugins(m_Preferences); } QmitkSimulationPreferencePage::~QmitkSimulationPreferencePage() { } void QmitkSimulationPreferencePage::CreateQtControl(QWidget* parent) { m_Control = new QWidget(parent); m_Controls.setupUi(m_Control); QStringList headerLabels; headerLabels << "Name" << "License" << "Version" << "Path"; m_Controls.pluginsTreeWidget->setHeaderLabels(headerLabels); connect(m_Controls.pluginsTreeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(OnPluginTreeWidgetItemSelectionChanged())); connect(m_Controls.addButton, SIGNAL(clicked()), this, SLOT(OnAddButtonClicked())); connect(m_Controls.removeButton, SIGNAL(clicked()), this, SLOT(OnRemoveButtonClicked())); this->Update(); } QWidget* QmitkSimulationPreferencePage::GetQtControl() const { return m_Control; } void QmitkSimulationPreferencePage::Init(berry::IWorkbench::Pointer) { } void QmitkSimulationPreferencePage::OnAddButtonClicked() { QString filter = "SOFA Plugins "; #if defined(__APPLE__) filter += "(*.dylib*)"; #elif defined(WIN32) filter += "(*.dll)"; #else filter += "(*.so)"; #endif std::string path = QFileDialog::getOpenFileName(m_Control, "Add SOFA Library", "", filter).toStdString(); + if (path.empty()) + return; + PluginManager &pluginManager = PluginManager::getInstance(); std::ostringstream errlog; if (pluginManager.loadPlugin(path, &errlog)) { if (!errlog.str().empty()) { QMessageBox* messageBox = new QMessageBox(m_Control); messageBox->setIcon(QMessageBox::Warning); messageBox->setStandardButtons(QMessageBox::Ok); messageBox->setText(errlog.str().c_str()); messageBox->setWindowTitle("Warning"); messageBox->show(); } Plugin& plugin = pluginManager.getPluginMap()[path]; plugin.initExternalModule(); QStringList pluginItem; pluginItem << plugin.getModuleName() << plugin.getModuleLicense() << plugin.getModuleVersion() << path.c_str(); m_Controls.pluginsTreeWidget->addTopLevelItem(new QTreeWidgetItem(pluginItem)); } else { QMessageBox* messageBox = new QMessageBox(m_Control); messageBox->setIcon(QMessageBox::Critical); messageBox->setStandardButtons(QMessageBox::Ok); messageBox->setText(errlog.str().c_str()); messageBox->setWindowTitle("Error"); messageBox->show(); } } void QmitkSimulationPreferencePage::OnPluginTreeWidgetItemSelectionChanged() { QList selectedItems = m_Controls.pluginsTreeWidget->selectedItems(); if (!selectedItems.isEmpty()) { PluginMap& pluginMap = sofa::helper::system::PluginManager::getInstance().getPluginMap(); std::string path = selectedItems[0]->text(3).toStdString(); m_Controls.descriptionPlainTextEdit->setPlainText(pluginMap[path].getModuleDescription()); m_Controls.removeButton->setEnabled(true); } else { m_Controls.descriptionPlainTextEdit->clear(); m_Controls.componentsListWidget->clear(); m_Controls.removeButton->setEnabled(false); } } void QmitkSimulationPreferencePage::OnRemoveButtonClicked() { QList selectedItems = m_Controls.pluginsTreeWidget->selectedItems(); if (selectedItems.isEmpty()) return; std::string path = selectedItems[0]->text(3).toStdString(); PluginManager& pluginManager = PluginManager::getInstance(); std::ostringstream errlog; if (pluginManager.unloadPlugin(path, &errlog)) { delete selectedItems[0]; } else { QMessageBox* messageBox = new QMessageBox(m_Control); messageBox->setIcon(QMessageBox::Critical); messageBox->setStandardButtons(QMessageBox::Ok); messageBox->setText(errlog.str().c_str()); messageBox->setWindowTitle("Error"); messageBox->show(); } } void QmitkSimulationPreferencePage::PerformCancel() { } bool QmitkSimulationPreferencePage::PerformOk() { PluginManager& pluginManager = PluginManager::getInstance(); PluginMap& pluginMap = pluginManager.getPluginMap(); std::string pluginPaths; for (PluginIterator it = pluginMap.begin(); it != pluginMap.end(); ++it) { if (!pluginPaths.empty()) pluginPaths += ";"; pluginPaths += it->first; } - m_Preferences->PutByteArray(PLUGIN_PATHS, pluginPaths); + m_Preferences->PutByteArray("plugin paths", pluginPaths); return true; } void QmitkSimulationPreferencePage::Update() { PluginManager& pluginManager = PluginManager::getInstance(); PluginMap& pluginMap = pluginManager.getPluginMap(); for (PluginIterator it = pluginMap.begin(); it != pluginMap.end(); ++it) { Plugin& plugin = it->second; QStringList pluginItem; pluginItem << plugin.getModuleName() << plugin.getModuleLicense() << plugin.getModuleVersion() << it->first.c_str(); m_Controls.pluginsTreeWidget->addTopLevelItem(new QTreeWidgetItem(pluginItem)); } } diff --git a/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationPreferencePage.h b/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationPreferencePage.h index 484c855305..d1fb5743e9 100644 --- a/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationPreferencePage.h +++ b/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationPreferencePage.h @@ -1,57 +1,52 @@ /*=================================================================== 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 QmitkSimulationPreferencePage_h #define QmitkSimulationPreferencePage_h #include #include #include #include -berry::IPreferences::Pointer getSimulationPreferences(); -void initSOFAPlugins(berry::IPreferences::Pointer preferences = getSimulationPreferences()); - class SIMULATION_EXPORT QmitkSimulationPreferencePage : public QObject, public berry::IQtPreferencePage { Q_OBJECT Q_INTERFACES(berry::IPreferencePage) public: - static const std::string PLUGIN_PATHS; - QmitkSimulationPreferencePage(); ~QmitkSimulationPreferencePage(); void CreateQtControl(QWidget* parent); QWidget* GetQtControl() const; void Init(berry::IWorkbench::Pointer workbench); void PerformCancel(); bool PerformOk(); void Update(); private slots: void OnAddButtonClicked(); void OnPluginTreeWidgetItemSelectionChanged(); void OnRemoveButtonClicked(); private: berry::IPreferences::Pointer m_Preferences; QWidget* m_Control; Ui::QmitkSimulationPreferencePageControls m_Controls; }; #endif diff --git a/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationView.cpp b/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationView.cpp index d54415ee0d..58a14d02c8 100644 --- a/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationView.cpp +++ b/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationView.cpp @@ -1,263 +1,254 @@ /*=================================================================== 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 "QmitkSimulationPreferencePage.h" #include "QmitkSimulationView.h" #include #include #include #include -#include #include -static void InitializeViews(mitk::IRenderWindowPart* renderWindowPart, mitk::Geometry3D* geometry) -{ - if (renderWindowPart == NULL || geometry == NULL) - return; - - mitk::IRenderingManager* renderingManager = renderWindowPart->GetRenderingManager(); - - if (renderingManager != NULL) - renderingManager->InitializeViews(geometry, mitk::RenderingManager::REQUEST_UPDATE_ALL, true); -} - QmitkSimulationView::QmitkSimulationView() : m_SelectionWasRemovedFromDataStorage(false), m_Timer(this) { this->GetDataStorage()->RemoveNodeEvent.AddListener( mitk::MessageDelegate1(this, &QmitkSimulationView::OnNodeRemovedFromDataStorage)); connect(&m_Timer, SIGNAL(timeout()), this, SLOT(OnTimerTimeout())); - initSOFAPlugins(); } QmitkSimulationView::~QmitkSimulationView() { this->GetDataStorage()->RemoveNodeEvent.RemoveListener( mitk::MessageDelegate1(this, &QmitkSimulationView::OnNodeRemovedFromDataStorage)); } void QmitkSimulationView::CreateQtPartControl(QWidget* parent) { m_Controls.setupUi(parent); m_Controls.simulationComboBox->SetDataStorage(this->GetDataStorage()); m_Controls.simulationComboBox->SetPredicate(mitk::NodePredicateDataType::New("Simulation")); m_Controls.stepsRecordedLabel->hide(); connect(m_Controls.animateButton, SIGNAL(toggled(bool)), this, SLOT(OnAnimateButtonToggled(bool))); connect(m_Controls.recordButton, SIGNAL(toggled(bool)), this, SLOT(OnRecordButtonToggled(bool))); connect(m_Controls.resetButton, SIGNAL(clicked()), this, SLOT(OnResetButtonClicked())); connect(m_Controls.stepButton, SIGNAL(clicked()), this, SLOT(OnStepButtonClicked())); connect(m_Controls.simulationComboBox, SIGNAL(OnSelectionChanged(const mitk::DataNode*)), this, SLOT(OnSimulationComboBoxSelectionChanged(const mitk::DataNode*))); connect(m_Controls.dtSpinBox, SIGNAL(valueChanged(double)), this, SLOT(OnDTSpinBoxValueChanged(double))); connect(m_Controls.snapshotButton, SIGNAL(clicked()), this, SLOT(OnSnapshotButtonClicked())); if (m_Controls.simulationComboBox->GetSelectedNode().IsNotNull()) this->OnSimulationComboBoxSelectionChanged(m_Controls.simulationComboBox->GetSelectedNode()); } void QmitkSimulationView::OnAnimateButtonToggled(bool toggled) { if (this->SetSelectionAsCurrentSimulation()) { mitk::Simulation::Pointer simulation = dynamic_cast(m_Selection->GetData()); sofa::simulation::Simulation::SPtr sofaSimulation = simulation->GetSimulation(); sofa::simulation::Node::SPtr rootNode = simulation->GetRootNode(); rootNode->getContext()->setAnimate(toggled); if (toggled) { m_Controls.stepButton->setEnabled(false); m_Timer.start(0); } } if (!toggled) { m_Timer.stop(); m_Controls.stepButton->setEnabled(true); } } void QmitkSimulationView::OnDTSpinBoxValueChanged(double value) { if (!this->SetSelectionAsCurrentSimulation()) return; mitk::Simulation::Pointer simulation = dynamic_cast(m_Selection->GetData()); sofa::simulation::Node::SPtr rootNode = simulation->GetRootNode(); rootNode->setDt(value == 0.0 ? simulation->GetDefaultDT() : value); } void QmitkSimulationView::OnNodeRemovedFromDataStorage(const mitk::DataNode* node) { if (m_Selection.IsNotNull() && m_Selection.GetPointer() == node) m_SelectionWasRemovedFromDataStorage = true; } void QmitkSimulationView::OnRecordButtonToggled(bool toggled) { if (!toggled) { if (m_Record.IsNotNull()) { mitk::DataNode::Pointer dataNode = mitk::DataNode::New(); dataNode->SetData(m_Record); dataNode->SetName(m_Record->GetTimeSteps() == 1 ? "Snapshot" : "Record"); this->GetDataStorage()->Add(dataNode, m_Selection); - InitializeViews(this->GetRenderWindowPart(), m_Record->GetTimeSlicedGeometry()); + mitk::RenderingManager::GetInstance()->InitializeViews(m_Record->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true); m_Record = NULL; } m_Controls.stepsRecordedLabel->hide(); m_Controls.stepsRecordedLabel->setText("0 steps recorded"); } else if (toggled) { m_Controls.stepsRecordedLabel->show(); } } void QmitkSimulationView::OnResetButtonClicked() { if (!this->SetSelectionAsCurrentSimulation()) return; if (m_Controls.recordButton->isChecked()) m_Controls.recordButton->setChecked(false); mitk::Simulation::Pointer simulation = dynamic_cast(m_Selection->GetData()); sofa::simulation::Simulation::SPtr sofaSimulation = simulation->GetSimulation(); sofa::simulation::Node::SPtr rootNode = simulation->GetRootNode(); m_Controls.dtSpinBox->setValue(0.0); sofaSimulation->reset(rootNode.get()); rootNode->setTime(0.0); rootNode->execute(sofa::core::ExecParams::defaultInstance()); simulation->GetDrawTool()->Reset(); this->RequestRenderWindowUpdate(mitk::RenderingManager::REQUEST_UPDATE_3DWINDOWS); } void QmitkSimulationView::OnSimulationComboBoxSelectionChanged(const mitk::DataNode* node) { if (m_Controls.animateButton->isChecked()) m_Controls.animateButton->setChecked(false); if (m_SelectionWasRemovedFromDataStorage) { m_SelectionWasRemovedFromDataStorage = false; m_Selection = NULL; } if (m_Controls.recordButton->isChecked()) m_Controls.recordButton->setChecked(false); if (node != NULL) { m_Selection = m_Controls.simulationComboBox->GetSelectedNode(); m_Controls.sceneGroupBox->setEnabled(true); m_Controls.snapshotButton->setEnabled(true); static_cast(node->GetData())->SetAsActiveSimulation(); } else { m_Selection = NULL; m_Controls.sceneGroupBox->setEnabled(false); m_Controls.snapshotButton->setEnabled(false); mitk::Simulation::SetActiveSimulation(NULL); } } void QmitkSimulationView::OnSnapshotButtonClicked() { if (!this->SetSelectionAsCurrentSimulation()) return; mitk::Simulation::Pointer simulation = dynamic_cast(m_Selection->GetData()); mitk::Surface::Pointer snapshot = simulation->TakeSnapshot(); if (snapshot.IsNull()) return; mitk::DataNode::Pointer snapshotDataNode = mitk::DataNode::New(); snapshotDataNode->SetData(snapshot); snapshotDataNode->SetName("Snapshot"); this->GetDataStorage()->Add(snapshotDataNode, m_Selection); } void QmitkSimulationView::OnStepButtonClicked() { if (!this->SetSelectionAsCurrentSimulation()) return; mitk::Simulation::Pointer simulation = dynamic_cast(m_Controls.simulationComboBox->GetSelectedNode()->GetData()); sofa::simulation::Simulation::SPtr sofaSimulation = simulation->GetSimulation(); sofa::simulation::Node::SPtr rootNode = simulation->GetRootNode(); simulation->GetDrawTool()->Reset(); sofaSimulation->animate(rootNode.get(), rootNode->getDt()); this->RequestRenderWindowUpdate(mitk::RenderingManager::REQUEST_UPDATE_3DWINDOWS); if (m_Controls.recordButton->isChecked()) { if (m_Record.IsNull()) m_Record = mitk::Surface::New(); - simulation->AppendSnapshot(m_Record); - - unsigned int numSteps = m_Record->GetTimeSteps(); - QString plural = numSteps != 1 ? "s" : ""; + if (simulation->AppendSnapshot(m_Record)) + { + unsigned int numSteps = m_Record->GetTimeSteps(); + QString plural = numSteps != 1 ? "s" : ""; - m_Controls.stepsRecordedLabel->setText(QString("%1 step%2 recorded").arg(numSteps).arg(plural)); + m_Controls.stepsRecordedLabel->setText(QString("%1 step%2 recorded").arg(numSteps).arg(plural)); + } + else if (m_Record->GetTimeSteps() == 1) + { + m_Record = NULL; + } } } void QmitkSimulationView::SetFocus() { m_Controls.animateButton->setFocus(); } bool QmitkSimulationView::SetSelectionAsCurrentSimulation() const { if (m_Selection.IsNotNull()) { static_cast(m_Selection->GetData())->SetAsActiveSimulation(); return true; } return false; } void QmitkSimulationView::OnTimerTimeout() { this->OnStepButtonClicked(); } diff --git a/Plugins/org.mitk.gui.qt.simulation/src/internal/org_mitk_gui_qt_simulation_Activator.cpp b/Plugins/org.mitk.gui.qt.simulation/src/internal/org_mitk_gui_qt_simulation_Activator.cpp index d29e31d03b..9abd83b10a 100644 --- a/Plugins/org.mitk.gui.qt.simulation/src/internal/org_mitk_gui_qt_simulation_Activator.cpp +++ b/Plugins/org.mitk.gui.qt.simulation/src/internal/org_mitk_gui_qt_simulation_Activator.cpp @@ -1,42 +1,34 @@ /*=================================================================== 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 "org_mitk_gui_qt_simulation_Activator.h" +#include "QmitkCreateSimulationAction.h" #include "QmitkSimulationPreferencePage.h" #include "QmitkSimulationView.h" -#include -#include #include void mitk::org_mitk_gui_qt_simulation_Activator::start(ctkPluginContext* context) { + BERRY_REGISTER_EXTENSION_CLASS(QmitkCreateSimulationAction, context); BERRY_REGISTER_EXTENSION_CLASS(QmitkSimulationPreferencePage, context); BERRY_REGISTER_EXTENSION_CLASS(QmitkSimulationView, context); - - QmitkNodeDescriptorManager* nodeDescriptorManager = QmitkNodeDescriptorManager::GetInstance(); - - if (nodeDescriptorManager != NULL) - { - mitk::NodePredicateDataType::Pointer isSimulation = mitk::NodePredicateDataType::New("Simulation"); - nodeDescriptorManager->AddDescriptor(new QmitkNodeDescriptor("Simulation", ":/Simulation/icon.png", isSimulation, nodeDescriptorManager)); - } } void mitk::org_mitk_gui_qt_simulation_Activator::stop(ctkPluginContext*) { } Q_EXPORT_PLUGIN2(org_mitk_gui_qt_simulation, mitk::org_mitk_gui_qt_simulation_Activator) diff --git a/Plugins/org.mitk.simulation/CMakeLists.txt b/Plugins/org.mitk.simulation/CMakeLists.txt new file mode 100644 index 0000000000..ead588d2af --- /dev/null +++ b/Plugins/org.mitk.simulation/CMakeLists.txt @@ -0,0 +1,7 @@ +project(org_mitk_simulation) + +MACRO_CREATE_MITK_CTK_PLUGIN( + EXPORT_DIRECTIVE SIMULATION_INIT_EXPORT + EXPORTED_INCLUDE_SUFFIXES src + MODULE_DEPENDENCIES Qmitk Simulation +) diff --git a/Plugins/org.mitk.simulation/files.cmake b/Plugins/org.mitk.simulation/files.cmake new file mode 100644 index 0000000000..cfe1fc0b72 --- /dev/null +++ b/Plugins/org.mitk.simulation/files.cmake @@ -0,0 +1,31 @@ +set(SRC_CPP_FILES + mitkGetSimulationPreferences.cpp +) + +set(INTERNAL_CPP_FILES + org_mitk_simulation_Activator.cpp +) + +set(MOC_H_FILES + src/internal/org_mitk_simulation_Activator.h +) + +set(CACHED_RESOURCE_FILES + resources/simulation.png + resources/simulationTemplate.png +) + +set(QRC_FILES + resources/Simulation.qrc +) + +set(CPP_FILES +) + +foreach(file ${SRC_CPP_FILES}) + set(CPP_FILES ${CPP_FILES} src/${file}) +endforeach() + +foreach(file ${INTERNAL_CPP_FILES}) + set(CPP_FILES ${CPP_FILES} src/internal/${file}) +endforeach() diff --git a/Plugins/org.mitk.gui.qt.simulation/manifest_headers.cmake b/Plugins/org.mitk.simulation/manifest_headers.cmake similarity index 52% copy from Plugins/org.mitk.gui.qt.simulation/manifest_headers.cmake copy to Plugins/org.mitk.simulation/manifest_headers.cmake index 912e7b0cf4..893c3d887f 100644 --- a/Plugins/org.mitk.gui.qt.simulation/manifest_headers.cmake +++ b/Plugins/org.mitk.simulation/manifest_headers.cmake @@ -1,5 +1,6 @@ -set(Plugin-Name "MITK Simulation") +set(Plugin-Name "MITK Simulation Initialization") set(Plugin-Version "0.1") set(Plugin-Vendor "DKFZ, Medical and Biological Informatics") set(Plugin-ContactAddress "http://www.mitk.org") -set(Require-Plugin org.mitk.gui.qt.common) +set(Require-Plugin org.mitk.gui.common) +set(Plugin-ActivationPolicy eager) diff --git a/Plugins/org.mitk.simulation/resources/Simulation.qrc b/Plugins/org.mitk.simulation/resources/Simulation.qrc new file mode 100644 index 0000000000..00b2d1b9fb --- /dev/null +++ b/Plugins/org.mitk.simulation/resources/Simulation.qrc @@ -0,0 +1,8 @@ + + + simulation.png + + + simulationTemplate.png + + diff --git a/Plugins/org.mitk.simulation/resources/simulation.png b/Plugins/org.mitk.simulation/resources/simulation.png new file mode 100644 index 0000000000..3e0ce703ea Binary files /dev/null and b/Plugins/org.mitk.simulation/resources/simulation.png differ diff --git a/Plugins/org.mitk.simulation/resources/simulationTemplate.png b/Plugins/org.mitk.simulation/resources/simulationTemplate.png new file mode 100644 index 0000000000..fdf69c0bbd Binary files /dev/null and b/Plugins/org.mitk.simulation/resources/simulationTemplate.png differ diff --git a/Plugins/org.mitk.simulation/src/internal/org_mitk_simulation_Activator.cpp b/Plugins/org.mitk.simulation/src/internal/org_mitk_simulation_Activator.cpp new file mode 100644 index 0000000000..a896b6e900 --- /dev/null +++ b/Plugins/org.mitk.simulation/src/internal/org_mitk_simulation_Activator.cpp @@ -0,0 +1,76 @@ +/*=================================================================== + +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 "org_mitk_simulation_Activator.h" +#include +#include +#include +#include +#include +#include + +static void InitSOFAPlugins() +{ + berry::IPreferences::Pointer preferences = mitk::GetSimulationPreferences(); + + if (preferences.IsNull()) + return; + + QString pluginPaths = preferences->GetByteArray("plugin paths", "").c_str(); + + if (pluginPaths.isEmpty()) + return; + + QStringList pluginPathList = pluginPaths.split(';', QString::SkipEmptyParts); + QStringListIterator it(pluginPathList); + + typedef sofa::helper::system::PluginManager PluginManager; + PluginManager& pluginManager = PluginManager::getInstance(); + + while (it.hasNext()) + { + std::string path = it.next().toStdString(); + std::ostringstream errlog; + + pluginManager.loadPlugin(path, &errlog); + + if (errlog.str().empty()) + pluginManager.getPluginMap()[path].initExternalModule(); + } +} + +void mitk::org_mitk_simulation_Activator::start(ctkPluginContext*) +{ + RegisterSimulationObjectFactory(); + InitSOFAPlugins(); + + QmitkNodeDescriptorManager* nodeDescriptorManager = QmitkNodeDescriptorManager::GetInstance(); + + if (nodeDescriptorManager != NULL) + { + mitk::NodePredicateDataType::Pointer isSimulation = mitk::NodePredicateDataType::New("Simulation"); + nodeDescriptorManager->AddDescriptor(new QmitkNodeDescriptor("Simulation", ":/Simulation/simulation.png", isSimulation, nodeDescriptorManager)); + + mitk::NodePredicateDataType::Pointer isSimulationTemplate = mitk::NodePredicateDataType::New("SimulationTemplate"); + nodeDescriptorManager->AddDescriptor(new QmitkNodeDescriptor("SimulationTemplate", ":/Simulation/simulationTemplate.png", isSimulationTemplate, nodeDescriptorManager)); + } +} + +void mitk::org_mitk_simulation_Activator::stop(ctkPluginContext* context) +{ +} + +Q_EXPORT_PLUGIN2(org_mitk_simulation, mitk::org_mitk_simulation_Activator) diff --git a/Plugins/org.mitk.simulation/src/internal/org_mitk_simulation_Activator.h b/Plugins/org.mitk.simulation/src/internal/org_mitk_simulation_Activator.h new file mode 100644 index 0000000000..ff456e120a --- /dev/null +++ b/Plugins/org.mitk.simulation/src/internal/org_mitk_simulation_Activator.h @@ -0,0 +1,35 @@ +/*=================================================================== + +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 org_mitk_simulation_Activator_h +#define org_mitk_simulation_Activator_h + +#include + +namespace mitk +{ + class org_mitk_simulation_Activator : public QObject, public ctkPluginActivator + { + Q_OBJECT + Q_INTERFACES(ctkPluginActivator) + + public: + void start(ctkPluginContext* context); + void stop(ctkPluginContext* context); + }; +} +#endif diff --git a/Plugins/org.mitk.simulation/src/mitkGetSimulationPreferences.cpp b/Plugins/org.mitk.simulation/src/mitkGetSimulationPreferences.cpp new file mode 100644 index 0000000000..d10b8403ac --- /dev/null +++ b/Plugins/org.mitk.simulation/src/mitkGetSimulationPreferences.cpp @@ -0,0 +1,28 @@ +/*=================================================================== + +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 "mitkGetSimulationPreferences.h" +#include +#include +#include + +berry::IPreferences::Pointer mitk::GetSimulationPreferences() +{ + berry::ServiceRegistry& serviceRegistry = berry::Platform::GetServiceRegistry(); + berry::IPreferencesService::Pointer preferencesService = serviceRegistry.GetServiceById(berry::IPreferencesService::ID); + berry::IPreferences::Pointer preferences = preferencesService->GetSystemPreferences(); + return preferences->Node("/org.mitk.views.simulation"); +} diff --git a/Plugins/org.mitk.simulation/src/mitkGetSimulationPreferences.h b/Plugins/org.mitk.simulation/src/mitkGetSimulationPreferences.h new file mode 100644 index 0000000000..debded83a3 --- /dev/null +++ b/Plugins/org.mitk.simulation/src/mitkGetSimulationPreferences.h @@ -0,0 +1,28 @@ +/*=================================================================== + +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 mitkGetSimulationPreferences_h +#define mitkGetSimulationPreferences_h + +#include +#include + +namespace mitk +{ + SIMULATION_INIT_EXPORT berry::IPreferences::Pointer GetSimulationPreferences(); +} + +#endif