This commit is contained in:
Andreas Fabri 2017-03-12 17:30:30 +01:00 committed by Maxime Gimeno
parent b4a44aa9ec
commit df83b94e77
1 changed files with 33 additions and 43 deletions

View File

@ -9,8 +9,10 @@
#include <QMap> #include <QMap>
#include "Messages_interface.h" #include "Messages_interface.h"
#include "Scene_polyhedron_item.h" #include "Scene_polyhedron_item.h"
#include "Polyhedron_type.h"
#include "Color_ramp.h" #include "Color_ramp.h"
#include "triangulate_primitive.h" #include "triangulate_primitive.h"
#include <CGAL/Polygon_mesh_processing/bbox.h>
#include <CGAL/Polygon_mesh_processing/distance.h> #include <CGAL/Polygon_mesh_processing/distance.h>
#include <CGAL/Polygon_mesh_processing/compute_normal.h> #include <CGAL/Polygon_mesh_processing/compute_normal.h>
#include <boost/iterator/counting_iterator.hpp> #include <boost/iterator/counting_iterator.hpp>
@ -114,23 +116,17 @@ public:
vaos[Edges]->release(); vaos[Edges]->release();
program->release(); program->release();
} }
void compute_bbox() const { void compute_bbox() const {
const Kernel::Point_3& p = *(poly->points_begin()); _bbox = PMP::bbox(*poly);
CGAL::Bbox_3 bbox(p.x(), p.y(), p.z(), p.x(), p.y(), p.z());
for(Polyhedron::Point_iterator it = poly->points_begin();
it != poly->points_end();
++it) {
bbox = bbox + it->bbox();
}
_bbox = Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(),
bbox.xmax(),bbox.ymax(),bbox.zmax());
} }
private: private:
Polyhedron* poly; Polyhedron* poly;
Polyhedron* poly_B; Polyhedron* poly_B;
mutable bool are_buffers_filled; mutable bool are_buffers_filled;
QString other_poly; QString other_poly;
mutable std::vector<float> vertices; mutable std::vector<float> m_vertices;
mutable std::vector<float> edge_vertices; mutable std::vector<float> edge_vertices;
mutable std::vector<float> normals; mutable std::vector<float> normals;
mutable std::vector<float> colors; mutable std::vector<float> colors;
@ -165,8 +161,8 @@ private:
Tree tree( faces(m).first, faces(m).second, m); Tree tree( faces(m).first, faces(m).second, m);
tree.accelerate_distance_queries(); tree.accelerate_distance_queries();
tree.build(); tree.build();
boost::graph_traits<Polyhedron>::vertex_descriptor vd = *(vertices(m).first);
Traits::Point_3 hint = m.vertices_begin()->point(); Traits::Point_3 hint = vd->point();
#if !defined(CGAL_LINKED_WITH_TBB) #if !defined(CGAL_LINKED_WITH_TBB)
double hdist = 0; double hdist = 0;
@ -191,17 +187,17 @@ private:
void computeElements()const void computeElements()const
{ {
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
vertices.resize(0); m_vertices.resize(0);
edge_vertices.resize(0); edge_vertices.resize(0);
normals.resize(0); normals.resize(0);
colors.resize(0); colors.resize(0);
typedef Polyhedron::Traits Kernel; typedef Polyhedron::Traits Kernel;
typedef Kernel::Vector_3 Vector; typedef Kernel::Vector_3 Vector;
typedef Polyhedron::Facet_iterator Facet_iterator;
typedef boost::graph_traits<Polyhedron>::face_descriptor face_descriptor; typedef boost::graph_traits<Polyhedron>::face_descriptor face_descriptor;
typedef boost::graph_traits<Polyhedron>::vertex_descriptor vertex_descriptor; typedef boost::graph_traits<Polyhedron>::vertex_descriptor vertex_descriptor;
boost::property_map<Polyhedron,CGAL::vertex_point_t>::type vpmap = get(CGAL::vertex_point,*poly);
//facets //facets
{ {
boost::container::flat_map<face_descriptor, Vector> face_normals_map; boost::container::flat_map<face_descriptor, Vector> face_normals_map;
@ -213,13 +209,10 @@ private:
PMP::compute_normals(*poly, nv_pmap, nf_pmap); PMP::compute_normals(*poly, nv_pmap, nf_pmap);
std::vector<Kernel::Point_3> total_points(0); std::vector<Kernel::Point_3> total_points(0);
Facet_iterator f = poly->facets_begin();
for(f = poly->facets_begin(); BOOST_FOREACH(boost::graph_traits<Polyhedron>::face_descriptor f, faces(*poly)) {
f != poly->facets_end();
f++)
{
Vector nf = get(nf_pmap, f); Vector nf = get(nf_pmap, f);
f->plane() = Kernel::Plane_3(f->halfedge()->vertex()->point(), nf); f->plane() = Kernel::Plane_3(get(vpmap,target(halfedge(f,*poly),*poly)), nf);
typedef FacetTriangulator<Polyhedron, Polyhedron::Traits, boost::graph_traits<Polyhedron>::vertex_descriptor> FT; typedef FacetTriangulator<Polyhedron, Polyhedron::Traits, boost::graph_traits<Polyhedron>::vertex_descriptor> FT;
double diagonal; double diagonal;
if(this->diagonalBbox() != std::numeric_limits<double>::infinity()) if(this->diagonalBbox() != std::numeric_limits<double>::infinity())
@ -232,12 +225,14 @@ private:
std::vector<Kernel::Point_3> sampled_points; std::vector<Kernel::Point_3> sampled_points;
std::size_t nb_points = (std::max)((int)std::ceil(nb_pts_per_face * PMP::face_area(f,*poly,PMP::parameters::geom_traits(Kernel()))), std::size_t nb_points = (std::max)((int)std::ceil(nb_pts_per_face * PMP::face_area(f,*poly,PMP::parameters::geom_traits(Kernel()))),
1); 1);
CGAL::Random_points_in_triangle_3<Kernel::Point_3> g(f->halfedge()->vertex()->point(), f->halfedge()->next()->vertex()->point(), Kernel::Point_3 &p = get(vpmap,target(halfedge(f,*poly),*poly));
f->halfedge()->next()->next()->vertex()->point()); Kernel::Point_3 &q = get(vpmap,target(next(halfedge(f,*poly),*poly),*poly));
Kernel::Point_3 &r = get(vpmap,target(next(next(halfedge(f,*poly),*poly),*poly),*poly));
CGAL::Random_points_in_triangle_3<Kernel::Point_3> g(p, q, r);
CGAL::cpp11::copy_n(g, nb_points, std::back_inserter(sampled_points)); CGAL::cpp11::copy_n(g, nb_points, std::back_inserter(sampled_points));
sampled_points.push_back(f->halfedge()->vertex()->point()); sampled_points.push_back(p);
sampled_points.push_back(f->halfedge()->next()->vertex()->point()); sampled_points.push_back(q);
sampled_points.push_back(f->halfedge()->next()->next()->vertex()->point()); sampled_points.push_back(r);
//triangle facets with sample points for color display //triangle facets with sample points for color display
FT triangulation(f,sampled_points,nf,poly,diagonal); FT triangulation(f,sampled_points,nf,poly,diagonal);
@ -262,9 +257,9 @@ private:
for (int i = 0; i<3; ++i) for (int i = 0; i<3; ++i)
{ {
total_points.push_back(ffit->vertex(i)->point()); total_points.push_back(ffit->vertex(i)->point());
vertices.push_back(ffit->vertex(i)->point().x()); m_vertices.push_back(ffit->vertex(i)->point().x());
vertices.push_back(ffit->vertex(i)->point().y()); m_vertices.push_back(ffit->vertex(i)->point().y());
vertices.push_back(ffit->vertex(i)->point().z()); m_vertices.push_back(ffit->vertex(i)->point().z());
normals.push_back(nf.x()); normals.push_back(nf.x());
normals.push_back(nf.y()); normals.push_back(nf.y());
@ -310,14 +305,11 @@ private:
{ {
//Lines //Lines
typedef Kernel::Point_3 Point; typedef Kernel::Point_3 Point;
typedef Polyhedron::Edge_iterator Edge_iterator; typedef boost::graph_traits<Polyhedron>::edge_descriptor edge_descriptor;
Edge_iterator he;
for(he = poly->edges_begin(); BOOST_FOREACH(edge_descriptor he, edges(*poly)){
he != poly->edges_end(); const Point& a = get(vpmap,target(he,*poly));
he++) const Point& b = get(vpmap,source(he,*poly));
{
const Point& a = he->vertex()->point();
const Point& b = he->opposite()->vertex()->point();
{ {
edge_vertices.push_back(a.x()); edge_vertices.push_back(a.x());
@ -339,8 +331,8 @@ private:
program->bind(); program->bind();
vaos[Facets]->bind(); vaos[Facets]->bind();
buffers[Vertices].bind(); buffers[Vertices].bind();
buffers[Vertices].allocate(vertices.data(), buffers[Vertices].allocate(m_vertices.data(),
static_cast<GLsizei>(vertices.size()*sizeof(float))); static_cast<GLsizei>(m_vertices.size()*sizeof(float)));
program->enableAttributeArray("vertex"); program->enableAttributeArray("vertex");
program->setAttributeBuffer("vertex",GL_FLOAT,0,3); program->setAttributeBuffer("vertex",GL_FLOAT,0,3);
buffers[Vertices].release(); buffers[Vertices].release();
@ -371,10 +363,10 @@ private:
vaos[Facets]->release(); vaos[Facets]->release();
program->release(); program->release();
nb_pos = vertices.size(); nb_pos = m_vertices.size();
vertices.resize(0); m_vertices.resize(0);
//"Swap trick" insures that the memory is indeed freed and not kept available //"Swap trick" insures that the memory is indeed freed and not kept available
std::vector<float>(vertices).swap(vertices); std::vector<float>(m_vertices).swap(m_vertices);
nb_edge_pos = edge_vertices.size(); nb_edge_pos = edge_vertices.size();
edge_vertices.resize(0); edge_vertices.resize(0);
std::vector<float>(edge_vertices).swap(edge_vertices); std::vector<float>(edge_vertices).swap(edge_vertices);
@ -398,11 +390,9 @@ public:
//decides if the plugin's actions will be displayed or not. //decides if the plugin's actions will be displayed or not.
bool applicable(QAction*) const bool applicable(QAction*) const
{ {
return scene->selectionIndices().size() == 2 && return scene->selectionIndices().size() == 2 &&
qobject_cast<Scene_polyhedron_item*>(scene->item(scene->selectionIndices().first())) && qobject_cast<Scene_polyhedron_item*>(scene->item(scene->selectionIndices().first())) &&
qobject_cast<Scene_polyhedron_item*>(scene->item(scene->selectionIndices().last())); qobject_cast<Scene_polyhedron_item*>(scene->item(scene->selectionIndices().last()));
} }
//the list of the actions of the plugin. //the list of the actions of the plugin.
QList<QAction*> actions() const QList<QAction*> actions() const