Orfeo Toolbox  3.16
itkMetaBlobConverter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkMetaBlobConverter.txx,v $
5  Language: C++
6  Date: $Date: 2008-01-07 21:48:41 $
7  Version: $Revision: 1.8 $
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 __itkMetaBlobConverter_txx
18 #define __itkMetaBlobConverter_txx
19 
20 #include "itkMetaBlobConverter.h"
21 
22 namespace itk
23 {
24 
26 template <unsigned int NDimensions>
29 {
30 
31 }
32 
34 template <unsigned int NDimensions>
38 {
39 
40  typedef itk::BlobSpatialObject<NDimensions> BlobSpatialObjectType;
41  typename BlobSpatialObjectType::Pointer blob = BlobSpatialObjectType::New();
42 
43  //typedef BlobSpatialObjectType::VectorType VectorType;
45 
46  unsigned int ndims = Blob->NDims();
47  double spacing[NDimensions];
48  for(unsigned int ii=0;ii<ndims;ii++)
49  {
50  spacing[ii]=Blob->ElementSpacing()[ii];
51  }
52 
53  blob->GetIndexToObjectTransform()->SetScaleComponent(spacing);
54  blob->GetProperty()->SetName(Blob->Name());
55  blob->SetId(Blob->ID());
56  blob->SetParentId(Blob->ParentID());
57  blob->GetProperty()->SetRed(Blob->Color()[0]);
58  blob->GetProperty()->SetGreen(Blob->Color()[1]);
59  blob->GetProperty()->SetBlue(Blob->Color()[2]);
60  blob->GetProperty()->SetAlpha(Blob->Color()[3]);
61 
62  typedef itk::SpatialObjectPoint<NDimensions> BlobPointType;
63  typedef BlobPointType* BlobPointPointer;
64 
65 
66  typedef MetaBlob::PointListType ListType;
67  ListType::iterator it2 = Blob->GetPoints().begin();
68 
69  vnl_vector<double> v(ndims);
70 
71  for(unsigned int identifier=0;identifier< Blob->GetPoints().size();identifier++)
72  {
73  BlobPointType pnt;
74 
75  typedef typename BlobSpatialObjectType::PointType PointType;
76  PointType point;
77 
78  for(unsigned int ii=0;ii<ndims;ii++)
79  {
80  point[ii]=(*it2)->m_X[ii];
81  }
82 
83  pnt.SetPosition(point);
84 
85  pnt.SetRed((*it2)->m_Color[0]);
86  pnt.SetGreen((*it2)->m_Color[1]);
87  pnt.SetBlue((*it2)->m_Color[2]);
88  pnt.SetAlpha((*it2)->m_Color[3]);
89 
90  blob->GetPoints().push_back(pnt);
91  it2++;
92  }
93 
94  return blob;
95 }
96 
98 template <unsigned int NDimensions>
99 MetaBlob*
102 {
103  MetaBlob* Blob = new MetaBlob(NDimensions);
104 
105  // fill in the Blob information
106 
107  typename SpatialObjectType::PointListType::const_iterator i;
108  for(i = dynamic_cast<SpatialObjectType*>(spatialObject)->GetPoints().begin();
109  i != dynamic_cast<SpatialObjectType*>(spatialObject)->GetPoints().end();
110  i++)
111  {
112  BlobPnt* pnt = new BlobPnt(NDimensions);
113 
114  for(unsigned int d=0;d<NDimensions;d++)
115  {
116  pnt->m_X[d]=(*i).GetPosition()[d];
117  }
118 
119  pnt->m_Color[0] = (*i).GetRed();
120  pnt->m_Color[1] = (*i).GetGreen();
121  pnt->m_Color[2] = (*i).GetBlue();
122  pnt->m_Color[3] = (*i).GetAlpha();
123 
124  Blob->GetPoints().push_back(pnt);
125  }
126 
127  if(NDimensions == 2)
128  {
129  Blob->PointDim("x y red green blue alpha");
130  }
131  else
132  {
133  Blob->PointDim("x y z red green blue alpha");
134  }
135 
136  float color[4];
137  for(unsigned int ii=0;ii<4;ii++)
138  {
139  color[ii]=spatialObject->GetProperty()->GetColor()[ii];
140  }
141 
142  Blob->Color(color);
143  Blob->ID( spatialObject->GetId());
144  if(spatialObject->GetParent())
145  {
146  Blob->ParentID(spatialObject->GetParent()->GetId());
147  }
148  Blob->NPoints(Blob->GetPoints().size());
149 
150 
151  for(unsigned int ii=0;ii<NDimensions;ii++)
152  {
153  Blob->ElementSpacing(ii, spatialObject->GetIndexToObjectTransform()
154  ->GetScaleComponent()[ii]);
155  }
156 
157  return Blob;
158 }
159 
160 
162 template <unsigned int NDimensions>
165 ::ReadMeta(const char* name)
166 {
167  SpatialObjectPointer spatialObject;
168  MetaBlob* Blob = new MetaBlob();
169  Blob->Read(name);
170  spatialObject = MetaBlobToBlobSpatialObject(Blob);
171 
172  return spatialObject;
173 }
174 
175 
177 template <unsigned int NDimensions>
178 bool
180 ::WriteMeta(SpatialObjectType* spatialObject,const char* name)
181 {
182  MetaBlob* Blob = BlobSpatialObjectToMetaBlob(spatialObject);
183  Blob->BinaryData(true);
184  Blob->Write(name);
185  return true;
186 }
187 
188 } // end namespace itk
189 
190 #endif

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