Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkPlanarFigureObjectFactory.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 #include "mitkPlanarFigureWriter.h"
15 
16 #include "mitkCoreObjectFactory.h"
17 
18 #include "mitkPlanarFigure.h"
23 #include "mitkVtkGLMapperWrapper.h"
24 
25 typedef std::multimap<std::string, std::string> MultimapType;
26 
28  : m_PlanarFigureIOFactory(PlanarFigureIOFactory::New().GetPointer()),
29  m_PlanarFigureWriterFactory(PlanarFigureWriterFactory::New().GetPointer())
30 {
31  static bool alreadyDone = false;
32  if (!alreadyDone)
33  {
34  itk::ObjectFactoryBase::RegisterFactory(m_PlanarFigureIOFactory);
35  itk::ObjectFactoryBase::RegisterFactory(m_PlanarFigureWriterFactory);
36 
37  m_FileWriters.push_back(PlanarFigureWriter::New().GetPointer());
38 
40 
41  alreadyDone = true;
42  }
43 }
44 
46 {
47  itk::ObjectFactoryBase::UnRegisterFactory(m_PlanarFigureWriterFactory);
48  itk::ObjectFactoryBase::UnRegisterFactory(m_PlanarFigureIOFactory);
49 }
50 
52 {
53  mitk::Mapper::Pointer newMapper = nullptr;
54  mitk::BaseData *data = node->GetData();
55 
56  if (dynamic_cast<PlanarFigure *>(data) != nullptr)
57  {
59  {
60  newMapper = mitk::PlanarFigureMapper2D::New();
61  newMapper->SetDataNode(node);
62  }
63  else if (id == mitk::BaseRenderer::Standard3D)
64  {
66  newMapper->SetDataNode(node);
67  }
68  }
69 
70  return newMapper;
71 }
72 
74 {
75  if (node == nullptr)
76  {
77  return;
78  }
79 
80  mitk::DataNode::Pointer nodePointer = node;
81 
82  mitk::PlanarFigure::Pointer pf = dynamic_cast<mitk::PlanarFigure *>(node->GetData());
83  if (pf.IsNotNull())
84  {
87  node->AddProperty("color", mitk::ColorProperty::New(1.0, 1.0, 1.0), nullptr, true);
88  node->AddProperty("opacity", mitk::FloatProperty::New(0.8), nullptr, true);
89  }
90 }
91 
93 {
94  return "";
95 }
96 
98 {
99  return m_FileExtensionsMap;
100 }
101 
103 {
104  // return ";;Planar Figures (*.pf)"; // for mitk::PlanarFigure and derived classes
105  std::string fileExtension;
106  this->CreateFileExtensions(m_SaveFileExtensionsMap, fileExtension);
107  return fileExtension.c_str();
108 };
109 
111 {
113 }
114 
116 {
117  m_FileExtensionsMap.insert(std::pair<std::string, std::string>("*.pf", "Planar Figure Files"));
118  m_SaveFileExtensionsMap.insert(std::pair<std::string, std::string>("*.pf", "Planar Figure Files"));
119 }
120 
122 {
123 }
124 
125 struct RegisterPlanarFigureObjectFactory
126 {
127  RegisterPlanarFigureObjectFactory() : m_Factory(mitk::PlanarFigureObjectFactory::New())
128  {
129  mitk::CoreObjectFactory::GetInstance()->RegisterExtraFactory(m_Factory);
130  }
131 
132  ~RegisterPlanarFigureObjectFactory() { mitk::CoreObjectFactory::GetInstance()->UnRegisterExtraFactory(m_Factory); }
134 };
135 
136 static RegisterPlanarFigureObjectFactory registerPlanarFigureObjectFactory;
mitk::CoreObjectFactoryBase::MultimapType GetSaveFileExtensionsMap() override
Base of all data objects.
Definition: mitkBaseData.h:37
static Pointer New()
static void SetDefaultProperties(DataNode *, BaseRenderer *=nullptr, bool=false)
mitk::CoreObjectFactoryBase::MultimapType GetFileExtensionsMap() override
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
void AddProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr, bool overwrite=false)
Add the property (instance of BaseProperty) if it does not exist (or always ifoverwrite istrue) with ...
Create instances of PlanarFigureReader objects using an object factory.
void SetDefaultProperties(mitk::DataNode *node) override
static RegisterPlanarFigureObjectFactory registerPlanarFigureObjectFactory
std::multimap< std::string, std::string > MultimapType
static void CreateFileExtensions(MultimapType fileExtensionsMap, std::string &fileExtensions)
create a string from a map that contains the file extensions
static Pointer New()
static void SetDefaultProperties(mitk::DataNode *node, mitk::BaseRenderer *renderer=nullptr, bool overwrite=false)
Base-class for geometric planar (2D) figures, such as lines, circles, rectangles, polygons...
static Pointer New()
unsigned int MapperSlotId
Definition: mitkCommon.h:33
std::multimap< std::string, std::string > MultimapType
Mapper::Pointer CreateMapper(mitk::DataNode *node, MapperSlotId slotId) override
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64