From e74ca6730cc3840fd7aa438229ede090eb4b41d5 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Tue, 31 May 2011 17:29:14 +0200 Subject: [PATCH] ajout exemple viewer --- Apps/CMakeLists.txt | 3 +- Apps/Examples/Debug/CMakeLists.txt | 53 +----- Apps/Examples/Release/CMakeLists.txt | 43 +---- Apps/Examples/viewer.cpp | 273 +++++++++++++++++++++++++++ Apps/Examples/viewer.h | 127 +++++++++++++ Apps/Examples/viewer.ui | 161 ++++++++++++++++ 6 files changed, 579 insertions(+), 81 deletions(-) create mode 100644 Apps/Examples/viewer.cpp create mode 100644 Apps/Examples/viewer.h create mode 100644 Apps/Examples/viewer.ui diff --git a/Apps/CMakeLists.txt b/Apps/CMakeLists.txt index 935f7562e..f9294f9d8 100644 --- a/Apps/CMakeLists.txt +++ b/Apps/CMakeLists.txt @@ -9,11 +9,10 @@ IF(WIN32) add_subdirectory(Examples/Release) add_subdirectory(Tuto) ELSE(WIN32) - SET(CGoGN_LIBS_D topologyD algoD containerD utilsD) + SET(CGoGN_LIBS_D topologyD algoD containerD utilsD) add_subdirectory(Examples/Release) add_subdirectory(Examples/Debug) add_subdirectory(Examples/Tests) add_subdirectory(Tuto) ENDIF(WIN32) - diff --git a/Apps/Examples/Debug/CMakeLists.txt b/Apps/Examples/Debug/CMakeLists.txt index 89f32fe6e..caae2f523 100644 --- a/Apps/Examples/Debug/CMakeLists.txt +++ b/Apps/Examples/Debug/CMakeLists.txt @@ -10,10 +10,9 @@ SET(QT_USE_QTOPENGL TRUE) INCLUDE(${QT_USE_FILE}) ADD_DEFINITIONS(${QT_DEFINITIONS}) - - # define includes path include_directories( + ${CMAKE_CURRENT_BINARY_DIR} /usr/include/libxml2/ ${CGoGN_ROOT_DIR}/include ${CGoGN_ROOT_DIR}/ThirdParty/Numerical @@ -34,51 +33,19 @@ link_directories( #define exec to compile -#add_executable( miniTestD ../miniTest.cpp) -#target_link_libraries( miniTestD -# containerD topologyD utilsD algoD numerical lapack blas f2c ${COMMON_LIBS} ) - -#add_executable( ViewerD ../Viewer.cpp) -#target_link_libraries( ViewerD -# containerD topologyD utilsD algoD ${COMMON_LIBS} ) - -#add_executable( simpleGMap2D ../simpleGMap2.cpp) -#target_link_libraries( simpleGMap2D -# containerD topologyD utilsD algoD ${COMMON_LIBS} Zinri) - -#add_executable( SimpleEMap3D ../simpleEMap3.cpp) -#target_link_libraries( SimpleEMap3D -# containerD topologyD utilsD algoD ${COMMON_LIBS} ) - -#add_executable( triangulationD ../triangulation.cpp) -#target_link_libraries( triangulationD -# containerD topologyD utilsD algoD ${COMMON_LIBS} ) - -#add_executable( decimationVolumiqueD ../decimationVolumique.cpp) -#target_link_libraries( decimationVolumiqueD -# containerD topologyD utilsD algoD numerical lapack blas f2c ${COMMON_LIBS} ) - -#add_executable( ter_meshesD ../ter_meshes.cpp) -#target_link_libraries( ter_meshesD -# containerD topologyD utilsD algoD ${COMMON_LIBS} ) - QT4_WRAP_CPP(polyhedronsView_moc ../polyhedronsView.h) add_executable( polyhedronsViewD ../polyhedronsView.cpp ${polyhedronsView_moc}) target_link_libraries( polyhedronsViewD - ${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} ) + ${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} ) QT4_WRAP_CPP(extrusionView_moc ../extrusionView.h) add_executable( extrusionViewD ../extrusionView.cpp ${extrusionView_moc}) target_link_libraries( extrusionViewD - ${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} ) - - -#add_executable( sceneD ../scene.cpp) -#target_link_libraries( sceneD -# containerD topologyD utilsD algoD ${COMMON_LIBS} ) - - -#add_executable( VizVolumeD ../VizVolume.cpp) -#target_link_libraries( VizVolumeD -# containerD topologyD utilsD algoD ${COMMON_LIBS} Zinri) - + ${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} ) + +QT4_WRAP_UI( viewer_ui ../viewer.ui ) +QT4_WRAP_CPP( viewer_moc ../viewer.h ) +add_executable( viewerD ../viewer.cpp ${viewer_moc} ${viewer_ui}) +target_link_libraries( viewerD + ${CGoGN_LIBS_D} ${NUMERICAL_LIBS} ${COMMON_LIBS} ${QT_LIBRARIES} ) + diff --git a/Apps/Examples/Release/CMakeLists.txt b/Apps/Examples/Release/CMakeLists.txt index 0350d6a2b..c5859e785 100644 --- a/Apps/Examples/Release/CMakeLists.txt +++ b/Apps/Examples/Release/CMakeLists.txt @@ -37,38 +37,6 @@ ENDIF(WIN32) #define exec to compile -#add_executable( miniTest ../miniTest.cpp) -#target_link_libraries( miniTest -# container topology utils algo numerical lapack blas f2c ${COMMON_LIBS} ) - -#add_executable( Viewer ../Viewer.cpp) -#target_link_libraries( Viewer -# container topology utils algo ${COMMON_LIBS} ) - -#add_executable( simpleGMap2 ../simpleGMap2.cpp) -#target_link_libraries( simpleGMap2 -# container topology utils algo ${COMMON_LIBS} Zinri) - -# add_executable( hm_convexhull ../hm_convexhull.cpp) -# target_link_libraries( hm_convexhull -# topology utils algo ${COMMON_LIBS}) - -#add_executable( squelette3carte ../squelette3carte.cpp) -#target_link_libraries( squelette3carte -# container topology utils algo numerical lapack blas f2c ${COMMON_LIBS} ) - -#add_executable( decimationVolumique ../decimationVolumique.cpp) -#target_link_libraries( decimationVolumique -# container topology utils algo numerical lapack blas f2c ${COMMON_LIBS} ) - -#add_executable( triangulation ../triangulation.cpp) -#target_link_libraries( triangulation -# container topology utils algo ${COMMON_LIBS} ) - -#add_executable( ter_meshes ../ter_meshes.cpp) -#target_link_libraries( ter_meshes -# container topology utils algo ${COMMON_LIBS} ) - QT4_WRAP_CPP(polyhedronsView_moc ../polyhedronsView.h) add_executable( polyhedronsView ../polyhedronsView.cpp ${polyhedronsView_moc}) target_link_libraries( polyhedronsView @@ -78,7 +46,10 @@ QT4_WRAP_CPP(extrusionView_moc ../extrusionView.h) add_executable( extrusionView ../extrusionView.cpp ${extrusionView_moc}) target_link_libraries( extrusionView ${CGoGN_LIBS_R} ${COMMON_LIBS} ${QT_LIBRARIES} ) - -#add_executable( scene ../scene.cpp) -#target_link_libraries( scene -# container topology utils algo ${COMMON_LIBS} ) + +QT4_WRAP_UI( viewer_ui ../viewer.ui ) +QT4_WRAP_CPP( viewer_moc ../viewer.h ) +add_executable( viewer ../viewer.cpp ${viewer_moc} ${viewer_ui}) +target_link_libraries( viewer + ${CGoGN_LIBS_R} ${NUMERICAL_LIBS} ${COMMON_LIBS} ${QT_LIBRARIES} ) + diff --git a/Apps/Examples/viewer.cpp b/Apps/Examples/viewer.cpp new file mode 100644 index 000000000..59adbdd75 --- /dev/null +++ b/Apps/Examples/viewer.cpp @@ -0,0 +1,273 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: https://iggservis.u-strasbg.fr/CGoGN/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#include "viewer.h" + +Viewer::Viewer() : + m_renderStyle(FLAT), + m_drawVertices(false), + m_drawEdges(false), + m_drawFaces(true), + m_drawNormals(false), + m_render(NULL), + m_phongShader(NULL), + m_flatShader(NULL), + m_vectorShader(NULL), + m_simpleColorShader(NULL), + m_pointSprite(NULL) +{ + normalScaleFactor = 1.0f ; + vertexScaleFactor = 1.0f ; + faceShrinkage = 1.0f ; + + colClear = Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f) ; + colDif = Geom::Vec4f(0.8f, 0.9f, 0.7f, 1.0f) ; + colSpec = Geom::Vec4f(0.9f, 0.9f, 0.9f, 1.0f) ; + colNormal = Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f) ; + shininess = 80.0f ; +} + +void Viewer::initGUI() +{ + setDock(&dock) ; + + dock.check_drawVertices->setChecked(false) ; + dock.check_drawEdges->setChecked(false) ; + dock.check_drawFaces->setChecked(true) ; + dock.check_drawNormals->setChecked(false) ; + + dock.slider_verticesSize->setVisible(false) ; + dock.slider_normalsSize->setVisible(false) ; + + dock.slider_verticesSize->setSliderPosition(50) ; + dock.slider_normalsSize->setSliderPosition(50) ; + + setCallBack( dock.check_drawVertices, SIGNAL(toggled(bool)), SLOT(slot_drawVertices(bool)) ) ; + setCallBack( dock.slider_verticesSize, SIGNAL(valueChanged(int)), SLOT(slot_verticesSize(int)) ) ; + 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_drawNormals, SIGNAL(toggled(bool)), SLOT(slot_drawNormals(bool)) ) ; + setCallBack( dock.slider_normalsSize, SIGNAL(valueChanged(int)), SLOT(slot_normalsSize(int)) ) ; +} + +void Viewer::cb_initGL() +{ + Utils::GLSLShader::setCurrentOGLVersion(2) ; + + setFocal(5.0f) ; + + m_render = new Algo::Render::GL2::MapRender() ; + + m_positionVBO = new Utils::VBO() ; + m_normalVBO = new Utils::VBO() ; + + m_phongShader = new Utils::ShaderPhong() ; + m_phongShader->setAttributePosition(m_positionVBO) ; + m_phongShader->setAttributeNormal(m_normalVBO) ; + m_phongShader->setAmbiant(colClear) ; + m_phongShader->setDiffuse(colDif) ; + m_phongShader->setSpecular(colSpec) ; + m_phongShader->setShininess(shininess) ; + + m_flatShader = new Utils::ShaderFlat() ; + m_flatShader->setAttributePosition(m_positionVBO) ; + m_flatShader->setAmbiant(colClear) ; + m_flatShader->setDiffuse(colDif) ; + m_flatShader->setExplode(faceShrinkage) ; + + m_vectorShader = new Utils::ShaderVectorPerVertex() ; + m_vectorShader->setAttributePosition(m_positionVBO) ; + m_vectorShader->setAttributeVector(m_normalVBO) ; + m_vectorShader->setColor(colNormal) ; + + m_simpleColorShader = new Utils::ShaderSimpleColor() ; + m_simpleColorShader->setAttributePosition(m_positionVBO) ; + Geom::Vec4f c(0.1f, 0.1f, 0.1f, 1.0f) ; + m_simpleColorShader->setColor(c) ; + + m_pointSprite = new Utils::PointSprite() ; + m_pointSprite->setAttributePosition(m_positionVBO) ; + + registerShader(m_phongShader) ; + registerShader(m_flatShader) ; + registerShader(m_vectorShader) ; + registerShader(m_simpleColorShader) ; + registerShader(m_pointSprite) ; +} + +void Viewer::cb_redraw() +{ + if(m_drawVertices) + { + float size = vertexBaseSize * vertexScaleFactor ; + m_pointSprite->setSize(size) ; + m_pointSprite->predraw(Geom::Vec3f(0.0f, 0.0f, 1.0f)) ; + m_render->draw(m_pointSprite, Algo::Render::GL2::POINTS) ; + m_pointSprite->postdraw() ; + } + + if(m_drawEdges) + { + glLineWidth(1.0f) ; + 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) ; + glEnable(GL_LIGHTING) ; + glEnable(GL_POLYGON_OFFSET_FILL) ; + glPolygonOffset(1.0f, 1.0f) ; + switch(m_renderStyle) + { + case FLAT : + m_flatShader->setExplode(faceShrinkage) ; + m_render->draw(m_flatShader, Algo::Render::GL2::TRIANGLES) ; + break ; + case PHONG : + m_render->draw(m_phongShader, Algo::Render::GL2::TRIANGLES) ; + break ; + } + glDisable(GL_POLYGON_OFFSET_FILL) ; + } +} + +void Viewer::cb_Open() +{ + std::string filters("all (*.*);; trian (*.trian);; ctm (*.ctm);; off (*.off);; ply (*.ply)") ; + std::string filename = selectFile("Open Mesh", "", filters) ; + + importMesh(filename) ; + updateGL() ; +} + +void Viewer::importMesh(std::string& filename) +{ + std::vector attrNames ; + if(!Algo::Import::importMesh(myMap, filename.c_str(), attrNames)) + { + CGoGNerr << "could not import " << filename << CGoGNendl ; + return; + } + position = myMap.getAttribute(VERTEX_ORBIT, attrNames[0]) ; + + m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::POINTS) ; + m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::LINES) ; + m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::TRIANGLES) ; + + Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position) ; + gPosObj = bb.center() ; + float tailleX = bb.size(0) ; + float tailleY = bb.size(1) ; + float tailleZ = bb.size(2) ; + gWidthObj = std::max(std::max(tailleX, tailleY), tailleZ) ; + normalBaseSize = std::min(std::min(tailleX,tailleY),tailleZ) / 50.0f ; + vertexBaseSize = normalBaseSize * 2.0f ; + + if(!normal.isValid()) + normal = myMap.addAttribute(VERTEX_ORBIT, "normal") ; + + Algo::Geometry::computeNormalVertices(myMap, position, normal) ; + + m_positionVBO->updateData(position) ; + m_normalVBO->updateData(normal) ; + + setParamObject(gWidthObj, gPosObj.data()) ; + updateGLMatrices() ; +} + +void Viewer::slot_drawVertices(bool b) +{ + m_drawVertices = b ; + updateGL() ; +} + +void Viewer::slot_verticesSize(int i) +{ + vertexScaleFactor = i / 50.0f ; + updateGL() ; +} + +void Viewer::slot_drawEdges(bool b) +{ + m_drawEdges = b ; + updateGL() ; +} + +void Viewer::slot_drawFaces(bool b) +{ + m_drawFaces = b ; + updateGL() ; +} + +void Viewer::slot_faceLighting(int i) +{ + m_renderStyle = i ; + updateGL() ; +} + +void Viewer::slot_drawNormals(bool b) +{ + m_drawNormals = b ; + updateGL() ; +} + +void Viewer::slot_normalsSize(int i) +{ + normalScaleFactor = i / 50.0f ; + updateGL() ; +} + +/********************************************************************************************** + * MAIN FUNCTION * + **********************************************************************************************/ + +int main(int argc, char **argv) +{ + QApplication app(argc, argv) ; + + Viewer sqt ; + sqt.setGeometry(0, 0, 1000, 800) ; + sqt.show() ; + + if(argc == 2) + { + std::string filename(argv[1]) ; + sqt.importMesh(filename) ; + } + + sqt.initGUI() ; + + return app.exec() ; +} + diff --git a/Apps/Examples/viewer.h b/Apps/Examples/viewer.h new file mode 100644 index 000000000..f77b44de9 --- /dev/null +++ b/Apps/Examples/viewer.h @@ -0,0 +1,127 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: https://iggservis.u-strasbg.fr/CGoGN/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#include + +#include "Utils/qtSimple.h" +#include "ui_viewer.h" +#include "Utils/qtui.h" + +#include "Topology/generic/parameters.h" +#include "Topology/map/map2.h" +#include "Topology/generic/embeddedMap2.h" + +#include "Geometry/vector_gen.h" +#include "Geometry/matrix.h" + +#include "Algo/Import/import.h" + +#include "Algo/Render/GL2/mapRender.h" + +#include "Utils/shaderPhong.h" +#include "Utils/shaderFlat.h" +#include "Utils/shaderSimpleColor.h" +#include "Utils/shaderVectorPerVertex.h" +#include "Utils/pointSprite.h" + +#include "Algo/Geometry/boundingbox.h" +#include "Algo/Geometry/normal.h" + +using namespace CGoGN ; + +struct PFP: public PFP_STANDARD +{ + // definition of the map + typedef EmbeddedMap2 MAP ; +}; + +typedef PFP::MAP MAP ; + +class Viewer : public Utils::QT::SimpleQT +{ + Q_OBJECT + +public: + MAP myMap ; + SelectorTrue allDarts ; + + Utils::QT::uiDockInterface dock ; + + enum renderMode { FLAT, PHONG } ; + + Geom::Vec4f colDif ; + Geom::Vec4f colSpec ; + Geom::Vec4f colClear ; + Geom::Vec4f colNormal ; + + float shininess ; + + Geom::Vec3f gPosObj ; + float gWidthObj ; + float normalBaseSize ; + float normalScaleFactor ; + float vertexBaseSize ; + float vertexScaleFactor ; + float faceShrinkage ; + + int m_renderStyle ; + bool m_drawVertices ; + bool m_drawEdges ; + bool m_drawFaces ; + bool m_drawNormals ; + + PFP::TVEC3 position ; + PFP::TVEC3 normal ; + + Algo::Render::GL2::MapRender* m_render ; + + Utils::VBO* m_positionVBO ; + Utils::VBO* m_normalVBO ; + + Utils::ShaderPhong* m_phongShader ; + Utils::ShaderFlat* m_flatShader ; + Utils::ShaderVectorPerVertex* m_vectorShader ; + Utils::ShaderSimpleColor* m_simpleColorShader ; + Utils::PointSprite* m_pointSprite ; + + Viewer() ; + + void initGUI() ; + + void cb_initGL() ; + void cb_redraw() ; + void cb_Open() ; + + void importMesh(std::string& filename) ; + +public slots: + void slot_drawVertices(bool b) ; + void slot_verticesSize(int i) ; + void slot_drawEdges(bool b) ; + void slot_drawFaces(bool b) ; + void slot_faceLighting(int i) ; + void slot_drawNormals(bool b) ; + void slot_normalsSize(int i) ; +}; + diff --git a/Apps/Examples/viewer.ui b/Apps/Examples/viewer.ui new file mode 100644 index 000000000..10bf2795b --- /dev/null +++ b/Apps/Examples/viewer.ui @@ -0,0 +1,161 @@ + + + DockWidget + + + + 0 + 0 + 174 + 393 + + + + + 174 + 393 + + + + Commands + + + + + + + 0 + + + + Visu + + + + + + draw vertices + + + + + + + Qt::Horizontal + + + + + + + draw edges + + + + + + + draw faces + + + + + + + + FLAT + + + + + PHONG + + + + + + + + draw normals + + + + + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + check_drawFaces + toggled(bool) + combo_faceLighting + setVisible(bool) + + + 65 + 98 + + + 65 + 127 + + + + + check_drawNormals + toggled(bool) + slider_normalsSize + setVisible(bool) + + + 75 + 191 + + + 75 + 222 + + + + + check_drawVertices + toggled(bool) + slider_verticesSize + setVisible(bool) + + + 75 + 44 + + + 75 + 75 + + + + + -- GitLab