Commit 5640f9f6 authored by julien's avatar julien

triangles singuliers

parent 487e70fc
......@@ -25,6 +25,8 @@
#ifndef __ALGO_GEOMETRY_FEATURE_H__
#define __ALGO_GEOMETRY_FEATURE_H__
namespace CGoGN
{
......@@ -34,6 +36,14 @@ namespace Algo
namespace Geometry
{
#define EMPTY 0
#define SEGMENT 1
#define BARY 2
typedef struct { Dart d ; float w ; } e0point ;
typedef struct { e0point p1 ; e0point p2 ; int valid ; } e0segment ;
typedef NoMathIONameAttribute<e0segment> ridgeSegment ;
template <typename PFP>
void featureEdgeDetection(typename PFP::MAP& map, const typename PFP::TVEC3& position, CellMarker& featureEdge) ;
......@@ -50,7 +60,13 @@ template <typename PFP>
void computeTriangleType(typename PFP::MAP& map, const typename PFP::TVEC3& position, CellMarker& regularMarker, const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
template <typename PFP>
void computeCurvatureSign(typename PFP::MAP& map, const typename PFP::TVEC3& position, CellMarker& regularMarker, typename PFP::TVEC3& faceGradient, const typename PFP::TREAL& area, const typename PFP::TREAL& k, const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
void computeRidgeLines(typename PFP::MAP& map, const typename PFP::TVEC3& position, CellMarker& regularMarker, const typename PFP::TVEC3& faceGradient, const typename PFP::TREAL& area, typename PFP::TVEC3& k, AttributeHandler<ridgeSegment>& ridge_segments, const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
template <typename PFP>
void initRidgeSegments(typename PFP::MAP& map, const typename PFP::TVEC3& position, AttributeHandler<ridgeSegment>& ridge_segments, const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
template <typename PFP>
void computeSingularTriangle(typename PFP::MAP& map, const typename PFP::TVEC3& position, CellMarker& regularMarker, typename PFP::TVEC3& k, AttributeHandler<ridgeSegment>& ridge_segments, const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
template <typename PFP>
std::vector<typename PFP::VEC3> occludingContoursDetection(typename PFP::MAP& map, const typename PFP::VEC3& cameraPosition, const typename PFP::TVEC3& position, const typename PFP::TVEC3& normal) ;
......@@ -68,14 +84,20 @@ template <typename PFP>
bool isInSameOctant(const typename PFP::VEC3& pos1, const typename PFP::VEC3& pos2) ;
template <typename PFP>
void curvatureSign(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, CellMarker& regularMarker, typename PFP::TREAL& k, typename PFP::TVEC3& faceGradient, typename PFP::TREAL& area) ;
void ridgeLines(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, CellMarker& regularMarker, typename PFP::TVEC3& k, const typename PFP::TVEC3& faceGradient, const typename PFP::TREAL& area, AttributeHandler<ridgeSegment>& ridge_segments) ;
template <typename PFP>
typename PFP::REAL extremality(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, typename PFP::TREAL& k, typename PFP::TVEC3& faceGradient, typename PFP::TREAL& area) ;
typename PFP::REAL extremality(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, typename PFP::TVEC3& k, const typename PFP::TVEC3& faceGradient, const typename PFP::TREAL& area) ;
template <typename PFP>
typename PFP::TVEC3 vertexGradient(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, const typename PFP::TVEC3& face_gradient, const typename PFP::TREAL& area) ;
template <typename PFP>
void singularTriangle(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, CellMarker& regularMarker, AttributeHandler<ridgeSegment>& ridge_segments) ;
template <typename PFP>
bool isEdgeInTriangle(typename PFP::MAP& map, Dart edge, Dart triangle) ;
} // namespace Geometry
} // namespace Algo
......
......@@ -92,24 +92,37 @@ void computeTriangleType(typename PFP::MAP& map, const typename PFP::TVEC3& posi
}
template <typename PFP>
void computeCurvatureSign(typename PFP::MAP& map, const typename PFP::TVEC3& position, CellMarker& regularMarker, typename PFP::TVEC3& faceGradient, const typename PFP::TREAL& area, const typename PFP::TREAL& k, const FunctorSelect& select = allDarts, unsigned int thread = 0)
void computeRidgeLines(typename PFP::MAP& map, const typename PFP::TVEC3& position, CellMarker& regularMarker, const typename PFP::TVEC3& faceGradient, const typename PFP::TREAL& area, typename PFP::TVEC3& k, AttributeHandler<ridgeSegment>& ridge_segments, const FunctorSelect& select = allDarts, unsigned int thread = 0)
{
/*CellMarker mv(map, VERTEX, thread);
TraversorV<typename PFP::MAP> trav(map, select, thread);
TraversorF<typename PFP::MAP> trav(map, select, thread);
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
{
if (!mv.isMarked(d))
if (regularMarker.isMarked(d))
{
curvatureSign<PFP>(map, d, position, triangle_type, k) ;
ridgeLines<PFP>(map, d, position, regularMarker, k, faceGradient, area, ridge_segments) ;
}
}*/
}
}
template <typename PFP>
void initRidgeSegments(typename PFP::MAP& map, const typename PFP::TVEC3& position, AttributeHandler<ridgeSegment>& ridge_segments, const FunctorSelect& select = allDarts, unsigned int thread = 0)
{
TraversorF<typename PFP::MAP> trav(map, select, thread);
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
{
if (regularMarker.isMarked(d))
ridge_segments[d].valid = EMPTY ;
}
}
template <typename PFP>
void computeSingularTriangle(typename PFP::MAP& map, const typename PFP::TVEC3& position, CellMarker& regularMarker, AttributeHandler<ridgeSegment>& ridge_segments, const FunctorSelect& select = allDarts, unsigned int thread = 0)
{
TraversorF<typename PFP::MAP> trav(map, select, thread);
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
{
if (! regularMarker.isMarked(d))
{
curvatureSign<PFP>(map, d, position, regularMarker, k, faceGradient, area) ;
singularTriangle<PFP>(map, d, position, regularMarker, ridge_segments) ;
}
}
}
......@@ -306,87 +319,124 @@ bool isInSameOctant(const typename PFP::VEC3& pos1, const typename PFP::VEC3& po
}
template <typename PFP>
void curvatureSign(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, CellMarker& regularMarker, typename PFP::TREAL& k, typename PFP::TVEC3& faceGradient, typename PFP::TREAL& area)
void ridgeLines(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, CellMarker& regularMarker, typename PFP::TVEC3& k, const typename PFP::TVEC3& faceGradient, const typename PFP::TREAL& area, AttributeHandler<ridgeSegment>& ridge_segments)
{
/*sommetTraité = true ;*/
/*Traversor2VE<typename PFP::MAP> trav2(map, d) ;
for (Dart d2 = trav2.begin(); d2 != trav2.end(); d2 = trav2.next())
{
if (arrete non traité true)
{
if((k[d] * k[d2]) <= 0)
{
k[d2] *= -1 ;
}
}
}*/
/* Choix du signe */
typedef typename PFP::REAL REAL ;
typedef typename PFP::VEC3 VEC3 ;
VEC3 pos1(0) ;
VEC3 pos2(0) ;
VEC3 pos3(0) ;
Traversor2FV<typename PFP::MAP> t(map, d) ;
Dart it = t.begin() ;
Dart v1 = t.begin() ;
Dart v2 = t.next() ;
Dart v3 = t.next() ;
pos1 += position[it] ;
it = t.next() ;
pos2 += position[it] ;
it = t.next() ;
pos3 += position[it] ;
if((k[pos1] ^ k[pos2]) <= 0)
if((k[v1] * k[v2]) <= 0)
{
k[pos2] *= -1 ;
k[v2] *= -1 ;
}
if((k[pos1] ^ k[pos3]) <= 0)
if((k[v1] * k[v3]) <= 0)
{
k[pos3] *= -1 ;
k[v3] *= -1 ;
}
/* Calcul coefficient extremalite */
REAL e1, e2, e3 ;
e1 = extremality<PFP>(map, d, position, k, faceGradient, area) ;
e2 = extremality<PFP>(map, d, position, k, faceGradient, area) ;
e3 = extremality<PFP>(map, d, position, k, faceGradient, area) ;
e1 = extremality<PFP>(map, v1, position, k, faceGradient, area) ;
e2 = extremality<PFP>(map, v2, position, k, faceGradient, area) ;
e3 = extremality<PFP>(map, v3, position, k, faceGradient, area) ;
/* Stockage des zeros */
if( (e1 < 0 and e2 > 0) or (e1 > 0 and e2 < 0) )
{
REAL alpha = abs(e1) / ( abs(e1) + abs(e2) ) ;
std::cout << "alpha : " << alpha << "\n" ;
ridge_segments[d].valid = SEGMENT ;
ridge_segments[d].p1.d = v1 ;
ridge_segments[d].p1.w = alpha ;
}
if( (e1 < 0 and e3 > 0) or (e1 > 0 and e3 < 0) )
{
REAL alpha = abs(e1) / ( abs(e1) + abs(e2) ) ;
if(ridge_segments[d].valid == EMPTY)
{
ridge_segments[d].valid = SEGMENT ;
ridge_segments[d].p1.d = v2 ;
ridge_segments[d].p1.w = alpha ;
}
else
{
ridge_segments[d].p2.d = v2 ;
ridge_segments[d].p2.w = alpha ;
}
}
if( (e2 < 0 and e3 > 0) or (e2 > 0 and e3 < 0) )
{
REAL alpha = abs(e1) / ( abs(e1) + abs(e2) ) ;
ridge_segments[d].p2.d = v3 ;
ridge_segments[d].p2.w = alpha ;
}
//stockage des zeros avec une autre methode pour le calcul du coefficient alpha
/*if( (e1 < 0 and e3 > 0) )
{
REAL alpha = -e1 / ( e3 - e1 ) ;
if(ridge_segments[d].valid == false)
{
ridge_segments[d].valid = true ;
ridge_segments[d].p1.d = v2 ;
ridge_segments[d].p1.w = alpha ;
}
else
{
ridge_segments[d].p2.d = v2 ;
ridge_segments[d].p2.w = alpha ;
}
}
else if(e1 > 0 and e3 < 0)
{
REAL alpha = -e3 / ( e1 - e3 ) ;
if(ridge_segments[d].valid == false)
{
ridge_segments[d].valid = true ;
ridge_segments[d].p1.d = v2 ;
ridge_segments[d].p1.w = alpha ;
}
else
{
ridge_segments[d].p2.d = v2 ;
ridge_segments[d].p2.w = alpha ;
}
}
if( (e2 < 0 and e3 > 0) )
{
REAL alpha = -e2 / ( e3 - e2 ) ;
ridge_segments[d].p2.d = v3 ;
ridge_segments[d].p2.w = alpha ;
}
else if(e2 > 0 and e3 < 0)
{
REAL alpha = -e3 / ( e2 - e3 ) ;
ridge_segments[d].p2.d = v3 ;
ridge_segments[d].p2.w = alpha ;
}*/
}
template <typename PFP>
typename PFP::REAL extremality(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, typename PFP::TREAL& k, typename PFP::TVEC3& faceGradient, typename PFP::TREAL& area)
typename PFP::REAL extremality(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, typename PFP::TVEC3& k, const typename PFP::TVEC3& faceGradient, const typename PFP::TREAL& area)
{
typedef typename PFP::REAL REAL ;
REAL a, e ;
REAL a = 0 ;
REAL e = 0 ;
Traversor2VF<typename PFP::MAP> trav(map, d) ;
for (Dart d2 = trav.begin(); d2 != trav.end(); d2 = trav.next())
{
a += area[d2] ;
e += area[d2] * ( faceGradient[d2] ^ k[d] ) ;
e += area[d2] * ( faceGradient[d2] * k[d] ) ;
}
return (e / a) ;
......@@ -415,6 +465,67 @@ typename PFP::TVEC3 vertexGradient(typename PFP::MAP& map, Dart d, const typenam
return G ;
}
template <typename PFP>
void singularTriangle(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, CellMarker& regularMarker, AttributeHandler<ridgeSegment>& ridge_segments)
{
int nbPoint = 0 ;
Traversor2FFaE<typename PFP::MAP> f(map, d) ;
for (Dart d2 = f.begin(); d2 != f.end(); d2 = f.next())
{
if(regularMarker.isMarked(d2) and ridge_segments[d2].valid == SEGMENT)
{
if(isEdgeInTriangle<PFP>(map, ridge_segments[d2].p1.d, d))
{
if(nbPoint == 0)
{
ridge_segments[d].p1.d = map.phi2(ridge_segments[d2].p1.d) ;
ridge_segments[d].p1.w = 1 - ridge_segments[d2].p1.w ;
}
else
{
ridge_segments[d].valid ++ ;
ridge_segments[d].p2.d = map.phi2(ridge_segments[d2].p1.d) ;
ridge_segments[d].p2.w = 1 - ridge_segments[d2].p1.w ;
}
nbPoint ++ ;
}
else if(isEdgeInTriangle<PFP>(map, ridge_segments[d2].p1.d, d))
{
if(nbPoint == 0)
{
ridge_segments[d].p1.d = map.phi2(ridge_segments[d2].p2.d) ;
ridge_segments[d].p1.w = 1 - ridge_segments[d2].p2.w ;
}
else
{
ridge_segments[d].valid ++ ;
ridge_segments[d].p2.d = map.phi2(ridge_segments[d2].p2.d) ;
ridge_segments[d].p2.w = 1 - ridge_segments[d2].p2.w ;
}
nbPoint ++ ;
}
}
}
}
template <typename PFP>
bool isEdgeInTriangle(typename PFP::MAP& map, Dart edge, Dart triangle)
{
bool inTriangle = false ;
Traversor2FE<typename PFP::MAP> t(map, triangle) ;
for (Dart e = t.begin(); e != t.end(); e = t.next())
{
if(map.phi2(e) == edge)
{
inTriangle = true ;
}
}
return inTriangle ;
}
} // namespace Geometry
} // namespace Algo
......
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