From 4eff38ed9155eebe2957a6f419f026f0bba385f1 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Tue, 18 Oct 2011 17:33:58 +0200 Subject: [PATCH] occluding contours v1 --- include/Algo/Geometry/area.hpp | 12 +++--- include/Algo/Geometry/feature.h | 5 ++- include/Algo/Geometry/feature.hpp | 69 +++++++++++++++++++++++++++---- include/Algo/Remeshing/pliant.hpp | 2 +- include/Geometry/bounding_box.hpp | 2 +- src/Utils/GLSLShader.cpp | 15 +------ src/Utils/qtSimple.cpp | 8 ++-- 7 files changed, 79 insertions(+), 34 deletions(-) diff --git a/include/Algo/Geometry/area.hpp b/include/Algo/Geometry/area.hpp index f073050c5..4112356ea 100644 --- a/include/Algo/Geometry/area.hpp +++ b/include/Algo/Geometry/area.hpp @@ -37,9 +37,9 @@ namespace Geometry template typename PFP::REAL triangleArea(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) { - typename PFP::VEC3 p1 = position[d]; - typename PFP::VEC3 p2 = position[map.phi1(d)]; - typename PFP::VEC3 p3 = position[map.phi_1(d)]; + typename PFP::VEC3 p1 = position[d] ; + typename PFP::VEC3 p2 = position[map.phi1(d)] ; + typename PFP::VEC3 p3 = position[map.phi_1(d)] ; return Geom::triangleArea(p1, p2, p3) ; } @@ -47,7 +47,7 @@ typename PFP::REAL triangleArea(typename PFP::MAP& map, Dart d, const typename P template typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) { - typedef typename PFP::VEC3 VEC3; + typedef typename PFP::VEC3 VEC3 ; if(map.isFaceTriangle(d)) return triangleArea(map, d, position) ; @@ -58,8 +58,8 @@ typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const typename Dart it = d ; do { - VEC3 p1 = position[it]; - VEC3 p2 = position[map.phi1(it)]; + VEC3 p1 = position[it] ; + VEC3 p2 = position[map.phi1(it)] ; area += Geom::triangleArea(p1, p2, centroid) ; it = map.phi1(it) ; } while (it != d) ; diff --git a/include/Algo/Geometry/feature.h b/include/Algo/Geometry/feature.h index 9a9a98d88..3ecab44b3 100644 --- a/include/Algo/Geometry/feature.h +++ b/include/Algo/Geometry/feature.h @@ -35,7 +35,10 @@ namespace Geometry { template -void featureEdgeDetection(typename PFP::MAP& map, const typename PFP::TVEC3& position, DartMarker& feature) ; +void featureEdgeDetection(typename PFP::MAP& map, const typename PFP::TVEC3& position, CellMarker& featureEdge) ; + +template +std::vector occludingContoursDetection(typename PFP::MAP& map, const typename PFP::VEC3& viewDir, const typename PFP::TVEC3& position, const typename PFP::TVEC3& normal) ; } // namespace Geometry diff --git a/include/Algo/Geometry/feature.hpp b/include/Algo/Geometry/feature.hpp index 889134c7e..d3fb3a055 100644 --- a/include/Algo/Geometry/feature.hpp +++ b/include/Algo/Geometry/feature.hpp @@ -35,28 +35,83 @@ namespace Geometry { template -void featureEdgeDetection(typename PFP::MAP& map, typename PFP::TVEC3& position, DartMarker& feature) +void featureEdgeDetection(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& featureEdge) { typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::REAL REAL ; - feature.unmarkAll() ; + featureEdge.unmarkAll() ; - AttributeHandler fNormal = map.template addAttribute(FACE, "fNormal") ; + AttributeHandler fNormal = map.template getAttribute(FACE, "normal") ; + if(!fNormal.isValid()) + fNormal = map.template addAttribute(FACE, "normal") ; Algo::Geometry::computeNormalFaces(map, position, fNormal) ; - DartMarker m(map) ; + CellMarker m(map, EDGE) ; for(Dart d = map.begin(); d != map.end(); map.next(d)) { if(!m.isMarked(d)) { - m.markOrbit(EDGE, d) ; + m.mark(d) ; if(Geom::angle(fNormal[d], fNormal[map.phi2(d)]) > M_PI / REAL(6)) - feature.markOrbit(EDGE, d) ; + featureEdge.mark(d) ; } } - map.template removeAttribute(fNormal) ; +// map.template removeAttribute(fNormal) ; +} + +template +std::vector occludingContoursDetection(typename PFP::MAP& map, const typename PFP::VEC3& viewDir, const typename PFP::TVEC3& position, const typename PFP::TVEC3& normal) +{ + typedef typename PFP::VEC3 VEC3 ; + typedef typename PFP::REAL REAL ; + + std::vector occludingContours ; + + CellMarker m(map, FACE) ; + for(Dart d = map.begin(); d != map.end(); map.next(d)) + { + if(!m.isMarked(d)) + { + m.mark(d) ; + REAL dp1 = viewDir * normal[d] ; + REAL dp2 = viewDir * normal[map.phi1(d)] ; + REAL dp3 = viewDir * normal[map.phi_1(d)] ; + if(dp1 < 0 && dp2 > 0) + { + REAL alpha = -dp1 / (-dp1 + dp2) ; + occludingContours.push_back(alpha * position[d] + (1 - alpha) * position[map.phi1(d)]) ; + } + if(dp2 < 0 && dp1 > 0) + { + REAL alpha = dp1 / (dp1 - dp2) ; + occludingContours.push_back(alpha * position[d] + (1 - alpha) * position[map.phi1(d)]) ; + } + if(dp1 < 0 && dp3 > 0) + { + REAL alpha = -dp1 / (-dp1 + dp3) ; + occludingContours.push_back(alpha * position[d] + (1 - alpha) * position[map.phi_1(d)]) ; + } + if(dp3 < 0 && dp1 > 0) + { + REAL alpha = dp1 / (dp1 - dp3) ; + occludingContours.push_back(alpha * position[d] + (1 - alpha) * position[map.phi_1(d)]) ; + } + if(dp2 < 0 && dp3 > 0) + { + REAL alpha = -dp2 / (-dp2 + dp3) ; + occludingContours.push_back(alpha * position[map.phi1(d)] + (1 - alpha) * position[map.phi_1(d)]) ; + } + if(dp3 < 0 && dp2 > 0) + { + REAL alpha = dp2 / (dp2 - dp3) ; + occludingContours.push_back(alpha * position[map.phi1(d)] + (1 - alpha) * position[map.phi_1(d)]) ; + } + } + } + + return occludingContours ; } } // namespace Geometry diff --git a/include/Algo/Remeshing/pliant.hpp b/include/Algo/Remeshing/pliant.hpp index a50192eea..659124bd5 100644 --- a/include/Algo/Remeshing/pliant.hpp +++ b/include/Algo/Remeshing/pliant.hpp @@ -81,7 +81,7 @@ void pliantRemeshing(typename PFP::MAP& map, typename PFP::TVEC3& position, type } // compute feature edges - DartMarker featureEdge(map) ; + CellMarker featureEdge(map, EDGE) ; Algo::Geometry::featureEdgeDetection(map, position, featureEdge) ; // compute feature vertices diff --git a/include/Geometry/bounding_box.hpp b/include/Geometry/bounding_box.hpp index 6db89968d..51e6478a8 100644 --- a/include/Geometry/bounding_box.hpp +++ b/include/Geometry/bounding_box.hpp @@ -169,7 +169,7 @@ void BoundingBox::fusion(const BoundingBox& bb) { VEC bbmin = bb.min() ; VEC bbmax = bb.max() ; - for(unsigned int i = 0; i < bbmin.size(); ++i) + for(unsigned int i = 0; i < bbmin.dimension(); ++i) { if(bbmin[i] < m_pMin[i]) m_pMin[i] = bbmin[i] ; diff --git a/src/Utils/GLSLShader.cpp b/src/Utils/GLSLShader.cpp index 25e692868..fcb68a791 100644 --- a/src/Utils/GLSLShader.cpp +++ b/src/Utils/GLSLShader.cpp @@ -910,14 +910,13 @@ void GLSLShader::addPathFileSeach(const std::string& path) m_pathes.push_back(path); } - unsigned int GLSLShader::bindVA_VBO(const std::string& name, VBO* vbo) { GLint idVA = glGetAttribLocation(this->m_program_object, name.c_str()); //valid ? if (idVA < 0) { - CGoGNerr << "GLSLShader: Attribute "<m_program_object, name.c_str()); @@ -971,9 +965,6 @@ void GLSLShader::unbindVA(const std::string& name) CGoGNerr << "GLSLShader: Attribute "<unbind(); } - void GLSLShader::updateCurrentMatrices() { glm::mat4 model(currentModelView()); @@ -1036,9 +1026,6 @@ void GLSLShader::updateCurrentMatrices() it->second->updateMatrices(currentProjection(), model); } - - - } // namespace Utils } // namespace CGoGN diff --git a/src/Utils/qtSimple.cpp b/src/Utils/qtSimple.cpp index 88c43e349..f945dfd57 100644 --- a/src/Utils/qtSimple.cpp +++ b/src/Utils/qtSimple.cpp @@ -316,9 +316,9 @@ GLfloat SimpleQT::getOrthoScreenRay(int x, int y, Geom::Vec3f& rayA, Geom::Vec3f GLfloat depth_t[25]; glReadPixels(x-2, yy-2, 5, 5, GL_DEPTH_COMPONENT, GL_FLOAT, depth_t); - GLfloat depth=0.0f; - unsigned int nb=0; - for (unsigned int i=0; i< 25; ++i) + GLfloat depth = 0.0f; + unsigned int nb = 0; + for (unsigned int i = 0; i < 25; ++i) { if (depth_t[i] != 1.0f) { @@ -326,7 +326,7 @@ GLfloat SimpleQT::getOrthoScreenRay(int x, int y, Geom::Vec3f& rayA, Geom::Vec3f nb++; } } - if (nb>0) + if (nb > 0) depth /= float(nb); else depth = 0.5f; -- GitLab