From e401dc0933fe9565857f8cb5ba9c8a38d9186bc6 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Wed, 25 Apr 2012 09:55:59 +0200 Subject: [PATCH] draw topo in viewer + update feature lines --- Apps/Examples/viewer.cpp | 36 ++- Apps/Examples/viewer.h | 3 + Apps/Examples/viewer.ui | 7 + include/Algo/Geometry/feature.h | 124 ++++----- include/Algo/Geometry/feature.hpp | 416 +++++++++++++----------------- 5 files changed, 270 insertions(+), 316 deletions(-) diff --git a/Apps/Examples/viewer.cpp b/Apps/Examples/viewer.cpp index 35a0291d..009b89a8 100644 --- a/Apps/Examples/viewer.cpp +++ b/Apps/Examples/viewer.cpp @@ -30,6 +30,7 @@ Viewer::Viewer() : m_drawEdges(false), m_drawFaces(true), m_drawNormals(false), + m_drawTopo(false), m_render(NULL), m_phongShader(NULL), m_flatShader(NULL), @@ -68,6 +69,7 @@ void Viewer::initGUI() setCallBack( dock.check_drawEdges, SIGNAL(toggled(bool)), SLOT(slot_drawEdges(bool)) ) ; setCallBack( dock.check_drawFaces, SIGNAL(toggled(bool)), SLOT(slot_drawFaces(bool)) ) ; setCallBack( dock.combo_faceLighting, SIGNAL(currentIndexChanged(int)), SLOT(slot_faceLighting(int)) ) ; + setCallBack( dock.check_drawTopo, SIGNAL(toggled(bool)), SLOT(slot_drawTopo(bool)) ) ; setCallBack( dock.check_drawNormals, SIGNAL(toggled(bool)), SLOT(slot_drawNormals(bool)) ) ; setCallBack( dock.slider_normalsSize, SIGNAL(valueChanged(int)), SLOT(slot_normalsSize(int)) ) ; } @@ -79,6 +81,9 @@ void Viewer::cb_initGL() setFocal(5.0f) ; m_render = new Algo::Render::GL2::MapRender() ; + m_topoRender = new Algo::Render::GL2::TopoRender() ; + + m_topoRender->setInitialDartsColor(0.25f, 0.25f, 0.25f) ; m_positionVBO = new Utils::VBO() ; m_normalVBO = new Utils::VBO() ; @@ -119,7 +124,6 @@ void Viewer::cb_initGL() void Viewer::cb_redraw() { - //glClearColor(1,1,1,0); if(m_drawVertices) { float size = vertexScaleFactor ; @@ -135,14 +139,6 @@ void Viewer::cb_redraw() m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES) ; } - if(m_drawNormals) - { - float size = normalBaseSize * normalScaleFactor ; - m_vectorShader->setScale(size) ; - glLineWidth(1.0f) ; - m_render->draw(m_vectorShader, Algo::Render::GL2::POINTS) ; - } - if(m_drawFaces) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ; @@ -161,6 +157,19 @@ void Viewer::cb_redraw() } glDisable(GL_POLYGON_OFFSET_FILL) ; } + + if(m_drawTopo) + { + m_topoRender->drawTopo() ; + } + + if(m_drawNormals) + { + float size = normalBaseSize * normalScaleFactor ; + m_vectorShader->setScale(size) ; + glLineWidth(1.0f) ; + m_render->draw(m_vectorShader, Algo::Render::GL2::POINTS) ; + } } void Viewer::cb_Open() @@ -209,6 +218,8 @@ void Viewer::importMesh(std::string& filename) m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::LINES) ; m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::TRIANGLES) ; + m_topoRender->updateData(myMap, position, 0.85f, 0.85f) ; + bb = Algo::Geometry::computeBoundingBox(myMap, position) ; normalBaseSize = bb.diagSize() / 100.0f ; // vertexBaseSize = normalBaseSize / 5.0f ; @@ -271,6 +282,12 @@ void Viewer::slot_faceLighting(int i) updateGL() ; } +void Viewer::slot_drawTopo(bool b) +{ + m_drawTopo = b ; + updateGL() ; +} + void Viewer::slot_drawNormals(bool b) { m_drawNormals = b ; @@ -280,6 +297,7 @@ void Viewer::slot_drawNormals(bool b) void Viewer::slot_normalsSize(int i) { normalScaleFactor = i / 50.0f ; + m_topoRender->updateData(myMap, position, i / 100.0f, i / 100.0f) ; updateGL() ; } diff --git a/Apps/Examples/viewer.h b/Apps/Examples/viewer.h index b60cff20..bc38941e 100644 --- a/Apps/Examples/viewer.h +++ b/Apps/Examples/viewer.h @@ -90,11 +90,13 @@ public: bool m_drawEdges ; bool m_drawFaces ; bool m_drawNormals ; + bool m_drawTopo ; PFP::TVEC3 position ; PFP::TVEC3 normal ; Algo::Render::GL2::MapRender* m_render ; + Algo::Render::GL2::TopoRender* m_topoRender ; Utils::VBO* m_positionVBO ; Utils::VBO* m_normalVBO ; @@ -123,6 +125,7 @@ public slots: void slot_drawEdges(bool b) ; void slot_drawFaces(bool b) ; void slot_faceLighting(int i) ; + void slot_drawTopo(bool b) ; void slot_drawNormals(bool b) ; void slot_normalsSize(int i) ; }; diff --git a/Apps/Examples/viewer.ui b/Apps/Examples/viewer.ui index 10bf2795..cef95e3b 100644 --- a/Apps/Examples/viewer.ui +++ b/Apps/Examples/viewer.ui @@ -73,6 +73,13 @@ + + + + draw topo + + + diff --git a/include/Algo/Geometry/feature.h b/include/Algo/Geometry/feature.h index c9de8183..e3e678d9 100644 --- a/include/Algo/Geometry/feature.h +++ b/include/Algo/Geometry/feature.h @@ -25,8 +25,6 @@ #ifndef __ALGO_GEOMETRY_FEATURE_H__ #define __ALGO_GEOMETRY_FEATURE_H__ - - namespace CGoGN { @@ -38,15 +36,11 @@ namespace Geometry enum { - EMPTY, - SEGMENT, - BARY + EMPTY = 0, + SEGMENT = 1, + BARY = 2 }; -//#define EMPTY 0 -//#define SEGMENT 1 -//#define BARY 2 - typedef struct { Dart d ; float w ; } e0point ; typedef struct { e0point p1 ; e0point p2 ; unsigned char type ; } e0segment ; typedef NoMathIONameAttribute ridgeSegment ; @@ -61,22 +55,45 @@ template void computeFaceGradient( typename PFP::MAP& map, const typename PFP::TVEC3& position, + const typename PFP::TVEC3& face_normal, + const typename PFP::TREAL& kmax, + const typename PFP::TREAL& face_area, typename PFP::TVEC3& face_gradient, + const FunctorSelect& select = allDarts, + unsigned int thread = 0) ; + +template +typename PFP::VEC3 faceGradient( + typename PFP::MAP& map, + Dart d, + const typename PFP::TVEC3& position, const typename PFP::TVEC3& face_normal, const typename PFP::TREAL& kmax, - const typename PFP::TREAL& area, + const typename PFP::TREAL& area) ; + +template +void computeVertexGradient( + typename PFP::MAP& map, + const typename PFP::TVEC3& face_gradient, + const typename PFP::TREAL& face_area, + typename PFP::TVEC3& vertex_gradient, const FunctorSelect& select = allDarts, unsigned int thread = 0) ; +template +typename PFP::VEC3 vertexGradient( + typename PFP::MAP& map, + Dart d, + const typename PFP::TVEC3& face_gradient, + const typename PFP::TREAL& area) ; + //template -//void computeVertexGradient( +//typename PFP::REAL extremality( // typename PFP::MAP& map, -// const typename PFP::TVEC3& position, -// typename PFP::TVEC3& gradient, -// typename PFP::TVEC3& face_gradient, -// const typename PFP::TREAL& area, -// const FunctorSelect& select = allDarts, -// unsigned int thread = 0) ; +// Dart d, +// const typename PFP::VEC3& K, +// const typename PFP::TVEC3& face_gradient, +// const typename PFP::TREAL& face_area) ; template void computeTriangleType( @@ -87,94 +104,61 @@ void computeTriangleType( unsigned int thread = 0) ; template -void computeRidgeLines( - typename PFP::MAP& map, - const typename PFP::TVEC3& position, - CellMarker& regularMarker, - const typename PFP::TVEC3& faceGradient, - const typename PFP::TREAL& area, - const typename PFP::TVEC3& K, - AttributeHandler& ridge_segments, - const FunctorSelect& select = allDarts, - unsigned int thread = 0) ; +bool isTriangleRegular(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& Kmax) ; template void initRidgeSegments( typename PFP::MAP& map, - const typename PFP::TVEC3& position, AttributeHandler& ridge_segments, const FunctorSelect& select = allDarts, unsigned int thread = 0) ; template -void computeSingularTriangle( +void computeRidgeLines( typename PFP::MAP& map, - const typename PFP::TVEC3& position, CellMarker& regularMarker, - typename PFP::TVEC3& k, + const typename PFP::TVEC3& vertex_gradient, + const typename PFP::TVEC3& K, AttributeHandler& ridge_segments, const FunctorSelect& select = allDarts, unsigned int thread = 0) ; -template -std::vector occludingContoursDetection( - typename PFP::MAP& map, - const typename PFP::VEC3& cameraPosition, - const typename PFP::TVEC3& position, - const typename PFP::TVEC3& normal) ; - -template -typename PFP::VEC3 faceGradient( - typename PFP::MAP& map, - Dart d, - const typename PFP::TVEC3& position, - const typename PFP::TVEC3& face_normal, - const typename PFP::TREAL& kmax, - const typename PFP::TREAL& area) ; - -template -bool isTriangleRegular(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& Kmax) ; - -//template -//bool isInSameOctant(const typename PFP::VEC3& pos1, const typename PFP::VEC3& pos2) ; - template void ridgeLines( typename PFP::MAP& map, Dart d, - const typename PFP::TVEC3& position, const typename PFP::TVEC3& K, - const typename PFP::TVEC3& faceGradient, - const typename PFP::TREAL& area, + const typename PFP::TVEC3& vertex_gradient, AttributeHandler& ridge_segments) ; template -typename PFP::REAL extremality( - typename PFP::MAP& map, - Dart d, - const typename PFP::VEC3& K, - const typename PFP::TVEC3& faceGradient, - const typename PFP::TREAL& area) ; +void computeExtremalities() ; -//template -//typename PFP::TVEC3 vertexGradient( -// typename PFP::MAP& map, -// Dart d, -// const typename PFP::TVEC3& position, -// const typename PFP::TVEC3& face_gradient, -// const typename PFP::TREAL& area) ; +template +void computeSingularTriangle( + typename PFP::MAP& map, + CellMarker& regularMarker, + AttributeHandler& ridge_segments, + const FunctorSelect& select = allDarts, + unsigned int thread = 0) ; template void singularTriangle( typename PFP::MAP& map, Dart d, - const typename PFP::TVEC3& position, CellMarker& regularMarker, AttributeHandler& ridge_segments) ; template bool isEdgeInTriangle(typename PFP::MAP& map, Dart edge, Dart triangle) ; +template +std::vector occludingContoursDetection( + typename PFP::MAP& map, + const typename PFP::VEC3& cameraPosition, + const typename PFP::TVEC3& position, + const typename PFP::TVEC3& normal) ; + } // namespace Geometry } // namespace Algo diff --git a/include/Algo/Geometry/feature.hpp b/include/Algo/Geometry/feature.hpp index 51675bc8..8d89bcbd 100644 --- a/include/Algo/Geometry/feature.hpp +++ b/include/Algo/Geometry/feature.hpp @@ -65,10 +65,10 @@ template void computeFaceGradient( typename PFP::MAP& map, const typename PFP::TVEC3& position, - typename PFP::TVEC3& face_gradient, const typename PFP::TVEC3& face_normal, const typename PFP::TREAL& kmax, const typename PFP::TREAL& area, + typename PFP::TVEC3& face_gradient, const FunctorSelect& select, unsigned int thread) { @@ -77,143 +77,6 @@ void computeFaceGradient( face_gradient[d] = faceGradient(map, d, position, face_normal, kmax, area) ; } -//template -//void computeVertexGradient( -// typename PFP::MAP& map, -// const typename PFP::TVEC3& position, -// typename PFP::TVEC3& gradient, -// typename PFP::TVEC3& face_gradient, -// const typename PFP::TREAL& area, -// const FunctorSelect& select, -// unsigned int thread) -//{ -// TraversorV trav(map, select, thread); -// for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) -// gradient[d] = vertexGradient(map, d, position, face_gradient, area) ; -//} - -template -void computeTriangleType( - typename PFP::MAP& map, - const typename PFP::TVEC3& Kmax, - CellMarker& regularMarker, - const FunctorSelect& select, - unsigned int thread) -{ - TraversorF trav(map, select, thread); - for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) - if(isTriangleRegular(map, d, Kmax)) - regularMarker.mark(d) ; -} - -template -void computeRidgeLines( - typename PFP::MAP& map, - const typename PFP::TVEC3& position, - CellMarker& regularMarker, - const typename PFP::TVEC3& faceGradient, - const typename PFP::TREAL& area, - const typename PFP::TVEC3& K, - AttributeHandler& ridge_segments, - const FunctorSelect& select, - unsigned int thread) -{ - TraversorF trav(map, select, thread); - for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) - { - if (regularMarker.isMarked(d)) - ridgeLines(map, d, position, K, faceGradient, area, ridge_segments) ; - } -} - -template -void initRidgeSegments( - typename PFP::MAP& map, - const typename PFP::TVEC3& position, - AttributeHandler& ridge_segments, - const FunctorSelect& select, - unsigned int thread) -{ - TraversorF trav(map, select, thread); - for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) - ridge_segments[d].type = EMPTY ; -} - -template -void computeSingularTriangle( - typename PFP::MAP& map, - const typename PFP::TVEC3& position, - CellMarker& regularMarker, - AttributeHandler& ridge_segments, - const FunctorSelect& select = allDarts, - unsigned int thread = 0) -{ - TraversorF trav(map, select, thread); - for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) - { - if (! regularMarker.isMarked(d)) - singularTriangle(map, d, position, regularMarker, ridge_segments) ; - } -} - -template -std::vector occludingContoursDetection( - typename PFP::MAP& map, - const typename PFP::VEC3& cameraPosition, - const typename PFP::TVEC3& position, - const typename PFP::TVEC3& normal) -{ - typedef typename PFP::VEC3 VEC3 ; - typedef typename PFP::REAL REAL ; - - std::vector occludingContours ; - - TraversorF t(map) ; - for(Dart d = t.begin(); d != t.end(); d = t.next()) - { - VEC3 p1 = position[d] ; - VEC3 p2 = position[map.phi1(d)] ; - VEC3 p3 = position[map.phi_1(d)] ; - - REAL dp1 = (p1 - cameraPosition) * normal[d] ; - REAL dp2 = (p2 - cameraPosition) * normal[map.phi1(d)] ; - REAL dp3 = (p3 - cameraPosition) * normal[map.phi_1(d)] ; - - if(dp1 < 0 && dp2 > 0) - { - REAL alpha = -dp1 / (-dp1 + dp2) ; - occludingContours.push_back(alpha * p1 + (1 - alpha) * p2) ; - } - if(dp2 < 0 && dp1 > 0) - { - REAL alpha = dp1 / (dp1 - dp2) ; - occludingContours.push_back(alpha * p1 + (1 - alpha) * p2) ; - } - if(dp1 < 0 && dp3 > 0) - { - REAL alpha = -dp1 / (-dp1 + dp3) ; - occludingContours.push_back(alpha * p1 + (1 - alpha) * p3) ; - } - if(dp3 < 0 && dp1 > 0) - { - REAL alpha = dp1 / (dp1 - dp3) ; - occludingContours.push_back(alpha * p1 + (1 - alpha) * p3) ; - } - if(dp2 < 0 && dp3 > 0) - { - REAL alpha = -dp2 / (-dp2 + dp3) ; - occludingContours.push_back(alpha * p2 + (1 - alpha) * p3) ; - } - if(dp3 < 0 && dp2 > 0) - { - REAL alpha = dp2 / (dp2 - dp3) ; - occludingContours.push_back(alpha * p2 + (1 - alpha) * p3) ; - } - } - - return occludingContours ; -} - template typename PFP::VEC3 faceGradient( typename PFP::MAP& map, @@ -221,7 +84,7 @@ typename PFP::VEC3 faceGradient( const typename PFP::TVEC3& position, const typename PFP::TVEC3& face_normal, const typename PFP::TREAL& kmax, - const typename PFP::TREAL& area) + const typename PFP::TREAL& face_area) { typedef typename PFP::REAL REAL ; typedef typename PFP::VEC3 VEC3 ; @@ -241,7 +104,7 @@ typename PFP::VEC3 faceGradient( REAL k3 = kmax[it] ; VEC3 n = face_normal[d] ; - REAL a = area[d] ; + REAL a = face_area[d] ; VEC3 G = k1 * ( ( n ^ ( pos3 - pos2 ) ) / ( 2 * a ) ) + k2 * ( ( n ^ ( pos1 - pos3 ) ) / ( 2 * a ) ) + k3 * ( ( n ^ ( pos2 - pos1 ) ) / ( 2 * a ) ) ; @@ -250,6 +113,78 @@ typename PFP::VEC3 faceGradient( return G ; } +template +void computeVertexGradient( + typename PFP::MAP& map, + const typename PFP::TVEC3& face_gradient, + const typename PFP::TREAL& face_area, + typename PFP::TVEC3& vertex_gradient, + const FunctorSelect& select, + unsigned int thread) +{ + TraversorV trav(map, select, thread); + for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) + vertex_gradient[d] = vertexGradient(map, d, face_gradient, face_area) ; +} + +template +typename PFP::VEC3 vertexGradient( + typename PFP::MAP& map, + Dart d, + const typename PFP::TVEC3& face_gradient, + const typename PFP::TREAL& face_area) +{ + typename PFP::VEC3 G(0) ; + typename PFP::REAL A(0) ; + Traversor2VF t(map, d) ; + for (Dart d = t.begin(); d != t.end(); d = t.next()) + { + G += face_area[d] * face_gradient[d] ; + A += face_area[d] ; + } + G /= A ; + + G.normalize() ; + return G ; +} + +//template +//typename PFP::REAL extremality( +// typename PFP::MAP& map, +// Dart d, +// const typename PFP::VEC3& K, +// const typename PFP::TVEC3& face_gradient, +// const typename PFP::TREAL& face_area) +//{ +// typedef typename PFP::REAL REAL ; +// +// REAL a = 0 ; +// REAL e = 0 ; +// +// Traversor2VF trav(map, d) ; +// for (Dart d2 = trav.begin(); d2 != trav.end(); d2 = trav.next()) +// { +// a += face_area[d2] ; +// e += face_area[d2] * ( face_gradient[d2] * K ) ; +// } +// +// return (e / a) ; +//} + +template +void computeTriangleType( + typename PFP::MAP& map, + const typename PFP::TVEC3& Kmax, + CellMarker& regularMarker, + const FunctorSelect& select, + unsigned int thread) +{ + TraversorF trav(map, select, thread); + for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) + if(isTriangleRegular(map, d, Kmax)) + regularMarker.mark(d) ; +} + template bool mutuallyPositive(typename PFP::VEC3& v1, typename PFP::VEC3& v2, typename PFP::VEC3& v3) { @@ -298,63 +233,44 @@ bool isTriangleRegular(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3 // return true ; return false ; +} -// if ( isInSameOctant(K1, K2) && isInSameOctant(K1, K3) ) -// { -// //regular triangle -// return true ; -// } -// else -// { -// //singular triangle -// return false ; -// } +template +void initRidgeSegments( + typename PFP::MAP& map, + AttributeHandler& ridge_segments, + const FunctorSelect& select, + unsigned int thread) +{ + TraversorF trav(map, select, thread); + for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) + ridge_segments[d].type = EMPTY ; } -//template -//bool isInSameOctant(const typename PFP::VEC3& pos1, const typename PFP::VEC3& pos2) -//{ -// return ( ( pos1[0] > 0 && pos1[1] > 0 && pos1[2] > 0 && //one of the eight octant -// ( ( pos2[0] > 0 && pos2[1] > 0 && pos2[2] > 0 ) or //one choice of sign -// ( pos2[0] < 0 && pos2[1] < 0 && pos2[2] < 0 ) ) ) or //the other choice -// -// ( pos1[0] > 0 && pos1[1] > 0 && pos1[2] < 0 && -// ( ( pos2[0] > 0 && pos2[1] > 0 && pos2[2] < 0 ) or -// ( pos2[0] < 0 && pos2[1] < 0 && pos2[2] > 0 ) ) ) or -// -// ( pos1[0] > 0 && pos1[1] < 0 && pos1[2] > 0 && -// ( ( pos2[0] > 0 && pos2[1] < 0 && pos2[2] > 0 ) or -// ( pos2[0] < 0 && pos2[1] > 0 && pos2[2] < 0 ) ) ) or -// -// ( pos1[0] > 0 && pos1[1] < 0 && pos1[2] < 0 && -// ( ( pos2[0] > 0 && pos2[1] < 0 && pos2[2] < 0 ) or -// ( pos2[0] < 0 && pos2[1] > 0 && pos2[2] > 0 ) ) ) or -// -// ( pos1[0] < 0 && pos1[1] > 0 && pos1[2] > 0 && -// ( ( pos2[0] < 0 && pos2[1] > 0 && pos2[2] > 0 ) or -// ( pos2[0] > 0 && pos2[1] < 0 && pos2[2] < 0 ) ) ) or -// -// ( pos1[0] < 0 && pos1[1] > 0 && pos1[2] < 0 && -// ( ( pos2[0] < 0 && pos2[1] > 0 && pos2[2] < 0 ) or -// ( pos2[0] > 0 && pos2[1] < 0 && pos2[2] > 0 ) ) ) or -// -// ( pos1[0] < 0 && pos1[1] < 0 && pos1[2] > 0 && -// ( ( pos2[0] < 0 && pos2[1] < 0 && pos2[2] > 0 ) or -// ( pos2[0] > 0 && pos2[1] > 0 && pos2[2] < 0 ) ) ) or -// -// ( pos1[0] < 0 && pos1[1] < 0 && pos1[2] < 0 && -// ( ( pos2[0] < 0 && pos2[1] < 0 && pos2[2] < 0 ) or -// ( pos2[0] > 0 && pos2[1] > 0 && pos2[2] > 0 ) ) ) ) ; -//} +template +void computeRidgeLines( + typename PFP::MAP& map, + CellMarker& regularMarker, + const typename PFP::TVEC3& vertex_gradient, + const typename PFP::TVEC3& K, + AttributeHandler& ridge_segments, + const FunctorSelect& select, + unsigned int thread) +{ + TraversorF trav(map, select, thread); + for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) + { + if (regularMarker.isMarked(d)) + ridgeLines(map, d, K, vertex_gradient, ridge_segments) ; + } +} template void ridgeLines( typename PFP::MAP& map, Dart d, - const typename PFP::TVEC3& position, const typename PFP::TVEC3& K, - const typename PFP::TVEC3& faceGradient, - const typename PFP::TREAL& area, + const typename PFP::TVEC3& vertex_gradient, AttributeHandler& ridge_segments) { typedef typename PFP::REAL REAL ; @@ -377,11 +293,15 @@ void ridgeLines( /* Calcul coefficient extremalite */ - REAL e1 = extremality(map, v1, Kv1, faceGradient, area) ; - REAL e2 = extremality(map, v2, Kv2, faceGradient, area) ; - REAL e3 = extremality(map, v3, Kv3, faceGradient, area) ; +// REAL e1 = extremality(map, v1, Kv1, face_gradient, face_area) ; +// REAL e2 = extremality(map, v2, Kv2, face_gradient, face_area) ; +// REAL e3 = extremality(map, v3, Kv3, face_gradient, face_area) ; - /* Stockage des zeros */ + REAL e1 = vertex_gradient[v1] * Kv1 ; + REAL e2 = vertex_gradient[v2] * Kv2 ; + REAL e3 = vertex_gradient[v3] * Kv3 ; + + /* Extraction des zeros */ bool p1set = false ; bool p2set = false ; @@ -426,61 +346,25 @@ void ridgeLines( } template -typename PFP::REAL extremality( +void computeSingularTriangle( typename PFP::MAP& map, - Dart d, - const typename PFP::VEC3& K, - const typename PFP::TVEC3& faceGradient, - const typename PFP::TREAL& area) + CellMarker& regularMarker, + AttributeHandler& ridge_segments, + const FunctorSelect& select, + unsigned int thread) { - typedef typename PFP::REAL REAL ; - - REAL a = 0 ; - REAL e = 0 ; - - Traversor2VF trav(map, d) ; - for (Dart d2 = trav.begin(); d2 != trav.end(); d2 = trav.next()) + TraversorF trav(map, select, thread); + for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) { - a += area[d2] ; - e += area[d2] * ( faceGradient[d2] * K ) ; + if (! regularMarker.isMarked(d)) + singularTriangle(map, d, regularMarker, ridge_segments) ; } - - return (e / a) ; } -//template -//typename PFP::TVEC3 vertexGradient( -// typename PFP::MAP& map, -// Dart d, -// const typename PFP::TVEC3& position, -// const typename PFP::TVEC3& face_gradient, -// const typename PFP::TREAL& area) -//{ -// typedef typename PFP::REAL REAL ; -// typedef typename PFP::VEC3 VEC3 ; -// -// VEC3 G(0) ; -// -// REAL A = 0 ; -// -// Traversor2VF t(map, d) ; -// for (Dart d = t.begin(); d != t.end(); d = t.next()) -// { -// G += area[d] * face_gradient[d] ; -// A += area[d] ; -// } -// -// G = G / A ; -// -// G.normalize() ; -// return G ; -//} - template void singularTriangle( typename PFP::MAP& map, Dart d, - const typename PFP::TVEC3& position, CellMarker& regularMarker, AttributeHandler& ridge_segments) { @@ -540,6 +424,64 @@ bool isEdgeInTriangle(typename PFP::MAP& map, Dart edge, Dart triangle) return inTriangle ; } +template +std::vector occludingContoursDetection( + typename PFP::MAP& map, + const typename PFP::VEC3& cameraPosition, + const typename PFP::TVEC3& position, + const typename PFP::TVEC3& normal) +{ + typedef typename PFP::VEC3 VEC3 ; + typedef typename PFP::REAL REAL ; + + std::vector occludingContours ; + + TraversorF t(map) ; + for(Dart d = t.begin(); d != t.end(); d = t.next()) + { + VEC3 p1 = position[d] ; + VEC3 p2 = position[map.phi1(d)] ; + VEC3 p3 = position[map.phi_1(d)] ; + + REAL dp1 = (p1 - cameraPosition) * normal[d] ; + REAL dp2 = (p2 - cameraPosition) * normal[map.phi1(d)] ; + REAL dp3 = (p3 - cameraPosition) * normal[map.phi_1(d)] ; + + if(dp1 < 0 && dp2 > 0) + { + REAL alpha = -dp1 / (-dp1 + dp2) ; + occludingContours.push_back(alpha * p1 + (1 - alpha) * p2) ; + } + if(dp2 < 0 && dp1 > 0) + { + REAL alpha = dp1 / (dp1 - dp2) ; + occludingContours.push_back(alpha * p1 + (1 - alpha) * p2) ; + } + if(dp1 < 0 && dp3 > 0) + { + REAL alpha = -dp1 / (-dp1 + dp3) ; + occludingContours.push_back(alpha * p1 + (1 - alpha) * p3) ; + } + if(dp3 < 0 && dp1 > 0) + { + REAL alpha = dp1 / (dp1 - dp3) ; + occludingContours.push_back(alpha * p1 + (1 - alpha) * p3) ; + } + if(dp2 < 0 && dp3 > 0) + { + REAL alpha = -dp2 / (-dp2 + dp3) ; + occludingContours.push_back(alpha * p2 + (1 - alpha) * p3) ; + } + if(dp3 < 0 && dp2 > 0) + { + REAL alpha = dp2 / (dp2 - dp3) ; + occludingContours.push_back(alpha * p2 + (1 - alpha) * p3) ; + } + } + + return occludingContours ; +} + } // namespace Geometry } // namespace Algo -- GitLab