From 88f326104745075061258f60cc7306f4588ee171 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Mon, 7 Nov 2011 18:20:09 +0100 Subject: [PATCH] filters almost OK with Traversors --- Apps/Examples/viewer.cpp | 17 +++ include/Algo/Filtering/average.h | 83 +++++------ include/Algo/Filtering/average_normals.h | 177 +++++++---------------- include/Algo/Filtering/bilateral.h | 69 +++------ include/Algo/Geometry/area.h | 2 +- include/Algo/Geometry/area.hpp | 27 ++-- include/Algo/Geometry/normal.hpp | 2 + include/Algo/Import/importMesh.hpp | 4 +- include/Algo/Selection/collector.h | 2 - include/Algo/Selection/collector.hpp | 33 +++-- include/Topology/generic/traversor2.h | 8 +- include/Topology/generic/traversorCell.h | 21 ++- src/Algo/Render/topo3Render.cpp | 7 +- src/Algo/Render/topoRender.cpp | 6 +- src/Topology/gmap/gmap2.cpp | 2 +- src/Topology/map/map2.cpp | 4 +- 16 files changed, 201 insertions(+), 263 deletions(-) diff --git a/Apps/Examples/viewer.cpp b/Apps/Examples/viewer.cpp index b97f444c..d08a9f3c 100644 --- a/Apps/Examples/viewer.cpp +++ b/Apps/Examples/viewer.cpp @@ -24,6 +24,9 @@ #include "viewer.h" +#include "Algo/Filtering/bilateral.h" +#include "Algo/Filtering/average_normals.h" + Viewer::Viewer() : m_renderStyle(FLAT), m_drawVertices(false), @@ -198,6 +201,20 @@ void Viewer::importMesh(std::string& filename) Algo::Geometry::computeNormalVertices(myMap, position, normal) ; + + + + AttributeHandler position2 = myMap.addAttribute(VERTEX, "position2") ; +// for(unsigned int i = 0; i < 3; ++i) +// { + Algo::Filtering::filterVNBA(myMap, 0.01f, 0.35f, position, position2, normal) ; + myMap.swapAttributes(position, position2) ; + Algo::Geometry::computeNormalVertices(myMap, position, normal) ; +// } + + + + m_positionVBO->updateData(position) ; m_normalVBO->updateData(normal) ; diff --git a/include/Algo/Filtering/average.h b/include/Algo/Filtering/average.h index be00c239..1ea2cb53 100644 --- a/include/Algo/Filtering/average.h +++ b/include/Algo/Filtering/average.h @@ -22,6 +22,7 @@ * * *******************************************************************************/ +#include "Topology/generic/traversorCell.h" #include "Algo/Filtering/functors.h" #include "Algo/Selection/collector.h" @@ -47,13 +48,11 @@ void filterAverageAttribute_OneRing( FunctorAverage fa(attIn) ; Algo::Selection::Collector_OneRing col(map) ; - CellMarker markV(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) && !markV.isMarked(d)) + if(select(d)) { - markV.mark(d) ; - if (neigh & INSIDE) col.collectAll(d) ; else @@ -75,14 +74,15 @@ void filterAverageAttribute_OneRing( break; } } - if (neigh & BORDER) col.applyOnBorder(fa) ; + if (neigh & BORDER) + col.applyOnBorder(fa) ; attOut[d] = fa.getAverage() ; } } } template -void filterAverageEdgesAttribute_WithinSphere( +void filterAverageVertexAttribute_WithinSphere( typename PFP::MAP& map, const AttributeHandler& attIn, AttributeHandler& attOut, @@ -91,31 +91,38 @@ void filterAverageEdgesAttribute_WithinSphere( typename PFP::REAL radius, const FunctorSelect& select = SelectorTrue()) { - FunctorAverage fa(attIn) ; + FunctorAverage faInside(attIn) ; + FunctorAverageOnSphereBorder faBorder(map, attIn, position) ; Algo::Selection::Collector_WithinSphere col(map, position, radius) ; - CellMarker markV(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) && !markV.isMarked(d)) + if(select(d)) { - markV.mark(d) ; - if (neigh & INSIDE) col.collectAll(d) ; else col.collectBorder(d) ; - fa.reset() ; - if (neigh & INSIDE) col.applyOnInsideEdges(fa) ; - if (neigh & BORDER) col.applyOnBorder(fa) ; - attOut[d] = fa.getAverage() ; + attOut[d] = T(0); + if (neigh & INSIDE){ + faInside.reset() ; + col.applyOnInsideVertices(faInside) ; + attOut[d] += faInside.getSum(); + } + if (neigh & BORDER){ + faBorder.reset(position[d], radius); + col.applyOnBorder(faBorder) ; + attOut[d] += faBorder.getSum(); + } + attOut[d] /= faInside.getCount() + faBorder.getCount() ; } } } template -void filterAverageFacesAttribute_WithinSphere( +void filterAverageEdgeAttribute_WithinSphere( typename PFP::MAP& map, const AttributeHandler& attIn, AttributeHandler& attOut, @@ -124,24 +131,21 @@ void filterAverageFacesAttribute_WithinSphere( typename PFP::REAL radius, const FunctorSelect& select = SelectorTrue()) { - FunctorAverage fa(attIn) ; Algo::Selection::Collector_WithinSphere col(map, position, radius) ; - CellMarker markV(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) && !markV.isMarked(d)) + if(select(d)) { - markV.mark(d) ; - if (neigh & INSIDE) col.collectAll(d) ; else col.collectBorder(d) ; fa.reset() ; - if (neigh & INSIDE) col.applyOnInsideFaces(fa) ; + if (neigh & INSIDE) col.applyOnInsideEdges(fa) ; if (neigh & BORDER) col.applyOnBorder(fa) ; attOut[d] = fa.getAverage() ; } @@ -149,7 +153,7 @@ void filterAverageFacesAttribute_WithinSphere( } template -void filterAverageVertexAttribute_WithinSphere( +void filterAverageFaceAttribute_WithinSphere( typename PFP::MAP& map, const AttributeHandler& attIn, AttributeHandler& attOut, @@ -158,34 +162,23 @@ void filterAverageVertexAttribute_WithinSphere( typename PFP::REAL radius, const FunctorSelect& select = SelectorTrue()) { - FunctorAverage faInside(attIn) ; - FunctorAverageOnSphereBorder faBorder(map, attIn, position) ; + FunctorAverage fa(attIn) ; Algo::Selection::Collector_WithinSphere col(map, position, radius) ; - CellMarker markV(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) && !markV.isMarked(d)) + if(select(d)) { - markV.mark(d) ; - if (neigh & INSIDE) col.collectAll(d) ; else col.collectBorder(d) ; - attOut[d] = T(0); - if (neigh & INSIDE){ - faInside.reset() ; - col.applyOnInsideVertices(faInside) ; - attOut[d] += faInside.getSum(); - } - if (neigh & BORDER){ - faBorder.reset(position[d], radius); - col.applyOnBorder(faBorder) ; - attOut[d] += faBorder.getSum(); - } - attOut[d] /= faInside.getCount() + faBorder.getCount() ; + fa.reset() ; + if (neigh & INSIDE) col.applyOnInsideFaces(fa) ; + if (neigh & BORDER) col.applyOnBorder(fa) ; + attOut[d] = fa.getAverage() ; } } } diff --git a/include/Algo/Filtering/average_normals.h b/include/Algo/Filtering/average_normals.h index 853998f3..55f23f51 100644 --- a/include/Algo/Filtering/average_normals.h +++ b/include/Algo/Filtering/average_normals.h @@ -22,7 +22,8 @@ * * *******************************************************************************/ -#include "Topology/generic/autoAttributeHandler.h" +#include "Topology/generic/traversorCell.h" +#include "Topology/generic/traversor2.h" namespace CGoGN { @@ -51,35 +52,31 @@ void computeNewPositionsFromFaceNormals( typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::REAL REAL ; - CellMarker markV(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) && !markV.isMarked(d)) + if(select(d)) { - markV.mark(d); - - // get pos of vertex const VEC3& pos_d = position[d] ; - // traversal of vertices neighbourhood VEC3 displ(0) ; REAL sumAreas = 0 ; - Dart dd = d ; - do + + Traversor2VF tvf(map, d) ; + for(Dart it = tvf.begin(); it != tvf.end(); it = tvf.next()) { - sumAreas += faceArea[dd] ; - VEC3 vT = faceCentroid[dd] - pos_d ; - vT = (vT * faceNewNormal[dd]) * faceNormal[dd] ; - displ += faceArea[dd] * vT ; - dd = map.phi1(map.phi2(dd)) ; - } while(dd != d) ; + sumAreas += faceArea[it] ; + VEC3 vT = faceCentroid[it] - pos_d ; + vT = (vT * faceNewNormal[it]) * faceNormal[it] ; + displ += faceArea[it] * vT ; + } + displ /= sumAreas ; position2[d] = pos_d + displ ; } } } - template void filterAverageNormals(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select = SelectorTrue()) { @@ -97,37 +94,21 @@ void filterAverageNormals(typename PFP::MAP& map, const typename PFP::TVEC3& pos AutoAttributeHandler faceNewNormal(map, FACE, "faceNewNormal") ; // Compute new normals - CellMarker markF(map, FACE); - for(Dart d = map.begin(); d != map.end(); map.next(d)) + TraversorF tf(map) ; + for(Dart d = tf.begin(); d != tf.end(); d = tf.next()) { - if(select(d) && !markF.isMarked(d)) + if(select(d)) { - markF.mark(d); - REAL sumArea = 0 ; VEC3 meanFilter(0) ; // traversal of adjacent faces (by edges and vertices) - Dart d_n = map.phi1(d) ; // next dart in the face - Dart d_f = map.phi1(map.phi2(d_n)) ; // test dart for end of vertex turning - - Dart e = map.phi2(d) ; // current dart for the traversal - Dart d_last = e ; - do + Traversor2FFaV taf(map, d) ; + for(Dart it = taf.begin(); it != taf.end(); it = taf.next()) { - // get info from face embedding and sum - sumArea += faceArea[e] ; - meanFilter += faceArea[e] * faceNormal[e] ; - e = map.phi_1(e) ; - e = map.phi2(e) ; - - if(e == d_f) - { - e = map.phi2(d_n) ; - d_n = map.phi1(d_n) ; - d_f = map.phi1(map.phi2(d_n)) ; - } - } while(e != d_last) ; + sumArea += faceArea[it] ; + meanFilter += faceArea[it] * faceNormal[it] ; + } // finalize the computation of meanFilter normal meanFilter /= sumArea ; @@ -160,13 +141,11 @@ void filterMMSE(typename PFP::MAP& map, float sigmaN2, const typename PFP::TVEC3 AutoAttributeHandler faceNewNormal(map, FACE, "faceNewNormal") ; // Compute new normals - CellMarker markF(map,FACE); - for(Dart d = map.begin(); d != map.end(); map.next(d)) + TraversorF tf(map) ; + for(Dart d = tf.begin(); d != tf.end(); d = tf.next()) { - if( select(d) && !markF.isMarked(d)) + if( select(d)) { - markF.mark(d); - // traversal of neighbour vertices REAL sumArea = 0 ; REAL sigmaX2 = 0 ; @@ -176,31 +155,18 @@ void filterMMSE(typename PFP::MAP& map, float sigmaN2, const typename PFP::TVEC3 VEC3 meanFilter(0) ; // traversal of adjacent faces (by edges and vertices) - Dart d_n = map.phi1(d) ; // next dart in the face - Dart d_f = map.phi1(map.phi2(d_n)) ; // test dart for end of vertex turning - - Dart e = map.phi2(d) ; // current dart for the traversal - Dart d_last = e ; - do + Traversor2FFaV taf(map, d) ; + for(Dart it = taf.begin(); it != taf.end(); it = taf.next()) { // get info from face embedding and sum - REAL area = faceArea[e] ; + REAL area = faceArea[it] ; sumArea += area ; - VEC3 normal = faceNormal[e] ; + VEC3 normal = faceNormal[it] ; meanFilter += area * normal ; sigmaX2 += area * normal[0] * normal[0] ; sigmaY2 += area * normal[1] * normal[1] ; sigmaZ2 += area * normal[2] * normal[2] ; - e = map.phi_1(e) ; - e = map.phi2(e) ; - - if(e == d_f) - { - e = map.phi2(d_n) ; - d_n = map.phi1(d_n) ; - d_f = map.phi1(map.phi2(d_n)) ; - } - } while(e != d_last) ; + } meanFilter /= sumArea ; sigmaX2 /= sumArea ; @@ -267,13 +233,11 @@ void filterTNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con long nbAdapt = 0 ; long nbSusan = 0 ; - CellMarker markF(map, FACE); - for(Dart d = map.begin(); d != map.end(); map.next(d)) + TraversorF tf(map) ; + for(Dart d = tf.begin(); d != tf.end(); d = tf.next()) { - if( select(d) && !markF.isMarked(d)) + if( select(d)) { - markF.mark(d); - const VEC3& normF = faceNormal[d] ; // traversal of neighbour vertices @@ -286,20 +250,16 @@ void filterTNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con bool SUSANregion = false ; // traversal of adjacent faces (by edges and vertices) - Dart d_n = map.phi1(d) ; // next dart in the face - Dart d_f = map.phi1(map.phi2(d_n)) ; // test dart for end of vertex turning - - Dart e = map.phi2(d) ; // current dart for the traversal - Dart d_last = e ; - do + Traversor2FFaV taf(map, d) ; + for(Dart it = taf.begin(); it != taf.end(); it = taf.next()) { // get info from face embedding and sum - const VEC3& normal = faceNormal[e] ; + const VEC3& normal = faceNormal[it] ; float angle = Geom::angle(normF, normal) ; if(angle <= SUSANthreshold) { - REAL area = faceArea[e] ; + REAL area = faceArea[it] ; sumArea += area ; meanFilter += area * normal ; sigmaX2 += area * normal[0] * normal[0] ; @@ -307,18 +267,7 @@ void filterTNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con sigmaZ2 += area * normal[2] * normal[2] ; } else SUSANregion = true ; - - e = map.phi_1(e) ; - e = map.phi2(e) ; - - if(e == d_f) - { - e = map.phi2(d_n) ; - d_n = map.phi1(d_n) ; - d_f = map.phi1(map.phi2(d_n)) ; - } - - } while(e != d_last) ; + } if(SUSANregion) ++nbSusan ; @@ -407,13 +356,11 @@ void filterVNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con long nbAdapt = 0 ; long nbSusan = 0 ; - CellMarker markV(map, VERTEX); - for(Dart d = map.begin(); d != map.end(); map.next(d)) + TraversorV tv(map) ; + for(Dart d = tv.begin(); d != tv.end(); d = tv.next()) { - if( select(d) && !markV.isMarked(d)) + if( select(d)) { - markV.mark(d) ; - const VEC3& normV = normal[d] ; // traversal of neighbour vertices @@ -426,23 +373,15 @@ void filterVNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con bool SUSANregion = false ; - Dart dd = d ; - do + Traversor2VVaE tav(map, d) ; + for(Dart it = tav.begin(); it != tav.end(); it = tav.next()) { - Dart e = map.phi2(dd) ; - const VEC3& neighborNormal = normal[e] ; - + const VEC3& neighborNormal = normal[it] ; float angle = Geom::angle(normV, neighborNormal) ; if( angle <= SUSANthreshold ) { - REAL umbArea = 0 ; - Dart ee = e ; - do - { - umbArea += faceArea[ee] ; - ee = map.phi1(map.phi2(ee)) ; - } while(ee!=e) ; - vertexArea[e] = umbArea ; + REAL umbArea = Algo::Geometry::vertexOneRingArea(map, it, position) ; + vertexArea[it] = umbArea ; sumArea += umbArea ; sigmaX2 += umbArea * neighborNormal[0] * neighborNormal[0] ; @@ -451,9 +390,7 @@ void filterVNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con meanFilter += neighborNormal * umbArea ; } else SUSANregion = true ; - - dd = map.phi1(e) ; - } while(dd != d) ; + } if(SUSANregion) ++nbSusan ; @@ -511,24 +448,22 @@ void filterVNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con } // Compute face normals from vertex normals - CellMarker markF(map,FACE); - for(Dart d = map.begin(); d != map.end(); map.next(d)) + TraversorF tf(map) ; + for(Dart d = tf.begin(); d != tf.end(); d = tf.next()) { - if (select(d) && !markF.isMarked(d)) + if (select(d)) { - markF.mark(d); VEC3 newNormal(0) ; REAL totArea = 0 ; - Dart dd = d ; - do - { - VEC3 vNorm = vertexNewNormal[dd] ; - REAL area = vertexArea[dd] ; + Traversor2FV tav(map, d) ; + for(Dart it = tav.begin(); it != tav.end(); it = tav.next()) + { + VEC3 vNorm = vertexNewNormal[it] ; + REAL area = vertexArea[it] ; totArea += area ; vNorm *= area ; newNormal += vNorm ; - dd = map.phi1(dd) ; - } while(dd != d) ; + } newNormal.normalize() ; faceNewNormal[d] = newNormal ; } diff --git a/include/Algo/Filtering/bilateral.h b/include/Algo/Filtering/bilateral.h index 1f074a78..93702064 100644 --- a/include/Algo/Filtering/bilateral.h +++ b/include/Algo/Filtering/bilateral.h @@ -23,6 +23,7 @@ *******************************************************************************/ #include +#include "Topology/generic/traversorCell.h" namespace CGoGN { @@ -33,7 +34,6 @@ namespace Algo namespace Filtering { - template void sigmaBilateral(typename PFP::MAP& map, const typename PFP::TVEC3& position, const typename PFP::TVEC3& normal, float& sigmaC, float& sigmaS, const FunctorSelect& select) { @@ -43,27 +43,14 @@ void sigmaBilateral(typename PFP::MAP& map, const typename PFP::TVEC3& position, float sumAngles = 0.0f ; long nbEdges = 0 ; - CellMarker mv(map, VERTEX) ; - for(Dart d = map.begin(); d != map.end(); map.next(d)) + TraversorE t(map) ; + for(Dart d = t.begin(); d != t.end(); d = t.next()) { - if(select(d) && !mv.isMarked(d)) + if(select(d)) { - mv.mark(d); - - Dart dd = d ; - do - { - // compute length and angle if not yet computed - Dart e = map.phi2(dd) ; - if(!mv.isMarked(e)) - { - sumLengths += Algo::Geometry::edgeLength(map, dd, position) ; - sumAngles += Geom::angle(normal[d], normal[e]) ; - ++nbEdges ; - } - // step to next face around vertex - dd = map.phi1(e) ; - } while(dd != d) ; + sumLengths += Algo::Geometry::edgeLength(map, d, position) ; + sumAngles += Geom::angle(normal[d], normal[map.phi1(d)]) ; + ++nbEdges ; } } @@ -80,30 +67,27 @@ void filterBilateral(typename PFP::MAP& map, const typename PFP::TVEC3& position float sigmaC, sigmaS ; sigmaBilateral(map, position, normal, sigmaC, sigmaS, select) ; - CellMarker mv(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) && !mv.isMarked(d)) + if(select(d)) { - mv.mark(d); - // get position & normal of vertex const VEC3& pos_d = position[d] ; const VEC3& normal_d = normal[d] ; - // traversal of neighbour vertices + // traversal of incident edges float sum = 0.0f, normalizer = 0.0f ; - Dart dd = d ; - do + Traversor2VE te(map, d) ; + for(Dart it = te.begin(); it != te.end(); it = te.next()) { - VEC3 vec = Algo::Geometry::vectorOutOfDart(map, dd, position) ; + VEC3 vec = Algo::Geometry::vectorOutOfDart(map, it, position) ; float h = normal_d * vec ; float t = vec.norm() ; float wcs = exp( ( -1.0f * (t * t) / (2.0f * sigmaC * sigmaC) ) + ( -1.0f * (h * h) / (2.0f * sigmaS * sigmaS) ) ) ; sum += wcs * h ; normalizer += wcs ; - dd = map.phi1(map.phi2(dd)) ; - } while (dd != d) ; + } position2[d] = pos_d + ((sum / normalizer) * normal_d) ; } @@ -121,29 +105,26 @@ void filterSUSAN(typename PFP::MAP& map, float SUSANthreshold, const typename PF long nbTot = 0 ; long nbSusan = 0 ; - CellMarker mv(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) && !mv.isMarked(d)) + if(select(d)) { - mv.mark(d); - // get position & normal of vertex const VEC3& pos_d = position[d] ; const VEC3& normal_d = normal[d] ; - // traversal of neighbour vertices + // traversal of incident edges float sum = 0.0f, normalizer = 0.0f ; bool SUSANregion = false ; - Dart dd = d ; - do + Traversor2VE te(map, d) ; + for(Dart it = te.begin(); it != te.end(); it = te.next()) { - Dart e = map.phi2(dd) ; - const VEC3& neighborNormal = normal[e] ; + const VEC3& neighborNormal = normal[map.phi1(it)] ; float angle = Geom::angle(normal_d, neighborNormal) ; if( angle <= SUSANthreshold ) { - VEC3 vec = Algo::Geometry::vectorOutOfDart(map, dd, position) ; + VEC3 vec = Algo::Geometry::vectorOutOfDart(map, it, position) ; float h = normal_d * vec ; float t = vec.norm() ; float wcs = exp( ( -1.0f * (t * t) / (2.0f * sigmaC * sigmaC) ) + ( -1.0f * (h * h) / (2.0f * sigmaS * sigmaS) ) ); @@ -152,9 +133,7 @@ void filterSUSAN(typename PFP::MAP& map, float SUSANthreshold, const typename PF } else SUSANregion = true ; - - dd = map.phi1(e) ; - } while(dd != d) ; + } if(SUSANregion) nbSusan++ ; diff --git a/include/Algo/Geometry/area.h b/include/Algo/Geometry/area.h index 4d8246de..5962a366 100644 --- a/include/Algo/Geometry/area.h +++ b/include/Algo/Geometry/area.h @@ -41,7 +41,7 @@ template typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) ; template -typename PFP::REAL totalArea(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& select = SelectorTrue(), unsigned int th=0) ; +typename PFP::REAL totalArea(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& select = SelectorTrue(), unsigned int thread = 0) ; template typename PFP::REAL vertexOneRingArea(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) ; diff --git a/include/Algo/Geometry/area.hpp b/include/Algo/Geometry/area.hpp index 4112356e..81d558e5 100644 --- a/include/Algo/Geometry/area.hpp +++ b/include/Algo/Geometry/area.hpp @@ -24,6 +24,8 @@ #include "Geometry/basic.h" #include "Algo/Geometry/centroid.h" +#include "Topology/generic/traversorCell.h" +#include "Topology/generic/traversor2.h" namespace CGoGN { @@ -55,30 +57,26 @@ typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const typename { float area = 0.0f ; VEC3 centroid = Algo::Geometry::faceCentroid(map, d, position) ; - Dart it = d ; - do + Traversor2FE t(map, d) ; + for(Dart it = t.begin(); it != t.end(); it = t.next()) { VEC3 p1 = position[it] ; VEC3 p2 = position[map.phi1(it)] ; area += Geom::triangleArea(p1, p2, centroid) ; - it = map.phi1(it) ; - } while (it != d) ; + } return area ; } } template -typename PFP::REAL totalArea(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& select, unsigned int th) +typename PFP::REAL totalArea(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& select, unsigned int thread) { typename PFP::REAL area(0) ; - DartMarker mark(map,th) ; - for(Dart d = map.begin(); d != map.end(); map.next(d)) + TraversorF t(map) ; + for(Dart d = t.begin(); d != t.end(); d = t.next()) { - if(select(d) && !mark.isMarked(d)) - { - mark.markOrbit(FACE, d) ; + if(select(d)) area += convexFaceArea(map, d, position) ; - } } return area ; } @@ -87,12 +85,9 @@ template typename PFP::REAL vertexOneRingArea(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) { typename PFP::REAL area(0) ; - Dart it = d ; - do - { + Traversor2VF t(map, d) ; + for(Dart it = t.begin(); it != t.end(); it = t.next()) area += convexFaceArea(map, it, position) ; - it = map.alpha1(it) ; - } while(it != d) ; return area ; } diff --git a/include/Algo/Geometry/normal.hpp b/include/Algo/Geometry/normal.hpp index 64d2fed7..7d5daf9e 100644 --- a/include/Algo/Geometry/normal.hpp +++ b/include/Algo/Geometry/normal.hpp @@ -141,6 +141,8 @@ typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart typedef typename PFP::VEC3 VEC3 ; Dart dd = map.phi2(d) ; + if(map.isBoundaryMarked(dd)) + return 0 ; const VEC3 n1 = faceNormal(map, d, position) ; const VEC3 n2 = faceNormal(map, dd, position) ; diff --git a/include/Algo/Import/importMesh.hpp b/include/Algo/Import/importMesh.hpp index 25afe382..0dc2f133 100644 --- a/include/Algo/Import/importMesh.hpp +++ b/include/Algo/Import/importMesh.hpp @@ -98,13 +98,13 @@ bool importMesh(typename PFP::MAP& map, MeshTablesSurface& mts) unsigned int embd = map.getEmbedding(VERTEX, d); Dart good_dart; - for (typename std::vector::iterator it = vec.begin(); it != vec.end() && good_dart == Dart::nil(); ++it) + for (typename std::vector::iterator it = vec.begin(); it != vec.end() && good_dart == NIL; ++it) { if (map.getEmbedding(VERTEX, map.phi1(*it)) == embd) good_dart = *it; } - if (good_dart != Dart::nil()) + if (good_dart != NIL) { if (good_dart == map.phi2(good_dart)) { diff --git a/include/Algo/Selection/collector.h b/include/Algo/Selection/collector.h index 1a07475c..81c44839 100644 --- a/include/Algo/Selection/collector.h +++ b/include/Algo/Selection/collector.h @@ -25,8 +25,6 @@ #ifndef __COLLECTOR_H__ #define __COLLECTOR_H__ -#include "Algo/Geometry/intersection.h" - /***************************************** * Class hierarchy : * Collector (virtual) diff --git a/include/Algo/Selection/collector.hpp b/include/Algo/Selection/collector.hpp index a253ef47..fd86fb27 100644 --- a/include/Algo/Selection/collector.hpp +++ b/include/Algo/Selection/collector.hpp @@ -22,6 +22,9 @@ * * *******************************************************************************/ +#include "Topology/generic/traversor2.h" +#include "Algo/Geometry/intersection.h" + namespace CGoGN { @@ -106,16 +109,18 @@ void Collector_OneRing::collectAll(Dart d) this->insideFaces.reserve(12); this->border.reserve(12); - const Dart end = this->centerDart; - this->insideVertices.push_back(end); - Dart dd = end; - do + this->insideVertices.push_back(this->centerDart); + + Traversor2VE te(this->map, this->centerDart) ; + for(Dart it = te.begin(); it != te.end(); it = te.next()) + this->insideEdges.push_back(it); + + Traversor2VF tf(this->map, this->centerDart) ; + for(Dart it = tf.begin(); it != tf.end(); it = tf.next()) { - this->insideEdges.push_back(dd); - this->insideFaces.push_back(dd); - this->border.push_back(this->map.phi1(dd)); - dd = this->map.alpha1(dd); - } while(dd != end); + this->insideFaces.push_back(it); + this->border.push_back(this->map.phi1(it)); + } } template @@ -124,13 +129,9 @@ void Collector_OneRing::collectBorder(Dart d) this->init(d); this->border.reserve(12); - const Dart end = this->centerDart; - Dart dd = end; - do - { - this->border.push_back(this->map.phi1(dd)); - dd = this->map.alpha1(dd); - } while(dd != end); + Traversor2VF t(this->map, this->centerDart) ; + for(Dart it = t.begin(); it != t.end(); it = t.next()) + this->border.push_back(this->map.phi1(it)); } /********************************************************* diff --git a/include/Topology/generic/traversor2.h b/include/Topology/generic/traversor2.h index 2dd34df3..92a196e1 100644 --- a/include/Topology/generic/traversor2.h +++ b/include/Topology/generic/traversor2.h @@ -74,7 +74,13 @@ public: Traversor2VF(MAP& map, Dart dart) : m(map), start(dart) {} - Dart begin() { current = start ; return current ; } + Dart begin() + { + current = start ; + if(m.isBoundaryMarked(current)) // jump over a boundary face + current = m.alpha1(current) ; + return current ; + } Dart end() { return NIL ; } Dart next() { diff --git a/include/Topology/generic/traversorCell.h b/include/Topology/generic/traversorCell.h index f4cfef94..1a88d518 100644 --- a/include/Topology/generic/traversorCell.h +++ b/include/Topology/generic/traversorCell.h @@ -52,6 +52,14 @@ public: dmark = new DartMarker(map, thread) ; } + ~TraversorCell() + { + if(dmark) + delete dmark ; + else + delete cmark ; + } + Dart begin() { if(!firstTraversal) @@ -76,6 +84,7 @@ public: cmark->mark(current) ; } + firstTraversal = false ; return current ; } @@ -121,28 +130,32 @@ template class TraversorV : public TraversorCell { public: - TraversorV(MAP& m, unsigned int thread = 0) : TraversorCell(m, thread) {} + TraversorV(MAP& m, unsigned int thread = 0) : TraversorCell(m, thread) + {} }; template class TraversorE : public TraversorCell { public: - TraversorE(MAP& m, unsigned int thread = 0) : TraversorCell(m, thread) {} + TraversorE(MAP& m, unsigned int thread = 0) : TraversorCell(m, thread) + {} }; template class TraversorF : public TraversorCell { public: - TraversorF(MAP& m, unsigned int thread = 0) : TraversorCell(m, thread) {} + TraversorF(MAP& m, unsigned int thread = 0) : TraversorCell(m, thread) + {} }; template class TraversorW : public TraversorCell { public: - TraversorW(MAP& m, unsigned int thread = 0) : TraversorCell(m, thread) {} + TraversorW(MAP& m, unsigned int thread = 0) : TraversorCell(m, thread) + {} }; } // namespace CGoGN diff --git a/src/Algo/Render/topo3Render.cpp b/src/Algo/Render/topo3Render.cpp index db039bda..5306159b 100644 --- a/src/Algo/Render/topo3Render.cpp +++ b/src/Algo/Render/topo3Render.cpp @@ -298,10 +298,9 @@ Dart Topo3Render::colToDart(float* color) unsigned int id = r + 255*g +255*255*b; - if (id==0) - return Dart::nil(); - return Dart(id-1); - + if (id == 0) + return NIL; + return Dart(id-1); } void Topo3Render::dartToCol(Dart d, float& r, float& g, float& b) diff --git a/src/Algo/Render/topoRender.cpp b/src/Algo/Render/topoRender.cpp index 16c265fc..54ad544c 100644 --- a/src/Algo/Render/topoRender.cpp +++ b/src/Algo/Render/topoRender.cpp @@ -193,9 +193,9 @@ Dart TopoRender::colToDart(float* color) unsigned int id = r + 255*g +255*255*b; - if (id==0) - return Dart::nil(); - return Dart(id-1); + if (id == 0) + return NIL; + return Dart(id-1); } diff --git a/src/Topology/gmap/gmap2.cpp b/src/Topology/gmap/gmap2.cpp index f8a08371..98ee35cb 100644 --- a/src/Topology/gmap/gmap2.cpp +++ b/src/Topology/gmap/gmap2.cpp @@ -135,7 +135,7 @@ Dart GMap2::collapseEdge(Dart d, bool delDegenerateFaces) Dart f = phi1(d) ; Dart g = phi_1(d) ; - if(resV == Dart::nil()) + if(resV == NIL) { if(!isFaceTriangle(d)) resV = f ; diff --git a/src/Topology/map/map2.cpp b/src/Topology/map/map2.cpp index 1c220959..2ec03f1d 100644 --- a/src/Topology/map/map2.cpp +++ b/src/Topology/map/map2.cpp @@ -232,7 +232,7 @@ Dart Map2::collapseEdge(Dart d, bool delDegenerateFaces) // Dart f = phi1(d) ; // Dart g = phi_1(d) ; // -// if(resV == Dart::nil()) +// if(resV == NIL) // { // if(!isFaceTriangle(d)) // resV = f ; @@ -740,7 +740,7 @@ Dart Map2::findBoundaryVertex(Dart d) return dNext ; dNext = alpha1(dNext) ; } while (dNext != d) ; - return Dart::nil(); + return NIL ; } bool Map2::isBoundaryEdge(Dart d) -- GitLab