ITK  6.0.0
Insight Toolkit
itkMetaSceneConverter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * https://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkMetaSceneConverter_h
19 #define itkMetaSceneConverter_h
20 
21 #include "itkObject.h"
23 
24 #include "metaScene.h"
25 #include "itkMetaEvent.h"
26 #include "itkSpatialObject.h"
27 #include "itkMetaConverterBase.h"
28 
29 #include <string>
30 #include <map>
31 
32 namespace itk
33 {
45 template <unsigned int VDimension = 3,
46  typename PixelType = unsigned char,
47  typename TMeshTraits = DefaultStaticMeshTraits<PixelType, VDimension, VDimension>>
48 class ITK_TEMPLATE_EXPORT MetaSceneConverter : public Object
49 {
50 public:
51 
54  using Superclass = Object;
57 
58  itkNewMacro(Self);
59 
61  itkOverrideGetNameOfClassMacro(MetaSceneConverter);
62 
67 
71  using ConverterMapType = std::map<std::string, MetaConverterPointer>;
72 
79  itkSetMacro(MetaIOVersion, unsigned int);
80  itkGetConstMacro(MetaIOVersion, unsigned int);
85  ReadMeta(const std::string & name);
86 
88  bool
89  WriteMeta(const SpatialObjectType * soScene,
90  const std::string & fileName,
91  unsigned int depth = SpatialObjectType::MaximumDepth,
92  const std::string & soName = "");
93 
94  itkGetMacro(Event, MetaEvent *);
95  itkSetObjectMacro(Event, MetaEvent);
96 
98  itkSetMacro(BinaryPoints, bool);
99  itkGetConstMacro(BinaryPoints, bool);
100  itkBooleanMacro(BinaryPoints);
104  itkSetMacro(TransformPrecision, unsigned int);
105  itkGetMacro(TransformPrecision, unsigned int);
109  itkSetMacro(WriteImagesInSeparateFile, bool);
110  itkGetConstMacro(WriteImagesInSeparateFile, bool);
111  itkBooleanMacro(WriteImagesInSeparateFile);
120  void
121  RegisterMetaConverter(const std::string & metaTypeName,
122  const std::string & spatialObjectTypeName,
123  MetaConverterBaseType * converter);
124 
129  MetaScene *
130  CreateMetaScene(const SpatialObjectType * soScene,
131  unsigned int depth = SpatialObjectType::MaximumDepth,
132  const std::string & name = "");
133 
135  CreateSpatialObjectScene(MetaScene * mScene);
136 
137 protected:
139  ~MetaSceneConverter() override = default;
140 
141 private:
143 
144  using MetaObjectListType = std::list<MetaObject *>;
145 
146  template <typename TConverter>
147  MetaObject *
149  {
150  auto converter = TConverter::New();
151  // needed just for Image & ImageMask
152  converter->SetMetaIOVersion(m_MetaIOVersion);
153  converter->SetWriteImagesInSeparateFile(this->m_WriteImagesInSeparateFile);
154  return converter->SpatialObjectToMetaObject(so);
155  }
156  template <typename TConverter>
157  SpatialObjectPointer
158  MetaObjectToSpatialObject(const MetaObject * mo)
159  {
160  auto converter = TConverter::New();
161  converter->SetMetaIOVersion(m_MetaIOVersion);
162  return converter->MetaObjectToSpatialObject(mo);
163  }
164  void
165  SetTransform(MetaObject * obj, const TransformType * transform);
166 
167  void
168  SetTransform(SpatialObjectType * so, const MetaObject * meta);
169 
170  MetaEvent * m_Event{};
171  bool m_BinaryPoints{};
172  bool m_WriteImagesInSeparateFile{};
173  unsigned int m_TransformPrecision{};
174  ConverterMapType m_ConverterMap{};
175  unsigned int m_MetaIOVersion{ 0 };
176 };
177 } // end namespace itk
178 
179 #ifndef ITK_MANUAL_INSTANTIATION
180 # include "itkMetaSceneConverter.hxx"
181 #endif
182 
183 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::MetaSceneConverter::TransformType
typename SpatialObjectType::TransformType TransformType
Definition: itkMetaSceneConverter.h:142
itkSpatialObject.h
itk::MetaSceneConverter::SpatialObjectConstPointer
typename SpatialObjectType::ConstPointer SpatialObjectConstPointer
Definition: itkMetaSceneConverter.h:66
itkMetaEvent.h
itk::SmartPointer< Self >
itk::MetaSceneConverter::MetaObjectToSpatialObject
SpatialObjectPointer MetaObjectToSpatialObject(const MetaObject *mo)
Definition: itkMetaSceneConverter.h:158
itk::AffineTransform
Definition: itkAffineTransform.h:101
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::MetaSceneConverter::MetaObjectListType
std::list< MetaObject * > MetaObjectListType
Definition: itkMetaSceneConverter.h:144
itk::MetaSceneConverter::SpatialObjectToMetaObject
MetaObject * SpatialObjectToMetaObject(SpatialObjectConstPointer &so)
Definition: itkMetaSceneConverter.h:148
itk::MetaEvent
Event abstract class.
Definition: itkMetaEvent.h:40
itk::MetaSceneConverter::ConverterMapType
std::map< std::string, MetaConverterPointer > ConverterMapType
Definition: itkMetaSceneConverter.h:71
itk::SpatialObject
Implementation of the composite pattern.
Definition: itkSpatialObject.h:58
itkObject.h
itk::MetaConverterBase
Base class for MetaObject<->SpatialObject converters.
Definition: itkMetaConverterBase.h:42
itk::MetaSceneConverter::SpatialObjectPointer
typename SpatialObjectType::Pointer SpatialObjectPointer
Definition: itkMetaSceneConverter.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::MetaSceneConverter::MetaConverterPointer
typename MetaConverterBaseType::Pointer MetaConverterPointer
Definition: itkMetaSceneConverter.h:70
itkDefaultStaticMeshTraits.h
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
New
static Pointer New()
itk::MetaSceneConverter
Converts between MetaObject and SpatialObject group.
Definition: itkMetaSceneConverter.h:48
itkMetaConverterBase.h