Orfeo Toolbox  3.16
itkMetaEllipseConverter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkMetaEllipseConverter.txx,v $
5  Language: C++
6  Date: $Date: 2007-01-28 19:24:38 $
7  Version: $Revision: 1.7 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkMetaEllipseConverter_txx
18 #define __itkMetaEllipseConverter_txx
19 
21 
22 namespace itk
23 {
24 
26 template <unsigned int NDimensions>
29 {
30 
31 }
32 
33 
35 template <unsigned int NDimensions>
39 {
40  SpatialObjectPointer spatialObject = SpatialObjectType::New();
41 
42  double spacing[NDimensions];
43  typename SpatialObjectType::ArrayType radius;
44  for(unsigned int i=0;i<NDimensions;i++)
45  {
46  radius[i]=ellipse->Radius()[i];
47  spacing[i]=ellipse->ElementSpacing()[i];
48  }
49 
50  spatialObject->GetIndexToObjectTransform()->SetScaleComponent(spacing);
51  spatialObject->SetRadius(radius);
52  spatialObject->GetProperty()->SetName(ellipse->Name());
53  spatialObject->SetId(ellipse->ID());
54  spatialObject->SetParentId(ellipse->ParentID());
55  spatialObject->GetProperty()->SetRed(ellipse->Color()[0]);
56  spatialObject->GetProperty()->SetGreen(ellipse->Color()[1]);
57  spatialObject->GetProperty()->SetBlue(ellipse->Color()[2]);
58  spatialObject->GetProperty()->SetAlpha(ellipse->Color()[3]);
59 
60  return spatialObject;
61 }
62 
64 template <unsigned int NDimensions>
65 MetaEllipse*
68 {
69  MetaEllipse* ellipse = new MetaEllipse(NDimensions);
70 
71  float* radius = new float[NDimensions];
72  for(unsigned int i=0;i<NDimensions;i++)
73  {
74  radius[i] = spatialObject->GetRadius()[i];
75  }
76 
77  if(spatialObject->GetParent())
78  {
79  ellipse->ParentID(spatialObject->GetParent()->GetId());
80  }
81  ellipse->Radius(radius);
82  ellipse->ID(spatialObject->GetId());
83 
84  ellipse->Color(spatialObject->GetProperty()->GetRed(),
85  spatialObject->GetProperty()->GetGreen(),
86  spatialObject->GetProperty()->GetBlue(),
87  spatialObject->GetProperty()->GetAlpha());
88 
89  for(unsigned int i=0;i<NDimensions;i++)
90  {
91  ellipse->ElementSpacing(i, spatialObject->GetIndexToObjectTransform()
92  ->GetScaleComponent()[i]);
93  }
94 
95 
96  delete []radius;
97  return ellipse;
98 }
99 
100 
102 template <unsigned int NDimensions>
105 ::ReadMeta(const char* name)
106 {
107  SpatialObjectPointer spatialObject;
108  MetaEllipse* ellipse = new MetaEllipse();
109  ellipse->Read(name);
110  spatialObject = MetaEllipseToEllipseSpatialObject(ellipse);
111 
112  return spatialObject;
113 }
114 
115 
117 template <unsigned int NDimensions>
118 bool
120 ::WriteMeta(SpatialObjectType* spatialObject,const char* name)
121 {
122  MetaEllipse* ellipse = EllipseSpatialObjectToMetaEllipse(spatialObject);
123  ellipse->Write(name);
124  return true;
125 }
126 
127 } // end namespace itk
128 
129 #endif

Generated at Sat May 18 2013 23:53:38 for Orfeo Toolbox with doxygen 1.8.3.1