Cleaned up BuildMeshFromCoordVectorIndexVector

This commit is contained in:
Paolo Cignoni 2017-07-23 09:32:51 +02:00
parent 77c0240737
commit 005adde169
1 changed files with 14 additions and 24 deletions

View File

@ -42,7 +42,7 @@ namespace tri {
that represent surfaces of platonic solids,
and other simple shapes.
The 1st parameter is the mesh that will
The 1st parameter is usually the mesh that will
be filled with the solid.
*/
template <class TetraMeshType>
@ -73,7 +73,7 @@ void Tetrahedron(TetraMeshType &in)
/// builds a Dodecahedron,
/// (each pentagon is composed of 5 triangles)
/// (each pentagonal face is composed by 5 triangles)
template <class DodMeshType>
void Dodecahedron(DodMeshType & in)
{
@ -697,8 +697,6 @@ template <class MeshType, class InCoordType, class InFaceIndexType >
void BuildMeshFromCoordVectorIndexVector(MeshType & in, const std::vector<InCoordType> & v, const std::vector<InFaceIndexType> & f)
{
typedef typename MeshType::CoordType CoordType;
typedef typename MeshType::VertexPointer VertexPointer;
typedef typename MeshType::VertexIterator VertexIterator;
in.Clear();
Allocator<MeshType>::AddVertices(in,v.size());
@ -709,25 +707,16 @@ void BuildMeshFromCoordVectorIndexVector(MeshType & in, const std::vector<InCoor
const InCoordType &vv = v[i];
in.vert[i].P() = CoordType( vv[0],vv[1],vv[2]);
}
std::vector<VertexPointer> index(in.vn);
VertexIterator j;
int k;
for(k=0,j=in.vert.begin();j!=in.vert.end();++j,++k)
index[k] = &*j;
for(size_t i=0;i<f.size();++i)
{
const InFaceIndexType &ff= f[i];
assert( ff[0]>=0 );
assert( ff[1]>=0 );
assert( ff[2]>=0 );
assert( ff[0]<in.vn );
assert( ff[1]<in.vn );
assert( ff[2]<in.vn );
assert( ff[0]>=0 && ff[0]<in.vn);
assert( ff[1]>=0 && ff[1]<in.vn);
assert( ff[2]>=0 && ff[2]<in.vn);
in.face[i].V(0) = &in.vert[ ff[0] ];
in.face[i].V(1) = &in.vert[ ff[0] ];
in.face[i].V(2) = &in.vert[ ff[0] ];
in.face[i].V(1) = &in.vert[ ff[1] ];
in.face[i].V(2) = &in.vert[ ff[2] ];
}
tri::UpdateBounding<MeshType>::Box(in);
@ -1092,7 +1081,7 @@ class _SphMesh : public tri::TriMesh< vector<_SphVertex>, vector<_SphFace>
template <class MeshType>
void BuildPrismFaceShell(MeshType &mIn, MeshType &mOut, float height=0, float inset=0, bool smoothFlag=true )
void BuildPrismFaceShell(MeshType &mIn, MeshType &mOut, float height=0, float inset=0, bool smoothFlag=false )
{
typedef typename MeshType::VertexPointer VertexPointer;
typedef typename MeshType::FacePointer FacePointer;
@ -1101,6 +1090,8 @@ void BuildPrismFaceShell(MeshType &mIn, MeshType &mOut, float height=0, float in
if(inset==0) inset = mIn.bbox.Diag()/200.0f;
tri::UpdateTopology<MeshType>::FaceFace(mIn);
tri::UpdateFlags<MeshType>::FaceClearV(mIn);
tri::UpdateNormal<MeshType>::PerVertexNormalizedPerFace(mIn);
for(size_t i=0;i<mIn.face.size();++i) if(!mIn.face[i].IsV())
{
MeshType faceM;
@ -1111,7 +1102,7 @@ void BuildPrismFaceShell(MeshType &mIn, MeshType &mOut, float height=0, float in
CoordType nf(0,0,0);
for(size_t j=0;j<faceVec.size();++j)
nf+=faceVec[j]->N().Normalize() * DoubleArea(*faceVec[j]);
nf+=vcg::NormalizedTriangleNormal(*faceVec[j]) * DoubleArea(*faceVec[j]);
nf.Normalize();
nf = nf*height/2.0f;
@ -1121,14 +1112,14 @@ void BuildPrismFaceShell(MeshType &mIn, MeshType &mOut, float height=0, float in
bary/=float(faceVec.size());
// Add vertices (alternated top and bottom)
tri::Allocator<MeshType>::AddVertex(faceM, bary-nf);
tri::Allocator<MeshType>::AddVertex(faceM, bary+nf);
tri::Allocator<MeshType>::AddVertex(faceM, bary-nf);
for(size_t j=0;j<vn;++j){
CoordType delta = (vertVec[j]->P() - bary);
delta.Normalize();
delta = delta*inset;
tri::Allocator<MeshType>::AddVertex(faceM, vertVec[j]->P()-delta-nf);
tri::Allocator<MeshType>::AddVertex(faceM, vertVec[j]->P()-delta+nf);
tri::Allocator<MeshType>::AddVertex(faceM, vertVec[j]->P()-delta-nf);
}
// Build top and bottom faces
@ -1150,7 +1141,6 @@ void BuildPrismFaceShell(MeshType &mIn, MeshType &mOut, float height=0, float in
if(smoothFlag)
{
faceM.face.EnableFFAdjacency();
tri::UpdateTopology<MeshType>::FaceFace(faceM);
tri::UpdateFlags<MeshType>::FaceBorderFromFF(faceM);
tri::Refine(faceM, MidPoint<MeshType>(&faceM),0,true);