diff options
author | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2015-10-08 21:15:51 +0000 |
---|---|---|
committer | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2015-10-08 21:15:51 +0000 |
commit | cd2e83819689afd2cd1bc76810282111cf5cd59d (patch) | |
tree | 8cf97b1f5a8589fa160d03248ca3f429b436b814 /src/GudhUI/view | |
parent | 58e633f51ffa06aa219231cd1c08eab59457a12f (diff) |
cpplint fixes on GudhUI
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@844 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: 3acf1e789f3e4bded974f324ce3161bc1d1d2433
Diffstat (limited to 'src/GudhUI/view')
-rw-r--r-- | src/GudhUI/view/Color.h | 42 | ||||
-rw-r--r-- | src/GudhUI/view/FirstCoordProjector.h | 44 | ||||
-rw-r--r-- | src/GudhUI/view/Projector3D.h | 47 | ||||
-rw-r--r-- | src/GudhUI/view/View_parameter.h | 264 | ||||
-rw-r--r-- | src/GudhUI/view/Viewer.cpp | 303 | ||||
-rw-r--r-- | src/GudhUI/view/Viewer.h | 129 | ||||
-rw-r--r-- | src/GudhUI/view/Viewer_instructor.cpp | 272 | ||||
-rw-r--r-- | src/GudhUI/view/Viewer_instructor.h | 149 |
8 files changed, 654 insertions, 596 deletions
diff --git a/src/GudhUI/view/Color.h b/src/GudhUI/view/Color.h index a63456cb..ba0592e1 100644 --- a/src/GudhUI/view/Color.h +++ b/src/GudhUI/view/Color.h @@ -1,21 +1,35 @@ -/* - * Color.h +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. * - * Created on: Aug 26, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * */ -#ifndef COLOR_H_ -#define COLOR_H_ - +#ifndef VIEW_COLOR_H_ +#define VIEW_COLOR_H_ +struct Color { + double r; + double g; + double b; -struct Color{ - double r; - double g; - double b; - Color(double r_,double g_,double b_):r(r_),g(g_),b(b_){} + Color(double r_, double g_, double b_) : r(r_), g(g_), b(b_) { } }; - -#endif /* COLOR_H_ */ +#endif // VIEW_COLOR_H_ diff --git a/src/GudhUI/view/FirstCoordProjector.h b/src/GudhUI/view/FirstCoordProjector.h index 2659eef1..529d2d42 100644 --- a/src/GudhUI/view/FirstCoordProjector.h +++ b/src/GudhUI/view/FirstCoordProjector.h @@ -1,24 +1,40 @@ -/* - * FirstCoordProjector.h +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. * - * Created on: Aug 27, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * */ -#ifndef FIRSTCOORDPROJECTOR_H_ -#define FIRSTCOORDPROJECTOR_H_ +#ifndef VIEW_FIRSTCOORDPROJECTOR_H_ +#define VIEW_FIRSTCOORDPROJECTOR_H_ #include "utils/UI_utils.h" #include "Projector3D.h" -class FirstCoordProjector3D : public Projector3D{ - typedef Projector3D::Point Point; - typedef Projector3D::Point_3 Point_3; +class FirstCoordProjector3D : public Projector3D { + typedef Projector3D::Point Point; + typedef Projector3D::Point_3 Point_3; - Point_3 operator()(const Point& p) const{ - assert(p.dimension()>=3); - return Point_3(p.x(),p.y(),p.z()); - } + Point_3 operator()(const Point& p) const { + assert(p.dimension() >= 3); + return Point_3(p.x(), p.y(), p.z()); + } }; -#endif /* FIRSTCOORDPROJECTOR_H_ */ +#endif // VIEW_FIRSTCOORDPROJECTOR_H_ diff --git a/src/GudhUI/view/Projector3D.h b/src/GudhUI/view/Projector3D.h index 503b35c5..2a756541 100644 --- a/src/GudhUI/view/Projector3D.h +++ b/src/GudhUI/view/Projector3D.h @@ -1,28 +1,39 @@ -/* - * Projector.h +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. * - * Created on: Aug 27, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * */ -#ifndef PROJECTOR3D_H_ -#define PROJECTOR3D_H_ +#ifndef VIEW_PROJECTOR3D_H_ +#define VIEW_PROJECTOR3D_H_ #include "model/Complex_typedefs.h" +class Projector3D { + public: + typedef Geometry_trait::Point Point; + typedef Geometry_trait::Point_3 Point_3; -class Projector3D{ -public: - typedef Geometry_trait::Point Point; - typedef Geometry_trait::Point_3 Point_3; - - virtual Point_3 operator()(const Point&) const = 0; - - virtual ~Projector3D(){ - } + virtual Point_3 operator()(const Point&) const = 0; + virtual ~Projector3D() { } }; - - -#endif /* PROJECTOR3D_H_ */ +#endif // VIEW_PROJECTOR3D_H_ diff --git a/src/GudhUI/view/View_parameter.h b/src/GudhUI/view/View_parameter.h index 39c5d7dd..9805abc2 100644 --- a/src/GudhUI/view/View_parameter.h +++ b/src/GudhUI/view/View_parameter.h @@ -1,13 +1,28 @@ -/* - * View_parameter.h +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. * - * Created on: Mar 10, 2014 - * Author: David Salinas - * Copyright 2013 INRIA. All rights reserved + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * */ -#ifndef VIEW_PARAMETER_H_ -#define VIEW_PARAMETER_H_ +#ifndef VIEW_VIEW_PARAMETER_H_ +#define VIEW_VIEW_PARAMETER_H_ #include <iostream> @@ -15,123 +30,122 @@ * Different parameters for the view such as the camera angle, * the light, options for vertices/edges/triangles. */ -class View_parameter{ -public: - bool light; - bool relative_light; - - double size_vertices; - double size_edges; - double light_edges; // in 0-1 - double light_triangles;// in 0-1 - - /** - * light angle - */ - double theta; - double phi; - - enum VERTEX_MODE{ V_NONE,V_SIMPLE,V_COUNT}; - enum EDGE_MODE{ E_NONE,E_SIMPLE,E_COUNT}; - enum TRIANGLE_MODE{ T_NONE,T_SIMPLE,T_COUNT}; - - - - - VERTEX_MODE vertex_mode; - EDGE_MODE edge_mode; - TRIANGLE_MODE triangle_mode; - - void change_vertex_mode(){ - int current_value = vertex_mode; - vertex_mode = static_cast<VERTEX_MODE>(++current_value % V_COUNT); - std::cout<<"Vertex mode : "; - switch (vertex_mode) { - case V_NONE: - std::cout<<"empty\n"; - break; - case V_SIMPLE: - std::cout<<"simple\n"; - break; - default: - break; - } - } - - void change_vertex_mode(int new_mode){ - vertex_mode = static_cast<VERTEX_MODE>(new_mode % V_COUNT); - } - - void change_edge_mode(){ - int current_value = edge_mode; - edge_mode = static_cast<EDGE_MODE>(++current_value % E_COUNT); - } - - void change_edge_mode(int new_mode){ - edge_mode = static_cast<EDGE_MODE>(new_mode % E_COUNT); - } - - - void change_triangle_mode(){ - int current_value = triangle_mode; - triangle_mode = static_cast<TRIANGLE_MODE>(++current_value % T_COUNT); - } - - - - - - View_parameter(){ - light = true; - relative_light = true; - vertex_mode = V_SIMPLE; - edge_mode = E_SIMPLE; - triangle_mode = T_NONE; - - size_vertices = 3; - size_edges = 2; - - light_edges = 0.3; - light_triangles = 0.85; - theta = 0; - phi = 0; - } - - friend std::ostream& operator<<(std::ostream& stream, const View_parameter& param){ - stream << param.light<< " "; - stream << param.relative_light<< " "; - stream << param.vertex_mode<< " "; - stream << param.edge_mode<< " "; - stream << param.triangle_mode<< " "; - stream << param.size_vertices<< " "; - stream << param.size_edges<< " "; - stream << param.light_edges<< " "; - stream << param.light_triangles<< " "; - stream << param.theta<< " "; - stream << param.phi<< " "; - return stream; - } - - friend std::istream& operator>>(std::istream& stream, View_parameter& param){ - stream >> param.light; - stream >> param.relative_light; - int a; - stream>>a; - param.vertex_mode = static_cast<VERTEX_MODE>(a % V_COUNT); - stream>>a; - param.edge_mode = static_cast<EDGE_MODE>(a % E_COUNT); - stream>>a; - param.triangle_mode = static_cast<TRIANGLE_MODE>(a % T_COUNT); - stream>>a; - stream >> param.size_vertices; - stream >> param.size_edges; - stream >> param.light_edges; - stream >> param.light_triangles; - stream >> param.theta; - stream >> param.phi; - return stream; - } - +class View_parameter { + public: + bool light; + bool relative_light; + + double size_vertices; + double size_edges; + double light_edges; // in 0-1 + double light_triangles; // in 0-1 + + /** + * light angle + */ + double theta; + double phi; + + enum VERTEX_MODE { + V_NONE, V_SIMPLE, V_COUNT + }; + + enum EDGE_MODE { + E_NONE, E_SIMPLE, E_COUNT + }; + + enum TRIANGLE_MODE { + T_NONE, T_SIMPLE, T_COUNT + }; + + VERTEX_MODE vertex_mode; + EDGE_MODE edge_mode; + TRIANGLE_MODE triangle_mode; + + void change_vertex_mode() { + int current_value = vertex_mode; + vertex_mode = static_cast<VERTEX_MODE> (++current_value % V_COUNT); + std::cout << "Vertex mode : "; + switch (vertex_mode) { + case V_NONE: + std::cout << "empty\n"; + break; + case V_SIMPLE: + std::cout << "simple\n"; + break; + default: + break; + } + } + + void change_vertex_mode(int new_mode) { + vertex_mode = static_cast<VERTEX_MODE> (new_mode % V_COUNT); + } + + void change_edge_mode() { + int current_value = edge_mode; + edge_mode = static_cast<EDGE_MODE> (++current_value % E_COUNT); + } + + void change_edge_mode(int new_mode) { + edge_mode = static_cast<EDGE_MODE> (new_mode % E_COUNT); + } + + void change_triangle_mode() { + int current_value = triangle_mode; + triangle_mode = static_cast<TRIANGLE_MODE> (++current_value % T_COUNT); + } + + View_parameter() { + light = true; + relative_light = true; + vertex_mode = V_SIMPLE; + edge_mode = E_SIMPLE; + triangle_mode = T_NONE; + + size_vertices = 3; + size_edges = 2; + + light_edges = 0.3; + light_triangles = 0.85; + theta = 0; + phi = 0; + } + + friend std::ostream& operator<<(std::ostream& stream, const View_parameter& param) { + stream << param.light << " "; + stream << param.relative_light << " "; + stream << param.vertex_mode << " "; + stream << param.edge_mode << " "; + stream << param.triangle_mode << " "; + stream << param.size_vertices << " "; + stream << param.size_edges << " "; + stream << param.light_edges << " "; + stream << param.light_triangles << " "; + stream << param.theta << " "; + stream << param.phi << " "; + return stream; + } + + friend std::istream& operator>>(std::istream& stream, View_parameter& param) { + stream >> param.light; + stream >> param.relative_light; + int a; + stream >> a; + param.vertex_mode = static_cast<VERTEX_MODE> (a % V_COUNT); + stream >> a; + param.edge_mode = static_cast<EDGE_MODE> (a % E_COUNT); + stream >> a; + param.triangle_mode = static_cast<TRIANGLE_MODE> (a % T_COUNT); + stream >> a; + stream >> param.size_vertices; + stream >> param.size_edges; + stream >> param.light_edges; + stream >> param.light_triangles; + stream >> param.theta; + stream >> param.phi; + return stream; + } }; -#endif /* VIEW_PARAMETER_H_ */ +#endif // VIEW_VIEW_PARAMETER_H_ diff --git a/src/GudhUI/view/Viewer.cpp b/src/GudhUI/view/Viewer.cpp index d8a35faf..c6c2b345 100644 --- a/src/GudhUI/view/Viewer.cpp +++ b/src/GudhUI/view/Viewer.cpp @@ -1,197 +1,186 @@ -/* - * Viewer.cpp +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. * - * Created on: Aug 26, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * */ #include "Viewer.h" #include "utils/UI_utils.h" -Viewer::Viewer(QWidget* parent): QGLViewer(QGLFormat(QGL::SampleBuffers),parent),instructor(0),theta(0),phi(0){ -} +Viewer::Viewer(QWidget* parent) : QGLViewer(QGLFormat(QGL::SampleBuffers), parent), instructor(0), theta(0), phi(0) { } -void -Viewer::set_instructor(Viewer_instructor* instructor_){ - instructor = instructor_; +void Viewer::set_instructor(Viewer_instructor* instructor_) { + instructor = instructor_; } -void -Viewer::show_entire_scene(){ - this->showEntireScene(); +void Viewer::show_entire_scene() { + this->showEntireScene(); } -void -Viewer::draw(){ - instructor->give_instructions(); +void Viewer::draw() { + instructor->give_instructions(); } - -void -Viewer::set_bounding_box(const Point_3 & lower_left,const Point_3 & upper_right){ - this->camera()->setSceneBoundingBox( - qglviewer::Vec(lower_left[0], lower_left[1], lower_left[2]), - qglviewer::Vec(upper_right[0], upper_right[1], upper_right[2]) - ); +void Viewer::set_bounding_box(const Point_3 & lower_left, const Point_3 & upper_right) { + this->camera()->setSceneBoundingBox(qglviewer::Vec(lower_left[0], lower_left[1], lower_left[2]), + qglviewer::Vec(upper_right[0], upper_right[1], upper_right[2])); } -void -Viewer::update_GL(){ - this->updateGL(); - +void Viewer::update_GL() { + this->updateGL(); } -void -Viewer::init_scene(){ - this->setBackgroundColor(Qt::white); - ::glEnable(GL_LINE_SMOOTH); - init_light(); +void Viewer::init_scene() { + this->setBackgroundColor(Qt::white); + ::glEnable(GL_LINE_SMOOTH); + init_light(); } -void -Viewer::init_light(){ - ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); +void Viewer::init_light() { + ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); } -void -Viewer::set_light(){ - if(theta>=0 && phi >=0){ - const GLfloat pos[4] = {(float)(sin(phi)*cos(theta)),(float)(sin(phi)*sin(theta)),(float)(cos(phi)),0.}; - glLightfv(GL_LIGHT0, GL_POSITION, pos); - } +void Viewer::set_light() { + if (theta >= 0 && phi >= 0) { + const GLfloat pos[4] = {static_cast<float> (sin(phi) * cos(theta)), + static_cast<float> (sin(phi) * sin(theta)), + static_cast<float> (cos(phi)), 0.}; + glLightfv(GL_LIGHT0, GL_POSITION, pos); + } } -void -Viewer::set_light_direction(double theta_,double phi_){ - theta = theta_; - phi = phi_; +void Viewer::set_light_direction(double theta_, double phi_) { + theta = theta_; + phi = phi_; } /** * set the light in the direction of the observer */ -void -Viewer::set_light_direction(){ - theta = -1; - phi = -1; +void Viewer::set_light_direction() { + theta = -1; + phi = -1; } +void Viewer::postSelection(const QPoint& point) { + bool found; -void -Viewer::postSelection(const QPoint& point){ - bool found; + auto vec = this->camera()->pointUnderPixel(point, found); - auto vec = this->camera()->pointUnderPixel(point,found); - - if(found){ - Point_3 position(vec[0],vec[1],vec[2]); - emit(click(position)); - } + if (found) { + Point_3 position(vec[0], vec[1], vec[2]); + emit(click(position)); + } } //////////////////////// // draw //////////////////////// -void -Viewer::set_size_point(double size_points){ - ::glPointSize(size_points); -} - -void -Viewer::draw_point(const Point_3& p,const Color& color,double size_points){ - ::glColor3f(color.r,color.g,color.b); - ::glDisable(GL_LIGHTING); - ::glEnable(GL_POINT_SMOOTH); - ::glPointSize(size_points); - ::glBegin(GL_POINTS); - ::glVertex3d(p.x(), p.y(), p.z()); - ::glEnd(); - ::glDisable(GL_POINT_SMOOTH); -} - -void -Viewer::begin_draw_points(double size,bool light){ - light?glEnable(GL_LIGHTING):glDisable(GL_LIGHTING); - ::glEnable(GL_POINT_SMOOTH); - ::glPointSize(size); - ::glBegin(GL_POINTS); -} - -void -Viewer::set_color(const Color& color){ - ::glColor3f(color.r,color.g,color.b); -} - -void -Viewer::draw_points(const Point_3 & point){ - ::glVertex3d(point.x(),point.y(),point.z()); -} - -void -Viewer::end_draw_points(){ - ::glEnd(); - ::glDisable(GL_POINT_SMOOTH); -} - -void -Viewer::draw_edge(const Point_3 &a,const Point_3 &b,const Color& color,double size){ - ::glColor3f(color.r,color.g,color.b); - ::glPointSize(3.0); - ::glLineWidth(size); - ::glBegin(GL_LINES); - ::glVertex3f(a.x(),a.y(),a.z()); - ::glVertex3f(b.x(),b.y(),b.z()); - ::glEnd(); -} - -void -Viewer::begin_draw_edges(double size,bool light){ - ::glLineWidth(size); - ::glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); - ::glEnable(GL_POLYGON_OFFSET_LINE); - ::glPolygonOffset(3.0f,-3.0f); - light?glEnable(GL_LIGHTING):glDisable(GL_LIGHTING); - ::glBegin(GL_LINES); -} - -void -Viewer::draw_edges(const Point_3 &a,const Point_3 &b){ - ::glVertex3f(a.x(),a.y(),a.z()); - ::glVertex3f(b.x(),b.y(),b.z()); -} - -void -Viewer::end_draw_edges(){ - ::glEnd(); -} - -void -Viewer::begin_draw_triangles(double size,bool light,bool transparent){ - if(transparent){ - ::glEnable (GL_BLEND); - ::glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - ::glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); - ::glEnable(GL_POLYGON_OFFSET_FILL); - ::glPolygonOffset(3.0f,-3.0f); - light?glEnable(GL_LIGHTING):glDisable(GL_LIGHTING); - ::glBegin(GL_TRIANGLES); -} - -void -Viewer::draw_triangles(const Point_3& p1,const Point_3& p2,const Point_3& p3){ - if(!CGAL::collinear(p1,p2,p3)){ - auto triangle_normal = CGAL::unit_normal(p1,p2,p3); - ::glNormal3d(triangle_normal.x(),triangle_normal.y(),triangle_normal.z()); - ::glVertex3d(p1.x(),p1.y(),p1.z()); - ::glVertex3d(p2.x(),p2.y(),p2.z()); - ::glVertex3d(p3.x(),p3.y(),p3.z()); - } -} - -void -Viewer::end_draw_triangles(){ - ::glEnd(); + +void Viewer::set_size_point(double size_points) { + ::glPointSize(size_points); +} + +void Viewer::draw_point(const Point_3& p, const Color& color, double size_points) { + ::glColor3f(color.r, color.g, color.b); + ::glDisable(GL_LIGHTING); + ::glEnable(GL_POINT_SMOOTH); + ::glPointSize(size_points); + ::glBegin(GL_POINTS); + ::glVertex3d(p.x(), p.y(), p.z()); + ::glEnd(); + ::glDisable(GL_POINT_SMOOTH); +} + +void Viewer::begin_draw_points(double size, bool light) { + light ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING); + ::glEnable(GL_POINT_SMOOTH); + ::glPointSize(size); + ::glBegin(GL_POINTS); +} + +void Viewer::set_color(const Color& color) { + ::glColor3f(color.r, color.g, color.b); +} + +void Viewer::draw_points(const Point_3 & point) { + ::glVertex3d(point.x(), point.y(), point.z()); +} + +void Viewer::end_draw_points() { + ::glEnd(); + ::glDisable(GL_POINT_SMOOTH); +} + +void Viewer::draw_edge(const Point_3 &a, const Point_3 &b, const Color& color, double size) { + ::glColor3f(color.r, color.g, color.b); + ::glPointSize(3.0); + ::glLineWidth(size); + ::glBegin(GL_LINES); + ::glVertex3f(a.x(), a.y(), a.z()); + ::glVertex3f(b.x(), b.y(), b.z()); + ::glEnd(); +} + +void Viewer::begin_draw_edges(double size, bool light) { + ::glLineWidth(size); + ::glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + ::glEnable(GL_POLYGON_OFFSET_LINE); + ::glPolygonOffset(3.0f, -3.0f); + light ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING); + ::glBegin(GL_LINES); +} + +void Viewer::draw_edges(const Point_3 &a, const Point_3 &b) { + ::glVertex3f(a.x(), a.y(), a.z()); + ::glVertex3f(b.x(), b.y(), b.z()); +} + +void Viewer::end_draw_edges() { + ::glEnd(); +} + +void Viewer::begin_draw_triangles(double size, bool light, bool transparent) { + if (transparent) { + ::glEnable(GL_BLEND); + ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + ::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + ::glEnable(GL_POLYGON_OFFSET_FILL); + ::glPolygonOffset(3.0f, -3.0f); + light ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING); + ::glBegin(GL_TRIANGLES); +} + +void Viewer::draw_triangles(const Point_3& p1, const Point_3& p2, const Point_3& p3) { + if (!CGAL::collinear(p1, p2, p3)) { + auto triangle_normal = CGAL::unit_normal(p1, p2, p3); + ::glNormal3d(triangle_normal.x(), triangle_normal.y(), triangle_normal.z()); + ::glVertex3d(p1.x(), p1.y(), p1.z()); + ::glVertex3d(p2.x(), p2.y(), p2.z()); + ::glVertex3d(p3.x(), p3.y(), p3.z()); + } +} + +void Viewer::end_draw_triangles() { + ::glEnd(); } #include "Viewer.moc" diff --git a/src/GudhUI/view/Viewer.h b/src/GudhUI/view/Viewer.h index 00f9b245..99bd63e4 100644 --- a/src/GudhUI/view/Viewer.h +++ b/src/GudhUI/view/Viewer.h @@ -1,10 +1,36 @@ -#ifndef VIEWER_H
-#define VIEWER_H
+/* This file is part of the Gudhi Library. The Gudhi library
+ * (Geometric Understanding in Higher Dimensions) is a generic C++
+ * library for computational topology.
+ *
+ * Author(s): David Salinas
+ *
+ * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef VIEW_VIEWER_H
+#define VIEW_VIEWER_H
// Workaround for moc-qt4 not parsing boost headers
#include <CGAL/config.h>
#include <QGLViewer/qglviewer.h>
+
+#include <vector>
+
#include "View_parameter.h"
#include "model/Complex_typedefs.h"
#include "Color.h"
@@ -13,87 +39,82 @@ class Viewer_instructor;
class Viewer : public QGLViewer {
- Q_OBJECT
-
- Viewer_instructor * instructor;
-
- /**
- * light angles
- */
- double theta,phi;
- typedef Complex::GT Gudhi_kernel;
- typedef Gudhi_kernel::Point_3 Point_3;
-public:
- Viewer(QWidget* parent);
+ Q_OBJECT
- void set_instructor(Viewer_instructor* instructor_);
+ Viewer_instructor * instructor;
- void show_entire_scene();
+ /**
+ * light angles
+ */
+ double theta, phi;
+ typedef Complex::GT Gudhi_kernel;
+ typedef Gudhi_kernel::Point_3 Point_3;
- void draw();
+ public:
+ Viewer(QWidget* parent);
+ void set_instructor(Viewer_instructor* instructor_);
- void set_bounding_box(const Point_3 & lower_left,const Point_3 & upper_right);
+ void show_entire_scene();
- void update_GL();
+ void draw();
- void init_scene();
+ void set_bounding_box(const Point_3 & lower_left, const Point_3 & upper_right);
- void init_light();
+ void update_GL();
- void set_light();
+ void init_scene();
- void set_light_direction(double theta,double phi);
+ void init_light();
- /**
- * set the light in the direction of the observer
- */
- void set_light_direction();
+ void set_light();
+ void set_light_direction(double theta, double phi);
-protected:
- virtual void postSelection(const QPoint& point);
+ /**
+ * set the light in the direction of the observer
+ */
+ void set_light_direction();
+ protected:
+ virtual void postSelection(const QPoint& point);
-public:
+ public:
+ ////////////////////////
+ // draw
+ ////////////////////////
+ void set_size_point(double size_points);
- ////////////////////////
- // draw
- ////////////////////////
- void set_size_point(double size_points);
+ void set_color(const Color& color);
- void set_color(const Color& color);
+ void draw_point(const Point_3& p, const Color& color, double size_points);
- void draw_point(const Point_3& p,const Color& color,double size_points);
+ void begin_draw_points(double size, bool light = false);
- void begin_draw_points(double size,bool light=false);
+ void draw_points(const Point_3 & point);
- void draw_points(const Point_3 & point);
+ void end_draw_points();
- void end_draw_points();
+ void draw_edge(const Point_3 &a, const Point_3 &b, const Color& color, double size);
- void draw_edge(const Point_3 &a,const Point_3 &b,const Color& color,double size);
+ void begin_draw_edges(double size, bool light = false);
- void begin_draw_edges(double size,bool light=false);
+ void draw_edges(const Point_3 &a, const Point_3 &b);
- void draw_edges(const Point_3 &a,const Point_3 &b);
+ void end_draw_edges();
- void end_draw_edges();
+ void begin_draw_triangles(double size, bool light, bool transparent = false);
- void begin_draw_triangles(double size,bool light,bool transparent = false);
+ void draw_triangles(const Point_3& p1, const Point_3& p2, const Point_3& p3);
- void draw_triangles(const Point_3& p1,const Point_3& p2,const Point_3& p3);
+ // todo remove
+ void draw_triangles(const std::vector<Point_3*>& points);
- //todo remove
- void draw_triangles(const std::vector<Point_3*>& points);
+ void end_draw_triangles();
- void end_draw_triangles();
-
- signals:
- void click(const Point_3& position);
+ signals:
+ void click(const Point_3& position);
};
-
-
-#endif
+#endif // VIEW_VIEWER_H
diff --git a/src/GudhUI/view/Viewer_instructor.cpp b/src/GudhUI/view/Viewer_instructor.cpp index 3cb8f152..4446d209 100644 --- a/src/GudhUI/view/Viewer_instructor.cpp +++ b/src/GudhUI/view/Viewer_instructor.cpp @@ -1,206 +1,192 @@ -/* - * Viewer_instructor.cpp +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. * - * Created on: Aug 26, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * */ #include <utility> + #include "Viewer_instructor.h" #include "utils/UI_utils.h" #include "FirstCoordProjector.h" - Viewer_instructor::Viewer_instructor(QWidget* parent, - Viewer* viewer, - const Complex& mesh -):viewer_(viewer),mesh_(mesh),projector_(new FirstCoordProjector3D()){ - viewer_->set_instructor(this); + Viewer* viewer, + const Complex& mesh + ) + : viewer_(viewer), mesh_(mesh), projector_(new FirstCoordProjector3D()) { + viewer_->set_instructor(this); +} + +void Viewer_instructor::initialize_bounding_box() { + auto pair_bounding_box = compute_bounding_box_corners(); + viewer_->set_bounding_box(proj(pair_bounding_box.first), proj(pair_bounding_box.second)); + viewer_->init_scene(); } +std::pair<Complex::Point, Complex::Point> Viewer_instructor::compute_bounding_box_corners() { + if (mesh_.empty()) { + return std::make_pair(Point(-1, -1, -1, 1), Point(1, 1, 1, 1)); + } else { + double x_min = 1e10; + double y_min = 1e10; + double z_min = 1e10; + double x_max = -1e10; + double y_max = -1e10; + double z_max = -1e10; + for (auto vi : mesh_.vertex_range()) { + auto pt = proj(mesh_.point(vi)); + x_min = (std::min)(x_min, pt.x()); + y_min = (std::min)(y_min, pt.y()); + z_min = (std::min)(z_min, pt.z()); -void -Viewer_instructor::initialize_bounding_box(){ - auto pair_bounding_box = compute_bounding_box_corners(); - viewer_->set_bounding_box(proj(pair_bounding_box.first),proj(pair_bounding_box.second)); - viewer_->init_scene(); -} - -std::pair<Complex::Point,Complex::Point> -Viewer_instructor::compute_bounding_box_corners(){ - if(mesh_.empty()){ - return std::make_pair(Point(-1,-1,-1,1),Point(1,1,1,1)); - } - else{ - double x_min = 1e10; - double y_min = 1e10; - double z_min = 1e10; - double x_max = -1e10; - double y_max = -1e10; - double z_max = -1e10; - for( auto vi : mesh_.vertex_range()) - { - auto pt = proj(mesh_.point(vi)); - x_min = (std::min)(x_min,pt.x()); - y_min = (std::min)(y_min,pt.y()); - z_min = (std::min)(z_min,pt.z()); - - x_max = (std::max)(x_max,pt.x()); - y_max = (std::max)(y_max,pt.y()); - z_max = (std::max)(z_max,pt.z()); - - } - return std::make_pair( - Point(x_min,y_min,z_min,1.), - Point(x_max,y_max,z_max,1.) - ); - } + x_max = (std::max)(x_max, pt.x()); + y_max = (std::max)(y_max, pt.y()); + z_max = (std::max)(z_max, pt.z()); + } + return std::make_pair(Point(x_min, y_min, z_min, 1.), + Point(x_max, y_max, z_max, 1.)); + } } -void -Viewer_instructor::show_entire_scene(){ - viewer_->show_entire_scene(); +void Viewer_instructor::show_entire_scene() { + viewer_->show_entire_scene(); } -const qglviewer::Camera* -Viewer_instructor::camera() const{ - return viewer_->camera(); +const qglviewer::Camera* Viewer_instructor::camera() const { + return viewer_->camera(); } int -Viewer_instructor::width() const{ - return viewer_->width(); +Viewer_instructor::width() const { + return viewer_->width(); } + int -Viewer_instructor::height() const{ - return viewer_->height(); +Viewer_instructor::height() const { + return viewer_->height(); } /** * to change display parameters */ -View_parameter& -Viewer_instructor::view_params(){ - return view_params_; +View_parameter& Viewer_instructor::view_params() { + return view_params_; } - void -Viewer_instructor::give_instructions(){ - if(view_params_.relative_light) - viewer_->set_light_direction(); - else - viewer_->set_light_direction(view_params_.theta,view_params_.phi); - viewer_->set_light(); - - if (view_params_.edge_mode) draw_edges(); - if (view_params_.triangle_mode) draw_triangles(); - if (view_params_.vertex_mode) draw_points(); +Viewer_instructor::give_instructions() { + if (view_params_.relative_light) + viewer_->set_light_direction(); + else + viewer_->set_light_direction(view_params_.theta, view_params_.phi); + viewer_->set_light(); + if (view_params_.edge_mode) draw_edges(); + if (view_params_.triangle_mode) draw_triangles(); + if (view_params_.vertex_mode) draw_points(); } -void -Viewer_instructor::draw_edges(){ - viewer_->begin_draw_edges(view_params_.size_edges,false); +void Viewer_instructor::draw_edges() { + viewer_->begin_draw_edges(view_params_.size_edges, false); - for(auto edge : mesh_.edge_range()){ - set_color_edge(edge); - const Point& a = mesh_.point(mesh_.first_vertex(edge)); - const Point& b = mesh_.point(mesh_.second_vertex(edge)) ; - viewer_->draw_edges(proj(a),proj(b)); - } + for (auto edge : mesh_.edge_range()) { + set_color_edge(edge); + const Point& a = mesh_.point(mesh_.first_vertex(edge)); + const Point& b = mesh_.point(mesh_.second_vertex(edge)); + viewer_->draw_edges(proj(a), proj(b)); + } - viewer_->end_draw_edges(); + viewer_->end_draw_edges(); } -void -Viewer_instructor::draw_triangles(){ - const double size_triangles = 1.0; - viewer_->begin_draw_triangles(size_triangles,view_params_.light); - - for(const auto& fit : mesh_.triangle_range()) { - set_color_triangle(fit); - if(view_params_.triangle_mode){ - auto fit_it = fit.begin(); - const Point& p1 = mesh_.point(*fit_it); - const Point& p2 = mesh_.point(*(++fit_it)); - const Point& p3 = mesh_.point(*(++fit_it)); - viewer_->draw_triangles(proj(p1),proj(p2),proj(p3)); - } - } - viewer_->end_draw_triangles(); -} +void Viewer_instructor::draw_triangles() { + const double size_triangles = 1.0; + viewer_->begin_draw_triangles(size_triangles, view_params_.light); -void -Viewer_instructor::draw_points(){ - viewer_->begin_draw_points( view_params_.size_vertices); - for( auto vi : mesh_.vertex_range()) - { - viewer_->set_size_point(view_params_.size_vertices); - set_color_vertex(vi); - viewer_->draw_points(proj(mesh_.point(vi))); - } - viewer_->end_draw_points(); + for (const auto& fit : mesh_.triangle_range()) { + set_color_triangle(fit); + if (view_params_.triangle_mode) { + auto fit_it = fit.begin(); + const Point& p1 = mesh_.point(*fit_it); + const Point& p2 = mesh_.point(*(++fit_it)); + const Point& p3 = mesh_.point(*(++fit_it)); + viewer_->draw_triangles(proj(p1), proj(p2), proj(p3)); + } + } + viewer_->end_draw_triangles(); } - -void -Viewer_instructor::draw_edge(const Point&,const Point&){ - +void Viewer_instructor::draw_points() { + viewer_->begin_draw_points(view_params_.size_vertices); + for (auto vi : mesh_.vertex_range()) { + viewer_->set_size_point(view_params_.size_vertices); + set_color_vertex(vi); + viewer_->draw_points(proj(mesh_.point(vi))); + } + viewer_->end_draw_points(); } -void -Viewer_instructor::draw_point(const Point&){ - -} +void Viewer_instructor::draw_edge(const Point&, const Point&) { } +void Viewer_instructor::draw_point(const Point&) { } /** * set the right color of vertex/edge/triangle considering the view_params choice */ -void -Viewer_instructor::set_color_vertex(Vertex_handle vh){ - viewer_->set_color(Color(view_params_.light_edges,view_params_.light_edges,view_params_.light_edges)); +void Viewer_instructor::set_color_vertex(Vertex_handle vh) { + viewer_->set_color(Color(view_params_.light_edges, view_params_.light_edges, view_params_.light_edges)); } -void -Viewer_instructor::set_color_edge(Edge_handle eh) { - viewer_->set_color(Color(view_params_.light_edges,view_params_.light_edges,view_params_.light_edges)); +void Viewer_instructor::set_color_edge(Edge_handle eh) { + viewer_->set_color(Color(view_params_.light_edges, view_params_.light_edges, view_params_.light_edges)); } -void -Viewer_instructor::set_color_triangle(const Simplex_handle& triangle){ - viewer_->set_color(Color(view_params_.light_triangles,view_params_.light_triangles,view_params_.light_triangles)); +void Viewer_instructor::set_color_triangle(const Simplex_handle& triangle) { + viewer_->set_color(Color(view_params_.light_triangles, view_params_.light_triangles, view_params_.light_triangles)); } - Viewer_instructor::Point_3 -Viewer_instructor::proj(const Point& p) const{ - return (*projector_)(p); +Viewer_instructor::proj(const Point& p) const { + return (*projector_)(p); } - -void -Viewer_instructor::sceneChanged(){ - UIDBG("sceneChanged"); - viewer_->update_GL(); +void Viewer_instructor::sceneChanged() { + UIDBG("sceneChanged"); + viewer_->update_GL(); } -void -Viewer_instructor::change_draw_vertices(){ - view_params_.change_vertex_mode(); +void Viewer_instructor::change_draw_vertices() { + view_params_.change_vertex_mode(); } -void -Viewer_instructor::change_draw_edges(){ - view_params_.change_edge_mode(); + +void Viewer_instructor::change_draw_edges() { + view_params_.change_edge_mode(); } -void -Viewer_instructor::change_draw_triangles(){ - view_params_.change_triangle_mode(); + +void Viewer_instructor::change_draw_triangles() { + view_params_.change_triangle_mode(); } -void -Viewer_instructor::change_light(){ - view_params_.light =! view_params_.light ; + +void Viewer_instructor::change_light() { + view_params_.light = !view_params_.light; } #include "Viewer_instructor.moc" diff --git a/src/GudhUI/view/Viewer_instructor.h b/src/GudhUI/view/Viewer_instructor.h index 62b3755e..e1c6af8b 100644 --- a/src/GudhUI/view/Viewer_instructor.h +++ b/src/GudhUI/view/Viewer_instructor.h @@ -1,17 +1,40 @@ -#ifndef VIEWER_INSTRUCTOR_H
-#define VIEWER_INSTRUCTOR_H
+/* This file is part of the Gudhi Library. The Gudhi library
+ * (Geometric Understanding in Higher Dimensions) is a generic C++
+ * library for computational topology.
+ *
+ * Author(s): David Salinas
+ *
+ * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef VIEW_VIEWER_INSTRUCTOR_H
+#define VIEW_VIEWER_INSTRUCTOR_H
// todo do a viewer instructor that have directely a pointer to a QGLviewer and buffer ot not triangles
// Workaround for moc-qt4 not parsing boost headers
#include <CGAL/config.h>
-#include <memory>
-
#include <QFileDialog>
#include <QKeyEvent>
#include <QGLViewer/camera.h>
+#include <memory>
+#include <utility> // for pair<>
#include "model/Complex_typedefs.h"
@@ -22,89 +45,73 @@ class Viewer;
class Viewer_parameter;
-class Viewer_instructor : public QWidget{
- Q_OBJECT
-
- typedef Geometry_trait::Point_3 Point_3;
- typedef Complex::Point Point;
- typedef Complex::Vertex_handle Vertex_handle;
- typedef Complex::Edge_handle Edge_handle;
- typedef Complex::Simplex_handle Simplex_handle;
-
-
- Viewer* viewer_;
- View_parameter view_params_;
- const Complex& mesh_;
- std::unique_ptr<Projector3D> projector_;
-
-
-public:
-
- Viewer_instructor(QWidget* parent,
- Viewer* viewer,
- const Complex& mesh
- );
-
-
- void initialize_bounding_box();
-
- std::pair<Point,Point> compute_bounding_box_corners();
-
- void show_entire_scene();
-
- const qglviewer::Camera* camera() const;
-
- int width() const;
- int height() const;
-
- /**
- * to change display parameters
- */
- View_parameter& view_params();
+class Viewer_instructor : public QWidget {
+ Q_OBJECT
+ typedef Geometry_trait::Point_3 Point_3;
+ typedef Complex::Point Point;
+ typedef Complex::Vertex_handle Vertex_handle;
+ typedef Complex::Edge_handle Edge_handle;
+ typedef Complex::Simplex_handle Simplex_handle;
-public:
+ Viewer* viewer_;
+ View_parameter view_params_;
+ const Complex& mesh_;
+ std::unique_ptr<Projector3D> projector_;
- /**
- * gives instructions to the viewer
- */
- void give_instructions();
+ public:
+ Viewer_instructor(QWidget* parent, Viewer* viewer, const Complex& mesh);
- void draw_edges();
- void draw_triangles();
- void draw_points();
+ void initialize_bounding_box();
+ std::pair<Point, Point> compute_bounding_box_corners();
- void draw_edge(const Point&,const Point&);
+ void show_entire_scene();
- void draw_point(const Point&);
+ const qglviewer::Camera* camera() const;
+ int width() const;
+ int height() const;
- /**
- * set the right color of vertex/edge/triangle considering the view_params choice
- */
- void set_color_vertex(Vertex_handle vh);
- void set_color_edge(Edge_handle eh);
+ /**
+ * to change display parameters
+ */
+ View_parameter& view_params();
- void set_color_triangle(const Simplex_handle& triangle);
+ public:
+ /**
+ * gives instructions to the viewer
+ */
+ void give_instructions();
-private:
- /**
- * Projection to 3D needed for the viewer.
- */
- Point_3 proj(const Point& p) const;
+ void draw_edges();
+ void draw_triangles();
+ void draw_points();
- public slots :
+ void draw_edge(const Point&, const Point&);
- void sceneChanged();
+ void draw_point(const Point&);
- void change_draw_vertices();
- void change_draw_edges();
- void change_draw_triangles();
- void change_light();
+ /**
+ * set the right color of vertex/edge/triangle considering the view_params choice
+ */
+ void set_color_vertex(Vertex_handle vh);
+ void set_color_edge(Edge_handle eh);
+ void set_color_triangle(const Simplex_handle& triangle);
+ private:
+ /**
+ * Projection to 3D needed for the viewer.
+ */
+ Point_3 proj(const Point& p) const;
+ public slots:
+ void sceneChanged();
+ void change_draw_vertices();
+ void change_draw_edges();
+ void change_draw_triangles();
+ void change_light();
};
-#endif //VIEWER_INSTRUCTOR_H
+#endif // VIEW_VIEWER_INSTRUCTOR_H
|