From 140a6b408a3ef5fa5ab0d24fe36cb65663ca1de8 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 25 Feb 2015 11:49:59 +0100 Subject: [PATCH] Implementation of draw_points just added the same function as polygon_soup_item and it works perfectly. --- .../demo/Polyhedron/Scene_polyhedron_item.cpp | 16 ++ .../demo/Polyhedron/Scene_polyhedron_item.h | 168 +++++++++--------- 2 files changed, 100 insertions(+), 84 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp index f88acac6821..a8c0ee729b4 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp @@ -852,6 +852,22 @@ void Scene_polyhedron_item::draw_edges(Viewer_interface* viewer) const { } +void +Scene_polyhedron_item::draw_points(Viewer_interface* viewer) const { + + glBindVertexArray(vao); + + // tells the GPU to use the program just created + glUseProgram(rendering_program); + + uniform_attrib(viewer); + + //draw the points + glDrawArrays(GL_POINTS, 0, positions_facets.size()/4); + + // Clean-up + glBindVertexArray(0); +} Polyhedron* Scene_polyhedron_item::polyhedron() { return poly; } diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h index 12d1d2341dd..3ca04971169 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h @@ -17,111 +17,111 @@ class QMenu; // This class represents a polyhedron in the OpenGL scene class SCENE_POLYHEDRON_ITEM_EXPORT Scene_polyhedron_item - : public Scene_item{ - Q_OBJECT + : public Scene_item{ + Q_OBJECT public: - Scene_polyhedron_item(); -// Scene_polyhedron_item(const Scene_polyhedron_item&); - Scene_polyhedron_item(const Polyhedron& p); - Scene_polyhedron_item(Polyhedron* const p); - ~Scene_polyhedron_item(); + Scene_polyhedron_item(); + // Scene_polyhedron_item(const Scene_polyhedron_item&); + Scene_polyhedron_item(const Polyhedron& p); + Scene_polyhedron_item(Polyhedron* const p); + ~Scene_polyhedron_item(); - Scene_polyhedron_item* clone() const; - - // IO - bool load(std::istream& in); - bool save(std::ostream& out) const; + Scene_polyhedron_item* clone() const; - // Function for displaying meta-data of the item - virtual QString toolTip() const; + // IO + bool load(std::istream& in); + bool save(std::ostream& out) const; - // Function to override the context menu - QMenu* contextMenu(); - - // Indicate if rendering mode is supported - virtual bool supportsRenderingMode(RenderingMode m) const { return (m!=PointsPlusNormals && m!=Splatting); } - // Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list - void draw() const {} - virtual void draw(Viewer_interface*) const; - virtual void draw_edges() const {} -virtual void draw_edges(Viewer_interface* viewer) const; + // Function for displaying meta-data of the item + virtual QString toolTip() const; - // Get wrapped polyhedron - Polyhedron* polyhedron(); - const Polyhedron* polyhedron() const; + // Function to override the context menu + QMenu* contextMenu(); + + // Indicate if rendering mode is supported + virtual bool supportsRenderingMode(RenderingMode m) const { return (m!=PointsPlusNormals && m!=Splatting); } + // Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list + void draw() const {} + virtual void draw(Viewer_interface*) const; + virtual void draw_edges() const {} + virtual void draw_edges(Viewer_interface* viewer) const; + void draw_points(Viewer_interface*) const; + // Get wrapped polyhedron + Polyhedron* polyhedron(); + const Polyhedron* polyhedron() const; + + // Get dimensions + bool isFinite() const { return true; } + bool isEmpty() const; + Bbox bbox() const; + std::vector& color_vector() {return colors_;} + void set_color_vector_read_only(bool on_off) {plugin_has_set_color_vector_m=on_off;} - // Get dimensions - bool isFinite() const { return true; } - bool isEmpty() const; - Bbox bbox() const; - std::vector& color_vector() {return colors_;} - void set_color_vector_read_only(bool on_off) {plugin_has_set_color_vector_m=on_off;} - public slots: - virtual void changed(); - virtual void shading_mode_changed(); - virtual void selection_changed(bool); - void show_only_feature_edges(bool); - void enable_facets_picking(bool); - void set_erase_next_picked_facet(bool); + virtual void changed(); + virtual void shading_mode_changed(); + virtual void selection_changed(bool); + void show_only_feature_edges(bool); + void enable_facets_picking(bool); + void set_erase_next_picked_facet(bool); - void select(double orig_x, - double orig_y, - double orig_z, - double dir_x, - double dir_y, - double dir_z); + void select(double orig_x, + double orig_y, + double orig_z, + double dir_x, + double dir_y, + double dir_z); - void update_vertex_indices(); - void update_facet_indices(); - void update_halfedge_indices(); + void update_vertex_indices(); + void update_facet_indices(); + void update_halfedge_indices(); signals: - void selected_vertex(void*); - void selected_facet(void*); - void selected_edge(void*); - void selected_halfedge(void*); - void item_is_about_to_be_changed(); // emitted in changed() + void selected_vertex(void*); + void selected_facet(void*); + void selected_edge(void*); + void selected_halfedge(void*); + void item_is_about_to_be_changed(); // emitted in changed() private: - // Initialization - void init(); - -private: - Polyhedron* poly; + // Initialization + void init(); private: - typedef Scene_item Base; - typedef std::vector Color_vector; + Polyhedron* poly; + +private: + typedef Scene_item Base; + typedef std::vector Color_vector; - Color_vector colors_; + Color_vector colors_; - bool show_only_feature_edges_m; - bool facet_picking_m; - bool erase_next_picked_facet_m; - //the following variable is used to indicate if the color vector must not be automatically updated. - bool plugin_has_set_color_vector_m; + bool show_only_feature_edges_m; + bool facet_picking_m; + bool erase_next_picked_facet_m; + //the following variable is used to indicate if the color vector must not be automatically updated. + bool plugin_has_set_color_vector_m; - std::vector positions_lines; - std::vector positions_facets; - std::vector normals; - std::vector color_lines; - std::vector color_facets; + std::vector positions_lines; + std::vector positions_facets; + std::vector normals; + std::vector color_lines; + std::vector color_facets; - GLuint rendering_program; - GLint location[8]; + GLuint rendering_program; + GLint location[8]; - GLuint vertex_shader; - GLuint fragment_shader; - GLuint program; - GLuint vao; - GLuint buffer[5]; - void initialize_buffers(); - GLuint compile_shaders(void); - void compute_normals_and_vertices(void); - void uniform_attrib(Viewer_interface*) const; - void compute_colors(); + GLuint vertex_shader; + GLuint fragment_shader; + GLuint program; + GLuint vao; + GLuint buffer[5]; + void initialize_buffers(); + GLuint compile_shaders(void); + void compute_normals_and_vertices(void); + void uniform_attrib(Viewer_interface*) const; + void compute_colors(); }; // end class Scene_polyhedron_item