Commit 418f98f6 authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'master' of cgogn:~cgogn/CGoGN

parents 8fb58c43 c0fb7beb
......@@ -35,17 +35,29 @@ namespace Geometry
{
template <typename PFP>
typename PFP::REAL triangleArea(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position);
typename PFP::REAL triangleArea(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) ;
template <typename PFP>
typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position);
typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) ;
template <typename PFP>
typename PFP::REAL totalArea(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& select = SelectorTrue(), unsigned int th=0) ;
template <typename PFP>
typename PFP::REAL vertexOneRingArea(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) ;
template <typename PFP>
typename PFP::REAL vertexVoronoiArea(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) ;
template <typename PFP>
void computeAreaFaces(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TREAL& face_area, const FunctorSelect& select = SelectorTrue()) ;
template <typename PFP>
void computeOneRingAreaVertices(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TREAL& vertex_area, const FunctorSelect& select = SelectorTrue()) ;
template <typename PFP>
void computeVoronoiAreaVertices(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TREAL& vertex_area, const FunctorSelect& select = SelectorTrue()) ;
} // namespace Geometry
} // namespace Algo
......
......@@ -70,7 +70,7 @@ typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const typename
template <typename PFP>
typename PFP::REAL totalArea(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& select, unsigned int th)
{
float area = 0.0f ;
typename PFP::REAL area(0) ;
DartMarker mark(map,th) ;
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
......@@ -83,6 +83,32 @@ typename PFP::REAL totalArea(typename PFP::MAP& map, const typename PFP::TVEC3&
return area ;
}
template <typename PFP>
typename PFP::REAL vertexOneRingArea(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position)
{
typename PFP::REAL area(0) ;
Dart it = d ;
do
{
area += convexFaceArea<PFP>(map, it, position) ;
it = map.alpha1(it) ;
} while(it != d) ;
return area ;
}
template <typename PFP>
typename PFP::REAL vertexVoronoiArea(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position)
{
typename PFP::REAL area(0) ;
Dart it = d ;
do
{
area += convexFaceArea<PFP>(map, it, position) / 3 ;
it = map.alpha1(it) ;
} while(it != d) ;
return area ;
}
template <typename PFP>
void computeAreaFaces(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TREAL& face_area, const FunctorSelect& select)
{
......@@ -97,6 +123,34 @@ void computeAreaFaces(typename PFP::MAP& map, const typename PFP::TVEC3& positio
}
}
template <typename PFP>
void computeOneRingAreaVertices(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TREAL& vertex_area, const FunctorSelect& select)
{
CellMarker marker(map, VERTEX);
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(select(d) && !marker.isMarked(d))
{
marker.mark(d);
vertex_area[d] = vertexOneRingArea<PFP>(map, d, position) ;
}
}
}
template <typename PFP>
void computeVoronoiAreaVertices(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TREAL& vertex_area, const FunctorSelect& select)
{
CellMarker marker(map, VERTEX);
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(select(d) && !marker.isMarked(d))
{
marker.mark(d);
vertex_area[d] = vertexVoronoiArea<PFP>(map, d, position) ;
}
}
}
} // namespace Geometry
} // namespace Algo
......
......@@ -40,25 +40,48 @@ namespace Algo
namespace Geometry
{
enum LaplacianType
{
TOPOLOGICAL
};
template <typename PFP, typename ATTR_TYPE>
ATTR_TYPE computeLaplacianTopoVertex(
typename PFP::MAP& map,
Dart d,
const AttributeHandler<ATTR_TYPE>& attr) ;
template <typename PFP>
void computeLaplacianVertices(
template <typename PFP, typename ATTR_TYPE>
ATTR_TYPE computeLaplacianCotanVertex(
typename PFP::MAP& map,
LaplacianType type,
const typename PFP::TVEC3& position,
typename PFP::TVEC3& laplacian,
Dart d,
const typename PFP::TREAL& edgeWeight,
const typename PFP::TREAL& vertexArea,
const AttributeHandler<ATTR_TYPE>& attr) ;
template <typename PFP, typename ATTR_TYPE>
void computeLaplacianTopoVertices(
typename PFP::MAP& map,
const AttributeHandler<ATTR_TYPE>& attr,
AttributeHandler<ATTR_TYPE>& laplacian,
const FunctorSelect& select = SelectorTrue()) ;
template <typename PFP, typename ATTR_TYPE>
void computeLaplacianCotanVertices(
typename PFP::MAP& map,
const typename PFP::TREAL& edgeWeight,
const typename PFP::TREAL& vertexArea,
const AttributeHandler<ATTR_TYPE>& attr,
AttributeHandler<ATTR_TYPE>& laplacian,
const FunctorSelect& select = SelectorTrue()) ;
template <typename PFP>
void computeLaplacianVertex_Topo(
typename PFP::REAL computeCotanWeightEdge(
typename PFP::MAP& map,
Dart d,
const typename PFP::TVEC3& position) ;
template <typename PFP>
void computeCotanWeightEdges(
typename PFP::MAP& map,
const typename PFP::TVEC3& position,
typename PFP::TVEC3& laplacian) ;
typename PFP::TREAL& edgeWeight,
const FunctorSelect& select = SelectorTrue()) ;
} // namespace Geoemtry
......
......@@ -33,13 +33,55 @@ namespace Algo
namespace Geometry
{
template <typename PFP>
void computeLaplacianVertices(
typename PFP::MAP& map,
LaplacianType type,
const typename PFP::TVEC3& position,
typename PFP::TVEC3& laplacian,
const FunctorSelect& select)
template <typename PFP, typename ATTR_TYPE>
ATTR_TYPE computeLaplacianTopoVertex(
typename PFP::MAP& map,
Dart d,
const AttributeHandler<ATTR_TYPE>& attr)
{
ATTR_TYPE l(0) ;
unsigned int val = 0 ;
Dart it = d ;
do
{
l += attr[map.phi1(it)] - attr[it] ;
val++ ;
it = map.alpha1(it) ;
} while(it != d) ;
l /= val ;
return l ;
}
template <typename PFP, typename ATTR_TYPE>
ATTR_TYPE computeLaplacianCotanVertex(
typename PFP::MAP& map,
Dart d,
const typename PFP::TREAL& edgeWeight,
const typename PFP::TREAL& vertexArea,
const AttributeHandler<ATTR_TYPE>& attr)
{
typedef typename PFP::REAL REAL ;
ATTR_TYPE l(0) ;
Dart it = d ;
REAL vArea = vertexArea[d] ;
REAL val = 0 ;
do
{
REAL w = edgeWeight[it] / vArea ;
l += (attr[map.phi1(it)] - attr[it]) * w ;
val += w ;
it = map.alpha1(it) ;
} while(it != d) ;
l /= val ;
return l ;
}
template <typename PFP, typename ATTR_TYPE>
void computeLaplacianTopoVertices(
typename PFP::MAP& map,
const AttributeHandler<ATTR_TYPE>& attr,
AttributeHandler<ATTR_TYPE>& laplacian,
const FunctorSelect& select)
{
CellMarker marker(map, VERTEX);
for(Dart d = map.begin(); d != map.end(); map.next(d))
......@@ -47,35 +89,59 @@ void computeLaplacianVertices(
if(select(d) && !marker.isMarked(d))
{
marker.mark(d);
switch(type)
{
case TOPOLOGICAL : {
computeLaplacianVertex_Topo<PFP>(map, d, position, laplacian) ;
break ; }
}
laplacian[d] = computeLaplacianTopoVertex<PFP, ATTR_TYPE>(map, d, attr) ;
}
}
}
template <typename PFP, typename ATTR_TYPE>
void computeLaplacianCotanVertices(
typename PFP::MAP& map,
const typename PFP::TREAL& edgeWeight,
const typename PFP::TREAL& vertexArea,
const AttributeHandler<ATTR_TYPE>& attr,
AttributeHandler<ATTR_TYPE>& laplacian,
const FunctorSelect& select)
{
CellMarker marker(map, VERTEX);
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(select(d) && !marker.isMarked(d))
{
marker.mark(d);
laplacian[d] = computeLaplacianCotanVertex<PFP, ATTR_TYPE>(map, d, edgeWeight, vertexArea, attr) ;
}
}
}
template <typename PFP>
void computeLaplacianVertex_Topo(
typename PFP::REAL computeCotanWeightEdge(
typename PFP::MAP& map,
Dart d,
const typename PFP::TVEC3& position)
{
typename PFP::REAL alpha = angle<PFP>(map, map.phi_1(d), map.phi2(map.phi1(d)), position) ;
Dart dd = map.phi2(d) ;
typename PFP::REAL beta = angle<PFP>(map, map.phi_1(dd), map.phi2(map.phi1(dd)), position) ;
return 0.5 * ( 1 / tan(alpha) + 1 / tan(beta) ) ;
}
template <typename PFP>
void computeCotanWeightEdges(
typename PFP::MAP& map,
const typename PFP::TVEC3& position,
typename PFP::TVEC3& laplacian)
typename PFP::TREAL& edgeWeight,
const FunctorSelect& select = SelectorTrue())
{
typedef typename PFP::VEC3 VEC3 ;
VEC3 l(0) ;
unsigned int val = 0 ;
Dart dd = d ;
do
CellMarker marker(map, EDGE);
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
l += vectorOutOfDart<PFP>(map, dd, position) ;
val++ ;
dd = map.alpha1(dd) ;
} while(dd != d) ;
l /= val ;
laplacian[d] = l ;
if(select(d) && !marker.isMarked(d))
{
marker.mark(d);
edgeWeight[d] = computeCotanWeightEdge<PFP>(map, d, position) ;
}
}
}
} // namespace Geometry
......
......@@ -50,24 +50,22 @@ typename PFP::VEC3 triangleNormal(typename PFP::MAP& map, Dart d, const typename
return N ;
}
template<typename PFP>
typename PFP::VEC3 newellNormal(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position)
{
Dart e=d;
Dart e = d;
typename PFP::VEC3 normal(0);
do
{
const typename PFP::VEC3& P = position[e];
e = map.phi1(e);
const typename PFP::VEC3& Q = position[e];
normal[0] += (P[1]-Q[1])*(P[2]+Q[2]);
normal[1] += (P[2]-Q[2])*(P[0]+Q[0]);
normal[2] += (P[0]-Q[0])*(P[1]+Q[1]);
}while (e !=d);
normal[0] += (P[1] - Q[1]) * (P[2] + Q[2]);
normal[1] += (P[2] - Q[2]) * (P[0] + Q[0]);
normal[2] += (P[0] - Q[0]) * (P[1] + Q[1]);
} while (e != d);
normal.normalize();
return normal;
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -22,8 +22,8 @@
* *
*******************************************************************************/
#ifndef __LINEAR_SOLVING_LAPLACIAN_SETUP__
#define __LINEAR_SOLVING_LAPLACIAN_SETUP__
#ifndef __LINEAR_SOLVING_VARIABLES_SETUP__
#define __LINEAR_SOLVING_VARIABLES_SETUP__
namespace CGoGN
{
......@@ -31,144 +31,122 @@ namespace CGoGN
namespace LinearSolving
{
enum LaplacianType
template <typename PFP, typename ATTR_TYPE, class SOLVER_TRAITS>
class FunctorMeshToSolver_Scalar : public FunctorType
{
TOPOLOGICAL,
COTWEIGHT
};
protected:
LinearSolver<SOLVER_TRAITS>* solver ;
const AttributeHandler<unsigned int>& indexTable ;
CellMarker& lockingMarker ;
const AttributeHandler<ATTR_TYPE>& attrTable ;
bool lockedVertices ;
public:
FunctorMeshToSolver_Scalar(
LinearSolver<SOLVER_TRAITS>* s,
const AttributeHandler<unsigned int> index,
CellMarker& lm,
const AttributeHandler<ATTR_TYPE>& attr
) : solver(s), indexTable(index), lockingMarker(lm), attrTable(attr), lockedVertices(false)
{}
bool operator()(Dart d)
{
solver->variable(indexTable[d]).set_value(attrTable[d]) ;
if(lockingMarker.isMarked(d))
{
solver->variable(indexTable[d]).lock() ;
lockedVertices = true ;
}
return false ;
}
bool hasLockedVertices() { return lockedVertices ; }
} ;
template<typename PFP, class SOLVER_TRAITS>
class LaplacianTopo : public FunctorMap<typename PFP::MAP>
template <typename PFP, typename ATTR_TYPE, class SOLVER_TRAITS>
class FunctorMeshToSolver_Vector : public FunctorType
{
protected:
LinearSolver<SOLVER_TRAITS>* solver ;
const AttributeHandler<unsigned int>& indexTable ;
CellMarker& lockingMarker ;
const AttributeHandler<ATTR_TYPE>& attrTable ;
unsigned int coord ;
bool lockedVertices ;
public:
typedef typename PFP::MAP MAP ;
LaplacianTopo(MAP& m, LinearSolver<SOLVER_TRAITS>* s, const AttributeHandler<unsigned int> index) :
FunctorMap<MAP>(m), solver(s), indexTable(index)
FunctorMeshToSolver_Vector(
LinearSolver<SOLVER_TRAITS>* s,
const AttributeHandler<unsigned int> index,
CellMarker& lm,
const AttributeHandler<ATTR_TYPE>& attr,
unsigned int c
) : solver(s), indexTable(index), lockingMarker(lm), attrTable(attr), coord(c), lockedVertices(false)
{}
bool operator()(Dart d)
{
solver->begin_row() ;
Dart dd = d ;
float aii = 0.0f ;
do
solver->variable(indexTable[d]).set_value((attrTable[d])[coord]) ;
if(lockingMarker.isMarked(d))
{
float aij = 1.0f ;
aii += aij ;
solver->add_coefficient(indexTable[this->m_map.phi2(dd)], aij) ;
dd = this->m_map.phi1(this->m_map.phi2(dd)) ;
} while(dd != d) ;
solver->add_coefficient(indexTable[d], -aii) ;
solver->set_right_hand_side(0.0f) ;
solver->normalize_row() ;
solver->end_row() ;
solver->variable(indexTable[d]).lock() ;
lockedVertices = true ;
}
return false ;
}
bool hasLockedVertices() { return lockedVertices ; }
} ;
/*
template<typename PFP, class SOLVER_TRAITS>
class LaplacianCotWeight : public FunctorMap<typename PFP::MAP>
template <typename PFP, typename ATTR_TYPE, class SOLVER_TRAITS>
class FunctorSolverToMesh_Scalar : public FunctorType
{
protected:
LinearSolver<SOLVER_TRAITS>* solver ;
const AttributeHandler<unsigned int>& indexTable ;
AttributeHandler<ATTR_TYPE>& attrTable ;
public:
LaplacianCotWeight(MAP& m, LinearSolver<SOLVER_TRAITS>* s) :
FunctorMap<MAP>(m), solver(s)
FunctorSolverToMesh_Scalar(
LinearSolver<SOLVER_TRAITS>* s,
const AttributeHandler<unsigned int> index,
AttributeHandler<ATTR_TYPE>& attr
) : solver(s), indexTable(index), attrTable(attr)
{}
// float half_w(Dart d)
// {
// Dart d1 = this->m_map.phi2( this->m_map.phi1( d)) ;
// gmtl::Vec3f V1 = this->m_map.getVertexEmb(d1)->getPosition() ;
// V1 -= this->m_map.getVertexEmb(this->m_map.phi2(d1))->getPosition() ;
// Dart d2 = this->m_map.phi_1( d) ;
// gmtl::Vec3f V2 = this->m_map.getVertexEmb(d2)->getPosition() ;
// V1 -= this->m_map.getVertexEmb(this->m_map.phi2(d2))->getPosition() ;
// float nV1 = gmtl::lengthSquared(V1) ;
// float nV2 = gmtl::lengthSquared(V2) ;
// float cos_angle = gmtl::dot(V1, V2) / sqrt(nV1 * nV2) ;
// float angle = acos(cos_angle) ;
// return 1.0 / tan(angle) ;
// }
//
// float w(Dart d)
// {
// float result = 0.0f ;
// Dart dd = this->m_map.phi2(d) ;
// result += half_w(d) ;
// result += half_w(dd) ;
// gmtl::Vec3f vec = this->m_map.getVertexEmb(d)->getPosition() ;
// vec -= this->m_map.getVertexEmb(dd)->getPosition() ;
// result *= gmtl::lengthSquared(vec) ;
// return result ;
// }
//
// float one_ring_area(Dart d)
// {
// float result = 0.0 ;
// Dart dd = d ;
// do
// {
// gmtl::Vec3f n ;
// Algo::Geometry::faceNormal<PFP>(this->m_map, d, n) ;
// result += 0.5f * gmtl::length(n) ;
// dd = this->m_map.phi1(this->m_map.phi2(dd)) ;
// } while(dd != d) ;
// return result ;
// }
bool operator()(Dart d)
{
solver->begin_row() ;
Dart dd = d ;
EMB* e = reinterpret_cast<EMB*>(this->m_map.getVertexEmb(d)) ;
unsigned int idx = e->getIndex() ;
float area = one_ring_area(d) ;
float aii = 0.0f ;
do
{
float aij = w(dd) / area ;
aii += aij ;
EMB* ne = reinterpret_cast<EMB*>(this->m_map.getVertexEmb(this->m_map.phi2(dd))) ;
unsigned int neighbour_idx = ne->getIndex() ;
this->solver->add_coefficient(neighbour_idx, aij) ;
dd = this->m_map.phi1(this->m_map.phi2(dd)) ;
} while(dd != d) ;
solver->add_coefficient(idx, -aii) ;
solver->set_right_hand_side(0.0f) ;
solver->normalize_row() ;
solver->end_row() ;
attrTable[d] = solver->variable(indexTable[d]).value() ;
return false ;
}
} ;
*/
template <typename PFP, class SOLVER_TRAITS>
void setupLaplacianMatrix(typename PFP::MAP& m, LinearSolver<SOLVER_TRAITS>* s, LaplacianType lt, const AttributeHandler<unsigned int> index)
template <typename PFP, typename ATTR_TYPE, class SOLVER_TRAITS>
class FunctorSolverToMesh_Vector : public FunctorType
{
switch(lt)
protected:
LinearSolver<SOLVER_TRAITS>* solver ;
const AttributeHandler<unsigned int>& indexTable ;
AttributeHandler<ATTR_TYPE>& attrTable ;
unsigned int coord ;
public:
FunctorSolverToMesh_Vector(
LinearSolver<SOLVER_TRAITS>* s,
const AttributeHandler<unsigned int> index,
AttributeHandler<ATTR_TYPE>& attr,
unsigned int c
) : solver(s), indexTable(index), attrTable(attr), coord(c)
{}
bool operator()(Dart d)
{
case TOPOLOGICAL : {
LaplacianTopo<PFP, SOLVER_TRAITS> lt(m, s, index) ;
m.foreach_orbit(VERTEX, lt) ;
break ; }
case COTWEIGHT : {
LaplacianTopo<PFP, SOLVER_TRAITS> lt(m, s, index) ;
m.foreach_orbit(VERTEX, lt) ;
break ; }
(attrTable[d])[coord] = solver->variable(indexTable[d]).value() ;
return false ;
}
}
} ;
}
} // namespace LinearSolving
}
} // namespace CGoGN
#endif
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