Commit 51620456 authored by untereiner's avatar untereiner

Merge cgogn:~cgogn/CGoGN

parents 22a1e9b7 c0fb7beb
...@@ -35,17 +35,29 @@ namespace Geometry ...@@ -35,17 +35,29 @@ namespace Geometry
{ {
template <typename PFP> 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> 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> template <typename PFP>
typename PFP::REAL totalArea(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& select = SelectorTrue(), unsigned int th=0) ; 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> template <typename PFP>
void computeAreaFaces(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TREAL& face_area, const FunctorSelect& select = SelectorTrue()) ; 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 Geometry
} // namespace Algo } // namespace Algo
......
...@@ -70,7 +70,7 @@ typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const typename ...@@ -70,7 +70,7 @@ typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const typename
template <typename PFP> template <typename PFP>
typename PFP::REAL totalArea(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& select, unsigned int th) 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) ; DartMarker mark(map,th) ;
for(Dart d = map.begin(); d != map.end(); map.next(d)) 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& ...@@ -83,6 +83,32 @@ typename PFP::REAL totalArea(typename PFP::MAP& map, const typename PFP::TVEC3&
return area ; 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> template <typename PFP>
void computeAreaFaces(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TREAL& face_area, const FunctorSelect& select) 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 ...@@ -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 Geometry
} // namespace Algo } // namespace Algo
......
...@@ -40,25 +40,48 @@ namespace Algo ...@@ -40,25 +40,48 @@ namespace Algo
namespace Geometry namespace Geometry
{ {
enum LaplacianType template <typename PFP, typename ATTR_TYPE>
{ ATTR_TYPE computeLaplacianTopoVertex(
TOPOLOGICAL typename PFP::MAP& map,
}; Dart d,
const AttributeHandler<ATTR_TYPE>& attr) ;
template <typename PFP> template <typename PFP, typename ATTR_TYPE>
void computeLaplacianVertices( ATTR_TYPE computeLaplacianCotanVertex(
typename PFP::MAP& map, typename PFP::MAP& map,
LaplacianType type, Dart d,
const typename PFP::TVEC3& position, const typename PFP::TREAL& edgeWeight,
typename PFP::TVEC3& laplacian, 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()) ; const FunctorSelect& select = SelectorTrue()) ;
template <typename PFP> template <typename PFP>
void computeLaplacianVertex_Topo( typename PFP::REAL computeCotanWeightEdge(
typename PFP::MAP& map, typename PFP::MAP& map,
Dart d, Dart d,
const typename PFP::TVEC3& position) ;
template <typename PFP>
void computeCotanWeightEdges(
typename PFP::MAP& map,
const typename PFP::TVEC3& position, const typename PFP::TVEC3& position,
typename PFP::TVEC3& laplacian) ; typename PFP::TREAL& edgeWeight,
const FunctorSelect& select = SelectorTrue()) ;
} // namespace Geoemtry } // namespace Geoemtry
......
...@@ -33,13 +33,55 @@ namespace Algo ...@@ -33,13 +33,55 @@ namespace Algo
namespace Geometry namespace Geometry
{ {
template <typename PFP> template <typename PFP, typename ATTR_TYPE>
void computeLaplacianVertices( ATTR_TYPE computeLaplacianTopoVertex(
typename PFP::MAP& map, typename PFP::MAP& map,
LaplacianType type, Dart d,
const typename PFP::TVEC3& position, const AttributeHandler<ATTR_TYPE>& attr)
typename PFP::TVEC3& laplacian, {
const FunctorSelect& select) 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); CellMarker marker(map, VERTEX);
for(Dart d = map.begin(); d != map.end(); map.next(d)) for(Dart d = map.begin(); d != map.end(); map.next(d))
...@@ -47,35 +89,59 @@ void computeLaplacianVertices( ...@@ -47,35 +89,59 @@ void computeLaplacianVertices(
if(select(d) && !marker.isMarked(d)) if(select(d) && !marker.isMarked(d))
{ {
marker.mark(d); marker.mark(d);
switch(type) laplacian[d] = computeLaplacianTopoVertex<PFP, ATTR_TYPE>(map, d, attr) ;
{ }
case TOPOLOGICAL : { }
computeLaplacianVertex_Topo<PFP>(map, d, position, laplacian) ; }
break ; }
} 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> template <typename PFP>
void computeLaplacianVertex_Topo( typename PFP::REAL computeCotanWeightEdge(
typename PFP::MAP& map, typename PFP::MAP& map,
Dart d, 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, const typename PFP::TVEC3& position,
typename PFP::TVEC3& laplacian) typename PFP::TREAL& edgeWeight,
const FunctorSelect& select = SelectorTrue())
{ {
typedef typename PFP::VEC3 VEC3 ; CellMarker marker(map, EDGE);
VEC3 l(0) ; for(Dart d = map.begin(); d != map.end(); map.next(d))
unsigned int val = 0 ;
Dart dd = d ;
do
{ {
l += vectorOutOfDart<PFP>(map, dd, position) ; if(select(d) && !marker.isMarked(d))
val++ ; {
dd = map.alpha1(dd) ; marker.mark(d);
} while(dd != d) ; edgeWeight[d] = computeCotanWeightEdge<PFP>(map, d, position) ;
l /= val ; }
laplacian[d] = l ; }
} }
} // namespace Geometry } // namespace Geometry
......
...@@ -50,24 +50,22 @@ typename PFP::VEC3 triangleNormal(typename PFP::MAP& map, Dart d, const typename ...@@ -50,24 +50,22 @@ typename PFP::VEC3 triangleNormal(typename PFP::MAP& map, Dart d, const typename
return N ; return N ;
} }
template<typename PFP> template<typename PFP>
typename PFP::VEC3 newellNormal(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) 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); typename PFP::VEC3 normal(0);
do do
{ {
const typename PFP::VEC3& P = position[e]; const typename PFP::VEC3& P = position[e];
e = map.phi1(e); e = map.phi1(e);
const typename PFP::VEC3& Q = position[e]; const typename PFP::VEC3& Q = position[e];
normal[0] += (P[1]-Q[1])*(P[2]+Q[2]); normal[0] += (P[1] - Q[1]) * (P[2] + Q[2]);
normal[1] += (P[2]-Q[2])*(P[0]+Q[0]); normal[1] += (P[2] - Q[2]) * (P[0] + Q[0]);
normal[2] += (P[0]-Q[0])*(P[1]+Q[1]); normal[2] += (P[0] - Q[0]) * (P[1] + Q[1]);
}while (e !=d); } while (e != d);
normal.normalize(); normal.normalize();
return normal; return normal;
} }
......
...@@ -65,9 +65,9 @@ class MeshTablesSurface ...@@ -65,9 +65,9 @@ class MeshTablesSurface
protected: protected:
typename PFP::MAP& m_map; typename PFP::MAP& m_map;
unsigned m_nbVertices; unsigned int m_nbVertices;
unsigned m_nbFaces; unsigned int m_nbFaces;
unsigned int m_lab; unsigned int m_lab;
...@@ -138,11 +138,11 @@ class MeshTablesVolume ...@@ -138,11 +138,11 @@ class MeshTablesVolume
protected: protected:
typename PFP::MAP& m_map; typename PFP::MAP& m_map;
unsigned m_nbVertices; unsigned int m_nbVertices;
unsigned m_nbFaces; unsigned int m_nbFaces;
unsigned m_nbVolumes; unsigned int m_nbVolumes;
/** /**
* number of edges per face * number of edges per face
......
...@@ -267,7 +267,7 @@ bool MeshTablesSurface<PFP>::importTrianBinGz(const std::string& filename, std:: ...@@ -267,7 +267,7 @@ bool MeshTablesSurface<PFP>::importTrianBinGz(const std::string& filename, std::
template<typename PFP> template<typename PFP>
bool MeshTablesSurface<PFP>::importOff(const std::string& filename, std::vector<std::string>& attrNames) bool MeshTablesSurface<PFP>::importOff(const std::string& filename, std::vector<std::string>& attrNames)
{ {
AttributeHandler<typename PFP::VEC3> positions = m_map.template getAttribute<typename PFP::VEC3>(VERTEX, "position") ; AttributeHandler<typename PFP::VEC3> positions = m_map.template getAttribute<typename PFP::VEC3>(VERTEX, "position") ;
if (!positions.isValid()) if (!positions.isValid())
positions = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "position") ; positions = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "position") ;
......
This diff is collapsed.
This diff is collapsed.
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#ifndef __LINEAR_SOLVING_LAPLACIAN_SETUP__ #ifndef __LINEAR_SOLVING_VARIABLES_SETUP__
#define __LINEAR_SOLVING_LAPLACIAN_SETUP__ #define __LINEAR_SOLVING_VARIABLES_SETUP__
namespace CGoGN namespace CGoGN
{ {
...@@ -31,144 +31,122 @@ namespace CGoGN ...@@ -31,144 +31,122 @@ namespace CGoGN
namespace LinearSolving namespace LinearSolving
{ {
enum LaplacianType template <typename PFP, typename ATTR_TYPE, class SOLVER_TRAITS>
class FunctorMeshToSolver_Scalar : public FunctorType
{ {
TOPOLOGICAL, protected:
COTWEIGHT 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> template <typename PFP, typename ATTR_TYPE, class SOLVER_TRAITS>
class LaplacianTopo : public FunctorMap<typename PFP::MAP> class FunctorMeshToSolver_Vector : public FunctorType
{ {
protected: protected:
LinearSolver<SOLVER_TRAITS>* solver ; LinearSolver<SOLVER_TRAITS>* solver ;
const AttributeHandler<unsigned int>& indexTable ; const AttributeHandler<unsigned int>& indexTable ;
CellMarker& lockingMarker ;
const AttributeHandler<ATTR_TYPE>& attrTable ;
unsigned int coord ;
bool lockedVertices ;
public: public:
typedef typename PFP::MAP MAP ; FunctorMeshToSolver_Vector(
LinearSolver<SOLVER_TRAITS>* s,
const AttributeHandler<unsigned int> index,
LaplacianTopo(MAP& m, LinearSolver<SOLVER_TRAITS>* s, const AttributeHandler<unsigned int> index) : CellMarker& lm,
FunctorMap<MAP>(m), solver(s), indexTable(index) const AttributeHandler<ATTR_TYPE>& attr,
unsigned int c
) : solver(s), indexTable(index), lockingMarker(lm), attrTable(attr), coord(c), lockedVertices(false)
{} {}
bool operator()(Dart d) bool operator()(Dart d)
{ {
solver->begin_row() ; solver->variable(indexTable[d]).set_value((attrTable[d])[coord]) ;
Dart dd = d ; if(lockingMarker.isMarked(d))
float aii = 0.0f ;
do
{ {
float aij = 1.0f ; solver->variable(indexTable[d]).lock() ;
aii += aij ; lockedVertices = true ;
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() ;
return false ; return false ;
} }
bool hasLockedVertices() { return lockedVertices ; }
} ; } ;
/* template <typename PFP, typename ATTR_TYPE, class SOLVER_TRAITS>
template<typename PFP, class SOLVER_TRAITS> class FunctorSolverToMesh_Scalar : public FunctorType
class LaplacianCotWeight : public FunctorMap<typename PFP::MAP>
{ {
protected: protected:
LinearSolver<SOLVER_TRAITS>* solver ; LinearSolver<SOLVER_TRAITS>* solver ;
const AttributeHandler<unsigned int>& indexTable ;
AttributeHandler<ATTR_TYPE>& attrTable ;
public: public:
LaplacianCotWeight(MAP& m, LinearSolver<SOLVER_TRAITS>* s) : FunctorSolverToMesh_Scalar(
FunctorMap<MAP>(m), solver(s) 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() ;