Commit 72faa2ea authored by Jund Thomas's avatar Jund Thomas

Merge cgogn.unistra.fr:~cazier/CGoGN

parents 974379f0 f2cdf37d
......@@ -40,15 +40,12 @@ bool isBetween(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>
}
template <typename PFP>
void mergeVertex(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& positions, Dart d, Dart e)
void mergeVertex(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& positions, Dart d, Dart e, int precision)
{
assert(Geom::arePointsEquals(positions[d], positions[e]) && !map.sameVertex(d, e)) ;
typedef typename PFP::VEC3 VEC3;
VEC3 p = positions[d] ;
assert(positions[d].isNear(positions[e], precision) && !map.sameVertex(d, e)) ;
bool notempty = true ;
do // while vertex of e contains more than one dart
do // While vertex of e contains more than one dart
{
Dart e1 = map.alpha1(e) ; // e1 stores next dart of vertex of e
if (e1 == e)
......@@ -72,32 +69,32 @@ void mergeVertex(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& po
d = e ;
e = e1 ;
} while (notempty) ;
// 0-embed z on the merged vertex
positions[d] = p ;
}
template <typename PFP>
void mergeVertices(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& positions)
void mergeVertices(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& positions, int precision)
{
// TODO optimiser en triant les sommets
for(Dart d = map.begin() ; d != map.end() ; map.next(d))
// map.template enableQuickTraversal<VERTEX>();
TraversorV<typename PFP::MAP> travV1(map) ;
CellMarker<VERTEX> vM(map);
for(Dart d1 = travV1.begin() ; d1 != travV1.end() ; d1 = travV1.next())
{
CellMarker<VERTEX> vM(map);
vM.mark(d);
for(Dart dd = map.begin() ; dd != map.end() ; map.next(dd))
vM.mark(d1);
TraversorV<typename PFP::MAP> travV2(map) ;
for(Dart d2 = travV2.begin() ; d2 != travV2.end() ; d2 = travV2.next())
{
if(!vM.isMarked(dd))
if(!vM.isMarked(d2))
{
if(Geom::arePointsEquals(positions[d],positions[dd]))
if(positions[d1].isNear(positions[d2], precision))
{
if (map.sameVertex(d,dd)) std::cout << "fusion: sameVertex" << std::endl ;
if (!map.sameVertex(d,dd)) mergeVertex<PFP>(map,positions,d,dd);
// vM.mark(d);
if (map.sameVertex(d1,d2)) std::cout << "fusion: sameVertex" << std::endl ;
if (!map.sameVertex(d1,d2)) mergeVertex<PFP>(map,positions,d1,d2,precision);
}
}
}
}
// map.template disableQuickTraversal<VERTEX>();
}
}
......
This diff is collapsed.
......@@ -152,13 +152,21 @@ public:
*/
bool isNormalized(const T& epsilon) const ;
/**
* Tests if current and given vectors are near within 1/precision (equal if precision is zero)
* @param V a vector
* @param epsilon tolerated error
* @return true if orthogonal
*/
bool isNear(const Vector<DIM, T>& v, int precision) const ;
/**
* Tests if current and given vectors are orthogonal
* @param V a vector
* @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 */
......@@ -174,6 +182,22 @@ private:
T m_data[DIM] ;
} ;
/***
* Test if x is null within precision.
* Two cases are possible :
* - precision == 0 : x is null if (x == 0)
* - precision > 0 : x is null if (|x| < 1/precision) or (precision * |x| < 1)
*/
template <typename T>
bool isNull(T x, int precision = 0) ;
/***
* Test if the square root of x is null within precision.
* In other words, test if x is null within precision*precision
*/
template <typename T>
bool isNull2(T x, int precision = 0) ;
template <unsigned int DIM, typename T>
Vector<DIM, T> operator*(T a, const Vector<DIM, T>& v) ;
......
......@@ -315,9 +315,23 @@ inline bool Vector<DIM, T>::isNormalized(const T& epsilon) const
}
template <unsigned int DIM, typename T>
inline bool Vector<DIM, T>::isOrthogonal(const Vector<DIM, T>& V, const T& epsilon) const
inline bool Vector<DIM, T>::isOrthogonal(const Vector<DIM, T>& v, const T& epsilon) const
{
return (fabs(V * (*this)) < epsilon) ;
return (fabs(v * (*this)) < epsilon) ;
}
template <unsigned int DIM, typename T>
inline bool Vector<DIM, T>::isNear(const Vector<DIM, T>& v, int precision) const
{
T diff ;
T norm2(0) ;
for (unsigned int i = 0 ; i < DIM ; ++i)
{
diff = m_data[i] - v[i] ;
if (!isNull(diff, precision)) return false ;
norm2 += diff * diff ;
}
return isNull2(norm2, precision) ;
}
/**********************************************/
......@@ -340,6 +354,39 @@ std::istream& operator>>(std::istream& in, Vector<DIM, T>& v)
return in ;
}
/***
* Test if x is null within precision.
* 3 cases are possible :
* - precision = 0 : x is null <=> (x == 0)
* - precision > 0 : x is null <=> (|x| < precision)
* - precision < 0 : x is null <=> (|x| < 1/precision) <=> (precision * |x| < 1)
*/
template <typename T>
inline bool isNull(T x, int precision)
{
if (precision == 0)
return (x == 0) ;
else if (precision > 0)
return (fabs(x) < precision) ;
else
return (precision * fabs(x) < 1) ;
}
/***
* Test if the square root of x is null within precision.
* In other words, test if x is null within precision*precision
*/
template <typename T>
inline bool isNull2(T x, int precision)
{
if (precision == 0)
return (x == 0) ;
else if (precision > 0)
return (isNull(x, precision * precision)) ;
else
return (isNull(x, - (precision * precision))) ;
}
template <unsigned int DIM, typename T>
inline Vector<DIM, T> operator*(T a, const Vector<DIM, T>& v)
{
......
......@@ -40,7 +40,10 @@ public:
typedef Map2 TOPO_MAP;
/*
*
*/
virtual Dart newPolyLine(unsigned int nbEdges) ;
/*
*/
virtual Dart newFace(unsigned int nbEdges, bool withBoundary = true) ;
......
......@@ -125,6 +125,12 @@ public:
*************************************************************************/
//@{
//! Create an new polyline of nbEdges, i.e 2*nbEdges darts pairewise sewn by phi2
/*! @param nbEdges the number of edges
* @return return a dart of the face
*/
virtual Dart newPolyLine(unsigned int nbEdges) ;
//! Create an new face of nbEdges
/*! @param nbEdges the number of edges
* @param withBoundary create the face and its boundary (default true)
......
......@@ -30,6 +30,37 @@
namespace CGoGN
{
Dart EmbeddedMap2::newPolyLine(unsigned int nbEdges)
{
Dart d = Map2::newPolyLine(nbEdges) ;
if (isOrbitEmbedded<VERTEX>())
{
Dart e = d ;
for (unsigned int i = 0 ; i <= nbEdges ; ++i)
{
initOrbitEmbeddingNewCell<VERTEX>(e) ;
e = this->phi1(e) ;
}
}
if (isOrbitEmbedded<EDGE>())
{
Dart e = d ;
for (unsigned int i = 0 ; i < nbEdges ; ++i)
{
initOrbitEmbeddingNewCell<EDGE>(e) ;
e = this->phi1(e) ;
}
}
if (isOrbitEmbedded<FACE>())
{
initOrbitEmbeddingNewCell<FACE>(d) ;
}
return d ;
}
Dart EmbeddedMap2::newFace(unsigned int nbEdges, bool withBoundary)
{
Dart d = Map2::newFace(nbEdges, withBoundary);
......
......@@ -107,6 +107,22 @@ void Map2::compactTopoRelations(const std::vector<unsigned int>& oldnew)
* To generate or delete faces in a 2-map
*************************************************************************/
Dart Map2::newPolyLine(unsigned int nbEdges)
{
Dart d = Map1::newCycle(2*nbEdges);
{
Dart it1 = d;
Dart it2 = phi_1(d);
for(unsigned int i = 0; i<nbEdges ; ++i)
{
phi2sew(it1, it2);
it1 = phi1(it1);
it2 = phi_1(it2);
}
}
return d;
}
Dart Map2::newFace(unsigned int nbEdges, bool withBoundary)
{
Dart d = Map1::newCycle(nbEdges);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment