Commit b515ee2c authored by Pierre Kraemer's avatar Pierre Kraemer

pliant remeshing premiere version

parent 38f0a625
......@@ -583,15 +583,29 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
break ;
}
case 'r':
case 'd':
{
AttributeHandler<PFP::VEC3> positionF = myMap.getAttribute<PFP::VEC3>(FACE_ORBIT, "position") ;
if(!positionF.isValid())
positionF = myMap.addAttribute<PFP::VEC3>(FACE_ORBIT, "position") ;
Algo::Geometry::computeCentroidFaces<PFP>(myMap, position, positionF) ;
GLint t1 = glutGet(GLUT_ELAPSED_TIME) ;
Algo::Remeshing::pliantRemeshing<PFP>(myMap, position) ;
Algo::Modelisation::computeDual<PFP>(myMap) ;
GLint t2 = glutGet(GLUT_ELAPSED_TIME) ;
GLfloat seconds = (t2 - t1) / 1000.0f ;
std::cout << "pliant remeshing: "<< seconds << "sec" << std::endl ;
std::cout << "dual computation: "<< seconds << "sec" << std::endl ;
position = positionF ;
normal = myMap.getAttribute<PFP::VEC3>(VERTEX_ORBIT, "normal") ;
if(!normal.isValid())
normal = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "normal") ;
laplacian = myMap.getAttribute<PFP::VEC3>(VERTEX_ORBIT, "laplacian") ;
if(!laplacian.isValid())
laplacian = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "laplacian") ;
t1 = glutGet(GLUT_ELAPSED_TIME) ;
......@@ -607,29 +621,16 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
break ;
}
case 'd':
case 'r':
{
AttributeHandler<PFP::VEC3> positionF = myMap.getAttribute<PFP::VEC3>(FACE_ORBIT, "position") ;
if(!positionF.isValid())
positionF = myMap.addAttribute<PFP::VEC3>(FACE_ORBIT, "position") ;
Algo::Geometry::computeCentroidFaces<PFP>(myMap, position, positionF) ;
GLint t1 = glutGet(GLUT_ELAPSED_TIME) ;
Algo::Modelisation::computeDual<PFP>(myMap) ;
Algo::Remeshing::pliantRemeshing<PFP>(myMap, position, normal) ;
GLint t2 = glutGet(GLUT_ELAPSED_TIME) ;
GLfloat seconds = (t2 - t1) / 1000.0f ;
std::cout << "dual computation: "<< seconds << "sec" << std::endl ;
position = positionF ;
normal = myMap.getAttribute<PFP::VEC3>(VERTEX_ORBIT, "normal") ;
if(!normal.isValid())
normal = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "normal") ;
laplacian = myMap.getAttribute<PFP::VEC3>(VERTEX_ORBIT, "laplacian") ;
if(!laplacian.isValid())
laplacian = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "laplacian") ;
std::cout << "pliant remeshing: "<< seconds << "sec" << std::endl ;
t1 = glutGet(GLUT_ELAPSED_TIME) ;
......
......@@ -121,7 +121,7 @@ EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& at
{
center += attributs[map.phi2(it)];
++count ;
it = map.phi1(map.phi2(it)) ;
it = map.alpha1(it) ;
} while(it != d) ;
center /= count ;
return center ;
......
......@@ -32,7 +32,7 @@ namespace Remeshing
{
template <typename PFP>
void pliantRemeshing(typename PFP::MAP& map, typename PFP::TVEC3& position) ;
void pliantRemeshing(typename PFP::MAP& map, typename PFP::TVEC3& position, typename PFP::TVEC3& normal) ;
} // namespace Remeshing
......@@ -41,3 +41,4 @@ void pliantRemeshing(typename PFP::MAP& map, typename PFP::TVEC3& position) ;
} // namespace CGoGN
#include "Algo/Remeshing/pliant.hpp"
......@@ -34,34 +34,37 @@ namespace Remeshing
{
template <typename PFP>
void pliantRemeshing(typename PFP::MAP& map, typename PFP::TVEC3& position)
void pliantRemeshing(typename PFP::MAP& map, typename PFP::TVEC3& position, typename PFP::TVEC3& normal)
{
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
DartMarker m(map) ;
// compute the mean edge length
DartMarker m1(map) ;
REAL meanEdgeLength = 0 ;
unsigned int nbEdges = 0 ;
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(!m.isMarked(d))
if(!m1.isMarked(d))
{
m.markOrbit(EDGE_ORBIT, d) ;
m1.markOrbit(EDGE_ORBIT, d) ;
meanEdgeLength += Algo::Geometry::edgeLength<PFP>(map, d, position) ;
++nbEdges ;
}
}
meanEdgeLength /= REAL(nbEdges) ;
REAL edgeLengthInf = REAL(4) / REAL(5) * meanEdgeLength ;
// compute the min and max edge lengths
REAL edgeLengthInf = REAL(3) / REAL(4) * meanEdgeLength ;
REAL edgeLengthSup = REAL(4) / REAL(3) * meanEdgeLength ;
// split long edges
DartMarker m2(map) ;
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(m.isMarked(d))
if(!m2.isMarked(d))
{
m.unmarkOrbit(EDGE_ORBIT, d) ;
m2.markOrbit(EDGE_ORBIT, d) ;
REAL length = Algo::Geometry::edgeLength<PFP>(map, d, position) ;
if(length > edgeLengthSup)
{
......@@ -75,11 +78,13 @@ void pliantRemeshing(typename PFP::MAP& map, typename PFP::TVEC3& position)
}
}
// collapse short edges
DartMarker m3(map) ;
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(!m.isMarked(d))
if(!m3.isMarked(d))
{
m.markOrbit(EDGE_ORBIT, d) ;
m3.markOrbit(EDGE_ORBIT, d) ;
REAL length = Algo::Geometry::edgeLength<PFP>(map, d, position) ;
if(length < edgeLengthInf)
{
......@@ -102,6 +107,54 @@ void pliantRemeshing(typename PFP::MAP& map, typename PFP::TVEC3& position)
}
}
}
// equalize valences with edge flips
DartMarker m4(map) ;
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(!m4.isMarked(d))
{
m4.markOrbit(EDGE_ORBIT, d) ;
Dart e = map.phi2(d) ;
unsigned int w = map.vertexDegree(d) ;
unsigned int x = map.vertexDegree(e) ;
unsigned int y = map.vertexDegree(map.phi1(map.phi1(d))) ;
unsigned int z = map.vertexDegree(map.phi1(map.phi1(e))) ;
int flip = 0 ;
flip += w > 6 ? 1 : (w < 6 ? -1 : 0) ;
flip += x > 6 ? 1 : (x < 6 ? -1 : 0) ;
flip += y < 6 ? 1 : (y > 6 ? -1 : 0) ;
flip += z < 6 ? 1 : (z > 6 ? -1 : 0) ;
if(flip > 2)
{
map.flipEdge(d) ;
m4.markOrbit(EDGE_ORBIT, map.phi1(d)) ;
m4.markOrbit(EDGE_ORBIT, map.phi_1(d)) ;
m4.markOrbit(EDGE_ORBIT, map.phi1(e)) ;
m4.markOrbit(EDGE_ORBIT, map.phi_1(e)) ;
}
}
}
// update vertices normals
Algo::Geometry::computeNormalVertices<PFP>(map, position, normal) ;
// tangential relaxation
AttributeHandler<VEC3> newPosition = map.template addAttribute<VEC3>(VERTEX_ORBIT, "newPosition") ;
Algo::Geometry::computeNeighborhoodCentroidVertices<PFP>(map, position, newPosition) ;
CellMarker vm(map, VERTEX_CELL) ;
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(!vm.isMarked(d))
{
vm.mark(d) ;
VEC3 l = position[d] - newPosition[d] ;
newPosition[d] = newPosition[d] + ((normal[d] * l) * normal[d]) ;
}
}
map.template swapAttributes<VEC3>(position, newPosition) ;
map.template removeAttribute<VEC3>(newPosition) ;
}
} // namespace Remeshing
......
......@@ -205,6 +205,26 @@ Dart EmbeddedMap2<MAP2>::collapseEdge(Dart d, bool delDegenerateFaces)
template <typename MAP2>
bool EmbeddedMap2<MAP2>::flipEdge(Dart d)
{
// unsigned int dVEmb = EMBNULL ;
// unsigned int eVEmb = EMBNULL ;
//
// Dart e = MAP2::phi2(d) ;
//
// if(MAP2::isOrbitEmbedded(VERTEX_ORBIT))
// {
// dVEmb = MAP2::getDartEmbedding(VERTEX_ORBIT, d) ;
// if(dVEmb != EMBNULL)
// MAP2::setDartEmbedding(VERTEX_ORBIT, MAP2::alpha1(d), dVEmb) ;
// MAP2::setDartEmbedding(VERTEX_ORBIT, d, EMBNULL) ;
//
// eVEmb = MAP2::getDartEmbedding(VERTEX_ORBIT, e) ;
// if(eVEmb != EMBNULL)
// MAP2::setDartEmbedding(VERTEX_ORBIT, MAP2::alpha1(e), eVEmb) ;
// MAP2::setDartEmbedding(VERTEX_ORBIT, e, EMBNULL) ;
// }
//
// return MAP2::flipEdge(d) ;
if(MAP2::flipEdge(d))
{
Dart e = MAP2::phi2(d) ;
......@@ -221,7 +241,6 @@ bool EmbeddedMap2<MAP2>::flipEdge(Dart d)
MAP2::setDartEmbedding(VERTEX_ORBIT, MAP2::phi_1(e), eVEmb) ;
MAP2::setDartEmbedding(VERTEX_ORBIT, e, EMBNULL) ;
}
if (MAP2::isOrbitEmbedded(FACE_ORBIT))
{
unsigned int dFEmb = MAP2::getDartEmbedding(FACE_ORBIT, MAP2::phi_1(e)) ;
......@@ -467,6 +486,7 @@ bool EmbeddedMap2<MAP2>::check()
bool topo = MAP2::check() ;
if (!topo)
return false ;
std::cout << "Check: embedding begin" << std::endl ;
for(Dart d = MAP2::begin(); d != MAP2::end(); MAP2::next(d))
{
......
......@@ -143,7 +143,7 @@ public:
virtual Dart collapseEdge(Dart d, bool delDegenerateFaces = true);
/**
* Flip the edge of d. (rotation in phi1 order)
* Flip the edge of d (rotation in phi1 order)
* WARNING : Works only for non-border edges.
* @param d a dart of the edge to flip
* @return true if the flip has been executed, false otherwise
......@@ -151,7 +151,7 @@ public:
virtual bool flipEdge(Dart d);
/**
* Flip the edge of d. (rotation in phi_1 order)
* Flip the edge of d (rotation in phi_1 order)
* WARNING : Works only for non-border edges.
* @param d a dart of the edge to flip
* @return true if the flip has been executed, false otherwise
......
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