diff --git a/Apps/Examples/frame_manip.cpp b/Apps/Examples/frame_manip.cpp index 27b6b0581c5d3c936e53524e697d1ef22dabf22b..de9131630625b3d96f727bdaeef591ab51d52fb5 100644 --- a/Apps/Examples/frame_manip.cpp +++ b/Apps/Examples/frame_manip.cpp @@ -134,9 +134,9 @@ void MyQT::cb_redraw() for (std::vector::iterator it=m_pickables.begin(); it != m_pickables.end(); ++it) { if (*it == m_lastPickedObject) - glLineWidth(2.0); + (*it)->setLineWidth(3.0); else - glLineWidth(1.0); + (*it)->setLineWidth(1.0); (*it)->draw(); } diff --git a/Apps/Examples/mcmesh.cpp b/Apps/Examples/mcmesh.cpp index 566d7f9a1173a457f86006849749037354b46352..937138eab575be6799c1a56994cd6a6d81aa5de0 100644 --- a/Apps/Examples/mcmesh.cpp +++ b/Apps/Examples/mcmesh.cpp @@ -29,7 +29,8 @@ MCMesh::MCMesh() : m_drawFaces(true), m_render(NULL), m_flatShader(NULL), - m_simpleColorShader(NULL) + m_simpleColorShader(NULL), + m_linesShader(NULL) {} void MCMesh::initGUI() @@ -58,31 +59,67 @@ void MCMesh::cb_initGL() m_flatShader->setDiffuse(colDif); m_flatShader->setExplode(1.0f); - m_simpleColorShader = new Utils::ShaderSimpleColor(); - m_simpleColorShader->setAttributePosition(m_positionVBO); + //m_simpleColorShader = new Utils::ShaderSimpleColor(); + //m_simpleColorShader->setAttributePosition(m_positionVBO); + + m_linesShader = new Utils::ShaderBoldLines(); + m_linesShader->setAttributePosition(m_positionVBO); registerShader(m_flatShader); - registerShader(m_simpleColorShader); +// registerShader(m_simpleColorShader); + registerShader(m_linesShader); + + m_dr = new Utils::Drawer(); + m_dr->newList(); + m_dr->pointSize(4.0f); + m_dr->lineWidth(25.0f); + m_dr->begin(GL_LINES); + m_dr->color3f(1.0,0.0,0.0); + m_dr->vertex3f(15.0,15.0,65.0); + m_dr->vertex3f(110.0,110.0,65.0); + m_dr->color3f(0.0,1.0,0.0); + m_dr->vertex3f(110.0,15.0,75.0); + m_dr->vertex3f(15.0,110.0,75.0); + m_dr->end(); + m_dr->endList(); + } void MCMesh::cb_redraw() { +glEnable(GL_BLEND); + m_dr->callList(0.1f); if (m_drawEdges) +// { +// glLineWidth(1.0f); +// if (m_drawFaces) +// { +// Geom::Vec4f c(0.0f, 0.0f, 0.0f, 0.0f); +// m_simpleColorShader->setColor(c); +// } +// else +// { +// Geom::Vec4f c(1.0f, 1.0f, 0.0f, 0.0f); +// m_simpleColorShader->setColor(c); +// } +// m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES); +// } { - glLineWidth(1.0f); + m_linesShader->setLineWidth(2.0f); if (m_drawFaces) { Geom::Vec4f c(0.0f, 0.0f, 0.0f, 0.0f); - m_simpleColorShader->setColor(c); + m_linesShader->setColor(c); } else { Geom::Vec4f c(1.0f, 1.0f, 0.0f, 0.0f); - m_simpleColorShader->setColor(c); + m_linesShader->setColor(c); } - m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES); + m_render->draw(m_linesShader, Algo::Render::GL2::LINES); } + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glEnable(GL_LIGHTING); glEnable(GL_POLYGON_OFFSET_FILL); diff --git a/Apps/Examples/mcmesh.h b/Apps/Examples/mcmesh.h index 848eba69fb8adc849a2485c3d47ca21dd9db1865..7f0caaddca26021ebafaf7403105c6f9302c3a11 100644 --- a/Apps/Examples/mcmesh.h +++ b/Apps/Examples/mcmesh.h @@ -39,9 +39,11 @@ #include "Algo/Render/GL2/mapRender.h" #include "Utils/Shaders/shaderFlat.h" #include "Utils/Shaders/shaderSimpleColor.h" +#include "Utils/Shaders/shaderBoldLines.h" #include "Utils/vbo.h" #include "Algo/Geometry/boundingbox.h" +#include "Utils/drawer.h" using namespace CGoGN ; @@ -79,9 +81,14 @@ public: Algo::Render::GL2::MapRender* m_render ; Utils::VBO* m_positionVBO ; + Utils::VBO* m_colorVBO ; Utils::ShaderFlat* m_flatShader ; Utils::ShaderSimpleColor* m_simpleColorShader ; + Utils::ShaderBoldLines* m_linesShader ; + + Utils::Drawer* m_dr; + DATATYPE valLabel; SAlgo::MC::Image* myImg; diff --git a/Apps/Examples/volumeExplorer.cpp b/Apps/Examples/volumeExplorer.cpp index f46843726eafe422354b3de095ae31fc5b7310ce..62434a43438c3516893d21b945133250fbadb236 100644 --- a/Apps/Examples/volumeExplorer.cpp +++ b/Apps/Examples/volumeExplorer.cpp @@ -218,6 +218,7 @@ void MyQT::cb_initGL() registerShader(m_explode_render->shaderLines()); m_PlanePick = new Utils::Pickable(Utils::Pickable::GRID,1); + m_PlanePick->drawable()->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); m_frame = new Utils::FrameManipulator(); m_frame->setSize(m_WidthObj/2.0f); @@ -254,6 +255,7 @@ void MyQT::cb_redraw() if (clip_volume && !hide_clipping) { m_frame->draw(); + m_PlanePick->setLineWidth(2.0f); m_PlanePick->draw(); } diff --git a/CGoGN/include/Algo/Modelisation/subdivision.hpp b/CGoGN/include/Algo/Modelisation/subdivision.hpp index 3b39031836a3b95a28601645b45190343b36ce00..8f4d35bbc649b6adfe36f92519ca4a3409cbeec8 100644 --- a/CGoGN/include/Algo/Modelisation/subdivision.hpp +++ b/CGoGN/include/Algo/Modelisation/subdivision.hpp @@ -442,7 +442,7 @@ void CatmullClarkInterpolSubdivision(typename PFP::MAP& map, EMBV& attributs) typedef typename PFP::MAP MAP; typedef typename EMBV::DATA_TYPE EMB; - VertexAutoAttribute facesAverage(map); + VertexAutoAttribute facesAverage(map); std::vector l_vertices; std::vector l_edges; @@ -464,14 +464,14 @@ void CatmullClarkInterpolSubdivision(typename PFP::MAP& map, EMBV& attributs) { if (!me.isMarked(d)) { - mf.markOrbit(d); + mf.template markOrbit(d); Dart f = map.phi1(d); Dart e = map.cutEdge(d); attributs[e] = (attributs[d] + attributs[f]) /2.0; me.template markOrbit(d); me.template markOrbit(e); // warning store the dart that does not belong to the boundary - if (map.isBoundaryMarked<2>(e)) + if (map.template isBoundaryMarked<2>(e)) l_edges.push_back(map.phi2(d)); else l_edges.push_back(e); @@ -522,7 +522,7 @@ void CatmullClarkInterpolSubdivision(typename PFP::MAP& map, EMBV& attributs) // compute face average of "edges" for (Dart e : l_edges) { - if (!map.isBoundaryMarked<2>(map.phi2(e))) // faster than map.isBoundaryEdge(e) + if (!map.template isBoundaryMarked<2>(map.phi2(e))) // faster than map.isBoundaryEdge(e) { Dart ff = map.phi_1(e); Dart f = map.template phi<211>(e); @@ -537,10 +537,10 @@ void CatmullClarkInterpolSubdivision(typename PFP::MAP& map, EMBV& attributs) { Dart xb = map.phi2(x); - if (map.isBoundaryMarked<2>(x)) + if (map.template isBoundaryMarked<2>(x)) std::cout << "ERROR " << attributs[x]; - if (!map.isBoundaryMarked<2>(xb)) + if (!map.template isBoundaryMarked<2>(xb)) { Dart v1 = map.phi1(x); Dart v2 = map.phi_1(map.phi2(map.phi_1(x))); @@ -860,11 +860,11 @@ void DooSabin(typename PFP::MAP& map, EMBV& position) Algo::Topo::setOrbitEmbedding(map, map.template phi<11>(nf), map.template getEmbedding(e2)); } - dm.markOrbit(nf); + dm.template markOrbit(nf); fp.push_back(map.phi1(nf)); fp.push_back(map.phi_1(nf)); } - dm.markOrbit(e); + dm.template markOrbit(e); e = map.phi1(e); } while (e!=d); } diff --git a/CGoGN/include/Container/attributeMultiVectorBool.hpp b/CGoGN/include/Container/attributeMultiVectorBool.hpp index 7a9e20e49c98318458cdbfab5c57c1ca9c32685e..9bac4e368b1f01b81fbfa73824f96cb4e7c5f482 100644 --- a/CGoGN/include/Container/attributeMultiVectorBool.hpp +++ b/CGoGN/include/Container/attributeMultiVectorBool.hpp @@ -118,7 +118,7 @@ public: // } for (unsigned int i = 0; i < atmv->m_tableData.size(); ++i) - memcpy(m_tableData[i],atmv->m_tableData[i],_BLOCKSIZE_/32); + memcpy(m_tableData[i],atmv->m_tableData[i],_BLOCKSIZE_/8); return true; } diff --git a/CGoGN/include/Container/sizeblock.h b/CGoGN/include/Container/sizeblock.h index bccf1b50659cc868e3bb7a9d3e2ac2702de74acd..176f144bdbe74bc94df9f4fe5c51c86fb8bf2e38 100644 --- a/CGoGN/include/Container/sizeblock.h +++ b/CGoGN/include/Container/sizeblock.h @@ -28,7 +28,6 @@ #include "Utils/gzstream.h" #include "Utils/cgognStream.h" -//#define _BLOCKSIZE_ 4096 const unsigned int _BLOCKSIZE_ = 4096; //typedef std::ifstream CGoGNistream; diff --git a/CGoGN/include/Utils/Shaders/shaderBoldColorLines.frag b/CGoGN/include/Utils/Shaders/shaderBoldColorLines.frag new file mode 100644 index 0000000000000000000000000000000000000000..ac06d065702a8cea02eba6b3b92517a7ded03673 --- /dev/null +++ b/CGoGN/include/Utils/Shaders/shaderBoldColorLines.frag @@ -0,0 +1,17 @@ +// ShaderBoldColorLines::fragmentShaderText + +PRECISION; + +VARYING_FRAG vec3 fragColor; +uniform float alpha; +uniform vec4 planeClip; +VARYING_FRAG vec3 fragClip; + +FRAG_OUT_DEF; + +void main() +{ + if (dot(planeClip,vec4(fragClip,1.0))>0.0) + discard; + FRAG_OUT = vec4(fragColor,alpha); +} diff --git a/CGoGN/include/Utils/Shaders/shaderBoldColorLines.geom b/CGoGN/include/Utils/Shaders/shaderBoldColorLines.geom new file mode 100644 index 0000000000000000000000000000000000000000..4e6e9cd235baa92d3aa2389c94b64ff8578b0736 --- /dev/null +++ b/CGoGN/include/Utils/Shaders/shaderBoldColorLines.geom @@ -0,0 +1,39 @@ +// ShaderBoldColorLines::geometryShaderText + +uniform vec2 lineWidth; + +VARYING_IN vec3 vcolor[]; +VARYING_OUT vec3 fragColor; + +VARYING_IN vec3 posClip[]; +VARYING_OUT vec3 fragClip; + +void main() +{ + + vec3 A = POSITION_IN(0).xyz / abs(POSITION_IN(0).w); + vec3 B = POSITION_IN(1).xyz / abs(POSITION_IN(1).w); + + vec3 U = normalize(B-A); + vec3 V = cross(U,vec3(0.0,0.0,1.0)); + + vec3 LW = vec3(lineWidth,1.0); + fragClip = posClip[0]; + fragColor = vcolor[0]; + gl_Position = vec4(A-U*LW, 1.0); + EmitVertex(); + gl_Position = vec4(A+V*LW, 1.0); + EmitVertex(); + gl_Position = vec4(A-V*LW, 1.0); + EmitVertex(); + fragColor = vcolor[1]; + fragClip = posClip[1]; + gl_Position = vec4(B+V*LW, 1.0); + EmitVertex(); + gl_Position = vec4(B-V*LW, 1.0); + EmitVertex(); + gl_Position = vec4(B+U*LW, 1.0); + EmitVertex(); + + EndPrimitive(); +} diff --git a/CGoGN/include/Utils/Shaders/shaderBoldColorLines.h b/CGoGN/include/Utils/Shaders/shaderBoldColorLines.h new file mode 100644 index 0000000000000000000000000000000000000000..4346bdea9e98008bb95040ccd209f8751e01597e --- /dev/null +++ b/CGoGN/include/Utils/Shaders/shaderBoldColorLines.h @@ -0,0 +1,91 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2012, 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: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#ifndef __CGOGN_SHADER_BOLDCOLORLINES__ +#define __CGOGN_SHADER_BOLDCOLORLINES__ + +#include "Utils/GLSLShader.h" +#include "Utils/clippingShader.h" +#include "Geometry/vector_gen.h" + +#include "Utils/dll.h" + +namespace CGoGN +{ + +namespace Utils +{ + +class CGoGN_UTILS_API ShaderBoldColorLines : public ClippingShader +{ +protected: + // shader sources + static std::string vertexShaderText; + static std::string geometryShaderText; + static std::string fragmentShaderText; + + CGoGNGLuint m_uniform_lineWidth; + CGoGNGLuint m_unif_alpha; + + Geom::Vec2f m_lineWidth; + float m_pixWidth; + + VBO* m_vboPos; + VBO* m_vboCol; + + float m_opacity; + + /// clipping + CGoGNGLuint m_unif_planeClip; + Geom::Vec4f m_planeClip; + + void getLocations(); + + void sendParams(); + + void restoreUniformsAttribs(); + +public: + ShaderBoldColorLines(); + + void setLineWidth(float pix); + + void updatePixelWidth(); + + void setOpacity(float op); + + unsigned int setAttributeColor(VBO* vbo); + + unsigned int setAttributePosition(VBO* vbo); + + void setClippingPlane(const Geom::Vec4f& plane); + inline void setNoClippingPlane() { setClippingPlane(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); } + +}; + +} // namespace Utils + +} // namespace CGoGN + +#endif diff --git a/CGoGN/include/Utils/Shaders/shaderBoldColorLines.vert b/CGoGN/include/Utils/Shaders/shaderBoldColorLines.vert new file mode 100644 index 0000000000000000000000000000000000000000..457a100dc1c16d9075cac7f7430938f0827d41e4 --- /dev/null +++ b/CGoGN/include/Utils/Shaders/shaderBoldColorLines.vert @@ -0,0 +1,15 @@ +// ShaderBoldColorLines::vertexShaderText + +ATTRIBUTE vec3 VertexPosition; +ATTRIBUTE vec3 VertexColor; +uniform mat4 ModelViewProjectionMatrix; +VARYING_VERT vec3 vcolor; +VARYING_VERT vec3 posClip; + +INVARIANT_POS; +void main () +{ + posClip = VertexPosition; + vcolor = VertexColor; + gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0); +} diff --git a/CGoGN/include/Utils/Shaders/shaderBoldLines.frag b/CGoGN/include/Utils/Shaders/shaderBoldLines.frag new file mode 100644 index 0000000000000000000000000000000000000000..426330dbe903461a7da84d3ae8d0a700333b1482 --- /dev/null +++ b/CGoGN/include/Utils/Shaders/shaderBoldLines.frag @@ -0,0 +1,14 @@ +// ShaderBoldLines::fragmentShaderText + +PRECISION; +uniform vec4 lineColor; +uniform vec4 planeClip; +VARYING_FRAG vec3 fragClip; +FRAG_OUT_DEF; + +void main() +{ + if (dot(planeClip,vec4(fragClip,1.0))>0.0) + discard; + FRAG_OUT = lineColor; +} diff --git a/CGoGN/include/Utils/Shaders/shaderBoldLines.geom b/CGoGN/include/Utils/Shaders/shaderBoldLines.geom new file mode 100644 index 0000000000000000000000000000000000000000..2622b2d1905445bda8915eb144bf19de1b8c7b41 --- /dev/null +++ b/CGoGN/include/Utils/Shaders/shaderBoldLines.geom @@ -0,0 +1,31 @@ +// ShaderBoldLines::geometryShaderText + +uniform vec2 lineWidth; +VARYING_IN vec3 posClip[]; +VARYING_OUT vec3 fragClip; + +void main() +{ + vec3 A = POSITION_IN(0).xyz / abs(POSITION_IN(0).w); + vec3 B = POSITION_IN(1).xyz / abs(POSITION_IN(1).w); + + vec3 U = normalize(B-A); + vec3 V = cross(U,vec3(0.0,0.0,1.0)); + + vec3 LW = vec3(lineWidth,1.0); + fragClip = posClip[0]; + gl_Position = vec4(A-U*LW, 1.0); + EmitVertex(); + gl_Position = vec4(A+V*LW, 1.0); + EmitVertex(); + gl_Position = vec4(A-V*LW, 1.0); + EmitVertex(); + fragClip = posClip[1]; + gl_Position = vec4(B+V*LW, 1.0); + EmitVertex(); + gl_Position = vec4(B-V*LW, 1.0); + EmitVertex(); + gl_Position = vec4(B+U*LW, 1.0); + EmitVertex(); + EndPrimitive(); +} diff --git a/CGoGN/include/Utils/Shaders/shaderBoldLines.h b/CGoGN/include/Utils/Shaders/shaderBoldLines.h new file mode 100644 index 0000000000000000000000000000000000000000..c15fb8177d5f39693d42756ad9d44dd21f687869 --- /dev/null +++ b/CGoGN/include/Utils/Shaders/shaderBoldLines.h @@ -0,0 +1,88 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2012, 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: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#ifndef __CGOGN_SHADER_BOLDLINES__ +#define __CGOGN_SHADER_BOLDLINES__ + +#include "Utils/GLSLShader.h" +#include "Utils/clippingShader.h" +#include "Geometry/vector_gen.h" + +#include "Utils/dll.h" + +namespace CGoGN +{ + +namespace Utils +{ + +class CGoGN_UTILS_API ShaderBoldLines : public ClippingShader +{ +protected: + // shader sources + static std::string vertexShaderText; + static std::string geometryShaderText; + static std::string fragmentShaderText; + + CGoGNGLuint m_uniform_lineWidth; + CGoGNGLuint m_uniform_color; + + Geom::Vec2f m_lineWidth; + float m_pixWidth; + + Geom::Vec4f m_color; + + VBO* m_vboPos; + + /// clipping + CGoGNGLuint m_unif_planeClip; + Geom::Vec4f m_planeClip; + + void getLocations(); + + void sendParams(); + + void restoreUniformsAttribs(); + +public: + ShaderBoldLines(); + + void setLineWidth(float pix); + + void updatePixelWidth(); + + void setColor(const Geom::Vec4f& color); + + unsigned int setAttributePosition(VBO* vbo); + + void setClippingPlane(const Geom::Vec4f& plane); + inline void setNoClippingPlane() { setClippingPlane(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); } + +}; + +} // namespace Utils + +} // namespace CGoGN + +#endif diff --git a/CGoGN/include/Utils/Shaders/shaderBoldLines.vert b/CGoGN/include/Utils/Shaders/shaderBoldLines.vert new file mode 100644 index 0000000000000000000000000000000000000000..6352374aef8f6b87079be55ab9aff47a9b2d8696 --- /dev/null +++ b/CGoGN/include/Utils/Shaders/shaderBoldLines.vert @@ -0,0 +1,12 @@ +// ShaderBoldLines::vertexShaderText + +ATTRIBUTE vec3 VertexPosition; +uniform mat4 ModelViewProjectionMatrix; +VARYING_VERT vec3 posClip; + +INVARIANT_POS; +void main () +{ + posClip = VertexPosition; + gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0); +} diff --git a/CGoGN/include/Utils/drawer.h b/CGoGN/include/Utils/drawer.h index f3f42aee46233637d50459f8c10195da840fa946..6d5d31dc0d6fb961b525c9d20db92d2dd32d80a6 100644 --- a/CGoGN/include/Utils/drawer.h +++ b/CGoGN/include/Utils/drawer.h @@ -29,6 +29,7 @@ #include "Utils/gl_def.h" #include "Geometry/vector_gen.h" #include "Utils/Shaders/shaderColorPerVertex.h" +#include "Utils/Shaders/shaderBoldColorLines.h" namespace CGoGN { namespace Utils { class VBO; } } namespace CGoGN { namespace Utils { namespace SVG { class SVGOut ; } } } @@ -65,10 +66,12 @@ protected: std::vector m_dataPos; std::vector m_dataCol; std::vector m_begins; + float m_currentWidth; float m_currentSize; GLenum m_compile; Utils::ShaderColorPerVertex* m_shader; + Utils::ShaderBoldColorLines* m_shader2; public: @@ -83,7 +86,11 @@ public: */ ~Drawer(); - Utils::ShaderColorPerVertex* getShader(); +// Utils::ShaderColorPerVertex* getShader(); + std::vector getShaders(); + + void updateMatrices(const glm::mat4& projection, const glm::mat4& modelview); + /** * init the data structure @@ -144,12 +151,12 @@ public: /** * call a set of sub-lists */ - void callSubLists(std::vector indices, float opacity); +// void callSubLists(std::vector indices, float opacity); /** * call a set of sub-lists */ - void callSubLists(int first, int nb, float opacity); +// void callSubLists(int first, int nb, float opacity); /** diff --git a/CGoGN/include/Utils/frameManipulator.h b/CGoGN/include/Utils/frameManipulator.h index 89b854db370243588ebb6893127f8df5b3e2fa55..69a7bd335881c96fa4e756695590e626400bf809 100644 --- a/CGoGN/include/Utils/frameManipulator.h +++ b/CGoGN/include/Utils/frameManipulator.h @@ -29,6 +29,7 @@ #include "Utils/vbo_base.h" #include "glm/glm.hpp" #include "Utils/Shaders/shaderSimpleColor.h" +#include "Utils/Shaders/shaderBoldLines.h" #include "Utils/pickables.h" #include "Utils/dll.h" @@ -71,12 +72,13 @@ protected: /** * VBO for color */ - Utils::VBO* m_vboCol; +// Utils::VBO* m_vboCol; /** * Shader */ Utils::ShaderSimpleColor* m_shader; + Utils::ShaderBoldLines* m_shaderBL; /** * the axis to be highlighted diff --git a/CGoGN/include/Utils/pickables.h b/CGoGN/include/Utils/pickables.h index cc9fdbe423a1ce2a20b2d466e3830e365d933b34..f0f33eb9b9f170b64997f3af07d88ee6371e6645 100644 --- a/CGoGN/include/Utils/pickables.h +++ b/CGoGN/include/Utils/pickables.h @@ -28,8 +28,8 @@ #include "Utils/vbo_base.h" #include "glm/glm.hpp" -#include "Utils/Shaders/shaderColorPerVertex.h" -#include "Utils/Shaders/shaderSimpleColor.h" +//#include "Utils/Shaders/shaderSimpleColor.h" +#include "Utils/Shaders/shaderBoldLines.h" #include "Utils/dll.h" @@ -56,7 +56,8 @@ protected: /** * Shader */ - Utils::ShaderSimpleColor* m_shader; +// static Utils::ShaderSimpleColor* s_shader; + static Utils::ShaderBoldLines* s_shader; /** * number of indices in vbo @@ -70,6 +71,8 @@ protected: unsigned int m_sub2; + float m_lineWidth; + public: /** @@ -124,6 +127,7 @@ public: */ void getPrecisionDrawing(unsigned int& sub, unsigned int& sub2); + inline void setLineWidth(float lw) { m_lineWidth = lw; } }; @@ -288,7 +292,7 @@ public: */ Geom::Vec3f getAxisScale(unsigned int ax, float& scale); - + inline void setLineWidth(float lw) { m_drawable->setLineWidth(lw); } }; diff --git a/CGoGN/src/Utils/Shaders/shaderBoldColorLines.cpp b/CGoGN/src/Utils/Shaders/shaderBoldColorLines.cpp new file mode 100644 index 0000000000000000000000000000000000000000..68c23e6b76d1243bcd2c6bd6377b086bcbd4f948 --- /dev/null +++ b/CGoGN/src/Utils/Shaders/shaderBoldColorLines.cpp @@ -0,0 +1,167 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2012, 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: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ +#define CGoGN_UTILS_DLL_EXPORT 1 +#include "Utils/Shaders/shaderBoldColorLines.h" +#include + +namespace CGoGN +{ + +namespace Utils +{ + +#include "ShaderBoldColorLines.vert" +#include "ShaderBoldColorLines.geom" +#include "ShaderBoldColorLines.frag" + + +ShaderBoldColorLines::ShaderBoldColorLines() : + m_lineWidth(0.01f), + m_opacity(1.0f), + m_planeClip(0.0f,0.0f,0.0f,0.0f) + +{ + m_nameVS = "ShaderBoldColorLines_vs"; + m_nameFS = "ShaderBoldColorLines_fs"; + m_nameGS = "ShaderBoldColorLines_gs"; + + std::string glxvert(GLSLShader::defines_gl()); + glxvert.append(vertexShaderText); + + std::string glxgeom = GLSLShader::defines_Geom("lines", "triangle_strip", 6); + glxgeom.append(geometryShaderText); + + std::string glxfrag(GLSLShader::defines_gl()); + glxfrag.append(fragmentShaderText); + + loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_LINES, GL_TRIANGLE_STRIP, 6); + + // get and fill uniforms + getLocations(); + sendParams(); +} + +void ShaderBoldColorLines::getLocations() +{ + bind(); + *m_uniform_lineWidth = glGetUniformLocation(this->program_handler(), "lineWidth"); + *m_unif_planeClip = glGetUniformLocation(this->program_handler(), "planeClip"); + *m_unif_alpha = glGetUniformLocation(this->program_handler(), "alpha"); + + unbind(); +} + +void ShaderBoldColorLines::sendParams() +{ + bind(); + glUniform2fv(*m_uniform_lineWidth, 1, m_lineWidth.data()); + glUniform1f (*m_unif_alpha, m_opacity); + + if (*m_unif_planeClip > 0) + glUniform4fv(*m_unif_planeClip, 1, m_planeClip.data()); + + unbind(); +} + + +void ShaderBoldColorLines::setLineWidth(float pix) +{ + glm::i32vec4 viewport; + glGetIntegerv(GL_VIEWPORT, &(viewport[0])); + m_pixWidth = pix; + m_lineWidth[0] = float(double(m_pixWidth) / double(viewport[2])); + m_lineWidth[1] = float(double(m_pixWidth) / double(viewport[3])); + bind(); + glUniform2fv(*m_uniform_lineWidth, 1, m_lineWidth.data()); + unbind(); +} + +void ShaderBoldColorLines::updatePixelWidth() +{ + glm::i32vec4 viewport; + glGetIntegerv(GL_VIEWPORT, &(viewport[0])); + m_lineWidth[0] = float(double(m_pixWidth) / double(viewport[2])); + m_lineWidth[1] = float(double(m_pixWidth) / double(viewport[3])); + bind(); + glUniform2fv(*m_uniform_lineWidth, 1, m_lineWidth.data()); + unbind(); +} + + + +unsigned int ShaderBoldColorLines::setAttributeColor(VBO* vbo) +{ + m_vboCol = vbo; + bind(); + unsigned int id = bindVA_VBO("VertexColor", vbo); + unbind(); + return id; +} + +unsigned int ShaderBoldColorLines::setAttributePosition(VBO* vbo) +{ + m_vboPos = vbo; + bind(); + unsigned int id = bindVA_VBO("VertexPosition", vbo); + unbind(); + return id; +} + + + +void ShaderBoldColorLines::restoreUniformsAttribs() +{ + getLocations(); + sendParams(); + + bind(); + bindVA_VBO("VertexPosition", m_vboPos); + bindVA_VBO("VertexColor", m_vboCol); + unbind(); +} + +void ShaderBoldColorLines::setOpacity(float op) +{ + m_opacity = op; + bind(); + glUniform1f (*m_unif_alpha, m_opacity); + unbind(); +} + +void ShaderBoldColorLines::setClippingPlane(const Geom::Vec4f& plane) +{ + if (*m_unif_planeClip > 0) + { + m_planeClip = plane; + bind(); + glUniform4fv(*m_unif_planeClip, 1, plane.data()); + unbind(); + } +} + + + +} // namespace Utils + +} // namespace CGoGN diff --git a/CGoGN/src/Utils/Shaders/shaderBoldLines.cpp b/CGoGN/src/Utils/Shaders/shaderBoldLines.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8c792093b57ac0cb5ddfacb3014b2abe2ef81f30 --- /dev/null +++ b/CGoGN/src/Utils/Shaders/shaderBoldLines.cpp @@ -0,0 +1,154 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2012, 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: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ +#define CGoGN_UTILS_DLL_EXPORT 1 +#include "Utils/Shaders/shaderBoldLines.h" + +namespace CGoGN +{ + +namespace Utils +{ + +#include "shaderBoldLines.vert" +#include "shaderBoldLines.geom" +#include "shaderBoldLines.frag" + + +ShaderBoldLines::ShaderBoldLines() : + m_lineWidth(0.01f), + m_color (0.0f, 0.0f, 0.0f, 0.0f), + m_planeClip(0.0f,0.0f,0.0f,0.0f) +{ + m_nameVS = "ShaderBoldLines_vs"; + m_nameFS = "ShaderBoldLines_fs"; + m_nameGS = "ShaderBoldLines_gs"; + + std::string glxvert(GLSLShader::defines_gl()); + glxvert.append(vertexShaderText); + + std::string glxgeom = GLSLShader::defines_Geom("lines", "triangle_strip", 6); + glxgeom.append(geometryShaderText); + + std::string glxfrag(GLSLShader::defines_gl()); + glxfrag.append(fragmentShaderText); + + loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_LINES, GL_TRIANGLE_STRIP,6); + + // get and fill uniforms + getLocations(); + sendParams(); +} + +void ShaderBoldLines::getLocations() +{ + bind(); + *m_uniform_lineWidth = glGetUniformLocation(this->program_handler(), "lineWidth"); + *m_uniform_color = glGetUniformLocation(this->program_handler(), "lineColor"); + *m_unif_planeClip = glGetUniformLocation(this->program_handler(), "planeClip"); + unbind(); +} + +void ShaderBoldLines::sendParams() +{ + bind(); + glUniform2fv(*m_uniform_lineWidth, 1, m_lineWidth.data()); + glUniform4fv(*m_uniform_color, 1, m_color.data()); + + if (*m_unif_planeClip > 0) + glUniform4fv(*m_unif_planeClip, 1, m_planeClip.data()); + + unbind(); +} + + +void ShaderBoldLines::setLineWidth(float pix) +{ + glm::i32vec4 viewport; + glGetIntegerv(GL_VIEWPORT, &(viewport[0])); + m_pixWidth = pix; + m_lineWidth[0] = float(double(m_pixWidth) / double(viewport[2])); + m_lineWidth[1] = float(double(m_pixWidth) / double(viewport[3])); + bind(); + glUniform2fv(*m_uniform_lineWidth, 1, m_lineWidth.data()); + unbind(); +} + +void ShaderBoldLines::updatePixelWidth() +{ + glm::i32vec4 viewport; + glGetIntegerv(GL_VIEWPORT, &(viewport[0])); + m_lineWidth[0] = float(double(m_pixWidth) / double(viewport[2])); + m_lineWidth[1] = float(double(m_pixWidth) / double(viewport[3])); + bind(); + glUniform2fv(*m_uniform_lineWidth, 1, m_lineWidth.data()); + unbind(); +} + + + +void ShaderBoldLines::setColor(const Geom::Vec4f& color) +{ + bind(); + glUniform4fv(*m_uniform_color, 1, color.data()); + m_color = color; + unbind(); +} + +unsigned int ShaderBoldLines::setAttributePosition(VBO* vbo) +{ + m_vboPos = vbo; + bind(); + unsigned int id = bindVA_VBO("VertexPosition", vbo); + unbind(); + return id; +} + + +void ShaderBoldLines::restoreUniformsAttribs() +{ + getLocations(); + sendParams(); + + bind(); + bindVA_VBO("VertexPosition", m_vboPos); + unbind(); +} + + +void ShaderBoldLines::setClippingPlane(const Geom::Vec4f& plane) +{ + if (*m_unif_planeClip > 0) + { + m_planeClip = plane; + bind(); + glUniform4fv(*m_unif_planeClip, 1, plane.data()); + unbind(); + } +} + + + +} // namespace Utils + +} // namespace CGoGN diff --git a/CGoGN/src/Utils/drawer.cpp b/CGoGN/src/Utils/drawer.cpp index 09190f66fd98c15ab57ba06ce581eb088a461866..8c697e81c7ff1bbb9c3746888383cd2771b4ff37 100644 --- a/CGoGN/src/Utils/drawer.cpp +++ b/CGoGN/src/Utils/drawer.cpp @@ -37,7 +37,11 @@ namespace CGoGN namespace Utils { -Drawer::Drawer() : m_currentWidth(1.0f) +Drawer::Drawer() : + m_currentWidth(1.0f), + m_currentSize(1.0f), + m_shader(NULL), + m_shader2(NULL) { m_vboPos = new Utils::VBO(); m_vboPos->setDataSize(3); @@ -46,12 +50,20 @@ Drawer::Drawer() : m_currentWidth(1.0f) m_vboCol->setDataSize(3); m_shader = new Utils::ShaderColorPerVertex(); - m_shader->setAttributePosition(m_vboPos); m_shader->setAttributeColor(m_vboCol); Utils::GLSLShader::registerShader(NULL, m_shader); + if (GLSLShader::CURRENT_OGL_VERSION >=3) + { + m_shader2 = new Utils::ShaderBoldColorLines(); + m_shader2->setAttributePosition(m_vboPos); + m_shader2->setAttributeColor(m_vboCol); + m_shader2->setNoClippingPlane(); + Utils::GLSLShader::registerShader(NULL, m_shader2); + } + m_dataPos.reserve(128); m_dataCol.reserve(128); m_begins.reserve(16); @@ -64,13 +76,32 @@ Drawer::~Drawer() delete m_vboPos; delete m_vboCol; delete m_shader; + if (m_shader2) + delete m_shader2; +} + +//Utils::ShaderColorPerVertex* Drawer::getShader() +//{ +// return m_shader; +//} + +std::vector Drawer::getShaders() +{ + std::vector shaders; + shaders.push_back(m_shader); + if (m_shader2) + shaders.push_back(m_shader2); + return shaders; } -Utils::ShaderColorPerVertex* Drawer::getShader() +void Drawer::updateMatrices(const glm::mat4& projection, const glm::mat4& modelview) { - return m_shader; + m_shader->updateMatrices(projection,modelview); + if (m_shader2) + m_shader2->updateMatrices(projection,modelview); } + void Drawer::lineWidth(float lw) { m_currentWidth = lw; @@ -84,18 +115,17 @@ void Drawer::pointSize(float ps) int Drawer::begin(GLenum mode) { int res = int(m_begins.size()); + if (mode == GL_POINTS) m_begins.push_back(PrimParam(uint32(m_dataPos.size()), mode, m_currentSize)); else m_begins.push_back(PrimParam(uint32(m_dataPos.size()), mode, m_currentWidth)); + return res; } void Drawer::end() { - if (m_begins.empty()) - return; - m_begins.back().nb = uint32(m_dataPos.size() - m_begins.back().begin); } @@ -180,18 +210,47 @@ void Drawer::callList(float opacity) if (m_begins.empty()) return; - m_shader->setOpacity(opacity); + if (GLSLShader::CURRENT_OGL_VERSION >=3) + { + m_shader->setOpacity(opacity); + m_shader->enableVertexAttribs(); + for (std::vector::iterator pp = m_begins.begin(); pp != m_begins.end(); ++pp) + { + if (pp->mode == GL_POINTS) + { + glPointSize(pp->width); + glDrawArrays(GL_POINTS, pp->begin, pp->nb); + } + } + m_shader->disableVertexAttribs(); - m_shader->enableVertexAttribs(); - for (std::vector::iterator pp = m_begins.begin(); pp != m_begins.end(); ++pp) + m_shader2->setOpacity(opacity); + m_shader2->enableVertexAttribs(); + for (std::vector::iterator pp = m_begins.begin(); pp != m_begins.end(); ++pp) + { + if (pp->mode != GL_POINTS) + { + m_shader2->setLineWidth(pp->width); + m_shader2->bind(); + glDrawArrays(pp->mode, pp->begin, pp->nb); + } + } + m_shader2->disableVertexAttribs(); + } + else { - if (pp->mode == GL_POINTS) - glPointSize(pp->width); - if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP)) - glLineWidth(pp->width); - glDrawArrays(pp->mode, pp->begin, pp->nb); + m_shader->setOpacity(opacity); + m_shader->enableVertexAttribs(); + for (std::vector::iterator pp = m_begins.begin(); pp != m_begins.end(); ++pp) + { + if (pp->mode == GL_POINTS) + glPointSize(pp->width); + if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP)) + glLineWidth(pp->width); + glDrawArrays(pp->mode, pp->begin, pp->nb); + } + m_shader->disableVertexAttribs(); } - m_shader->disableVertexAttribs(); } @@ -199,64 +258,82 @@ void Drawer::callSubList(int index, float opacity) { if (index >= int(m_begins.size())) return; - - m_shader->setOpacity(opacity); - - m_shader->enableVertexAttribs(); - PrimParam* pp = & (m_begins[index]); - if (pp->mode == GL_POINTS) - glPointSize(pp->width); - if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP)) - glLineWidth(pp->width); - glDrawArrays(pp->mode, pp->begin, pp->nb); - - m_shader->disableVertexAttribs(); -} - -void Drawer::callSubLists(int first, int nb, float opacity) -{ - m_shader->setOpacity(opacity); - m_shader->enableVertexAttribs(); - - int last = first+nb; - for (int i = first; i< last; ++i) - if (i < int(m_begins.size())) + if (GLSLShader::CURRENT_OGL_VERSION >=3) + { + if (pp->mode == GL_POINTS) { - PrimParam* pp = & (m_begins[i]); - - if (pp->mode == GL_POINTS) - glPointSize(pp->width); - if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP)) - glLineWidth(pp->width); + m_shader->setOpacity(opacity); + m_shader->enableVertexAttribs(); + glPointSize(pp->width); glDrawArrays(pp->mode, pp->begin, pp->nb); + m_shader->disableVertexAttribs(); } - - m_shader->disableVertexAttribs(); -} - -void Drawer::callSubLists(std::vector indices, float opacity) -{ - m_shader->setOpacity(opacity); - - m_shader->enableVertexAttribs(); - - for (std::vector::iterator it = indices.begin(); it != indices.end(); ++it) - if (*it < int(m_begins.size())) + else { - PrimParam* pp = & (m_begins[*it]); - - if (pp->mode == GL_POINTS) - glPointSize(pp->width); - if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP)) - glLineWidth(pp->width); + m_shader2->setOpacity(opacity); + m_shader2->enableVertexAttribs(); + m_shader2->setLineWidth(pp->width); glDrawArrays(pp->mode, pp->begin, pp->nb); + m_shader2->disableVertexAttribs(); } - - m_shader->disableVertexAttribs(); + } + else + { + m_shader->setOpacity(opacity); + m_shader->enableVertexAttribs(); + if (pp->mode == GL_POINTS) + glPointSize(pp->width); + if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP)) + glLineWidth(pp->width); + glDrawArrays(pp->mode, pp->begin, pp->nb); + m_shader->disableVertexAttribs(); + } } +//void Drawer::callSubLists(int first, int nb, float opacity) +//{ +// m_shader->setOpacity(opacity); +// m_shader->enableVertexAttribs(); + +// int last = first+nb; +// for (int i = first; i< last; ++i) +// if (i < int(m_begins.size())) +// { +// PrimParam* pp = & (m_begins[i]); + +// if (pp->mode == GL_POINTS) +// glPointSize(pp->width); +// if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP)) +// glLineWidth(pp->width); +// glDrawArrays(pp->mode, pp->begin, pp->nb); +// } + +// m_shader->disableVertexAttribs(); +//} + +//void Drawer::callSubLists(std::vector indices, float opacity) +//{ +// m_shader->setOpacity(opacity); + +// m_shader->enableVertexAttribs(); + +// for (std::vector::iterator it = indices.begin(); it != indices.end(); ++it) +// if (*it < int(m_begins.size())) +// { +// PrimParam* pp = & (m_begins[*it]); + +// if (pp->mode == GL_POINTS) +// glPointSize(pp->width); +// if ((pp->mode == GL_LINES) || (pp->mode == GL_LINE_LOOP) || (pp->mode == GL_LINE_STRIP)) +// glLineWidth(pp->width); +// glDrawArrays(pp->mode, pp->begin, pp->nb); +// } + +// m_shader->disableVertexAttribs(); +//} + void Drawer::toSVG(Utils::SVG::SVGOut& svg) { diff --git a/CGoGN/src/Utils/frameManipulator.cpp b/CGoGN/src/Utils/frameManipulator.cpp index 878cce88463661269e52a8c63b104cd39b0db761..b4c11804ba3ad6f69bbef3786cf845a7052ded19 100644 --- a/CGoGN/src/Utils/frameManipulator.cpp +++ b/CGoGN/src/Utils/frameManipulator.cpp @@ -59,15 +59,18 @@ FrameManipulator::FrameManipulator(): m_vboPos = new VBO(); m_vboPos->setDataSize(3); - m_vboCol = new VBO(); - m_vboCol->setDataSize(3); +// m_vboCol = new VBO(); +// m_vboCol->setDataSize(3); m_shader = new ShaderSimpleColor(); - m_shader->setAttributePosition(m_vboPos); - GLSLShader::registerShader(NULL, m_shader); + m_shaderBL = new ShaderBoldLines(); + m_shaderBL->setAttributePosition(m_vboPos); + GLSLShader::registerShader(NULL, m_shaderBL); + + std::vector points; points.reserve(6*nb_segments+30); points.resize(6*nb_segments+6); @@ -157,7 +160,7 @@ void FrameManipulator::draw() Utils::GLSLShader::applyTransfo(transfoRenderFrame()); Utils::GLSLShader::updateCurrentMatrices(); - glPushAttrib(GL_LINE_BIT); + // glPushAttrib(GL_LINE_BIT); m_shader->enableVertexAttribs(); if (!m_locked_axis[Xr]) @@ -190,11 +193,49 @@ void FrameManipulator::draw() glDrawArrays(GL_TRIANGLE_STRIP, 4*nb_segments+4, 2*nb_segments+2); } - if ((!m_locked_axis[CENTER]) && (m_highlighted == CENTER)) + if (!m_locked_axis[Xt]) + { + if (m_highlighted == Xt) + m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); + else + m_shader->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); + m_shader->bind(); + glDrawArrays(GL_TRIANGLE_FAN, 6*nb_segments+14, 6); + } + + if (!m_locked_axis[Yt]) { - glLineWidth(6.0f); - m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); + if (m_highlighted == Yt) + m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); + else + m_shader->setColor(Geom::Vec4f(0.0f,1.0f,0.0f,0.0f)); m_shader->bind(); + glDrawArrays(GL_TRIANGLE_FAN, 6*nb_segments+22, 6); + } + + if (!m_locked_axis[Zt]) + { + if (m_highlighted == Zt) + m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); + else + m_shader->setColor(Geom::Vec4f(0.0f,0.0f,1.0f,0.0f)); + m_shader->bind(); + glDrawArrays(GL_TRIANGLE_FAN, 6*nb_segments+30, 6); + } + + + m_shader->disableVertexAttribs(); + + + + + + m_shaderBL->enableVertexAttribs(); + if ((!m_locked_axis[CENTER]) && (m_highlighted == CENTER)) + { + m_shaderBL->setLineWidth(6.0f); + m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); + m_shaderBL->bind(); glDrawArrays(GL_LINES, 6*nb_segments+6, 6); } else @@ -203,15 +244,15 @@ void FrameManipulator::draw() { if (m_highlighted == Xs) { - glLineWidth(6.0f); - m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); + m_shaderBL->setLineWidth(6.0f); + m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); } else { - glLineWidth(3.0f); - m_shader->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); + m_shaderBL->setLineWidth(3.0f); + m_shaderBL->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); } - m_shader->bind(); + m_shaderBL->bind(); glDrawArrays(GL_LINES, 6*nb_segments+6, 2); } @@ -219,15 +260,15 @@ void FrameManipulator::draw() { if (m_highlighted == Ys) { - glLineWidth(6.0f); - m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); + m_shaderBL->setLineWidth(6.0f); + m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); } else { - glLineWidth(3.0f); - m_shader->setColor(Geom::Vec4f(0.0f,0.7f,0.0f,0.0f)); + m_shaderBL->setLineWidth(3.0f); + m_shaderBL->setColor(Geom::Vec4f(0.0f,0.7f,0.0f,0.0f)); } - m_shader->bind(); + m_shaderBL->bind(); glDrawArrays(GL_LINES, 6*nb_segments+8, 2); } @@ -235,74 +276,69 @@ void FrameManipulator::draw() { if (m_highlighted == Zs) { - glLineWidth(6.0f); - m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); + m_shaderBL->setLineWidth(6.0f); + m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); } else { - glLineWidth(3.0f); - m_shader->setColor(Geom::Vec4f(0.0f,0.0f,0.7f,0.0f)); + m_shaderBL->setLineWidth(3.0f); + m_shaderBL->setColor(Geom::Vec4f(0.0f,0.0f,0.7f,0.0f)); } - m_shader->bind(); + m_shaderBL->bind(); glDrawArrays(GL_LINES, 6*nb_segments+10, 2); } } - if (!m_locked_axis[Xt]) { if (m_highlighted == Xt) { - m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); - glLineWidth(6.0f); + m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); + m_shaderBL->setLineWidth(6.0f); } else { - glLineWidth(3.0f); - m_shader->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); + m_shaderBL->setLineWidth(3.0f); + m_shaderBL->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); } - - m_shader->bind(); + m_shaderBL->bind(); glDrawArrays(GL_LINES, 6*nb_segments+12, 2); - glDrawArrays(GL_TRIANGLE_FAN, 6*nb_segments+14, 6); } if (!m_locked_axis[Yt]) { if (m_highlighted == Yt) { - glLineWidth(6.0f); - m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); + m_shaderBL->setLineWidth(6.0f); + m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); } else { - glLineWidth(3.0f); - m_shader->setColor(Geom::Vec4f(0.0f,1.0f,0.0f,0.0f)); + m_shaderBL->setLineWidth(3.0f); + m_shaderBL->setColor(Geom::Vec4f(0.0f,1.0f,0.0f,0.0f)); } - m_shader->bind(); + m_shaderBL->bind(); glDrawArrays(GL_LINES, 6*nb_segments+20, 2); - glDrawArrays(GL_TRIANGLE_FAN, 6*nb_segments+22, 6); } if (!m_locked_axis[Zt]) { if (m_highlighted == Zt) { - glLineWidth(6.0f); - m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); + m_shaderBL->setLineWidth(6.0f); + m_shaderBL->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); } else { - glLineWidth(3.0f); - m_shader->setColor(Geom::Vec4f(0.0f,0.0f,1.0f,0.0f)); + m_shaderBL->setLineWidth(3.0f); + m_shaderBL->setColor(Geom::Vec4f(0.0f,0.0f,1.0f,0.0f)); } - m_shader->bind(); + m_shaderBL->bind(); glDrawArrays(GL_LINES, 6*nb_segments+28, 2); - glDrawArrays(GL_TRIANGLE_FAN, 6*nb_segments+30, 6); } - m_shader->disableVertexAttribs(); - glPopAttrib(); + m_shaderBL->disableVertexAttribs(); +// glPopAttrib(); Utils::GLSLShader::popTransfo(); Utils::GLSLShader::updateCurrentMatrices(); diff --git a/CGoGN/src/Utils/pickables.cpp b/CGoGN/src/Utils/pickables.cpp index c46eb95e3a906b0f65f833420e75877617c2b8c1..0740aab0cb22b904accf9e311a46e4ea5da0dd45 100644 --- a/CGoGN/src/Utils/pickables.cpp +++ b/CGoGN/src/Utils/pickables.cpp @@ -36,16 +36,20 @@ namespace CGoGN namespace Utils { + Utils::ShaderBoldLines* LineDrawable::s_shader = NULL; +// Utils::ShaderSimpleColor* LineDrawable::s_shader = NULL; + LineDrawable::LineDrawable() { m_vboPos = new VBO(); m_vboPos->setDataSize(3); - m_shader = new ShaderSimpleColor(); - - m_shader->setAttributePosition(m_vboPos); - m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.)); - GLSLShader::registerShader(NULL, m_shader); + if (s_shader == NULL) + { +// s_shader = new ShaderSimpleColor(); + s_shader = new ShaderBoldLines(); + GLSLShader::registerShader(NULL, s_shader); + } glGenBuffers(1, &(*m_ind)); } @@ -53,8 +57,8 @@ LineDrawable::LineDrawable() LineDrawable::~LineDrawable() { delete m_vboPos; - GLSLShader::unregisterShader(NULL, m_shader); - delete m_shader; +// GLSLShader::unregisterShader(NULL, s_shader); +// delete s_shader; glDeleteBuffers(1, &(*m_ind)); } @@ -63,7 +67,7 @@ LineDrawable::~LineDrawable() void LineDrawable::setColor(const Geom::Vec4f& col) { m_color=col; - m_shader->setColor(col); +// s_shader->setColor(col); } const Geom::Vec4f& LineDrawable::getColor() @@ -73,9 +77,12 @@ const Geom::Vec4f& LineDrawable::getColor() void LineDrawable::draw() { - m_shader->enableVertexAttribs(); + s_shader->setAttributePosition(m_vboPos); + s_shader->setColor(m_color); + s_shader->setLineWidth(m_lineWidth); + s_shader->enableVertexAttribs(); glDrawArrays(GL_LINES, 0, m_nb); - m_shader->disableVertexAttribs(); + s_shader->disableVertexAttribs(); } void LineDrawable::getPrecisionDrawing(unsigned int& sub, unsigned int& sub2) @@ -495,10 +502,13 @@ void Sphere::updatePrecisionDrawing(unsigned int sub, unsigned int sub2) void Sphere::draw() { - m_shader->enableVertexAttribs(); + s_shader->setAttributePosition(m_vboPos); + s_shader->setColor(m_color); + s_shader->setLineWidth(m_lineWidth); + s_shader->enableVertexAttribs(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *m_ind); glDrawElements(GL_LINES, m_nb, GL_UNSIGNED_INT, 0); - m_shader->disableVertexAttribs(); + s_shader->disableVertexAttribs(); } @@ -884,10 +894,13 @@ void Cube::updatePrecisionDrawing(unsigned int sub, unsigned int sub2) void Cube::draw() { - m_shader->enableVertexAttribs(); + s_shader->setAttributePosition(m_vboPos); + s_shader->setColor(m_color); + s_shader->setLineWidth(m_lineWidth); + s_shader->enableVertexAttribs(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *m_ind); glDrawElements(GL_LINES, m_nb, GL_UNSIGNED_INT, 0); - m_shader->disableVertexAttribs(); + s_shader->disableVertexAttribs(); } diff --git a/SCHNApps/Plugins/surface_modelisation/src/surface_modelisation.cpp b/SCHNApps/Plugins/surface_modelisation/src/surface_modelisation.cpp index 76cfb339a8a9a44a3f767fd357aaa4804f712a59..08c6b411614d9e64684d68fc3e7bae6c179626ff 100644 --- a/SCHNApps/Plugins/surface_modelisation/src/surface_modelisation.cpp +++ b/SCHNApps/Plugins/surface_modelisation/src/surface_modelisation.cpp @@ -40,7 +40,7 @@ bool Surface_Modelisation_Plugin::enable() m_dockTab->updateMapParameters(); m_drawer = new Utils::Drawer(); - registerShader(m_drawer->getShader()); + registerShader(m_drawer->getShaders()); mapNumber = 1; @@ -53,6 +53,7 @@ void Surface_Modelisation_Plugin::disable() disconnect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*))); disconnect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*))); + unregisterShader(m_drawer->getShaders()); delete m_drawer; } diff --git a/SCHNApps/Plugins/surface_radiance/include/edgeSelectorRadiance.hpp b/SCHNApps/Plugins/surface_radiance/include/edgeSelectorRadiance.hpp index 6b9c67a6f821fda9b16ac8839d8a195af9e40664..cc8d54ef626ae14ff4d02c2f586a4881ad191d50 100644 --- a/SCHNApps/Plugins/surface_radiance/include/edgeSelectorRadiance.hpp +++ b/SCHNApps/Plugins/surface_radiance/include/edgeSelectorRadiance.hpp @@ -206,7 +206,7 @@ void EdgeSelector_Radiance::computeEdgeInfo(Dart d, EdgeInfo& einfo) const REAL rad = computeRadianceError(d, newPos, newN, newRad); - const REAL t = 0.01 ; + const REAL t = 0.01f ; const REAL err = t*geom + (1-t)*rad ; // Check if errated values appear diff --git a/SCHNApps/Plugins/surface_radiance/include/halfEdgeSelectorRadiance.hpp b/SCHNApps/Plugins/surface_radiance/include/halfEdgeSelectorRadiance.hpp index 179678bd100c4411b4f6ddc349c1f2832c736faf..5b7df6c51e00fe781a1851d60ab965489154ace1 100644 --- a/SCHNApps/Plugins/surface_radiance/include/halfEdgeSelectorRadiance.hpp +++ b/SCHNApps/Plugins/surface_radiance/include/halfEdgeSelectorRadiance.hpp @@ -267,7 +267,7 @@ void HalfEdgeSelector_Radiance::computeHalfEdgeInfo(Dart d, HalfEdgeInfo& h const REAL rad = computeRadianceError(d); - const REAL t = 0.01 ; + const REAL t = 0.01f ; const REAL err = t*geom + (1-t)*rad ; // Check if errated values appear diff --git a/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp b/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp index 29f839bdf9e9d074a5a4f262448fdc8137a2a988..4bf3ace31b32cb81ca0cab85ab40bcc3e581f620 100644 --- a/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp +++ b/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp @@ -45,9 +45,9 @@ bool Surface_Selection_Plugin::enable() m_selectionSphereVBO = new Utils::VBO(); registerShader(m_pointSprite); - registerShader(m_selectedEdgesDrawer->getShader()); - registerShader(m_selectedFacesDrawer->getShader()); - registerShader(m_selectingCellDrawer->getShader()); + registerShader(m_selectedEdgesDrawer->getShaders()); + registerShader(m_selectedFacesDrawer->getShaders()); + registerShader(m_selectingCellDrawer->getShaders()); connect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*))); connect(m_schnapps, SIGNAL(selectedCellSelectorChanged(CellSelectorGen*)), this, SLOT(updateSelectedCellsRendering())); @@ -69,6 +69,11 @@ bool Surface_Selection_Plugin::enable() void Surface_Selection_Plugin::disable() { + unregisterShader(m_pointSprite); + unregisterShader(m_selectedEdgesDrawer->getShaders()); + unregisterShader(m_selectedFacesDrawer->getShaders()); + unregisterShader(m_selectingCellDrawer->getShaders()); + delete m_pointSprite; delete m_selectedVerticesVBO; diff --git a/SCHNApps/Plugins/surface_subdivision/forms/dialog_surface_subdivision.ui b/SCHNApps/Plugins/surface_subdivision/forms/dialog_surface_subdivision.ui index 292db6d811751142c599e33f10e9a2837c7e3370..90d448f89c50ba4aafde78a013e0300bf21d2c8d 100644 --- a/SCHNApps/Plugins/surface_subdivision/forms/dialog_surface_subdivision.ui +++ b/SCHNApps/Plugins/surface_subdivision/forms/dialog_surface_subdivision.ui @@ -6,25 +6,18 @@ 0 0 - 327 - 230 + 282 + 334 Subdivide surface - + - - - - Position attribute : - - - - + @@ -34,45 +27,66 @@ - - + + - Loop + Triangule - - + + - Catmull-Clark + Loop - - + + - Triangule faces + Quadrangule - - + + - Cancel + Position attribute : - + Apply - + - OK + Close + + + + + + + Do-Sabin + + + + + + + Catmull-Clark + + + + + + + Interp diff --git a/SCHNApps/Plugins/surface_subdivision/include/surface_subdivision.h b/SCHNApps/Plugins/surface_subdivision/include/surface_subdivision.h index 1696710ae44da7ad607d53e1fafdd90c9b3d69fe..760b5335802ed3a5889b8f1a5d31d62fe389da0e 100644 --- a/SCHNApps/Plugins/surface_subdivision/include/surface_subdivision.h +++ b/SCHNApps/Plugins/surface_subdivision/include/surface_subdivision.h @@ -36,16 +36,24 @@ private slots: public slots: void loopSubdivision( const QString& mapName, - const QString& positionAttributeName = "position" - ); + const QString& positionAttributeName = "position"); + void CCSubdivision( const QString& mapName, - const QString& positionAttributeName = "position" - ); + const QString& positionAttributeName = "position", + bool interp = false ); + + void DoSabinSubdivision( + const QString& mapName, + const QString& positionAttributeName = "position"); + void trianguleFaces( const QString& mapName, - const QString& positionAttributeName = "position" - ); + const QString& positionAttributeName = "position"); + + void quadranguleFaces( + const QString& mapName, + const QString& positionAttributeName = "position"); private: Dialog_Surface_Subdivision* m_subdivisionDialog; diff --git a/SCHNApps/Plugins/surface_subdivision/src/surface_subdivision.cpp b/SCHNApps/Plugins/surface_subdivision/src/surface_subdivision.cpp index 27898d71867dee3e0d82cd63cb8b98b1aea96a82..c441949df4847884b3980528eb53e25c587a39fa 100644 --- a/SCHNApps/Plugins/surface_subdivision/src/surface_subdivision.cpp +++ b/SCHNApps/Plugins/surface_subdivision/src/surface_subdivision.cpp @@ -26,6 +26,7 @@ bool Surface_Subdivision_Plugin::enable() connect(m_subdivisionDialog, SIGNAL(accepted()), this, SLOT(subdivideFromDialog())); connect(m_subdivisionDialog->button_apply, SIGNAL(clicked()), this, SLOT(subdivideFromDialog())); + connect(m_subdivisionDialog->button_ok, SIGNAL(clicked()), this, SLOT(schnappsClosing())); connect(m_schnapps, SIGNAL(schnappsClosing()), this, SLOT(schnappsClosing())); return true; @@ -56,10 +57,20 @@ void Surface_Subdivision_Plugin::subdivideFromDialog() if(m_subdivisionDialog->radio_Loop->isChecked()) loopSubdivision(mapName, positionName); - else if(m_subdivisionDialog->radio_CC->isChecked()) - CCSubdivision(mapName, positionName); + else if (m_subdivisionDialog->radio_CC->isChecked()) + { + if (m_subdivisionDialog->check_interp->isChecked()) + CCSubdivision(mapName, positionName, true); + else + CCSubdivision(mapName, positionName, false); + } + else if (m_subdivisionDialog->radio_DoSabin->isChecked()) + DoSabinSubdivision(mapName, positionName); else if(m_subdivisionDialog->radio_trianguleFaces->isChecked()) trianguleFaces(mapName, positionName); + else if (m_subdivisionDialog->radio_quadranguleFaces->isChecked()) + quadranguleFaces(mapName, positionName); + } } @@ -89,7 +100,7 @@ void Surface_Subdivision_Plugin::loopSubdivision( void Surface_Subdivision_Plugin::CCSubdivision( const QString& mapName, - const QString& positionAttributeName) + const QString& positionAttributeName, bool interp) { MapHandler* mh = static_cast*>(m_schnapps->getMap(mapName)); if(mh == NULL) @@ -99,10 +110,38 @@ void Surface_Subdivision_Plugin::CCSubdivision( if(!position.isValid()) return; - pythonRecording("CCSubdivision", "", mapName, positionAttributeName); + pythonRecording("CCSubdivision", "", mapName, positionAttributeName,interp); + + PFP2::MAP* map = mh->getMap(); + if (interp) + Algo::Surface::Modelisation::CatmullClarkInterpolSubdivision(*map, position); + else + Algo::Surface::Modelisation::CatmullClarkSubdivision(*map, position); + + mh->notifyAttributeModification(position); + mh->notifyConnectivityModification(); + + foreach(View* view, mh->getLinkedViews()) + view->updateGL(); +} + + +void Surface_Subdivision_Plugin::DoSabinSubdivision( + const QString& mapName, + const QString& positionAttributeName) +{ + MapHandler* mh = static_cast*>(m_schnapps->getMap(mapName)); + if (mh == NULL) + return; + + VertexAttribute position = mh->getAttribute(positionAttributeName); + if (!position.isValid()) + return; + + pythonRecording("DoSabinSubdivision", "", mapName, positionAttributeName); PFP2::MAP* map = mh->getMap(); - Algo::Surface::Modelisation::CatmullClarkSubdivision(*map, position); + Algo::Surface::Modelisation::DooSabin(*map, position); mh->notifyAttributeModification(position); mh->notifyConnectivityModification(); @@ -111,6 +150,7 @@ void Surface_Subdivision_Plugin::CCSubdivision( view->updateGL(); } + void Surface_Subdivision_Plugin::trianguleFaces( const QString& mapName, const QString& positionAttributeName) @@ -135,6 +175,32 @@ void Surface_Subdivision_Plugin::trianguleFaces( view->updateGL(); } +void Surface_Subdivision_Plugin::quadranguleFaces( + const QString& mapName, + const QString& positionAttributeName) +{ + MapHandler* mh = static_cast*>(m_schnapps->getMap(mapName)); + if (mh == NULL) + return; + + VertexAttribute position = mh->getAttribute(positionAttributeName); + if (!position.isValid()) + return; + + pythonRecording("quadranguleFaces", "", mapName, positionAttributeName); + + PFP2::MAP* map = mh->getMap(); + Algo::Surface::Modelisation::quadranguleFaces(*map, position); + + mh->notifyAttributeModification(position); + mh->notifyConnectivityModification(); + + foreach(View* view, mh->getLinkedViews()) + view->updateGL(); +} + + + void Surface_Subdivision_Plugin::schnappsClosing() { m_subdivisionDialog->close(); diff --git a/SCHNApps/forms/controlDock_MapTabWidget.ui b/SCHNApps/forms/controlDock_MapTabWidget.ui index bf48ec7c8f4a7d215d63439a0c74ec21359e5932..617a0cdbf0adad30d174d62df0d70da7e835545f 100644 --- a/SCHNApps/forms/controlDock_MapTabWidget.ui +++ b/SCHNApps/forms/controlDock_MapTabWidget.ui @@ -44,6 +44,16 @@ + + + + + + + true + + + @@ -63,6 +73,24 @@ + + + + + + remove + + + + + + + duplicate + + + + + diff --git a/SCHNApps/include/camera.h b/SCHNApps/include/camera.h index 166668d1afa4002f973a05f994faccb43266381b..c8ee53abfb8247a5ec6e83e33ddb24b75842b542 100644 --- a/SCHNApps/include/camera.h +++ b/SCHNApps/include/camera.h @@ -50,6 +50,9 @@ public slots: void enableViewsBoundingBoxFitting() { b_fitToViewsBoundingBox = true; } void disableViewsBoundingBoxFitting() { b_fitToViewsBoundingBox = false; } + QString toString(); + void fromString(QString cam); + private: void linkView(View* view); void unlinkView(View* view); diff --git a/SCHNApps/include/controlDock_mapTab.h b/SCHNApps/include/controlDock_mapTab.h index 488f132526b2e905a8c21b05e5aed31c153a7002..004bf4b2238e02b4d3a7c57a63d29d9c76cee550 100644 --- a/SCHNApps/include/controlDock_mapTab.h +++ b/SCHNApps/include/controlDock_mapTab.h @@ -40,6 +40,10 @@ private slots: // slots called from UI actions void selectedMapChanged(); + void duplicateCurrentMap(); + void removeCurrentMap(); + + void showBBChanged(bool b); void bbVertexAttributeChanged(int index); void vertexAttributeCheckStateChanged(QListWidgetItem* item); diff --git a/SCHNApps/include/mapHandler.h b/SCHNApps/include/mapHandler.h index 03e4695c0e6c5c148b81a9fdeecf650548ee93ce..bb7a8feaaa29df1659b4a34c30aa0d5b44f29b02 100644 --- a/SCHNApps/include/mapHandler.h +++ b/SCHNApps/include/mapHandler.h @@ -82,6 +82,19 @@ private slots: *********************************************************/ public slots: + + void showBB(bool b) + { + m_showBB = b; + foreach(View* view, l_views) + view->updateGL(); + } + + bool isBBshown() const + { + return m_showBB; + } + void setBBVertexAttribute(const QString& name) { m_bbVertexAttribute = m_map->getAttributeVectorGen(VERTEX, name.toStdString()); @@ -107,17 +120,15 @@ public slots: float getBBdiagSize() const { return m_bbDiagSize; } - Utils::GLSLShader* getBBDrawerShader() const + inline Utils::Drawer* getBBDrawer() const { - if(m_bbDrawer) - return m_bbDrawer->getShader(); - else - return NULL; + return m_bbDrawer; } virtual bool transformedBB(qglviewer::Vec& bbMin, qglviewer::Vec& bbMax) = 0; protected: + bool m_showBB; virtual void updateBB() = 0; /********************************************************* diff --git a/SCHNApps/include/mapHandler.hpp b/SCHNApps/include/mapHandler.hpp index fab72b93a876d974b0c97fe61e3f8c7cf38e81b3..989d6378093bb1778bbf607ed707c9e4bfd6ccb4 100644 --- a/SCHNApps/include/mapHandler.hpp +++ b/SCHNApps/include/mapHandler.hpp @@ -87,7 +87,7 @@ void MapHandler::draw(Utils::GLSLShader* shader, int primitive) template void MapHandler::drawBB() { - if (m_bbDrawer) + if (m_showBB && m_bbDrawer) m_bbDrawer->callList(); } diff --git a/SCHNApps/include/plugin_interaction.h b/SCHNApps/include/plugin_interaction.h index 34d2d7bc8dc60ed5bfc77c8b5b11734178147aa3..ad4211cc53df4cad8b908bf20047b3273610aa30 100644 --- a/SCHNApps/include/plugin_interaction.h +++ b/SCHNApps/include/plugin_interaction.h @@ -58,6 +58,10 @@ protected: void registerShader(Utils::GLSLShader* shader); void unregisterShader(Utils::GLSLShader* shader); + void registerShader(const std::vector& shaders); + void unregisterShader(const std::vector& shaders); + + protected: QList l_views; QList l_shaders; diff --git a/SCHNApps/include/schnapps.h b/SCHNApps/include/schnapps.h index b7a91d3e78604c4e9871f071da3aa2ee2392d779..51147291058389aa9b32de4179adf509e2746f42 100644 --- a/SCHNApps/include/schnapps.h +++ b/SCHNApps/include/schnapps.h @@ -56,6 +56,7 @@ public slots: public: void redrawAllViews(); + public slots: View* addView(const QString& name); View* addView(); @@ -69,6 +70,10 @@ public slots: void splitView(const QString& name, Qt::Orientation orientation); + QString saveSplitViewPositions(); + void restoreSplitViewPositions(QString stringStates); + + /********************************************************* * MANAGE PLUGINS *********************************************************/ @@ -99,6 +104,9 @@ private slots: public slots: MapHandlerGen* addMap(const QString& name, unsigned int dim); void removeMap(const QString& name); + MapHandlerGen* duplicateMap(const QString& name, bool properties); + + void setSelectedMap(const QString& mapName); MapHandlerGen* getMap(const QString& name) const; @@ -145,6 +153,7 @@ public slots: QString saveFileDialog(const QString& title, const QString& dir = QString(), const QString& filter = QString()); + void setWindowSize(int w, int h) { this->resize(w, h); } private slots: void loadPythonScriptFromFileDialog(); @@ -160,7 +169,7 @@ protected: QString m_pyBuffer; private slots: - void beginPyRecording(); + void pyRecording(); void appendPyRecording(); //void endPyRecording(); diff --git a/SCHNApps/src/camera.cpp b/SCHNApps/src/camera.cpp index 8ec39d5202fd42138becc998828067db05db73f8..d1447511040cf5becd58ee85adf5e8907d56bf5d 100644 --- a/SCHNApps/src/camera.cpp +++ b/SCHNApps/src/camera.cpp @@ -121,6 +121,35 @@ void Camera::fitToViewsBoundingBox() } } + +QString Camera::toString() +{ + QString res; + QTextStream str(&res); + qglviewer::Vec pos = this->position(); + qglviewer::Quaternion ori = this->orientation(); + str << pos[0] << " " << pos[1] << " " << pos[2] << " "; + str << ori[0] << " " << ori[1] << " " << ori[2] << " " << ori[3]; + return res; +} + +void Camera::fromString(QString cam) +{ + QTextStream str(&cam); + qglviewer::Vec pos = this->position(); + qglviewer::Quaternion ori = this->orientation(); + str >> pos[0]; + str >> pos[1]; + str >> pos[2]; + str >> ori[0]; + str >> ori[1]; + str >> ori[2]; + str >> ori[3]; + this->setPosition(pos); + this->setOrientation(ori); +} + + } // namespace SCHNApps } // namespace CGoGN diff --git a/SCHNApps/src/controlDock_mapTab.cpp b/SCHNApps/src/controlDock_mapTab.cpp index 2c72ae15da002968901f39221a97b0e576cf2c18..dad2b47595feb95e2cfb48c42231e1c96ebf30c4 100644 --- a/SCHNApps/src/controlDock_mapTab.cpp +++ b/SCHNApps/src/controlDock_mapTab.cpp @@ -21,6 +21,10 @@ ControlDock_MapTab::ControlDock_MapTab(SCHNApps* s) : connect(list_maps, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapChanged())); + connect(button_duplicate, SIGNAL(clicked()), this, SLOT(duplicateCurrentMap())); + connect(button_remove, SIGNAL(clicked()), this, SLOT(removeCurrentMap())); + + connect(check_drawBB, SIGNAL(toggled(bool)), this, SLOT(showBBChanged(bool))); connect(combo_bbVertexAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(bbVertexAttributeChanged(int))); connect(list_vertexAttributes, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(vertexAttributeCheckStateChanged(QListWidgetItem*))); @@ -77,8 +81,9 @@ void ControlDock_MapTab::setSelectedMap(const QString& mapName) if(!items.empty()) { items[0]->setSelected(false); - m_selectedMap = NULL; } + m_selectedMap = NULL; + updateSelectedMapInfo(); return; } @@ -133,6 +138,52 @@ void ControlDock_MapTab::selectedMapChanged() } } +void ControlDock_MapTab::showBBChanged(bool b) +{ + if (!b_updatingUI) + { + + if (m_selectedMap) + { + m_selectedMap->showBB(b); + // RECORDING + QTextStream* rec = m_schnapps->pythonStreamRecorder(); + if (rec) + *rec << m_selectedMap->getName() << ".showBB(" << b << ");" << endl; + } + + } +} + + +void ControlDock_MapTab::duplicateCurrentMap() +{ + if (!b_updatingUI) + { + if (m_selectedMap) + { + /*MapHandlerGen* mhg = */m_schnapps->duplicateMap(m_selectedMap->getName(), true); + } + } +} + +void ControlDock_MapTab::removeCurrentMap() +{ + if (!b_updatingUI) + { + if (m_selectedMap) + { + m_schnapps->removeMap(m_selectedMap->getName()); + // RECORDING + QTextStream* rec = m_schnapps->pythonStreamRecorder(); + if (rec) + *rec << "schnapps.removeMap(" << m_selectedMap->getName() << ".getName());" << endl; + } + } +} + + + void ControlDock_MapTab::bbVertexAttributeChanged(int index) { if (!b_updatingUI) @@ -319,6 +370,8 @@ void ControlDock_MapTab::updateSelectedMapInfo() for (unsigned int orbit = DART; orbit <= VOLUME; ++orbit) { + check_drawBB->setChecked(m_selectedMap->isBBshown()); + unsigned int nbc = m->getNbCells(orbit); QListWidget* selectorList = NULL; diff --git a/SCHNApps/src/mapHandler.cpp b/SCHNApps/src/mapHandler.cpp index 7423d4691132db60f62496825c439fd088cbc9de..50fdf2add894ee4fff532218de5d7527954f90b4 100644 --- a/SCHNApps/src/mapHandler.cpp +++ b/SCHNApps/src/mapHandler.cpp @@ -7,6 +7,7 @@ namespace SCHNApps { MapHandlerGen::MapHandlerGen(const QString& name, SCHNApps* s, GenericMap* map) : + m_showBB(true), m_name(name), m_schnapps(s), m_map(map), diff --git a/SCHNApps/src/plugin_interaction.cpp b/SCHNApps/src/plugin_interaction.cpp index 7d51f062109b7a192a4bb09f030e719e68d79407..2fd3b1968187aadf4b329c2e67ed5dee228bac57 100644 --- a/SCHNApps/src/plugin_interaction.cpp +++ b/SCHNApps/src/plugin_interaction.cpp @@ -49,6 +49,19 @@ void PluginInteraction::unregisterShader(Utils::GLSLShader* shader) l_shaders.removeOne(shader); } +void PluginInteraction::registerShader(const std::vector& shaders) +{ + for (auto shader: shaders) + if(shader && !l_shaders.contains(shader)) + l_shaders.push_back(shader); +} + +void PluginInteraction::unregisterShader(const std::vector& shaders) +{ + for (auto shader: shaders) + l_shaders.removeOne(shader); +} + } // namespace SCHNApps } // namespace CGoGN diff --git a/SCHNApps/src/schnapps.cpp b/SCHNApps/src/schnapps.cpp index 74e57c5081a5bbcd28289e992f2b15107e6a3d71..3d74fee4b19caedd85ded8700cd1146a684b72ac 100644 --- a/SCHNApps/src/schnapps.cpp +++ b/SCHNApps/src/schnapps.cpp @@ -11,7 +11,7 @@ #include #include #include - +#include #include "mapHandler.h" #include "schnapps.h" @@ -107,7 +107,7 @@ SCHNApps::SCHNApps(const QString& appPath, PythonQtObjectPtr& pythonContext, Pyt connect(action_ShowHidePythonDock, SIGNAL(triggered()), this, SLOT(showHidePythonDock())); connect(action_LoadPythonScript, SIGNAL(triggered()), this, SLOT(loadPythonScriptFromFileDialog())); - connect(action_Python_Recording, SIGNAL(triggered()), this, SLOT(beginPyRecording())); + connect(action_Python_Recording, SIGNAL(triggered()), this, SLOT(pyRecording())); connect(action_Append_Python_Recording, SIGNAL(triggered()), this, SLOT(appendPyRecording())); action_Python_Recording->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P)); @@ -118,6 +118,7 @@ SCHNApps::SCHNApps(const QString& appPath, PythonQtObjectPtr& pythonContext, Pyt // create & setup central widget (views) m_centralLayout = new QVBoxLayout(centralwidget); + m_centralLayout->setMargin(2); m_rootSplitter = new QSplitter(centralwidget); b_rootSplitterInitialized = false; @@ -320,8 +321,18 @@ void SCHNApps::splitView(const QString& name, Qt::Orientation orientation) m_rootSplitter->setOrientation(orientation); b_rootSplitterInitialized = true; } - if(parent->orientation() == orientation) - parent->insertWidget(parent->indexOf(view)+1, newView); + if (parent->orientation() == orientation) + { + parent->insertWidget(parent->indexOf(view) + 1, newView); + QList sz = parent->sizes(); + int tot = 0; + for (int i = 0; i < parent->count(); ++i) + tot += sz[i]; + sz[0] = tot / parent->count() + tot % parent->count(); + for (int i = 1; i < parent->count(); ++i) + sz[i] = tot / parent->count(); + parent->setSizes(sz); + } else { int idx = parent->indexOf(view); @@ -330,10 +341,82 @@ void SCHNApps::splitView(const QString& name, Qt::Orientation orientation) spl->addWidget(view); spl->addWidget(newView); parent->insertWidget(idx, spl); + + QList sz = spl->sizes(); + int tot = sz[0] + sz[1]; + sz[0] = tot / 2; + sz[1] = tot - sz[0]; + spl->setSizes(sz); + } +} + +QString SCHNApps::saveSplitViewPositions() +{ + QList liste; + liste.push_back(m_rootSplitter); + + QString result; + QTextStream qts(&result); + while (!liste.empty()) + { + QSplitter* spl = liste.first(); + for (int i = 0; i < spl->count(); ++i) + { + QWidget *w = spl->widget(i); + QSplitter* qw = dynamic_cast(w); + if (qw != NULL) + liste.push_back(qw); + } + QByteArray ba = spl->saveState(); + qts << ba.count() << " "; + for (int j = 0; j < ba.count(); ++j) + qts << int(ba[j]) << " "; + //qts << endl; + liste.pop_front(); + } + return result; +} + + +void SCHNApps::restoreSplitViewPositions(QString stringStates) +{ + QList liste; + liste.push_back(m_rootSplitter); + + QTextStream qts(&stringStates); + while (!liste.empty()) + { + QSplitter* spl = liste.first(); + for (int i = 0; i < spl->count(); ++i) + { + QWidget *w = spl->widget(i); + QSplitter* qw = dynamic_cast(w); + if (qw != NULL) + liste.push_back(qw); + } + if (qts.atEnd()) + { + std::cerr << "Problem restoring view split configuration" << std::endl; + return; + } + + int nb; + qts >> nb; + QByteArray ba(nb + 1, 0); + for (int j = 0; j < nb; ++j) + { + int v; + qts >> v; + ba[j] = char(v); + } + spl->restoreState(ba); + liste.pop_front(); } - } + + + /********************************************************* * MANAGE PLUGINS *********************************************************/ @@ -543,6 +626,91 @@ void SCHNApps::disablePluginTabWidgets(PluginInteraction* plugin) * MANAGE MAPS *********************************************************/ +MapHandlerGen* SCHNApps::duplicateMap(const QString& name, bool properties) +{ + if (! m_maps.contains(name)) + return NULL; + + QString newName = name + "_copy"; + + if (m_maps.contains(newName)) + return NULL; + + // RECORDING + QTextStream* rec = this->pythonStreamRecorder(); + if (rec) + *rec << newName << " = schnapps.duplicateMap(" << name << ".getName(),1);" << endl; + + MapHandlerGen* maph = m_maps[name]; + MapHandlerGen* new_mh; + + unsigned int dim = maph->getGenericMap()->dimension(); + + switch (dim) + { + case 2: { + PFP2::MAP* map = new PFP2::MAP(); + map->copyFrom(*(maph->getGenericMap())); + new_mh = new MapHandler(newName, this, map); + + for (unsigned int orbit = VERTEX; orbit <= VOLUME; orbit++) + { + AttributeContainer& cont = map->getAttributeContainer(orbit); + std::vector names; + std::vector types; + cont.getAttributesNames(names); + cont.getAttributesTypes(types); + for (unsigned int i = 0; i < names.size(); ++i) + new_mh->registerAttribute(orbit, QString::fromStdString(names[i]), QString::fromStdString(types[i])); + } + break; + } + case 3: { + PFP3::MAP* map = new PFP3::MAP(); + map->copyFrom(*(maph->getGenericMap())); + new_mh = new MapHandler(newName, this, map); + for (unsigned int orbit = VERTEX; orbit <= VOLUME; orbit++) + { + AttributeContainer& cont = map->getAttributeContainer(orbit); + std::vector names; + std::vector types; + cont.getAttributesNames(names); + cont.getAttributesTypes(types); + for (unsigned int i = 0; i < names.size(); ++i) + new_mh->registerAttribute(orbit, QString::fromStdString(names[i]), QString::fromStdString(types[i])); + } + break; + } + } + + + + + m_maps.insert(newName, new_mh); + DEBUG_EMIT("mapAdded"); + emit(mapAdded(new_mh)); + + if (properties) + { + // BB + new_mh->setBBVertexAttribute(maph->getBBVertexAttributeName()); + + //VBOs + const VBOSet& vbos = maph->getVBOSet(); + foreach(QString s, vbos.keys()) + { + new_mh->createVBO(s); + } + } + + pythonVarDeclare(new_mh->getName()); + + return new_mh; +} + + + + MapHandlerGen* SCHNApps::addMap(const QString& name, unsigned int dim) { if (m_maps.contains(name)) @@ -588,8 +756,9 @@ void SCHNApps::removeMap(const QString& name) // unselect map if it is removed if (this->getSelectedMap() == map) + { setSelectedMap(QString("NONE")); - + } delete map; } } @@ -834,7 +1003,7 @@ void SCHNApps::loadPythonScriptFromFileDialog() } -void SCHNApps::beginPyRecording() +void SCHNApps::pyRecording() { if (m_pyRecording != NULL) // WRITE & CLOSE { @@ -843,7 +1012,21 @@ void SCHNApps::beginPyRecording() { m_pyBuffer.replace("\"" + var + "\"", var + ".getName()"); } + out << m_pyBuffer << endl; + + // split view positions + out << "schnapps.restoreSplitViewPositions(\"" << saveSplitViewPositions() << "\")" << endl; + + // cameras + foreach(Camera* cam, m_cameras) + { + out << "schnapps.getCamera(\"" << cam->getName() << "\").fromString(\"" << cam->toString() << "\")" << endl; + } + + //windows + out << "schnapps.setWindowSize(" << this->width() << ", "<< this->height() << ")" << endl; + m_pyRecFile->close(); delete m_pyRecording; @@ -851,6 +1034,7 @@ void SCHNApps::beginPyRecording() m_pyRecording = NULL; m_pyRecFile = NULL; statusbar->showMessage(QString(" Stop recording python"), 2000); + action_Python_Recording->setText("Python Recording"); return; } @@ -873,6 +1057,7 @@ void SCHNApps::beginPyRecording() statusbar->showMessage(QString(" Recording python in ") + fileName); pythonVarsClear(); + action_Python_Recording->setText("Stop Python Recording"); } else { @@ -893,6 +1078,19 @@ void SCHNApps::appendPyRecording() m_pyBuffer.replace("\"" + var + "\"", var + ".getName()"); } out << m_pyBuffer << endl; + + // split view positions + out << "schnapps.restoreSplitViewPositions(\"" << saveSplitViewPositions() << "\")" << endl; + + // cameras + foreach(Camera* cam, m_cameras) + { + out << "schnapps.getCamera(\"" << cam->getName() << "\").fromString(\"" << cam->toString() << "\")" << endl; + } + + //windows + out << "schnapps.setWindowSize(" << this->width() << ", " << this->height() << ")" << endl; + m_pyRecFile->close(); delete m_pyRecording; @@ -900,6 +1098,7 @@ void SCHNApps::appendPyRecording() m_pyRecording = NULL; m_pyRecFile = NULL; statusbar->showMessage(QString(" Stop recording python"), 2000); + action_Append_Python_Recording->setText("Append Python Recording"); return; } @@ -924,7 +1123,7 @@ void SCHNApps::appendPyRecording() } statusbar->showMessage(QString(" Append recording python in ") + fileName); - + action_Append_Python_Recording->setText("Stop Append Python Recording"); } else { @@ -938,6 +1137,10 @@ void SCHNApps::appendPyRecording() void SCHNApps::closeEvent(QCloseEvent *event) { DEBUG_EMIT("schnappsClosing"); + if (m_pyRecording != NULL) // WRITE & CLOSE + { + pyRecording(); + } emit(schnappsClosing()); QMainWindow::closeEvent(event); } diff --git a/SCHNApps/src/view.cpp b/SCHNApps/src/view.cpp index e504c790f663abe0666303f410b85a9c0cf6a5a0..49441228a65a1245adef347051652cbb6671fe63 100644 --- a/SCHNApps/src/view.cpp +++ b/SCHNApps/src/view.cpp @@ -168,6 +168,8 @@ bool View::usesCamera(const QString& name) const return usesCamera(c); } + + void View::linkPlugin(PluginInteraction* plugin) { // RECORDING @@ -369,11 +371,12 @@ void View::init() m_frameDrawer = new Utils::Drawer(); glm::mat4 mm(1.0); glm::mat4 pm(1.0); - m_frameDrawer->getShader()->updateMatrices(mm, pm); +// m_frameDrawer->getShader()->updateMatrices(mm, pm); + m_frameDrawer->updateMatrices(mm, pm); m_frameDrawer->newList(GL_COMPILE); m_frameDrawer->color3f(0.0f,1.0f,0.0f); - m_frameDrawer->lineWidth(4.0f); + m_frameDrawer->lineWidth(6.0f); m_frameDrawer->begin(GL_LINE_LOOP); m_frameDrawer->vertex3f(-1.0f,-1.0f, 0.0f); m_frameDrawer->vertex3f( 1.0f,-1.0f, 0.0f); @@ -447,9 +450,9 @@ void View::draw() if(map == selectedMap) { - Utils::GLSLShader* bbShader = map->getBBDrawerShader(); - if(bbShader) - bbShader->updateMatrices(pm, map_mm); + Utils::Drawer* bbDr = map->getBBDrawer(); + if(bbDr) + bbDr->updateMatrices(pm, map_mm); map->drawBB(); } @@ -539,7 +542,7 @@ void View::keyPressEvent(QKeyEvent* event) msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Ok); if (msgBox.exec() == QMessageBox::Ok) - exit(0); + m_schnapps->close(); } else QGLViewer::keyPressEvent(event); diff --git a/apps_cmake.txt b/apps_cmake.txt index 97660373239b1685939a18636680f2788c30adfd..c68b7ddba4112c372c8c6855cb9abe8f24c72b99 100644 --- a/apps_cmake.txt +++ b/apps_cmake.txt @@ -21,7 +21,7 @@ # qt_wrap_cpp( pipo_moc pipo.h ) # add_executable( pipo pipo.cpp ${pipo_ui} ${pipo_moc} ) # target_link_libraries( pipo ${CGoGN_LIBS} ${CGoGN_EXT_LIBS} ) -# +# qt_use_cgogn_modules(pipo) # # WARNING: to avoid problem of DLL loading, on windows executable are generated in CGoGN/bin/.... # Take care while choosing executable names @@ -75,7 +75,11 @@ IF (WIN32) ENDIF() ELSE() link_directories( ${CGoGN_ROOT_DIR}/lib/${CMAKE_BUILD_TYPE} ) - SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE} ) + IF(APPLE) + SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}/Contents/MacOS/ ) + ELSE() + SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE} ) + ENDIF() ENDIF() # Qt version from CGoGN