17 #ifndef __itkSphereMeshSource_txx
18 #define __itkSphereMeshSource_txx
28 template<
class TOutputMesh>
35 typename TOutputMesh::Pointer output = TOutputMesh::New();
49 template<
class TOutputMesh>
54 unsigned long i, j, jn, p, numpts;
55 double ustep, vstep, ubeg, vbeg, u, v;
59 numpts = m_ResolutionX*m_ResolutionY + 2;
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;
71 unsigned long tripoints[3] = {0,1,2};
74 typename OutputMeshType::Pointer outputMesh = this->GetOutput();
76 outputMesh->GetPoints()->Reserve(numpts);
78 outputMesh->SetCellsAllocationMethod( OutputMeshType::CellsAllocatedDynamicallyCellByCell );
81 typename PointsContainer::Iterator point = myPoints->Begin();
86 while( point != myPoints->End() )
88 for (u=ubeg, i=0; i < m_ResolutionX; u += ustep, i++)
90 for (v=vbeg, j=0; j < m_ResolutionY; v += vstep, j++)
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];
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];
133 p1[2] = m_Scale[2]*signu*(vcl_pow((
float)(vcl_fabs(vcl_sin(u))), (
float) m_Squareness1)) +
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))
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))
168 for(
unsigned int ii=0; ii+1 < m_ResolutionX; ii++)
170 for (
unsigned int jj=0; jj<m_ResolutionY; jj++)
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;
177 testCell->SetPointIds(tripoints);
178 outputMesh->SetCell(p, testCell );
182 tripoints[0] = tripoints[1];
183 tripoints[1] = tripoints[0]+m_ResolutionY;
184 testCell->SetPointIds(tripoints);
185 outputMesh->SetCell(p, testCell );
192 for (
unsigned int jj=0; jj<m_ResolutionY; jj++)
194 jn = (jj+1)%m_ResolutionY;
195 tripoints[0] = numpts-2;
199 testCell->SetPointIds(tripoints);
200 outputMesh->SetCell(p, testCell );
206 for (
unsigned int jj=0; jj<m_ResolutionY; jj++)
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;
213 testCell->SetPointIds(tripoints);
214 outputMesh->SetCell(p, testCell );
220 template<
class TOutputMesh>
225 Superclass::PrintSelf(os,indent);
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;