ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkMetaSceneConverter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 "metaScene.h"
22 #include "itkMetaEvent.h"
23 #include "itkSceneSpatialObject.h"
25 #include "itkMetaConverterBase.h"
26 #include <string>
27 #include <map>
28 
29 namespace itk
30 {
41 template< unsigned int NDimensions,
42  typename PixelType = unsigned char,
43  typename TMeshTraits =
44  DefaultStaticMeshTraits< PixelType, NDimensions, NDimensions >
45  >
46 class ITK_EXPORT MetaSceneConverter
47 {
48 public:
49 
52  typedef typename SceneType::Pointer ScenePointer;
53 
56  typedef typename MetaConverterBaseType::Pointer MetaConverterPointer;
57  typedef std::map< std::string, MetaConverterPointer > ConverterMapType;
58 
61 
62  itkStaticConstMacro(MaximumDepth, unsigned int, 9999999);
63 
65  ScenePointer ReadMeta(const char *name);
66 
68  bool WriteMeta(SceneType *scene, const char *fileName,
69  unsigned int depth = MaximumDepth,
70  char *spatialObjectTypeName = NULL);
71 
72  const MetaEvent * GetEvent() const { return m_Event; }
73  void SetEvent(MetaEvent *event) { m_Event = event; }
74 
76  void SetBinaryPoints(bool binary) { m_BinaryPoints = binary; }
77 
79  void SetTransformPrecision(unsigned int precision)
80  {
81  m_TransformPrecision = precision;
82  }
83  unsigned int GetTransformPrecision(){ return m_TransformPrecision; }
85 
87  void SetWriteImagesInSeparateFile(bool separate)
88  {
89  m_WriteImagesInSeparateFile = separate;
90  }
91 
98  void RegisterMetaConverter(const char *metaTypeName,
99  const char *spatialObjectTypeName,
100  MetaConverterBaseType *converter);
101 
102  MetaScene * CreateMetaScene(SceneType *scene,
103  unsigned int depth = MaximumDepth,
104  char *name = NULL);
105 
106  ScenePointer CreateSpatialObjectScene(MetaScene *scene);
107 private:
108 
112 
113  typedef std::list< MetaObject * > MetaObjectListType;
114 
115  template <typename TConverter>
116  MetaObject *SpatialObjectToMetaObject(SpatialObjectPointer &so)
117  {
118  typename TConverter::Pointer converter = TConverter::New();
119  // needed just for Image & ImageMask
120  converter->SetWriteImagesInSeparateFile(this->m_WriteImagesInSeparateFile);
121  return converter->SpatialObjectToMetaObject(so.GetPointer());
122  }
123  template <typename TConverter>
124  SpatialObjectPointer MetaObjectToSpatialObject(const MetaObject *mo)
125  {
126  typename TConverter::Pointer converter = TConverter::New();
127  return converter->MetaObjectToSpatialObject(mo);
128  }
129  void SetTransform(MetaObject *obj, TransformType *transform);
130 
131  void SetTransform(SpatialObjectType *so, MetaObject *obj);
132 
133  double m_Orientation[100];
134  double m_Position[10];
135  double m_CenterOfRotation[10];
136 
140  unsigned int m_TransformPrecision;
142 };
143 } // end namespace itk
144 
145 #ifndef ITK_MANUAL_INSTANTIATION
146 #include "itkMetaSceneConverter.hxx"
147 #endif
148 
149 #endif
150