From 7631797f47fe1e5ca21ec5d17c17dd010c35d2c0 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Fri, 4 Mar 2011 18:29:22 +0100 Subject: [PATCH] pliant remeshing : la suite.. --- Apps/Examples/miniTest.cpp | 55 ++++++++++++++++++++++++++++++- include/Algo/Geometry/normal.hpp | 17 ++++++---- include/Algo/Remeshing/pliant.hpp | 18 +++++----- include/Geometry/vector_gen.h | 2 ++ include/Geometry/vector_gen.hpp | 14 ++++++-- 5 files changed, 88 insertions(+), 18 deletions(-) diff --git a/Apps/Examples/miniTest.cpp b/Apps/Examples/miniTest.cpp index 7974fece..fabf2abf 100644 --- a/Apps/Examples/miniTest.cpp +++ b/Apps/Examples/miniTest.cpp @@ -45,6 +45,8 @@ #include "Algo/Decimation/decimation.h" #include "Algo/Remeshing/pliant.h" +#include "Algo/Selection/raySelector.h" + using namespace CGoGN ; struct PFP: public PFP_STANDARD @@ -96,6 +98,8 @@ public: Algo::Render::VBO::topo_VBORenderMapD* topo_render ; GLuint dl_norm, dl_lapl ; + Dart selectedDart ; + MyGlutWin(int* argc, char **argv, int winX, int winY) ; void init() ; @@ -306,6 +310,8 @@ MyGlutWin::MyGlutWin(int* argc, char **argv, int winX, int winY) : shaders[0].loadShaders("phong_vs.txt", "phong_ps.txt") ; shaders[1].loadShaders("flat_vs.txt", "flat_ps.txt", "flat_gs.txt") ; } + + selectedDart = Dart::nil() ; } void MyGlutWin::init() @@ -349,10 +355,26 @@ void MyGlutWin::myRedraw() glPushMatrix() ; - float sc = 50. / gWidthObj ; + float sc = 50.0f / gWidthObj ; glScalef(sc, sc, sc) ; glTranslatef(-gPosObj[0], -gPosObj[1], -gPosObj[2]) ; + if(!selectedDart.isNil()) + { + glDisable(GL_LIGHTING) ; + glColor3f(1.0f,0.0f,0.0f) ; + glLineWidth(3.0f) ; + PFP::VEC3 c = Algo::Geometry::faceCentroid(myMap, selectedDart, position) ; + PFP::VEC3 p1 = position[selectedDart] ; + PFP::VEC3 p2 = position[myMap.phi1(selectedDart)] ; + p1 += PFP::REAL(0.1) * (c - p1) ; + p2 += PFP::REAL(0.1) * (c - p2) ; + glBegin(GL_LINES) ; + glVertex3fv(p1.data()) ; + glVertex3fv(p2.data()) ; + glEnd() ; + } + if (renderTopo) { glDisable(GL_LIGHTING); @@ -705,6 +727,37 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y) break ; } + case 'i': + { + glPushMatrix(); + + float sc = 50.0f / gWidthObj ; + glScalef(sc, sc, sc) ; + glTranslatef(-gPosObj[0], -gPosObj[1], -gPosObj[2]) ; + + PFP::VEC3 rayA, rayB ; + getOrthoScreenRay(x, y, rayA, rayB) ; + PFP::VEC3 AB = rayB - rayA ; + + std::vector darts ; + Algo::Selection::dartsRaySelection(myMap, position, rayA, AB, darts) ; + + glPopMatrix(); + + if(!darts.empty()) + { + selectedDart = darts[0] ; + std::cout << "selected dart -> " << selectedDart << std::endl ; + std::cout << " phi1 -> " << myMap.phi1(selectedDart) << " / phi2 -> " << myMap.phi2(selectedDart) << std::endl ; + std::cout << " emb0 -> " << myMap.getDartEmbedding(VERTEX_ORBIT, selectedDart) << std::endl ; + } + else + selectedDart = Dart::nil() ; + + glutPostRedisplay() ; + break ; + } + case 'a': { Algo::Geometry::computeLaplacianVertices(myMap, Algo::Geometry::TOPOLOGICAL, position, laplacian) ; diff --git a/include/Algo/Geometry/normal.hpp b/include/Algo/Geometry/normal.hpp index 8404be6c..e2f340d2 100644 --- a/include/Algo/Geometry/normal.hpp +++ b/include/Algo/Geometry/normal.hpp @@ -40,9 +40,9 @@ typename PFP::VEC3 triangleNormal(typename PFP::MAP& map, Dart d, const typename { typedef typename PFP::VEC3 VEC3 ; - VEC3 p1 = position[d]; - VEC3 p2 = position[map.phi1(d)]; - VEC3 p3 = position[map.phi_1(d)]; + const VEC3& p1 = position[d]; + const VEC3& p2 = position[map.phi1(d)]; + const VEC3& p3 = position[map.phi_1(d)]; VEC3 N = Geom::triangleNormal(p1, p2, p3) ; N.normalize() ; @@ -84,10 +84,13 @@ typename PFP::VEC3 vertexNormal(typename PFP::MAP& map, Dart d, const typename P do { VEC3 n = faceNormal(map, it, position) ; - VEC3 v1 = vectorOutOfDart(map, it, position) ; - VEC3 v2 = vectorOutOfDart(map, map.phi_1(it), position) ; - n *= convexFaceArea(map,it,position) / (v1.norm2() * v2.norm2()) ; - N += n ; + if(!n.hasNan()) + { + VEC3 v1 = vectorOutOfDart(map, it, position) ; + VEC3 v2 = vectorOutOfDart(map, map.phi_1(it), position) ; + n *= convexFaceArea(map, it, position) / (v1.norm2() * v2.norm2()) ; + N += n ; + } it = map.phi1(map.phi2(it)) ; } while (it != d) ; N.normalize() ; diff --git a/include/Algo/Remeshing/pliant.hpp b/include/Algo/Remeshing/pliant.hpp index 01f22545..466bc94d 100644 --- a/include/Algo/Remeshing/pliant.hpp +++ b/include/Algo/Remeshing/pliant.hpp @@ -86,7 +86,7 @@ void pliantRemeshing(typename PFP::MAP& map, typename PFP::TVEC3& position, type { m3.markOrbit(EDGE_ORBIT, d) ; REAL length = Algo::Geometry::edgeLength(map, d, position) ; - if(length < edgeLengthInf) + if(length < edgeLengthInf && map.edgeCanCollapse(d)) { bool collapse = true ; Dart dd = map.phi2(d) ; @@ -125,7 +125,7 @@ void pliantRemeshing(typename PFP::MAP& map, typename PFP::TVEC3& position, type flip += x > 6 ? 1 : (x < 6 ? -1 : 0) ; flip += y < 6 ? 1 : (y > 6 ? -1 : 0) ; flip += z < 6 ? 1 : (z > 6 ? -1 : 0) ; - if(flip > 2) + if(flip > 1) { map.flipEdge(d) ; m4.markOrbit(EDGE_ORBIT, map.phi1(d)) ; @@ -140,8 +140,8 @@ void pliantRemeshing(typename PFP::MAP& map, typename PFP::TVEC3& position, type Algo::Geometry::computeNormalVertices(map, position, normal) ; // tangential relaxation - AttributeHandler newPosition = map.template addAttribute(VERTEX_ORBIT, "newPosition") ; - Algo::Geometry::computeNeighborhoodCentroidVertices(map, position, newPosition) ; + AttributeHandler centroid = map.template addAttribute(VERTEX_ORBIT, "centroid") ; + Algo::Geometry::computeNeighborhoodCentroidVertices(map, position, centroid) ; CellMarker vm(map, VERTEX_CELL) ; for(Dart d = map.begin(); d != map.end(); map.next(d)) @@ -149,12 +149,14 @@ void pliantRemeshing(typename PFP::MAP& map, typename PFP::TVEC3& position, type if(!vm.isMarked(d)) { vm.mark(d) ; - VEC3 l = position[d] - newPosition[d] ; - newPosition[d] = newPosition[d] + ((normal[d] * l) * normal[d]) ; + VEC3 l = position[d] - centroid[d] ; + REAL e = l * normal[d] ; + VEC3 displ = e * normal[d] ; + position[d] = centroid[d] + displ ; } } - map.template swapAttributes(position, newPosition) ; - map.template removeAttribute(newPosition) ; + + map.template removeAttribute(centroid) ; } } // namespace Remeshing diff --git a/include/Geometry/vector_gen.h b/include/Geometry/vector_gen.h index 9a253b34..f86dfd19 100644 --- a/include/Geometry/vector_gen.h +++ b/include/Geometry/vector_gen.h @@ -132,6 +132,8 @@ public: // Equal bool operator==(const Vector& v) const ; + bool hasNan() const ; + /**********************************************/ /* STREAM OPERATORS */ /**********************************************/ diff --git a/include/Geometry/vector_gen.hpp b/include/Geometry/vector_gen.hpp index c2fdc758..db3de877 100644 --- a/include/Geometry/vector_gen.hpp +++ b/include/Geometry/vector_gen.hpp @@ -270,11 +270,21 @@ inline Vector Vector::operator^(const Vector v) const template inline bool Vector::operator==(const Vector& v) const { - for (unsigned int i = 0 ; i < DIM ; ++i) - if (v[i] != m_data[i]) return false ; + for(unsigned int i = 0 ; i < DIM ; ++i) + if(v[i] != m_data[i]) + return false ; return true ; } +template +inline bool Vector::hasNan() const +{ + for(unsigned int i = 0 ; i < DIM ; ++i) + if(isnan(m_data[i])) + return true ; + return false ; +} + /**********************************************/ /* STREAM OPERATORS */ /**********************************************/ -- GitLab