Commit 1ee70274 authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'develop' of cgogn:~kraemer/CGoGN into develop

parents c66ab714 19872ac9
......@@ -59,10 +59,14 @@ int main()
// easy way to find the central vertex of the grid
Vertex v;
// findCell(VERTEX,v,MAP,myMap, position[v] == VEC3(0,0,0) );
find_cell<VERTEX>(myMap,v, [&](Vertex v)
foreach_cell_until<VERTEX>(myMap, [&] (Vertex it)
{
return position[v] == VEC3(0,0,0);
if (position[it] == VEC3(0,0,0))
{
v = it;
return true;
}
return false;
});
// must test of find ok (if not v.dart is NIL)
......@@ -73,14 +77,14 @@ int main()
// WITH TRAVERSORS:
// find incident faces to vertex
Traversor2VF<MAP> trvf(myMap,v.dart);
Traversor2VF<MAP> trvf(myMap, v.dart);
for (Dart e = trvf.begin(); e != trvf.end(); e = trvf.next())
{
std::cout << "Face of dart "<<e<< " incident to vertex of dart " << v.dart<< std::endl;
}
// find adjacent vertices thru a face
Traversor2VVaF<MAP> trvvaf(myMap,v.dart);
Traversor2VVaF<MAP> trvvaf(myMap, v.dart);
for (Dart e = trvvaf.begin(); e != trvvaf.end(); e = trvvaf.next())
{
std::cout << "vertex of dart "<<e<< " adjacent to vertex of dart " << v.dart<< " by a face" << std::endl;
......@@ -88,16 +92,16 @@ int main()
// WITH FOREACH FUNCTION (C++11 lambda expression)
// find incident faces to vertex
foreach_incident2<FACE>(myMap,v,[&](Face f)
// find faces incident to vertex v
foreach_incident2<FACE>(myMap, v, [&](Face f)
{
std::cout << "Face of dart "<<f<< " incident to vertex of dart " << v.dart<< std::endl;
std::cout << "Face of dart " << f << " incident to vertex of dart " << v.dart << std::endl;
});
// find adjacent vertices thru a face
foreach_adjacent2<FACE>(myMap,v,[&](Vertex x)
// find vertices adjacent to vertex v thru a face
foreach_adjacent2<FACE>(myMap, v, [&](Vertex x)
{
std::cout << "vertex of dart "<<x<< " adjacent to vertex of dart " << v.dart<< " by a face" << std::endl;
std::cout << "vertex of dart " << x << " adjacent to vertex of dart " << v.dart << " by a face" << std::endl;
});
return 0;
......
......@@ -28,9 +28,9 @@ public:
inline const QString& getName() { return m_name; }
virtual inline unsigned int getOrbit() const = 0;
virtual unsigned int getOrbit() const = 0;
virtual inline unsigned int getNbSelectedCells() const = 0;
virtual unsigned int getNbSelectedCells() const = 0;
virtual void rebuild() = 0;
......@@ -45,7 +45,7 @@ public:
inline void setMutuallyExclusive(bool b) { m_isMutuallyExclusive = b; }
inline bool isMutuallyExclusive() const { return m_isMutuallyExclusive; }
virtual inline void setMutuallyExclusiveSet(const QList<CellSelectorGen*>& mex) = 0;
virtual void setMutuallyExclusiveSet(const QList<CellSelectorGen*>& mex) = 0;
signals:
void selectedCellsChanged();
......
......@@ -151,10 +151,10 @@ protected:
* @param tableIndices the indices table
*/
template <typename PFP>
void addTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices) ;
void addTri(typename PFP::MAP& map, Face f, std::vector<GLuint>& tableIndices) ;
template<typename PFP>
inline void addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>* position);
inline void addEarTri(typename PFP::MAP& map, Face f, std::vector<GLuint>& tableIndices, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>* position);
template<typename PFP>
float computeEarAngle(const typename PFP::VEC3& P1, const typename PFP::VEC3& P2, const typename PFP::VEC3& P3, const typename PFP::VEC3& normalPoly);
......@@ -166,7 +166,7 @@ protected:
void recompute2Ears(const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly, VPMS& ears, bool convex);
template<typename VEC3>
bool inTriangle(const VEC3& P, const VEC3& normal, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc);
bool inTriangle(const VEC3& P, const VEC3& normal, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc);
public:
/**
......
......@@ -180,7 +180,7 @@ bool MapRender::computeEarIntersection(const VertexAttribute<typename PFP::VEC3,
}
template<typename PFP>
inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>* pos)
inline void MapRender::addEarTri(typename PFP::MAP& map, Face f, std::vector<GLuint>& tableIndices, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>* pos)
{
typedef typename PFP::VEC3 VEC3;
......@@ -190,24 +190,24 @@ inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLu
const VertexAttribute<VEC3, typename PFP::MAP::IMPL>& position = *pos ;
// compute normal to polygon
VEC3 normalPoly = Algo::Surface::Geometry::newellNormal<PFP>(map, d, position);
VEC3 normalPoly = Algo::Surface::Geometry::newellNormal<PFP>(map, f, position);
// first pass create polygon in chained list with angle computation
VertexPoly* vpp = NULL;
VertexPoly* prem = NULL;
unsigned int nbv = 0;
unsigned int nbe = 0;
Dart a = d;
Dart b = map.phi1(a);
Dart c = map.phi1(b);
Vertex a = f.dart;
Vertex b = map.phi1(a);
Vertex c = map.phi1(b);
do
{
VEC3 P1 = position[map.template getEmbedding<VERTEX>(a)];
VEC3 P2 = position[map.template getEmbedding<VERTEX>(b)];
VEC3 P3 = position[map.template getEmbedding<VERTEX>(c)];
VEC3 P1 = position[map.getEmbedding(a)];
VEC3 P2 = position[map.getEmbedding(b)];
VEC3 P3 = position[map.getEmbedding(c)];
float val = computeEarAngle<PFP>(P1, P2, P3, normalPoly);
VertexPoly* vp = new VertexPoly(map.template getEmbedding<VERTEX>(b), val, (P3-P1).norm2(), vpp);
VertexPoly* vp = new VertexPoly(map.getEmbedding(b), val, (P3-P1).norm2(), vpp);
if (vp->value < 5.0f)
nbe++;
......@@ -218,7 +218,7 @@ inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLu
b = c;
c = map.phi1(c);
nbv++;
}while (a != d);
} while (a.dart != f.dart);
VertexPoly::close(prem, vpp);
......@@ -227,7 +227,7 @@ inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLu
{
// second pass with no test of intersections with polygons
vpp = prem;
for (unsigned int i=0; i< nbv; ++i)
for (unsigned int i = 0; i < nbv; ++i)
{
vpp->ear = ears.insert(vpp);
vpp = vpp->next;
......@@ -237,9 +237,9 @@ inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLu
{
// second pass test intersections with polygons
vpp = prem;
for (unsigned int i=0; i< nbv; ++i)
for (unsigned int i = 0; i < nbv; ++i)
{
if (vpp->value <5.0f)
if (vpp->value < 5.0f)
computeEarIntersection<PFP>(position, vpp, normalPoly);
vpp->ear = ears.insert(vpp);
vpp = vpp->next;
......@@ -248,7 +248,7 @@ inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLu
// NOW WE HAVE THE POLYGON AND EARS
// LET'S REMOVE THEM
while (nbv>3)
while (nbv > 3)
{
// take best (and valid!) ear
VPMS::iterator be_it = ears.begin(); // best ear
......@@ -259,14 +259,14 @@ inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLu
tableIndices.push_back(be->prev->id);
nbv--;
if (nbv>3) // do not recompute if only one triangle left
if (nbv > 3) // do not recompute if only one triangle left
{
//remove ears and two sided ears
ears.erase(be_it); // from map of ears
ears.erase(be->next->ear);
ears.erase(be->prev->ear);
be = VertexPoly::erase(be); // and remove ear vertex from polygon
recompute2Ears<PFP>(position,be,normalPoly,ears,convex);
recompute2Ears<PFP>(position, be, normalPoly, ears, convex);
convex = (*(ears.rbegin()))->value < 5.0f;
}
else // finish (no need to update ears)
......@@ -286,21 +286,21 @@ inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLu
}
template<typename PFP>
inline void MapRender::addTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices)
inline void MapRender::addTri(typename PFP::MAP& map, Face f, std::vector<GLuint>& tableIndices)
{
Dart a = d;
Dart b = map.phi1(a);
Dart c = map.phi1(b);
Vertex a = f.dart;
Vertex b = map.phi1(a);
Vertex c = map.phi1(b);
// loop to cut a polygon in triangle on the fly (works only with convex faces)
do
{
tableIndices.push_back(map.template getEmbedding<VERTEX>(d));
tableIndices.push_back(map.template getEmbedding<VERTEX>(b));
tableIndices.push_back(map.template getEmbedding<VERTEX>(c));
tableIndices.push_back(map.getEmbedding(a));
tableIndices.push_back(map.getEmbedding(b));
tableIndices.push_back(map.getEmbedding(c));
b = c;
c = map.phi1(b);
} while (c != d);
} while (c.dart != a.dart);
}
template<typename PFP>
......@@ -308,27 +308,22 @@ void MapRender::initTriangles(typename PFP::MAP& map, std::vector<GLuint>& table
{
tableIndices.reserve(4 * map.getNbDarts() / 3);
// TraversorF<typename PFP::MAP> trav(map, thread);
if(position == NULL)
{
// for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
// foreachCellMT(VERTEX,d,typename PFP::MAP,map,thread)
foreach_cell<VERTEX>(map, [&] (Vertex v)
foreach_cell<FACE>(map, [&] (Face f)
{
addTri<PFP>(map, v, tableIndices);
},false,thread);
addTri<PFP>(map, f, tableIndices);
}, false, thread);
}
else
{
// for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
foreach_cell<VERTEX>(map, [&] (Vertex v)
foreach_cell<FACE>(map, [&] (Face f)
{
if(map.faceDegree(v) == 3)
addTri<PFP>(map, v, tableIndices);
if(map.faceDegree(f) == 3)
addTri<PFP>(map, f, tableIndices);
else
addEarTri<PFP>(map, v, tableIndices, position);
},false,thread);
addEarTri<PFP>(map, f, tableIndices, position);
}, false, thread);
}
}
......
......@@ -65,19 +65,6 @@ public:
inline Cell<ORBIT> next() ;
inline void skip(Cell<ORBIT> c);
inline void apply(std::function<bool (Cell<ORBIT>)> f)
{
for (Cell<ORBIT> c = begin(), e = end(); c.dart != e.dart; c = next())
if (f(c))
return;
}
inline void apply(std::function<void (Cell<ORBIT>)> f)
{
for (Cell<ORBIT> c = begin(), e = end(); c.dart != e.dart; c = next())
f(c);
}
} ;
......@@ -86,23 +73,22 @@ template <unsigned int ORBIT, typename MAP, typename FUNC>
inline void foreach_cell(const MAP& map, FUNC f, bool forceDartMarker = false, unsigned int thread = 0)
{
TraversorCell<MAP, ORBIT> trav(map, forceDartMarker, thread);
trav.apply(f);
for (Cell<ORBIT> c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next())
f(c);
}
template <unsigned int ORBIT, typename MAP >
inline void find_cell(const MAP& map, Cell<ORBIT> c, std::function<bool (Cell<ORBIT>)> cond, bool forceDartMarker = false, unsigned int thread = 0)
template <unsigned int ORBIT, typename MAP, typename FUNC>
inline void foreach_cell_until(const MAP& map, FUNC f, bool forceDartMarker = false, unsigned int thread = 0)
{
TraversorCell<MAP, ORBIT> trav(map, forceDartMarker, thread);
c = trav.begin();
Cell<ORBIT> e = trav.end();
while ((c.dart != e.dart) && (!cond(c)))
c = trav.next();
for (Cell<ORBIT> c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next())
if (!f(c))
break;
}
template <typename MAP>
class TraversorV : public TraversorCell<MAP, VERTEX>
{
......
......@@ -309,110 +309,110 @@ public:
*************************************************************************/
//@{
//! Test if dart d and e belong to the same oriented vertex
/*! @param d a dart
* @param e a dart
//! Test if vertices v1 and v2 represent the same oriented vertex
/*! @param v1 a vertex
* @param v2 a vertex
*/
bool sameOrientedVertex(Dart d, Dart e) const;
bool sameOrientedVertex(Vertex v1, Vertex v2) const;
//! Test if dart d and e belong to the same vertex
/*! @param d a dart
* @param e a dart
//! Test if vertices v1 and v2 represent the same vertex
/*! @param v1 a vertex
* @param v2 a vertex
*/
bool sameVertex(Dart d, Dart e) const;
bool sameVertex(Vertex v1, Vertex v2) const;
//! Compute the number of edges of the vertex of d
/*! @param d a dart
//! Compute the number of edges of the vertex v
/*! @param v a vertex
*/
unsigned int vertexDegree(Dart d) const;
unsigned int vertexDegree(Vertex v) const;
//! Check number of edges of the vertex of d with given parameter
/*! @param d a dart
//! Check number of edges of the vertex v with given parameter
/*! @param v a vertex
* @param vd degree to compare with
* @return negative/null/positive if vertex degree is less/equal/greater than given degree
* @return negative/null/positive if vertex degree is less/equal/greater than given degree
*/
int checkVertexDegree(Dart d, unsigned int vd) const;
int checkVertexDegree(Vertex v, unsigned int vd) const;
//! Tell if the vertex of d is on the boundary of the map
/*! @param d a dart
//! Tell if the vertex v is on the boundary of the map
/*! @param v a vertex
*/
bool isBoundaryVertex(Dart d) const;
bool isBoundaryVertex(Vertex v) const;
/**
* find the dart of vertex that belong to the boundary
* find the dart of vertex v that belongs to the boundary
* return NIL if the vertex is not on the boundary
*/
Dart findBoundaryEdgeOfVertex(Dart d) const;
Dart findBoundaryEdgeOfVertex(Vertex v) const;
//! Test if dart d and e belong to the same edge
/*! @param d a dart
* @param e a dart
//! Test if edges e1 and e2 represent the same edge
/*! @param e1 an edge
* @param e2 an edge
*/
bool sameEdge(Dart d, Dart e) const;
bool sameEdge(Edge e1, Edge e2) const;
/**
* tell if the edge of d is on the boundary of the map
* tell if the edge e is on the boundary of the map
*/
bool isBoundaryEdge(Dart d) const;
bool isBoundaryEdge(Edge e) const;
//! Test if dart d and e belong to the same oriented face
/*! @param d a dart
* @param e a dart
//! Test if faces f1 and f2 represent the same oriented face
/*! @param f1 a face
* @param f2 a face
*/
bool sameOrientedFace(Dart d, Dart e) const;
bool sameOrientedFace(Face f1, Face f2) const;
//! Test if dart d and e belong to the same face
/*! @param d a dart
* @param e a dart
//! Test if faces f1 and f2 represent the same face
/*! @param f1 a face
* @param f2 a face
*/
bool sameFace(Dart d, Dart e) const;
bool sameFace(Face f1, Face f2) const;
/**
* compute the number of edges of the face of d
* compute the number of edges of the face f
*/
unsigned int faceDegree(Dart d) const;
unsigned int faceDegree(Face f) const;
//! Check number of edges of the face of d with given parameter
/*! @param d a dart
* @param vd degree to compare with
* @return negative/null/positive if vertex degree is less/equal/greater than given degree
//! Check number of edges of the face f with given parameter
/*! @param f a face
* @param fd degree to compare with
* @return negative/null/positive if face degree is less/equal/greater than given degree
*/
int checkFaceDegree(Dart d, unsigned int le) const;
int checkFaceDegree(Face f, unsigned int fd) const;
/**
* tell if the face of d is adjacent to the boundary of the map
* tell if the face f is incident to the boundary of the map
*/
bool isBoundaryAdjacentFace(Dart d) const;
bool isFaceIncidentToBoundary(Face f) const;
/**
* find the dart of edge that belong to the boundary
* return NIL if the face is not on the boundary
* find the dart of face f that belongs to the boundary
* return NIL if the face is not incident to the boundary
*/
Dart findBoundaryEdgeOfFace(Dart d) const;
Dart findBoundaryEdgeOfFace(Face f) const;
//! Test if dart d and e belong to the same oriented volume
//! Test if volumes v1 and v2 represent the same oriented volume
/*! @param d a dart
* @param e a dart
*/
bool sameOrientedVolume(Dart d, Dart e) const;
bool sameOrientedVolume(Vol v1, Vol v2) const;
//! Test if dart d and e belong to the same volume
//! Test if volumes v1 and v2 represent the same volume
/*! @param d a dart
* @param e a dart
*/
bool sameVolume(Dart d, Dart e) const;
bool sameVolume(Vol v1, Vol v2) const;
//! Compute the number of faces in the volume of d
//! Compute the number of faces in the volume v
/*! @param d a dart
*/
unsigned int volumeDegree(Dart d) const;
unsigned int volumeDegree(Vol v) const;
//! Check number of faces of the volume of d with given parameter
/*! @param d a dart
//! Check number of faces of the volume v with given parameter
/*! @param v a volume
* @param vd degree to compare with
* @return negative/null/positive if volume degree is less/equal/greater than given degree
* @return negative/null/positive if volume degree is less/equal/greater than given degree
*/
int checkVolumeDegree(Dart d, unsigned int volDeg)const;
int checkVolumeDegree(Vol v, unsigned int vd) const;
// TODO a mettre en algo
/**
......
......@@ -537,7 +537,7 @@ void Map2<MAP_IMPL>::extractTrianglePair(Dart d)
{
Dart e = phi2(d) ;
assert(!isBoundaryAdjacentFace(d) && !isBoundaryAdjacentFace(e)) ;
assert(!isFaceIncidentToBoundary(d) && !isFaceIncidentToBoundary(e)) ;
assert(faceDegree(d) == 3 && faceDegree(e) == 3) ;
Dart d1 = phi2(this->phi1(d)) ;
......@@ -577,7 +577,7 @@ bool Map2<MAP_IMPL>::mergeVolumes(Dart d, Dart e, bool deleteFace)
{
assert(!this->template isBoundaryMarked<2>(d) && !this->template isBoundaryMarked<2>(e)) ;
if (isBoundaryAdjacentFace(d) || isBoundaryAdjacentFace(e))
if (isFaceIncidentToBoundary(d) || isFaceIncidentToBoundary(e))
return false;
// First traversal of both faces to check the face sizes
......@@ -653,157 +653,158 @@ void Map2<MAP_IMPL>::splitSurface(std::vector<Dart>& vd, bool firstSideClosed, b
*************************************************************************/
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::sameOrientedVertex(Dart d, Dart e) const
bool Map2<MAP_IMPL>::sameOrientedVertex(Vertex v1, Vertex v2) const
{
Dart it = d; // Foreach dart dNext in the vertex of d
Dart it = v1.dart; // Foreach dart in vertex v1
do
{
if (it == e) // Test equality with e
if (it == v2.dart) // Test equality with v2
return true;
it = phi2(this->phi_1(it));
} while (it != d);
} while (it != v1.dart);
return false; // None is equal to e => vertices are distinct
}
template <typename MAP_IMPL>
inline bool Map2<MAP_IMPL>::sameVertex(Dart d, Dart e) const
inline bool Map2<MAP_IMPL>::sameVertex(Vertex v1, Vertex v2) const
{
return sameOrientedVertex(d, e) ;
return sameOrientedVertex(v1, v2) ;
}
template <typename MAP_IMPL>
unsigned int Map2<MAP_IMPL>::vertexDegree(Dart d) const
unsigned int Map2<MAP_IMPL>::vertexDegree(Vertex v) const
{
unsigned int count = 0 ;
Dart it = d ;
Dart it = v.dart ;
do
{
++count ;
it = phi2(this->phi_1(it)) ;
} while (it != d) ;
} while (it != v.dart) ;
return count ;
}
template <typename MAP_IMPL>
int Map2<MAP_IMPL>::checkVertexDegree(Dart d, unsigned int vd) const
int Map2<MAP_IMPL>::checkVertexDegree(Vertex v, unsigned int vd) const
{
unsigned int count = 0 ;
Dart it = d ;
Dart it = v.dart ;
do
{
++count ;
it = phi2(this->phi_1(it)) ;
} while ((count <= vd) && (it != d)) ;
} while ((count <= vd) && (it != v.dart)) ;
return count - vd;
}
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::isBoundaryVertex(Dart d) const
bool Map2<MAP_IMPL>::isBoundaryVertex(Vertex v) const
{
Dart it = d ;
Dart it = v.dart ;
do
{
if (this->template isBoundaryMarked<2>(it))
return true ;
it = phi2(this->phi_1(it)) ;
} while (it != d) ;
} while (it != v.dart) ;
return false ;
}
template <typename MAP_IMPL>
Dart Map2<MAP_IMPL>::findBoundaryEdgeOfVertex(Dart d) const
Dart Map2<MAP_IMPL>::findBoundaryEdgeOfVertex(Vertex v) const
{
Dart it = d ;
Dart it = v.dart ;
do
{
if (this->template isBoundaryMarked<2>(it))
return it ;
it = phi2(this->phi_1(it)) ;
} while (it != d) ;
} while (it != v.dart) ;
return NIL ;
}
template <typename MAP_IMPL>
inline bool Map2<MAP_IMPL>::sameEdge(Dart d, Dart e) const
inline bool Map2<MAP_IMPL>::sameEdge(Edge e1, Edge e2) const
{
return d == e || phi2(d) == e ;
return e1.dart == e2.dart || phi2(e1.dart) == e2.dart ;
}
template <typename MAP_IMPL>
inline bool Map2<MAP_IMPL>::isBoundaryEdge(Dart d) const
inline bool Map2<MAP_IMPL>::isBoundaryEdge(Edge e) const
{
return this->template isBoundaryMarked<2>(d) || this->template isBoundaryMarked<2>(phi2(d));
return this->template isBoundaryMarked<2>(e.dart) || this->template isBoundaryMarked<2>(phi2(e.dart));
}
template <typename MAP_IMPL>
inline bool Map2<MAP_IMPL>::sameOrientedFace(Dart d, Dart e) const
inline bool Map2<MAP_IMPL>::sameOrientedFace(Face f1, Face f2) const