Corrected refine, Now instead of using a dangerous vector of vertex type (that could cause issues with ocf types) it use just a vector of pair<position,normal>

This commit is contained in:
Paolo Cignoni 2012-10-22 18:37:51 +00:00
parent c932c5d60a
commit c980267cd8
1 changed files with 26 additions and 14 deletions

View File

@ -221,14 +221,12 @@ struct Centroid {
} }
inline void addVertex(const typename MESH_TYPE::VertexType &v, LScalar w) { inline void addVertex(const typename MESH_TYPE::VertexType &v, LScalar w) {
LVector p(v.cP().X(), v.cP().Y(), v.cP().Z()); LVector p(v.cP().X(), v.cP().Y(), v.cP().Z());
LVector n(v.cN().X(), v.cN().Y(), v.cN().Z());
sumP += p * w; sumP += p * w;
sumW += w; sumW += w;
} }
inline void project(typename MESH_TYPE::VertexType &v) const { inline void project(std::pair<Point3f,Point3f> &nv) const {
LVector position = sumP / sumW; LVector position = sumP / sumW;
v.P() = Coord(position.X(), position.Y(), position.Z()); nv.first = Coord(position.X(), position.Y(), position.Z());
} }
}; };
@ -274,7 +272,7 @@ struct LS3Projection {
sumDotPP += w * vcg::SquaredNorm(p); sumDotPP += w * vcg::SquaredNorm(p);
sumW += w; sumW += w;
} }
void project(typename MESH_TYPE::VertexType &v) const { void project(std::pair<Point3f,Point3f> &nv) const {
LScalar invSumW = Scalar(1)/sumW; LScalar invSumW = Scalar(1)/sumW;
LScalar aux4 = beta * LScalar(0.5) * LScalar aux4 = beta * LScalar(0.5) *
(sumDotPN - invSumW*sumP.dot(sumN)) (sumDotPN - invSumW*sumP.dot(sumN))
@ -339,8 +337,8 @@ struct LS3Projection {
normal.Normalize(); normal.Normalize();
} }
v.P() = Coord(position.X(), position.Y(), position.Z()); nv.first = Coord(position.X(), position.Y(), position.Z());
v.N() = Coord(normal.X(), normal.Y(), normal.Z()); nv.second = Coord(normal.X(), normal.Y(), normal.Z());
} }
}; };
@ -374,7 +372,10 @@ struct OddPointLoopGeneric : public std::unary_function<face::Pos<typename MESH_
if (he.IsBorder()) { if (he.IsBorder()) {
proj.addVertex(*l, 0.5); proj.addVertex(*l, 0.5);
proj.addVertex(*r, 0.5); proj.addVertex(*r, 0.5);
proj.project(nv); std::pair<Point3f,Point3f>pp;
proj.project(pp);
nv.P()=pp.first;
nv.N()=pp.second;
} }
else { else {
he.FlipE(); he.FlipV(); he.FlipE(); he.FlipV();
@ -398,7 +399,11 @@ struct OddPointLoopGeneric : public std::unary_function<face::Pos<typename MESH_
proj.addVertex(*u, 1.0/8.0); proj.addVertex(*u, 1.0/8.0);
proj.addVertex(*d, 1.0/8.0); proj.addVertex(*d, 1.0/8.0);
} }
proj.project(nv); std::pair<Point3f,Point3f>pp;
proj.project(pp);
nv.P()=pp.first;
nv.N()=pp.second;
// proj.project(nv);
} }
} }
@ -437,7 +442,7 @@ struct EvenPointLoopGeneric : public std::unary_function<face::Pos<typename MESH
inline EvenPointLoopGeneric(Projection proj = Projection(), Weight weight = Weight()) : inline EvenPointLoopGeneric(Projection proj = Projection(), Weight weight = Weight()) :
proj(proj), weight(weight), valence(0) {} proj(proj), weight(weight), valence(0) {}
void operator()(typename MESH_TYPE::VertexType &nv, face::Pos<typename MESH_TYPE::FaceType> ep) { void operator()(std::pair<Point3f,Point3f> &nv, face::Pos<typename MESH_TYPE::FaceType> ep) {
proj.reset(); proj.reset();
face::Pos<typename MESH_TYPE::FaceType> he(ep.f,ep.z,ep.f->V(ep.z)); face::Pos<typename MESH_TYPE::FaceType> he(ep.f,ep.z,ep.f->V(ep.z));
@ -473,7 +478,11 @@ struct EvenPointLoopGeneric : public std::unary_function<face::Pos<typename MESH
proj.addVertex(*curr, 3.0/4.0); proj.addVertex(*curr, 3.0/4.0);
proj.addVertex(*l, 1.0/8.0); proj.addVertex(*l, 1.0/8.0);
proj.addVertex(*r, 1.0/8.0); proj.addVertex(*r, 1.0/8.0);
// std::pair<Point3f,Point3f>pp;
proj.project(nv); proj.project(nv);
// nv.P()=pp.first;
// nv.N()=pp.second;
// proj.project(nv);
} }
else { // Inner rule else { // Inner rule
// assert(!he.v->IsB()); border flag no longer updated (useless) // assert(!he.v->IsB()); border flag no longer updated (useless)
@ -565,7 +574,8 @@ bool RefineOddEvenE(MESH_TYPE &m, ODD_VERT odd, EVEN_VERT even, PREDICATE edgePr
// store updated vertices // store updated vertices
std::vector<bool> updatedList(m.vn, false); std::vector<bool> updatedList(m.vn, false);
std::vector<typename MESH_TYPE::VertexType> newEven(m.vn); //std::vector<typename MESH_TYPE::VertexType> newEven(m.vn);
std::vector<std::pair<Point3f,Point3f> > newEven(m.vn);
typename MESH_TYPE::VertexIterator vi; typename MESH_TYPE::VertexIterator vi;
typename MESH_TYPE::FaceIterator fi; typename MESH_TYPE::FaceIterator fi;
@ -597,11 +607,13 @@ bool RefineOddEvenE(MESH_TYPE &m, ODD_VERT odd, EVEN_VERT even, PREDICATE edgePr
// refine dei vertici odd, crea dei nuovi vertici in coda // refine dei vertici odd, crea dei nuovi vertici in coda
RefineE< MESH_TYPE, ODD_VERT > (m, odd, edgePred, RefineSelected, cbOdd); RefineE< MESH_TYPE, ODD_VERT > (m, odd, edgePred, RefineSelected, cbOdd);
typename std::vector<typename MESH_TYPE::VertexType>::iterator nei; typename std::vector<std::pair<Point3f,Point3f> >::iterator nei;
for (nei=newEven.begin(); nei!=newEven.end(); ++nei) { for (nei=newEven.begin(); nei!=newEven.end(); ++nei) {
if(updatedList[nei-newEven.begin()]) { if(updatedList[nei-newEven.begin()]) {
m.vert[nei-newEven.begin()].ImportData(*nei); // m.vert[nei-newEven.begin()].ImportData(*nei);
assert(m.vert[nei-newEven.begin()].N() == nei->N()); // assert(m.vert[nei-newEven.begin()].N() == nei->N());
m.vert[nei-newEven.begin()].P()=(*nei).first;
m.vert[nei-newEven.begin()].N()=(*nei).second;
} }
} }