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)
sqt.setCallBack( sqt.dock.listOper, SIGNAL(currentRowChanged(int)), SLOT(operation(int)) );
sqt.setCallBack( sqt.dock.svg, SIGNAL(clicked()), SLOT(svg()) );
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;
if (argc==2)
n = atoi(argv[1]);
......@@ -62,6 +64,36 @@ int main(int argc, char **argv)
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)
{
switch(x)
......@@ -191,8 +223,8 @@ void MyQT::operation(int x)
Dart dit = m_selecteds.front();
PFP::VEC3 Q = (position[myMap.phi1(m_selected)] + position[m_selected])/2.0f;
//PFP::VEC3 c1 = Algo::Geometry::volumeCentroid<PFP>(myMap, dit, position);
//Dart dres = myMap.splitVertex(m_selecteds);
Dart dres = Algo::Modelisation::Tetrahedralization::splitVertex<PFP>(myMap, m_selecteds);
Dart dres = myMap.splitVertex(m_selecteds);
//Dart dres = Algo::Modelisation::Tetrahedralization::splitVertex<PFP>(myMap, m_selecteds);
position[dres] = position[dit] + Q*0.25f;
//position[dit] = position[dit] - c1*0.5f;
m_selecteds.clear();
......@@ -220,17 +252,8 @@ void MyQT::createMap(int n)
prim.hexaGrid_topo(n,n,n);
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
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
setParamObject(bb.maxSize(), bb.center().data()) ;
m_shift = bb.maxSize()/200.0f;
......@@ -254,6 +277,20 @@ void MyQT::cb_initGL()
{
glClearColor(1.0f,1.0f,1.0f,1.0f);
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)
......@@ -276,6 +313,12 @@ void MyQT::cb_redraw()
{
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)
......@@ -294,6 +337,29 @@ void MyQT::cb_mousePress(int button, int x, int y)
m_selected2 = d;
}
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())
......@@ -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)
{
switch(keycode)
......@@ -521,10 +655,12 @@ void MyQT::importMesh(std::string& filename)
m_selected = 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()) ;
m_shift = bb.maxSize()/200.0f;
m_frame->setSize(bb.maxSize());
updateMap();
updateGLMatrices() ;
}
......
......@@ -37,12 +37,13 @@
#endif
#include "Algo/Render/GL2/topo3Render.h"
#include "Algo/Geometry/boundingbox.h"
#include "ui_tuto_oper3.h"
#include "Utils/Qt/qtui.h"
#include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h"
#include "Utils/frameManipulator.h"
using namespace CGoGN ;
......@@ -69,11 +70,13 @@ class MyQT: public Utils::QT::SimpleQT
{
Q_OBJECT
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_initGL();
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_Open();
void cb_Save();
......@@ -88,6 +91,8 @@ protected:
SelectorDartNoBoundary<PFP::MAP> nb;
Geom::BoundingBox<PFP::VEC3> bb;
// render (for the topo)
Algo::Render::GL2::Topo3Render* m_render_topo;
Dart m_selected;
......@@ -98,6 +103,17 @@ protected:
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
inline Dart PHI1(Dart d) {return myMap.phi1(d);}
inline Dart PHI_1(Dart d) {return myMap.phi_1(d);}
......@@ -116,6 +132,9 @@ public slots:
void operation(int x);
void svg();
void width(int w);
void clipping_onoff(bool x);
void hide_onoff(bool x);
};
#endif
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>227</width>
<height>369</height>
<width>215</width>
<height>481</height>
</rect>
</property>
<property name="minimumSize">
......@@ -36,116 +36,129 @@
</size>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>2</number>
</property>
<property name="spacing">
<number>4</number>
</property>
<item row="1" column="0">
<widget class="QSlider" name="widthSlider">
<property name="minimum">
<number>0</number>
</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">
<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>
<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>
<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>
<property name="text">
<string>deleteEdge</string>
</property>
</item>
<item>
<widget class="QSlider" name="widthSlider">
<property name="minimum">
<number>0</number>
</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>
<property name="text">
<string>collapseEdge</string>
</property>
</item>
<item>
<widget class="QPushButton" name="svg">
<property name="text">
<string>SnapshotSVG</string>
</property>
</widget>
<property name="text">
<string>splitFace</string>
</property>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
<property name="text">
<string>mergeVolume</string>
</property>
</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>
</layout>
</widget>
......
......@@ -85,7 +85,7 @@ Dart splitVertex(typename PFP::MAP& map, std::vector<Dart>& vd)
std::cout << " - " << v.back();
v.push_back(map.phi1(map.phi2(map.phi_1(dit))));
std::cout << " - " << v.back() << "]" << std::endl;
//map.splitVolume(v);
map.splitVolume(v);
}
return dres;
......
/*******************************************************************************
* 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 __MAP2MR_PM__
#define __MAP2MR_PM__
#include "Topology/map/embeddedMap2.h"
#include "Topology/generic/traversorCell.h"
#include "Topology/generic/traversor2.h"
#include "Algo/Decimation/selector.h"
#include "Algo/Decimation/edgeSelector.h"
#include "Algo/Decimation/geometryApproximator.h"
#include "Algo/Decimation/geometryPredictor.h"
#include "Algo/Decimation/lightfieldApproximator.h"
namespace CGoGN
{
namespace Algo
{
namespace Multiresolution
{
template <typename PFP>
class Map2MR_PM
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
private:
MAP& m_map ;
VertexAttribute<VEC3>& m_position;
bool shareVertexEmbeddings ;
//SelectorUnmarked dartSelect ;
bool m_initOk ;
Algo::Decimation::EdgeSelector<PFP>* m_selector ;
std::vector<Algo::Decimation::ApproximatorGen<PFP>*> m_approximators ;
std::vector<Algo::Decimation::PredictorGen<PFP>*> m_predictors ;
Algo::Decimation::Approximator<PFP, VEC3>* m_positionApproximator ;
public:
Map2MR_PM(MAP& map, VertexAttribute<VEC3>& position,
Algo::Decimation::SelectorType s, Algo::Decimation::ApproximatorType a) ;
~Map2MR_PM();
//add a coarse level
void addNewLevel() ;
//coarsen the mesh -> analysis
void coarsen() ;
//refine the mesh -> synthesis
void refine() ;
} ;
} // namespace Multiresolution
} // namespace Algo
} // namespace CGoGN
#include "Algo/Multiresolution/map2MR/map2MR_PM.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 *