diff --git a/include/Algo/Geometry/boundingbox.h b/include/Algo/Geometry/boundingbox.h index ca112fe5446b5cd1c68d3996afdd50270a9a0e5d..8e6bd40315309870f05f89a64da3c55c2cbe3fb9 100644 --- a/include/Algo/Geometry/boundingbox.h +++ b/include/Algo/Geometry/boundingbox.h @@ -25,7 +25,6 @@ #ifndef __ALGO_GEOMETRY_BOUNDINGBOX_H__ #define __ALGO_GEOMETRY_BOUNDINGBOX_H__ -#include "Geometry/basic.h" #include "Geometry/bounding_box.h" #include "Topology/generic/attributeHandler.h" #include "Topology/generic/traversor/traversorCell.h" @@ -43,9 +42,7 @@ template Geom::BoundingBox computeBoundingBox(typename PFP::MAP& map, const VertexAttribute& position) { Geom::BoundingBox bb ; - TraversorV t(map) ; - for(Dart d = t.begin(); d != t.end(); d = t.next()) - bb.addPoint(position[d]) ; + foreach_cell(map, [&] (Vertex v) { bb.addPoint(position[v]) ; }); return bb ; } diff --git a/include/Algo/Geometry/convexity.h b/include/Algo/Geometry/convexity.h index 8155afbc25e09f77625684dc65b22c6a73fca409..b43950468b64b50acb2e60a8b7fde00a7be4921d 100644 --- a/include/Algo/Geometry/convexity.h +++ b/include/Algo/Geometry/convexity.h @@ -41,7 +41,7 @@ namespace Geometry * Test if an edge bounded by 2 faces is convex or concave */ template -bool isEdgeConvexe(typename PFP::MAP& map, Dart d, const VertexAttribute& position) ; +bool isEdgeConvex(typename PFP::MAP& map, Edge e, const VertexAttribute& position) ; } // namespace Geometry diff --git a/include/Algo/Geometry/convexity.hpp b/include/Algo/Geometry/convexity.hpp index 19a44eeda7b6129f0baacabbc618534e8f2d6b36..fd5b72617e6bb084577eaeefb92b489e7ac7f971 100644 --- a/include/Algo/Geometry/convexity.hpp +++ b/include/Algo/Geometry/convexity.hpp @@ -40,14 +40,14 @@ namespace Geometry { template -bool isEdgeConvexe(typename PFP::MAP& map, Dart d, const VertexAttribute& position) +bool isEdgeConvex(typename PFP::MAP& map, Edge e, const VertexAttribute& position) { typedef typename PFP::VEC3 VEC3 ; - const VEC3 n = faceNormal(map, d, position); - const VEC3 e = vectorOutOfDart(map, map.phi1(map.phi2(d)), position) ; + const VEC3 n = faceNormal(map, e.dart, position); + const VEC3 ee = vectorOutOfDart(map, map.phi1(map.phi2(e.dart)), position) ; - if((e * n) > 0) + if((ee * n) < 0) return true; else return false; diff --git a/include/Algo/Geometry/distances.h b/include/Algo/Geometry/distances.h index f2d43978f738dff00212d91c83b4bdedfb11e60e..594ff8a0e15471e414411150ffaee1044f01a1fc 100644 --- a/include/Algo/Geometry/distances.h +++ b/include/Algo/Geometry/distances.h @@ -37,38 +37,36 @@ namespace Geometry /** * compute squared distance from point to the plane of a planar face * @param map the map -* @param d a dart of the face +* @param f a face +* @param position the vertex attribute storing positions * @param P the point -* @return the squared distance to tha plane +* @return the squared distance to the plane */ template -typename PFP::REAL squaredDistancePoint2FacePlane(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const VEC3& P) ; +typename PFP::REAL squaredDistancePoint2FacePlane(typename PFP::MAP& map, Face f, const VertexAttribute& position, const VEC3& P) ; /** * compute squared distance from point to face (assuming face is convex) * Algo: min distance of each subtriangle of face (not optimum ?) * @param map the map -* @param d a dart of the face +* @param f a face +* @param position the vertex attribute storing positions * @param P the point * @return the squared distance */ template -typename PFP::REAL squaredDistancePoint2Face(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const VEC3& P) ; - +typename PFP::REAL squaredDistancePoint2Face(typename PFP::MAP& map, Face f, const VertexAttribute& position, const VEC3& P) ; /** * compute squared distance from point to an edge * @param map the map -* @param d a dart of the edge +* @param e an edge +* @param position the vertex attribute storing positions * @param P the point * @return the squared distance */ template -typename PFP::REAL squaredDistancePoint2Edge(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const VEC3& P) ; - -template -bool isPlanar(typename PFP::MAP& map, Dart d, const VertexAttribute& position); - +typename PFP::REAL squaredDistancePoint2Edge(typename PFP::MAP& map, Edge e, const VertexAttribute& position, const VEC3& P) ; } // namespace Geometry diff --git a/include/Algo/Geometry/distances.hpp b/include/Algo/Geometry/distances.hpp index b867c4dae7c2d6ddbc6d4c8052ccd16a23534470..5de395839766de35e0aaffd0c97febb8183cbf80 100644 --- a/include/Algo/Geometry/distances.hpp +++ b/include/Algo/Geometry/distances.hpp @@ -23,8 +23,6 @@ *******************************************************************************/ #include "Geometry/distances.h" -#include "Algo/Geometry/normal.h" -#include namespace CGoGN { @@ -36,64 +34,50 @@ namespace Geometry { template -bool isPlanar(typename PFP::MAP& map, Dart d, const VertexAttribute& position) +typename PFP::REAL squaredDistancePoint2FacePlane(typename PFP::MAP& map, Face f, const VertexAttribute& position, const VEC3& P) { - if (map.phi<111>(d)==d) - return true; + Vertex v(f.dart); + const typename PFP::VEC3& A = position[v]; + v.dart = map.phi1(v.dart); + const typename PFP::VEC3& B = position[v]; + v.dart = map.phi1(v.dart); + const typename PFP::VEC3& C = position[v]; - typename PFP::VEC3 No = Algo::Surface::Geometry::triangleNormal(map, d, position) ; - - Dart e = map.phi<11>(d); - while (e != d) - { - typename PFP::VEC3 n = Algo::Surface::Geometry::triangleNormal(map, e, position) ; - e = map.phi1(e); - if (e!=d) - e = map.phi1(e); - } + return Geom::squaredDistancePoint2TrianglePlane(P, A, B, C); } template -typename PFP::REAL squaredDistancePoint2FacePlane(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const VEC3& P) -{ - const typename PFP::VEC3& A = position[d]; - d = map.phi1(d); - const typename PFP::VEC3& B = position[d]; - d = map.phi1(d); - const typename PFP::VEC3& C = position[d]; - return Geom::squaredDistancePoint2TrianglePlane(P,A,B,C); -} - -template -typename PFP::REAL squaredDistancePoint2Face(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const VEC3& P) +typename PFP::REAL squaredDistancePoint2Face(typename PFP::MAP& map, Face f, const VertexAttribute& position, const VEC3& P) { typedef typename PFP::REAL REAL; - const typename PFP::VEC3& A = position[d]; + const typename PFP::VEC3& A = position[f.dart]; + + Dart d = map.phi1(f.dart); Dart e = map.phi1(d); - Dart f = map.phi1(e); - REAL dist2 = Geom::squaredDistancePoint2Triangle(P,A,position[e],position[f]); - e = f; - f = map.phi1(e); + REAL dist2 = Geom::squaredDistancePoint2Triangle(P, A, position[d], position[e]); + d = e; + e = map.phi1(d); - while (f != d) + while (e != f.dart) { - REAL d2 = Geom::squaredDistancePoint2Triangle(P,A,position[e],position[f]); + REAL d2 = Geom::squaredDistancePoint2Triangle(P, A, position[d], position[e]); if (d2 < dist2) dist2 = d2; - e = f; - f = map.phi1(e); + d = e; + e = map.phi1(d); } + return dist2; } template -typename PFP::REAL squaredDistancePoint2Edge(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const VEC3& P) +typename PFP::REAL squaredDistancePoint2Edge(typename PFP::MAP& map, Edge e, const VertexAttribute& position, const VEC3& P) { - const typename PFP::VEC3& A = position[d]; - typename PFP::VEC3& AB = position[map.phi1(d)]-A; - typename PFP::REAL AB2 = AB*AB; - return Geom::squaredDistanceSeg2Point(A,AB,AB2,P) ; + const typename PFP::VEC3& A = position[e.dart]; + typename PFP::VEC3 AB = position[map.phi1(e.dart)] - A; + typename PFP::REAL AB2 = AB * AB; + return Geom::squaredDistanceSeg2Point(A, AB, AB2, P) ; } } // namespace Geometry diff --git a/include/Algo/Geometry/feature.hpp b/include/Algo/Geometry/feature.hpp index 87b789c24de73604c0b4e306f23b1b46d46a20ca..dd6d89350f9a687db30e827d4464c83fe9c97446 100644 --- a/include/Algo/Geometry/feature.hpp +++ b/include/Algo/Geometry/feature.hpp @@ -24,7 +24,7 @@ #include "Geometry/basic.h" #include "Algo/Geometry/normal.h" -#include "Topology/generic/traversorCell.h" +#include "Topology/generic/traversor/traversorCell.h" namespace CGoGN { diff --git a/include/Algo/Geometry/inclusion.h b/include/Algo/Geometry/inclusion.h index 1012c46efdd80b172094975a57e42e5b4ba8691f..2b0a9d7d37ad9d30fb6571e7ee35fb58412bf9ee 100644 --- a/include/Algo/Geometry/inclusion.h +++ b/include/Algo/Geometry/inclusion.h @@ -45,61 +45,61 @@ namespace Geometry /** * test if the volume is convex * @param the map - * @param a dart of the volume + * @param a volume * @param true if the faces of the volume must be in CCW order (default=true) */ template -bool isConvex(typename PFP::MAP& map, Dart d, const VertexAttribute& positions, bool CCW, unsigned int thread = 0); +bool isConvex(typename PFP::MAP& map, Vol v, const VertexAttribute& positions, bool CCW, unsigned int thread = 0); /** * test if a point is inside a volume * @param map the map - * @param d a dart defining the volume + * @param a volume * @param the point */ template -bool isPointInVolume(typename PFP::MAP& map, Dart d, const VertexAttribute& positions, const typename PFP::VEC3& point); +bool isPointInVolume(typename PFP::MAP& map, Vol v, const VertexAttribute& positions, const typename PFP::VEC3& point); /** * test if a point is inside a volume * @param map the map - * @param d a dart defining a convex volume + * @param a convex volume * @param the point */ template -bool isPointInConvexVolume(typename PFP::MAP& map, Dart d, const VertexAttribute& positions, const typename PFP::VEC3& point, bool CCW = true); +bool isPointInConvexVolume(typename PFP::MAP& map, Vol v, const VertexAttribute& positions, const typename PFP::VEC3& point, bool CCW = true); /** - * test if a point is inside a face in a plane + * test if a point is inside a face * @param map the map - * @param d a dart defining the face + * @param a face * @param the point */ template -bool isPointInConvexFace2D(typename PFP::MAP& map, Dart d, const VertexAttribute& positions, const typename PFP::VEC3& point, bool CCW = true); +bool isPointInConvexFace(typename PFP::MAP& map, Face f, const VertexAttribute& positions, const typename PFP::VEC3& point, bool CCW); /** - * test if a point is inside a face + * test if a point is inside a face in a plane * @param map the map - * @param d a dart defining the face + * @param a face * @param the point */ template -bool isPointInConvexFace(typename PFP::MAP& map, Dart d, const VertexAttribute& positions, const typename PFP::VEC3& point, bool CCW); +bool isPointInConvexFace2D(typename PFP::MAP& map, Face f, const VertexAttribute& positions, const typename PFP::VEC3& point, bool CCW = true); /** * test if a point is on an edge * @param map the map - * @param d a dart defining the edge + * @param an edge * @param the point */ template -bool isPointOnEdge(typename PFP::MAP& map, Dart d, const VertexAttribute& positions, const typename PFP::VEC3& point); +bool isPointOnEdge(typename PFP::MAP& map, Edge e, const VertexAttribute& positions, const typename PFP::VEC3& point); /** * test if a point is on an half-edge defined by a dart * @param map the map - * @param d a dart defining the edge + * @param a Dart * @param the point */ template @@ -108,23 +108,22 @@ bool isPointOnHalfEdge(typename PFP::MAP& map, Dart d, const VertexAttribute -bool isPointOnVertex(typename PFP::MAP& map, Dart d, const VertexAttribute& positions, const typename PFP::VEC3& point); - +bool isPointOnVertex(typename PFP::MAP& map, Vertex v, const VertexAttribute& positions, const typename PFP::VEC3& point); /** * test if a face is intersecting or totally included in a tetrahedron * TODO to test * @param map the map - * @param d a dart defining the face + * @param f a face * @param the points of the tetra (0,1,2) the first face and (3) the last point of the tetra, in well oriented order * @param true if the faces of the tetra are in CCW order (default=true) */ template -bool isConvexFaceInOrIntersectingTetrahedron(typename PFP::MAP& map, Dart d, const VertexAttribute& positions, const typename PFP::VEC3 points[4], bool CCW); +bool isConvexFaceInOrIntersectingTetrahedron(typename PFP::MAP& map, Face f, const VertexAttribute& positions, const typename PFP::VEC3 points[4], bool CCW); } // namespace Geometry diff --git a/include/Algo/Geometry/inclusion.hpp b/include/Algo/Geometry/inclusion.hpp index 684d3e52a2cd7f112a2d634bf1c8019e611cfda7..912669c086b938ef7aac392e65aff6a547b31d66 100644 --- a/include/Algo/Geometry/inclusion.hpp +++ b/include/Algo/Geometry/inclusion.hpp @@ -66,7 +66,7 @@ bool isConvex(typename PFP::MAP& map, Vol v, const VertexAttribute -bool isPointInVolume(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const typename PFP::VEC3& point) +bool isPointInVolume(typename PFP::MAP& map, Vol v, const VertexAttribute& position, const typename PFP::VEC3& point) { typedef typename PFP::VEC3 VEC3; @@ -75,74 +75,79 @@ bool isPointInVolume(typename PFP::MAP& map, Dart d, const VertexAttribute interPrec; interPrec.reserve(16); - std::vector visitedFaces; // Faces that are traversed + + std::vector visitedFaces; // Faces that are traversed visitedFaces.reserve(64); - visitedFaces.push_back(d); // Start with the face of d + Face f(v.dart); + visitedFaces.push_back(f); // Start with the first face of v + DartMarkerStore mark(map); - mark.markOrbit(d) ; - for(unsigned int iface = 0; iface != visitedFaces.size(); ++iface) + mark.markOrbit(f) ; + + for(unsigned int iface = 0; iface != visitedFaces.size(); ++iface) { - Dart e = visitedFaces[iface]; + f = visitedFaces[iface]; VEC3 inter; - bool interRes = intersectionLineConvexFace(map, e, position, point, dir, inter); + bool interRes = intersectionLineConvexFace(map, f, position, point, dir, inter); if (interRes) { // check if already intersect on same point (a vertex certainly) bool alreadyfound = false; for(typename std::vector::iterator it = interPrec.begin(); !alreadyfound && it != interPrec.end(); ++it) { - if (Geom::arePointsEquals(*it,inter)) - alreadyfound = true; + if (Geom::arePointsEquals(*it, inter)) + alreadyfound = true; } if (!alreadyfound) { - float v = dir * (inter-point); - if (v>0) + float v = dir * (inter - point); + if (v > 0) ++countInter; - if (v<0) + if (v < 0) ++countInter2; interPrec.push_back(inter); } } // add all face neighbours to the table - Dart currentFace = e; - do + foreach_adjacent2(map, f, [&] (Face ff) { - Dart ee = map.phi2(e) ; - if(!mark.isMarked(ee)) // not already marked + if(!mark.isMarked(ff)) // not already marked { - visitedFaces.push_back(ee) ; - mark.markOrbit(ee) ; + visitedFaces.push_back(ff) ; + mark.markOrbit(ff) ; } - e = map.phi1(e) ; - } while(e != currentFace) ; + }); } //if the point is in the volume there is an odd number of intersection with all faces with any direction return ((countInter % 2) != 0) && ((countInter2 % 2) != 0); // return (countInter % 2) == 1; - } template -bool isPointInConvexVolume(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const typename PFP::VEC3& point, bool CCW) +bool isPointInConvexVolume(typename PFP::MAP& map, Vol v, const VertexAttribute& position, const typename PFP::VEC3& point, bool CCW) { typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::REAL REAL; - std::list visitedFaces; // Faces that are traversed - visitedFaces.push_back(d); // Start with the face of d - std::list::iterator face; - VEC3 N; + std::vector visitedFaces; // Faces that are traversed + visitedFaces.reserve(64); + Face f(v.dart); + visitedFaces.push_back(f); // Start with the first face of v DartMarkerStore mark(map); // Lock a marker - for (face = visitedFaces.begin(); face != visitedFaces.end(); ++face) + + for (std::vector::iterator face = visitedFaces.begin(); face != visitedFaces.end(); ++face) { - if (!mark.isMarked(*face)) + f = *face; + if (!mark.isMarked(f)) { - Geom::Plane3D p = facePlane(map, *face, position); + mark.markOrbit(f); + + Geom::Plane3D p = facePlane(map, f, position); Geom::Orientation3D o3d = p.orient(point); if(CCW) { @@ -152,15 +157,12 @@ bool isPointInConvexVolume(typename PFP::MAP& map, Dart d, const VertexAttribute else if(o3d == Geom::UNDER) return false; - Dart dNext = *face ; - do + // add all face neighbours to the table + foreach_adjacent2(map, f, [&] (Face ff) { - mark.mark(dNext); // Mark - Dart adj = map.phi2(dNext); // Get adjacent face - if (adj != dNext && !mark.isMarked(adj)) - visitedFaces.push_back(adj); // Add it - dNext = map.phi1(dNext) ; - } while(dNext != *face) ; + if(!mark.isMarked(ff)) // not already marked + visitedFaces.push_back(ff) ; + }); } } @@ -168,22 +170,22 @@ bool isPointInConvexVolume(typename PFP::MAP& map, Dart d, const VertexAttribute } template -bool isPointInConvexFace(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const typename PFP::VEC3& point, bool CCW) +bool isPointInConvexFace(typename PFP::MAP& map, Face f, const VertexAttribute& position, const typename PFP::VEC3& point, bool CCW) { typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::REAL REAL; - Geom::Plane3D pl = Geometry::facePlane(map, d, position); + Geom::Plane3D pl = Geometry::facePlane(map, f, position); Geom::Orientation3D o3d = pl.orient(point); if(o3d == Geom::ON) { - Traversor2FV tfv(map, d) ; - for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next()) + Traversor2FV tfv(map, f) ; + for(Vertex v = tfv.begin(); v != tfv.end(); v = tfv.next()) { VEC3 N = pl.normal(); - VEC3 v2(position[map.phi1(it)] - position[it]); - VEC3 norm2 = N^v2; - Geom::Plane3D pl2(norm2, position[it]); + VEC3 v2(position[map.phi1(v.dart)] - position[v]); + VEC3 norm2 = N ^ v2; + Geom::Plane3D pl2(norm2, position[v]); o3d = pl2.orient(point); if(CCW) { @@ -200,7 +202,7 @@ bool isPointInConvexFace(typename PFP::MAP& map, Dart d, const VertexAttribute -bool isPointInConvexFace2D(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const typename PFP::VEC3& point, bool CCW ) +bool isPointInConvexFace2D(typename PFP::MAP& map, Face f, const VertexAttribute& position, const typename PFP::VEC3& point, bool CCW ) { typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::REAL REAL; @@ -209,10 +211,10 @@ bool isPointInConvexFace2D(typename PFP::MAP& map, Dart d, const VertexAttribute Geom::Orientation2D o2d; - Traversor2FV tfv(map, d) ; - for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next()) + Traversor2FV tfv(map, f) ; + for(Vertex v = tfv.begin(); v != tfv.end(); v = tfv.next()) { - o2d = Geom::testOrientation2D(point, position[it], position[map.phi1(it)]); + o2d = Geom::testOrientation2D(point, position[v], position[map.phi1(v.dart)]); if(CCW) { if(o2d == Geom::RIGHT) @@ -226,7 +228,7 @@ bool isPointInConvexFace2D(typename PFP::MAP& map, Dart d, const VertexAttribute } template -bool isPointOnEdge(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const typename PFP::VEC3& point) +bool isPointOnEdge(typename PFP::MAP& map, Edge e, const VertexAttribute& position, const typename PFP::VEC3& point) { // typedef typename PFP::REAL REAL; // typedef typename PFP::VEC3 VEC3 ; @@ -239,6 +241,8 @@ bool isPointOnEdge(typename PFP::MAP& map, Dart d, const VertexAttribute::min(); + Dart d = e.dart; + if( ( isPointOnHalfEdge(map,d,position,point) && isPointOnHalfEdge(map,map.phi2(d),position,point) ) || isPointOnVertex(map,d,position,point) || @@ -265,34 +269,34 @@ bool isPointOnHalfEdge(typename PFP::MAP& map, Dart d, const VertexAttribute= -REAL(0.00001); + return abs(v1*v2) <= REAL(0.00001); } template -bool isPointOnVertex(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const typename PFP::VEC3& point) +bool isPointOnVertex(typename PFP::MAP& map, Vertex v, const VertexAttribute& position, const typename PFP::VEC3& point) { - return Geom::arePointsEquals(point, position[d]); + return Geom::arePointsEquals(point, position[v]); } template -bool isConvexFaceInOrIntersectingTetrahedron(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const typename PFP::VEC3 points[4], bool CCW) +bool isConvexFaceInOrIntersectingTetrahedron(typename PFP::MAP& map, Face f, const VertexAttribute& position, const typename PFP::VEC3 points[4], bool CCW) { typedef typename PFP::VEC3 VEC3 ; - Traversor2FV tfv(map, d) ; - for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next()) + Traversor2FV tfv(map, f) ; + for(Vertex v = tfv.begin(); v != tfv.end(); v = tfv.next()) { - if(Geom::isPointInTetrahedron(points, position[it], CCW)) + if(Geom::isPointInTetrahedron(points, position[v], CCW)) return true; } VEC3 inter; - if( intersectionSegmentConvexFace(map, d, position, points[0], points[1], inter) - || intersectionSegmentConvexFace(map, d, position, points[1], points[2], inter) - || intersectionSegmentConvexFace(map, d, position, points[2], points[0], inter) - || intersectionSegmentConvexFace(map, d, position, points[0], points[3], inter) - || intersectionSegmentConvexFace(map, d, position, points[1], points[3], inter) - || intersectionSegmentConvexFace(map, d, position, points[2], points[3], inter) + if( intersectionSegmentConvexFace(map, f, position, points[0], points[1], inter) + || intersectionSegmentConvexFace(map, f, position, points[1], points[2], inter) + || intersectionSegmentConvexFace(map, f, position, points[2], points[0], inter) + || intersectionSegmentConvexFace(map, f, position, points[0], points[3], inter) + || intersectionSegmentConvexFace(map, f, position, points[1], points[3], inter) + || intersectionSegmentConvexFace(map, f, position, points[2], points[3], inter) ) return true; diff --git a/include/Algo/Geometry/intersection.h b/include/Algo/Geometry/intersection.h index 29951d7a3bd6500818a8dafb16a6f4c884d0ad90..d0ec4a3a9cffd4ad4f43fde7a1192737c5b981bf 100644 --- a/include/Algo/Geometry/intersection.h +++ b/include/Algo/Geometry/intersection.h @@ -42,47 +42,48 @@ namespace Geometry * (works with triangular faces but not optimized) * TODO to test * @param map the map - * @param d a dart defining the n-sided face + * @param f a n-sided face * @param PA segment point 1 * @param Dir a direction for the line * @param Inter store the intersection point * @return true if segment intersects the face */ template -bool intersectionLineConvexFace(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const typename PFP::VEC3& P, const typename PFP::VEC3& Dir, typename PFP::VEC3& Inter) ; +bool intersectionLineConvexFace(typename PFP::MAP& map, Face f, const VertexAttribute& position, const typename PFP::VEC3& P, const typename PFP::VEC3& Dir, typename PFP::VEC3& Inter) ; /** * test the intersection between a segment and a n-sided face (n>=3) * (works with triangular faces but not optimized) * TODO optimize - based on intersectionLineConvexFace - check whether the points are on both sides of the face before computing intersection * @param map the map - * @param d a dart defining the n-sided face + * @param f a n-sided face * @param PA segment point 1 * @param PB segment point 2 * @param Inter store the intersection point * @return true if segment intersects the face */ template -bool intersectionSegmentConvexFace(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const typename PFP::VEC3& PA, const typename PFP::VEC3& PB, typename PFP::VEC3& Inter) ; +bool intersectionSegmentConvexFace(typename PFP::MAP& map, Face f, const VertexAttribute& position, const typename PFP::VEC3& PA, const typename PFP::VEC3& PB, typename PFP::VEC3& Inter) ; /** * test if two triangles intersect * (based on the "Faster Triangle-Triangle intersection Tests" by Oliver Deviller and Philippe Guigue) * @param the map - * @param a dart of the first triangle - * @param a dart of the second triangle + * @param the first triangle + * @param the second triangle */ template -bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, const VertexAttribute& position) ; +bool areTrianglesInIntersection(typename PFP::MAP& map, Face t1, Face t2, const VertexAttribute& position) ; /** - * alpha = coef d'interpolation dans [0 ,1] tel que v = (1-alpha)*pin + alpha*pout + * alpha = coef d'interpolation dans [0,1] tel que v = (1-alpha)*pin + alpha*pout * est le point d'intersection entre la sphère et le segment [pin, pout] - * avec pin = position[d] à l'intérieur de la sphère - * avec pout = position[phi1(d)] à l'extérieur de la sphère + * avec pin = position[v1] à l'intérieur de la sphère + * avec pout = position[v2] à l'extérieur de la sphère + * et v1 et v2 les deux sommets de l'arête */ template -bool intersectionSphereEdge(typename PFP::MAP& map, typename PFP::VEC3& center, typename PFP::REAL radius, Dart d, const VertexAttribute& position, typename PFP::REAL& alpha) ; +bool intersectionSphereEdge(typename PFP::MAP& map, typename PFP::VEC3& center, typename PFP::REAL radius, Edge e, const VertexAttribute& position, typename PFP::REAL& alpha) ; } // namespace Geometry diff --git a/include/Algo/Geometry/intersection.hpp b/include/Algo/Geometry/intersection.hpp index e2dca3d6dca7475c1fdd4b603ebc7d1d9fb3cd0b..224fe3c2e91aceb7cab0b6e230fec643ef81a043 100644 --- a/include/Algo/Geometry/intersection.hpp +++ b/include/Algo/Geometry/intersection.hpp @@ -44,12 +44,14 @@ namespace Geometry { template -bool intersectionLineConvexFace(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const typename PFP::VEC3& P, const typename PFP::VEC3& Dir, typename PFP::VEC3& Inter) +bool intersectionLineConvexFace(typename PFP::MAP& map, Face f, const VertexAttribute& position, const typename PFP::VEC3& P, const typename PFP::VEC3& Dir, typename PFP::VEC3& Inter) { typedef typename PFP::VEC3 VEC3 ; const float SMALL_NUM = std::numeric_limits::min() * 5.0f; + Dart d = f.dart; + VEC3 p1 = position[d]; VEC3 n = faceNormal(map, d, position); VEC3 w0 = P - p1; @@ -90,12 +92,12 @@ bool intersectionLineConvexFace(typename PFP::MAP& map, Dart d, const VertexAttr } template -bool intersectionSegmentConvexFace(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const typename PFP::VEC3& PA, const typename PFP::VEC3& PB, typename PFP::VEC3& Inter) +bool intersectionSegmentConvexFace(typename PFP::MAP& map, Face f, const VertexAttribute& position, const typename PFP::VEC3& PA, const typename PFP::VEC3& PB, typename PFP::VEC3& Inter) { typedef typename PFP::VEC3 VEC3 ; VEC3 dir = PB - PA; - if (intersectionLineConvexFace(map, d, position, PA, dir, Inter)) + if (intersectionLineConvexFace(map, f, position, PA, dir, Inter)) { VEC3 dirA = PA - Inter; VEC3 dirB = PB - Inter; @@ -107,10 +109,13 @@ bool intersectionSegmentConvexFace(typename PFP::MAP& map, Dart d, const VertexA } template -bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, const VertexAttribute& position) +bool areTrianglesInIntersection(typename PFP::MAP& map, Face t1, Face t2, const VertexAttribute& position) { typedef typename PFP::VEC3 VEC3 ; + Dart tri1 = t1.dart; + Dart tri2 = t2.dart; + //get vertices position VEC3 tris1[3]; VEC3 tris2[3]; @@ -174,8 +179,8 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co // return isSegmentInTriangle2D(inter1,inter2,tris2[0],tris2[1],triS2[2],nTri2); //compute face normal - VEC3 normale1 = faceNormal(map, tri1, position); - VEC3 bary1 = faceCentroid(map, tri1, position); + VEC3 normale1 = faceNormal(map, t1, position); + VEC3 bary1 = faceCentroid(map, t1, position); int pos = 0; int neg = 0; @@ -184,9 +189,9 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co { VEC3 nTest = bary1 - tris2[i]; float scal = nTest * normale1; - if (scal<0) + if (scal < 0) ++neg; - if (scal>0) + if (scal > 0) ++pos; } @@ -195,8 +200,8 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co return false; //same for the second triangle - VEC3 normale2 = faceNormal(map, tri2, position); - VEC3 bary2 = faceCentroid(map, tri2, position); + VEC3 normale2 = faceNormal(map, t2, position); + VEC3 bary2 = faceCentroid(map, t2, position); pos = 0; neg = 0; for (unsigned int i = 0; i < 3 ; ++i) @@ -233,13 +238,13 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co } template -bool intersectionSphereEdge(typename PFP::MAP& map, typename PFP::VEC3& center, typename PFP::REAL radius, Dart d, const VertexAttribute& position, typename PFP::REAL& alpha) +bool intersectionSphereEdge(typename PFP::MAP& map, typename PFP::VEC3& center, typename PFP::REAL radius, Edge e, const VertexAttribute& position, typename PFP::REAL& alpha) { typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::REAL REAL ; - const VEC3& p1 = position[d]; - const VEC3& p2 = position[map.phi1(d)]; + const VEC3& p1 = position[e.dart]; + const VEC3& p2 = position[map.phi1(e.dart)]; if(Geom::isPointInSphere(p1, center, radius) && !Geom::isPointInSphere(p2, center, radius)) { VEC3 p = p1 - center; diff --git a/include/Algo/Geometry/plane.h b/include/Algo/Geometry/plane.h index ff3574e9159be8a6387739e8f6de531ae361c96d..0a848006183d0e29781a897b074b1bb2c4401126 100644 --- a/include/Algo/Geometry/plane.h +++ b/include/Algo/Geometry/plane.h @@ -42,24 +42,24 @@ namespace Geometry { template -Geom::Plane3D trianglePlane(typename PFP::MAP& map, Dart d, const VertexAttribute& position) +Geom::Plane3D trianglePlane(typename PFP::MAP& map, Face f, const VertexAttribute& position) { - typename PFP::VEC3 n = triangleNormal(map, d, position) ; - return Geom::Plane3D(n, position[d]) ; + typename PFP::VEC3 n = triangleNormal(map, f, position) ; + return Geom::Plane3D(n, position[f.dart]) ; } template -Geom::Plane3D facePlane(typename PFP::MAP& map, Dart d, const VertexAttribute& position) +Geom::Plane3D facePlane(typename PFP::MAP& map, Face f, const VertexAttribute& position) { - typename PFP::VEC3 n = faceNormal(map, d, position) ; - return Geom::Plane3D(n, position[d]) ; + typename PFP::VEC3 n = faceNormal(map, f, position) ; + return Geom::Plane3D(n, position[f.dart]) ; } template -Geom::Plane3D vertexTangentPlane(typename PFP::MAP& map, Dart d, const VertexAttribute& position) +Geom::Plane3D vertexTangentPlane(typename PFP::MAP& map, Vertex v, const VertexAttribute& position) { - typename PFP::VEC3 n = vertexNormal(map, d, position) ; - return Geom::Plane3D(n, position[d]) ; + typename PFP::VEC3 n = vertexNormal(map, v, position) ; + return Geom::Plane3D(n, position[v]) ; } } // namespace Geometry diff --git a/include/Topology/generic/traversor/traversorCell.h b/include/Topology/generic/traversor/traversorCell.h index 21d198145a7edcf32476a2b496875695f3a10b2b..8dc33e74bf29cf720e3d4024898c4c8d7dcc82ac 100644 --- a/include/Topology/generic/traversor/traversorCell.h +++ b/include/Topology/generic/traversor/traversorCell.h @@ -127,6 +127,7 @@ inline void foreach_cell_until(const MAP& map, FUNC f, TraversalOptim opt = AUTO namespace Parallel { + /** * @brief foreach_cell * @param map @@ -136,9 +137,12 @@ namespace Parallel * @param nbth number of used thread (0:for traversal, [1,nbth-1] for func computing */ template -void foreach_cell(MAP& map, FUNC func, bool needMarkers=true, TraversalOptim opt=AUTO, unsigned int nbth=NumberOfThreads); +void foreach_cell(MAP& map, FUNC func, bool needMarkers = true, TraversalOptim opt = AUTO, unsigned int nbth = NumberOfThreads); + +} // namespace Parallel + + -} template diff --git a/include/Topology/generic/traversor/traversorCell.hpp b/include/Topology/generic/traversor/traversorCell.hpp index 843fbc21ae04e52faf36eb79cb1efd23a5bc08a6..59c85d9c2676e5855fee0cd57760df1d716fc4b3 100644 --- a/include/Topology/generic/traversor/traversorCell.hpp +++ b/include/Topology/generic/traversor/traversorCell.hpp @@ -21,6 +21,7 @@ * Contact information: cgogn@unistra.fr * * * *******************************************************************************/ + #include #include #include @@ -29,284 +30,301 @@ namespace CGoGN { template -TraversorCell::TraversorCell(const MAP& map, bool forceDartMarker, unsigned int thread) : - m(map), dmark(NULL), cmark(NULL), quickTraversal(NULL), current(NIL), firstTraversal(true) +TraversorCell::TraversorCell(const MAP& map, bool forceDartMarker, unsigned int thread) : + m(map), + dmark(NULL), + cmark(NULL), + quickTraversal(NULL), + current(NIL), + firstTraversal(true) { dimension = map.dimension(); switch(OPT) { - case FORCE_DART_MARKING: - dmark = new DartMarker(map, thread) ; - break; - case FORCE_CELL_MARKING: - cmark = new CellMarker(map, thread) ; - break; - case FORCE_QUICK_TRAVERSAL: - quickTraversal = map.template getQuickTraversal() ; - assert(quickTraversal != NULL); - cont = &(map.template getAttributeContainer()) ; - break; - case AUTO: - if(forceDartMarker) + case FORCE_DART_MARKING: dmark = new DartMarker(map, thread) ; - else - { + break; + case FORCE_CELL_MARKING: + cmark = new CellMarker(map, thread) ; + break; + case FORCE_QUICK_TRAVERSAL: quickTraversal = map.template getQuickTraversal() ; - if(quickTraversal != NULL) - { - cont = &(map.template getAttributeContainer()) ; - - } + assert(quickTraversal != NULL); + cont = &(map.template getAttributeContainer()) ; + break; + case AUTO: + if(forceDartMarker) + dmark = new DartMarker(map, thread) ; else { - if(map.template isOrbitEmbedded()) - cmark = new CellMarker(map, thread) ; + quickTraversal = map.template getQuickTraversal() ; + if(quickTraversal != NULL) + { + cont = &(map.template getAttributeContainer()) ; + + } else - dmark = new DartMarker(map, thread) ; + { + if(map.template isOrbitEmbedded()) + cmark = new CellMarker(map, thread) ; + else + dmark = new DartMarker(map, thread) ; + } } - } - default: - break; + break; + default: + break; } } - template -TraversorCell::TraversorCell(const TraversorCell& tc) : - m(tc.m), dimension(tc.dimension), cont( tc.cont), qCurrent(tc.qCurrent), dmark(tc.dmark), cmark(tc.cmark), - quickTraversal(tc.quickTraversal), current(tc.current), firstTraversal(tc.firstTraversal) -{ -} - - - +TraversorCell::TraversorCell(const TraversorCell& tc) : + m(tc.m), + dimension(tc.dimension), + cont(tc.cont), + qCurrent(tc.qCurrent), + dmark(tc.dmark), + cmark(tc.cmark), + quickTraversal(tc.quickTraversal), + current(tc.current), + firstTraversal(tc.firstTraversal) +{} template TraversorCell::~TraversorCell() { switch(OPT) { - case FORCE_DART_MARKING: - delete dmark ; - break; - case FORCE_CELL_MARKING: - delete cmark ; - break; - case AUTO: - if(dmark) + case FORCE_DART_MARKING: delete dmark ; - else if(cmark) + break; + case FORCE_CELL_MARKING: delete cmark ; - default: - break; + break; + case AUTO: + if(dmark) + delete dmark ; + else if(cmark) + delete cmark ; + break; + default: + break; } } template -Cell TraversorCell::begin() +Cell TraversorCell::begin() { - switch(OPT) { - case FORCE_DART_MARKING: - { - if(!firstTraversal) - dmark->unmarkAll() ; - - current.dart = m.begin() ; - while(current.dart != m.end() && (m.isBoundaryMarked(dimension, current.dart) )) - m.next(current.dart) ; - - if(current.dart == m.end()) - current.dart = NIL ; - else - dmark->template markOrbit(current.dart) ; - } - break; - case FORCE_CELL_MARKING: - { - if(!firstTraversal) - cmark->unmarkAll() ; + case FORCE_DART_MARKING: + { + if(!firstTraversal) + dmark->unmarkAll() ; - current.dart = m.begin() ; - while(current.dart != m.end() && (m.isBoundaryMarked(dimension, current.dart) )) - m.next(current.dart) ; + current.dart = m.begin() ; + while(current.dart != m.end() && (m.isBoundaryMarked(dimension, current.dart))) + m.next(current.dart) ; - if(current.dart == m.end()) - current.dart = NIL ; - else - cmark->mark(current) ; - } - break; - case FORCE_QUICK_TRAVERSAL: - qCurrent = cont->begin() ; - current.dart = (*quickTraversal)[qCurrent] ; - break; - case AUTO: - - if(quickTraversal != NULL) - { - qCurrent = cont->begin() ; - current.dart = (*quickTraversal)[qCurrent] ; + if(current.dart == m.end()) + current.dart = NIL ; + else + dmark->markOrbit(current) ; } - else + break; + case FORCE_CELL_MARKING: { if(!firstTraversal) - { - if(dmark) - dmark->unmarkAll() ; - else - cmark->unmarkAll() ; - } + cmark->unmarkAll() ; current.dart = m.begin() ; - while(current.dart != m.end() && (m.isBoundaryMarked(dimension, current.dart) )) + while(current.dart != m.end() && (m.isBoundaryMarked(dimension, current.dart))) m.next(current.dart) ; if(current.dart == m.end()) current.dart = NIL ; + else + cmark->mark(current) ; + } + break; + case FORCE_QUICK_TRAVERSAL: + { + qCurrent = cont->begin() ; + current.dart = (*quickTraversal)[qCurrent] ; + } + break; + case AUTO: + { + if(quickTraversal != NULL) + { + qCurrent = cont->begin() ; + current.dart = (*quickTraversal)[qCurrent] ; + } else { - if(dmark) - dmark->template markOrbit(current.dart) ; + if(!firstTraversal) + { + if(dmark) + dmark->unmarkAll() ; + else + cmark->unmarkAll() ; + } + + current.dart = m.begin() ; + while(current.dart != m.end() && (m.isBoundaryMarked(dimension, current.dart))) + m.next(current.dart) ; + + if(current.dart == m.end()) + current.dart = NIL ; else - cmark->mark(current) ; + { + if(dmark) + dmark->markOrbit(current) ; + else + cmark->mark(current) ; + } } } - default: - break; + break; + default: + break; } + firstTraversal = false ; return current ; } template -Cell TraversorCell::end() +Cell TraversorCell::end() { return Cell(NIL) ; } template -Cell TraversorCell::next() +Cell TraversorCell::next() { assert(current.dart != NIL); switch(OPT) { - case FORCE_DART_MARKING: - { - bool ismarked = dmark->isMarked(current.dart) ; - while(current.dart != NIL && (ismarked || m.isBoundaryMarked(dimension, current.dart))) + case FORCE_DART_MARKING: { - m.next(current.dart) ; - if(current.dart == m.end()) - current.dart = NIL ; - else - ismarked = dmark->isMarked(current.dart) ; + bool ismarked = dmark->isMarked(current.dart) ; + while(current.dart != NIL && (ismarked || m.isBoundaryMarked(dimension, current.dart))) + { + m.next(current.dart) ; + if(current.dart == m.end()) + current.dart = NIL ; + else + ismarked = dmark->isMarked(current.dart) ; + } + if(current.dart != NIL) + dmark->markOrbit(current) ; } - if(current.dart != NIL) - dmark->template markOrbit(current.dart) ; - } - break; - case FORCE_CELL_MARKING: - { - bool ismarked = cmark->isMarked(current) ; - while(current.dart != NIL && (ismarked || m.isBoundaryMarked(dimension, current.dart) )) + break; + case FORCE_CELL_MARKING: { - m.next(current.dart) ; - if(current.dart == m.end()) - current.dart = NIL ; - else - ismarked = cmark->isMarked(current) ; + bool ismarked = cmark->isMarked(current) ; + while(current.dart != NIL && (ismarked || m.isBoundaryMarked(dimension, current.dart))) + { + m.next(current.dart) ; + if(current.dart == m.end()) + current.dart = NIL ; + else + ismarked = cmark->isMarked(current) ; + } + if(current.dart != NIL) + cmark->mark(current) ; } - if(current.dart != NIL) - cmark->mark(current) ; - } - break; - case FORCE_QUICK_TRAVERSAL: - cont->next(qCurrent) ; - if (qCurrent != cont->end()) - current.dart = (*quickTraversal)[qCurrent] ; - else current.dart = NIL; - break; - case AUTO: - if(quickTraversal != NULL) + break; + case FORCE_QUICK_TRAVERSAL: { cont->next(qCurrent) ; if (qCurrent != cont->end()) current.dart = (*quickTraversal)[qCurrent] ; else current.dart = NIL; } - else + break; + case AUTO: { - if(dmark) + if(quickTraversal != NULL) { - bool ismarked = dmark->isMarked(current.dart) ; - while(current.dart != NIL && (ismarked || m.isBoundaryMarked(dimension, current.dart))) - { - m.next(current.dart) ; - if(current.dart == m.end()) - current.dart = NIL ; - else - ismarked = dmark->isMarked(current.dart) ; - } - if(current.dart != NIL) - dmark->template markOrbit(current.dart) ; + cont->next(qCurrent) ; + if (qCurrent != cont->end()) + current.dart = (*quickTraversal)[qCurrent] ; + else current.dart = NIL; } else { - bool ismarked = cmark->isMarked(current) ; - while(current.dart != NIL && (ismarked || m.isBoundaryMarked(dimension, current.dart) )) + if(dmark) { - m.next(current.dart) ; - if(current.dart == m.end()) - current.dart = NIL ; - else - ismarked = cmark->isMarked(current) ; + bool ismarked = dmark->isMarked(current.dart) ; + while(current.dart != NIL && (ismarked || m.isBoundaryMarked(dimension, current.dart))) + { + m.next(current.dart) ; + if(current.dart == m.end()) + current.dart = NIL ; + else + ismarked = dmark->isMarked(current.dart) ; + } + if(current.dart != NIL) + dmark->markOrbit(current) ; + } + else + { + bool ismarked = cmark->isMarked(current) ; + while(current.dart != NIL && (ismarked || m.isBoundaryMarked(dimension, current.dart) )) + { + m.next(current.dart) ; + if(current.dart == m.end()) + current.dart = NIL ; + else + ismarked = cmark->isMarked(current) ; + } + if(current.dart != NIL) + cmark->mark(current) ; } - if(current.dart != NIL) - cmark->mark(current) ; } } - default: - break; + break; + default: + break; } return current ; } template -void TraversorCell::skip(Cell c) +void TraversorCell::skip(Cell c) { switch(OPT) { - case FORCE_DART_MARKING: - dmark->template markOrbit(c.dart) ; - break; - case FORCE_CELL_MARKING: - cmark->mark(c) ; - break; - case FORCE_QUICK_TRAVERSAL: - break; - case AUTO: - if(dmark) - dmark->template markOrbit(c.dart) ; - else + case FORCE_DART_MARKING: + dmark->markOrbit(c) ; + break; + case FORCE_CELL_MARKING: cmark->mark(c) ; - default: - break; + break; + case FORCE_QUICK_TRAVERSAL: + break; + case AUTO: + if(dmark) + dmark->markOrbit(c) ; + else + cmark->mark(c) ; + break; + default: + break; } - - } template -Cell TraversorCellEven::begin() +Cell TraversorCellEven::begin() { - Cell c = TraversorCell::begin(); + Cell c = TraversorCell::begin(); this->firstTraversal = true; return c; } @@ -314,41 +332,23 @@ Cell TraversorCellEven::begin() template -Cell TraversorCellOdd::begin() +Cell TraversorCellOdd::begin() { switch(OPT) { - case FORCE_DART_MARKING: - this->current.dart = this->m.begin() ; - while(this->current.dart != this->m.end() && (this->m.isBoundaryMarked(this->dimension, this->current.dart) )) - this->m.next(this->current.dart) ; - - if(this->current.dart == this->m.end()) - this->current.dart = NIL ; - else - this->dmark->template unmarkOrbit(this->current.dart) ; - break; - case FORCE_CELL_MARKING: - this->current.dart = this->m.begin() ; - while(this->current.dart != this->m.end() && (this->m.isBoundaryMarked(this->dimension, this->current.dart) )) - this->m.next(this->current.dart) ; - - if(this->current.dart == this->m.end()) - this->current.dart = NIL ; - else - this->cmark->unmark(this->current) ; - break; - case FORCE_QUICK_TRAVERSAL: - this->qCurrent = this->cont->begin() ; - this->current.dart = this->quickTraversal->operator[](this->qCurrent); - break; - case AUTO: - if(this->quickTraversal != NULL) + case FORCE_DART_MARKING: { - this->qCurrent = this->cont->begin() ; - this->current.dart = this->quickTraversal->operator[](this->qCurrent); + this->current.dart = this->m.begin() ; + while(this->current.dart != this->m.end() && (this->m.isBoundaryMarked(this->dimension, this->current.dart) )) + this->m.next(this->current.dart) ; + + if(this->current.dart == this->m.end()) + this->current.dart = NIL ; + else + this->dmark->unmarkOrbit(this->current) ; } - else + break; + case FORCE_CELL_MARKING: { this->current.dart = this->m.begin() ; while(this->current.dart != this->m.end() && (this->m.isBoundaryMarked(this->dimension, this->current.dart) )) @@ -356,105 +356,136 @@ Cell TraversorCellOdd::begin() if(this->current.dart == this->m.end()) this->current.dart = NIL ; + else + this->cmark->unmark(this->current) ; + } + break; + case FORCE_QUICK_TRAVERSAL: + { + this->qCurrent = this->cont->begin() ; + this->current.dart = this->quickTraversal->operator[](this->qCurrent); + } + break; + case AUTO: + { + if(this->quickTraversal != NULL) + { + this->qCurrent = this->cont->begin() ; + this->current.dart = this->quickTraversal->operator[](this->qCurrent); + } else { - if(this->dmark) - this->dmark->template unmarkOrbit(this->current.dart) ; + this->current.dart = this->m.begin() ; + while(this->current.dart != this->m.end() && (this->m.isBoundaryMarked(this->dimension, this->current.dart) )) + this->m.next(this->current.dart) ; + + if(this->current.dart == this->m.end()) + this->current.dart = NIL ; else - this->cmark->unmark(this->current) ; + { + if(this->dmark) + this->dmark->unmarkOrbit(this->current) ; + else + this->cmark->unmark(this->current) ; + } } } - default: - break; + break; + default: + break; } return this->current ; } - template -Cell TraversorCellOdd::next() +Cell TraversorCellOdd::next() { assert(this->current.dart != NIL); switch(OPT) { - case FORCE_DART_MARKING: - { - bool ismarked = this->dmark->isMarked(this->current.dart) ; - while(this->current.dart != NIL && (!ismarked || this->m.isBoundaryMarked(this->dimension,this->current.dart))) + case FORCE_DART_MARKING: { - this->m.next(this->current.dart) ; - if(this->current.dart == this->m.end()) - this->current.dart = NIL ; - else - ismarked = this->dmark->isMarked(this->current.dart) ; + bool ismarked = this->dmark->isMarked(this->current.dart) ; + while(this->current.dart != NIL && (!ismarked || this->m.isBoundaryMarked(this->dimension,this->current.dart))) + { + this->m.next(this->current.dart) ; + if(this->current.dart == this->m.end()) + this->current.dart = NIL ; + else + ismarked = this->dmark->isMarked(this->current.dart) ; + } + if(this->current.dart != NIL) + this->dmark->unmarkOrbit(this->current) ; } - if(this->current.dart != NIL) - this->dmark->template unmarkOrbit(this->current.dart) ; - } - break; - case FORCE_CELL_MARKING: - { - bool ismarked = this->cmark->isMarked(this->current) ; - while(this->current.dart != NIL && (!ismarked || this->m.isBoundaryMarked(this->dimension, this->current.dart) )) + break; + case FORCE_CELL_MARKING: { - this->m.next(this->current.dart) ; - if(this->current.dart == this->m.end()) - this->current.dart = NIL ; - else - ismarked = this->cmark->isMarked(this->current) ; + bool ismarked = this->cmark->isMarked(this->current) ; + while(this->current.dart != NIL && (!ismarked || this->m.isBoundaryMarked(this->dimension, this->current.dart) )) + { + this->m.next(this->current.dart) ; + if(this->current.dart == this->m.end()) + this->current.dart = NIL ; + else + ismarked = this->cmark->isMarked(this->current) ; + } + if(this->current.dart != NIL) + this->cmark->unmark(this->current) ; } - if(this->current.dart != NIL) - this->cmark->unmark(this->current) ; - } - break; - case FORCE_QUICK_TRAVERSAL: - this->cont->next(this->qCurrent) ; - if (this->qCurrent != this->cont->end()) - this->current.dart = this->quickTraversal->operator[](this->qCurrent) ; - else this->current.dart = NIL; - break; - case AUTO: - if(this->quickTraversal != NULL) + break; + case FORCE_QUICK_TRAVERSAL: { this->cont->next(this->qCurrent) ; if (this->qCurrent != this->cont->end()) this->current.dart = this->quickTraversal->operator[](this->qCurrent) ; else this->current.dart = NIL; } - else + break; + case AUTO: { - if(this->dmark) + if(this->quickTraversal != NULL) { - bool ismarked = this->dmark->isMarked(this->current.dart) ; - while(this->current.dart != NIL && (!ismarked || this->m.isBoundaryMarked(this->dimension,this->current.dart))) - { - this->m.next(this->current.dart) ; - if(this->current.dart == this->m.end()) - this->current.dart = NIL ; - else - ismarked = this->dmark->isMarked(this->current.dart) ; - } - if(this->current.dart != NIL) - this->dmark->template unmarkOrbit(this->current.dart) ; + this->cont->next(this->qCurrent) ; + if (this->qCurrent != this->cont->end()) + this->current.dart = this->quickTraversal->operator[](this->qCurrent) ; + else this->current.dart = NIL; } else { - bool ismarked = this->cmark->isMarked(this->current) ; - while(this->current.dart != NIL && (!ismarked || this->m.isBoundaryMarked(this->dimension, this->current.dart) )) + if(this->dmark) { - this->m.next(this->current.dart) ; - if(this->current.dart == this->m.end()) - this->current.dart = NIL ; - else - ismarked = this->cmark->isMarked(this->current) ; + bool ismarked = this->dmark->isMarked(this->current.dart) ; + while(this->current.dart != NIL && (!ismarked || this->m.isBoundaryMarked(this->dimension,this->current.dart))) + { + this->m.next(this->current.dart) ; + if(this->current.dart == this->m.end()) + this->current.dart = NIL ; + else + ismarked = this->dmark->isMarked(this->current.dart) ; + } + if(this->current.dart != NIL) + this->dmark->unmarkOrbit(this->current) ; + } + else + { + bool ismarked = this->cmark->isMarked(this->current) ; + while(this->current.dart != NIL && (!ismarked || this->m.isBoundaryMarked(this->dimension, this->current.dart) )) + { + this->m.next(this->current.dart) ; + if(this->current.dart == this->m.end()) + this->current.dart = NIL ; + else + ismarked = this->cmark->isMarked(this->current) ; + } + if(this->current.dart != NIL) + this->cmark->unmark(this->current) ; } - if(this->current.dart != NIL) - this->cmark->unmark(this->current) ; } } - default: - break; + break; + default: + break; } return this->current ; @@ -468,36 +499,35 @@ inline void foreach_cell(const MAP& map, FUNC f, TraversalOptim opt, unsigned in { switch(opt) { - case FORCE_DART_MARKING: - { - TraversorCell trav(map, false, thread); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - f(c); - } - break; - case FORCE_CELL_MARKING: - { - TraversorCell trav(map, false, thread); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - f(c); - } - break; - case FORCE_QUICK_TRAVERSAL: - { - TraversorCell trav(map, false, thread); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - f(c); - } - break; - case AUTO: - default: - { - TraversorCell trav(map, false, thread); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - f(c); - } - break; - + case FORCE_DART_MARKING: + { + TraversorCell trav(map, false, thread); + for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) + f(c); + } + break; + case FORCE_CELL_MARKING: + { + TraversorCell trav(map, false, thread); + for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) + f(c); + } + break; + case FORCE_QUICK_TRAVERSAL: + { + TraversorCell trav(map, false, thread); + for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) + f(c); + } + break; + case AUTO: + default: + { + TraversorCell trav(map, false, thread); + for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) + f(c); + } + break; } } @@ -506,39 +536,39 @@ inline void foreach_cell_until(const MAP& map, FUNC f, TraversalOptim opt, unsig { switch(opt) { - case FORCE_DART_MARKING: - { - TraversorCell trav(map, false, thread); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - if (!f(c)) - break; - } - break; - case FORCE_CELL_MARKING: - { - TraversorCell trav(map, false, thread); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - if (!f(c)) - break; - } - break; - case FORCE_QUICK_TRAVERSAL: - { - TraversorCell trav(map, false, thread); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - if (!f(c)) - break; - } - break; - case AUTO: - default: - { - TraversorCell trav(map, false, thread); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - if (!f(c)) - break; - } - break; + case FORCE_DART_MARKING: + { + TraversorCell trav(map, false, thread); + for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) + if (!f(c)) + break; + } + break; + case FORCE_CELL_MARKING: + { + TraversorCell trav(map, false, thread); + for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) + if (!f(c)) + break; + } + break; + case FORCE_QUICK_TRAVERSAL: + { + TraversorCell trav(map, false, thread); + for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) + if (!f(c)) + break; + } + break; + case AUTO: + default: + { + TraversorCell trav(map, false, thread); + for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) + if (!f(c)) + break; + } + break; } } @@ -631,6 +661,7 @@ protected: bool& m_finished; unsigned int m_id; FUNC m_lambda; + public: ThreadFunction(FUNC func, std::vector& vd, boost::barrier& s1, boost::barrier& s2, bool& finished, unsigned int id): m_cells(vd), m_sync1(s1), m_sync2(s2), m_finished(finished), m_id(id), m_lambda(func) @@ -645,7 +676,7 @@ public: while (!m_finished) { for (typename std::vector::const_iterator it = m_cells.begin(); it != m_cells.end(); ++it) - m_lambda(*it,m_id); + m_lambda(*it, m_id); m_cells.clear(); m_sync1.wait(); // wait every body has finished m_sync2.wait(); // wait vectors has been refilled @@ -733,34 +764,32 @@ void foreach_cell_tmpl(MAP& map, FUNC func, bool needMarkers, unsigned int nbth) delete[] tempo; } - template void foreach_cell(MAP& map, FUNC func, bool needMarkers, TraversalOptim opt, unsigned int nbth) { if (nbth < 2) { CGoGNerr << "Warning number of threads must be > 1 for //" << CGoGNendl; - nbth =2; + nbth = 2; } switch(opt) { - case FORCE_DART_MARKING: - foreach_cell_tmpl(map,func,needMarkers,nbth-1); - break; - case FORCE_CELL_MARKING: - foreach_cell_tmpl(map,func,needMarkers,nbth-1); - break; - case FORCE_QUICK_TRAVERSAL: - foreach_cell_tmpl(map,func,needMarkers,nbth-1); - break; - case AUTO: - default: - foreach_cell_tmpl(map,func,needMarkers,nbth-1); - break; + case FORCE_DART_MARKING: + foreach_cell_tmpl(map,func,needMarkers,nbth-1); + break; + case FORCE_CELL_MARKING: + foreach_cell_tmpl(map,func,needMarkers,nbth-1); + break; + case FORCE_QUICK_TRAVERSAL: + foreach_cell_tmpl(map,func,needMarkers,nbth-1); + break; + case AUTO: + default: + foreach_cell_tmpl(map,func,needMarkers,nbth-1); + break; } } -}// namespace Parallel - +} // namespace Parallel } // namespace CGoGN