From bf20b43ea5a13788a50c8a9fe592f79c679d14f2 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 7 Sep 2018 20:19:41 +0200 Subject: [PATCH] Start to implement 2D mode for viewers; nyf. --- GraphicsView/include/CGAL/Buffer_for_vao.h | 24 ++++++++ .../include/CGAL/Qt/Basic_viewer_qt.h | 56 +++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/GraphicsView/include/CGAL/Buffer_for_vao.h b/GraphicsView/include/CGAL/Buffer_for_vao.h index 0ff36cc96cd..ed1f819f71d 100644 --- a/GraphicsView/include/CGAL/Buffer_for_vao.h +++ b/GraphicsView/include/CGAL/Buffer_for_vao.h @@ -161,6 +161,9 @@ public: m_flat_normal_buffer(flat_normal), m_gouraud_normal_buffer(gouraud_normal), m_bb(bbox), + m_zero_x(true), + m_zero_y(true), + m_zero_z(true), m_face_started(false) {} @@ -171,6 +174,10 @@ public: if (m_index_buffer!=NULL) { m_index_buffer->clear(); } if (m_flat_normal_buffer!=NULL) { m_flat_normal_buffer->clear(); } if (m_gouraud_normal_buffer!=NULL) { m_gouraud_normal_buffer->clear(); } + + m_zero_x=true; + m_zero_y=true; + m_zero_z=true; } bool is_empty() const @@ -198,6 +205,15 @@ public: bool has_gouraud_normal() const { return m_gouraud_normal_buffer!=NULL; } + bool has_zero_x() const + { return m_zero_x; } + + bool has_zero_y() const + { return m_zero_y; } + + bool has_zero_z() const + { return m_zero_z; } + // 1.1) Add a point, without color. Return the index of the added point. template std::size_t add_point(const KPoint& kp) @@ -209,6 +225,10 @@ public: if (m_bb!=NULL) { (*m_bb)=(*m_bb)+p.bbox(); } + + if (m_zero_x && p.x()!=0) { m_zero_x=false; } + if (m_zero_y && p.y()!=0) { m_zero_y=false; } + if (m_zero_z && p.z()!=0) { m_zero_z=false; } return m_pos_buffer->size()-3; } @@ -808,6 +828,10 @@ protected: std::vector* m_gouraud_normal_buffer; CGAL::Bbox_3* m_bb; + + bool m_zero_x; /// True iff all points have x==0 + bool m_zero_y; /// True iff all points have y==0 + bool m_zero_z; /// True iff all points have z==0 // Local variables, used when we started a new face. bool m_face_started; diff --git a/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h b/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h index 78376d06bce..c8bbd4c128e 100644 --- a/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h +++ b/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h @@ -42,6 +42,8 @@ #include #include +#include +#include #include namespace CGAL @@ -217,6 +219,8 @@ public: for (int i=0; i void add_point(const KPoint& p) { m_buffer_for_mono_points.add_point(p); } @@ -719,6 +756,19 @@ protected: rendering_program_face.release(); } + + if (!is_empty() && (has_zero_x() || has_zero_y() || has_zero_z())) + { + camera()->setType(CGAL::qglviewer::Camera::ORTHOGRAPHIC); + // Camera Constraint: + constraint.setRotationConstraintType(CGAL::qglviewer::AxisPlaneConstraint::FORBIDDEN); + constraint.setTranslationConstraintType(CGAL::qglviewer::AxisPlaneConstraint::FREE); + constraint.setRotationConstraintDirection(CGAL::qglviewer::Vec((has_zero_x()?1:0), + (has_zero_y()?1:0), + (has_zero_z()?1:0))); + + frame->setConstraint(&constraint); + } } virtual void redraw() @@ -763,6 +813,9 @@ protected: compile_shaders(); + frame = new qglviewer::ManipulatedFrame; + setManipulatedFrame(frame); + CGAL::Bbox_3 bb; if (bb==bounding_box()) // Case of "empty" bounding box { @@ -984,6 +1037,9 @@ private: bool m_are_buffers_initialized; CGAL::Bbox_3 m_bounding_box; + + qglviewer::ManipulatedFrame *frame; + CGAL::qglviewer::LocalConstraint constraint; // The following enum gives the indices of different elements of arrays vectors. enum