Start to implement 2D mode for viewers; nyf.

This commit is contained in:
Guillaume Damiand 2018-09-07 20:19:41 +02:00
parent a36b79a778
commit bf20b43ea5
2 changed files with 80 additions and 0 deletions

View File

@ -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<typename KPoint>
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<BufferType>* 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;

View File

@ -42,6 +42,8 @@
#include <CGAL/Buffer_for_vao.h>
#include <CGAL/Qt/CreateOpenGLContext.h>
#include <CGAL/Qt/constraint.h>
#include <CGAL/Qt/manipulatedFrame.h>
#include <CGAL/Random.h>
namespace CGAL
@ -217,6 +219,8 @@ public:
for (int i=0; i<NB_VAO_BUFFERS; ++i)
vao[i].destroy();
delete frame;
}
void clear()
@ -240,6 +244,39 @@ public:
const CGAL::Bbox_3& bounding_box() const
{ return m_bounding_box; }
bool has_zero_x() const
{
return
m_buffer_for_mono_points.has_zero_x() &&
m_buffer_for_colored_points.has_zero_x() &&
m_buffer_for_mono_segments.has_zero_x() &&
m_buffer_for_colored_segments.has_zero_x() &&
m_buffer_for_mono_faces.has_zero_x() &&
m_buffer_for_colored_faces.has_zero_x();
}
bool has_zero_y() const
{
return
m_buffer_for_mono_points.has_zero_y() &&
m_buffer_for_colored_points.has_zero_y() &&
m_buffer_for_mono_segments.has_zero_y() &&
m_buffer_for_colored_segments.has_zero_y() &&
m_buffer_for_mono_faces.has_zero_y() &&
m_buffer_for_colored_faces.has_zero_y();
}
bool has_zero_z() const
{
return
m_buffer_for_mono_points.has_zero_z() &&
m_buffer_for_colored_points.has_zero_z() &&
m_buffer_for_mono_segments.has_zero_z() &&
m_buffer_for_colored_segments.has_zero_z() &&
m_buffer_for_mono_faces.has_zero_z() &&
m_buffer_for_colored_faces.has_zero_z();
}
template<typename KPoint>
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