Update viewers.

This commit is contained in:
Guillaume Damiand 2014-12-24 08:19:09 +01:00
parent bdc0dee6ce
commit 34e9139cde
2 changed files with 171 additions and 133 deletions

View File

@ -16,7 +16,8 @@
// $Id$ // $Id$
// //
// Author(s) : Guillaume Damiand <guillaume.damiand@liris.cnrs.fr> // Author(s) : Guillaume Damiand <guillaume.damiand@liris.cnrs.fr>
// // Contributor(s): Adrien Pilleboue
#ifndef CGAL_LCC_3_VIEWER_QT_H #ifndef CGAL_LCC_3_VIEWER_QT_H
#define CGAL_LCC_3_VIEWER_QT_H #define CGAL_LCC_3_VIEWER_QT_H
@ -39,11 +40,11 @@ struct Geom_utils;
template<class LCC> template<class LCC>
struct Geom_utils<LCC,3> struct Geom_utils<LCC,3>
{ {
Local_point get_point(typename LCC::Vertex_attribute_const_handle vh) Local_point get_point(LCC& lcc, typename LCC::Vertex_attribute_const_handle vh)
{ return converter(vh->point()); } { return converter(lcc.point_of_vertex_attribute(vh)); }
Local_point get_point(typename LCC::Dart_const_handle dh) Local_point get_point(LCC& lcc, typename LCC::Dart_const_handle dh)
{ return converter(LCC::point(dh)); } { return converter(lcc.point(dh)); }
Local_vector get_facet_normal(LCC& lcc, typename LCC::Dart_const_handle dh) Local_vector get_facet_normal(LCC& lcc, typename LCC::Dart_const_handle dh)
{ {
@ -65,14 +66,15 @@ protected:
template<class LCC> template<class LCC>
struct Geom_utils<LCC,2> struct Geom_utils<LCC,2>
{ {
Local_point get_point(typename LCC::Vertex_attribute_const_handle vh) Local_point get_point(LCC& lcc, typename LCC::Vertex_attribute_const_handle vh)
{ {
Local_point p(converter(vh->point().x()),0,converter(vh->point().y())); Local_point p(converter(lcc.point_of_vertex_attribute(vh).x()),0,
converter(lcc.point_of_vertex_attribute(vh).y()));
return p; return p;
} }
Local_point get_point(typename LCC::Dart_const_handle dh) Local_point get_point(LCC& lcc, typename LCC::Dart_const_handle dh)
{ return get_point(LCC::vertex_attribute(dh)); } { return get_point(lcc, lcc.vertex_attribute(dh)); }
Local_vector get_facet_normal(LCC&, typename LCC::Dart_const_handle) Local_vector get_facet_normal(LCC&, typename LCC::Dart_const_handle)
{ {
@ -99,10 +101,10 @@ CGAL::Bbox_3 bbox(LCC& lcc)
it=lcc.vertex_attributes().begin(), itend=lcc.vertex_attributes().end(); it=lcc.vertex_attributes().begin(), itend=lcc.vertex_attributes().end();
if ( it!=itend ) if ( it!=itend )
{ {
bb = geomutils.get_point(it).bbox(); bb = geomutils.get_point(lcc, it).bbox();
for( ++it; it!=itend; ++it) for( ++it; it!=itend; ++it)
{ {
bb = bb + geomutils.get_point(it).bbox(); bb = bb + geomutils.get_point(lcc, it).bbox();
} }
} }
@ -114,128 +116,154 @@ class SimpleLCCViewerQt : public QGLViewer
{ {
typedef typename LCC::Dart_handle Dart_handle; typedef typename LCC::Dart_handle Dart_handle;
public: public:
// Constructor/Destructor // Constructor/Destructor
SimpleLCCViewerQt(LCC& alcc) : QGLViewer(), lcc(alcc), SimpleLCCViewerQt(LCC& alcc) :
wireframe(false), flatShading(true), lcc(alcc),
edges(true), vertices(true) wireframe(false),
flatShading(true),
edges(true),
vertices(true),
m_displayListCreated(false)
{ {
setWindowTitle("3D lcc viewer"); setWindowTitle("3D lcc viewer");
resize(500, 450); resize(500, 450);
QGLFormat newFormat = this->format();
newFormat.setSampleBuffers(true);
newFormat.setSamples(16);
this->setFormat(newFormat);
} }
protected : protected :
// Draw the facet given by ADart void drawAllFaces(bool flat)
void drawFacet(Dart_handle ADart, int AMark)
{ {
for(typename LCC::template One_dart_per_cell_range<2>::iterator
dartIter=lcc.template one_dart_per_cell<2>().begin();
dartIter.cont(); ++dartIter)
{
Dart_handle& dart = dartIter;
::glBegin(GL_POLYGON); ::glBegin(GL_POLYGON);
::glColor3f(.7,.7,.7); ::glColor3f(1.0f, .7f, .7f);
// If Flat shading: 1 normal per polygon if(flat)
if (flatShading)
{ {
Local_vector n = geomutils.get_facet_normal(lcc,ADart); Local_vector normal = geomutils.get_facet_normal(lcc,dart);
::glNormal3d(n.x(),n.y(),n.z()); ::glNormal3d(normal.x(), normal.y(), normal.z());
} }
for (typename LCC::template Dart_of_orbit_range<1>::const_iterator for (typename LCC::template Dart_of_orbit_range<1>::const_iterator
it=lcc.template darts_of_orbit<1>(ADart).begin(); orbitIter = lcc.template darts_of_orbit<1>(dart).begin();
it.cont(); ++it) orbitIter.cont(); ++orbitIter)
{
if(!flat)
{ {
// If Gouraud shading: 1 normal per vertex // If Gouraud shading: 1 normal per vertex
if (!flatShading) Local_vector n = geomutils.get_vertex_normal(lcc,orbitIter);
{
Local_vector n = geomutils.get_vertex_normal(lcc,it);
::glNormal3d(n.x(),n.y(),n.z()); ::glNormal3d(n.x(),n.y(),n.z());
} }
Local_point p = geomutils.get_point(it); Local_point p = geomutils.get_point(lcc, orbitIter);
::glVertex3d(p.x(),p.y(),p.z()); ::glVertex3d(p.x(),p.y(),p.z());
lcc.mark(it, AMark);
if ( lcc.dimension>=3 && !it->is_free(3) ) lcc.mark(it->beta(3), AMark);
} }
// close the polygon
if (!flatShading)
{
Local_vector n = geomutils.get_vertex_normal(lcc,ADart);
::glNormal3d(n.x(),n.y(),n.z());
}
Local_point p = geomutils.get_point(ADart);
::glVertex3d(p.x(),p.y(),p.z());
::glEnd(); ::glEnd();
} }
}
/// Draw all the edge of the facet given by ADart void drawAllEdges()
void drawEdges(Dart_handle ADart)
{ {
glDepthRange (0.0, 0.9); // ::glDepthRange(0.0, 1.0-0.005);
glBegin(GL_LINES); ::glBegin(GL_LINES);
::glColor3f(.2,.2,.6); ::glColor3f(0.0f, 0.0f, 0.0f);
for (typename LCC::template Dart_of_orbit_range<1>::iterator
it=lcc.template darts_of_orbit<1>(ADart).begin(); for(typename LCC::template One_dart_per_cell_range<1>::iterator
it.cont(); ++it) dartIter=lcc.template one_dart_per_cell<1>().begin();
dartIter.cont(); ++dartIter)
{ {
Local_point p = geomutils.get_point(it); Dart_handle& dart = dartIter;
Dart_handle d2 = it->other_extremity();
Local_point p = geomutils.get_point(lcc, dartIter);
Dart_handle d2 = lcc.other_extremity(dartIter);
if ( d2!=NULL ) if ( d2!=NULL )
{ {
Local_point p2 = geomutils.get_point(d2); Local_point p2 = geomutils.get_point(lcc, d2);
glVertex3f( p.x(),p.y(),p.z()); glVertex3f( p.x(),p.y(),p.z());
glVertex3f( p2.x(),p2.y(),p2.z()); glVertex3f( p2.x(),p2.y(),p2.z());
} }
} }
glEnd();
glDepthRange (0.1, 1.0); ::glEnd();
// ::glDepthRange(0.005, 1.0);
}
void drawAllVertices()
{
// ::glDepthRange(0.0, 1.0-0.005);
::glPointSize(7.0);
::glBegin(GL_POINTS);
::glColor3f(0.2f, 0.2f, 0.7f);
for (typename LCC::Vertex_attribute_const_range::iterator
v=lcc.vertex_attributes().begin(),
vend=lcc.vertex_attributes().end();
v!=vend; ++v)
{
Local_point p = geomutils.get_point(lcc, v);
glVertex3f(p.x(), p.y(), p.z());
}
::glEnd();
// ::glDepthRange(0.005, 1.0);
}
void initDraw()
{
//Compile drawFacet
std::cout << "Compile Display List : Faces" << std::endl;
m_dlFaces = ::glGenLists(1);
::glNewList(m_dlFaces, GL_COMPILE);
drawAllFaces(false);
::glEndList();
//Compile drawFacet with flat shading
std::cout << "Compile Display List : Faces (flat shading)" << std::endl;
m_dlFacesFlat = ::glGenLists(1);
::glNewList(m_dlFacesFlat, GL_COMPILE);
drawAllFaces(true);
::glEndList();
//Compile drawEdge
std::cout << "Compile Display List : Edges" << std::endl;
m_dlEdges = ::glGenLists(1);
::glNewList(m_dlEdges, GL_COMPILE);
drawAllEdges();
::glEndList();
//Compile drawvertices
std::cout << "Compile Display List : Vertices" << std::endl;
m_dlVertices = ::glGenLists(1);
::glNewList(m_dlVertices, GL_COMPILE);
drawAllVertices();
::glEndList();
m_displayListCreated = true;
} }
virtual void draw() virtual void draw()
{ {
int facettreated = lcc.get_new_mark(); if(!m_displayListCreated) initDraw();
int vertextreated = -1;
if ( vertices) vertextreated=lcc.get_new_mark(); if ( !wireframe )
for(typename LCC::Dart_range::iterator it=lcc.darts().begin(),
itend=lcc.darts().end(); it!=itend; ++it)
{ {
if ( !lcc.is_marked(it,facettreated) ) if(flatShading) ::glCallList(m_dlFacesFlat);
{ else ::glCallList(m_dlFaces);
drawFacet(it,facettreated);
if ( edges) drawEdges(it);
} }
if (vertices) if(edges) ::glCallList(m_dlEdges);
{
if ( !lcc.is_marked(it, vertextreated) )
{
Local_point p = geomutils.get_point(it);
glDepthRange (0.0, 0.9); if(vertices) ::glCallList(m_dlVertices);
glBegin(GL_POINTS);
::glColor3f(.6,.2,.8);
glVertex3f(p.x(),p.y(),p.z());
glEnd();
glDepthRange (0.1, 1.0);
CGAL::mark_cell<LCC, 0>(lcc, it, vertextreated);
}
}
}
CGAL_assertion(lcc.is_whole_map_marked(facettreated));
if ( vertices)
{
CGAL_assertion(lcc.is_whole_map_marked(vertextreated));
lcc.free_mark(vertextreated);
}
lcc.free_mark(facettreated);
} }
virtual void init() virtual void init()
@ -265,6 +293,7 @@ protected :
::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
// ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); // ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
// ::glDepthRange(0.005, 1.0);
if (flatShading) if (flatShading)
{ {
::glShadeModel(GL_FLAT); ::glShadeModel(GL_FLAT);
@ -293,6 +322,7 @@ protected :
bb.zmax())); bb.zmax()));
this->showEntireScene(); this->showEntireScene();
initDraw();
} }
void keyPressEvent(QKeyEvent *e) void keyPressEvent(QKeyEvent *e)
@ -389,6 +419,12 @@ private:
bool edges; bool edges;
bool vertices; bool vertices;
Geom_utils<LCC> geomutils; Geom_utils<LCC> geomutils;
GLuint m_dlFaces;
GLuint m_dlFacesFlat;
GLuint m_dlEdges;
GLuint m_dlVertices;
bool m_displayListCreated;
}; };
template<class LCC> template<class LCC>

View File

@ -48,11 +48,11 @@ struct Geom_utils;
template<class LCC> template<class LCC>
struct Geom_utils<LCC,3> struct Geom_utils<LCC,3>
{ {
Local_point get_point(typename LCC::Vertex_attribute_const_handle vh) Local_point get_point(LCC& lcc, typename LCC::Vertex_attribute_const_handle vh)
{ return converter(vh->point()); } { return converter(lcc.point_of_vertex_attribute(vh)); }
Local_point get_point(typename LCC::Dart_const_handle dh) Local_point get_point(LCC& lcc, typename LCC::Dart_const_handle dh)
{ return converter(LCC::point(dh)); } { return converter(lcc.point(dh)); }
Local_vector get_facet_normal(LCC& lcc, typename LCC::Dart_const_handle dh) Local_vector get_facet_normal(LCC& lcc, typename LCC::Dart_const_handle dh)
{ {
@ -74,14 +74,15 @@ protected:
template<class LCC> template<class LCC>
struct Geom_utils<LCC,2> struct Geom_utils<LCC,2>
{ {
Local_point get_point(typename LCC::Vertex_attribute_const_handle vh) Local_point get_point(LCC& lcc, typename LCC::Vertex_attribute_const_handle vh)
{ {
Local_point p(converter(vh->point().x()),0,converter(vh->point().y())); Local_point p(converter(lcc.point_of_vertex_attribute(vh).x()),0,
converter(lcc.point_of_vertex_attribute(vh).y()));
return p; return p;
} }
Local_point get_point(typename LCC::Dart_const_handle dh) Local_point get_point(LCC& lcc, typename LCC::Dart_const_handle dh)
{ return get_point(LCC::vertex_attribute(dh)); } { return get_point(lcc, lcc.vertex_attribute(dh)); }
Local_vector get_facet_normal(LCC&, typename LCC::Dart_const_handle) Local_vector get_facet_normal(LCC&, typename LCC::Dart_const_handle)
{ {
@ -171,7 +172,8 @@ public:
{ {
++nb; ++nb;
lcc.mark(it2, facettreated); lcc.mark(it2, facettreated);
if ( lcc.dimension>=3 && !it2->is_free(3) ) lcc.mark(it2->beta(3), facettreated); if ( lcc.dimension>=3 && !lcc.is_free(it2, 3) )
lcc.mark(lcc.beta(it2, 3), facettreated);
} }
polygons->InsertNextCell(nb); polygons->InsertNextCell(nb);
@ -179,7 +181,7 @@ public:
it2=lcc.template darts_of_orbit<1>(it).begin(); it2=lcc.template darts_of_orbit<1>(it).begin();
it2.cont(); ++it2) it2.cont(); ++it2)
{ {
Local_point p = geomutils.get_point(it2); Local_point p = geomutils.get_point(lcc, it2);
vtkIdType id=points->InsertNextPoint(p.x(),p.y(),p.z()); vtkIdType id=points->InsertNextPoint(p.x(),p.y(),p.z());
++nbpoints; ++nbpoints;