Commit 7631797f authored by Pierre Kraemer's avatar Pierre Kraemer

pliant remeshing : la suite..

parent ba8c6802
......@@ -45,6 +45,8 @@
#include "Algo/Decimation/decimation.h"
#include "Algo/Remeshing/pliant.h"
#include "Algo/Selection/raySelector.h"
using namespace CGoGN ;
struct PFP: public PFP_STANDARD
......@@ -96,6 +98,8 @@ public:
Algo::Render::VBO::topo_VBORenderMapD* topo_render ;
GLuint dl_norm, dl_lapl ;
Dart selectedDart ;
MyGlutWin(int* argc, char **argv, int winX, int winY) ;
void init() ;
......@@ -306,6 +310,8 @@ MyGlutWin::MyGlutWin(int* argc, char **argv, int winX, int winY) :
shaders[0].loadShaders("phong_vs.txt", "phong_ps.txt") ;
shaders[1].loadShaders("flat_vs.txt", "flat_ps.txt", "flat_gs.txt") ;
}
selectedDart = Dart::nil() ;
}
void MyGlutWin::init()
......@@ -349,10 +355,26 @@ void MyGlutWin::myRedraw()
glPushMatrix() ;
float sc = 50. / gWidthObj ;
float sc = 50.0f / gWidthObj ;
glScalef(sc, sc, sc) ;
glTranslatef(-gPosObj[0], -gPosObj[1], -gPosObj[2]) ;
if(!selectedDart.isNil())
{
glDisable(GL_LIGHTING) ;
glColor3f(1.0f,0.0f,0.0f) ;
glLineWidth(3.0f) ;
PFP::VEC3 c = Algo::Geometry::faceCentroid<PFP>(myMap, selectedDart, position) ;
PFP::VEC3 p1 = position[selectedDart] ;
PFP::VEC3 p2 = position[myMap.phi1(selectedDart)] ;
p1 += PFP::REAL(0.1) * (c - p1) ;
p2 += PFP::REAL(0.1) * (c - p2) ;
glBegin(GL_LINES) ;
glVertex3fv(p1.data()) ;
glVertex3fv(p2.data()) ;
glEnd() ;
}
if (renderTopo)
{
glDisable(GL_LIGHTING);
......@@ -705,6 +727,37 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
break ;
}
case 'i':
{
glPushMatrix();
float sc = 50.0f / gWidthObj ;
glScalef(sc, sc, sc) ;
glTranslatef(-gPosObj[0], -gPosObj[1], -gPosObj[2]) ;
PFP::VEC3 rayA, rayB ;
getOrthoScreenRay(x, y, rayA, rayB) ;
PFP::VEC3 AB = rayB - rayA ;
std::vector<Dart> darts ;
Algo::Selection::dartsRaySelection<PFP>(myMap, position, rayA, AB, darts) ;
glPopMatrix();
if(!darts.empty())
{
selectedDart = darts[0] ;
std::cout << "selected dart -> " << selectedDart << std::endl ;
std::cout << " phi1 -> " << myMap.phi1(selectedDart) << " / phi2 -> " << myMap.phi2(selectedDart) << std::endl ;
std::cout << " emb0 -> " << myMap.getDartEmbedding(VERTEX_ORBIT, selectedDart) << std::endl ;
}
else
selectedDart = Dart::nil() ;
glutPostRedisplay() ;
break ;
}
case 'a':
{
Algo::Geometry::computeLaplacianVertices<PFP>(myMap, Algo::Geometry::TOPOLOGICAL, position, laplacian) ;
......
......@@ -40,9 +40,9 @@ typename PFP::VEC3 triangleNormal(typename PFP::MAP& map, Dart d, const typename
{
typedef typename PFP::VEC3 VEC3 ;
VEC3 p1 = position[d];
VEC3 p2 = position[map.phi1(d)];
VEC3 p3 = position[map.phi_1(d)];
const VEC3& p1 = position[d];
const VEC3& p2 = position[map.phi1(d)];
const VEC3& p3 = position[map.phi_1(d)];
VEC3 N = Geom::triangleNormal(p1, p2, p3) ;
N.normalize() ;
......@@ -84,10 +84,13 @@ typename PFP::VEC3 vertexNormal(typename PFP::MAP& map, Dart d, const typename P
do
{
VEC3 n = faceNormal<PFP>(map, it, position) ;
VEC3 v1 = vectorOutOfDart<PFP>(map, it, position) ;
VEC3 v2 = vectorOutOfDart<PFP>(map, map.phi_1(it), position) ;
n *= convexFaceArea<PFP>(map,it,position) / (v1.norm2() * v2.norm2()) ;
N += n ;
if(!n.hasNan())
{
VEC3 v1 = vectorOutOfDart<PFP>(map, it, position) ;
VEC3 v2 = vectorOutOfDart<PFP>(map, map.phi_1(it), position) ;
n *= convexFaceArea<PFP>(map, it, position) / (v1.norm2() * v2.norm2()) ;
N += n ;
}
it = map.phi1(map.phi2(it)) ;
} while (it != d) ;
N.normalize() ;
......
......@@ -86,7 +86,7 @@ void pliantRemeshing(typename PFP::MAP& map, typename PFP::TVEC3& position, type
{
m3.markOrbit(EDGE_ORBIT, d) ;
REAL length = Algo::Geometry::edgeLength<PFP>(map, d, position) ;
if(length < edgeLengthInf)
if(length < edgeLengthInf && map.edgeCanCollapse(d))
{
bool collapse = true ;
Dart dd = map.phi2(d) ;
......@@ -125,7 +125,7 @@ void pliantRemeshing(typename PFP::MAP& map, typename PFP::TVEC3& position, type
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)
if(flip > 1)
{
map.flipEdge(d) ;
m4.markOrbit(EDGE_ORBIT, map.phi1(d)) ;
......@@ -140,8 +140,8 @@ void pliantRemeshing(typename PFP::MAP& map, typename PFP::TVEC3& position, type
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) ;
AttributeHandler<VEC3> centroid = map.template addAttribute<VEC3>(VERTEX_ORBIT, "centroid") ;
Algo::Geometry::computeNeighborhoodCentroidVertices<PFP>(map, position, centroid) ;
CellMarker vm(map, VERTEX_CELL) ;
for(Dart d = map.begin(); d != map.end(); map.next(d))
......@@ -149,12 +149,14 @@ void pliantRemeshing(typename PFP::MAP& map, typename PFP::TVEC3& position, type
if(!vm.isMarked(d))
{
vm.mark(d) ;
VEC3 l = position[d] - newPosition[d] ;
newPosition[d] = newPosition[d] + ((normal[d] * l) * normal[d]) ;
VEC3 l = position[d] - centroid[d] ;
REAL e = l * normal[d] ;
VEC3 displ = e * normal[d] ;
position[d] = centroid[d] + displ ;
}
}
map.template swapAttributes<VEC3>(position, newPosition) ;
map.template removeAttribute<VEC3>(newPosition) ;
map.template removeAttribute<VEC3>(centroid) ;
}
} // namespace Remeshing
......
......@@ -132,6 +132,8 @@ public:
// Equal
bool operator==(const Vector<DIM,T>& v) const ;
bool hasNan() const ;
/**********************************************/
/* STREAM OPERATORS */
/**********************************************/
......
......@@ -270,11 +270,21 @@ inline Vector<DIM,T> Vector<DIM,T>::operator^(const Vector<DIM,T> v) const
template <unsigned int DIM, typename T>
inline bool Vector<DIM,T>::operator==(const Vector<DIM,T>& v) const
{
for (unsigned int i = 0 ; i < DIM ; ++i)
if (v[i] != m_data[i]) return false ;
for(unsigned int i = 0 ; i < DIM ; ++i)
if(v[i] != m_data[i])
return false ;
return true ;
}
template <unsigned int DIM, typename T>
inline bool Vector<DIM,T>::hasNan() const
{
for(unsigned int i = 0 ; i < DIM ; ++i)
if(isnan(m_data[i]))
return true ;
return false ;
}
/**********************************************/
/* STREAM OPERATORS */
/**********************************************/
......
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