Commit da95e06c authored by David Cazier's avatar David Cazier

-

parent 7ae912f0
......@@ -22,6 +22,10 @@ ENDIF(WIN32)
#define exec to compile
QT4_WRAP_CPP(tutoriel_moc ../tutoriel.h)
add_executable( tutoriel ../tutoriel.cpp ${tutoriel_moc})
target_link_libraries( tutoriel
${CGoGN_LIBS_R} ${CGoGN_EXT_LIBS} )
QT4_WRAP_CPP(polyhedronsView_moc ../polyhedronsView.h)
add_executable( polyhedronsView ../polyhedronsView.cpp ${polyhedronsView_moc})
......
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 PARTBASE_H
#define PARTBASE_H
#include "Geometry/vector_gen.h"
//#include "Geometry/vector_gen.h"
namespace CGoGN
{
......@@ -12,40 +12,38 @@ 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(typename PFP::VEC3 position) :
m_position(position),
m_state(FACE)
{
m_position.zero();
}
ParticleBase(VEC3 position)
{
m_position = position;
void setState(unsigned int state) {
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(typename PFP::VEC3 position)
{
m_position = position;
return true;
}
VEC3 getPosition() { return m_position; }
typename PFP::VEC3 getPosition() { return m_position; }
};
} // namespace MovingObjects
......
#ifndef PARTCELL_H
#define PARTCELL_H
#include "particle_base.h"
#include <iostream>
#include "Algo/Geometry/inclusion.h"
#include "Geometry/intersection.h"
#include "Geometry/orientation.h"
#include <iostream>
#include "Algo/Geometry/orientation.h"
#include "particle_base.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 +23,94 @@ 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;
public:
typedef typename PFP::MAP Map ;
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::TVEC3 TAB_POS;
typedef typename PFP::TVEC3 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) :
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)
{}
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, VEC3 point, 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);
Dart faceOrientationState(const VEC3& toward) ;
void faceState(const VEC3& current);
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;
this->ParticleBase<PFP>::move(goal) ;
}
};
} ;
#include "particle_cell_2D.hpp"
......
// #define DEBUG
template <typename PFP>
void ParticleCell2DMemo<PFP>::move(const VEC3& newCurrent)
......@@ -181,4 +180,4 @@ void ParticleCell2DMemo<PFP>::faceState(const VEC3& current)
else
this->state = EDGE;
}
}
\ No newline at end of file
}
......@@ -82,19 +82,19 @@ Geom::Orientation3D ParticleCell2DAndHalf<PFP>::getOrientationFace(VEC3 point, V
}
template <typename PFP>
void ParticleCell2DAndHalf<PFP>::vertexState(VEC3 current)
void ParticleCell2DAndHalf<PFP>::vertexState(VEC3 goal)
{
#ifdef DEBUG
CGoGNout << "vertexState" << d << CGoGNendl;
#endif
assert(std::isfinite(current[0]) && std::isfinite(current[1]) && std::isfinite(current[2]));
assert(gola.isfinite()) ;
crossCell = CROSS_OTHER;
if(Algo::Geometry::isPointOnVertex<PFP>(m,d,m_positions,current))
if(Algo::Geometry::isPointOnVertex<PFP>(m,d,m_positions,goal))
{
state = VERTEX;
m_position = current;
m_position = goal;
return;
}
else
......@@ -102,7 +102,7 @@ void ParticleCell2DAndHalf<PFP>::vertexState(VEC3 current)
//orientation step
if(m_positions[d][0] == m_positions[m.phi1(d)][0] && m_positions[d][1] == m_positions[m.phi1(d)][1])
d = m.alpha1(d);
if(getOrientationEdge(current,m.alpha1(d)) != Geom::UNDER)
if(getOrientationEdge(goal,m.alpha1(d)) != Geom::UNDER)
{
Dart dd_vert = d;
do
......@@ -110,19 +110,19 @@ void ParticleCell2DAndHalf<PFP>::vertexState(VEC3 current)
d = m.alpha1(d);
if(m_positions[d][0] == m_positions[m.phi1(d)][0] && m_positions[d][1] == m_positions[m.phi1(d)][1])
d = m.alpha1(d);
} while(getOrientationEdge(current, m.alpha1(d)) != Geom::UNDER && dd_vert != d);
} while(getOrientationEdge(goal, m.alpha1(d)) != Geom::UNDER && dd_vert != d);
if(dd_vert == d)
{
//orbit with 2 edges : point on one edge
if(m.alpha1(m.alpha1(d)) == d)
{
if(!Algo::Geometry::isPointOnHalfEdge<PFP>(m,d,m_positions,current))
if(!Algo::Geometry::isPointOnHalfEdge<PFP>(m,d,m_positions,goal))
d = m.alpha1(d);
}
else
{
m_position = current;
m_position = goal;
state = VERTEX;
return;
}
......@@ -131,7 +131,7 @@ void ParticleCell2DAndHalf<PFP>::vertexState(VEC3 current)
else
{
Dart dd_vert = m.alpha1(d);
while(getOrientationEdge(current, d) == Geom::OVER && dd_vert != d)
while(getOrientationEdge(goal, d) == Geom::OVER && dd_vert != d)
{
d = m.alpha_1(d);
if(m_positions[d][0] == m_positions[m.phi1(d)][0] && m_positions[d][1] == m_positions[m.phi1(d)][1])
......@@ -140,24 +140,24 @@ void ParticleCell2DAndHalf<PFP>::vertexState(VEC3 current)
}
//displacement step
if(getOrientationEdge(current, d) == Geom::ON && Algo::Geometry::isPointOnHalfEdge<PFP>(m, d, m_positions, current))
edgeState(current);
if(getOrientationEdge(goal, d) == Geom::ON && Algo::Geometry::isPointOnHalfEdge<PFP>(m, d, m_positions, goal))
edgeState(goal);
else
{
d = m.phi1(d);
faceState(current);
faceState(goal);
}
}
}
template <typename PFP>
void ParticleCell2DAndHalf<PFP>::edgeState(VEC3 current, Geom::Orientation3D sideOfEdge)
void ParticleCell2DAndHalf<PFP>::edgeState(VEC3 goal, Geom::Orientation3D sideOfEdge)
{
#ifdef DEBUG
CGoGNout << "edgeState" << d << CGoGNendl;
#endif
assert(std::isfinite(current[0]) && std::isfinite(current[1]) && std::isfinite(current[2]));
assert(goal.isfinite()) ;
// assert(Algo::Geometry::isPointOnEdge<PFP>(m,d,m_positions,m_position));
if(crossCell == NO_CROSS)
......@@ -169,21 +169,21 @@ void ParticleCell2DAndHalf<PFP>::edgeState(VEC3 current, Geom::Orientation3D sid
crossCell = CROSS_OTHER;
if(sideOfEdge == Geom::ON)
sideOfEdge = getOrientationEdge(current, d);
sideOfEdge = getOrientationEdge(goal, d);
switch(sideOfEdge)
{
case Geom::UNDER :
{
d = m.phi1(d);
faceState(current);
faceState(goal);
return;
}
case Geom::OVER:
{
//transform the displacement into the new entered face
VEC3 displ = current - m_position;
VEC3 displ = goal - m_position;
VEC3 n1 = Algo::Geometry::faceNormal<PFP>(m, d, m_positions);
VEC3 n2 = Algo::Geometry::faceNormal<PFP>(m, m.phi2(d), m_positions);
......@@ -192,10 +192,10 @@ void ParticleCell2DAndHalf<PFP>::edgeState(VEC3 current, Geom::Orientation3D sid
float angle = Geom::angle(n1, n2) ;
displ = Geom::rotate(axis, angle, displ) ;
current = m_position + displ;
goal = m_position + displ;
d = m.phi1(m.phi2(d));
faceState(current);
faceState(goal);
return;
}
......@@ -203,35 +203,35 @@ void ParticleCell2DAndHalf<PFP>::edgeState(VEC3 current, Geom::Orientation3D sid
state = EDGE;
}
if(!Algo::Geometry::isPointOnHalfEdge<PFP>(m, d, m_positions, current))
if(!Algo::Geometry::isPointOnHalfEdge<PFP>(m, d, m_positions, goal))
{
m_position = m_positions[d];
vertexState(current);
vertexState(goal);
return;
}
else if(!Algo::Geometry::isPointOnHalfEdge<PFP>(m, m.phi2(d), m_positions, current))
else if(!Algo::Geometry::isPointOnHalfEdge<PFP>(m, m.phi2(d), m_positions, goal))
{
d = m.phi2(d);
m_position = m_positions[d];
vertexState(current);
vertexState(goal);
return;
}
m_position = current;
m_position = goal;
}
template <typename PFP>
void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
void ParticleCell2DAndHalf<PFP>::faceState(VEC3 goal)
{
#ifdef DEBUG
CGoGNout << "faceState" << d << CGoGNendl;
#endif
assert(std::isfinite(m_position[0]) && std::isfinite(m_position[1]) && std::isfinite(m_position[2]));
assert(std::isfinite(current[0]) && std::isfinite(current[1]) && std::isfinite(current[2]));
assert(goal.isfinite()) ;
assert(this->getPosition().isFinite()) ;
// assert(Algo::Geometry::isPointInConvexFace2D<PFP>(m,d,m_positions,m_position,true));
//project current within face plane
//project goal within face plane
VEC3 n1 = Algo::Geometry::faceNormal<PFP>(m,d,m_positions);
VEC3 n2 = current - m_position;
// n1.normalize();
......@@ -242,17 +242,17 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
//track new position within map
Dart dd = d;
float wsoe = getOrientationFace(current, m_position, m.phi1(d));
float wsoe = getOrientationFace(goal, m_position, m.phi1(d));
// orientation step
if(wsoe != Geom::UNDER)
{
d = m.phi1(d);
wsoe = getOrientationFace(current, m_position, m.phi1(d));
wsoe = getOrientationFace(goal, m_position, m.phi1(d));
while(wsoe != Geom::UNDER && dd != d)
{
d = m.phi1(d);
wsoe = getOrientationFace(current, m_position, m.phi1(d));
wsoe = getOrientationFace(goal, m_position, m.phi1(d));
}
// source and position to reach are the same : verify if no edge is crossed due to numerical approximation
......@@ -260,15 +260,15 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
{
do
{
switch (getOrientationEdge(current, d))
switch (getOrientationEdge(goal, d))
{
case Geom::UNDER: d = m.phi1(d);
break;
case Geom::ON: m_position = current;
edgeState(current);
edgeState(goal);
return;
case Geom::OVER:
// CGoGNout << "smthg went bad " << m_position << " " << current << CGoGNendl;
// CGoGNout << "smthg went bad " << m_position << " " << goal << CGoGNendl;
// CGoGNout << "d1 " << m_positions[d] << " d2 " << m_positions[m.phi1(d)] << CGoGNendl;
m_position = intersectLineEdge(current, m_position, d);
// CGoGNout << " " << m_position << CGoGNendl;
......@@ -277,13 +277,13 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
return;
}
} while(d != dd);
m_position = current;
m_position = goal;
state = FACE;
// m_position = Algo::Geometry::faceCentroid<PFP>(m,d,m_positions);
// d = m.phi1(d);
// m_position = pointInFace(d);
// faceState(current);
// faceState(goal);
// m_position = m_positions[d];
// vertexState(current);
......@@ -294,11 +294,11 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
}
else
{
wsoe = getOrientationFace(current,m_position,d);
wsoe = getOrientationFace(goal,m_position,d);
while(wsoe == Geom::UNDER && m.phi_1(d) != dd)
{
d = m.phi_1(d);
wsoe = getOrientationFace(current, m_position, d);
wsoe = getOrientationFace(goal, m_position, d);
}
// in case of numerical incoherence
......@@ -307,37 +307,37 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
d = m.phi_1(d);
do
{
switch (getOrientationEdge(current, d))
switch (getOrientationEdge(goal, d))
{
case Geom::UNDER :
d = m.phi1(d);
break;
case Geom::ON :
// CGoGNout << "pic" << CGoGNendl;
m_position = current;
edgeState(current);
m_position = goal;
edgeState(goal);
return;
case Geom::OVER:
// CGoGNout << "smthg went bad(2) " << m_position << CGoGNendl;
m_position = intersectLineEdge(current, m_position, d);
m_position = intersectLineEdge(goal, m_position, d);
// CGoGNout << " " << m_position << CGoGNendl;
edgeState(current, Geom::OVER);
return;
}
} while(d != dd);
m_position = current;
m_position = goal;
state = FACE;
return;
}
}
//displacement step
switch (getOrientationEdge(current, d))
switch (getOrientationEdge(goal, d))
{
case Geom::UNDER :
distance += (current - m_position).norm();
m_position = current;
distance += (goal - m_position).norm();
m_position = goal;
state = FACE;
break;
default :
......@@ -347,7 +347,7 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
// d = m.phi1(d); //to check
// m_position = m_positions[d];
//
// vertexState(current);
// vertexState(goal);
}
else
{
......@@ -358,7 +358,7 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
distance += (isect - m_position).norm();
m_position = isect;
// CGoGNout << " inter : " << m_position << CGoGNendl;
edgeState(current, Geom::OVER);
edgeState(goal, Geom::OVER);
}
}
}
......
......@@ -47,7 +47,10 @@ class Vector
{
public:
typedef T DATA_TYPE ;
enum { DIMENSION = DIM } ;
enum
{
DIMENSION = DIM
} ;
static std::string CGoGNnameOfType() ;
......@@ -57,10 +60,10 @@ public:
Vector() ;
Vector(const Vector<DIM,T>& v) ;
Vector(const Vector<DIM, T>& v) ;
template <typename T2>
Vector(const Vector<DIM,T2>& v) ;
Vector(const Vector<DIM, T2>& v) ;
Vector(T x, T y) ;
......@@ -96,25 +99,25 @@ public:
/* ARITHMETIC SELF-OPERATORS */
/**********************************************/
Vector<DIM,T>& operator+=(const Vector<DIM,T>& v) ;
Vector<DIM, T>& operator+=(const Vector<DIM, T>& v) ;
Vector<DIM,T>& operator-=(const Vector<DIM,T>& v) ;
Vector<DIM, T>& operator-=(const Vector<DIM, T>& v) ;
Vector<DIM,T> operator*=(T a) ;
Vector<DIM, T> operator*=(T a) ;
Vector<DIM,T> operator/=(T a) ;
Vector<DIM, T> operator/=(T a) ;
/**********************************************/
/* ARITHMETIC OPERATORS */
/**********************************************/
Vector<DIM,T> operator+(const Vector<DIM,T>& v) const ;
Vector<DIM, T> operator+(const Vector<DIM, T>& v) const ;
Vector<DIM,T> operator-(const Vector<DIM,T>& v) const ;
Vector<DIM, T> operator-(const Vector<DIM, T>& v) const ;
Vector<DIM,T> operator*(T a) const ;
Vector<DIM, T> operator*(T a) const ;
Vector<DIM,T> operator/(T a) const ;
Vector<DIM, T> operator/(T a) const ;
/**********************************************/
/* UTILITY FUNCTIONS */
......@@ -127,19 +130,21 @@ public:
double normalize() ;
// dot product
T operator*(const Vector<DIM,T> v) const ;
T operator*(const Vector<DIM, T> v) const ;
// cross product
Vector<DIM,T> operator^(const Vector<DIM,T> v) const ;
Vector<DIM, T> operator^(const Vector<DIM, T> v) const ;
// Equal
bool operator==(const Vector<DIM,T>& v) const ;
bool operator==(const Vector<DIM, T>& v) const ;
// Different
bool operator!=(const Vector<DIM,T>& v) const ;
bool operator!=(const Vector<DIM, T>& v) const ;
bool hasNan() const ;
bool isNormal() const ;
/**
* Tests if the vector is normalized
* @param epsilon tolerated error
......@@ -153,59 +158,57 @@ public:
* @param epsilon tolerated error
* @return true if orthogonal
*/
bool isOrthogonal(const Vector<DIM,T>& V, const T& epsilon = 1e-5) const ;
bool isOrthogonal(const Vector<DIM, T>& V, const T& epsilon = 1e-5) const ;
/**********************************************/
/* STREAM OPERATORS */
/**********************************************/
template <unsigned int DD, typename TT>
friend std::ostream& operator<< (std::ostream& out, const Vector<DD,TT>& v) ;
friend std::ostream& operator<<(std::ostream& out, const Vector<DD, TT>& v) ;
template <unsigned int DD, typename TT>
friend std::istream& operator>> (std::istream& in, Vector<DD,TT>& v) ;
friend std::istream& operator>>(std::istream& in, Vector<DD, TT>& v) ;
private:
T m_data[DIM] ;
};
} ;
template <unsigned int DIM, typename T>
Vector<DIM,T> operator*(T a, const Vector<DIM,T>& v) ;
Vector<DIM, T> operator*(T a, const Vector<DIM, T>& v) ;
template <unsigned int DIM, typename T>
Vector<DIM,T> operator/(T a, const Vector<DIM,T>& v) ;
Vector<DIM, T> operator/(T a, const Vector<DIM, T>& v) ;
// returns the signed volume of the parallelepiped spanned by vectors v1, v2 and v3
template <unsigned int DIM, typename T>
T tripleProduct(const Vector<DIM,T>& v1, const Vector<DIM,T>& v2, const Vector<DIM,T>& v3) ;
T t