Skip to content

Commit

Permalink
introduce the splatting taken from the Point set demo
Browse files Browse the repository at this point in the history
  glew.h needs to be included before gl.h, thus the change
  of some include directives

  There is still a lighting/color bug that I need to fix
  • Loading branch information
sloriot committed Jul 16, 2014
1 parent e97efd2 commit 756f502
Show file tree
Hide file tree
Showing 35 changed files with 168 additions and 13 deletions.
1 change: 1 addition & 0 deletions Polyhedron/demo/Polyhedron/CGAL_demo/Scene_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Scene_item;
// OpenGL rendering mode
enum RenderingMode { Points = 0,
PointsPlusNormals,
Splatting,
Wireframe,
Flat,
FlatPlusEdges,
Expand Down
25 changes: 24 additions & 1 deletion Polyhedron/demo/Polyhedron/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ if( POLYHEDRON_QTSCRIPT_DEBUGGER)
endif()
find_package(Qt4)

# Find Glew (optional), for splatting
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/GlSplat/cmake)
find_package(GLEW)

# Find OpenGL
find_package(OpenGL)

Expand All @@ -59,7 +63,12 @@ if(QT4_FOUND)
find_package(QGLViewer )
endif(QT4_FOUND)


if(GLEW_FOUND)
include_directories ( ${GLEW_INCLUDE_DIR} )
add_definitions(-DCGAL_GLEW_ENABLED)
else(GLEW_FOUND)
message(STATUS "NOTICE: GLEW library is not found. Splat rendering will not be available.")
endif(GLEW_FOUND)

# Eigen is required by default
find_package(Eigen3 3.1.0) #(requires 3.1.0 or greater)
Expand Down Expand Up @@ -172,6 +181,13 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
# special
target_link_libraries(scene_polyhedron_transform_item scene_polyhedron_item)

if(GLEW_FOUND)
qt4_add_resources(gl_splat_rc GlSplat/glsplat.qrc)
add_library(gl_splat SHARED
GlSplat/GlSplat.cpp GlSplat/Shader.cpp ${gl_splat_rc})
target_link_libraries(gl_splat ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${GLEW_LIBRARIES})
endif(GLEW_FOUND)

add_item(scene_combinatorial_map_item Scene_combinatorial_map_item.cpp Scene_combinatorial_map_item.moc)
# special
target_link_libraries(scene_combinatorial_map_item scene_polyhedron_item)
Expand Down Expand Up @@ -199,6 +215,9 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
Scene_nef_rendering.cpp)
target_link_libraries(scene_nef_polyhedron_item scene_polyhedron_item)
add_item(scene_points_with_normal_item Scene_points_with_normal_item.cpp Scene_points_with_normal_item.moc)
if(GLEW_FOUND)
target_link_libraries( scene_points_with_normal_item gl_splat ${GLEW_LIBRARIES} )
endif(GLEW_FOUND)

foreach( lib
demo_framework
Expand Down Expand Up @@ -243,6 +262,10 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
target_link_libraries( Polyhedron_3 demo_framework )
target_link_libraries( Polyhedron_3 point_dialog )

if(GLEW_FOUND)
target_link_libraries( Polyhedron_3 gl_splat ${GLEW_LIBRARIES} )
endif(GLEW_FOUND)

# Link with CGAL
target_link_libraries( Polyhedron_3 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} )

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QAction>
#include <QStringList>

#include "opengl_tools.h"
#include "Scene_polyhedron_item.h"
#include "Scene_points_with_normal_item.h"
#include "Scene_polylines_item.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class Q_DECL_EXPORT Scene_c3t3_item : public Scene_item

// Indicate if rendering mode is supported
bool supportsRenderingMode(RenderingMode m) const {
return (m != Gouraud && m!=PointsPlusNormals); // CHECK THIS!
return (m != Gouraud && m!=PointsPlusNormals && m!=Splatting); // CHECK THIS!
}

