Orfeo Toolbox  3.16
itkSphereMeshSource.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkSphereMeshSource.txx,v $
5  Language: C++
6  Date: $Date: 2009-04-06 16:49:23 $
7  Version: $Revision: 1.18 $
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 __itkSphereMeshSource_txx
18 #define __itkSphereMeshSource_txx
19 
20 #include "itkSphereMeshSource.h"
21 
22 namespace itk
23 {
24 
28 template<class TOutputMesh>
31 {
35  typename TOutputMesh::Pointer output = TOutputMesh::New();
37  this->ProcessObject::SetNthOutput(0, output.GetPointer());
38  m_Squareness1 = 1.0;
39  m_Squareness2 = 1.0;
40  m_Center.Fill(0);
41  m_Scale.Fill(1);
42  m_ResolutionX = 4;
43  m_ResolutionY = 4;
44 }
45 
46 /*
47  *
48  */
49 template<class TOutputMesh>
50 void
53 {
54  unsigned long i, j, jn, p, numpts;
55  double ustep, vstep, ubeg, vbeg, u, v;
56  int signu, signv;
57 
58  // calculate the number os cells and points
59  numpts = m_ResolutionX*m_ResolutionY + 2;
60 
61  // calculate the steps using resolution
62  ustep = vnl_math::pi / (m_ResolutionX+1);
63  vstep = 2.0*vnl_math::pi / m_ResolutionY;
64  ubeg = (-vnl_math::pi/2.0) + ustep;
65  vbeg = -vnl_math::pi;
66 
68  // nodes allocation
69 
70  // the temporary container of nodes' connectness
71  unsigned long tripoints[3] = {0,1,2};
72 
73  // memory allocation for nodes
74  typename OutputMeshType::Pointer outputMesh = this->GetOutput();
75 
76  outputMesh->GetPoints()->Reserve(numpts);
77 
78  outputMesh->SetCellsAllocationMethod( OutputMeshType::CellsAllocatedDynamicallyCellByCell );
79 
80  PointsContainerPointer myPoints = outputMesh->GetPoints();
81  typename PointsContainer::Iterator point = myPoints->Begin();
82 
83  OPointType p1;
84 
85  // calculate all regular nodes
86  while( point != myPoints->End() )
87  {
88  for (u=ubeg, i=0; i < m_ResolutionX; u += ustep, i++)
89  {
90  for (v=vbeg, j=0; j < m_ResolutionY; v += vstep, j++)
91  {
92  if (vcl_cos(u) > 0)
93  {
94  signu = 1;
95  }
96  else
97  {
98  signu = -1;
99  }
100  if (vcl_cos(v) > 0)
101  {
102  signv = 1;
103  }
104  else
105  {
106  signv = -1;
107  }
108 
109  p1[0] = m_Scale[0]*signu*(vcl_pow((float)(vcl_fabs(vcl_cos(u))), (float) m_Squareness1))*signv*
110  (vcl_pow((float)(vcl_fabs(vcl_cos(v))), (float) m_Squareness2)) + m_Center[0];
111 
112  if (vcl_sin(v) > 0)
113  {
114  signv = 1;
115  }
116  else
117  {
118  signv = -1;
119  }
120 
121  p1[1] = m_Scale[1]*signu*(vcl_pow((float)(vcl_fabs(vcl_cos(u))), (float) m_Squareness1))*signv*
122  (vcl_pow((float)(vcl_fabs(vcl_sin(v))), (float) m_Squareness2)) + m_Center[1];
123 
124  if (vcl_sin(u) > 0)
125  {
126  signu = 1;
127  }
128  else
129  {
130  signu = -1;
131  }
132 
133  p1[2] = m_Scale[2]*signu*(vcl_pow((float)(vcl_fabs(vcl_sin(u))), (float) m_Squareness1)) +
134  m_Center[2];
135 
136  point.Value() = p1;
137  ++point;
138  }
139  }
140 
141  // calculate the south pole node
142  p1[0] = (m_Scale[0]*(vcl_pow((float)(vcl_fabs(vcl_cos(-vnl_math::pi/2))),1.0f))*
143  (vcl_pow((float)(vcl_fabs(vcl_cos(0.0))),1.0f)) + m_Center[0]);
144  p1[1] = (m_Scale[1]*(vcl_pow((float)(vcl_fabs(vcl_cos(-vnl_math::pi/2))),1.0f))*
145  (vcl_pow((float)(vcl_fabs(vcl_sin(0.0))),1.0f)) + m_Center[1]);
146  p1[2] = (m_Scale[2]*-1*(vcl_pow((float)(vcl_fabs(vcl_sin(-vnl_math::pi/2))),1.0f))
147  + m_Center[2]);
148  point.Value() = p1;
149  ++point;
150 
151  // calculate the north pole node
152  p1[0] = (m_Scale[0]*(vcl_pow((float)(vcl_fabs(vcl_cos(vnl_math::pi/2))),1.0f))*
153  (vcl_pow(vcl_fabs(vcl_cos(0.0)),1.0)) + m_Center[0]);
154  p1[1] = (m_Scale[1]*(vcl_pow((float)(vcl_fabs(vcl_cos(vnl_math::pi/2))),1.0f))*
155  (vcl_pow(vcl_fabs(vcl_sin(0.0)),1.0)) + m_Center[1]);
156  p1[2] = (m_Scale[2]*(vcl_pow((float)(vcl_fabs(vcl_sin(vnl_math::pi/2))),1.0f))
157  + m_Center[2]);
158  point.Value() = p1;
159  ++point;
160  }
161 
163  // cells allocation
164  p = 0;
165 
166  // store all regular cells
167  CellAutoPointer testCell;
168  for(unsigned int ii=0; ii+1 < m_ResolutionX; ii++)
169  {
170  for (unsigned int jj=0; jj<m_ResolutionY; jj++)
171  {
172  jn = (jj+1)%m_ResolutionY;
173  tripoints[0] = ii*m_ResolutionY+jj;
174  tripoints[1] = tripoints[0]-jj+jn;
175  tripoints[2] = tripoints[0]+m_ResolutionY;
176  testCell.TakeOwnership( new TriCellType );
177  testCell->SetPointIds(tripoints);
178  outputMesh->SetCell(p, testCell );
179  outputMesh->SetCellData(p, (OPixelType)3.0);
180  p++;
181  testCell.TakeOwnership( new TriCellType );
182  tripoints[0] = tripoints[1];
183  tripoints[1] = tripoints[0]+m_ResolutionY;
184  testCell->SetPointIds(tripoints);
185  outputMesh->SetCell(p, testCell );
186  outputMesh->SetCellData(p, (OPixelType)3.0);
187  p++;
188  }
189  }
190 
191  // store cells containing the south pole nodes
192  for (unsigned int jj=0; jj<m_ResolutionY; jj++)
193  {
194  jn = (jj+1)%m_ResolutionY;
195  tripoints[0] = numpts-2;
196  tripoints[1] = jn;
197  tripoints[2] = jj;
198  testCell.TakeOwnership( new TriCellType );
199  testCell->SetPointIds(tripoints);
200  outputMesh->SetCell(p, testCell );
201  outputMesh->SetCellData(p, (OPixelType)1.0);
202  p++;
203  }
204 
205  // store cells containing the north pole nodes
206  for (unsigned int jj=0; jj<m_ResolutionY; jj++)
207  {
208  jn = (jj+1)%m_ResolutionY;
209  tripoints[2] = (m_ResolutionX-1)*m_ResolutionY+jj;
210  tripoints[1] = numpts-1;
211  tripoints[0] = tripoints[2]-jj+jn;
212  testCell.TakeOwnership( new TriCellType );
213  testCell->SetPointIds(tripoints);
214  outputMesh->SetCell(p, testCell );
215  outputMesh->SetCellData(p, (OPixelType)2.0);
216  p++;
217  }
218 }
219 
220 template<class TOutputMesh>
221 void
223 ::PrintSelf( std::ostream& os, Indent indent ) const
224 {
225  Superclass::PrintSelf(os,indent);
226 
227  os << indent << "Center: " << m_Center << std::endl;
228  os << indent << "Scale: " << m_Scale << std::endl;
229  os << indent << "ResolutionX: " << m_ResolutionX << std::endl;
230  os << indent << "ResolutionX: " << m_ResolutionY << std::endl;
231  os << indent << "Squareness1: " << m_Squareness1 << std::endl;
232  os << indent << "Squareness2: " << m_Squareness2 << std::endl;
233 }
234 
235 } // end namespace itk
236 
237 #endif

Generated at Sun May 19 2013 00:08:56 for Orfeo Toolbox with doxygen 1.8.3.1