Orfeo Toolbox  3.16
itkMetaArrowConverter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkMetaArrowConverter.txx,v $
5  Language: C++
6  Date: $Date: 2010-06-11 21:14:05 $
7  Version: $Revision: 1.6 $
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 __itkMetaArrowConverter_txx
18 #define __itkMetaArrowConverter_txx
19 
20 #include "itkMetaArrowConverter.h"
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  float length=arrow->Length();
44 
45  for(unsigned int i=0;i<NDimensions;i++)
46  {
47  spacing[i]=arrow->ElementSpacing()[i];
48  }
49 
50 
51  // convert position and direction/orientation
52  const double* metaPosition = arrow->Position();
53  const double* metaDirection = arrow->Direction();
54  typename SpatialObjectType::PointType position;
55  typename SpatialObjectType::VectorType direction;
56  for (unsigned int i = 0; i < NDimensions; i++)
57  {
58  position[i] = metaPosition[i];
59  direction[i] = metaDirection[i];
60  }
61  spatialObject->SetPosition(position);
62  spatialObject->SetDirection(direction);
63 
64  // convert the other fields
65  spatialObject->GetIndexToObjectTransform()->SetScaleComponent(spacing);
66  spatialObject->SetLength(length);
67  spatialObject->GetProperty()->SetName(arrow->Name());
68  spatialObject->SetId(arrow->ID());
69  spatialObject->SetParentId(arrow->ParentID());
70  spatialObject->GetProperty()->SetRed(arrow->Color()[0]);
71  spatialObject->GetProperty()->SetGreen(arrow->Color()[1]);
72  spatialObject->GetProperty()->SetBlue(arrow->Color()[2]);
73  spatialObject->GetProperty()->SetAlpha(arrow->Color()[3]);
74 
75  return spatialObject;
76 }
77 
79 template <unsigned int NDimensions>
80 MetaArrow*
83 {
84  MetaArrow* arrow = new MetaArrow(NDimensions);
85 
86  float length = spatialObject->GetLength();
87 
88  if(spatialObject->GetParent())
89  {
90  arrow->ParentID(spatialObject->GetParent()->GetId());
91  }
92 
93  // convert position and direction
94  double position[NDimensions];
95  double direction[NDimensions];
96  typename SpatialObjectType::PointType spPosition = spatialObject->GetPosition();
97  typename SpatialObjectType::VectorType spDirection = spatialObject->GetDirection();
98  for (unsigned int i = 0; i < NDimensions; i++)
99  {
100  position[i] = spPosition[i];
101  direction[i] = spDirection[i];
102  }
103  arrow->Position(position);
104  arrow->Direction(direction);
105 
106  // convert the rest of the parameters
107  arrow->Length(length);
108  arrow->ID(spatialObject->GetId());
109 
110  arrow->Color(spatialObject->GetProperty()->GetRed(),
111  spatialObject->GetProperty()->GetGreen(),
112  spatialObject->GetProperty()->GetBlue(),
113  spatialObject->GetProperty()->GetAlpha());
114 
115  for(unsigned int i=0;i<NDimensions;i++)
116  {
117  arrow->ElementSpacing(i,spatialObject->GetIndexToObjectTransform()
118  ->GetScaleComponent()[i]);
119  }
120 
121  return arrow;
122 }
123 
124 
126 template <unsigned int NDimensions>
129 ::ReadMeta(const char* name)
130 {
131  SpatialObjectPointer spatialObject;
132  MetaArrow* arrow = new MetaArrow();
133  arrow->Read(name);
134  spatialObject = MetaArrowToArrowSpatialObject(arrow);
135 
136  return spatialObject;
137 }
138 
139 
141 template <unsigned int NDimensions>
142 bool
144 ::WriteMeta(SpatialObjectType* spatialObject,const char* name)
145 {
146  MetaArrow* arrow = ArrowSpatialObjectToMetaArrow(spatialObject);
147  arrow->Write(name);
148  return true;
149 }
150 
151 } // end namespace itk
152 
153 #endif

Generated at Sat Feb 2 2013 23:52:43 for Orfeo Toolbox with doxygen 1.8.1.1