mirror of https://github.com/CGAL/cgal
Edges management
- The shader of the edges of the base item discards the edges when it should - The facets of the cutplane have edges - The grid is displayed in all the rendering modes
This commit is contained in:
parent
d4dd0c1b28
commit
d1b3937a88
|
|
@ -95,4 +95,4 @@ struct Graph_manipulations
|
|||
} // namespace internal
|
||||
} // namespace CGAL
|
||||
|
||||
#endif CGAL_INTERNAL_MESH_3_INTERNAL_GRAPH_MANIPULATIONS
|
||||
#endif //CGAL_INTERNAL_MESH_3_INTERNAL_GRAPH_MANIPULATIONS
|
||||
|
|
|
|||
|
|
@ -34,14 +34,14 @@ namespace CGAL {
|
|||
template <typename P>
|
||||
void
|
||||
polylines_to_protect(const CGAL::Image_3& cgal_image,
|
||||
const double vx, const double vy, const double vz,
|
||||
const double, const double, const double,
|
||||
std::vector<std::vector<P> >& polylines)
|
||||
{
|
||||
typedef typename Kernel_traits<P>::Kernel K;
|
||||
typedef P Point_3;
|
||||
typedef boost::adjacency_list<boost::setS, boost::setS, boost::undirectedS, Point_3> Graph;
|
||||
typedef boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
|
||||
typedef boost::graph_traits<Graph>::edge_iterator edge_iterator;
|
||||
typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
|
||||
// typedef typename boost::graph_traits<Graph>::edge_iterator edge_iterator;
|
||||
|
||||
const int xdim = static_cast<int>(cgal_image.xdim());
|
||||
const int ydim = static_cast<int>(cgal_image.ydim());
|
||||
|
|
|
|||
|
|
@ -178,10 +178,10 @@ Scene_item* cgal_code_mesh_3(const Image* pImage,
|
|||
|
||||
|
||||
|
||||
typedef Facet_extra_criterion<Tr,
|
||||
/*typedef Facet_extra_criterion<Tr,
|
||||
Image_mesh_domain,
|
||||
Mesh_criteria::Facet_criteria::Visitor>
|
||||
Extra_criterion;
|
||||
Extra_criterion;*/
|
||||
|
||||
|
||||
// facet_criteria.add(new Extra_criterion(*p_domain));
|
||||
|
|
|
|||
|
|
@ -34,5 +34,8 @@
|
|||
<file>resources/shader_with_texture.v</file>
|
||||
<file>resources/shader_instanced.v</file>
|
||||
<file>resources/shader_no_light_no_selection.f</file>
|
||||
<file>resources/shader_c3t3_edges.f</file>
|
||||
<file>resources/shader_c3t3.f</file>
|
||||
<file>resources/shader_c3t3_edges.v</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
|||
|
|
@ -477,6 +477,20 @@ void Scene_c3t3_item::draw(CGAL::Three::Viewer_interface* viewer) const {
|
|||
ncthis->compute_elements();
|
||||
ncthis->initialize_buffers(viewer);
|
||||
}
|
||||
|
||||
vaos[Grid]->bind();
|
||||
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
|
||||
attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
|
||||
program->bind();
|
||||
program->setAttributeValue("colors", QColor(Qt::black));
|
||||
QMatrix4x4 f_mat;
|
||||
for (int i = 0; i<16; i++)
|
||||
f_mat.data()[i] = frame->matrix()[i];
|
||||
program->setUniformValue("f_matrix", f_mat);
|
||||
viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_grid.size() / 3));
|
||||
program->release();
|
||||
vaos[Grid]->release();
|
||||
|
||||
vaos[Facets]->bind();
|
||||
program = getShaderProgram(PROGRAM_C3T3);
|
||||
attrib_buffers(viewer, PROGRAM_C3T3);
|
||||
|
|
@ -558,7 +572,10 @@ void Scene_c3t3_item::draw_edges(CGAL::Three::Viewer_interface* viewer) const {
|
|||
ncthis->compute_elements();
|
||||
ncthis->initialize_buffers(viewer);
|
||||
}
|
||||
vaos[2]->bind();
|
||||
|
||||
if(renderingMode() == Wireframe)
|
||||
{
|
||||
vaos[Grid]->bind();
|
||||
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
|
||||
attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
|
||||
program->bind();
|
||||
|
|
@ -569,16 +586,27 @@ void Scene_c3t3_item::draw_edges(CGAL::Three::Viewer_interface* viewer) const {
|
|||
program->setUniformValue("f_matrix", f_mat);
|
||||
viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_grid.size() / 3));
|
||||
program->release();
|
||||
vaos[2]->release();
|
||||
|
||||
vaos[Grid]->release();
|
||||
}
|
||||
vaos[Edges]->bind();
|
||||
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
|
||||
attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
|
||||
program = getShaderProgram(PROGRAM_C3T3_EDGES);
|
||||
attrib_buffers(viewer, PROGRAM_C3T3_EDGES);
|
||||
program->bind();
|
||||
QVector4D cp(this->plane().a(),this->plane().b(),this->plane().c(),this->plane().d());
|
||||
program->setUniformValue("cutplane", cp);
|
||||
program->setAttributeValue("colors", QColor(Qt::black));
|
||||
viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_lines_size / 3));
|
||||
program->release();
|
||||
vaos[Edges]->release();
|
||||
|
||||
vaos[iEdges]->bind();
|
||||
program = getShaderProgram(PROGRAM_NO_SELECTION);
|
||||
attrib_buffers(viewer, PROGRAM_NO_SELECTION);
|
||||
program->bind();
|
||||
program->setAttributeValue("colors", QColor(Qt::black));
|
||||
viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_lines.size() / 3));
|
||||
program->release();
|
||||
vaos[Edges]->release();
|
||||
vaos[iEdges]->release();
|
||||
|
||||
if(spheres_are_shown)
|
||||
{
|
||||
|
|
@ -633,15 +661,17 @@ void Scene_c3t3_item::draw_points(CGAL::Three::Viewer_interface * viewer) const
|
|||
ncthis-> initialize_buffers(viewer);
|
||||
}
|
||||
vaos[Edges]->bind();
|
||||
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
|
||||
attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
|
||||
program = getShaderProgram(PROGRAM_C3T3_EDGES);
|
||||
attrib_buffers(viewer, PROGRAM_C3T3_EDGES);
|
||||
program->bind();
|
||||
QVector4D cp(this->plane().a(),this->plane().b(),this->plane().c(),this->plane().d());
|
||||
program->setUniformValue("cutplane", cp);
|
||||
program->setAttributeValue("colors", this->color());
|
||||
viewer->glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(positions_lines.size() / 3));
|
||||
vaos[Edges]->release();
|
||||
program->release();
|
||||
|
||||
vaos[2]->bind();
|
||||
vaos[Grid]->bind();
|
||||
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
|
||||
attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
|
||||
program->bind();
|
||||
|
|
@ -652,7 +682,7 @@ void Scene_c3t3_item::draw_points(CGAL::Three::Viewer_interface * viewer) const
|
|||
program->setUniformValue("f_matrix", f_mat);
|
||||
viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_grid.size() / 3));
|
||||
program->release();
|
||||
vaos[2]->release();
|
||||
vaos[Grid]->release();
|
||||
}
|
||||
|
||||
void Scene_c3t3_item::draw_triangle(const Kernel::Point_3& pa,
|
||||
|
|
@ -819,6 +849,22 @@ void Scene_c3t3_item::initialize_intersection_buffers(CGAL::Three::Viewer_interf
|
|||
vaos[iFacets]->release();
|
||||
program->release();
|
||||
|
||||
}
|
||||
//vao containing the data for the lines
|
||||
{
|
||||
program = getShaderProgram(PROGRAM_NO_SELECTION, viewer);
|
||||
program->bind();
|
||||
|
||||
vaos[iEdges]->bind();
|
||||
buffers[iEdges_vertices].bind();
|
||||
buffers[iEdges_vertices].allocate(positions_lines.data(),
|
||||
static_cast<int>(positions_lines.size()*sizeof(float)));
|
||||
program->enableAttributeArray("vertex");
|
||||
program->setAttributeBuffer("vertex", GL_FLOAT, 0, 3);
|
||||
buffers[iEdges_vertices].release();
|
||||
|
||||
vaos[iEdges]->release();
|
||||
program->release();
|
||||
}
|
||||
are_intersection_buffers_filled = true;
|
||||
}
|
||||
|
|
@ -858,16 +904,16 @@ void Scene_c3t3_item::initialize_buffers(CGAL::Three::Viewer_interface *viewer)
|
|||
|
||||
positions_poly_size = positions_poly.size();
|
||||
positions_poly.clear();
|
||||
positions_poly.swap(std::vector<float>());
|
||||
positions_poly.swap(positions_poly);
|
||||
normals.clear();
|
||||
normals.swap(std::vector<float>());
|
||||
normals.swap(normals);
|
||||
f_colors.clear();
|
||||
f_colors.swap(std::vector<float>());
|
||||
f_colors.swap(f_colors);
|
||||
}
|
||||
|
||||
//vao containing the data for the lines
|
||||
{
|
||||
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer);
|
||||
program = getShaderProgram(PROGRAM_C3T3_EDGES, viewer);
|
||||
program->bind();
|
||||
|
||||
vaos[Edges]->bind();
|
||||
|
|
@ -881,6 +927,10 @@ void Scene_c3t3_item::initialize_buffers(CGAL::Three::Viewer_interface *viewer)
|
|||
vaos[Edges]->release();
|
||||
program->release();
|
||||
|
||||
positions_lines_size = positions_lines.size();
|
||||
positions_lines.clear();
|
||||
positions_lines.swap(positions_lines);
|
||||
|
||||
}
|
||||
|
||||
//vao containing the data for the grid
|
||||
|
|
@ -888,14 +938,14 @@ void Scene_c3t3_item::initialize_buffers(CGAL::Three::Viewer_interface *viewer)
|
|||
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer);
|
||||
program->bind();
|
||||
|
||||
vaos[2]->bind();
|
||||
vaos[Grid]->bind();
|
||||
buffers[Grid_vertices].bind();
|
||||
buffers[Grid_vertices].allocate(positions_grid.data(),
|
||||
static_cast<int>(positions_grid.size()*sizeof(float)));
|
||||
program->enableAttributeArray("vertex");
|
||||
program->setAttributeBuffer("vertex", GL_FLOAT, 0, 3);
|
||||
buffers[Grid_vertices].release();
|
||||
vaos[2]->release();
|
||||
vaos[Grid]->release();
|
||||
program->release();
|
||||
}
|
||||
|
||||
|
|
@ -1012,6 +1062,8 @@ void Scene_c3t3_item::compute_intersection(const Primitive& facet)
|
|||
draw_triangle_edges(pa, pb, pd);
|
||||
draw_triangle_edges(pa, pc, pd);
|
||||
draw_triangle_edges(pb, pc, pd);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Scene_c3t3_item::compute_intersections()
|
||||
|
|
@ -1019,6 +1071,7 @@ void Scene_c3t3_item::compute_intersections()
|
|||
positions_poly.clear();
|
||||
normals.clear();
|
||||
f_colors.clear();
|
||||
positions_lines.clear();
|
||||
const Kernel::Plane_3& plane = this->plane();
|
||||
tree.all_intersected_primitives(plane, boost::make_function_output_iterator(Compute_intersection(*this)));
|
||||
}
|
||||
|
|
@ -1087,13 +1140,6 @@ void Scene_c3t3_item::compute_elements()
|
|||
|
||||
//The facets
|
||||
{
|
||||
const Kernel::Plane_3& plane = this->plane();
|
||||
GLdouble clip_plane[4];
|
||||
clip_plane[0] = plane.a();
|
||||
clip_plane[1] = plane.b();
|
||||
clip_plane[2] = plane.c();
|
||||
clip_plane[3] = plane.d();
|
||||
|
||||
for (C3t3::Facet_iterator
|
||||
fit = c3t3().facets_begin(),
|
||||
end = c3t3().facets_end();
|
||||
|
|
|
|||
|
|
@ -183,6 +183,7 @@ private:
|
|||
Sphere_radius,
|
||||
Sphere_center,
|
||||
Wired_spheres_vertices,
|
||||
iEdges_vertices,
|
||||
iFacet_vertices,
|
||||
iFacet_normals,
|
||||
iFacet_colors,
|
||||
|
|
@ -195,6 +196,7 @@ private:
|
|||
Grid,
|
||||
Spheres,
|
||||
Wired_spheres,
|
||||
iEdges,
|
||||
iFacets,
|
||||
NumberOfVaos
|
||||
};
|
||||
|
|
@ -218,6 +220,7 @@ private:
|
|||
PFNGLVERTEXATTRIBDIVISORARBPROC glVertexAttribDivisor;
|
||||
|
||||
mutable std::size_t positions_poly_size;
|
||||
mutable std::size_t positions_lines_size;
|
||||
mutable std::vector<float> positions_lines;
|
||||
mutable std::vector<float> positions_grid;
|
||||
mutable std::vector<float> positions_poly;
|
||||
|
|
|
|||
|
|
@ -474,6 +474,9 @@ void Viewer::attrib_buffers(int program_name) const {
|
|||
program->setUniformValue("spec_power", 51.8f);
|
||||
program->setUniformValue("is_two_side", is_both_sides);
|
||||
break;
|
||||
case PROGRAM_C3T3_EDGES:
|
||||
program->setUniformValue("mvp_matrix", mvp_mat);
|
||||
break;
|
||||
case PROGRAM_WITHOUT_LIGHT:
|
||||
program->setUniformValue("mvp_matrix", mvp_mat);
|
||||
program->setUniformValue("mv_matrix", mv_mat);
|
||||
|
|
@ -908,7 +911,7 @@ QOpenGLShaderProgram* Viewer::getShaderProgram(int name) const
|
|||
{
|
||||
std::cerr<<"adding vertex shader FAILED"<<std::endl;
|
||||
}
|
||||
if(!program->addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_with_light.f"))
|
||||
if(!program->addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_c3t3.f"))
|
||||
{
|
||||
std::cerr<<"adding fragment shader FAILED"<<std::endl;
|
||||
}
|
||||
|
|
@ -917,6 +920,29 @@ QOpenGLShaderProgram* Viewer::getShaderProgram(int name) const
|
|||
return program;
|
||||
}
|
||||
break;
|
||||
case PROGRAM_C3T3_EDGES:
|
||||
if(d->shader_programs[PROGRAM_C3T3_EDGES])
|
||||
{
|
||||
return d->shader_programs[PROGRAM_C3T3_EDGES];
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
QOpenGLShaderProgram *program = new QOpenGLShaderProgram(viewer);
|
||||
if(!program->addShaderFromSourceFile(QOpenGLShader::Vertex,":/cgal/Polyhedron_3/resources/shader_c3t3_edges.v"))
|
||||
{
|
||||
std::cerr<<"adding vertex shader FAILED"<<std::endl;
|
||||
}
|
||||
if(!program->addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_c3t3_edges.f"))
|
||||
{
|
||||
std::cerr<<"adding fragment shader FAILED"<<std::endl;
|
||||
}
|
||||
program->link();
|
||||
d->shader_programs[PROGRAM_C3T3_EDGES] = program;
|
||||
return program;
|
||||
}
|
||||
break;
|
||||
case PROGRAM_WITH_LIGHT:
|
||||
if(d->shader_programs[PROGRAM_WITH_LIGHT])
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
#version 120
|
||||
varying highp vec4 color;
|
||||
varying highp vec4 fP;
|
||||
varying highp vec3 fN;
|
||||
uniform highp vec4 light_pos;
|
||||
uniform highp vec4 light_diff;
|
||||
uniform highp vec4 light_spec;
|
||||
uniform highp vec4 light_amb;
|
||||
uniform highp float spec_power ;
|
||||
uniform int is_two_side;
|
||||
uniform bool is_selected;
|
||||
void main(void) {
|
||||
if(color.x>0)
|
||||
{
|
||||
highp vec3 L = light_pos.xyz - fP.xyz;
|
||||
highp vec3 V = -fP.xyz;
|
||||
highp vec3 N;
|
||||
if(fN == highp vec3(0.0,0.0,0.0))
|
||||
N = highp vec3(0.0,0.0,0.0);
|
||||
else
|
||||
N = normalize(fN);
|
||||
L = normalize(L);
|
||||
V = normalize(V);
|
||||
highp vec3 R = reflect(-L, N);
|
||||
vec4 diffuse;
|
||||
if(is_two_side == 1)
|
||||
diffuse = abs(dot(N,L)) * light_diff * color;
|
||||
else
|
||||
diffuse = max(dot(N,L), 0.0) * light_diff * color;
|
||||
highp vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec;
|
||||
vec4 ret_color = vec4((color*light_amb).xyz + diffuse.xyz + specular.xyz,1);
|
||||
if(is_selected)
|
||||
gl_FragColor = vec4(ret_color.r+70.0/255.0, ret_color.g+70.0/255.0, ret_color.b+70.0/255.0, 1.0);
|
||||
else
|
||||
gl_FragColor = ret_color;
|
||||
}
|
||||
else
|
||||
discard;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#version 120
|
||||
varying highp vec4 color;
|
||||
void main(void)
|
||||
{
|
||||
if(color.w>0)
|
||||
gl_FragColor = vec4(0,0,0,1.0);
|
||||
else
|
||||
discard;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#version 120
|
||||
attribute highp vec4 vertex;
|
||||
attribute highp vec3 colors;
|
||||
uniform highp mat4 mvp_matrix;
|
||||
uniform highp vec4 cutplane;
|
||||
varying highp vec4 color;
|
||||
void main(void)
|
||||
{
|
||||
if(vertex.x * cutplane.x + vertex.y * cutplane.y + vertex.z * cutplane.z + cutplane.w > 0)
|
||||
{
|
||||
color = vec4(0.0, 1.0, 1.0, 0.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
color = vec4(colors, 1.0);
|
||||
}
|
||||
gl_Position = mvp_matrix * vertex;
|
||||
}
|
||||
|
||||
|
|
@ -10,7 +10,6 @@ uniform highp float spec_power ;
|
|||
uniform int is_two_side;
|
||||
uniform bool is_selected;
|
||||
void main(void) {
|
||||
if(color.w > 0.0){
|
||||
highp vec3 L = light_pos.xyz - fP.xyz;
|
||||
highp vec3 V = -fP.xyz;
|
||||
highp vec3 N;
|
||||
|
|
@ -32,9 +31,6 @@ void main(void) {
|
|||
gl_FragColor = vec4(ret_color.r+70.0/255.0, ret_color.g+70.0/255.0, ret_color.b+70.0/255.0, 1.0);
|
||||
else
|
||||
gl_FragColor = ret_color;
|
||||
}else{
|
||||
discard;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ public:
|
|||
PROGRAM_INSTANCED,
|
||||
PROGRAM_INSTANCED_WIRE,
|
||||
PROGRAM_C3T3,
|
||||
PROGRAM_C3T3_EDGES,
|
||||
NB_OF_PROGRAMS };
|
||||
|
||||
typedef CGAL::Three::Scene_interface::Bbox Bbox;
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ public:
|
|||
PROGRAM_INSTANCED,
|
||||
PROGRAM_INSTANCED_WIRE,
|
||||
PROGRAM_C3T3,
|
||||
PROGRAM_C3T3_EDGES,
|
||||
NB_OF_PROGRAMS };
|
||||
|
||||
Viewer_interface(QWidget* parent) : QGLViewer(CGAL::Qt::createOpenGLContext(), parent) {}
|
||||
|
|
|
|||
Loading…
Reference in New Issue