From 7dd5fd6183c8d73ebd5c4d42c8578353899bf7b8 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Wed, 26 Oct 2011 16:24:00 +0200 Subject: [PATCH] diverses petites modifs.. --- include/Algo/Geometry/curvature.hpp | 14 ++--- include/Algo/Geometry/feature.h | 2 +- include/Algo/Geometry/feature.hpp | 26 +++++---- include/Algo/Geometry/normal.hpp | 23 ++------ include/Algo/LinearSolving/basic.h | 33 ++++++++++-- include/Algo/LinearSolving/matrixSetup.h | 68 ++++++++++++++++++++++-- include/Utils/pointSprite.h | 1 + include/Utils/qtSimple.h | 10 ++-- include/Utils/qtgl.h | 4 ++ src/Utils/qtSimple.cpp | 41 +++++++------- src/Utils/qtgl.cpp | 49 ++++++++--------- 11 files changed, 173 insertions(+), 98 deletions(-) diff --git a/include/Algo/Geometry/curvature.hpp b/include/Algo/Geometry/curvature.hpp index c030293a..ec036138 100644 --- a/include/Algo/Geometry/curvature.hpp +++ b/include/Algo/Geometry/curvature.hpp @@ -117,12 +117,12 @@ void computeCurvatureVertex_QuadraticFitting( template void vertexQuadraticFitting( - typename PFP::MAP& map, - Dart dart, - typename PFP::MATRIX33& localFrame, - const typename PFP::TVEC3& position, - const typename PFP::TVEC3& normal, - float& a, float& b, float& c, float& d, float& e) + typename PFP::MAP& map, + Dart dart, + typename PFP::MATRIX33& localFrame, + const typename PFP::TVEC3& position, + const typename PFP::TVEC3& normal, + float& a, float& b, float& c, float& d, float& e) { typename PFP::VEC3 p = position[dart] ; @@ -352,7 +352,7 @@ void computeCurvatureVertex_NormalCycles( const std::vector& vd1 = neigh.getInsideEdges() ; for (std::vector::const_iterator it = vd1.begin(); it != vd1.end(); ++it) { - const VEC3 e = position[map.phi2(*it)] - position[*it] ; + const VEC3 e = Algo::Geometry::vectorOutOfDart(map, *it, position) ; tensor += Geom::transposed_vectors_mult(e,e) * edgeangle[*it] * (1 / e.norm()) ; } // border diff --git a/include/Algo/Geometry/feature.h b/include/Algo/Geometry/feature.h index 3ecab44b..cbdbe6ca 100644 --- a/include/Algo/Geometry/feature.h +++ b/include/Algo/Geometry/feature.h @@ -38,7 +38,7 @@ template 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) ; +std::vector occludingContoursDetection(typename PFP::MAP& map, const typename PFP::VEC3& cameraPosition, 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 d3fb3a05..a406b6a3 100644 --- a/include/Algo/Geometry/feature.hpp +++ b/include/Algo/Geometry/feature.hpp @@ -62,7 +62,7 @@ void featureEdgeDetection(typename PFP::MAP& map, typename PFP::TVEC3& position, } template -std::vector occludingContoursDetection(typename PFP::MAP& map, const typename PFP::VEC3& viewDir, const typename PFP::TVEC3& position, const typename PFP::TVEC3& normal) +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 ; @@ -75,38 +75,44 @@ std::vector occludingContoursDetection(typename PFP::MAP& ma 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)] ; + + 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 * position[d] + (1 - alpha) * position[map.phi1(d)]) ; + occludingContours.push_back(alpha * p1 + (1 - alpha) * p2) ; } if(dp2 < 0 && dp1 > 0) { REAL alpha = dp1 / (dp1 - dp2) ; - occludingContours.push_back(alpha * position[d] + (1 - alpha) * position[map.phi1(d)]) ; + occludingContours.push_back(alpha * p1 + (1 - alpha) * p2) ; } if(dp1 < 0 && dp3 > 0) { REAL alpha = -dp1 / (-dp1 + dp3) ; - occludingContours.push_back(alpha * position[d] + (1 - alpha) * position[map.phi_1(d)]) ; + occludingContours.push_back(alpha * p1 + (1 - alpha) * p3) ; } if(dp3 < 0 && dp1 > 0) { REAL alpha = dp1 / (dp1 - dp3) ; - occludingContours.push_back(alpha * position[d] + (1 - alpha) * position[map.phi_1(d)]) ; + occludingContours.push_back(alpha * p1 + (1 - alpha) * p3) ; } 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)]) ; + occludingContours.push_back(alpha * p2 + (1 - alpha) * p3) ; } 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)]) ; + occludingContours.push_back(alpha * p2 + (1 - alpha) * p3) ; } } } diff --git a/include/Algo/Geometry/normal.hpp b/include/Algo/Geometry/normal.hpp index 4138cd02..e6bc5855 100644 --- a/include/Algo/Geometry/normal.hpp +++ b/include/Algo/Geometry/normal.hpp @@ -84,7 +84,7 @@ typename PFP::VEC3 faceNormal(typename PFP::MAP& map, Dart d, const typename PFP { VEC3 n = triangleNormal(map, it, position) ; //if(!std::isnan(n[0]) && !std::isnan(n[1]) && !std::isnan(n[2])) - if (n[0] == n[0] && n[1] == n[1] && n[2] == n[2]) + if(!n.hasNan()) N += n ; it = map.phi1(it) ; } while (it != d) ; @@ -130,24 +130,6 @@ void computeNormalFaces(typename PFP::MAP& map, const typename PFP::TVEC3& posit } } -template -class computeNormalVerticesFunctor : public FunctorMap -{ -protected: - typename PFP::MAP& m_map; - const typename PFP::TVEC3& m_position; - typename PFP::TVEC3& m_normal; -public: - computeNormalVerticesFunctor(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& normal): - m_map(map), m_position(position), m_normal(normal) - {} - bool operator()(Dart d) - { - m_normal[d] = vertexNormal(m_map, d, m_position) ; - return false; - } -}; - template void computeNormalVertices(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& normal, const FunctorSelect& select, unsigned int thread) { @@ -186,7 +168,8 @@ typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart if (s >= 0) a = acos(c) ; else a = -acos(c) ; } - if (isnan(a)) +// if (isnan(a)) + if(a != a) std::cerr<< "Warning : computeAngleBetweenNormalsOnEdge returns NaN on edge " << d << "-" << dd << std::endl ; return a ; } diff --git a/include/Algo/LinearSolving/basic.h b/include/Algo/LinearSolving/basic.h index 68235770..5b786ef9 100644 --- a/include/Algo/LinearSolving/basic.h +++ b/include/Algo/LinearSolving/basic.h @@ -106,9 +106,9 @@ void addRowsRHS_Equality( LinearSolver* s, const AttributeHandler index, const AttributeHandler& attr, - float amount) + const AttributeHandler& weight) { - FunctorEquality_Scalar ec(s, index, attr, amount) ; + FunctorEquality_PerVertexWeight_Scalar ec(s, index, attr, weight) ; m.foreach_orbit(VERTEX, ec) ; } @@ -118,10 +118,35 @@ void addRowsRHS_Equality( LinearSolver* s, const AttributeHandler index, const AttributeHandler& attr, - float amount, + float weight) +{ + FunctorEquality_UniformWeight_Scalar ec(s, index, attr, weight) ; + m.foreach_orbit(VERTEX, ec) ; +} + +template +void addRowsRHS_Equality( + typename PFP::MAP& m, + LinearSolver* s, + const AttributeHandler index, + const AttributeHandler& attr, + const AttributeHandler& weight, + unsigned int coord) +{ + FunctorEquality_PerVertexWeight_Vector ec(s, index, attr, weight, coord) ; + m.foreach_orbit(VERTEX, ec) ; +} + +template +void addRowsRHS_Equality( + typename PFP::MAP& m, + LinearSolver* s, + const AttributeHandler index, + const AttributeHandler& attr, + float weight, unsigned int coord) { - FunctorEquality_Vector ec(s, index, attr, amount, coord) ; + FunctorEquality_UniformWeight_Vector ec(s, index, attr, weight, coord) ; m.foreach_orbit(VERTEX, ec) ; } diff --git a/include/Algo/LinearSolving/matrixSetup.h b/include/Algo/LinearSolving/matrixSetup.h index c55e0984..23c96ada 100644 --- a/include/Algo/LinearSolving/matrixSetup.h +++ b/include/Algo/LinearSolving/matrixSetup.h @@ -36,7 +36,36 @@ namespace LinearSolving *******************************************************************************/ template -class FunctorEquality_Scalar : public FunctorType +class FunctorEquality_PerVertexWeight_Scalar : public FunctorType +{ +protected: + LinearSolver* solver ; + const AttributeHandler& indexTable ; + const AttributeHandler& attrTable ; + const AttributeHandler& weightTable ; + +public: + FunctorEquality_PerVertexWeight_Scalar( + LinearSolver* s, + const AttributeHandler& index, + const AttributeHandler& attr, + const AttributeHandler& weight + ) : solver(s), indexTable(index), attrTable(attr), weightTable(weight) + {} + + bool operator()(Dart d) + { + solver->begin_row() ; + solver->add_coefficient(indexTable[d], 1) ; + solver->set_right_hand_side(attrTable[d]) ; + solver->normalize_row(weightTable[d]) ; + solver->end_row() ; + return false ; + } +} ; + +template +class FunctorEquality_UniformWeight_Scalar : public FunctorType { protected: LinearSolver* solver ; @@ -45,7 +74,7 @@ protected: float weight ; public: - FunctorEquality_Scalar( + FunctorEquality_UniformWeight_Scalar( LinearSolver* s, const AttributeHandler& index, const AttributeHandler& attr, @@ -69,7 +98,38 @@ public: *******************************************************************************/ template -class FunctorEquality_Vector : public FunctorType +class FunctorEquality_PerVertexWeight_Vector : public FunctorType +{ +protected: + LinearSolver* solver ; + const AttributeHandler& indexTable ; + const AttributeHandler& attrTable ; + const AttributeHandler& weightTable ; + unsigned int coord ; + +public: + FunctorEquality_PerVertexWeight_Vector( + LinearSolver* s, + const AttributeHandler& index, + const AttributeHandler& attr, + const AttributeHandler& weight, + unsigned int c + ) : solver(s), indexTable(index), attrTable(attr), weightTable(weight), coord(c) + {} + + bool operator()(Dart d) + { + solver->begin_row() ; + solver->add_coefficient(indexTable[d], 1) ; + solver->set_right_hand_side((attrTable[d])[coord]) ; + solver->normalize_row(weightTable[d]) ; + solver->end_row() ; + return false ; + } +} ; + +template +class FunctorEquality_UniformWeight_Vector : public FunctorType { protected: LinearSolver* solver ; @@ -79,7 +139,7 @@ protected: unsigned int coord ; public: - FunctorEquality_Vector( + FunctorEquality_UniformWeight_Vector( LinearSolver* s, const AttributeHandler& index, const AttributeHandler& attr, diff --git a/include/Utils/pointSprite.h b/include/Utils/pointSprite.h index f3e44e6e..150eb653 100644 --- a/include/Utils/pointSprite.h +++ b/include/Utils/pointSprite.h @@ -60,6 +60,7 @@ protected: GLuint m_uniform_size; GLuint m_uniform_color; + public: /** * init shaders, texture and variables diff --git a/include/Utils/qtSimple.h b/include/Utils/qtSimple.h index 3427a511..bbf761c8 100644 --- a/include/Utils/qtSimple.h +++ b/include/Utils/qtSimple.h @@ -80,7 +80,7 @@ public: * @param signal use macro SIGNAL(qt_signal) * @param method use macro SLOT(name_of_method(params)) */ - void setCallBack( const QObject* sender, const char* signal, const char* method); + void setCallBack(const QObject* sender, const char* signal, const char* method); /** * set window Title @@ -147,11 +147,11 @@ public: void setGLWidgetMouseTracking(bool b); protected: - GLWidget *m_glWidget; + GLWidget* m_glWidget; - QDockWidget *m_dock; + QDockWidget* m_dock; - QDockWidget *m_dockConsole; + QDockWidget* m_dockConsole; QTextEdit* m_textConsole; @@ -219,7 +219,7 @@ public: * @param pixel_width width on pixel on screen * @param center reference point on world to use (defaut 0,0,0) */ - float getWidthInWorld(unsigned int pixel_width, const Geom::Vec3f& center=Geom::Vec3f(0.0f,0.0f,0.0f)); + float getWidthInWorld(unsigned int pixel_width, const Geom::Vec3f& center = Geom::Vec3f(0.0f,0.0f,0.0f)); const glm::mat4& transfoMatrix() const { return m_transfo_matrix; } glm::mat4& transfoMatrix() { return m_transfo_matrix; } diff --git a/include/Utils/qtgl.h b/include/Utils/qtgl.h index 6bdf3f22..332d0a60 100644 --- a/include/Utils/qtgl.h +++ b/include/Utils/qtgl.h @@ -88,6 +88,8 @@ protected: int m_state_modifier; + bool allow_rotation; + /** * met a jour la matrice modelview */ @@ -102,6 +104,8 @@ protected: public: void setParamObject(float width, float* pos); + void setRotation(bool b); + void initializeGL(); void paintGL(); diff --git a/src/Utils/qtSimple.cpp b/src/Utils/qtSimple.cpp index f945dfd5..c7892aee 100644 --- a/src/Utils/qtSimple.cpp +++ b/src/Utils/qtSimple.cpp @@ -41,10 +41,10 @@ namespace QT { SimpleQT::SimpleQT() : - m_dock(NULL), - m_projection_matrix(m_mat.m_matrices[0]), - m_modelView_matrix(m_mat.m_matrices[1]), - m_transfo_matrix(m_mat.m_matrices[2]) + m_dock(NULL), + m_projection_matrix(m_mat.m_matrices[0]), + m_modelView_matrix(m_mat.m_matrices[1]), + m_transfo_matrix(m_mat.m_matrices[2]) { m_glWidget = new GLWidget(this); setCentralWidget(m_glWidget); @@ -56,17 +56,17 @@ SimpleQT::SimpleQT() : connect(action, SIGNAL(triggered()), this, SLOT(cb_New())); m_fileMenu->addAction(action); - action= new QAction(tr("Open"), this); + action = new QAction(tr("Open"), this); connect(action, SIGNAL(triggered()), this, SLOT(cb_Open())); m_fileMenu->addAction(action); - action= new QAction(tr("Save"), this); + action = new QAction(tr("Save"), this); connect(action, SIGNAL(triggered()), this, SLOT(cb_Save())); m_fileMenu->addAction(action); m_fileMenu->addSeparator(); - action= new QAction(tr("Quit"), this); + action = new QAction(tr("Quit"), this); connect(action, SIGNAL(triggered()), this, SLOT(cb_Quit())); m_fileMenu->addAction(action); @@ -74,25 +74,25 @@ SimpleQT::SimpleQT() : QMenu* m_helpMenu = menuBar()->addMenu(tr("&Help")); - action= new QAction(tr("console on/off"), this); + action = new QAction(tr("console on/off"), this); connect(action, SIGNAL(triggered()), this, SLOT(cb_consoleOnOff())); m_helpMenu->addAction(action); - action= new QAction(tr("console clear"), this); + action = new QAction(tr("console clear"), this); connect(action, SIGNAL(triggered()), this, SLOT(cb_consoleClear())); m_helpMenu->addAction(action); - action= new QAction(tr("About"), this); + action = new QAction(tr("About"), this); connect(action, SIGNAL(triggered()), this, SLOT(cb_about())); m_helpMenu->addAction(action); - action= new QAction(tr("About CGoGN"), this); + action = new QAction(tr("About CGoGN"), this); connect(action, SIGNAL(triggered()), this, SLOT(cb_about_cgogn())); m_helpMenu->addAction(action); m_dockConsole = new QDockWidget(tr("Console"), this); m_dockConsole->setAllowedAreas(Qt::BottomDockWidgetArea); - m_dockConsole->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetClosable); + m_dockConsole->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetClosable); addDockWidget(Qt::BottomDockWidgetArea, m_dockConsole); m_textConsole = new QTextEdit(); @@ -108,11 +108,11 @@ SimpleQT::SimpleQT() : } SimpleQT::SimpleQT(const SimpleQT& sqt): - m_dock(NULL), - m_mat(m_mat), - m_projection_matrix(m_mat.m_matrices[0]), - m_modelView_matrix(m_mat.m_matrices[1]), - m_transfo_matrix(m_mat.m_matrices[2]) + m_dock(NULL), + m_mat(m_mat), + m_projection_matrix(m_mat.m_matrices[0]), + m_modelView_matrix(m_mat.m_matrices[1]), + m_transfo_matrix(m_mat.m_matrices[2]) { m_glWidget = new GLWidget(this); setCentralWidget(m_glWidget); @@ -383,11 +383,6 @@ float SimpleQT::getWidthInWorld(unsigned int pixel_width, const Geom::Vec3f& cen return glm::distance(P,Q); } - - - - - void SimpleQT::synchronize(SimpleQT* sqt) { m_glWidget->getObjPos() = sqt->m_glWidget->getObjPos() ; @@ -454,7 +449,7 @@ void SimpleQT::updateGL() void SimpleQT::updateGLMatrices() { m_glWidget->modelModified(); - m_glWidget->updateGL(); +// m_glWidget->updateGL(); } void SimpleQT::transfoRotate(float angle, float x, float y, float z) diff --git a/src/Utils/qtgl.cpp b/src/Utils/qtgl.cpp index 067c1e48..266f0b32 100644 --- a/src/Utils/qtgl.cpp +++ b/src/Utils/qtgl.cpp @@ -40,14 +40,13 @@ namespace Utils namespace QT { - -float GLWidget::FAR_PLANE=500.0f; - +float GLWidget::FAR_PLANE = 500.0f; GLWidget::GLWidget(SimpleQT* cbs, QWidget *parent) : QGLWidget(QGLFormat(QGL::Rgba | QGL::DoubleBuffer| QGL::DepthBuffer), parent), m_cbs(cbs), - m_state_modifier(0) + m_state_modifier(0), + allow_rotation(true) { makeCurrent(); glewInit(); @@ -73,6 +72,11 @@ void GLWidget::setParamObject(float width, float* pos) m_obj_pos = glm::vec3(-pos[0], -pos[1], -pos[2]); } +void GLWidget::setRotation(bool b) +{ + allow_rotation = b; +} + void GLWidget::setFocal(float df) { if (df > 5.0f) @@ -106,7 +110,7 @@ void GLWidget::recalcModelView() // tourne l'objet / mvt souris glm::mat4 m; build_rotmatrixgl3(m, m_cbs->curquat()); -// // update matrice + // update matrice m_cbs->modelViewMatrix() *= m; // transfo pour que l'objet soit centre et a la bonne taille @@ -197,7 +201,6 @@ void GLWidget::paintGL() Utils::GLSLShader::s_current_matrices = m_cbs->matricesPtr(); m_cbs->cb_redraw(); } - } void GLWidget::mousePressEvent(QMouseEvent* event) @@ -276,13 +279,16 @@ void GLWidget::mouseMoveEvent(QMouseEvent* event) break; case Qt::LeftButton: { - trackball( - m_cbs->lastquat(), - (2.0f * beginx - W) / W, - (H - 2.0f * beginy) / H, - (2.0f * x - W) / W,(H - 2.0f * y) / H - ); - add_quats(m_cbs->lastquat(), m_cbs->curquat(), m_cbs->curquat()); + if(allow_rotation) + { + trackball( + m_cbs->lastquat(), + (2.0f * beginx - W) / W, + (H - 2.0f * beginy) / H, + (2.0f * x - W) / W,(H - 2.0f * y) / H + ); + add_quats(m_cbs->lastquat(), m_cbs->curquat(), m_cbs->curquat()); + } } break; } @@ -324,19 +330,16 @@ void GLWidget::closeEvent(QCloseEvent *event) void GLWidget::keyPressEvent(QKeyEvent* event) { - if (event->key() == Qt::Key_Escape) - close(); -// else -// QWidget::keyPressEvent(event); + close(); - m_state_modifier = event->modifiers(); + m_state_modifier = event->modifiers(); - int k = event->key(); - if ( (k >= 65) && (k <= 91) && !(event->modifiers() & Qt::ShiftModifier) ) - k += 32; + int k = event->key(); +// if ( (k >= 65) && (k <= 91) && !(event->modifiers() & Qt::ShiftModifier) ) +// k += 32; - if (m_cbs) + if (m_cbs) m_cbs->cb_keyPress(k); } @@ -372,7 +375,6 @@ void GLWidget::keyReleaseEvent(QKeyEvent *event) updateGL(); } - if ( (k >= 65) && (k <= 91) && (event->modifiers() != Qt::ShiftModifier) ) k += 32; @@ -395,7 +397,6 @@ void GLWidget::oglScale(float sx, float sy, float sz) m_cbs->modelViewMatrix() = glm::scale(m_cbs->modelViewMatrix(), glm::vec3(sx,sy,sz)); } - } // namespace QT } // namespace Utils -- GitLab