mirror of https://github.com/CGAL/cgal
Update of polyline_item.
Polylines now use shaders, and spheres are made without gluSphere. The displayList has been replaced bay an Instanced drawing of the shperes with the function DrawArraysInstanced.
This commit is contained in:
parent
3a945c9e00
commit
4a48cfb524
|
|
@ -889,3 +889,4 @@ Scene_polygon_soup_item::new_triangle(const std::size_t i,
|
|||
// Local Variables:
|
||||
// c-basic-offset: 4
|
||||
// End:
|
||||
|
||||
|
|
|
|||
|
|
@ -780,13 +780,7 @@ Scene_polyhedron_item::compute_normals_and_vertices(void)
|
|||
positions_lines.push_back(b.z());
|
||||
positions_lines.push_back(1.0);
|
||||
|
||||
/* color_lines.push_back(1.0);
|
||||
color_lines.push_back(0.0);
|
||||
color_lines.push_back(0.0);
|
||||
|
||||
color_lines.push_back(1.0);
|
||||
color_lines.push_back(0.0);
|
||||
color_lines.push_back(0.0);*/
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1124,7 +1118,7 @@ void Scene_polyhedron_item::draw(Viewer_interface* viewer) const {
|
|||
glBindVertexArray(vao[0]);
|
||||
|
||||
// tells the GPU to use the program just created
|
||||
// glUseProgram(rendering_program_facets);
|
||||
glUseProgram(rendering_program_facets);
|
||||
uniform_attrib(viewer,0);
|
||||
//draw the polygons
|
||||
// the third argument is the number of vec4 that will be entered
|
||||
|
|
@ -1162,7 +1156,7 @@ Scene_polyhedron_item::draw_points(Viewer_interface* viewer) const {
|
|||
uniform_attrib(viewer,1);
|
||||
|
||||
//draw the points
|
||||
glDrawArrays(GL_POINTS, 0, positions_facets.size());
|
||||
glDrawArrays(GL_POINTS, 0, positions_facets.size()/4);
|
||||
|
||||
// Clean-up
|
||||
glBindVertexArray(0);
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ private:
|
|||
GLint location[9];
|
||||
|
||||
GLuint vao[1];
|
||||
GLuint buffer[6];
|
||||
GLuint buffer[5];
|
||||
void initialize_buffers();
|
||||
void compile_shaders(void);
|
||||
void compute_normals_and_vertices(void);
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef SCENE_POLYLINES_ITEM_H
|
||||
#define SCENE_POLYLINES_ITEM_H
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include "Scene_polylines_item_config.h"
|
||||
|
||||
#include "Viewer_interface.h"
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include "Scene_item.h"
|
||||
|
||||
|
|
@ -16,77 +16,107 @@ class Scene_polylines_item_private;
|
|||
|
||||
class SCENE_POLYLINES_ITEM_EXPORT Scene_polylines_item : public Scene_item
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
||||
typedef K::Point_3 Point_3;
|
||||
typedef std::vector<Point_3> Polyline;
|
||||
typedef std::list<Polyline> Polylines_container;
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
||||
typedef K::Point_3 Point_3;
|
||||
typedef std::vector<Point_3> Polyline;
|
||||
typedef std::list<Polyline> Polylines_container;
|
||||
|
||||
typedef K::Iso_cuboid_3 Iso_cuboid_3;
|
||||
typedef K::Iso_cuboid_3 Iso_cuboid_3;
|
||||
|
||||
Scene_polylines_item();
|
||||
virtual ~Scene_polylines_item();
|
||||
Scene_polylines_item();
|
||||
virtual ~Scene_polylines_item();
|
||||
|
||||
bool isFinite() const { return true; }
|
||||
bool isEmpty() const;
|
||||
Bbox bbox() const;
|
||||
bool isFinite() const { return true; }
|
||||
bool isEmpty() const;
|
||||
Bbox bbox() const;
|
||||
|
||||
Scene_polylines_item* clone() const;
|
||||
Scene_polylines_item* clone() const;
|
||||
|
||||
QString toolTip() const;
|
||||
QString toolTip() const;
|
||||
|
||||
// Indicate if rendering mode is supported
|
||||
bool supportsRenderingMode(RenderingMode m) const;
|
||||
// Indicate if rendering mode is supported
|
||||
bool supportsRenderingMode(RenderingMode m) const;
|
||||
|
||||
QMenu* contextMenu();
|
||||
|
||||
// Flat/Gouraud OpenGL drawing
|
||||
void draw() const;
|
||||
QMenu* contextMenu();
|
||||
|
||||
// Wireframe OpenGL drawing
|
||||
void draw_edges() const;
|
||||
// Flat/Gouraud OpenGL drawing
|
||||
void draw() const {}
|
||||
void draw(Viewer_interface*) const;
|
||||
|
||||
void draw_points() const;
|
||||
|
||||
void smooth(std::vector<Point_3>& polyline){
|
||||
bool is_closed = polyline.front()==polyline.back();
|
||||
typedef K::Vector_3 Vector_3;
|
||||
|
||||
std::size_t start = is_closed ? 0:1;
|
||||
std::size_t end = polyline.size()-1;
|
||||
|
||||
Vector_3 prev = (is_closed ? polyline[end-1] : polyline[0]) - CGAL::ORIGIN;
|
||||
|
||||
for (std::size_t i=start; i!=end; ++i)
|
||||
{
|
||||
Vector_3 curr = polyline[i] - CGAL::ORIGIN;
|
||||
Vector_3 next = polyline[i+1] - CGAL::ORIGIN;
|
||||
|
||||
polyline[i] = CGAL::ORIGIN+(prev+2*curr+next)/4;
|
||||
prev=curr;
|
||||
// Wireframe OpenGL drawing
|
||||
void draw_edges() const{}
|
||||
void draw_edges(Viewer_interface*) const;
|
||||
|
||||
void draw_points() const{}
|
||||
void draw_points(Viewer_interface*) const;
|
||||
|
||||
|
||||
void smooth(std::vector<Point_3>& polyline){
|
||||
bool is_closed = polyline.front()==polyline.back();
|
||||
typedef K::Vector_3 Vector_3;
|
||||
|
||||
std::size_t start = is_closed ? 0:1;
|
||||
std::size_t end = polyline.size()-1;
|
||||
|
||||
Vector_3 prev = (is_closed ? polyline[end-1] : polyline[0]) - CGAL::ORIGIN;
|
||||
|
||||
for (std::size_t i=start; i!=end; ++i)
|
||||
{
|
||||
Vector_3 curr = polyline[i] - CGAL::ORIGIN;
|
||||
Vector_3 next = polyline[i+1] - CGAL::ORIGIN;
|
||||
|
||||
polyline[i] = CGAL::ORIGIN+(prev+2*curr+next)/4;
|
||||
prev=curr;
|
||||
}
|
||||
|
||||
if (is_closed) polyline[end]=polyline[0];
|
||||
}
|
||||
|
||||
if (is_closed) polyline[end]=polyline[0];
|
||||
}
|
||||
|
||||
|
||||
public slots:
|
||||
void change_corner_radii(double);
|
||||
void change_corner_radii();
|
||||
void split_at_sharp_angles();
|
||||
virtual void changed();
|
||||
void change_corner_radii(double);
|
||||
void change_corner_radii();
|
||||
void split_at_sharp_angles();
|
||||
|
||||
void merge(Scene_polylines_item*);
|
||||
void merge(Scene_polylines_item*);
|
||||
|
||||
void smooth(){
|
||||
for (Polylines_container::iterator pit=polylines.begin(),pit_end=polylines.end();pit!=pit_end;++pit)
|
||||
smooth(*pit);
|
||||
emit itemChanged();
|
||||
}
|
||||
void smooth(){
|
||||
for (Polylines_container::iterator pit=polylines.begin(),pit_end=polylines.end();pit!=pit_end;++pit)
|
||||
smooth(*pit);
|
||||
emit itemChanged();
|
||||
}
|
||||
public:
|
||||
Polylines_container polylines;
|
||||
Polylines_container polylines;
|
||||
|
||||
// http://en.wikipedia.org/wiki/D-pointer
|
||||
Scene_polylines_item_private* d;
|
||||
private:
|
||||
std::vector<float> positions_lines;
|
||||
std::vector<float> positions_spheres;
|
||||
std::vector<float> positions_wire_spheres;
|
||||
std::vector<float> positions_center;
|
||||
std::vector<float> normals_spheres;
|
||||
std::vector<float> color_spheres;
|
||||
|
||||
|
||||
|
||||
GLint location[11];
|
||||
GLuint vao[1];
|
||||
GLuint buffer[6];
|
||||
GLuint rendering_program_spheres;
|
||||
GLuint rendering_program_lines;
|
||||
GLuint rendering_program_WireSpheres;
|
||||
GLuint nbSpheres;
|
||||
typedef std::map<Point_3, int> Point_to_int_map;
|
||||
typedef Point_to_int_map::iterator iterator;
|
||||
void create_Sphere(double);
|
||||
void initialize_buffers();
|
||||
void compile_shaders();
|
||||
void uniform_attrib(Viewer_interface*, int) const;
|
||||
void compute_elements();
|
||||
|
||||
// http://en.wikipedia.org/wiki/D-pointer
|
||||
Scene_polylines_item_private* d;
|
||||
|
||||
}; // end class Scene_polylines_item
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue