diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index ece211e9e31..f5edd194a9c 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -311,27 +311,28 @@ Scene::keyPressEvent(QKeyEvent* e){ return res; } -void -Scene::draw() -{ - draw_aux(false, 0); -} void Scene::draw(CGAL::Three::Viewer_interface* viewer) { draw_aux(false, viewer); } void -Scene::drawWithNames() -{ - draw_aux(true, 0); -} -void Scene::drawWithNames(CGAL::Three::Viewer_interface* viewer) { draw_aux(true, viewer); } +bool item_should_be_skipped_in_draw(Scene_item* item) { + if(!item->visible()) return true; + if(item->has_group == 0) return false; + Scene_group_item* group = item->parentGroup(); + while(group != 0) { + if(!group->visible()) return false; + group = group->parentGroup(); + } + return true; +} + void Scene::draw_aux(bool with_names, CGAL::Three::Viewer_interface* viewer) { @@ -342,10 +343,12 @@ Scene::draw_aux(bool with_names, CGAL::Three::Viewer_interface* viewer) // Flat/Gouraud OpenGL drawing for(int index = 0; index < m_entries.size(); ++index) { + CGAL::Three::Scene_item& item = *m_entries[index]; if(with_names) { viewer->glPushName(index); + } else { + if(item_should_be_skipped_in_draw(&item)) continue; } - CGAL::Three::Scene_item& item = *m_entries[index]; if(item.visible()) { if(item.renderingMode() == Flat || item.renderingMode() == FlatPlusEdges || item.renderingMode() == Gouraud) @@ -378,14 +381,17 @@ Scene::draw_aux(bool with_names, CGAL::Three::Viewer_interface* viewer) viewer->glPopName(); } } -glDepthFunc(GL_LEQUAL); + glDepthFunc(GL_LEQUAL); // Wireframe OpenGL drawing for(int index = 0; index < m_entries.size(); ++index) { + CGAL::Three::Scene_item& item = *m_entries[index]; if(with_names) { viewer->glPushName(index); } - CGAL::Three::Scene_item& item = *m_entries[index]; + else { + if(item_should_be_skipped_in_draw(&item)) continue; + } if(item.visible()) { if(item.renderingMode() == FlatPlusEdges || item.renderingMode() == Wireframe) @@ -442,10 +448,12 @@ glDepthFunc(GL_LEQUAL); // Points OpenGL drawing for(int index = 0; index < m_entries.size(); ++index) { + CGAL::Three::Scene_item& item = *m_entries[index]; if(with_names) { viewer->glPushName(index); + } else { + if(item_should_be_skipped_in_draw(&item)) continue; } - CGAL::Three::Scene_item& item = *m_entries[index]; if(item.visible()) { if(item.renderingMode() == Points || item.renderingMode() == PointsPlusNormals) @@ -474,6 +482,7 @@ glDepthFunc(GL_LEQUAL); for(int index = 0; index < m_entries.size(); ++index) { CGAL::Three::Scene_item& item = *m_entries[index]; + if(item_should_be_skipped_in_draw(&item)) continue; if(item.visible() && item.renderingMode() == Splatting) { @@ -486,9 +495,11 @@ glDepthFunc(GL_LEQUAL); } } - ms_splatting->beginAttributePass(); - for(int index = 0; index < m_entries.size(); ++index) - { CGAL::Three::Scene_item& item = *m_entries[index]; + ms_splatting->beginAttributePass(); + for(int index = 0; index < m_entries.size(); ++index) + { + CGAL::Three::Scene_item& item = *m_entries[index]; + if(item_should_be_skipped_in_draw(&item)) continue; if(item.visible() && item.renderingMode() == Splatting) { viewer->glColor4d(item.color().redF(), item.color().greenF(), item.color().blueF(), item.color().alphaF()); @@ -1077,7 +1088,7 @@ void Scene::changeGroup(Scene_item *item, CGAL::Three::Scene_group_item *target_ } //add the item to the target group target_group->addChild(item); - item->has_group = target_group->has_group +1; + item->moveToGroup(target_group); } float Scene::get_bbox_length() const diff --git a/Polyhedron/demo/Polyhedron/Scene.h b/Polyhedron/demo/Polyhedron/Scene.h index 7e938d163fb..9e747154651 100644 --- a/Polyhedron/demo/Polyhedron/Scene.h +++ b/Polyhedron/demo/Polyhedron/Scene.h @@ -110,10 +110,6 @@ public: * of OpenGL code that needs a context. */ void initializeGL(); - /*! Is called by Viewer::draw(). Is deprecated and does nothing.*/ - void draw(); - /*! Is deprecated and does nothing.*/ - void drawWithNames(); /*! Is called by Viewer::draw(Viewer_interface*). Calls draw_aux(false, viewer). * @see draw_aux(bool with_names, Viewer_interface).*/ void draw(CGAL::Three::Viewer_interface*); diff --git a/Polyhedron/demo/Polyhedron/Scene_group_item.cpp b/Polyhedron/demo/Polyhedron/Scene_group_item.cpp index 86d2b2269e5..56a597e29ac 100644 --- a/Polyhedron/demo/Polyhedron/Scene_group_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_group_item.cpp @@ -1,5 +1,5 @@ - #include +#include #include using namespace CGAL::Three; @@ -114,3 +114,55 @@ void Scene_group_item::moveUp(int i) { children.move(i, i-1); } + +void Scene_group_item::draw(CGAL::Three::Viewer_interface* viewer) const { + if(viewer->inDrawWithNames()) return; + Q_FOREACH(Scene_item* child, children) { + if(!child->visible()) continue; + switch(child->renderingMode()) { + case Flat: + case FlatPlusEdges: + case Gouraud: + child->draw(viewer); break; + default: break; + } + } +} + +void Scene_group_item::draw_edges(CGAL::Three::Viewer_interface* viewer) const +{ + if(viewer->inDrawWithNames()) return; + Q_FOREACH(Scene_item* child, children) { + if(!child->visible()) continue; + switch(child->renderingMode()) { + case FlatPlusEdges: + case Wireframe: + case PointsPlusNormals: + child->draw_edges(viewer); break; + default: break; + } + } +} + +void Scene_group_item::draw_points(CGAL::Three::Viewer_interface* viewer) const +{ + if(viewer->inDrawWithNames()) return; + Q_FOREACH(Scene_item* child, children) { + if(!child->visible()) continue; + switch(child->renderingMode()) { + case Points: + case PointsPlusNormals: + child->draw_points(viewer); break; + default: break; + } + } +} + +void Scene_group_item::draw_splats(CGAL::Three::Viewer_interface* viewer) const +{ + if(viewer->inDrawWithNames()) return; + Q_FOREACH(Scene_item* child, children) { + if(child->visible() && child->renderingMode() == Splatting) + child->draw_splats(viewer); + } +} diff --git a/Polyhedron/demo/Polyhedron/Scene_item.cpp b/Polyhedron/demo/Polyhedron/Scene_item.cpp index c4ba9a84db7..ee89e41f305 100644 --- a/Polyhedron/demo/Polyhedron/Scene_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_item.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -6,6 +7,37 @@ #include const QColor CGAL::Three::Scene_item::defaultColor = QColor(100, 100, 255); +CGAL::Three::Scene_item::Scene_item(int buffers_size, int vaos_size) + : name_("unamed"), + color_(defaultColor), + visible_(true), + are_buffers_filled(false), + rendering_mode(FlatPlusEdges), + defaultContextMenu(0), + buffersSize(buffers_size), + vaosSize(vaos_size), + vaos(vaos_size) +{ + is_bbox_computed = false; + is_monochrome = true; + for(int i=0; icreate(); + } + + buffers.reserve(buffersSize); + for(int i=0; ihas_group + 1; + else + has_group = 0; +} + void CGAL::Three::Scene_item::invalidateOpenGLBuffers() {} void CGAL::Three::Scene_item::selection_changed(bool) {} diff --git a/Polyhedron/demo/Polyhedron/Viewer.cpp b/Polyhedron/demo/Polyhedron/Viewer.cpp index 48f80eea8b0..9b50f0e33ba 100644 --- a/Polyhedron/demo/Polyhedron/Viewer.cpp +++ b/Polyhedron/demo/Polyhedron/Viewer.cpp @@ -16,6 +16,7 @@ public: bool twosides; bool macro_mode; bool inFastDrawing; + bool inDrawWithNames; void draw_aux(bool with_names, Viewer*); @@ -31,6 +32,7 @@ Viewer::Viewer(QWidget* parent, bool antialiasing) d->twosides = false; d->macro_mode = false; d->inFastDrawing = true; + d->inDrawWithNames = false; d->shader_programs.resize(NB_OF_PROGRAMS); setShortcut(EXIT_VIEWER, 0); setShortcut(DRAW_AXIS, 0); @@ -321,6 +323,7 @@ void Viewer_impl::draw_aux(bool with_names, Viewer* viewer) viewer->glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); viewer->glBlendFunc(GL_ONE, GL_ZERO); } + inDrawWithNames = with_names; if(with_names) scene->drawWithNames(viewer); else @@ -329,6 +332,10 @@ void Viewer_impl::draw_aux(bool with_names, Viewer* viewer) viewer->glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); } +bool Viewer::inDrawWithNames() const { + return d->inDrawWithNames; +} + void Viewer::drawWithNames() { QGLViewer::draw(); diff --git a/Polyhedron/demo/Polyhedron/Viewer.h b/Polyhedron/demo/Polyhedron/Viewer.h index 3435ebe047d..2f81d77dab6 100644 --- a/Polyhedron/demo/Polyhedron/Viewer.h +++ b/Polyhedron/demo/Polyhedron/Viewer.h @@ -59,6 +59,8 @@ public: bool antiAliasing() const; //! @returns the fastDrawing state. bool inFastDrawing() const; + //! Implementation of `Viewer_interface::inDrawWithNames()` + bool inDrawWithNames() const; //! Implementation of `Viewer_interface::attrib_buffers()` void attrib_buffers(int program_name) const; //! Implementation of `Viewer_interface::getShaderProgram()` diff --git a/Three/include/CGAL/Three/Scene_draw_interface.h b/Three/include/CGAL/Three/Scene_draw_interface.h index c9fa3f0844b..cbc562a8c30 100644 --- a/Three/include/CGAL/Three/Scene_draw_interface.h +++ b/Three/include/CGAL/Three/Scene_draw_interface.h @@ -33,10 +33,8 @@ class Scene_draw_interface { public: virtual ~Scene_draw_interface(){} virtual void initializeGL() = 0; - virtual void draw() = 0; - virtual void draw(CGAL::Three::Viewer_interface*) { draw(); }; - virtual void drawWithNames() = 0; - virtual void drawWithNames(CGAL::Three::Viewer_interface*) { drawWithNames(); } + virtual void draw(CGAL::Three::Viewer_interface*) = 0; + virtual void drawWithNames(CGAL::Three::Viewer_interface*) = 0; virtual bool keyPressEvent(QKeyEvent* e) = 0; virtual float get_bbox_length() const = 0; }; diff --git a/Three/include/CGAL/Three/Scene_group_item.h b/Three/include/CGAL/Three/Scene_group_item.h index bc4db1cc511..4d0a8c0e776 100644 --- a/Three/include/CGAL/Three/Scene_group_item.h +++ b/Three/include/CGAL/Three/Scene_group_item.h @@ -62,6 +62,15 @@ public : bool supportsRenderingMode(RenderingMode m) const; //!Prints the number of children. QString toolTip() const; + + /// Draw functions + ///@{ + virtual void draw(CGAL::Three::Viewer_interface*) const; + virtual void draw_edges(CGAL::Three::Viewer_interface*) const; + virtual void draw_points(CGAL::Three::Viewer_interface*) const; + virtual void draw_splats(CGAL::Three::Viewer_interface*) const; + ///@} + //!Adds a Scene_item* to the list of children. //!@see getChildren. @see removeChild. void addChild(Scene_item* new_item); diff --git a/Three/include/CGAL/Three/Scene_item.h b/Three/include/CGAL/Three/Scene_item.h index 37eafaae201..24a8349ae6b 100644 --- a/Three/include/CGAL/Three/Scene_item.h +++ b/Three/include/CGAL/Three/Scene_item.h @@ -43,6 +43,7 @@ class QKeyEvent; namespace CGAL { namespace Three { +class Scene_group_item; class Viewer_interface; //! This class represents an object in the OpenGL scene class SCENE_ITEM_EXPORT Scene_item : public QObject { @@ -78,72 +79,12 @@ public: //! The default color of a scene_item. static const QColor defaultColor; // defined in Scene_item.cpp - //!The default Constructor. - /*! - * Initializes the number of VBOs to 20 and VAOs to 10 and creates them. - */ - Scene_item() - : name_("unamed"), - color_(defaultColor), - visible_(true), - are_buffers_filled(false), - rendering_mode(FlatPlusEdges), - defaultContextMenu(0), - buffersSize(20), - vaosSize(10), - vaos(10) - { - is_bbox_computed = false; - is_monochrome = true; - for(int i=0; icreate(); - } - - buffers.reserve(buffersSize); - for(int i=0; icreate(); - } + Scene_item(int buffers_size = 20, int vaos_size = 10); - buffers.reserve(buffersSize); - for(int i=0; i