Commit 293b5646 authored by untereiner's avatar untereiner

add multiresolution progressive meshes

add cut plan to tuto_oper3
parent 70500ef4
...@@ -45,6 +45,8 @@ int main(int argc, char **argv) ...@@ -45,6 +45,8 @@ int main(int argc, char **argv)
sqt.setCallBack( sqt.dock.listOper, SIGNAL(currentRowChanged(int)), SLOT(operation(int)) ); sqt.setCallBack( sqt.dock.listOper, SIGNAL(currentRowChanged(int)), SLOT(operation(int)) );
sqt.setCallBack( sqt.dock.svg, SIGNAL(clicked()), SLOT(svg()) ); sqt.setCallBack( sqt.dock.svg, SIGNAL(clicked()), SLOT(svg()) );
sqt.setCallBack( sqt.dock.widthSlider, SIGNAL(valueChanged(int)), SLOT(width(int)) ); sqt.setCallBack( sqt.dock.widthSlider, SIGNAL(valueChanged(int)), SLOT(width(int)) );
sqt.setCallBack( sqt.dock.checkBox_hide, SIGNAL(toggled(bool)), SLOT(hide_onoff(bool)) );
sqt.setCallBack( sqt.dock.checkBox_plane, SIGNAL(toggled(bool)), SLOT(clipping_onoff(bool)) );
int n=3; int n=3;
if (argc==2) if (argc==2)
n = atoi(argv[1]); n = atoi(argv[1]);
...@@ -62,6 +64,36 @@ int main(int argc, char **argv) ...@@ -62,6 +64,36 @@ int main(int argc, char **argv)
return app.exec(); return app.exec();
} }
void MyQT::clipping_onoff(bool x)
{
clip_volume = x;
if (clip_volume)
{
Geom::Vec3f pos = m_PlanePick->getPosition();
float pipo;
Geom::Vec3f normal = m_PlanePick->getAxisScale(2, pipo); // 2 = Z axis = plane normal
m_render_topo->shader1()->setClipPlaneParamsAll(clip_id1, normal, pos);
m_render_topo->shader2()->setClipPlaneParamsAll(clip_id2, normal, pos);
}
else
{
m_render_topo->shader1()->setClipPlaneParamsAll(clip_id1, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f));
m_render_topo->shader2()->setClipPlaneParamsAll(clip_id2, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f));
m_render_topo->shader1()->setClipColorAttenuationFactorRelative(0.0f,0.0f);
m_render_topo->shader2()->setClipColorAttenuationFactorRelative(0.0f,0.0f);
}
updateMap();
updateGL();
}
void MyQT::hide_onoff(bool x)
{
hide_clipping = !hide_clipping;
updateMap();
updateGL();
}
void MyQT::operation(int x) void MyQT::operation(int x)
{ {
switch(x) switch(x)
...@@ -191,8 +223,8 @@ void MyQT::operation(int x) ...@@ -191,8 +223,8 @@ void MyQT::operation(int x)
Dart dit = m_selecteds.front(); Dart dit = m_selecteds.front();
PFP::VEC3 Q = (position[myMap.phi1(m_selected)] + position[m_selected])/2.0f; PFP::VEC3 Q = (position[myMap.phi1(m_selected)] + position[m_selected])/2.0f;
//PFP::VEC3 c1 = Algo::Geometry::volumeCentroid<PFP>(myMap, dit, position); //PFP::VEC3 c1 = Algo::Geometry::volumeCentroid<PFP>(myMap, dit, position);
//Dart dres = myMap.splitVertex(m_selecteds); Dart dres = myMap.splitVertex(m_selecteds);
Dart dres = Algo::Modelisation::Tetrahedralization::splitVertex<PFP>(myMap, m_selecteds); //Dart dres = Algo::Modelisation::Tetrahedralization::splitVertex<PFP>(myMap, m_selecteds);
position[dres] = position[dit] + Q*0.25f; position[dres] = position[dit] + Q*0.25f;
//position[dit] = position[dit] - c1*0.5f; //position[dit] = position[dit] - c1*0.5f;
m_selecteds.clear(); m_selecteds.clear();
...@@ -220,17 +252,8 @@ void MyQT::createMap(int n) ...@@ -220,17 +252,8 @@ void MyQT::createMap(int n)
prim.hexaGrid_topo(n,n,n); prim.hexaGrid_topo(n,n,n);
prim.embedHexaGrid(1.0f,1.0f,1.0f); prim.embedHexaGrid(1.0f,1.0f,1.0f);
// Dart d = Algo::Modelisation::createTetrahedron<PFP>(myMap);
// myMap.closeMap();
//
// position[d] = typename PFP::VEC3(0.0f, 0.0f, 0.0f);
// position[myMap.phi1(d)] = typename PFP::VEC3(0.0f, 1.0f, 0.0f);
// position[myMap.phi1(myMap.phi1(d))] = typename PFP::VEC3(1.0f, 0.5f, 0.0f);
// position[myMap.phi_1(myMap.phi2(d))] = typename PFP::VEC3(0.5f, 0.5f, 1.0f);
// bounding box of scene // bounding box of scene
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ; bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
setParamObject(bb.maxSize(), bb.center().data()) ; setParamObject(bb.maxSize(), bb.center().data()) ;
m_shift = bb.maxSize()/200.0f; m_shift = bb.maxSize()/200.0f;
...@@ -254,6 +277,20 @@ void MyQT::cb_initGL() ...@@ -254,6 +277,20 @@ void MyQT::cb_initGL()
{ {
glClearColor(1.0f,1.0f,1.0f,1.0f); glClearColor(1.0f,1.0f,1.0f,1.0f);
m_render_topo = new Algo::Render::GL2::Topo3Render() ; m_render_topo = new Algo::Render::GL2::Topo3Render() ;
m_PlanePick = new Utils::Pickable(Utils::Pickable::GRID,1);
m_frame = new Utils::FrameManipulator();
m_frame->setSize(bb.maxSize());
m_render_topo->shader1()->insertClippingCode();
m_render_topo->shader2()->insertClippingCode();
clip_id1 = m_render_topo->shader1()->addClipPlane();
clip_id2 = m_render_topo->shader2()->addClipPlane();
m_render_topo->shader1()->setClipPlaneParamsAll(clip_id1, Geom::Vec3f(0,0,1), bb.center());
m_render_topo->shader2()->setClipPlaneParamsAll(clip_id2, Geom::Vec3f(0,0,1), bb.center());
} }
// redraw GL callback (clear and swap already done) // redraw GL callback (clear and swap already done)
...@@ -276,6 +313,12 @@ void MyQT::cb_redraw() ...@@ -276,6 +313,12 @@ void MyQT::cb_redraw()
{ {
m_render_topo->overdrawDart(*it, 11, 0.0f, 0.0f, 1.0f); m_render_topo->overdrawDart(*it, 11, 0.0f, 0.0f, 1.0f);
} }
if (clip_volume && !hide_clipping)
{
m_frame->draw();
m_PlanePick->draw();
}
} }
void MyQT::cb_mousePress(int button, int x, int y) void MyQT::cb_mousePress(int button, int x, int y)
...@@ -294,6 +337,29 @@ void MyQT::cb_mousePress(int button, int x, int y) ...@@ -294,6 +337,29 @@ void MyQT::cb_mousePress(int button, int x, int y)
m_selected2 = d; m_selected2 = d;
} }
updateGL(); updateGL();
if (hide_clipping || !clip_volume)
return;
m_begX = x;
m_begY = y;
// get ray of selection
Geom::Vec3f rayA,rayB;
float dist = getOrthoScreenRay(x,y,rayA,rayB);
Geom::Vec3f AB = rayB-rayA;
unsigned int fr_picked =0;
// picking the frame -> axis
fr_picked = m_frame->pick(rayA,AB,dist);
if (fr_picked != 0)
{
m_pickedAxis=fr_picked;
m_frame->highlight(m_pickedAxis);
m_frame->storeProjection(m_pickedAxis);
updateGL();
}
} }
if (Control()) if (Control())
...@@ -308,6 +374,74 @@ void MyQT::cb_mousePress(int button, int x, int y) ...@@ -308,6 +374,74 @@ void MyQT::cb_mousePress(int button, int x, int y)
} }
} }
void MyQT::cb_mouseRelease(int button, int x, int y)
{
if (hide_clipping || !clip_volume)
return;
m_pickedAxis=0;
m_frame->highlight(m_pickedAxis);
updateGL();
}
void MyQT::cb_mouseMove(int buttons, int x, int y)
{
if (!Shift())
return;
if (hide_clipping || !clip_volume)
return;
// rotation selected ?
if (Utils::FrameManipulator::rotationAxis(m_pickedAxis))
{
if (buttons&1)
{
float angle = m_frame->angleFromMouse(x,y,x-m_begX, y-m_begY);
m_frame->rotate(m_pickedAxis, angle);
}
else if (buttons&2)
m_frame->rotateInScreen(x-m_begX, y-m_begY);
m_PlanePick->transfo() = m_frame->transfo();
}
// translation selected
else if (Utils::FrameManipulator::translationAxis(m_pickedAxis))
{
if (buttons&1)
{
float dist = m_frame->distanceFromMouse(x-m_begX, y-m_begY);
m_frame->translate(m_pickedAxis, dist);
}
else if (buttons&2)
m_frame->translateInScreen(x-m_begX, y-m_begY);
m_PlanePick->transfo() = m_frame->transfo();
}
// scale selected
else if (Utils::FrameManipulator::scaleAxis(m_pickedAxis) )
{
float scale = m_frame->scaleFromMouse(x-m_begX, y-m_begY);
m_frame->scale(m_pickedAxis, scale );
m_PlanePick->transfo() = m_frame->transfo();
}
Geom::Vec3f pos = m_PlanePick->getPosition();
float pipo;
Geom::Vec3f normal = m_PlanePick->getAxisScale(2, pipo); // 2 = Z axis = plane normal
m_render_topo->shader1()->setClipPlaneParamsAll(clip_id1, normal, pos);
m_render_topo->shader2()->setClipPlaneParamsAll(clip_id2, normal, pos);
m_begX = x;
m_begY = y;
updateGL();
return;
}
void MyQT::cb_keyPress(int keycode) void MyQT::cb_keyPress(int keycode)
{ {
switch(keycode) switch(keycode)
...@@ -521,10 +655,12 @@ void MyQT::importMesh(std::string& filename) ...@@ -521,10 +655,12 @@ void MyQT::importMesh(std::string& filename)
m_selected = NIL; m_selected = NIL;
m_selected2 = NIL; m_selected2 = NIL;
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ; bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
setParamObject(bb.maxSize(), bb.center().data()) ; setParamObject(bb.maxSize(), bb.center().data()) ;
m_shift = bb.maxSize()/200.0f; m_shift = bb.maxSize()/200.0f;
m_frame->setSize(bb.maxSize());
updateMap(); updateMap();
updateGLMatrices() ; updateGLMatrices() ;
} }
......
...@@ -37,12 +37,13 @@ ...@@ -37,12 +37,13 @@
#endif #endif
#include "Algo/Render/GL2/topo3Render.h" #include "Algo/Render/GL2/topo3Render.h"
#include "Algo/Geometry/boundingbox.h"
#include "ui_tuto_oper3.h" #include "ui_tuto_oper3.h"
#include "Utils/Qt/qtui.h" #include "Utils/Qt/qtui.h"
#include "Utils/Qt/qtSimple.h" #include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h" #include "Utils/cgognStream.h"
#include "Utils/frameManipulator.h"
using namespace CGoGN ; using namespace CGoGN ;
...@@ -69,11 +70,13 @@ class MyQT: public Utils::QT::SimpleQT ...@@ -69,11 +70,13 @@ class MyQT: public Utils::QT::SimpleQT
{ {
Q_OBJECT Q_OBJECT
public: public:
MyQT():nb(myMap),m_render_topo(NULL),m_selected(NIL),m_selected2(NIL),dm(myMap),m_shift(0.01f),m_ex1(0.9f),m_ex2(0.9f),m_ex3(0.9f) {} MyQT():nb(myMap),m_render_topo(NULL),m_selected(NIL),m_selected2(NIL),dm(myMap),m_shift(0.01f),m_ex1(0.9f),m_ex2(0.9f),m_ex3(0.9f), clip_volume(true) , hide_clipping(false) {}
void cb_redraw(); void cb_redraw();
void cb_initGL(); void cb_initGL();
void cb_mousePress(int button, int x, int y); void cb_mousePress(int button, int x, int y);
void cb_mouseRelease(int button, int x, int y);
void cb_mouseMove(int button, int x, int y);
void cb_keyPress(int code); void cb_keyPress(int code);
void cb_Open(); void cb_Open();
void cb_Save(); void cb_Save();
...@@ -88,6 +91,8 @@ protected: ...@@ -88,6 +91,8 @@ protected:
SelectorDartNoBoundary<PFP::MAP> nb; SelectorDartNoBoundary<PFP::MAP> nb;
Geom::BoundingBox<PFP::VEC3> bb;
// render (for the topo) // render (for the topo)
Algo::Render::GL2::Topo3Render* m_render_topo; Algo::Render::GL2::Topo3Render* m_render_topo;
Dart m_selected; Dart m_selected;
...@@ -98,6 +103,17 @@ protected: ...@@ -98,6 +103,17 @@ protected:
float m_ex1, m_ex2, m_ex3; float m_ex1, m_ex2, m_ex3;
// for clipping plane manipulation
bool clip_volume;
bool hide_clipping;
Utils::Pickable* m_PlanePick;
Utils::FrameManipulator* m_frame;
unsigned int m_pickedAxis;
int m_begX;
int m_begY;
int clip_id1;
int clip_id2;
// just for more compact writing // just for more compact writing
inline Dart PHI1(Dart d) {return myMap.phi1(d);} inline Dart PHI1(Dart d) {return myMap.phi1(d);}
inline Dart PHI_1(Dart d) {return myMap.phi_1(d);} inline Dart PHI_1(Dart d) {return myMap.phi_1(d);}
...@@ -116,6 +132,9 @@ public slots: ...@@ -116,6 +132,9 @@ public slots:
void operation(int x); void operation(int x);
void svg(); void svg();
void width(int w); void width(int w);
void clipping_onoff(bool x);
void hide_onoff(bool x);
}; };
#endif #endif
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>227</width> <width>215</width>
<height>369</height> <height>481</height>
</rect> </rect>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
...@@ -36,116 +36,129 @@ ...@@ -36,116 +36,129 @@
</size> </size>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<property name="margin"> <item row="1" column="0">
<number>2</number> <widget class="QSlider" name="widthSlider">
</property> <property name="minimum">
<property name="spacing"> <number>0</number>
<number>4</number> </property>
</property> <property name="maximum">
<number>10</number>
</property>
<property name="singleStep">
<number>0</number>
</property>
<property name="value">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="7" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>113</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="svg">
<property name="text">
<string>SnapshotSVG</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="checkBox_hide">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>hide clipping plane</string>
</property>
</widget>
</item>
<item row="0" column="0"> <item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout"> <widget class="QListWidget" name="listOper">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<item>
<property name="text">
<string>deleteVertex</string>
</property>
</item>
<item>
<property name="text">
<string>cutEdge</string>
</property>
</item>
<item>
<property name="text">
<string>uncutEdge</string>
</property>
</item>
<item> <item>
<widget class="QListWidget" name="listOper"> <property name="text">
<property name="focusPolicy"> <string>deleteEdge</string>
<enum>Qt::NoFocus</enum> </property>
</property>
<item>
<property name="text">
<string>deleteVertex</string>
</property>
</item>
<item>
<property name="text">
<string>cutEdge</string>
</property>
</item>
<item>
<property name="text">
<string>uncutEdge</string>
</property>
</item>
<item>
<property name="text">
<string>deleteEdge</string>
</property>
</item>
<item>
<property name="text">
<string>collapseEdge</string>
</property>
</item>
<item>
<property name="text">
<string>splitFace</string>
</property>
</item>
<item>
<property name="text">
<string>mergeVolume</string>
</property>
</item>
<item>
<property name="text">
<string>splitVolume</string>
</property>
</item>
<item>
<property name="text">
<string>collapseFace</string>
</property>
</item>
<item>
<property name="text">
<string>collapseVolume</string>
</property>
</item>
<item>
<property name="text">
<string>splitVertex</string>
</property>
</item>
</widget>
</item> </item>
<item> <item>
<widget class="QSlider" name="widthSlider"> <property name="text">
<property name="minimum"> <string>collapseEdge</string>
<number>0</number> </property>
</property>
<property name="maximum">
<number>10</number>
</property>
<property name="singleStep">
<number>0</number>
</property>
<property name="value">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="svg"> <property name="text">
<property name="text"> <string>splitFace</string>
<string>SnapshotSVG</string> </property>
</property>
</widget>
</item> </item>
<item> <item>
<spacer name="verticalSpacer"> <property name="text">
<property name="orientation"> <string>mergeVolume</string>
<enum>Qt::Vertical</enum> </property>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item> </item>
</layout> <item>
<property name="text">
<string>splitVolume</string>
</property>
</item>
<item>
<property name="text">
<string>collapseFace</string>
</property>
</item>
<item>
<property name="text">
<string>collapseVolume</string>
</property>
</item>
<item>
<property name="text">
<string>splitVertex</string>
</property>
</item>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="checkBox_plane">
<property name="text">
<string>clipping</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
......
...@@ -85,7 +85,7 @@ Dart splitVertex(typename PFP::MAP& map, std::vector<Dart>& vd) ...@@ -85,7 +85,7 @@ Dart splitVertex(typename PFP::MAP& map, std::vector<Dart>& vd)
std::cout << " - " << v.back(); std::cout << " - " << v.back();
v.push_back(map.phi1(map.phi2(map.phi_1(dit)))); v.push_back(map.phi1(map.phi2(map.phi_1(dit))));