Commit 887aa340 by Pierre Kraemer

### Traversor pour calcul de normales et BB

parent 8906fc73
 ... ... @@ -27,7 +27,7 @@ #include "Geometry/basic.h" #include "Geometry/bounding_box.h" #include "Topology/generic/cellmarker.h" #include "Topology/generic/traversorCell.h" namespace CGoGN { ... ... @@ -42,17 +42,12 @@ template Geom::BoundingBox computeBoundingBox(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& select = SelectorTrue()) { Geom::BoundingBox bb ; CellMarker vmarker(map, VERTEX); for(Dart d = map.begin(); d != map.end(); map.next(d)) TraversorV t(map) ; for(Dart d = t.begin(); d != t.end(); d = t.next()) { if(select(d) && !vmarker.isMarked(d)) { vmarker.mark(d); if(select(d)) bb.addPoint(position[d]) ; } } return bb ; } ... ...
 ... ... @@ -25,6 +25,7 @@ #include "Algo/Geometry/basic.h" #include "Algo/Geometry/area.h" #include "Topology/generic/traversorCell.h" #include "Topology/generic/traversor2.h" #include ... ... @@ -41,35 +42,26 @@ namespace Geometry template typename PFP::VEC3 triangleNormal(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) { typedef typename PFP::VEC3 VEC3 ; const VEC3& p1 = position[d]; const VEC3& p2 = position[map.phi1(d)]; const VEC3& p3 = position[map.phi_1(d)]; VEC3 N = Geom::triangleNormal(p1, p2, p3) ; typename PFP::VEC3 N = Geom::triangleNormal(position[d], position[map.phi1(d)], position[map.phi_1(d)]) ; N.normalize() ; return N ; } template typename PFP::VEC3 newellNormal(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) { Dart it = d; typename PFP::VEC3 N(0); Traversor2FV t(map, d) ; do for(Dart it = t.begin(); it != t.end(); it = t.next()) { const typename PFP::VEC3& P = position[it]; it = map.phi1(it); const typename PFP::VEC3& Q = position[it]; const typename PFP::VEC3& Q = position[map.phi1(it)]; N[0] += (P[1] - Q[1]) * (P[2] + Q[2]); N[1] += (P[2] - Q[2]) * (P[0] + Q[0]); N[2] += (P[0] - Q[0]) * (P[1] + Q[1]); } while (it != d); } N.normalize(); return N; } ... ... @@ -77,25 +69,24 @@ typename PFP::VEC3 newellNormal(typename PFP::MAP& map, Dart d, const typename P template typename PFP::VEC3 faceNormal(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) { typedef typename PFP::VEC3 VEC3 ; if(map.isFaceTriangle(d)) return triangleNormal(map, d, position) ; else { VEC3 N(0) ; Dart it = d ; do { VEC3 n = triangleNormal(map, it, position) ; //if(!std::isnan(n[0]) && !std::isnan(n[1]) && !std::isnan(n[2])) if(!n.hasNan()) N += n ; it = map.phi1(it) ; } while (it != d) ; N.normalize() ; return N ; } return newellNormal(map, d, position) ; // { // VEC3 N(0) ; // Dart it = d ; // do // { // VEC3 n = triangleNormal(map, it, position) ; // //if(!std::isnan(n[0]) && !std::isnan(n[1]) && !std::isnan(n[2])) // if(!n.hasNan()) // N += n ; // it = map.phi1(it) ; // } while (it != d) ; // N.normalize() ; // return N ; // } } template ... ... @@ -104,8 +95,9 @@ typename PFP::VEC3 vertexNormal(typename PFP::MAP& map, Dart d, const typename P typedef typename PFP::VEC3 VEC3 ; VEC3 N(0) ; Dart it = d ; do Traversor2VF t(map, d) ; for(Dart it = t.begin(); it != t.end(); it = t.next()) { VEC3 n = faceNormal(map, it, position) ; if(!n.hasNan()) ... ... @@ -115,8 +107,8 @@ typename PFP::VEC3 vertexNormal(typename PFP::MAP& map, Dart d, const typename P n *= convexFaceArea(map, it, position) / (v1.norm2() * v2.norm2()) ; N += n ; } it = map.phi1(map.phi2(it)) ; } while (it != d) ; } N.normalize() ; return N ; } ... ... @@ -124,28 +116,22 @@ typename PFP::VEC3 vertexNormal(typename PFP::MAP& map, Dart d, const typename P template void computeNormalFaces(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& face_normal, const FunctorSelect& select, unsigned int thread) { CellMarker marker(map, FACE,thread); for(Dart d = map.begin(); d != map.end(); map.next(d)) TraversorF trav(map, thread); for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) { if(select(d) && !marker.isMarked(d)) { marker.mark(d); if (select(d)) face_normal[d] = faceNormal(map, d, position) ; } } } template void computeNormalVertices(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& normal, const FunctorSelect& select, unsigned int thread) { CellMarker marker(map, VERTEX, thread); for(Dart d = map.begin(); d != map.end(); map.next(d)) TraversorV trav(map, thread); for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) { if(select(d) && !marker.isMarked(d)) { marker.mark(d); if (select(d)) normal[d] = vertexNormal(map, d, position) ; } } } ... ... @@ -155,8 +141,6 @@ typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart typedef typename PFP::VEC3 VEC3 ; Dart dd = map.phi2(d) ; if(dd == d) return 0 ; const VEC3 n1 = faceNormal(map, d, position) ; const VEC3 n2 = faceNormal(map, dd, position) ; ... ... @@ -165,6 +149,7 @@ typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart typename PFP::REAL s = e * (n1 ^ n2) ; typename PFP::REAL c = n1 * n2 ; typename PFP::REAL a(0) ; // the following trick is useful for avoiding NaNs (due to floating point errors) if (c > 0.5) a = asin(s) ; else ... ... @@ -182,14 +167,11 @@ typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart template void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, typename PFP::TVEC3& position, typename PFP::TREAL& angles, const FunctorSelect& select, unsigned int thread) { CellMarker me(map, EDGE, thread) ; for(Dart d = map.begin(); d != map.end(); map.next(d)) TraversorE trav(map, thread); for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) { if(select(d) && !me.isMarked(d)) { me.mark(d) ; if (select(d)) angles[d] = computeAngleBetweenNormalsOnEdge(map, d, position) ; } } } ... ...