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) ; } } } ... ...
 ... ... @@ -22,16 +22,16 @@ * * *******************************************************************************/ #include "Topology/generic/attributeHandler.h" #include "Topology/generic/dartmarker.h" #include "Topology/generic/cellmarker.h" #include "Topology/generic/traversorCell.h" #include "Utils/vbo.h" #include "Topology/generic/attributeHandler.h" #include "Geometry/intersection.h" #include "Algo/Geometry/normal.h" #include "Topology/generic/traversorCell.h" namespace CGoGN { ... ... @@ -44,7 +44,6 @@ namespace Render namespace GL2 { inline bool MapRender::cmpVP(VertexPoly* lhs, VertexPoly* rhs) { // return lhs->value < rhs->value; ... ... @@ -54,7 +53,6 @@ inline bool MapRender::cmpVP(VertexPoly* lhs, VertexPoly* rhs) return lhs->value < rhs->value; } template bool MapRender::inTriangle(const VEC3& P, const VEC3& normal, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc) { ... ... @@ -72,8 +70,6 @@ bool MapRender::inTriangle(const VEC3& P, const VEC3& normal, const VEC3& Ta, c return true; } template void MapRender::recompute2Ears( AttributeHandler& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly, VPMS& ears, bool convex) { ... ... @@ -136,7 +132,6 @@ void MapRender::recompute2Ears( AttributeHandler& position, vp2->ear = ears.insert(vp2); } template float MapRender::computeEarAngle(const typename PFP::VEC3& P1, const typename PFP::VEC3& P2, const typename PFP::VEC3& P3, const typename PFP::VEC3& normalPoly) { ... ... @@ -155,7 +150,6 @@ float MapRender::computeEarAngle(const typename PFP::VEC3& P1, const typename PF return dotpr; } template bool MapRender::computeEarIntersection(AttributeHandler& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly) { ... ... @@ -180,8 +174,6 @@ bool MapRender::computeEarIntersection(AttributeHandler& pos return true; } template inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector& tableIndices) { ... ... @@ -287,7 +279,6 @@ inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector inline void MapRender::addTri(typename PFP::MAP& map, Dart d, std::vector& tableIndices) { ... ... @@ -317,15 +308,13 @@ inline void MapRender::addTri(typename PFP::MAP& map, Dart d, std::vector void MapRender::initTriangles(typename PFP::MAP& map, const FunctorSelect& good, std::vector& tableIndices, unsigned int thread) { // DartMarker m(map, thread); tableIndices.reserve(4 * map.getNbDarts() / 3); TraversorF trav(map); for (Dart d = trav.begin(); d!= trav.end(); d = trav.next()) TraversorF trav(map, thread); for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) { if (good(d)) addTri(map, d, tableIndices); ... ... @@ -391,23 +380,12 @@ void MapRender::initTrianglesOptimized(typename PFP::MAP& map, const FunctorSele template void MapRender::initLines(typename PFP::MAP& map, const FunctorSelect& good, std::vector& tableIndices, unsigned int thread) { // DartMarker m(map, thread); tableIndices.reserve(map.getNbDarts()); // for(Dart d = map.begin(); d != map.end(); map.next(d)) // { // if(!m.isMarked(d) && good(d)) // { // tableIndices.push_back(map.getEmbedding(VERTEX, d)); // tableIndices.push_back(map.getEmbedding(VERTEX, map.phi1(d))); // m.markOrbit(EDGE, d); // } // } TraversorE trav(map); for (Dart d = trav.begin(); d!= trav.end(); d = trav.next()) TraversorE trav(map, thread); for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) { if (good(d) && map.isBoundaryEdge(d)) if (good(d)) { tableIndices.push_back(map.getEmbedding(VERTEX, d)); tableIndices.push_back(map.getEmbedding(VERTEX, map.phi1(d))); ... ... @@ -418,10 +396,10 @@ void MapRender::initLines(typename PFP::MAP& map, const FunctorSelect& good, std template void MapRender::initBoundaries(typename PFP::MAP& map, const FunctorSelect& good, std::vector& tableIndices, unsigned int thread) { TraversorE trav(map); tableIndices.reserve(map.getNbDarts()); //TODO optimisation ? for (Dart d = trav.begin(); d!= trav.end(); d = trav.next()) TraversorE trav(map, thread); for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) { if (good(d) && map.isBoundaryEdge(d)) { ... ... @@ -483,21 +461,16 @@ void MapRender::initLinesOptimized(typename PFP::MAP& map, const FunctorSelect& template void MapRender::initPoints(typename PFP::MAP& map, const FunctorSelect& good, std::vector& tableIndices, unsigned int thread) { CellMarker m(map, VERTEX, thread) ; tableIndices.reserve(map.getNbDarts() / 5); 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(!m.isMarked(d) && good(d)) { if (good(d)) tableIndices.push_back(map.getEmbedding(VERTEX, d)); m.mark(d) ; } } } template void MapRender::initPrimitives(typename PFP::MAP& map, const FunctorSelect& good, int prim, bool optimized, unsigned int thread) { ... ...
 ... ... @@ -81,7 +81,7 @@ public: if(current != NIL) { current = m.alpha1(current) ; if(m.isBoundarymarked(current)) // jump over a boundary face if(m.isBoundaryMarked(current)) // jump over a boundary face current = m.alpha1(current) ; if(current == start) current = NIL ; ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment