Merge branch 'releases/CGAL-4.10-branch'

This commit is contained in:
Laurent Rineau 2017-06-16 11:45:45 +02:00
commit 01fc5c3b33
10 changed files with 273 additions and 221 deletions

View File

@ -25,6 +25,8 @@
// Tests if GMP is available.
#include <iostream>
#include <cstdio>
#include <cstddef>
#include "gmp.h"
int main()

View File

@ -25,6 +25,8 @@
// Tests if MPFR is available.
#include <iostream>
#include <cstdio>
#include <cstddef>
#include "mpfr.h"
int main()

View File

@ -10,5 +10,6 @@ int main() {
Nef_polyhedron N1(Nef_polyhedron::COMPLETE);
CGAL_assertion (N0 == N1.complement());
CGAL_assertion (N0 != N1);
return 0;
}

View File

@ -1416,6 +1416,10 @@ protected:
intersection(const Nef_polyhedron_3<Kernel,Items, Mark>& N1) const
/*{\Mop returns |\Mvar| $\cap$ |N1|. }*/ {
CGAL_NEF_TRACEN(" intersection between nef3 "<<&*this<<" and "<<&N1);
if (is_empty()) return *this;
if (N1.is_empty()) return N1;
if (is_space()) return N1;
if (N1.is_space()) return *this;
AND _and;
SNC_structure rsnc;
Nef_polyhedron_3<Kernel,Items, Mark> res(rsnc, new SNC_point_locator_default, false);
@ -1440,6 +1444,10 @@ protected:
join(const Nef_polyhedron_3<Kernel,Items, Mark>& N1) const
/*{\Mop returns |\Mvar| $\cup$ |N1|. }*/ {
CGAL_NEF_TRACEN(" join between nef3 "<<&*this<<" and "<<&N1);
if (is_empty()) return N1;
if (N1.is_empty()) return *this;
if (is_space()) return *this;
if (N1.is_space()) return N1;
OR _or;
//CGAL::binop_intersection_tests_allpairs<SNC_decorator, OR> tests_impl;
SNC_structure rsnc;
@ -1453,6 +1461,10 @@ protected:
difference(const Nef_polyhedron_3<Kernel,Items, Mark>& N1) const
/*{\Mop returns |\Mvar| $-$ |N1|. }*/ {
CGAL_NEF_TRACEN(" difference between nef3 "<<&*this<<" and "<<&N1);
if (is_empty()) return *this;
if (N1.is_empty()) return *this;
if (is_space()) return N1.complement();
if (N1.is_space()) return Nef_polyhedron_3(EMPTY);
DIFF _diff;
//CGAL::binop_intersection_tests_allpairs<SNC_decorator, DIFF> tests_impl;
SNC_structure rsnc;
@ -1467,6 +1479,10 @@ protected:
/*{\Mop returns the symmectric difference |\Mvar - T| $\cup$
|T - \Mvar|. }*/ {
CGAL_NEF_TRACEN(" symmetic difference between nef3 "<<&*this<<" and "<<&N1);
if (is_empty()) return N1;
if (N1.is_empty()) return *this;
if (is_space()) return Nef_polyhedron_3(EMPTY);
if (N1.is_space()) return Nef_polyhedron_3(EMPTY);
XOR _xor;
//CGAL::binop_intersection_tests_allpairs<SNC_decorator, XOR> tests_impl;
SNC_structure rsnc;

View File

@ -174,22 +174,27 @@ void Polyhedron_demo_point_set_shape_detection_plugin::on_actionDetect_triggered
// Shapes to be searched for are registered by using the template Shape_factory
if(dialog.detect_plane()){
groups[0] = new Scene_group_item("Planes");
groups[0]->setRenderingMode(Points);
shape_detection.add_shape_factory<CGAL::Shape_detection_3::Plane<Traits> >();
}
if(dialog.detect_cylinder()){
groups[1] = new Scene_group_item("Cylinders");
groups[1]->setRenderingMode(Points);
shape_detection.add_shape_factory<CGAL::Shape_detection_3::Cylinder<Traits> >();
}
if(dialog.detect_torus()){
groups[2] = new Scene_group_item("Torus");
groups[2]->setRenderingMode(Points);
shape_detection.add_shape_factory< CGAL::Shape_detection_3::Torus<Traits> >();
}
if(dialog.detect_cone()){
groups[3] = new Scene_group_item("Cones");
groups[3]->setRenderingMode(Points);
shape_detection.add_shape_factory< CGAL::Shape_detection_3::Cone<Traits> >();
}
if(dialog.detect_sphere()){
groups[4] = new Scene_group_item("Spheres");
groups[4]->setRenderingMode(Points);
shape_detection.add_shape_factory< CGAL::Shape_detection_3::Sphere<Traits> >();
}
@ -230,7 +235,6 @@ void Polyhedron_demo_point_set_shape_detection_plugin::on_actionDetect_triggered
}
Scene_points_with_normal_item *point_item = new Scene_points_with_normal_item;
point_item->point_set()->add_normal_map();
BOOST_FOREACH(std::size_t i, shape->indices_of_assigned_points())
point_item->point_set()->insert(points->point(*(points->begin()+i)));
@ -315,8 +319,8 @@ void Polyhedron_demo_point_set_shape_detection_plugin::on_actionDetect_triggered
}
else if (dynamic_cast<CGAL::Shape_detection_3::Plane<Traits> *>(shape.get()))
{
point_item->point_set()->add_normal_map();
CGAL::Shape_detection_3::Plane<Traits> * plane = dynamic_cast<CGAL::Shape_detection_3::Plane<Traits> *>(shape.get());
//set normals for point_item to the plane's normal
for(Point_set::iterator it = point_item->point_set()->begin(); it != point_item->point_set()->end(); ++it)
point_item->point_set()->normal(*it) = plane->plane_normal();

View File

@ -65,6 +65,14 @@ Polyhedron_demo::Polyhedron_demo(int& argc, char **argv,
mainWindow.setWindowTitle(main_window_title);
mainWindow.show();
// On Apple, the first time the application is launched, the menus are unclicable, and
// the only way you can fix it is to unfocus and re-focus the application.
// This is a hack that makes the application lose the focus after it is started, to force the user
// to re-focus it. (source : http://www.alecjacobson.com/weblog/?p=3910)
#ifdef __APPLE__
system("osascript -e 'tell application \"System Events\" "
"to keystroke tab using {command down, shift down}'");
#endif
if(parser.isSet(use_meta)) {
mainWindow.setAddKeyFrameKeyboardModifiers(::Qt::MetaModifier);
}

View File

@ -121,7 +121,7 @@ void Scene_group_item::moveUp(int i)
children.move(i, i-1);
}
void Scene_group_item::draw(CGAL::Three::Viewer_interface* viewer) const {
void Scene_group_item::draw(CGAL::Three::Viewer_interface* viewer) const {
if(viewer->inDrawWithNames() || already_drawn ) return;
Q_FOREACH(Scene_item* child, children) {
if(!child->visible()) continue;
@ -141,10 +141,13 @@ void Scene_group_item::draw(CGAL::Three::Viewer_interface* viewer) const {
}
switch(child->renderingMode()) {
case Points:
case ShadedPoints:
case PointsPlusNormals:
child->drawPoints(viewer); break;
default: break;
}
if(child->renderingMode() == Splatting)
child->drawSplats(viewer); break;
}
already_drawn = true;
}
@ -170,6 +173,7 @@ void Scene_group_item::drawEdges(CGAL::Three::Viewer_interface* viewer) const
}
switch(child->renderingMode()) {
case Points:
case ShadedPoints:
case PointsPlusNormals:
child->drawPoints(viewer); break;
default: break;
@ -185,6 +189,7 @@ void Scene_group_item::drawPoints(CGAL::Three::Viewer_interface* viewer) const
if(!child->visible()) continue;
switch(child->renderingMode()) {
case Points:
case ShadedPoints:
case PointsPlusNormals:
child->drawPoints(viewer); break;
default: break;

View File

@ -99,7 +99,9 @@ struct Scene_points_with_normal_item_priv
enum VAOs {
Edges=0,
ThePoints,
TheShadedPoints,
Selected_points,
Selected_shaded_points,
NbOfVaos
};
enum VBOs {
@ -119,8 +121,6 @@ struct Scene_points_with_normal_item_priv
QSlider* point_Slider;
mutable bool is_point_slider_moving;
mutable std::vector<CGAL_data_type> positions_lines;
mutable std::vector<CGAL_data_type> positions_points;
mutable std::vector<CGAL_data_type> positions_selected_points;
mutable std::vector<CGAL_data_type> normals;
mutable std::vector<CGAL_data_type> positions_normals;
mutable std::vector<CGAL_data_type> positions_selected_normals;
@ -185,6 +185,7 @@ void Scene_points_with_normal_item_priv::initializeBuffers(CGAL::Three::Viewer_i
{
compute_normals_and_vertices();
//vao for the edges
if(item->has_normals())
{
program = item->getShaderProgram(Scene_points_with_normal_item::PROGRAM_NO_SELECTION, viewer);
program->bind();
@ -208,38 +209,28 @@ void Scene_points_with_normal_item_priv::initializeBuffers(CGAL::Three::Viewer_i
}
item->vaos[Edges]->release();
nb_lines = positions_lines.size();
positions_lines.resize(0);
std::vector<CGAL_data_type>(positions_lines).swap(positions_lines);
program->release();
}
//vao for the points
{
if(item->has_normals() && !(m_points->has_colors()))
program = item->getShaderProgram(Scene_points_with_normal_item::PROGRAM_WITH_LIGHT, viewer);
else
program = item->getShaderProgram(Scene_points_with_normal_item::PROGRAM_NO_SELECTION, viewer);
program = item->getShaderProgram(Scene_points_with_normal_item::PROGRAM_NO_SELECTION, viewer);
program->bind();
item->vaos[ThePoints]->bind();
item->buffers[Points_vertices].bind();
item->buffers[Points_vertices].allocate(positions_points.data(),
static_cast<int>(positions_points.size()*sizeof(CGAL_data_type)));
program->enableAttributeArray("vertex");
program->setAttributeBuffer("vertex",CGAL_GL_data_type,0,3);
item->buffers[Points_vertices].release();
if(item->has_normals() && !(m_points->has_colors()))
{
item->buffers[Points_normals].bind();
item->buffers[Points_normals].allocate(positions_normals.data(),
static_cast<int>(positions_normals.size()*sizeof(CGAL_data_type)));
program->enableAttributeArray("normals");
program->setAttributeBuffer("normals",CGAL_GL_data_type,0,3);
item->buffers[Points_normals].release();
positions_normals.resize(0);
std::vector<CGAL_data_type>(positions_normals).swap(positions_normals);
item->buffers[Edges_vertices].bind();
if(!item->has_normals()) {
item->buffers[Edges_vertices].allocate(positions_lines.data(),
static_cast<int>(positions_lines.size()*sizeof(CGAL_data_type)));
}
program->enableAttributeArray("vertex");
if(item->has_normals())
program->setAttributeBuffer("vertex",CGAL_GL_data_type,0,3,
static_cast<int>(6*sizeof(CGAL_GL_data_type)));
else
program->setAttributeBuffer("vertex",CGAL_GL_data_type,0,3);
item->buffers[Edges_vertices].release();
if (!(colors_points.empty()))
{
item->buffers[Points_colors].bind();
@ -253,43 +244,88 @@ void Scene_points_with_normal_item_priv::initializeBuffers(CGAL::Three::Viewer_i
}
item->vaos[ThePoints]->release();
nb_points = positions_points.size();
positions_points.resize(0);
std::vector<CGAL_data_type>(positions_points).swap(positions_points);
program->release();
if(item->has_normals())
{
program = item->getShaderProgram(Scene_points_with_normal_item::PROGRAM_WITH_LIGHT, viewer);
item->vaos[TheShadedPoints]->bind();
item->buffers[Edges_vertices].bind();
program->enableAttributeArray("vertex");
program->setAttributeBuffer("vertex",CGAL_GL_data_type,0,3,
static_cast<int>(6*sizeof(CGAL_GL_data_type)));
item->buffers[Edges_vertices].release();
item->buffers[Points_normals].bind();
item->buffers[Points_normals].allocate(positions_normals.data(),
static_cast<int>(positions_normals.size()*sizeof(CGAL_data_type)));
program->enableAttributeArray("normals");
program->setAttributeBuffer("normals",CGAL_GL_data_type,0,3);
item->buffers[Points_normals].release();
positions_normals.resize(0);
std::vector<CGAL_data_type>(positions_normals).swap(positions_normals);
item->vaos[TheShadedPoints]->release();
program->release();
}
if(item->has_normals())
nb_points = positions_lines.size()/2;
else
nb_points = positions_lines.size();
}
//vao for the selected points
{
if(item->has_normals())
program = item->getShaderProgram(Scene_points_with_normal_item::PROGRAM_WITH_LIGHT, viewer);
else
program = item->getShaderProgram(Scene_points_with_normal_item::PROGRAM_NO_SELECTION, viewer);
program->bind();
item->vaos[Selected_points]->bind();
item->buffers[Selected_points_vertices].bind();
item->buffers[Selected_points_vertices].allocate(positions_selected_points.data(),
static_cast<int>(positions_selected_points.size()*sizeof(CGAL_data_type)));
program->enableAttributeArray("vertex");
program->setAttributeBuffer("vertex",CGAL_GL_data_type,0,3);
item->buffers[Selected_points_vertices].release();
program = item->getShaderProgram(Scene_points_with_normal_item::PROGRAM_NO_SELECTION, viewer);
program->bind();
if(item->has_normals())
{
item->buffers[Selected_points_normals].bind();
item->buffers[Selected_points_normals].allocate(positions_selected_normals.data(),
static_cast<int>(positions_selected_normals.size()*sizeof(CGAL_data_type)));
program->enableAttributeArray("normals");
program->setAttributeBuffer("normals",CGAL_GL_data_type,0,3);
item->buffers[Selected_points_normals].release();
positions_selected_normals.resize(0);
std::vector<CGAL_data_type>(positions_selected_normals).swap(positions_selected_normals);
}
item->vaos[Selected_points]->release();
nb_selected_points = positions_selected_points.size();
positions_selected_points.resize(0);
std::vector<CGAL_data_type>(positions_selected_points).swap(positions_selected_points);
item->vaos[Selected_points]->bind();
item->buffers[Edges_vertices].bind();
program->enableAttributeArray("vertex");
if(!item->has_normals())
{
program->setAttributeBuffer("vertex",CGAL_GL_data_type,
static_cast<int>( 3*(m_points->size()-m_points->nb_selected_points())*sizeof(CGAL_data_type) ),
3,
0);
}
else
{
program->setAttributeBuffer("vertex",CGAL_GL_data_type,
static_cast<int>( 6*(m_points->size()-m_points->nb_selected_points())*sizeof(CGAL_data_type) ),
3,
static_cast<int>(6*sizeof(CGAL_GL_data_type)));
}
item->buffers[Edges_vertices].release();
item->vaos[Selected_points]->release();
program->release();
if(item->has_normals())
{
program = item->getShaderProgram(Scene_points_with_normal_item::PROGRAM_WITH_LIGHT, viewer);
item->vaos[Selected_shaded_points]->bind();
item->buffers[Edges_vertices].bind();
program->enableAttributeArray("vertex");
program->setAttributeBuffer("vertex",CGAL_GL_data_type,
static_cast<int>( 6*(m_points->size()-m_points->nb_selected_points())*sizeof(CGAL_data_type) ),
3,
static_cast<int>(6*sizeof(CGAL_GL_data_type)));
item->buffers[Edges_vertices].release();
item->buffers[Selected_points_normals].bind();
item->buffers[Selected_points_normals].allocate(positions_selected_normals.data(),
static_cast<int>(positions_selected_normals.size()*sizeof(CGAL_data_type)));
program->enableAttributeArray("normals");
program->setAttributeBuffer("normals",CGAL_GL_data_type,0,3);
item->buffers[Selected_points_normals].release();
positions_selected_normals.resize(0);
std::vector<CGAL_data_type>(positions_selected_normals).swap(positions_selected_normals);
item->vaos[Selected_shaded_points]->release();
program->release();
}
nb_selected_points = 3*m_points->nb_selected_points();
}
positions_lines.resize(0);
positions_lines.shrink_to_fit();
item->are_buffers_filled = true;
}
@ -297,103 +333,86 @@ void Scene_points_with_normal_item_priv::compute_normals_and_vertices() const
{
const qglviewer::Vec offset = static_cast<CGAL::Three::Viewer_interface*>(QGLViewer::QGLViewerPool().first())->offset();
QApplication::setOverrideCursor(Qt::WaitCursor);
positions_points.resize(0);
positions_lines.resize(0);
positions_selected_points.resize(0);
normals.resize(0);
positions_normals.resize(0);
positions_selected_normals.resize(0);
normals.resize(0);
colors_points.resize(0);
positions_points.reserve(m_points->size() * 3);
positions_lines.reserve(m_points->size() * 3 * 2);
//Shuffle container to allow quick display random points
std::random_shuffle (m_points->begin(), m_points->first_selected());
if (m_points->nb_selected_points() != 0)
std::random_shuffle (m_points->first_selected(), m_points->end());
//The points
{
// The *non-selected* points
for (Point_set::const_iterator it = m_points->begin();
it != m_points->first_selected(); ++ it)
{
positions_points.push_back(m_points->point(*it).x()+offset.x);
positions_points.push_back(m_points->point(*it).y()+offset.y);
positions_points.push_back(m_points->point(*it).z()+offset.z);
}
// Draw *selected* points
for (Point_set::const_iterator it = m_points->first_selected();
it != m_points->end(); ++ it)
{
positions_selected_points.push_back(m_points->point(*it).x()+offset.x);
positions_selected_points.push_back(m_points->point(*it).y()+offset.y);
positions_selected_points.push_back(m_points->point(*it).z()+offset.z);
}
}
//The lines
//if item has normals, points will be one point out of two in the lines data.
//else points will be lines and lines discarded.
double average_spacing = 0;
double normal_length =0;
double length_factor =0;
if (item->has_normals())
{
positions_lines.reserve(m_points->size() * 6);
positions_normals.reserve((m_points->size() - m_points->nb_selected_points()) * 3);
positions_selected_normals.reserve(m_points->nb_selected_points() * 3);
// Store normals
Kernel::Sphere_3 region_of_interest = m_points->region_of_interest();
#ifdef LINK_WITH_TBB
typedef CGAL::Parallel_tag Concurrency_tag;
typedef CGAL::Parallel_tag Concurrency_tag;
#else
typedef CGAL::Sequential_tag Concurrency_tag;
typedef CGAL::Sequential_tag Concurrency_tag;
#endif
double average_spacing = CGAL::compute_average_spacing<Concurrency_tag>(
m_points->begin(), m_points->end(), m_points->point_map(),
6);
double normal_length = (std::min)(average_spacing, std::sqrt(region_of_interest.squared_radius() / 1000.));
double length_factor = 5.0/100*normal_Slider->value();
for (Point_set_3<Kernel>::const_iterator it = m_points->begin(); it != m_points->first_selected(); ++it)
{
const Kernel::Point_3& p = m_points->point(*it);
const Kernel::Vector_3& n = m_points->normal(*it);
Point_set_3<Kernel>::Point q = p + normal_length * length_factor* n;
positions_lines.push_back(p.x()+offset.x);
positions_lines.push_back(p.y()+offset.y);
positions_lines.push_back(p.z()+offset.z);
positions_lines.push_back(q.x()+offset.x);
positions_lines.push_back(q.y()+offset.y);
positions_lines.push_back(q.z()+offset.z);
// Store normals
Kernel::Sphere_3 region_of_interest = m_points->region_of_interest();
positions_lines.reserve(m_points->size() * 6);
positions_normals.reserve((m_points->size() - m_points->nb_selected_points()) * 3);
positions_selected_normals.reserve(m_points->nb_selected_points() * 3);
average_spacing = CGAL::compute_average_spacing<Concurrency_tag>(
m_points->begin(), m_points->end(), m_points->point_map(),
6);
normal_length = (std::min)(average_spacing, std::sqrt(region_of_interest.squared_radius() / 1000.));
length_factor = 5.0/100*normal_Slider->value();
}
else
{
positions_lines.reserve(m_points->size() * 3);
}
positions_normals.push_back(n.x());
positions_normals.push_back(n.y());
positions_normals.push_back(n.z());
}
for (Point_set_3<Kernel>::const_iterator it = m_points->first_selected(); it != m_points->end(); ++it)
{
const Kernel::Point_3& p = m_points->point(*it);
const Kernel::Vector_3& n = m_points->normal(*it);
Point_set_3<Kernel>::Point q = p + normal_length * length_factor* n;
positions_lines.push_back(p.x()+offset.x);
positions_lines.push_back(p.y()+offset.y);
positions_lines.push_back(p.z()+offset.z);
positions_lines.push_back(q.x()+offset.x);
positions_lines.push_back(q.y()+offset.y);
positions_lines.push_back(q.z()+offset.z);
for (Point_set_3<Kernel>::const_iterator it = m_points->begin(); it != m_points->first_selected(); ++it)
{
const Kernel::Point_3& p = m_points->point(*it);
positions_lines.push_back(p.x()+offset.x);
positions_lines.push_back(p.y()+offset.y);
positions_lines.push_back(p.z()+offset.z);
if(item->has_normals())
{
const Kernel::Vector_3& n = m_points->normal(*it);
Point_set_3<Kernel>::Point q = p + normal_length * length_factor* n;
positions_lines.push_back(q.x()+offset.x);
positions_lines.push_back(q.y()+offset.y);
positions_lines.push_back(q.z()+offset.z);
positions_selected_normals.push_back(n.x());
positions_selected_normals.push_back(n.y());
positions_selected_normals.push_back(n.z());
}
positions_normals.push_back(n.x());
positions_normals.push_back(n.y());
positions_normals.push_back(n.z());
}
}
for (Point_set_3<Kernel>::const_iterator it = m_points->first_selected(); it != m_points->end(); ++it)
{
const Kernel::Point_3& p = m_points->point(*it);
positions_lines.push_back(p.x()+offset.x);
positions_lines.push_back(p.y()+offset.y);
positions_lines.push_back(p.z()+offset.z);
if(item->has_normals())
{
const Kernel::Vector_3& n = m_points->normal(*it);
Point_set_3<Kernel>::Point q = p + normal_length * length_factor* n;
positions_lines.push_back(q.x()+offset.x);
positions_lines.push_back(q.y()+offset.y);
positions_lines.push_back(q.z()+offset.z);
positions_selected_normals.push_back(n.x());
positions_selected_normals.push_back(n.y());
positions_selected_normals.push_back(n.z());
}
}
//The colors
if (m_points->has_colors())
@ -673,34 +692,44 @@ void Scene_points_with_normal_item::drawPoints(CGAL::Three::Viewer_interface* vi
if ((viewer->inFastDrawing () || d->isPointSliderMoving())
&&((d->nb_points + d->nb_selected_points)/3 > limit_fast_drawing)) // arbitrary large value
ratio_displayed = 3 * limit_fast_drawing / (double)(d->nb_points + d->nb_selected_points);
vaos[Scene_points_with_normal_item_priv::ThePoints]->bind();
// POINTS
if(has_normals() && renderingMode() == ShadedPoints)
{
vaos[Scene_points_with_normal_item_priv::TheShadedPoints]->bind();
d->program=getShaderProgram(PROGRAM_WITH_LIGHT);
attribBuffers(viewer,PROGRAM_WITH_LIGHT);
}
else
{
vaos[Scene_points_with_normal_item_priv::ThePoints]->bind();
d->program=getShaderProgram(PROGRAM_NO_SELECTION);
attribBuffers(viewer,PROGRAM_NO_SELECTION);
}
d->program->bind();
if (!(d->m_points->has_colors()))
if (!(d->m_points->has_colors()) || renderingMode() == ShadedPoints)
d->program->setAttributeValue("colors", this->color());
if(renderingMode() != ShadedPoints)
d->program->setAttributeValue("normals", QVector3D(0,0,0));
viewer->glDrawArrays(GL_POINTS, 0,
static_cast<GLsizei>(((std::size_t)(ratio_displayed * d->nb_points)/3)));
vaos[Scene_points_with_normal_item_priv::ThePoints]->release();
if(has_normals() && renderingMode() == ShadedPoints)
vaos[Scene_points_with_normal_item_priv::TheShadedPoints]->release();
else
vaos[Scene_points_with_normal_item_priv::ThePoints]->release();
d->program->release();
// SELECTED POINTS
vaos[Scene_points_with_normal_item_priv::Selected_points]->bind();
if(has_normals() && renderingMode() == ShadedPoints)
{
vaos[Scene_points_with_normal_item_priv::Selected_shaded_points]->bind();
d->program=getShaderProgram(PROGRAM_WITH_LIGHT);
attribBuffers(viewer,PROGRAM_WITH_LIGHT);
}
else
{
vaos[Scene_points_with_normal_item_priv::Selected_points]->bind();
d->program=getShaderProgram(PROGRAM_NO_SELECTION);
attribBuffers(viewer,PROGRAM_NO_SELECTION);
}
@ -708,7 +737,11 @@ void Scene_points_with_normal_item::drawPoints(CGAL::Three::Viewer_interface* vi
d->program->setAttributeValue("colors", QColor(255,0,0));
viewer->glDrawArrays(GL_POINTS, 0,
static_cast<GLsizei>(((std::size_t)(ratio_displayed * d->nb_selected_points)/3)));
vaos[Scene_points_with_normal_item_priv::Selected_points]->release();
if(has_normals() && renderingMode() == ShadedPoints)
vaos[Scene_points_with_normal_item_priv::Selected_shaded_points]->bind();
else
vaos[Scene_points_with_normal_item_priv::Selected_points]->release();
d->program->release();
viewer->glPointSize(point_size);
}

View File

@ -261,10 +261,7 @@ void Viewer::initializeGL()
"attribute highp vec3 normal;\n"
"attribute highp vec4 colors;\n"
"uniform highp mat4 mvp_matrix;\n"
"uniform highp mat4 ortho_mat;\n"
"uniform highp mat4 mv_matrix; \n"
"uniform highp float width; \n"
"uniform highp float height; \n"
"varying highp vec4 fP; \n"
"varying highp vec3 fN; \n"
"varying highp vec4 color; \n"
@ -273,10 +270,7 @@ void Viewer::initializeGL()
" color = colors; \n"
" fP = mv_matrix * vertex; \n"
" fN = mat3(mv_matrix)* normal; \n"
" vec4 temp = vec4(mvp_matrix * vertex); \n"
" vec4 ort = ortho_mat * vec4(width-150, height-150, 0,0); \n"
" float ratio = width/height; \n"
" gl_Position = ort +vec4(temp.x, temp.y, temp.z, 1.0); \n"
" gl_Position = vec4(mvp_matrix * vertex); \n"
"} \n"
"\n"
};
@ -333,6 +327,7 @@ void Viewer::initializeGL()
{
std::cerr<<"adding fragment shader FAILED"<<std::endl;
}
d->rendering_program.bindAttributeLocation("colors", 1);
if(!d->rendering_program.link())
{
//std::cerr<<"linking Program FAILED"<<std::endl;
@ -389,6 +384,41 @@ void Viewer::initializeGL()
}
}
Viewer_impl::AxisData data;
d->v_Axis.resize(0);
d->n_Axis.resize(0);
d->c_Axis.resize(0);
data.vertices = &d->v_Axis;
data.normals = &d->n_Axis;
data.colors = &d->c_Axis;
GLdouble l = 1.0;
d->makeArrow(0.06,10, qglviewer::Vec(0,0,0),qglviewer::Vec(l,0,0),qglviewer::Vec(1,0,0), data);
d->makeArrow(0.06,10, qglviewer::Vec(0,0,0),qglviewer::Vec(0,l,0),qglviewer::Vec(0,1,0), data);
d->makeArrow(0.06,10, qglviewer::Vec(0,0,0),qglviewer::Vec(0,0,l),qglviewer::Vec(0,0,1), data);
d->rendering_program.bind();
d->vao[0].bind();
d->buffers[0].bind();
d->buffers[0].allocate(d->v_Axis.data(), static_cast<int>(d->v_Axis.size()) * sizeof(float));
d->rendering_program.enableAttributeArray("vertex");
d->rendering_program.setAttributeBuffer("vertex",GL_FLOAT,0,3);
d->buffers[0].release();
d->buffers[1].bind();
d->buffers[1].allocate(d->n_Axis.data(), static_cast<int>(d->n_Axis.size() * sizeof(float)));
d->rendering_program.enableAttributeArray("normal");
d->rendering_program.setAttributeBuffer("normal",GL_FLOAT,0,3);
d->buffers[1].release();
d->buffers[2].bind();
d->buffers[2].allocate(d->c_Axis.data(), static_cast<int>(d->c_Axis.size() * sizeof(float)));
d->rendering_program.enableAttributeArray("colors");
d->rendering_program.setAttributeBuffer("colors",GL_FLOAT,0,3);
d->buffers[2].release();
d->vao[0].release();
d->rendering_program.release();
d->painter = new QPainter(this);
}
@ -937,24 +967,17 @@ void Viewer::drawVisualHints()
QGLViewer::drawVisualHints();
if(d->axis_are_displayed)
{
d->rendering_program.bind();
SetOrthoProjection(true);
QMatrix4x4 mvpMatrix;
double mat[16];
QMatrix4x4 mvMatrix;
camera()->getModelViewProjectionMatrix(mat);
//nullifies the translation
mat[12]=0;
mat[13]=0;
mat[14]=0;
for(int i=0; i < 16; i++)
{
mvpMatrix.data()[i] = (float)mat[i];
mvMatrix.data()[i] = camera()->orientation().inverse().matrix()[i];
}
camera()->getModelViewMatrix(mat);
for(int i=0; i < 16; i++)
{
mvMatrix.data()[i] = (float)mat[i];
}
mvpMatrix.ortho(-1,1,-1,1,-1,1);
mvpMatrix = mvpMatrix*mvMatrix;
SetOrthoProjection(false);
QVector4D position(0.0f,0.0f,1.0f,1.0f );
// define material
QVector4D ambient;
@ -979,7 +1002,6 @@ void Viewer::drawVisualHints()
// Shininess
shininess = 51.2f;
d->rendering_program.bind();
d->rendering_program.setUniformValue("light_pos", position);
d->rendering_program.setUniformValue("mvp_matrix", mvpMatrix);
d->rendering_program.setUniformValue("mv_matrix", mvMatrix);
@ -987,13 +1009,26 @@ void Viewer::drawVisualHints()
d->rendering_program.setUniformValue("light_spec", specular);
d->rendering_program.setUniformValue("light_amb", ambient);
d->rendering_program.setUniformValue("spec_power", shininess);
d->rendering_program.release();
d->vao[0].bind();
d->rendering_program.bind();
int viewport[4];
int scissor[4];
// The viewport and the scissor are changed to fit the upper right
// corner. Original values are saved.
glGetIntegerv(GL_VIEWPORT, viewport);
glGetIntegerv(GL_SCISSOR_BOX, scissor);
// Axis viewport size, in pixels
const int size = 100;
glViewport(width()*devicePixelRatio()-size, height()*devicePixelRatio()-size, size, size);
glScissor (width()*devicePixelRatio()-size, height()*devicePixelRatio()-size, size, size);
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(d->v_Axis.size() / 3));
d->rendering_program.release();
// The viewport and the scissor are restored.
glScissor(scissor[0],scissor[1],scissor[2],scissor[3]);
glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);
d->vao[0].release();
d->rendering_program.release();
}
if(d->distance_is_displayed)
@ -1054,63 +1089,6 @@ void Viewer::drawVisualHints()
void Viewer::resizeGL(int w, int h)
{
QGLViewer::resizeGL(w,h);
qglviewer::Vec dim = qglviewer::Vec(w,h, 0) ;
GLdouble ortho[16];
QMatrix4x4 orthoMatrix;
ortho[0] = 1.0/width(); ortho[1] = 0; ortho[2] = 0; ortho[3] = -0.0;
ortho[4] = 0; ortho[5] = 1.0/height(); ortho[6] = 0; ortho[7] = -0.0;
ortho[8] = 0; ortho[9] = 0; ortho[10] = 2.0/(camera()->zNear()-camera()->zFar()); ortho[11] = -(camera()->zNear()+camera()->zFar())/(-camera()->zNear()+camera()->zFar());
ortho[12] = 0; ortho[13] = 0; ortho[14] = 0; ortho[15] = 1;
for(int i=0; i < 16; i++)
{
orthoMatrix.data()[i] = (float)ortho[i];
}
QVector4D length(60,60,60, 1.0);
length = orthoMatrix * length;
Viewer_impl::AxisData data;
d->v_Axis.resize(0);
d->n_Axis.resize(0);
d->c_Axis.resize(0);
data.vertices = &d->v_Axis;
data.normals = &d->n_Axis;
data.colors = &d->c_Axis;
double l = length.x()*w/h;
d->makeArrow(0.06,10, qglviewer::Vec(0,0,0),qglviewer::Vec(l,0,0),qglviewer::Vec(1,0,0), data);
d->makeArrow(0.06,10, qglviewer::Vec(0,0,0),qglviewer::Vec(0,l,0),qglviewer::Vec(0,1,0), data);
d->makeArrow(0.06,10, qglviewer::Vec(0,0,0),qglviewer::Vec(0,0,l),qglviewer::Vec(0,0,1), data);
d->vao[0].bind();
d->buffers[0].bind();
d->buffers[0].allocate(d->v_Axis.data(), static_cast<int>(d->v_Axis.size()) * sizeof(float));
d->rendering_program.enableAttributeArray("vertex");
d->rendering_program.setAttributeBuffer("vertex",GL_FLOAT,0,3);
d->buffers[0].release();
d->buffers[1].bind();
d->buffers[1].allocate(d->n_Axis.data(), static_cast<int>(d->n_Axis.size() * sizeof(float)));
d->rendering_program.enableAttributeArray("normal");
d->rendering_program.setAttributeBuffer("normal",GL_FLOAT,0,3);
d->buffers[1].release();
d->buffers[2].bind();
d->buffers[2].allocate(d->c_Axis.data(), static_cast<int>(d->c_Axis.size() * sizeof(float)));
d->rendering_program.enableAttributeArray("colors");
d->rendering_program.setAttributeBuffer("colors",GL_FLOAT,0,3);
d->buffers[2].release();
d->rendering_program.release();
d->vao[0].release();
d->rendering_program.bind();
d->rendering_program.setUniformValue("width", (float)dim.x);
d->rendering_program.setUniformValue("height", (float)dim.y);
d->rendering_program.setUniformValue("ortho_mat", orthoMatrix);
d->rendering_program.release();
}
QOpenGLShaderProgram* Viewer::declare_program(int name,
const char* v_shader,

View File

@ -27,6 +27,9 @@
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stdexcept>
#include <boost/array.hpp>