diff --git a/vcg/complex/algorithms/create/platonic.h b/vcg/complex/algorithms/create/platonic.h index 13a674fb..f4321caf 100644 --- a/vcg/complex/algorithms/create/platonic.h +++ b/vcg/complex/algorithms/create/platonic.h @@ -28,6 +28,9 @@ #include #include #include +#include +#include + namespace vcg { namespace tri { @@ -168,7 +171,7 @@ void Dodecahedron(DodMeshType & in) (*fi).V(0)=index[added[i] ]; (*fi).V(1)=index[reindex[penta[i*9 + order[j ] ] -1 ] ]; (*fi).V(2)=index[reindex[penta[i*9 + order[(j+1)%5] ] -1 ] ]; - if (in.HasPerFaceFlags()) { + if (HasPerFaceFlags(in)) { // tag faux edges (*fi).SetF(0); (*fi).SetF(2); @@ -309,7 +312,7 @@ void Hexahedron(MeshType &in) (*fi).V(0)=ivp[7]; (*fi).V(1)=ivp[3]; (*fi).V(2)=ivp[5]; ++fi; (*fi).V(0)=ivp[1]; (*fi).V(1)=ivp[5]; (*fi).V(2)=ivp[3]; - if (in.HasPerFaceFlags()) { + if (HasPerFaceFlags(in)) { FaceIterator fi=in.face.begin(); for (int k=0; k<12; k++) { (*fi).SetF(1); fi++; @@ -343,7 +346,7 @@ void Square(MeshType &in) (*fi).V(0)=ivp[0]; (*fi).V(1)=ivp[1]; (*fi).V(2)=ivp[2]; ++fi; (*fi).V(0)=ivp[2]; (*fi).V(1)=ivp[3]; (*fi).V(2)=ivp[0]; - if (in.HasPerFaceFlags()) { + if (HasPerFaceFlags(in)) { FaceIterator fi=in.face.begin(); for (int k=0; k<2; k++) { (*fi).SetF(2); fi++; @@ -517,7 +520,7 @@ void Box(MeshType &in, const typename MeshType::BoxType & bb ) (*fi).V(0)=ivp[7]; (*fi).V(1)=ivp[3]; (*fi).V(2)=ivp[5]; ++fi; (*fi).V(0)=ivp[1]; (*fi).V(1)=ivp[5]; (*fi).V(2)=ivp[3]; - if (in.HasPerFaceFlags()) { + if (HasPerFaceFlags(in)) { FaceIterator fi=in.face.begin(); for (int k=0; k<12; k++) { (*fi).SetF(1); fi++; @@ -596,8 +599,8 @@ void Grid(MeshType & in, int w, int h, float wl, float hl, float *data) Allocator::AddVertices(in,w*h); - float wld=wl/float(w); - float hld=hl/float(h); + float wld=wl/float(w-1); + float hld=hl/float(h-1); for(int i=0;i &grid, int w, int h) int V3i= grid[(i+1)*w+j+1]; int ndone=0; - bool quad = (V0i>=0 && V1i>=0 && V2i>=0 && V3i>=0 ) && in.HasPerFaceFlags(); + bool quad = (V0i>=0 && V1i>=0 && V2i>=0 && V3i>=0 ) && tri::HasPerFaceFlags(in); if(V0i>=0 && V2i>=0 && V3i>=0 ) { @@ -718,6 +721,34 @@ void FaceGrid(MeshType & in, const std::vector &grid, int w, int h) } } +template +void Disk(MeshType & m, int slices) +{ + typename MeshType::VertexIterator vi = vcg::tri::Allocator::AddVertices(m,slices+1); + (*vi).P() = typename MeshType::CoordType(0,0,0); + ++vi; + + for ( int j = 0; j < slices; ++j) + { + float x,y; + x = cos( 2.0 * M_PI / slices * j); + y = sin( 2.0 * M_PI / slices * j); + + (*vi).P() = typename MeshType::CoordType(x,y,0); + ++vi; + } + typename MeshType::FaceIterator fi ; + for ( int j = 0; j < slices; ++j) + { + int a = 1+(j+0)%slices; + int b = 1+(j+1)%slices; + fi = vcg::tri::Allocator::AddFaces(m,1); + (*fi).V(0) = &m.vert[ 0 ]; + (*fi).V(1) = &m.vert[ a ]; + (*fi).V(2) = &m.vert[ b ]; + } +} + template void Cylinder(int slices, int stacks, MeshType & m){ @@ -768,7 +799,7 @@ void Cylinder(int slices, int stacks, MeshType & m){ } } - if (m.HasPerFaceFlags()) { + if (HasPerFaceFlags(m)) { for (typename MeshType::FaceIterator fi=m.face.begin(); fi!=m.face.end(); fi++) { (*fi).SetF(2); } @@ -822,6 +853,31 @@ void GenerateCameraMesh(MeshType &in){ } } +template +void OrientedRect(MeshType &square, float width, float height, Point3f c, Point3f dir=Point3f(0,0,0), float angleDeg=0,Point3f preRotTra = Point3f(0,0,0)) +{ + float zeros[4]={0,0,0,0}; + square.Clear(); + Matrix44f rotM; + tri::Grid(square,2,2,width,height,zeros); + tri::UpdatePosition::Translate(square,Point3f(-5.0f,-5.0f,0.0f)); + if(angleDeg!=0){ + tri::UpdatePosition::Translate(square,preRotTra); + rotM.SetRotateDeg(angleDeg,dir); + tri::UpdatePosition::Matrix(square,rotM); + } + tri::UpdatePosition::Translate(square,c); + tri::UpdateBounding::Box(square); +} + +template +void OrientedSquare(MeshType &square, float width, Point3f c, Point3f dir=Point3f(0,0,0), float angleDeg=0,Point3f preRotTra = Point3f(0,0,0)) +{ + OrientedRect(square,width,width,c,dir,angleDeg,preRotTra); +} + + + //@} } // End Namespace TriMesh