Commit 7596ab32 authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

Merge cgogn:~thery/CGoGN

parents a52d10da c2731df0
...@@ -106,6 +106,15 @@ void MyQT::cb_combo6(int x) ...@@ -106,6 +106,15 @@ void MyQT::cb_combo6(int x)
CGoGNerr <<"undefined traversor" << CGoGNendl; CGoGNerr <<"undefined traversor" << CGoGNendl;
} }
void MyQT::cb_explode(int x)
{
m_expl = float (x) /100.0f;
if (m_last==2)
traverse2();
if (m_last==3)
traverse3();
}
void MyQT::cb_initGL() void MyQT::cb_initGL()
{ {
...@@ -154,6 +163,13 @@ void MyQT::cb_mousePress(int button, int x, int y) ...@@ -154,6 +163,13 @@ void MyQT::cb_mousePress(int button, int x, int y)
} }
void MyQT::cb_Save()
{
std::string filename = selectFileSave("Export SVG file ",".","(*.svg)");
Utils::SVG::SVGOut svg(filename,modelViewMatrix(),projectionMatrix());
m_drawer.toSVG(svg);
}
void MyQT::colorizeCell(Dart d, unsigned int orbit, float r,float g, float b) void MyQT::colorizeCell(Dart d, unsigned int orbit, float r,float g, float b)
{ {
TraversorDartsOfOrbit<PFP::MAP>doo (myMap,orbit,d); TraversorDartsOfOrbit<PFP::MAP>doo (myMap,orbit,d);
...@@ -166,37 +182,37 @@ void MyQT::traverse2() ...@@ -166,37 +182,37 @@ void MyQT::traverse2()
{ {
if (m_selected == NIL) if (m_selected == NIL)
return; return;
m_last=2;
// int code = (m_ajd_or_inci2)*100+m_first2*10+m_second2; // int code = (m_ajd_or_inci2)*100+m_first2*10+m_second2;
SelectorDartNoBoundary<PFP::MAP> nb(myMap); SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_drawer.newList(GL_COMPILE); m_drawer.newList(GL_COMPILE);
m_drawer.lineWidth(3.0f); m_drawer.lineWidth(3.0f);
m_drawer.pointSize(7.0f); m_drawer.pointSize(7.0f);
m_drawer.color3f(1.0f,1.0f,0.0f); m_drawer.color3f(0.0f,0.7f,0.0f);
m_affDarts.clear(); m_affDarts.clear();
if (m_ajd_or_inci2 == 0) // incident if (m_ajd_or_inci2 == 0) // incident
{ {
Algo::Render::drawerCell<PFP>(VERTEX+m_second2, m_drawer,myMap,m_selected,position,0.7f); Algo::Render::drawerCell<PFP>(VERTEX+m_second2, m_drawer,myMap,m_selected,position,m_expl);
m_drawer.color3f(1.0f,0.0f,0.0f); m_drawer.color3f(1.0f,0.0f,0.0f);
Traversor2<PFP::MAP>* tra = Traversor2<PFP::MAP>::createIncident(myMap,m_selected,VERTEX+m_second2,VERTEX+m_first2); Traversor2<PFP::MAP>* tra = Traversor2<PFP::MAP>::createIncident(myMap,m_selected,VERTEX+m_second2,VERTEX+m_first2);
for (Dart d=tra->begin(); d != tra->end(); d= tra->next()) for (Dart d=tra->begin(); d != tra->end(); d= tra->next())
m_affDarts.push_back(d); m_affDarts.push_back(d);
Algo::Render::drawerCells<PFP>(VERTEX+m_first2, m_drawer, myMap,m_affDarts,position,0.7f); Algo::Render::drawerCells<PFP>(VERTEX+m_first2, m_drawer, myMap,m_affDarts,position,m_expl);
} }
else // adjacent else // adjacent
{ {
Algo::Render::drawerCell<PFP>(VERTEX+m_first2, m_drawer,myMap,m_selected,position,0.7f); Algo::Render::drawerCell<PFP>(VERTEX+m_first2, m_drawer,myMap,m_selected,position,m_expl);
m_drawer.color3f(1.0f,0.0f,0.0f); m_drawer.color3f(1.0f,0.0f,0.0f);
Traversor2<PFP::MAP>* tra = Traversor2<PFP::MAP>::createAdjacent(myMap,m_selected,VERTEX+m_first2,VERTEX+m_second2); Traversor2<PFP::MAP>* tra = Traversor2<PFP::MAP>::createAdjacent(myMap,m_selected,VERTEX+m_first2,VERTEX+m_second2);
for (Dart d=tra->begin(); d != tra->end(); d= tra->next()) for (Dart d=tra->begin(); d != tra->end(); d= tra->next())
m_affDarts.push_back(d); m_affDarts.push_back(d);
Algo::Render::drawerCells<PFP>(VERTEX+m_first2, m_drawer, myMap,m_affDarts,position,0.7f); Algo::Render::drawerCells<PFP>(VERTEX+m_first2, m_drawer, myMap,m_affDarts,position,m_expl);
} }
m_drawer.endList(); m_drawer.endList();
...@@ -207,35 +223,36 @@ void MyQT::traverse2() ...@@ -207,35 +223,36 @@ void MyQT::traverse2()
void MyQT::traverse3() void MyQT::traverse3()
{ {
// int code = (m_ajd_or_inci3)*100+m_first3*10+m_second3;
// std::cout << "CODE="<< code << std::endl;
if (m_selected == NIL) if (m_selected == NIL)
return; return;
m_last=3;
SelectorDartNoBoundary<PFP::MAP> nb(myMap); SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_affDarts.clear(); m_affDarts.clear();
m_drawer.newList(GL_COMPILE); m_drawer.newList(GL_COMPILE);
m_drawer.lineWidth(3.0f); m_drawer.lineWidth(3.0f);
m_drawer.pointSize(7.0f); m_drawer.pointSize(7.0f);
m_drawer.color3f(1.0f,1.0f,0.0f); m_drawer.color3f(0.0f,0.7f,0.0f);
if (m_ajd_or_inci3 == 0) // incident if (m_ajd_or_inci3 == 0) // incident
{ {
Algo::Render::drawerCell<PFP>(VERTEX+m_second3, m_drawer,myMap,m_selected,position,0.7f); Algo::Render::drawerCell<PFP>(VERTEX+m_second3, m_drawer,myMap,m_selected,position,m_expl);
m_drawer.color3f(1.0f,0.0f,0.0f); m_drawer.color3f(1.0f,0.0f,0.0f);
Traversor3XY<PFP::MAP> tra(myMap,m_selected,VERTEX+m_second3,VERTEX+m_first3); Traversor3XY<PFP::MAP> tra(myMap,m_selected,VERTEX+m_second3,VERTEX+m_first3);
for (Dart d=tra.begin(); d != tra.end(); d= tra.next()) for (Dart d=tra.begin(); d != tra.end(); d= tra.next())
m_affDarts.push_back(d); m_affDarts.push_back(d);
Algo::Render::drawerCells<PFP>(VERTEX+m_first3, m_drawer, myMap,m_affDarts,position,0.7f); Algo::Render::drawerCells<PFP>(VERTEX+m_first3, m_drawer, myMap,m_affDarts,position,m_expl);
} }
else // adjacent else // adjacent
{ {
Algo::Render::drawerCell<PFP>(VERTEX+m_first3, m_drawer,myMap,m_selected,position,0.7f); Algo::Render::drawerCell<PFP>(VERTEX+m_first3, m_drawer,myMap,m_selected,position,m_expl);
m_drawer.color3f(1.0f,0.0f,0.0f); m_drawer.color3f(1.0f,0.0f,0.0f);
Traversor3XXaY<PFP::MAP> tra(myMap,m_selected,VERTEX+m_first3,VERTEX+m_second3); Traversor3XXaY<PFP::MAP> tra(myMap,m_selected,VERTEX+m_first3,VERTEX+m_second3);
for (Dart d=tra.begin(); d != tra.end(); d= tra.next()) for (Dart d=tra.begin(); d != tra.end(); d= tra.next())
m_affDarts.push_back(d); m_affDarts.push_back(d);
Algo::Render::drawerCells<PFP>(VERTEX+m_first3, m_drawer, myMap,m_affDarts,position,0.7f); Algo::Render::drawerCells<PFP>(VERTEX+m_first3, m_drawer, myMap,m_affDarts,position,m_expl);
} }
m_drawer.endList(); m_drawer.endList();
...@@ -280,6 +297,7 @@ int main(int argc, char **argv) ...@@ -280,6 +297,7 @@ int main(int argc, char **argv)
sqt.setCallBack( dock.combo4, SIGNAL( activated(int)), SLOT(cb_combo4(int)) ); sqt.setCallBack( dock.combo4, SIGNAL( activated(int)), SLOT(cb_combo4(int)) );
sqt.setCallBack( dock.combo5, SIGNAL( activated(int)), SLOT(cb_combo5(int)) ); sqt.setCallBack( dock.combo5, SIGNAL( activated(int)), SLOT(cb_combo5(int)) );
sqt.setCallBack( dock.combo6, SIGNAL( activated(int)), SLOT(cb_combo6(int)) ); sqt.setCallBack( dock.combo6, SIGNAL( activated(int)), SLOT(cb_combo6(int)) );
sqt.setCallBack( dock.explodeSlider, SIGNAL(valueChanged(int)), SLOT(cb_explode(int)) );
sqt.setCallBack( dock.checkTopo, SIGNAL( clicked(bool)), SLOT(cb_checkTopo(bool)) ); sqt.setCallBack( dock.checkTopo, SIGNAL( clicked(bool)), SLOT(cb_checkTopo(bool)) );
......
...@@ -96,6 +96,8 @@ class MyQT: public Utils::QT::SimpleQT ...@@ -96,6 +96,8 @@ class MyQT: public Utils::QT::SimpleQT
unsigned int m_first2; unsigned int m_first2;
unsigned int m_ajd_or_inci2; unsigned int m_ajd_or_inci2;
unsigned int m_second2; unsigned int m_second2;
float m_expl;
unsigned int m_last;
public: public:
MyQT(): MyQT():
m_render_topo(NULL), m_render_topo(NULL),
...@@ -106,6 +108,8 @@ public: ...@@ -106,6 +108,8 @@ public:
m_first2(0), m_first2(0),
m_ajd_or_inci2(0), m_ajd_or_inci2(0),
m_second2(1), m_second2(1),
m_expl(0.8f),
m_last(2),
m_selected(NIL) m_selected(NIL)
{} {}
...@@ -122,6 +126,8 @@ protected: ...@@ -122,6 +126,8 @@ protected:
void cb_initGL(); void cb_initGL();
void cb_Save();
void cb_mousePress(int button, int x, int y); void cb_mousePress(int button, int x, int y);
void colorizeCell(Dart d, unsigned int orbit, float r,float g, float b); void colorizeCell(Dart d, unsigned int orbit, float r,float g, float b);
...@@ -139,6 +145,8 @@ public slots: ...@@ -139,6 +145,8 @@ public slots:
void cb_combo5(int x); void cb_combo5(int x);
void cb_combo6(int x); void cb_combo6(int x);
void cb_checkTopo(bool b); void cb_checkTopo(bool b);
void cb_explode(int x);
}; };
#endif #endif
...@@ -210,6 +210,29 @@ ...@@ -210,6 +210,29 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QSlider" name="explodeSlider">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="sliderPosition">
<number>80</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="checkTopo"> <widget class="QCheckBox" name="checkTopo">
<property name="focusPolicy"> <property name="focusPolicy">
......
...@@ -91,7 +91,7 @@ public: ...@@ -91,7 +91,7 @@ public:
virtual Dart end() ; virtual Dart end() ;
virtual void next(Dart& d) ; virtual Dart next(Dart& d) ;
virtual bool foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread = 0) ; virtual bool foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread = 0) ;
......
...@@ -152,12 +152,13 @@ inline Dart ImplicitHierarchicalMap::end() ...@@ -152,12 +152,13 @@ inline Dart ImplicitHierarchicalMap::end()
return Map2::end() ; return Map2::end() ;
} }
inline void ImplicitHierarchicalMap::next(Dart& d) inline Dart ImplicitHierarchicalMap::next(Dart& d)
{ {
do do
{ {
Map2::next(d) ; Map2::next(d) ;
} while(d != Map2::end() && m_dartLevel[d] > m_curLevel) ; } while(d != Map2::end() && m_dartLevel[d] > m_curLevel) ;
return d;
} }
inline bool ImplicitHierarchicalMap::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread) inline bool ImplicitHierarchicalMap::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread)
......
...@@ -364,7 +364,7 @@ public: ...@@ -364,7 +364,7 @@ public:
virtual Dart end() ; virtual Dart end() ;
virtual void next(Dart& d) ; virtual Dart next(Dart& d) ;
virtual bool foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread = 0) ; virtual bool foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread = 0) ;
......
...@@ -213,12 +213,13 @@ inline Dart ImplicitHierarchicalMap3::end() ...@@ -213,12 +213,13 @@ inline Dart ImplicitHierarchicalMap3::end()
return Map3::end() ; return Map3::end() ;
} }
inline void ImplicitHierarchicalMap3::next(Dart& d) inline Dart ImplicitHierarchicalMap3::next(Dart& d)
{ {
do do
{ {
Map3::next(d) ; Map3::next(d) ;
} while(d != Map3::end() && m_dartLevel[d] > m_curLevel) ; } while(d != Map3::end() && m_dartLevel[d] > m_curLevel) ;
return d;
} }
inline bool ImplicitHierarchicalMap3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread) inline bool ImplicitHierarchicalMap3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread)
......
/*******************************************************************************
* 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 _COLOR_PER_FACE_RENDER
#define _COLOR_PER_FACE_RENDER
#include <GL/glew.h>
#include "Topology/generic/dart.h"
#include "Topology/generic/attributeHandler.h"
#include "Topology/generic/functor.h"
#include "Utils/vbo.h"
#include "Utils/GLSLShader.h"
namespace CGoGN
{
namespace Algo
{
namespace Render
{
namespace GL2
{
/**
* Class that update VBO to allow the rendering of per face color rendering
* Warning: do not use same position & color VBO than with pervertex rendering !
*/
class ColorPerFaceRender
{
protected:
GLuint m_nbTris;
public:
/**
* Constructor
*/
ColorPerFaceRender() ;
/**
* update drawing buffers
* @param map the map
* @param positions attribute of position vertices
* @param colorPerFace attribute of color (per face, or per vertex per face)
* @param good selector
*/
template<typename PFP>
void updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboColor, typename PFP::MAP& map, const typename PFP::TVEC3& positions, const typename PFP::TVEC3& colorPerFace, const FunctorSelect& good = allDarts) ;
template<typename PFP>
void updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboNormals, Utils::VBO& vboColor, typename PFP::MAP& map, const typename PFP::TVEC3& positions, const typename PFP::TVEC3& normals, const typename PFP::TVEC3& colorPerFace, const FunctorSelect& good = allDarts) ;
/**
* draw
*/
void draw(Utils::GLSLShader* sh) ;
};
}//end namespace GL2
}//end namespace Algo
}//end namespace Render
}//end namespace CGoGN
#include "Algo/Render/GL2/colorPerFaceRender.hpp"
#endif
/*******************************************************************************
* 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 *
* *
*******************************************************************************/
#include <cmath>
#include "Geometry/vector_gen.h"
#include "Topology/generic/dartmarker.h"
#include "Topology/generic/cellmarker.h"
#include "Algo/Geometry/centroid.h"
namespace CGoGN
{
namespace Algo
{
namespace Render
{
namespace GL2
{
inline ColorPerFaceRender::ColorPerFaceRender():
m_nbTris(0)
{
}
template<typename PFP>
void ColorPerFaceRender::updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboColor, typename PFP::MAP& map, const typename PFP::TVEC3& positions,const typename PFP::TVEC3& colorPerXXX, const FunctorSelect& good)
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
std::vector<VEC3> buffer;
buffer.reserve(16384);
std::vector<VEC3> bufferColors;
bufferColors.reserve(16384);
TraversorCell<typename PFP::MAP> traFace(map, FACE,good);
for (Dart d=traFace.begin(); d!=traFace.end(); d=traFace.next())
{
Dart a = d;
Dart b = map.phi1(a);
Dart c = map.phi1(b);
// loop to cut a polygon in triangle on the fly (works only with convex faces)
do
{
buffer.push_back(positions[d]);
bufferColors.push_back(colorPerXXX[d]);
buffer.push_back(positions[b]);
bufferColors.push_back(colorPerXXX[b]);
buffer.push_back(positions[c]);
bufferColors.push_back(colorPerXXX[c]);
b = c;
c = map.phi1(b);
} while (c != d);
}
m_nbTris = buffer.size()/3;
vboPosition.setDataSize(3);
vboPosition.allocate(buffer.size());
VEC3* ptrPos = reinterpret_cast<VEC3*>(vboPosition.lockPtr());
memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3));
vboPosition.releasePtr();
vboColor.setDataSize(3);
vboColor.allocate(bufferColors.size());
VEC3* ptrCol = reinterpret_cast<VEC3*>(vboColor.lockPtr());
memcpy(ptrCol,&bufferColors[0],bufferColors.size()*sizeof(VEC3));
vboColor.releasePtr();
}
template<typename PFP>
void ColorPerFaceRender::updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboNormal, Utils::VBO& vboColor, typename PFP::MAP& map, const typename PFP::TVEC3& positions, const typename PFP::TVEC3& normals, const typename PFP::TVEC3& colorPerXXX, const FunctorSelect& good)
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
std::vector<VEC3> buffer;
buffer.reserve(16384);
std::vector<VEC3> bufferNormals;
bufferNormals.reserve(16384);
std::vector<VEC3> bufferColors;
bufferColors.reserve(16384);
TraversorCell<typename PFP::MAP> traFace(map, FACE,good);
for (Dart d=traFace.begin(); d!=traFace.end(); d=traFace.next())
{
Dart a = d;
Dart b = map.phi1(a);
Dart c = map.phi1(b);
// loop to cut a polygon in triangle on the fly (works only with convex faces)
do
{
buffer.push_back(positions[d]);
bufferNormals.push_back(normals[d]);
bufferColors.push_back(colorPerXXX[d]);
buffer.push_back(positions[b]);
bufferNormals.push_back(normals[b]);
bufferColors.push_back(colorPerXXX[b]);
buffer.push_back(positions[c]);
bufferNormals.push_back(normals[c]);
bufferColors.push_back(colorPerXXX[c]);
b = c;
c = map.phi1(b);
} while (c != d);
}
m_nbTris = buffer.size()/3;
vboPosition.setDataSize(3);
vboPosition.allocate(buffer.size());
VEC3* ptrPos = reinterpret_cast<VEC3*>(vboPosition.lockPtr());
memcpy(ptrPos, &buffer[0], buffer.size()*sizeof(VEC3));
vboPosition.releasePtr();