ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkMetaSceneConverter_h 00019 #define __itkMetaSceneConverter_h 00020 00021 #include "metaScene.h" 00022 #include "itkMetaEvent.h" 00023 #include "itkSceneSpatialObject.h" 00024 #include "itkDefaultStaticMeshTraits.h" 00025 #include "itkMetaConverterBase.h" 00026 #include <string> 00027 #include <map> 00028 00029 namespace itk 00030 { 00041 template< unsigned int NDimensions, 00042 typename PixelType = unsigned char, 00043 typename TMeshTraits = 00044 DefaultStaticMeshTraits< PixelType, NDimensions, NDimensions > 00045 > 00046 class ITK_EXPORT MetaSceneConverter 00047 { 00048 public: 00049 00051 typedef itk::SceneSpatialObject< NDimensions > SceneType; 00052 typedef typename SceneType::Pointer ScenePointer; 00053 00055 typedef MetaConverterBase< NDimensions > MetaConverterBaseType; 00056 typedef typename MetaConverterBaseType::Pointer MetaConverterPointer; 00057 typedef std::map< std::string, MetaConverterPointer > ConverterMapType; 00058 00059 MetaSceneConverter(); 00060 ~MetaSceneConverter(); 00061 00062 itkStaticConstMacro(MaximumDepth, unsigned int, 9999999); 00063 00065 ScenePointer ReadMeta(const char *name); 00066 00068 bool WriteMeta(SceneType *scene, const char *fileName, 00069 unsigned int depth = MaximumDepth, 00070 char *spatialObjectTypeName = NULL); 00071 00072 const MetaEvent * GetEvent() const { return m_Event; } 00073 void SetEvent(MetaEvent *event) { m_Event = event; } 00074 00076 void SetBinaryPoints(bool binary) { m_BinaryPoints = binary; } 00077 00079 void SetTransformPrecision(unsigned int precision) 00080 { 00081 m_TransformPrecision = precision; 00082 } 00083 unsigned int GetTransformPrecision(){ return m_TransformPrecision; } 00085 00087 void SetWriteImagesInSeparateFile(bool separate) 00088 { 00089 m_WriteImagesInSeparateFile = separate; 00090 } 00091 00098 void RegisterMetaConverter(const char *metaTypeName, 00099 const char *spatialObjectTypeName, 00100 MetaConverterBaseType *converter); 00101 00102 MetaScene * CreateMetaScene(SceneType *scene, 00103 unsigned int depth = MaximumDepth, 00104 char *name = NULL); 00105 00106 ScenePointer CreateSpatialObjectScene(MetaScene *scene); 00107 private: 00108 00109 typedef itk::SpatialObject< NDimensions > SpatialObjectType; 00110 typedef typename SpatialObjectType::Pointer SpatialObjectPointer; 00111 typedef typename SpatialObjectType::TransformType TransformType; 00112 00113 typedef std::list< MetaObject * > MetaObjectListType; 00114 00115 template <typename TConverter> 00116 MetaObject *SpatialObjectToMetaObject(SpatialObjectPointer &so) 00117 { 00118 typename TConverter::Pointer converter = TConverter::New(); 00119 // needed just for Image & ImageMask 00120 converter->SetWriteImagesInSeparateFile(this->m_WriteImagesInSeparateFile); 00121 return converter->SpatialObjectToMetaObject(so.GetPointer()); 00122 } 00123 template <typename TConverter> 00124 SpatialObjectPointer MetaObjectToSpatialObject(const MetaObject *mo) 00125 { 00126 typename TConverter::Pointer converter = TConverter::New(); 00127 return converter->MetaObjectToSpatialObject(mo); 00128 } 00129 void SetTransform(MetaObject *obj, TransformType *transform); 00130 00131 void SetTransform(SpatialObjectType *so, MetaObject *obj); 00132 00133 double m_Orientation[100]; 00134 double m_Position[10]; 00135 double m_CenterOfRotation[10]; 00136 00137 MetaEvent * m_Event; 00138 bool m_BinaryPoints; 00139 bool m_WriteImagesInSeparateFile; 00140 unsigned int m_TransformPrecision; 00141 ConverterMapType m_ConverterMap; 00142 }; 00143 } // end namespace itk 00144 00145 #ifndef ITK_MANUAL_INSTANTIATION 00146 #include "itkMetaSceneConverter.hxx" 00147 #endif 00148 00149 #endif 00150