From c1d6d4e9bdb44fbad55c70ed18050ef5a097502e Mon Sep 17 00:00:00 2001 From: cignoni Date: Tue, 1 Jul 2014 10:11:23 +0000 Subject: [PATCH] Improved float/double consistency removing some wrong Point3f and substitued with MeshType::CoordType. Removed also the use of an additional mesh type called spheremesh to create sphere (the method require ff adj). --- vcg/complex/algorithms/create/platonic.h | 73 +++++++++++++----------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/vcg/complex/algorithms/create/platonic.h b/vcg/complex/algorithms/create/platonic.h index a355d450..04254835 100644 --- a/vcg/complex/algorithms/create/platonic.h +++ b/vcg/complex/algorithms/create/platonic.h @@ -866,7 +866,7 @@ void Disk(MeshType & m, int slices) } template -void OrientedDisk(MeshType &m, int slices, Point3f center, Point3f norm, float radius) +void OrientedDisk(MeshType &m, int slices, typename MeshType::CoordType center, typename MeshType::CoordType norm, float radius) { Disk(m,slices); tri::UpdatePosition::Scale(m,radius); @@ -880,19 +880,22 @@ void OrientedDisk(MeshType &m, int slices, Point3f center, Point3f norm, float r } template -void OrientedEllipticPrism(MeshType & m, const Point3f origin, const Point3f end, float radius, float xScale, float yScale,bool capped, int slices=32, int stacks=4 ) +void OrientedEllipticPrism(MeshType & m, const typename MeshType::CoordType origin, const typename MeshType::CoordType end, float radius, float xScale, float yScale,bool capped, int slices=32, int stacks=4 ) { + typedef typename MeshType::ScalarType ScalarType; + typedef typename MeshType::CoordType CoordType; + typedef Matrix44 Matrix44x; Cylinder(slices,stacks,m,capped); - tri::UpdatePosition::Translate(m,Point3f(0,1,0)); - tri::UpdatePosition::Scale(m,Point3f(1,0.5f,1)); - tri::UpdatePosition::Scale(m,Point3f(xScale,1.0f,yScale)); + tri::UpdatePosition::Translate(m,CoordType(0,1,0)); + tri::UpdatePosition::Scale(m,CoordType(1,0.5f,1)); + tri::UpdatePosition::Scale(m,CoordType(xScale,1.0f,yScale)); float height = Distance(origin,end); - tri::UpdatePosition::Scale(m,Point3f(radius,height,radius)); - Point3f norm = end-origin; - float angleRad = Angle(Point3f(0,1,0),norm); - Point3f axis = Point3f(0,1,0)^norm; - Matrix44f rotM; + tri::UpdatePosition::Scale(m,CoordType(radius,height,radius)); + CoordType norm = end-origin; + ScalarType angleRad = Angle(CoordType(0,1,0),norm); + CoordType axis = CoordType(0,1,0)^norm; + Matrix44x rotM; rotM.SetRotateRad(angleRad,axis); tri::UpdatePosition::Matrix(m,rotM); tri::UpdatePosition::Translate(m,origin); @@ -900,7 +903,7 @@ void OrientedEllipticPrism(MeshType & m, const Point3f origin, const Point3f end } template -void OrientedCylinder(MeshType & m, const Point3f origin, const Point3f end, float radius, bool capped, int slices=32, int stacks=4 ) +void OrientedCylinder(MeshType & m, const typename MeshType::CoordType origin, const typename MeshType::CoordType end, float radius, bool capped, int slices=32, int stacks=4 ) { OrientedEllipticPrism(m,origin,end,radius,1.0f,1.0f,capped,slices,stacks); } @@ -982,7 +985,7 @@ void BuildPrismFaceShell(MeshType &mIn, MeshType &mOut, float height=0, float in tri::UpdateFlags::FaceClearV(mIn); for(size_t i=0;i vertVec; std::vector faceVec; tri::PolygonSupport::ExtractPolygon(&(mIn.face[i]),vertVec,faceVec); @@ -1000,41 +1003,44 @@ void BuildPrismFaceShell(MeshType &mIn, MeshType &mOut, float height=0, float in bary/=float(faceVec.size()); // Add vertices (alternated top and bottom) - tri::Allocator<_SphMesh>::AddVertex(faceM, bary-nf); - tri::Allocator<_SphMesh>::AddVertex(faceM, bary+nf); + tri::Allocator::AddVertex(faceM, bary-nf); + tri::Allocator::AddVertex(faceM, bary+nf); for(size_t j=0;jP() - bary); delta.Normalize(); delta = delta*inset; - tri::Allocator<_SphMesh>::AddVertex(faceM, vertVec[j]->P()-delta-nf); - tri::Allocator<_SphMesh>::AddVertex(faceM, vertVec[j]->P()-delta+nf); + tri::Allocator::AddVertex(faceM, vertVec[j]->P()-delta-nf); + tri::Allocator::AddVertex(faceM, vertVec[j]->P()-delta+nf); } // Build top and bottom faces for(size_t j=0;j::AddFace(faceM, 0, 2+(j+0)*2, 2+((j+1)%vn)*2 ); + tri::Allocator::AddFace(faceM, 0, 2+(j+0)*2, 2+((j+1)%vn)*2 ); for(size_t j=0;j::AddFace(faceM, 1, 3+((j+1)%vn)*2, 3+(j+0)*2 ); + tri::Allocator::AddFace(faceM, 1, 3+((j+1)%vn)*2, 3+(j+0)*2 ); // Build side strip for(size_t j=0;j::AddFace(faceM, 2+ j0*2 + 0 , 2+ j0*2+1, 2+j1*2+0); - tri::Allocator<_SphMesh>::AddFace(faceM, 2+ j0*2 + 1 , 2+ j1*2+1, 2+j1*2+0); + tri::Allocator::AddFace(faceM, 2+ j0*2 + 0 , 2+ j0*2+1, 2+j1*2+0); + tri::Allocator::AddFace(faceM, 2+ j0*2 + 1 , 2+ j1*2+1, 2+j1*2+0); } for(size_t j=0;j<2*vn;++j) faceM.face[j].SetS(); - tri::UpdateTopology<_SphMesh>::FaceFace(faceM); - tri::UpdateFlags<_SphMesh>::FaceBorderFromFF(faceM); - tri::Refine(faceM, MidPoint<_SphMesh>(&faceM),0,true); - tri::Refine(faceM, MidPoint<_SphMesh>(&faceM),0,true); - tri::UpdateSelection<_SphMesh>::VertexFromFaceStrict(faceM); - tri::Smooth<_SphMesh>::VertexCoordLaplacian(faceM,2,true,true); + if(smoothFlag) + { + tri::UpdateTopology::FaceFace(faceM); + tri::UpdateFlags::FaceBorderFromFF(faceM); + tri::Refine(faceM, MidPoint(&faceM),0,true); + tri::Refine(faceM, MidPoint(&faceM),0,true); + tri::UpdateSelection::VertexFromFaceStrict(faceM); + tri::Smooth::VertexCoordLaplacian(faceM,2,true,true); + } - tri::Append::Mesh(mOut,faceM); + tri::Append::Mesh(mOut,faceM); } // end main loop for each face; } @@ -1061,23 +1067,24 @@ void BuildSphereVertexShell(MeshType &mIn, MeshType &mOut, float radius=0, int r if(radius==0) radius = mIn.bbox.Diag()/100.0f; for(size_t i=0;i::Scale(mSph,radius); - tri::UpdatePosition<_SphMesh>::Translate(mSph,mIn.vert[i].P()); - tri::Append::Mesh(mOut,mSph); + tri::UpdatePosition::Scale(mSph,radius); + tri::UpdatePosition::Translate(mSph,mIn.vert[i].P()); + tri::Append::Mesh(mOut,mSph); } } template void BuildCylinderVertexShell(MeshType &mIn, MeshType &mOut, float radius=0, float height=0 ) { + typedef typename MeshType::CoordType CoordType; if(radius==0) radius = mIn.bbox.Diag()/100.0f; if(height==0) height = mIn.bbox.Diag()/200.0f; for(size_t i=0;i