diff --git a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh_deformation/Scene_edit_polyhedron_item.cpp b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh_deformation/Scene_edit_polyhedron_item.cpp index ef6b193a5fa..7f8311c3368 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh_deformation/Scene_edit_polyhedron_item.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh_deformation/Scene_edit_polyhedron_item.cpp @@ -347,7 +347,6 @@ void Scene_edit_polyhedron_item_priv::compute_normals_and_vertices(Mesh* mesh) typedef typename boost::property_map::type VertexPointMap; VertexPointMap pmap = get(boost::vertex_point, *mesh); - int s_index = 0; for(mesh_vd vd : fs.get_deform_mesh(mesh)->roi_vertices()) { if(!fs.get_deform_mesh(mesh)->is_control_vertex(vd)) @@ -361,7 +360,7 @@ void Scene_edit_polyhedron_item_priv::compute_normals_and_vertices(Mesh* mesh) { CGAL::Color c(0,255,0); EPICK::Point_3 point(p.x()+offset.x, p.y()+offset.y, p.z()+offset.z); - spheres->add_sphere(EPICK::Sphere_3(point, length_of_axis/15.0*length_of_axis/15.0), s_index++, c); + spheres->add_sphere(EPICK::Sphere_3(point, length_of_axis/15.0*length_of_axis/15.0), 0, c); } } @@ -401,7 +400,7 @@ void Scene_edit_polyhedron_item_priv::compute_normals_and_vertices(Mesh* mesh) EPICK::Point_3 center(p.x()+offset.x, p.y()+offset.y, p.z()+offset.z); - spheres_ctrl->add_sphere(EPICK::Sphere_3(center, length_of_axis/15.0*length_of_axis/15.0), s_index++, c); + spheres_ctrl->add_sphere(EPICK::Sphere_3(center, length_of_axis/15.0*length_of_axis/15.0), 0, c); } } } @@ -1272,7 +1271,7 @@ void Scene_edit_polyhedron_item::ShowAsSphere(bool b) { if(!d->spheres) { - d->spheres = new Scene_spheres_item(this, 0, false); + d->spheres = new Scene_spheres_item(this, 0, false, false); d->spheres->setName("ROI spheres"); d->spheres->setRenderingMode(Gouraud); connect(d->spheres, SIGNAL(destroyed()), this, SLOT(reset_spheres())); @@ -1284,7 +1283,7 @@ void Scene_edit_polyhedron_item::ShowAsSphere(bool b) } if(!d->spheres_ctrl) { - d->spheres_ctrl = new Scene_spheres_item(this, false); + d->spheres_ctrl = new Scene_spheres_item(this, false, false); d->spheres_ctrl->setName("Control spheres"); d->spheres_ctrl->setRenderingMode(Gouraud); connect(d->spheres_ctrl, &QObject::destroyed, this, Reset_spheres_ctrl(d) ); @@ -1777,6 +1776,10 @@ Scene_surface_mesh_item* Scene_edit_polyhedron_item::sm_item()const void Scene_edit_polyhedron_item::computeElements() const { d->compute_normals_and_vertices(sm_item()->face_graph()); + if(d->spheres) + d->spheres->computeElements(); + if(d->spheres_ctrl) + d->spheres_ctrl->computeElements(); std::vector vertices; std::vector *vertices_ptr; const CGAL::qglviewer::Vec offset = Three::mainViewer()->offset(); diff --git a/Polyhedron/demo/Polyhedron/Scene_spheres_item.cpp b/Polyhedron/demo/Polyhedron/Scene_spheres_item.cpp index b7364214cb9..b54d0705bfd 100644 --- a/Polyhedron/demo/Polyhedron/Scene_spheres_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_spheres_item.cpp @@ -17,9 +17,10 @@ struct Scene_spheres_item_priv typedef std::pair Sphere_pair; typedef std::vector > Spheres_container; - Scene_spheres_item_priv(bool planed, std::size_t max_index, Scene_spheres_item* parent) + Scene_spheres_item_priv(bool planed, std::size_t max_index, Scene_spheres_item* parent, bool pickable) :precision(36) ,has_plane(planed) + ,pickable(pickable) { item = parent; create_flat_and_wire_sphere(1.0f,vertices,normals, edges); @@ -62,11 +63,14 @@ struct Scene_spheres_item_priv Scene_spheres_item* item; QString tooltip; mutable Spheres_container spheres; + const bool pickable; }; void Scene_spheres_item_priv::pick(int id) const { + if(!pickable) + return; int offset = 0; float color[4]; for(std::size_t i=0; igetTriangleContainer(0)->initializeBuffers(viewer); item->getTriangleContainer(0)->setFlatDataSize(nb_vertices); item->getTriangleContainer(0)->setCenterSize(nb_centers); - - item->getTriangleContainer(1)->initializeBuffers(viewer); - item->getTriangleContainer(1)->setFlatDataSize(nb_vertices); - item->getTriangleContainer(1)->setCenterSize(nb_centers); + if(pickable) + { + item->getTriangleContainer(1)->initializeBuffers(viewer); + item->getTriangleContainer(1)->setFlatDataSize(nb_vertices); + item->getTriangleContainer(1)->setCenterSize(nb_centers); + } vertices.clear(); vertices.shrink_to_fit(); item->getEdgeContainer(0)->initializeBuffers(viewer); @@ -170,9 +179,10 @@ void Scene_spheres_item::draw(Viewer_interface *viewer) const { QVector4D cp(d->plane.a(),d->plane.b(),d->plane.c(),d->plane.d()); getTriangleContainer(0)->setPlane(cp); - getTriangleContainer(1)->setPlane(cp); + if(d->pickable) + getTriangleContainer(1)->setPlane(cp); } - if(d->spheres.size() > 1 && viewer->inDrawWithNames()) + if(d->pickable && (d->spheres.size() > 1 && viewer->inDrawWithNames())) { getTriangleContainer(1)->getVao(viewer)->program->setAttributeValue("normals", QVector3D(0,0,0)); getTriangleContainer(1)->draw(viewer, false); @@ -181,7 +191,7 @@ void Scene_spheres_item::draw(Viewer_interface *viewer) const { getTriangleContainer(0)->draw(viewer, false); } - if(d->spheres.size() > 1 && viewer->inDrawWithNames()) + if(d->pickable && (d->spheres.size() > 1 && viewer->inDrawWithNames())) { int rowLength = deviceWidth * 4; // data asked in RGBA,so 4 bytes. const static int dataLength = rowLength * deviceHeight; @@ -235,16 +245,18 @@ void Scene_spheres_item::add_sphere(const Sphere &sphere, std::size_t index, CG d->colors.push_back((float)color.red()/255); d->colors.push_back((float)color.green()/255); d->colors.push_back((float)color.blue()/255); - int R = (index & 0x000000FF) >> 0; - int G = (index & 0x0000FF00) >> 8; - int B = (index & 0x00FF0000) >> 16; - float r = R/255.0; - float g = G/255.0; - float b = B/255.0; - d->picking_colors.push_back(r); - d->picking_colors.push_back(g); - d->picking_colors.push_back(b); - + if(d->pickable) + { + int R = (index & 0x000000FF) >> 0; + int G = (index & 0x0000FF00) >> 8; + int B = (index & 0x00FF0000) >> 16; + float r = R/255.0; + float g = G/255.0; + float b = B/255.0; + d->picking_colors.push_back(r); + d->picking_colors.push_back(g); + d->picking_colors.push_back(b); + } d->edges_colors.push_back((float)color.red()/255); d->edges_colors.push_back((float)color.green()/255); d->edges_colors.push_back((float)color.blue()/255); @@ -252,16 +264,18 @@ void Scene_spheres_item::add_sphere(const Sphere &sphere, std::size_t index, CG d->centers.push_back(sphere.center().x()); d->centers.push_back(sphere.center().y()); d->centers.push_back(sphere.center().z()); - d->radius.push_back(CGAL::sqrt(sphere.squared_radius())); } void Scene_spheres_item::clear_spheres() { + d->spheres.clear(); d->colors.clear(); d->edges_colors.clear(); d->centers.clear(); d->radius.clear(); + d->picking_colors.clear(); + setBuffersFilled(false); } void Scene_spheres_item::setPrecision(int prec) { d->precision = prec; } void Scene_spheres_item::setPlane(Kernel::Plane_3 p_plane) { d->plane = p_plane; } @@ -269,7 +283,11 @@ void Scene_spheres_item::invalidateOpenGLBuffers() { setBuffersFilled(false); getTriangleContainer(0)->reset_vbos(NOT_INSTANCED); - getTriangleContainer(1)->reset_vbos(NOT_INSTANCED); + getTriangleContainer(0)->reset_vbos(COLORS); + if(d->pickable){ + getTriangleContainer(1)->reset_vbos(NOT_INSTANCED); + getTriangleContainer(1)->reset_vbos(COLORS); + } getEdgeContainer(0)->reset_vbos(NOT_INSTANCED); } @@ -304,10 +322,10 @@ void Scene_spheres_item::computeElements() const getTriangleContainer(0)->allocate(Tc::Flat_normals, d->normals.data(), static_cast(d->normals.size()*sizeof(float))); - - getTriangleContainer(1)->allocate(Tc::Flat_vertices, d->vertices.data(), - static_cast(d->vertices.size()*sizeof(float))); - + if(d->pickable) + getTriangleContainer(1)->allocate(Tc::Flat_vertices, d->vertices.data(), + static_cast(d->vertices.size()*sizeof(float))); + d->nb_vertices = d->vertices.size(); } @@ -318,12 +336,15 @@ void Scene_spheres_item::computeElements() const getTriangleContainer(0)->allocate(Tc::Facet_centers, d->centers.data(), static_cast(d->centers.size()*sizeof(float))); - getTriangleContainer(1)->allocate(Tc::FColors, d->picking_colors.data(), - static_cast(d->picking_colors.size()*sizeof(float))); - getTriangleContainer(1)->allocate(Tc::Radius, d->radius.data(), - static_cast(d->radius.size()*sizeof(float))); - getTriangleContainer(1)->allocate(Tc::Facet_centers, d->centers.data(), - static_cast(d->centers.size()*sizeof(float))); + if(d->pickable) + { + getTriangleContainer(1)->allocate(Tc::FColors, d->picking_colors.data(), + static_cast(d->picking_colors.size()*sizeof(float))); + getTriangleContainer(1)->allocate(Tc::Radius, d->radius.data(), + static_cast(d->radius.size()*sizeof(float))); + getTriangleContainer(1)->allocate(Tc::Facet_centers, d->centers.data(), + static_cast(d->centers.size()*sizeof(float))); + } if(!d->model_sphere_is_up) { @@ -395,3 +416,4 @@ bool Scene_spheres_item::save(const std::string& file_name)const out << "\n"; return true; } + diff --git a/Polyhedron/demo/Polyhedron/Scene_spheres_item.h b/Polyhedron/demo/Polyhedron/Scene_spheres_item.h index 2757012d578..fe88d7b2721 100644 --- a/Polyhedron/demo/Polyhedron/Scene_spheres_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_spheres_item.h @@ -33,7 +33,7 @@ public: typedef std::pair Sphere_pair; typedef std::vector > Spheres_container; - Scene_spheres_item(Scene_group_item* parent, std::size_t max_index = 0, bool planed = false); + Scene_spheres_item(Scene_group_item* parent, std::size_t max_index = 0, bool planed = false, bool pickable = true); ~Scene_spheres_item();