added Annulus and OrientedAnnulus to mesh creation helpers

This commit is contained in:
Paolo Cignoni 2013-04-15 20:14:27 +00:00
parent a5f4b797c7
commit cbba83d17c
1 changed files with 226 additions and 183 deletions

View File

@ -749,6 +749,50 @@ void FaceGrid(MeshType & in, const std::vector<int> &grid, int w, int h)
} }
} }
template <class MeshType>
void Annulus(MeshType & m, float externalRadius, float internalRadius, int slices)
{
m.Clear();
typename MeshType::VertexIterator vi = vcg::tri::Allocator<MeshType>::AddVertices(m,slices*2);
for ( int j = 0; j < slices; ++j)
{
float x = cos( 2.0 * M_PI / slices * j);
float y = sin( 2.0 * M_PI / slices * j);
(*vi).P() = typename MeshType::CoordType(x,y,0)*internalRadius;
++vi;
(*vi).P() = typename MeshType::CoordType(x,y,0)*externalRadius;
++vi;
}
typename MeshType::FaceIterator fi ;
for ( int j = 0; j < slices; ++j)
{
fi = vcg::tri::Allocator<MeshType>::AddFaces(m,1);
(*fi).V(0) = &m.vert[ ((j+0)*2+0)%(slices*2) ];
(*fi).V(1) = &m.vert[ ((j+1)*2+1)%(slices*2) ];
(*fi).V(2) = &m.vert[ ((j+0)*2+1)%(slices*2) ];
fi = vcg::tri::Allocator<MeshType>::AddFaces(m,1);
(*fi).V(0) = &m.vert[ ((j+1)*2+0)%(slices*2) ];
(*fi).V(1) = &m.vert[ ((j+1)*2+1)%(slices*2) ];
(*fi).V(2) = &m.vert[ ((j+0)*2+0)%(slices*2) ];
}
}
template <class MeshType>
void OrientedAnnulus(MeshType & m, Point3f center, Point3f norm, float externalRadius, float internalRadius, int slices)
{
Annulus(m,externalRadius,internalRadius, slices);
float angleRad = Angle(Point3f(0,0,1),norm);
Point3f axis = Point3f(0,0,1)^norm;
Matrix44f rotM;
rotM.SetRotateRad(angleRad,axis);
tri::UpdatePosition<MeshType>::Matrix(m,rotM);
tri::UpdatePosition<MeshType>::Translate(m,center);
}
template <class MeshType> template <class MeshType>
void Disk(MeshType & m, int slices) void Disk(MeshType & m, int slices)
@ -760,9 +804,8 @@ void Disk(MeshType & m, int slices)
for ( int j = 0; j < slices; ++j) for ( int j = 0; j < slices; ++j)
{ {
float x,y; float x = cos( 2.0 * M_PI / slices * j);
x = cos( 2.0 * M_PI / slices * j); float y = sin( 2.0 * M_PI / slices * j);
y = sin( 2.0 * M_PI / slices * j);
(*vi).P() = typename MeshType::CoordType(x,y,0); (*vi).P() = typename MeshType::CoordType(x,y,0);
++vi; ++vi;