void draw() const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <QtCore/qglobal.h>
#include "opengl_tools.h"

#include "Messages_interface.h"
#include "Scene_polyhedron_item.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <QtCore/qglobal.h>
#include "opengl_tools.h"

#include "Messages_interface.h"
#include "Scene_polyhedron_item.h"
Expand Down
67 changes: 66 additions & 1 deletion Polyhedron/demo/Polyhedron/Scene.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@

#ifdef CGAL_GLEW_ENABLED
# include "GlSplat/GlSplat.h"
#endif


#include <CGAL/check_gl_error.h>
#include "config.h"
#include "Scene.h"
Expand All @@ -22,6 +28,16 @@ namespace {
}
}

#ifdef CGAL_GLEW_ENABLED
GlSplat::SplatRenderer* Scene::ms_splatting = 0;
int Scene::ms_splattingCounter = 0;
GlSplat::SplatRenderer* Scene::splatting()
{
assert(ms_splatting!=0 && "A Scene object must be created before requesting the splatting object");
return ms_splatting;
}
#endif

Scene::Scene(QObject* parent)
: QAbstractListModel(parent),
selected_item(-1),
Expand All @@ -32,6 +48,11 @@ Scene::Scene(QObject* parent)
double, double, double)),
this, SLOT(setSelectionRay(double, double, double,
double, double, double)));
#ifdef CGAL_GLEW_ENABLED
if(ms_splatting==0)
ms_splatting = new GlSplat::SplatRenderer();
ms_splattingCounter++;
#endif
}

Scene::Item_id
Expand Down Expand Up @@ -140,6 +161,11 @@ Scene::~Scene()
delete item_ptr;
}
m_entries.clear();

#ifdef CGAL_GLEW_ENABLED
if((--ms_splattingCounter)==0)
delete ms_splatting;
#endif
}

Scene_item*
Expand Down Expand Up @@ -183,6 +209,9 @@ Scene::duplicate(Item_id index)

void Scene::initializeGL()
{
#ifdef CGAL_GLEW_ENABLED
ms_splatting->init();
#endif
}

// workaround for Qt-4.2.
Expand Down Expand Up @@ -350,6 +379,37 @@ Scene::draw_aux(bool with_names, Viewer_interface* viewer)
}
}
}

#ifdef CGAL_GLEW_ENABLED
// Splatting
if(ms_splatting->isSupported())
{
ms_splatting->beginVisibilityPass();
for(int index = 0; index < m_entries.size(); ++index)
{
Scene_item& item = *m_entries[index];
if(item.visible() && item.renderingMode() == Splatting)
{
item.draw_splats();
}
}
ms_splatting->beginAttributePass();
for(int index = 0; index < m_entries.size(); ++index)
{
Scene_item& item = *m_entries[index];
if(item.visible() && item.renderingMode() == Splatting)
{
if(index == selected_item)
CGALglcolor(item.color().lighter(120));
else
CGALglcolor(item.color());
item.draw_splats();
}
}
ms_splatting->finalize();
}
#endif

}

