mirror of https://github.com/CGAL/cgal
Fix polygon_soup and optimize loading time
- fill_edges was called in a loop on the edges, which made the loading of big items extremely slow. - fill_edges is now only called in compute_normals, when it was called several times when creating or converting a polygon_soup - compute_normals_and_vertices is now const and called with initialized_buffers in the draw functions, which allows to reduce the number of times it is called, in Scene_polygon_soup_item and in Scene_polyhedron_item.
This commit is contained in:
parent
362e4ef7db
commit
c99b79bfc9
|
|
@ -131,7 +131,7 @@ void Polyhedron_demo_orient_soup_plugin::shuffle()
|
|||
|
||||
if(item) {
|
||||
item->shuffle_orientations();
|
||||
scene->itemChanged(item);
|
||||
//scene->itemChanged(item);
|
||||
}
|
||||
else {
|
||||
Scene_polyhedron_item* poly_item =
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ void Polyhedron_demo_scale_space_reconstruction_plugin::on_actionScaleSpaceRecon
|
|||
map_i2i[(*it)[2]] );
|
||||
}
|
||||
|
||||
new_item->finalize_polygon_soup();
|
||||
new_item->changed();
|
||||
|
||||
new_item->setName(tr("%1-shell %2 (ss reconstruction)").arg(scene->item(index)->name()).arg(sh+1));
|
||||
new_item->setColor(Qt::magenta);
|
||||
|
|
@ -176,7 +176,7 @@ void Polyhedron_demo_scale_space_reconstruction_plugin::on_actionScaleSpaceRecon
|
|||
map_i2i_smoothed[(*it)[2]] );
|
||||
}
|
||||
|
||||
new_item_smoothed->finalize_polygon_soup();
|
||||
new_item_smoothed->changed();
|
||||
|
||||
new_item_smoothed->setName(tr("%1-shell %2 (ss smoothed reconstruction)").arg(scene->item(index)->name()).arg(sh+1));
|
||||
new_item_smoothed->setColor(Qt::magenta);
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ TDS,
|
|||
Itag> CDTbase;
|
||||
typedef CGAL::Constrained_triangulation_plus_2<CDTbase> CDT;
|
||||
void
|
||||
Scene_polygon_soup_item::triangulate_polygon(Polygons_iterator pit)
|
||||
Scene_polygon_soup_item::triangulate_polygon(Polygons_iterator pit) const
|
||||
{
|
||||
//Computes the normal of the facet
|
||||
const Point_3& pa = soup->points[pit->at(0)];
|
||||
|
|
@ -227,7 +227,6 @@ Scene_polygon_soup_item::triangulate_polygon(Polygons_iterator pit)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//iterates on the internal faces to add the vertices to the positions
|
||||
//and the normals to the appropriate vectors
|
||||
int count =0;
|
||||
|
|
@ -280,12 +279,14 @@ Scene_polygon_soup_item::triangulate_polygon(Polygons_iterator pit)
|
|||
}
|
||||
}
|
||||
void
|
||||
Scene_polygon_soup_item::compute_normals_and_vertices(){
|
||||
Scene_polygon_soup_item::compute_normals_and_vertices() const{
|
||||
//get the vertices and normals
|
||||
typedef Polygon_soup::Polygons::size_type size_type;
|
||||
positions_poly.resize(0);
|
||||
positions_lines.resize(0);
|
||||
normals.resize(0);
|
||||
positions_nm_lines.resize(0);
|
||||
soup->fill_edges();
|
||||
for(Polygons_iterator it = soup->polygons.begin();
|
||||
it != soup->polygons.end(); ++it)
|
||||
{
|
||||
|
|
@ -343,8 +344,6 @@ Scene_polygon_soup_item::compute_normals_and_vertices(){
|
|||
positions_lines.push_back(1.0);
|
||||
}
|
||||
//Non manifold edges
|
||||
positions_nm_lines.resize(0);
|
||||
soup->fill_edges();
|
||||
BOOST_FOREACH(const Polygon_soup::Edge& edge,
|
||||
soup->non_manifold_edges)
|
||||
{
|
||||
|
|
@ -411,7 +410,7 @@ void Scene_polygon_soup_item::init_polygon_soup(std::size_t nb_pts, std::size_t
|
|||
oriented = false;
|
||||
}
|
||||
|
||||
void Scene_polygon_soup_item::finalize_polygon_soup(){ soup->fill_edges(); }
|
||||
|
||||
|
||||
#include <CGAL/IO/generic_print_polyhedron.h>
|
||||
#include <iostream>
|
||||
|
|
@ -435,7 +434,6 @@ Scene_polygon_soup_item::setDisplayNonManifoldEdges(const bool b)
|
|||
{
|
||||
|
||||
soup->display_non_manifold_edges = b;
|
||||
changed();
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
@ -451,8 +449,7 @@ void Scene_polygon_soup_item::shuffle_orientations()
|
|||
{
|
||||
if(std::rand() % 2 == 0) soup->inverse_orientation(i);
|
||||
}
|
||||
soup->fill_edges();
|
||||
changed();
|
||||
|
||||
}
|
||||
|
||||
void Scene_polygon_soup_item::inside_out()
|
||||
|
|
@ -462,7 +459,6 @@ void Scene_polygon_soup_item::inside_out()
|
|||
{
|
||||
soup->inverse_orientation(i);
|
||||
}
|
||||
soup->fill_edges();
|
||||
changed();
|
||||
}
|
||||
|
||||
|
|
@ -568,7 +564,8 @@ Scene_polygon_soup_item::toolTip() const
|
|||
void
|
||||
Scene_polygon_soup_item::draw(Viewer_interface* viewer) const {
|
||||
if(!are_buffers_filled)
|
||||
{
|
||||
{
|
||||
compute_normals_and_vertices();
|
||||
initialize_buffers(viewer);
|
||||
}
|
||||
if(soup == 0) return;
|
||||
|
|
@ -595,8 +592,9 @@ void
|
|||
Scene_polygon_soup_item::draw_points(Viewer_interface* viewer) const {
|
||||
if(!are_buffers_filled)
|
||||
{
|
||||
initialize_buffers(viewer);
|
||||
}
|
||||
compute_normals_and_vertices();
|
||||
initialize_buffers(viewer);
|
||||
}
|
||||
if(soup == 0) return;
|
||||
vaos[1]->bind();
|
||||
attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT);
|
||||
|
|
@ -615,6 +613,7 @@ void
|
|||
Scene_polygon_soup_item::draw_edges(Viewer_interface* viewer) const {
|
||||
if(!are_buffers_filled)
|
||||
{
|
||||
compute_normals_and_vertices();
|
||||
initialize_buffers(viewer);
|
||||
}
|
||||
if(soup == 0) return;
|
||||
|
|
@ -656,7 +655,6 @@ Scene_polygon_soup_item::isEmpty() const {
|
|||
void
|
||||
Scene_polygon_soup_item::changed()
|
||||
{
|
||||
compute_normals_and_vertices();
|
||||
are_buffers_filled = false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ public:
|
|||
soup->polygons[i].assign(polygons[i].begin(), polygons[i].end());
|
||||
|
||||
/// fill non-manifold edges container
|
||||
soup->fill_edges();
|
||||
//soup->fill_edges();
|
||||
oriented = false;
|
||||
|
||||
Q_EMIT changed();
|
||||
|
|
@ -155,7 +155,6 @@ public:
|
|||
void new_triangle(const std::size_t, const std::size_t, const std::size_t);
|
||||
|
||||
void init_polygon_soup(std::size_t nb_pts, std::size_t nb_polygons);
|
||||
void finalize_polygon_soup();
|
||||
|
||||
public Q_SLOTS:
|
||||
void shuffle_orientations();
|
||||
|
|
@ -179,8 +178,8 @@ private:
|
|||
mutable int nb_lines;
|
||||
using Scene_item::initialize_buffers;
|
||||
void initialize_buffers(Viewer_interface *viewer) const;
|
||||
void compute_normals_and_vertices(void);
|
||||
void triangulate_polygon(Polygons_iterator );
|
||||
void compute_normals_and_vertices(void) const;
|
||||
void triangulate_polygon(Polygons_iterator ) const;
|
||||
mutable QOpenGLShaderProgram *program;
|
||||
|
||||
}; // end class Scene_polygon_soup_item
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ typedef CGAL::Constrained_triangulation_plus_2<CDTbase> CDT;
|
|||
|
||||
//Make sure all the facets are triangles
|
||||
void
|
||||
Scene_polyhedron_item::is_Triangulated()
|
||||
Scene_polyhedron_item::is_Triangulated() const
|
||||
{
|
||||
typedef Polyhedron::Halfedge_around_facet_circulator HF_circulator;
|
||||
Facet_iterator f = poly->facets_begin();
|
||||
|
|
@ -115,7 +115,7 @@ Scene_polyhedron_item::is_Triangulated()
|
|||
}
|
||||
}
|
||||
void
|
||||
Scene_polyhedron_item::triangulate_facet(Facet_iterator fit)
|
||||
Scene_polyhedron_item::triangulate_facet(Facet_iterator fit) const
|
||||
{
|
||||
//Computes the normal of the facet
|
||||
Traits::Vector_3 normal =
|
||||
|
|
@ -214,7 +214,7 @@ Scene_polyhedron_item::triangulate_facet(Facet_iterator fit)
|
|||
}
|
||||
|
||||
void
|
||||
Scene_polyhedron_item::triangulate_facet_color(Facet_iterator fit)
|
||||
Scene_polyhedron_item::triangulate_facet_color(Facet_iterator fit) const
|
||||
{
|
||||
Traits::Vector_3 normal =
|
||||
CGAL::Polygon_mesh_processing::compute_face_normal(fit, *poly);
|
||||
|
|
@ -439,7 +439,7 @@ Scene_polyhedron_item::initialize_buffers(Viewer_interface* viewer) const
|
|||
}
|
||||
|
||||
void
|
||||
Scene_polyhedron_item::compute_normals_and_vertices(void)
|
||||
Scene_polyhedron_item::compute_normals_and_vertices(void) const
|
||||
{
|
||||
positions_facets.resize(0);
|
||||
positions_lines.resize(0);
|
||||
|
|
@ -552,7 +552,7 @@ Scene_polyhedron_item::compute_normals_and_vertices(void)
|
|||
}
|
||||
|
||||
void
|
||||
Scene_polyhedron_item::compute_colors()
|
||||
Scene_polyhedron_item::compute_colors() const
|
||||
{
|
||||
color_lines.resize(0);
|
||||
color_facets.resize(0);
|
||||
|
|
@ -877,7 +877,11 @@ void Scene_polyhedron_item::set_erase_next_picked_facet(bool b)
|
|||
|
||||
void Scene_polyhedron_item::draw(Viewer_interface* viewer) const {
|
||||
if(!are_buffers_filled)
|
||||
{
|
||||
is_Triangulated();
|
||||
compute_normals_and_vertices();
|
||||
initialize_buffers(viewer);
|
||||
}
|
||||
|
||||
|
||||
if(!is_selected)
|
||||
|
|
@ -899,6 +903,12 @@ void Scene_polyhedron_item::draw(Viewer_interface* viewer) const {
|
|||
|
||||
// Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list
|
||||
void Scene_polyhedron_item::draw_edges(Viewer_interface* viewer) const {
|
||||
if(!are_buffers_filled)
|
||||
{
|
||||
is_Triangulated();
|
||||
compute_normals_and_vertices();
|
||||
initialize_buffers(viewer);
|
||||
}
|
||||
|
||||
if(!is_selected)
|
||||
{
|
||||
|
|
@ -922,6 +932,12 @@ void Scene_polyhedron_item::draw_edges(Viewer_interface* viewer) const {
|
|||
|
||||
void
|
||||
Scene_polyhedron_item::draw_points(Viewer_interface* viewer) const {
|
||||
if(!are_buffers_filled)
|
||||
{
|
||||
is_Triangulated();
|
||||
compute_normals_and_vertices();
|
||||
initialize_buffers(viewer);
|
||||
}
|
||||
|
||||
vaos[1]->bind();
|
||||
attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
|
||||
|
|
@ -966,8 +982,6 @@ changed()
|
|||
delete_aabb_tree(this);
|
||||
init();
|
||||
Base::changed();
|
||||
is_Triangulated();
|
||||
compute_normals_and_vertices();
|
||||
are_buffers_filled = false;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public:
|
|||
// IO
|
||||
bool load(std::istream& in);
|
||||
bool save(std::ostream& out) const;
|
||||
bool is_Triangle;
|
||||
mutable bool is_Triangle;
|
||||
|
||||
// Function for displaying meta-data of the item
|
||||
virtual QString toolTip() const;
|
||||
|
|
@ -125,11 +125,11 @@ private:
|
|||
|
||||
using Scene_item::initialize_buffers;
|
||||
void initialize_buffers(Viewer_interface *viewer = 0) const;
|
||||
void compute_normals_and_vertices(void);
|
||||
void compute_colors();
|
||||
void triangulate_facet(Facet_iterator );
|
||||
void triangulate_facet_color(Facet_iterator );
|
||||
void is_Triangulated();
|
||||
void compute_normals_and_vertices(void) const;
|
||||
void compute_colors() const;
|
||||
void triangulate_facet(Facet_iterator ) const;
|
||||
void triangulate_facet_color(Facet_iterator ) const;
|
||||
void is_Triangulated() const;
|
||||
double volume, area;
|
||||
|
||||
}; // end class Scene_polyhedron_item
|
||||
|
|
|
|||
Loading…
Reference in New Issue