Commit ed9da781 authored by Pierre Kraemer's avatar Pierre Kraemer

Merge cgogn:~cgogn/CGoGN

parents 71d3a2da 351c36b2
......@@ -36,6 +36,11 @@ add_executable(test_traversor2 test_traversor2.cpp ${test_traversor2_ui} ${test
target_link_libraries(test_traversor2 ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS})
QT4_WRAP_UI( testPlaneCutting_ui testPlaneCutting.ui )
QT4_WRAP_CPP(testPlaneCutting_moc testPlaneCutting.h)
add_executable(testPlaneCutting testPlaneCutting.cpp ${testPlaneCutting_ui} ${testPlaneCutting_moc})
target_link_libraries(testPlaneCutting ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS})
# Example with Qt
#
#QT4_WRAP_CPP(tuto1_moc tuto1.h)
......
This diff is collapsed.
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
......@@ -22,94 +22,119 @@
* *
*******************************************************************************/
#ifndef __VPMESH__
#define __VPMESH__
#include <iostream>
//TODO add this file with git !!!
#include "Algo/VolumetricProgressiveMesh/vsplit.h"
#include "Utils/Qt/qtQGLV.h"
#include "ui_testPlaneCutting.h"
#include "Utils/Qt/qtui.h"
#include "Algo/Decimation/selector.h"
#include "Algo/Decimation/edgeSelector.h"
#include "Algo/Decimation/geometryApproximator.h"
#include "Algo/Decimation/geometryPredictor.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Utils/quantization.h"
#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"
namespace CGoGN
{
#include "Algo/Import/import.h"
#include "Algo/Export/export.h"
namespace Algo
{
#include "Algo/Render/GL2/mapRender.h"
#include "Algo/Render/GL2/topoRender.h"
namespace Volume
{
#include "Utils/Shaders/shaderPhong.h"
#include "Utils/Shaders/shaderFlat.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderVectorPerVertex.h"
#include "Utils/pointSprite.h"
#include "Utils/text3d.h"
#include "Utils/vbo.h"
namespace VPMesh
{
#include "Utils/Qt/qtInputs.h"
template <typename PFP>
class VolumetricProgressiveMesh
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Geometry/normal.h"
#include "Algo/Geometry/convexity.h"
private:
MAP& m_map ;
VertexAttribute<typename PFP::VEC3>& positionsTable ;
using namespace CGoGN ;
DartMarker& inactiveMarker ;
SelectorUnmarked dartSelect ;
Algo::Decimation::EdgeSelector<PFP>* m_selector ;
std::vector<Algo::Decimation::ApproximatorGen<PFP>*> m_approximators ;
std::vector<Algo::Decimation::PredictorGen<PFP>*> m_predictors ;
std::vector<VSplit<PFP>*> m_splits ;
unsigned int m_cur ;
struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedMap2 MAP ;
};
Algo::Decimation::Approximator<PFP, VEC3>* m_positionApproximator ;
typedef PFP::MAP MAP ;
typedef PFP::VEC3 VEC3 ;
bool m_initOk ;
class Viewer : public Utils::QT::SimpleQGLV
{
Q_OBJECT
public:
VolumetricProgressiveMesh(
MAP& map, DartMarker& inactive,
Algo::Decimation::SelectorType s, Algo::Decimation::ApproximatorType a,
VertexAttribute<typename PFP::VEC3>& position
) ;
MAP myMap ;
Utils::QT::uiDockInterface dock ;
enum renderMode { FLAT, PHONG } ;
~VolumetricProgressiveMesh() ;
Geom::Vec4f colDif ;
Geom::Vec4f colSpec ;
Geom::Vec4f colClear ;
Geom::Vec4f colNormal ;
bool initOk() { return m_initOk ; }
float shininess ;
void createPM(unsigned int percentWantedVertices) ;
Geom::BoundingBox<PFP::VEC3> bb ;
float normalBaseSize ;
float normalScaleFactor ;
float vertexBaseSize ;
float vertexScaleFactor ;
float faceShrinkage ;
std::vector<VSplit<PFP>*>& splits() { return m_splits ; }
Algo::Decimation::EdgeSelector<PFP>* selector() { return m_selector ; }
std::vector<Algo::Decimation::ApproximatorGen<PFP>*>& approximators() { return m_approximators ; }
std::vector<Algo::Decimation::PredictorGen<PFP>*>& predictors() { return m_predictors ; }
int m_renderStyle ;
bool m_drawVertices ;
bool m_drawEdges ;
bool m_drawFaces ;
bool m_drawNormals ;
bool m_drawTopo ;
bool m_drawBoundaryTopo;
void edgeCollapse(VSplit<PFP>* vs) ;
void vertexSplit(VSplit<PFP>* vs) ;
VertexAttribute<VEC3> position ;
VertexAttribute<VEC3> normal ;
void coarsen() ;
void refine() ;
Algo::Render::GL2::MapRender* m_render ;
Algo::Render::GL2::TopoRender* m_topoRender ;
void gotoLevel(unsigned int l) ;
unsigned int& currentLevel() { return m_cur ; }
unsigned int nbSplits() { return m_splits.size() ; }
Utils::VBO* m_positionVBO ;
Utils::VBO* m_normalVBO;
} ;
Utils::ShaderPhong* m_phongShader ;
Utils::ShaderFlat* m_flatShader ;
Utils::ShaderVectorPerVertex* m_vectorShader ;
Utils::ShaderSimpleColor* m_simpleColorShader ;
Utils::PointSprite* m_pointSprite ;
} //namespace PMesh
Viewer() ;
}
void initGUI() ;
} //namespace Algo
void cb_initGL() ;
void cb_redraw() ;
void cb_Open() ;
void cb_Save() ;
} //namespace CGoGN
void cb_keyPress(int keycode);
#include "Algo/VolumetricProgressiveMesh/vpmesh.hpp"
void importMesh(std::string& filename) ;
void exportMesh(std::string& filename, bool askExportMode = true);
#endif
public slots:
void slot_drawVertices(bool b) ;
void slot_verticesSize(int i) ;
void slot_drawEdges(bool b) ;
void slot_drawFaces(bool b) ;
void slot_faceLighting(int i) ;
void slot_drawTopo(bool b) ;
void slot_drawNormals(bool b) ;
void slot_normalsSize(int i) ;
};
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DockWidget</class>
<widget class="QDockWidget" name="DockWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>174</width>
<height>393</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>174</width>
<height>393</height>
</size>
</property>
<property name="windowTitle">
<string>Commands</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Visu</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="check_drawVertices">
<property name="text">
<string>draw vertices</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="slider_verticesSize">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawEdges">
<property name="text">
<string>draw edges</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawFaces">
<property name="text">
<string>draw faces</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="combo_faceLighting">
<item>
<property name="text">
<string>FLAT</string>
</property>
</item>
<item>
<property name="text">
<string>PHONG</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawTopo">
<property name="text">
<string>draw topo</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawNormals">
<property name="text">
<string>draw normals</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="slider_normalsSize">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</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>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>check_drawFaces</sender>
<signal>toggled(bool)</signal>
<receiver>combo_faceLighting</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>65</x>
<y>98</y>
</hint>
<hint type="destinationlabel">
<x>65</x>
<y>127</y>
</hint>
</hints>
</connection>
<connection>
<sender>check_drawNormals</sender>
<signal>toggled(bool)</signal>
<receiver>slider_normalsSize</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>75</x>
<y>191</y>
</hint>
<hint type="destinationlabel">
<x>75</x>
<y>222</y>
</hint>
</hints>
</connection>
<connection>
<sender>check_drawVertices</sender>
<signal>toggled(bool)</signal>
<receiver>slider_verticesSize</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>75</x>
<y>44</y>
</hint>
<hint type="destinationlabel">
<x>75</x>
<y>75</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -106,6 +106,8 @@ void MyQT::squareTiling(int code)
Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,10,10,true);
g.embedIntoGrid(position,50,50);
g.exportPositions(position, "grid.bs");
break;
}
case 2:
......@@ -114,14 +116,18 @@ void MyQT::squareTiling(int code)
Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,10,10,true);
g.embedIntoTwistedStrip(position, 0.3, 0.8, 5);
g.exportPositions(position, "gridtwisted.bs");
break;
}
case 3:
{
std::cout << "square grid helocoid tiling" << std::endl;
std::cout << "square grid helicoid tiling" << std::endl;
Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,20,20,true);
g.embedIntoHelicoid(position, 0.3, 0.8, 5.0, 2.0);
g.exportPositions(position, "gridhelicoid.bs");
break;
}
case 4:
......@@ -130,6 +136,8 @@ void MyQT::squareTiling(int code)
Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
c.embedIntoCylinder(position,0.5,0.7,5.0);
c.exportPositions(position, "cylinder.bs");
break;
}
case 5:
......@@ -168,14 +176,17 @@ void MyQT::squareTiling(int code)
Algo::Surface::Tilings::Square::Cube<PFP> c(myMap,20,20,20);
c.embedIntoCube(position,5.0,5.0, 5.0);
c.exportPositions(position, "cube.bs");
break;
}
case 9:
{
std::cout << "square cylinder cone tiling" << std::endl;
std::cout << "square tore tiling" << std::endl;
Algo::Surface::Tilings::Square::Tore<PFP> c(myMap,20,10);
c.embedIntoTore(position,5.0,2.0);
c.exportPositions(position, "tore.bs");
break;
}
......@@ -184,6 +195,8 @@ void MyQT::squareTiling(int code)
break;
}
}
myMap.check();
}
// mouse picking
......
/*******************************************************************************
* 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 __APPROXIMATOR_VOLUMES_H__
#define __APPROXIMATOR_VOLUMES_H__
#include "Algo/DecimationVolumes/operator.h"
#include "Algo/DecimationVolumes/predictor.h"
namespace CGoGN
{
namespace Algo
{
namespace Volume
{
namespace Decimation
{
enum ApproximatorType
{
A_QEM,
A_MidEdge,
A_MidFace,
A_MidVolume,
A_hHalfEdgeCollapse,
A_QEM
};
template <typename PFP>
class ApproximatorGen
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
protected:
MAP& m_map ;
public:
ApproximatorGen(MAP& m) : m_map(m)
{}
virtual ~ApproximatorGen()
{}
virtual const std::string& getApproximatedAttributeName(unsigned int index = 0) const = 0 ;
virtual ApproximatorType getType() const = 0 ;
virtual bool init() = 0 ;
virtual void approximate(Dart d) = 0 ;
virtual void saveApprox(Dart d) = 0 ;
virtual void affectApprox(Dart d) = 0 ;
virtual const PredictorGen<PFP>* getPredictor() const = 0 ;
} ;
template <typename PFP, typename T, unsigned int ORBIT>
class Approximator : public ApproximatorGen<PFP>
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL;
protected:
Predictor<PFP, T>* m_predictor ;
std::vector<VertexAttribute<T>* > m_attrV ; // vertex attributes to be approximated
std::vector<AttributeHandler<T,ORBIT> > m_approx ; // attributes to store approximation result
std::vector<AttributeHandler<T,ORBIT> > m_detail ; // attributes to store detail information for reconstruction
std::vector<T> m_app ;
public:
Approximator(MAP& m, std::vector<VertexAttribute<T>* > va, Predictor<PFP, T> * predictor) :
ApproximatorGen<PFP>(m), m_predictor(predictor), m_attrV(va)
{
const unsigned int& size = m_attrV.size() ;
assert(size > 0 || !"Approximator: no attributes provided") ;
m_approx.resize(size) ;
m_detail.resize(size) ;
m_app.resize(size) ;
for (unsigned int i = 0 ; i < size ; ++i)
{
if (!m_attrV[i]->isValid())
std::cerr << "Approximator Warning: attribute number " << i << " is not valid" << std::endl ;
std::stringstream aname ;
aname << "approx_" << m_attrV[i]->name() ;
m_approx[i] = this->m_map.template addAttribute<T, ORBIT>(aname.str()) ;
if(m_predictor) // if predictors are associated to the approximator
{ // create attributes to store the details needed for reconstruction
std::stringstream dname ;
dname << "detail_" << m_attrV[i]->name() ;
m_detail[i] = this->m_map.template addAttribute<T, ORBIT>(dname.str()) ;
}
}
}
virtual ~Approximator()
{
for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
{
this->m_map.template removeAttribute(m_approx[i]) ;
if(m_predictor)
this->m_map.template removeAttribute(m_detail[i]) ;
}
}
const std::string& getApproximatedAttributeName(unsigned int index = 0) const
{
return m_attrV[index]->name() ;
}
unsigned int getNbApproximated() const
{
return m_attrV.size() ;
}
void saveApprox(Dart d)
{
for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
m_app[i] = m_approx[i][d] ;
}
void affectApprox(Dart d)
{
for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
m_attrV[i]->operator[](d) = m_app[i] ;
}
const T& getApprox(Dart d, unsigned int index = 0) const
{
return m_approx[index][d] ;
}
const VertexAttribute<T>& getAttr(unsigned int index = 0) const
{
return *(m_attrV[index]) ;
}
std::vector<T> getAllApprox(Dart d) const
{
std::vector<T> res ;
res.resize(m_attrV.size()) ;
for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
res[i] = m_approx[i][d] ;
return res ;
}
const Predictor<PFP, T>* getPredictor() const
{
return m_predictor ;
}