// workaround for Qt-4.2 (see above)
Expand Down Expand Up @@ -512,7 +572,12 @@ Scene::setData(const QModelIndex &index,
{
RenderingMode rendering_mode = static_cast<RenderingMode>(value.toInt());
// Find next supported rendering mode
while ( ! item->supportsRenderingMode(rendering_mode) ) {
while ( ! item->supportsRenderingMode(rendering_mode)
#ifdef CGAL_GLEW_ENABLED
|| (rendering_mode==Splatting && !Scene::splatting()->isSupported())
#endif
)
{
rendering_mode = static_cast<RenderingMode>( (rendering_mode+1) % NumberOfRenderingMode );
}
item->setRenderingMode(rendering_mode);
Expand Down
8 changes: 7 additions & 1 deletion Polyhedron/demo/Polyhedron/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

class QEvent;
class QMouseEvent;
namespace GlSplat { class SplatRenderer; }

class Viewer_interface;

Expand Down Expand Up @@ -148,7 +149,12 @@ private slots:
QList<int> selected_items_list;
int item_A;
int item_B;

#ifdef CGAL_GLEW_ENABLED
static GlSplat::SplatRenderer* ms_splatting;
static int ms_splattingCounter;
public:
static GlSplat::SplatRenderer* splatting();
#endif
}; // end class Scene

class SCENE_EXPORT SceneDelegate : public QItemDelegate
Expand Down
2 changes: 1 addition & 1 deletion Polyhedron/demo/Polyhedron/Scene_c2t3_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class SCENE_C2T3_ITEM_EXPORT Scene_c2t3_item : public Scene_item

// Indicate if rendering mode is supported
bool supportsRenderingMode(RenderingMode m) const {
return (m != Gouraud && m!=PointsPlusNormals); // CHECK THIS!
return (m != Gouraud && m!=PointsPlusNormals && m!=Splatting); // CHECK THIS!
}

void draw() const {
Expand Down
2 changes: 1 addition & 1 deletion Polyhedron/demo/Polyhedron/Scene_combinatorial_map_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SCENE_COMBINATORIAL_MAP_ITEM_EXPORT Scene_combinatorial_map_item
QString toolTip() const;

// Indicate if rendering mode is supported
virtual bool supportsRenderingMode(RenderingMode m) const { return (m != Gouraud && m!=PointsPlusNormals); } // CHECK THIS!
virtual bool supportsRenderingMode(RenderingMode m) const { return (m != Gouraud && m!=PointsPlusNormals && m!=Splatting); } // CHECK THIS!
//Event handling
virtual bool keyPressEvent(QKeyEvent*);
// OpenGL drawing in a display list
Expand Down
1 change: 1 addition & 0 deletions Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "opengl_tools.h"
#include "Scene_edit_polyhedron_item.h"
#include <boost/foreach.hpp>
#include <algorithm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Scene_implicit_function_item::supportsRenderingMode(RenderingMode m) const
{
switch ( m )
{
case Splatting:
case Gouraud:
return false;

Expand Down
4 changes: 4 additions & 0 deletions Polyhedron/demo/Polyhedron/Scene_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ QString modeName(RenderingMode mode) {
return QObject::tr("Gouraud");
case PointsPlusNormals:
return QObject::tr("pts+normals");
case Splatting:
return QObject::tr("splats");
default:
Q_ASSERT(false);
return QObject::tr("unknown");
Expand All @@ -50,6 +52,8 @@ const char* slotName(RenderingMode mode) {
return SLOT(setGouraudMode());
case PointsPlusNormals:
return SLOT(setPointsPlusNormalsMode());
case Splatting:
return SLOT(setSplattingMode());
default:
Q_ASSERT(false);
return "";
Expand Down
7 changes: 7 additions & 0 deletions Polyhedron/demo/Polyhedron/Scene_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class SCENE_ITEM_EXPORT Scene_item : public QObject {
// Points OpenGL drawing
virtual void draw_points() const { draw(); }
virtual void draw_points(Viewer_interface*) const { draw_points(); }
// Splats OpenGL drawing
virtual void draw_splats() const {}
virtual void draw_splats(Viewer_interface*) const {draw_splats();}

// Functions for displaying meta-data of the item
virtual QString toolTip() const = 0;
Expand Down Expand Up @@ -122,6 +125,10 @@ public slots:
setRenderingMode(PointsPlusNormals);
}

void setSplattingMode(){
setRenderingMode(Splatting);
}

virtual void itemAboutToBeDestroyed(Scene_item*);

virtual void select(double orig_x,
Expand Down
2 changes: 1 addition & 1 deletion Polyhedron/demo/Polyhedron/Scene_nef_polyhedron_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SCENE_NEF_POLYHEDRON_ITEM_EXPORT Scene_nef_polyhedron_item
QString toolTip() const;

// Indicate if rendering mode is supported
virtual bool supportsRenderingMode(RenderingMode m) const { return m != Gouraud; } // CHECK THIS!
virtual bool supportsRenderingMode(RenderingMode m) const { return m != Gouraud && m!=Splatting; } // CHECK THIS!
// OpenGL drawing in a display list
void direct_draw() const;
// Wireframe OpenGL drawing
Expand Down
21 changes: 20 additions & 1 deletion Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Scene_points_with_normal_item::toolTip() const

bool Scene_points_with_normal_item::supportsRenderingMode(RenderingMode m) const
{
return m==Points || m==PointsPlusNormals;
return m==Points || m==PointsPlusNormals || m==Splatting;
}

// Points OpenGL drawing in a display list
Expand Down Expand Up @@ -202,6 +202,21 @@ void Scene_points_with_normal_item::draw_normals() const
}
}

void Scene_points_with_normal_item::draw_splats() const
{
Q_ASSERT(m_points != NULL);

// Draw splats
bool points_have_normals = (m_points->begin() != m_points->end() &&
m_points->begin()->normal() != CGAL::NULL_VECTOR);
bool points_have_radii = (m_points->begin() != m_points->end() &&
m_points->begin()->radius() != 0);
if(points_have_normals && points_have_radii)
{
m_points->gl_draw_splats();
}
}

// Gets wrapped point set
Point_set* Scene_points_with_normal_item::point_set()
{
Expand Down Expand Up @@ -300,6 +315,10 @@ QMenu* Scene_points_with_normal_item::contextMenu()
void Scene_points_with_normal_item::setRenderingMode(RenderingMode m)
{
Scene_item_with_display_list::setRenderingMode(m);
if (rendering_mode==Splatting && (!m_points->are_radii_uptodate()))
{
computes_local_spacing(6); // default value = small
}
}

#include "Scene_points_with_normal_item.moc"
3 changes: 3 additions & 0 deletions Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class SCENE_POINTS_WITH_NORMAL_ITEM_EXPORT Scene_points_with_normal_item
void draw_normals() const;
virtual void draw_edges() const { draw_normals(); }//to tweak scene

// Splat OpenGL drawing
virtual void draw_splats() const;

// Gets wrapped point set
Point_set* point_set();
const Point_set* point_set() const;
Expand Down
2 changes: 1 addition & 1 deletion Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SCENE_POLYGON_SOUP_ITEM_EXPORT Scene_polygon_soup_item
QString toolTip() const;

// Indicate if rendering mode is supported
virtual bool supportsRenderingMode(RenderingMode m) const { return (m!=Gouraud && m!=PointsPlusNormals); } // CHECK THIS!
virtual bool supportsRenderingMode(RenderingMode m) const { return (m!=Gouraud && m!=PointsPlusNormals && m!=Splatting); } // CHECK THIS!
// OpenGL drawing in a display list
void direct_draw() const;
void draw_points() const;
Expand Down
2 changes: 1 addition & 1 deletion Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SCENE_POLYHEDRON_ITEM_EXPORT Scene_polyhedron_item
QMenu* contextMenu();

// Indicate if rendering mode is supported
virtual bool supportsRenderingMode(RenderingMode m) const { return (m!=PointsPlusNormals); }
virtual bool supportsRenderingMode(RenderingMode m) const { return (m!=PointsPlusNormals && m!=Splatting); }
// Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list
virtual void direct_draw() const;
virtual void direct_draw_edges() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SCENE_POLYHEDRON_ITEM_DECORATOR_EXPORT Scene_polyhedron_item_decorator
// QMenu* contextMenu();

// Indicate if rendering mode is supported
bool supportsRenderingMode(RenderingMode m) const { return (m!=PointsPlusNormals); }
bool supportsRenderingMode(RenderingMode m) const { return (m!=PointsPlusNormals && m!=Splatting); }
// Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list
// dispatch to poly_item direct_draw and direct_draw_edges
void draw() const;
Expand Down
Loading

0 comments on commit 756f502

Please sign in to comment.