Scene_edit_polyhedron_item::Scene_edit_polyhedron_item (Scene_polyhedron_item* poly_item, Ui::DeformMesh* ui_widget, QMainWindow* mw) : Scene_item(NumberOfBuffers,NumberOfVaos), ui_widget(ui_widget), poly_item(poly_item), is_rot_free(true), own_poly_item(true), k_ring_selector(poly_item, mw, Scene_polyhedron_item_k_ring_selection::Active_handle::VERTEX, true) { nb_ROI = 0; nb_sphere = 0; nb_control = 0; nb_axis = 0; nb_bbox = 0; mw->installEventFilter(this); // bind vertex picking connect(&k_ring_selector, SIGNAL(selected(const std::set<Polyhedron::Vertex_handle>&)), this, SLOT(selected(const std::set<Polyhedron::Vertex_handle>&))); poly_item->set_color_vector_read_only(true); // to prevent recomputation of color vector in invalidateOpenGLBuffers() poly_item->update_vertex_indices(); deform_mesh = new Deform_mesh(*(poly_item->polyhedron()), Deform_mesh::Vertex_index_map(), Deform_mesh::Hedge_index_map(), Array_based_vertex_point_map(&positions)); length_of_axis = bbox().diagonal_length() / 15.0; // interleave events of viewer (there is only one viewer) QGLViewer* viewer = *QGLViewer::QGLViewerPool().begin(); viewer->installEventFilter(this); // create an empty group of control vertices for starting create_ctrl_vertices_group(); // start QObject's timer for continuous effects // (deforming mesh while mouse not moving) startTimer(0); // Required for drawing functionality reset_drawing_data(); //Generates an integer which will be used as ID for each buffer const char vertex_shader_source_bbox[] = { "#version 120 \n" "attribute highp vec3 vertex; \n" "attribute highp vec3 colors; \n" "uniform highp mat4 mvp_matrix; \n" "uniform highp mat4 rotations; \n" "uniform highp vec3 translation; \n" "uniform highp vec3 translation_2; \n" "varying highp vec3 fColors; \n" " \n" "void main(void) \n" "{ \n" " fColors = colors; \n" " gl_Position = mvp_matrix * (rotations *(vec4(translation_2,0.0)+vec4(vertex,1.0) )+ vec4(translation,0.0)) ; \n" "} \n" }; const char fragment_shader_source[]= { "#version 120 \n" "varying vec3 fColors; \n" " \n" "void main(void) \n" "{ \n" " gl_FragColor = vec4(fColors, 1.0); \n" "} \n" }; bbox_program.addShaderFromSourceCode(QOpenGLShader::Vertex,vertex_shader_source_bbox); bbox_program.addShaderFromSourceCode(QOpenGLShader::Fragment,fragment_shader_source); bbox_program.link(); ui_widget->remeshing_iterations_spinbox->setValue(1); ui_widget->remeshing_edge_length_spinbox->setValue(length_of_axis); ui_widget->remeshing_edge_length_spinbox->setDisabled(true); ui_widget->remeshingEdgeLengthInput_checkBox->setChecked(false); connect(ui_widget->remeshingEdgeLengthInput_checkBox, SIGNAL(toggled(bool)), ui_widget->remeshing_edge_length_spinbox, SLOT(setEnabled(bool))); //the spheres : create_Sphere(length_of_axis/15.0); invalidateOpenGLBuffers(); }
void Scene_polylines_item::compute_elements() const { positions_spheres.resize(0); positions_wire_spheres.resize(0); positions_lines.resize(0); color_spheres.resize(0); normals_spheres.resize(0); positions_center.resize(0); nbSpheres = 0; //Fills the VBO with the lines for(std::list<std::vector<Point_3> >::const_iterator it = polylines.begin(); it != polylines.end(); ++it){ if(it->empty()) continue; for(size_t i = 0, end = it->size()-1; i < end; ++i) { const Point_3& a = (*it)[i]; const Point_3& b = (*it)[i+1]; positions_lines.push_back(a.x()); positions_lines.push_back(a.y()); positions_lines.push_back(a.z()); positions_lines.push_back(1.0); positions_lines.push_back(b.x()); positions_lines.push_back(b.y()); positions_lines.push_back(b.z()); positions_lines.push_back(1.0); } } //Fills the VBO with the spheres if(d->draw_extremities) { // FIRST, count the number of incident cycles and polylines // for all extremities. typedef std::map<Point_3, int> Point_to_int_map; typedef Point_to_int_map::iterator iterator; Point_to_int_map corner_polyline_nb; { // scope to fill corner_polyline_nb' Point_to_int_map corner_cycles_nb; for(std::list<std::vector<Point_3> >::const_iterator it = this->polylines.begin(), end = this->polylines.end(); it != end; ++it) { const K::Point_3& a = *it->begin(); const K::Point_3& b = *it->rbegin(); if(a == b) { if ( it->size()>1 ) ++corner_cycles_nb[a]; else ++corner_polyline_nb[a]; } else { ++corner_polyline_nb[a]; ++corner_polyline_nb[b]; } } // THEN, ignore points that are incident to one cycle only. for(iterator c_it = corner_cycles_nb.begin(), end = corner_cycles_nb.end(); c_it != end; ++c_it) { const Point_3& a = c_it->first; iterator p_it = corner_polyline_nb.find(a); // If the point 'a'=c_it->first has only incident cycles... if(p_it == corner_polyline_nb.end()) { // ...then count it as a corner only if it has two incident cycles // or more. if(c_it->second > 1) { corner_polyline_nb[a] = c_it->second; } } else { // else add the number of cycles. p_it->second += c_it->second; } } } // At this point, 'corner_polyline_nb' gives the multiplicity of all // corners. //Finds the centers of the spheres and their color for(iterator p_it = corner_polyline_nb.begin(), end = corner_polyline_nb.end(); p_it != end; ++p_it) { nbSpheres++; const K::Point_3& centre = p_it->first; positions_center.push_back(centre.x()); positions_center.push_back(centre.y()); positions_center.push_back(centre.z()); float colors[3]; switch(p_it->second) { case 1: colors[0] = 0.0; // black colors[1] = 0.0; colors[2] = 0.0; break; case 2: colors[0] = 0.0; // green colors[1] = 0.8f; colors[2] = 0.0; break; case 3: colors[0] = 0.0; // blue colors[1] = 0.0; colors[2] = 0.8f; break; case 4: colors[0] = 0.8f; //red colors[1] = 0.0; colors[2] = 0.0; break; default: colors[0] = 0.8f; //fuschia colors[1] = 0.0; colors[2] = 0.8f; } color_spheres.push_back(colors[0]); color_spheres.push_back(colors[1]); color_spheres.push_back(colors[2]); color_wire_spheres.push_back(colors[0]); color_wire_spheres.push_back(colors[1]); color_wire_spheres.push_back(colors[2]); color_wire_spheres.push_back(colors[0]); color_wire_spheres.push_back(colors[1]); color_wire_spheres.push_back(colors[2]); } create_Sphere(d->spheres_drawn_radius); } }