Commit e401dc09 authored by Pierre Kraemer's avatar Pierre Kraemer

draw topo in viewer + update feature lines

parent 3288e972
......@@ -30,6 +30,7 @@ Viewer::Viewer() :
m_drawEdges(false),
m_drawFaces(true),
m_drawNormals(false),
m_drawTopo(false),
m_render(NULL),
m_phongShader(NULL),
m_flatShader(NULL),
......@@ -68,6 +69,7 @@ void Viewer::initGUI()
setCallBack( dock.check_drawEdges, SIGNAL(toggled(bool)), SLOT(slot_drawEdges(bool)) ) ;
setCallBack( dock.check_drawFaces, SIGNAL(toggled(bool)), SLOT(slot_drawFaces(bool)) ) ;
setCallBack( dock.combo_faceLighting, SIGNAL(currentIndexChanged(int)), SLOT(slot_faceLighting(int)) ) ;
setCallBack( dock.check_drawTopo, SIGNAL(toggled(bool)), SLOT(slot_drawTopo(bool)) ) ;
setCallBack( dock.check_drawNormals, SIGNAL(toggled(bool)), SLOT(slot_drawNormals(bool)) ) ;
setCallBack( dock.slider_normalsSize, SIGNAL(valueChanged(int)), SLOT(slot_normalsSize(int)) ) ;
}
......@@ -79,6 +81,9 @@ void Viewer::cb_initGL()
setFocal(5.0f) ;
m_render = new Algo::Render::GL2::MapRender() ;
m_topoRender = new Algo::Render::GL2::TopoRender() ;
m_topoRender->setInitialDartsColor(0.25f, 0.25f, 0.25f) ;
m_positionVBO = new Utils::VBO() ;
m_normalVBO = new Utils::VBO() ;
......@@ -119,7 +124,6 @@ void Viewer::cb_initGL()
void Viewer::cb_redraw()
{
//glClearColor(1,1,1,0);
if(m_drawVertices)
{
float size = vertexScaleFactor ;
......@@ -135,14 +139,6 @@ void Viewer::cb_redraw()
m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES) ;
}
if(m_drawNormals)
{
float size = normalBaseSize * normalScaleFactor ;
m_vectorShader->setScale(size) ;
glLineWidth(1.0f) ;
m_render->draw(m_vectorShader, Algo::Render::GL2::POINTS) ;
}
if(m_drawFaces)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
......@@ -161,6 +157,19 @@ void Viewer::cb_redraw()
}
glDisable(GL_POLYGON_OFFSET_FILL) ;
}
if(m_drawTopo)
{
m_topoRender->drawTopo() ;
}
if(m_drawNormals)
{
float size = normalBaseSize * normalScaleFactor ;
m_vectorShader->setScale(size) ;
glLineWidth(1.0f) ;
m_render->draw(m_vectorShader, Algo::Render::GL2::POINTS) ;
}
}
void Viewer::cb_Open()
......@@ -209,6 +218,8 @@ void Viewer::importMesh(std::string& filename)
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES) ;
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES) ;
m_topoRender->updateData<PFP>(myMap, position, 0.85f, 0.85f) ;
bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
normalBaseSize = bb.diagSize() / 100.0f ;
// vertexBaseSize = normalBaseSize / 5.0f ;
......@@ -271,6 +282,12 @@ void Viewer::slot_faceLighting(int i)
updateGL() ;
}
void Viewer::slot_drawTopo(bool b)
{
m_drawTopo = b ;
updateGL() ;
}
void Viewer::slot_drawNormals(bool b)
{
m_drawNormals = b ;
......@@ -280,6 +297,7 @@ void Viewer::slot_drawNormals(bool b)
void Viewer::slot_normalsSize(int i)
{
normalScaleFactor = i / 50.0f ;
m_topoRender->updateData<PFP>(myMap, position, i / 100.0f, i / 100.0f) ;
updateGL() ;
}
......
......@@ -90,11 +90,13 @@ public:
bool m_drawEdges ;
bool m_drawFaces ;
bool m_drawNormals ;
bool m_drawTopo ;
PFP::TVEC3 position ;
PFP::TVEC3 normal ;
Algo::Render::GL2::MapRender* m_render ;
Algo::Render::GL2::TopoRender* m_topoRender ;
Utils::VBO* m_positionVBO ;
Utils::VBO* m_normalVBO ;
......@@ -123,6 +125,7 @@ public slots:
void slot_drawEdges(bool b) ;
void slot_drawFaces(bool b) ;
void slot_faceLighting(int i) ;
void slot_drawTopo(bool b) ;
void slot_drawNormals(bool b) ;
void slot_normalsSize(int i) ;
};
......@@ -73,6 +73,13 @@
</item>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawTopo">
<property name="text">
<string>draw topo</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawNormals">
<property name="text">
......
......@@ -25,8 +25,6 @@
#ifndef __ALGO_GEOMETRY_FEATURE_H__
#define __ALGO_GEOMETRY_FEATURE_H__
namespace CGoGN
{
......@@ -38,15 +36,11 @@ namespace Geometry
enum
{
EMPTY,
SEGMENT,
BARY
EMPTY = 0,
SEGMENT = 1,
BARY = 2
};
//#define EMPTY 0
//#define SEGMENT 1
//#define BARY 2
typedef struct { Dart d ; float w ; } e0point ;
typedef struct { e0point p1 ; e0point p2 ; unsigned char type ; } e0segment ;
typedef NoMathIONameAttribute<e0segment> ridgeSegment ;
......@@ -61,22 +55,45 @@ template <typename PFP>
void computeFaceGradient(
typename PFP::MAP& map,
const typename PFP::TVEC3& position,
const typename PFP::TVEC3& face_normal,
const typename PFP::TREAL& kmax,
const typename PFP::TREAL& face_area,
typename PFP::TVEC3& face_gradient,
const FunctorSelect& select = allDarts,
unsigned int thread = 0) ;
template <typename PFP>
typename PFP::VEC3 faceGradient(
typename PFP::MAP& map,
Dart d,
const typename PFP::TVEC3& position,
const typename PFP::TVEC3& face_normal,
const typename PFP::TREAL& kmax,
const typename PFP::TREAL& area,
const typename PFP::TREAL& area) ;
template <typename PFP>
void computeVertexGradient(
typename PFP::MAP& map,
const typename PFP::TVEC3& face_gradient,
const typename PFP::TREAL& face_area,
typename PFP::TVEC3& vertex_gradient,
const FunctorSelect& select = allDarts,
unsigned int thread = 0) ;
template <typename PFP>
typename PFP::VEC3 vertexGradient(
typename PFP::MAP& map,
Dart d,
const typename PFP::TVEC3& face_gradient,
const typename PFP::TREAL& area) ;
//template <typename PFP>
//void computeVertexGradient(
//typename PFP::REAL extremality(
// typename PFP::MAP& map,
// const typename PFP::TVEC3& position,
// typename PFP::TVEC3& gradient,
// typename PFP::TVEC3& face_gradient,
// const typename PFP::TREAL& area,
// const FunctorSelect& select = allDarts,
// unsigned int thread = 0) ;
// Dart d,
// const typename PFP::VEC3& K,
// const typename PFP::TVEC3& face_gradient,
// const typename PFP::TREAL& face_area) ;
template <typename PFP>
void computeTriangleType(
......@@ -87,94 +104,61 @@ void computeTriangleType(
unsigned int thread = 0) ;
template <typename PFP>
void computeRidgeLines(
typename PFP::MAP& map,
const typename PFP::TVEC3& position,
CellMarker& regularMarker,
const typename PFP::TVEC3& faceGradient,
const typename PFP::TREAL& area,
const typename PFP::TVEC3& K,
AttributeHandler<ridgeSegment>& ridge_segments,
const FunctorSelect& select = allDarts,
unsigned int thread = 0) ;
bool isTriangleRegular(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& Kmax) ;
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(
void computeRidgeLines(
typename PFP::MAP& map,
const typename PFP::TVEC3& position,
CellMarker& regularMarker,
typename PFP::TVEC3& k,
const typename PFP::TVEC3& vertex_gradient,
const 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) ;
template <typename PFP>
typename PFP::VEC3 faceGradient(
typename PFP::MAP& map,
Dart d,
const typename PFP::TVEC3& position,
const typename PFP::TVEC3& face_normal,
const typename PFP::TREAL& kmax,
const typename PFP::TREAL& area) ;
template <typename PFP>
bool isTriangleRegular(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& Kmax) ;
//template <typename PFP>
//bool isInSameOctant(const typename PFP::VEC3& pos1, const typename PFP::VEC3& pos2) ;
template <typename PFP>
void ridgeLines(
typename PFP::MAP& map,
Dart d,
const typename PFP::TVEC3& position,
const typename PFP::TVEC3& K,
const typename PFP::TVEC3& faceGradient,
const typename PFP::TREAL& area,
const typename PFP::TVEC3& vertex_gradient,
AttributeHandler<ridgeSegment>& ridge_segments) ;
template <typename PFP>
typename PFP::REAL extremality(
typename PFP::MAP& map,
Dart d,
const typename PFP::VEC3& K,
const typename PFP::TVEC3& faceGradient,
const typename PFP::TREAL& area) ;
void computeExtremalities() ;
//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 computeSingularTriangle(
typename PFP::MAP& map,
CellMarker& regularMarker,
AttributeHandler<ridgeSegment>& ridge_segments,
const FunctorSelect& select = allDarts,
unsigned int thread = 0) ;
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) ;
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) ;
} // namespace Geometry
} // namespace Algo
......
......@@ -65,10 +65,10 @@ template <typename PFP>
void computeFaceGradient(
typename PFP::MAP& map,
const typename PFP::TVEC3& position,
typename PFP::TVEC3& face_gradient,
const typename PFP::TVEC3& face_normal,
const typename PFP::TREAL& kmax,
const typename PFP::TREAL& area,
typename PFP::TVEC3& face_gradient,
const FunctorSelect& select,
unsigned int thread)
{
......@@ -77,143 +77,6 @@ void computeFaceGradient(
face_gradient[d] = faceGradient<PFP>(map, d, position, face_normal, kmax, area) ;
}
//template <typename PFP>
//void computeVertexGradient(
// typename PFP::MAP& map,
// const typename PFP::TVEC3& position,
// typename PFP::TVEC3& gradient,
// typename PFP::TVEC3& face_gradient,
// const typename PFP::TREAL& area,
// const FunctorSelect& select,
// unsigned int thread)
//{
// TraversorV<typename PFP::MAP> trav(map, select, thread);
// for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
// gradient[d] = vertexGradient<PFP>(map, d, position, face_gradient, area) ;
//}
template <typename PFP>
void computeTriangleType(
typename PFP::MAP& map,
const typename PFP::TVEC3& Kmax,
CellMarker& regularMarker,
const FunctorSelect& select,
unsigned int thread)
{
TraversorF<typename PFP::MAP> trav(map, select, thread);
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
if(isTriangleRegular<PFP>(map, d, Kmax))
regularMarker.mark(d) ;
}
template <typename PFP>
void computeRidgeLines(
typename PFP::MAP& map,
const typename PFP::TVEC3& position,
CellMarker& regularMarker,
const typename PFP::TVEC3& faceGradient,
const typename PFP::TREAL& area,
const typename PFP::TVEC3& K,
AttributeHandler<ridgeSegment>& ridge_segments,
const FunctorSelect& select,
unsigned int thread)
{
TraversorF<typename PFP::MAP> trav(map, select, thread);
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
{
if (regularMarker.isMarked(d))
ridgeLines<PFP>(map, d, position, 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,
unsigned int thread)
{
TraversorF<typename PFP::MAP> trav(map, select, thread);
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
ridge_segments[d].type = 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))
singularTriangle<PFP>(map, d, position, regularMarker, ridge_segments) ;
}
}
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)
{
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
std::vector<VEC3> occludingContours ;
TraversorF<typename PFP::MAP> t(map) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
VEC3 p1 = position[d] ;
VEC3 p2 = position[map.phi1(d)] ;
VEC3 p3 = position[map.phi_1(d)] ;
REAL dp1 = (p1 - cameraPosition) * normal[d] ;
REAL dp2 = (p2 - cameraPosition) * normal[map.phi1(d)] ;
REAL dp3 = (p3 - cameraPosition) * normal[map.phi_1(d)] ;
if(dp1 < 0 && dp2 > 0)
{
REAL alpha = -dp1 / (-dp1 + dp2) ;
occludingContours.push_back(alpha * p1 + (1 - alpha) * p2) ;
}
if(dp2 < 0 && dp1 > 0)
{
REAL alpha = dp1 / (dp1 - dp2) ;
occludingContours.push_back(alpha * p1 + (1 - alpha) * p2) ;
}
if(dp1 < 0 && dp3 > 0)
{
REAL alpha = -dp1 / (-dp1 + dp3) ;
occludingContours.push_back(alpha * p1 + (1 - alpha) * p3) ;
}
if(dp3 < 0 && dp1 > 0)
{
REAL alpha = dp1 / (dp1 - dp3) ;
occludingContours.push_back(alpha * p1 + (1 - alpha) * p3) ;
}
if(dp2 < 0 && dp3 > 0)
{
REAL alpha = -dp2 / (-dp2 + dp3) ;
occludingContours.push_back(alpha * p2 + (1 - alpha) * p3) ;
}
if(dp3 < 0 && dp2 > 0)
{
REAL alpha = dp2 / (dp2 - dp3) ;
occludingContours.push_back(alpha * p2 + (1 - alpha) * p3) ;
}
}
return occludingContours ;
}
template <typename PFP>
typename PFP::VEC3 faceGradient(
typename PFP::MAP& map,
......@@ -221,7 +84,7 @@ typename PFP::VEC3 faceGradient(
const typename PFP::TVEC3& position,
const typename PFP::TVEC3& face_normal,
const typename PFP::TREAL& kmax,
const typename PFP::TREAL& area)
const typename PFP::TREAL& face_area)
{
typedef typename PFP::REAL REAL ;
typedef typename PFP::VEC3 VEC3 ;
......@@ -241,7 +104,7 @@ typename PFP::VEC3 faceGradient(
REAL k3 = kmax[it] ;
VEC3 n = face_normal[d] ;
REAL a = area[d] ;
REAL a = face_area[d] ;
VEC3 G = k1 * ( ( n ^ ( pos3 - pos2 ) ) / ( 2 * a ) ) +
k2 * ( ( n ^ ( pos1 - pos3 ) ) / ( 2 * a ) ) +
k3 * ( ( n ^ ( pos2 - pos1 ) ) / ( 2 * a ) ) ;
......@@ -250,6 +113,78 @@ typename PFP::VEC3 faceGradient(
return G ;
}
template <typename PFP>
void computeVertexGradient(
typename PFP::MAP& map,
const typename PFP::TVEC3& face_gradient,
const typename PFP::TREAL& face_area,
typename PFP::TVEC3& vertex_gradient,
const FunctorSelect& select,
unsigned int thread)
{
TraversorV<typename PFP::MAP> trav(map, select, thread);
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
vertex_gradient[d] = vertexGradient<PFP>(map, d, face_gradient, face_area) ;
}
template <typename PFP>
typename PFP::VEC3 vertexGradient(
typename PFP::MAP& map,
Dart d,
const typename PFP::TVEC3& face_gradient,
const typename PFP::TREAL& face_area)
{
typename PFP::VEC3 G(0) ;
typename PFP::REAL A(0) ;
Traversor2VF<typename PFP::MAP> t(map, d) ;
for (Dart d = t.begin(); d != t.end(); d = t.next())
{
G += face_area[d] * face_gradient[d] ;
A += face_area[d] ;
}
G /= A ;
G.normalize() ;
return G ;
}
//template <typename PFP>
//typename PFP::REAL extremality(
// typename PFP::MAP& map,
// Dart d,
// const typename PFP::VEC3& K,
// const typename PFP::TVEC3& face_gradient,
// const typename PFP::TREAL& face_area)
//{
// typedef typename PFP::REAL REAL ;
//
// 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 += face_area[d2] ;
// e += face_area[d2] * ( face_gradient[d2] * K ) ;
// }
//
// return (e / a) ;
//}
template <typename PFP>
void computeTriangleType(
typename PFP::MAP& map,
const typename PFP::TVEC3& Kmax,
CellMarker& regularMarker,
const FunctorSelect& select,
unsigned int thread)
{
TraversorF<typename PFP::MAP> trav(map, select, thread);
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
if(isTriangleRegular<PFP>(map, d, Kmax))
regularMarker.mark(d) ;
}
template <typename PFP>
bool mutuallyPositive(typename PFP::VEC3& v1, typename PFP::VEC3& v2, typename PFP::VEC3& v3)
{
......@@ -298,63 +233,44 @@ bool isTriangleRegular(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3
// return true ;
return false ;
}
// if ( isInSameOctant<PFP>(K1, K2) && isInSameOctant<PFP>(K1, K3) )
// {
// //regular triangle
// return true ;
// }
// else
// {
// //singular triangle
// return false ;
// }
template <typename PFP>
void initRidgeSegments(
typename PFP::MAP& map,
AttributeHandler<ridgeSegment>& ridge_segments,
const FunctorSelect& select,
unsigned int thread)
{
TraversorF<typename PFP::MAP> trav(map, select, thread);
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
ridge_segments[d].type = EMPTY ;
}
//template <typename PFP>
//bool isInSameOctant(const typename PFP::VEC3& pos1, const typename PFP::VEC3& pos2)
//{
// return ( ( pos1[0] > 0 && pos1[1] > 0 && pos1[2] > 0 && //one of the eight octant
// ( ( pos2[0] > 0 && pos2[1] > 0 && pos2[2] > 0 ) or //one choice of sign
// ( pos2[0] < 0 && pos2[1] < 0 && pos2[2] < 0 ) ) ) or //the other choice
//
// ( pos1[0] > 0 && pos1[1] > 0 && pos1[2] < 0 &&
// ( ( pos2[0] > 0 && pos2[1] > 0 && pos2[2] < 0 ) or
// ( pos2[0] < 0 && pos2[1] < 0 && pos2[2] > 0 ) ) ) or
//
// ( pos1[0] > 0 && pos1[1] < 0 && pos1[2] > 0 &&
// ( ( pos2[0] > 0 && pos2[1] < 0 && pos2[2] > 0 ) or
// ( pos2[0] < 0 && pos2[1] > 0 && pos2[2] < 0 ) ) ) or
//
// ( pos1[0] > 0 && pos1[1] < 0 && pos1[2] < 0 &&
// ( ( pos2[0] > 0 && pos2[1] < 0 && pos2[2] < 0 ) or
// ( pos2[0] < 0 && pos2[1] > 0 && pos2[2] > 0 ) ) ) or
//
// ( pos1[0] < 0 && pos1[1] > 0 && pos1[2] > 0 &&
// ( ( pos2[0] < 0 && pos2[1] > 0 && pos2[2] > 0 ) or
// ( pos2[0] > 0 && pos2[1] < 0 && pos2[2] < 0 ) ) ) or
//
// ( pos1[0] < 0 && pos1[1] > 0 && pos1[2] < 0 &&
// ( ( pos2[0] < 0 && pos2[1] > 0 && pos2[2] < 0 ) or
// ( pos2[0] > 0 && pos2[1] < 0 && pos2[2] > 0 ) ) ) or
//
// ( pos1[0] < 0 && pos1[1] < 0 && pos1[2] > 0 &&