Commit ae5dff32 authored by Pierre Kraemer's avatar Pierre Kraemer

Merge cgogn.unistra.fr:~jund/CGoGN

Conflicts:
	Apps/deprecated/tutoriel.cpp
	apps_cmake.txt
	include/Topology/generic/dartmarker.h
parents 16ece449 d2c82ad7
This diff is collapsed.
......@@ -27,7 +27,7 @@
#include <iostream>
#include "Utils/qtSimple.h"
#include "Utils/Qt/qtSimple.h"
// forward definitions (minimize includes)
namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; } } } }
......
#ifndef FIRSTPLUGIN_H_
#define FIRSTPLUGIN_H_
#include "visualPlugin.h"
/**---CGoGN includes **/
#include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h"
#include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h"
#include "Topology/generic/parameters.h"
#include "Topology/generic/parameters.h"
#ifdef USE_GMAP
#include "Topology/gmap/embeddedGMap2.h"
#else
#include "Topology/map/embeddedMap2.h"
#endif
#ifdef USE_GMAP
#include "Topology/gmap/embeddedGMap2.h"
#else
#include "Topology/map/embeddedMap2.h"
#endif
#include "Algo/Render/GL2/topoRender.h"
#include "Algo/Render/GL2/topoRender.h"
/**---CGoGN includes **/
/**---Definitions specific to CGoGN ---*/
using namespace CGoGN ;
/**---Definitions specific to CGoGN ---*/
using namespace CGoGN ;
/**
* Struct that contains some informations about the types of the manipulated objects
* Mainly here to be used by the algorithms that are parameterized by it
*/
struct PFP: public PFP_STANDARD
{
// definition of the type of the map
#ifdef USE_GMAP
typedef EmbeddedGMap2 MAP;
#else
typedef EmbeddedMap2 MAP;
#endif
};
/**
* Struct that contains some informations about the types of the manipulated objects
* Mainly here to be used by the algorithms that are parameterized by it
*/
struct PFP: public PFP_STANDARD
{
// definition of the type of the map
#ifdef USE_GMAP
typedef EmbeddedGMap2 MAP;
#else
typedef EmbeddedMap2 MAP;
#endif
};
typedef PFP::MAP MAP;
typedef PFP::VEC3 VEC3;
typedef PFP::MAP MAP;
typedef PFP::VEC3 VEC3;
/**---Definitions specific to CGoGN ---*/
/**
......@@ -58,15 +54,17 @@
* of the Plugin interface (virtual class). It contains
* many useful and essantial methods.
*/
class FirstPlugin : public VisualPlugin{
class FirstPlugin : public VisualPlugin
{
/**
* Essential Qt macros.
*/
Q_OBJECT
Q_INTERFACES(Plugin)
public:
FirstPlugin(){}
~FirstPlugin(){}
FirstPlugin() {}
~FirstPlugin() {}
/**
* The classical call back for the initGL method
......@@ -92,6 +90,7 @@ public:
* If this methods return 'false', the plugin load will be aborted.
*/
bool activate();
/**
* The plugin's disabling method
* Each time the main application will unload the plugin
......@@ -99,23 +98,22 @@ public:
*/
void disable();
protected:
/** Attributes that are specific to this plugin **/
MAP myMap;
MAP myMap;
// attribute for vertices positions
VertexAttribute<VEC3> position;
// attribute for vertices positions
VertexAttribute<VEC3> position;
// render (for the topo)
Algo::Render::GL2::TopoRender* m_render_topo;
// render (for the topo)
Algo::Render::GL2::TopoRender* m_render_topo;
// 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); }
inline Dart PHI2(Dart d) { return myMap.phi2(d); }
template<int X>
Dart PHI(Dart d) { return myMap.phi<X>(d); }
// 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); }
inline Dart PHI2(Dart d) { return myMap.phi2(d); }
template<int X>
Dart PHI(Dart d) { return myMap.phi<X>(d); }
/** Attributes that are specific to this plugin **/
};
......
#include "firstPlugin.h"
#include "Algo/Geometry/boundingbox.h"
void FirstPlugin::cb_initGL(Scene* scene)
{
if(scene)
{
// we fit the first (possibly the only) view of the newly liked
// scene to the content of our map
bool FirstPlugin::activate(){
// creation of 2 new faces: 1 triangle and 1 square
Dart d1 = myMap.newFace(3);
Dart d2 = myMap.newFace(4);
// sew these faces along one of their edge
myMap.sewFaces(d1, d2);
// creation of a new attribute on vertices of type 3D vector for position.
// a handler to this attribute is returned
position = myMap.addAttribute<VEC3, VERTEX>("position");
// affect position by moving in the map
position[d1] = VEC3(0, 0, 0);
position[PHI1(d1)] = VEC3(2, 0, 0);
position[PHI_1(d1)] = VEC3(1, 2, 0);
position[PHI<11>(d2)] = VEC3(0, -2, 0);
position[PHI_1(d2)] = VEC3(2, -2, 0);
// bounding box of scene
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
m_render_topo=NULL;
scene->firstViewFitSphere(bb.center()[0], bb.center()[1], bb.center()[2], bb.maxSize());
return true;
}
m_render_topo = new Algo::Render::GL2::TopoRender() ;
void FirstPlugin::disable(){
if(m_render_topo){
delete m_render_topo;
// render the topo of the map without boundary darts
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f, nb);
}
}
void FirstPlugin::cb_redraw(Scene* scene){
void FirstPlugin::cb_redraw(Scene* scene)
{
m_render_topo->drawTopo();
}
void FirstPlugin::cb_initGL(Scene* scene){
if(scene){
//we fit the first (possibly the only) view of the newly liked
//scene to the content of our map
// bounding box of scene
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
bool FirstPlugin::activate()
{
// creation of 2 new faces: 1 triangle and 1 square
Dart d1 = myMap.newFace(3);
Dart d2 = myMap.newFace(4);
scene->firstViewFitSphere(bb.center()[0], bb.center()[1], bb.center()[2], bb.maxSize());
// sew these faces along one of their edge
myMap.sewFaces(d1, d2);
// creation of a new attribute on vertices of type 3D vector for position.
// a handler to this attribute is returned
position = myMap.addAttribute<VEC3, VERTEX>("position");
// affect position by moving in the map
position[d1] = VEC3(0, 0, 0);
position[PHI1(d1)] = VEC3(2, 0, 0);
position[PHI_1(d1)] = VEC3(1, 2, 0);
position[PHI<11>(d2)] = VEC3(0, -2, 0);
position[PHI_1(d2)] = VEC3(2, -2, 0);
m_render_topo = new Algo::Render::GL2::TopoRender() ;
m_render_topo=NULL;
// render the topo of the map without boundary darts
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f, nb);
return true;
}
void FirstPlugin::disable()
{
if(m_render_topo)
{
delete m_render_topo;
}
}
/**
* If we want to compile this plugin in debug mode,
* we also define a DEBUG macro at the compilation
*/
#ifndef DEBUG
//essential Qt function:
//arguments are
// essential Qt function:
// arguments are
// - the complied name of the plugin
// - the main class of our plugin (that extends VisualPlugin)
Q_EXPORT_PLUGIN2(FirstPlugin, FirstPlugin)
......
......@@ -20,7 +20,8 @@ class VBOHandler;
class Context;
class ViewButton;
class Scene : public QObject{
class Scene : public QObject
{
Q_OBJECT
public:
Scene(QString name, Window* window, Camera* sharedCamera=NULL);
......@@ -75,7 +76,6 @@ public:
bool addCustomViewButton(ViewButton* viewButton);
ViewButton* takeCustomViewButton(ViewButton* viewButton);
protected:
Window* m_window;
......@@ -97,5 +97,4 @@ signals:
void viewButtonClicked(View*, ViewButton*);
};
#endif
......@@ -15,7 +15,6 @@ IF (FORCE_MR EQUAL 1)
add_definitions(-DCGoGN_FORCE_MR=1)
ENDIF (FORCE_MR EQUAL 1)
# for CGoGN in one lib or not
file(STRINGS ${CGoGN_ROOT_DIR}/include/cgogn_onelib.h ONELIB_STR)
IF (ONELIB_STR EQUAL 1)
......@@ -26,28 +25,22 @@ ELSE (ONELIB_STR EQUAL 1)
SET(CGoGN_LIBS_R topology algo container utils)
ENDIF (ONELIB_STR EQUAL 1)
IF(WIN32)
set(CMAKE_PREFIX_PATH ${CGoGN_ROOT_DIR}/windows_dependencies CACHE STRING "path to dependencies")
ENDIF(WIN32)
find_package(OpenGL REQUIRED)
find_package(Boost COMPONENTS regex thread REQUIRED)
find_package(ZLIB REQUIRED)
find_package(LibXml2 REQUIRED)
find_package(GLEW REQUIRED)
IF (DEFINED ASSERTON)
add_definitions(-DCGOGN_ASSERT_BOOL=${ASSERTON})
ELSE (DEFINED ASSERTON)
add_definitions(-DCGOGN_ASSERT_BOOL=false)
ENDIF (DEFINED ASSERTON)
add_definitions(-DSHADERPATH="${CGoGN_ROOT_DIR}/lib/Shaders/")
# define includes of external libs
......@@ -97,7 +90,6 @@ IF (WITH_NUMERICAL)
SET (COMMON_LIBS ${COMMON_LIBS} numerical lapack blas f2c)
ENDIF (WITH_NUMERICAL)
# qq definition specifiques pour mac
IF(APPLE)
# attention a changer pour chercher la bonne version automatiquement
......@@ -123,6 +115,3 @@ IF(WIN32)
ELSE (WIN32)
link_directories( ${CGoGN_ROOT_DIR}/lib/Debug ${CGoGN_ROOT_DIR}/lib/Release)
ENDIF (WIN32)
......@@ -38,6 +38,9 @@ namespace Algo
namespace BooleanOperator
{
template <typename PFP>
bool isBetween(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, Dart d, Dart e, Dart f) ;
template <typename PFP>
void mergeVertex(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, Dart d, Dart e);
......
......@@ -31,41 +31,57 @@ namespace Algo
namespace BooleanOperator
{
template <typename PFP>
bool isBetween(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, Dart d, Dart e, Dart f)
{
return CGoGN::Geom::isBetween(positions[map.phi1(d)]-positions[d],
positions[map.phi1(e)]-positions[e],
positions[map.phi1(f)]-positions[f]);
}
template <typename PFP>
void mergeVertex(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, Dart d, Dart e)
{
assert(Geom::arePointsEquals(positions[d],positions[e]) && !map.sameVertex(d,e));
Dart dd;
do
{
dd = map.phi2_1(d);
map.removeEdgeFromVertex(dd);
Dart ee = e;
do
{
if(Geom::testOrientation2D(positions[map.phi1(dd)],positions[ee],positions[map.phi1(ee)])!=Geom::RIGHT
&& Geom::testOrientation2D(positions[map.phi1(dd)],positions[ee],positions[map.phi1(map.phi2_1(ee))])==Geom::RIGHT)
{
break;
}
ee = map.phi2_1(ee);
} while(ee != e);
map.insertEdgeInVertex(ee,dd);
} while(dd!=d);
// d1 traverses the vertex of d (following the alpha1 permutation)
// y is a temporay buffer to stop the loop
Dart d1=d;
// e1 traverses the vertex of e (following the alpha1 permutation)
Dart e1=e;
bool notempty = true;
do {
if (map.phi2_1(e1) == e1) notempty = false;
// detach z from its vertex
map.removeEdgeFromVertex(e1);
// Searchs the dart of the vertex of x where tz may be inserted
Dart nd1 = d1;
do {
if (CGoGN::Algo::BooleanOperator::isBetween<PFP>(map,positions,e1,d1,map.phi2_1(d1))) break;
d1 = map.phi2_1(d1);
} while (d1 != nd1);
map.insertEdgeInVertex(d1,e1);
d1 = e1;
} while (notempty);
// 0-embed z on the vertex of x without copy of the vertex
// positions[d] = ;
}
template <typename PFP>
void mergeVertices(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions)
{
// TODO optimiser en triant les sommets
for(Dart d = map.begin() ; d != map.end() ; map.next(d))
{
CellMarker<VERTEX> vM(map);
vM.mark(d);
std::cout << "." ; std::cout.flush() ;
for(Dart dd = map.begin() ; dd != map.end() ; map.next(dd))
{
if(!vM.isMarked(dd))
{
vM.mark(dd);
if(Geom::arePointsEquals(positions[d],positions[dd]))
{
mergeVertex<PFP>(map,positions,d,dd);
......
......@@ -55,10 +55,10 @@ void exportMeshPlain(std::ofstream& out, typename PFP::MAP& map, VertexAttribute
Dart dd = d;
do
{
out << "<" << position[dd][0] << "," << position[dd][1] << "," << position[dd][2] << ">," << std::endl;
out << "<" << position[dd][0] << "," << position[dd][2] << "," << position[dd][1] << ">," << std::endl;
dd = map.phi1(dd);
} while(dd!=d);
out << "<" << position[d][0] << "," << position[d][1] << "," << position[d][2] << ">" << std::endl;
out << "<" << position[d][0] << "," << position[d][2] << "," << position[d][1] << ">" << std::endl;
out << "}" << std::endl;
}
}
......
......@@ -42,6 +42,12 @@ namespace Import
*/
bool checkXmlNode(xmlNodePtr node, const std::string& name);
template <typename PFP>
void readCoordAndStyle(xmlNode* cur_path,
std::vector<std::vector<VEC3 > >& allPoly,
std::vector<std::vector<VEC3 > >& allBrokenLines,
std::vector<float>& allBrokenLinesWidth);
template <typename PFP>
bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttribute<typename PFP::VEC3>& position, CellMarker<EDGE>& polygons, CellMarker<FACE>& polygonsFaces);
......
This diff is collapsed.
#ifndef PARTBASE_H
#define PARTBASE_H
#include "Geometry/vector_gen.h"
//#include "Geometry/vector_gen.h"
namespace CGoGN
{
......@@ -12,41 +12,42 @@ namespace Algo
namespace MovingObjects
{
typedef Geom::Vec3f VEC3;
/* A particle base defines a position with a displacement function */
template <typename PFP>
class ParticleBase
{
public :
VEC3 m_position;
private:
typename PFP::VEC3 m_position ;
unsigned int m_state ;
ParticleBase()
public:
ParticleBase(const typename PFP::VEC3& position) :
m_position(position), m_state(FACE)
{
m_position.zero();
}
ParticleBase(VEC3 position)
void setState(unsigned int state)
{
m_position = position;
m_state = state ;
}
virtual unsigned int getState()
unsigned int getState()
{
return 0;
return m_state ;
}
/**
* @param newPosition new position to reach
*/
virtual bool move(VEC3 position)
bool move(const typename PFP::VEC3& position)
{
m_position = position;
return true;
m_position = position ;
return true ;
}
VEC3 getPosition() { return m_position; }
};
const typename PFP::VEC3& getPosition() const
{
return m_position ;
}
} ;
} // namespace MovingObjects
......
......@@ -2,14 +2,14 @@
#define PARTCELL_H
#include "Algo/MovingObjects/particle_base.h"
#include "Algo/Geometry/inclusion.h"
#include "Geometry/intersection.h"
#include "Geometry/orientation.h"
#include <iostream>
#include "Algo/Geometry/orientation.h"
/* A particle cell is a particle base within a map, within a precise cell, the displacement function should indicate
after each displacement wherein lies the new position of the particle */
/* A particle cell is a particle base within a map, within a precise cell,
* the displacement function should indicate after each displacement
* wherein lies the new position of the particle
*/
namespace CGoGN
{
......@@ -20,84 +20,92 @@ namespace Algo
namespace MovingObjects
{
enum {
NO_CROSS,
CROSS_EDGE,
CROSS_OTHER
};
enum
{
NO_CROSS, CROSS_EDGE, CROSS_OTHER
} ;
template <typename PFP>
class ParticleCell2D : public ParticleBase
class ParticleCell2D : public ParticleBase<PFP>
{
public :
typedef typename PFP::MAP Map;
typedef typename PFP::VEC3 VEC3;
typedef VertexAttribute<typename PFP::VEC3> TAB_POS;
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef VertexAttribute<VEC3> TAB_POS ;
Map& m;
MAP& m ;
const TAB_POS& m_positions;
Dart d;
Dart lastCrossed;
const TAB_POS& positionAttribut ;
unsigned int state;
Dart d ;
Dart lastCrossed ;
unsigned int crossCell ;
ParticleCell2D(Map& map) : m(map)
{}
ParticleCell2D(Map& map, Dart belonging_cell, VEC3 pos, const TAB_POS& tabPos) :
ParticleBase(pos), m(map), m_positions(tabPos), d(belonging_cell), lastCrossed(belonging_cell), state(FACE), crossCell(NO_CROSS)
{}
ParticleCell2D(MAP& map, Dart belonging_cell, const VEC3& pos, const TAB_POS& tabPos) :
ParticleBase<PFP>(pos),
m(map),
positionAttribut(tabPos),
d(belonging_cell),
lastCrossed(belonging_cell),
crossCell(NO_CROSS)
{
}
Dart getCell() { return d; }
Dart getCell()
{
return d ;
}
Geom::Orientation2D getOrientationEdge(const VEC3& point, Dart d);
Geom::Orientation2D getOrientationEdge(const VEC3& point, Dart d) ;
void display();
void display() ;
// template <unsigned int DD, typename TT>
// friend std::istream& operator>> (std::istream& in, Vector<DD,TT>& v) ;
VEC3 pointInFace(Dart d);
VEC3 pointInFace(Dart d) ;
VEC3 intersectLineEdge(const VEC3& pA, const VEC3& pB, Dart d);
VEC3 intersectLineEdge(const VEC3& pA, const VEC3& pB, Dart d) ;
Geom::Orientation2D getOrientationFace(VEC3 sourcePoint, VEC3 point, Dart d);
Geom::Orientation2D getOrientationFace(VEC3 sourcePoint, Dart d) ;
void vertexState(const VEC3& current);
void vertexState(const VEC3& current) ;
void edgeState(const VEC3& current, Geom::Orientation2D sideOfEdge=Geom::ALIGNED);
void edgeState(const VEC3& current, Geom::Orientation2D sideOfEdge = Geom::ALIGNED) ;
//just an orientation test : check which dart is aimed to leave the current face to reach an other position
Dart faceOrientationState(const VEC3& toward);
void faceState(const VEC3& current);
Dart faceOrientationState(const VEC3& toward) ;
virtual unsigned int getState()
{
return state;
}
void faceState(const VEC3& current) ;
void move(const VEC3& newCurrent)
void move(const VEC3& goal)
{
crossCell = NO_CROSS ;
if(!Geom::arePointsEquals(newCurrent, m_position))
if (!Geom::arePointsEquals(goal, this->getPosition()))
{
switch(state) {
case VERTEX : vertexState(newCurrent); break;
case EDGE : edgeState(newCurrent); break;
case FACE : faceState(newCurrent); break;
switch (this->getState())
{
case VERTEX :
vertexState(goal) ;
break ;
case EDGE :
edgeState(goal) ;
break ;
case FACE :
faceState(goal) ;
break ;
}
display();
display() ;
}
else
m_position = newCurrent;
{
// TODO Des petits pas répétés peuvent faire sortir de la cellule actuelle
this->ParticleBase<PFP>::move(goal) ;
}
}
};
} ;
#include "particle_cell_2D.hpp"
......
#ifndef PARTCELL2DMEMO_H
#define PARTCELL2DMEMO_H
//#define DEBUG
#include "particle_cell_2D.h"
#include "Algo/Geometry/inclusion.h"
......@@ -9,7 +9,7 @@
#include <iostream>
/* A particle cell is a particle base within a map, within a precise cell, the displacement function should indicate
after each displacement wherein lies the new position of the particle */
after each displacement wherein lies the new position of the particle */
namespace CGoGN
{
......@@ -24,29 +24,35 @@ template <typename PFP>
class ParticleCell2DMemo : public ParticleCell2D<PFP>
{
public :
typedef typename PFP::MAP Map;
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3;
typedef VertexAttribute<typename PFP::VEC3> TAB_POS;
typedef VertexAttribute<typename PFP::VEC3> TAB_POS ;
private:
ParticleCell2DMemo(){
}