mirror of https://github.com/CGAL/cgal
Start to implement infinite line in basic viewer.
This commit is contained in:
parent
d2eaef16d0
commit
608ba3eee8
|
|
@ -42,6 +42,7 @@ namespace CGAL
|
||||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Local_kernel;
|
typedef CGAL::Exact_predicates_inexact_constructions_kernel Local_kernel;
|
||||||
typedef Local_kernel::Point_3 Local_point;
|
typedef Local_kernel::Point_3 Local_point;
|
||||||
typedef Local_kernel::Vector_3 Local_vector;
|
typedef Local_kernel::Vector_3 Local_vector;
|
||||||
|
typedef Local_kernel::Ray_2 Local_ray;
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
namespace internal
|
namespace internal
|
||||||
|
|
@ -108,6 +109,11 @@ namespace internal
|
||||||
CGAL::Cartesian_converter<K, Local_kernel> converter;
|
CGAL::Cartesian_converter<K, Local_kernel> converter;
|
||||||
return converter(v);
|
return converter(v);
|
||||||
}
|
}
|
||||||
|
static Local_ray get_local_ray(const typename K::Ray_2& r)
|
||||||
|
{
|
||||||
|
CGAL::Cartesian_converter<K, Local_kernel> converter;
|
||||||
|
return converter(r);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Specialization for Local_kernel, because there is no need of convertion here.
|
// Specialization for Local_kernel, because there is no need of convertion here.
|
||||||
|
|
@ -246,6 +252,14 @@ public:
|
||||||
add_color(c);
|
add_color(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2.2+) Add a line, without color. TODO: Modify comment numbering
|
||||||
|
template<typename KPoint>
|
||||||
|
void add_line(const KPoint& kp1, const KPoint& kp2)
|
||||||
|
{
|
||||||
|
add_point(kp1);
|
||||||
|
add_point(kp2);
|
||||||
|
}
|
||||||
|
|
||||||
// 2.3) Add an indexed segment, without color.
|
// 2.3) Add an indexed segment, without color.
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void add_indexed_segment(T index1, T index2)
|
void add_indexed_segment(T index1, T index2)
|
||||||
|
|
|
||||||
|
|
@ -179,8 +179,10 @@ public:
|
||||||
m_inverse_normal(inverse_normal),
|
m_inverse_normal(inverse_normal),
|
||||||
m_size_points(7.),
|
m_size_points(7.),
|
||||||
m_size_edges(3.1),
|
m_size_edges(3.1),
|
||||||
|
m_size_lines(3.1),
|
||||||
m_vertices_mono_color(200, 60, 60),
|
m_vertices_mono_color(200, 60, 60),
|
||||||
m_edges_mono_color(0, 0, 0),
|
m_edges_mono_color(0, 0, 0),
|
||||||
|
m_lines_mono_color(0,100,0),
|
||||||
m_faces_mono_color(60, 60, 200),
|
m_faces_mono_color(60, 60, 200),
|
||||||
m_ambient_color(0.6f, 0.5f, 0.5f, 0.5f),
|
m_ambient_color(0.6f, 0.5f, 0.5f, 0.5f),
|
||||||
m_are_buffers_initialized(false),
|
m_are_buffers_initialized(false),
|
||||||
|
|
@ -202,6 +204,15 @@ public:
|
||||||
&m_bounding_box,
|
&m_bounding_box,
|
||||||
&arrays[COLOR_SEGMENTS],
|
&arrays[COLOR_SEGMENTS],
|
||||||
NULL, NULL),
|
NULL, NULL),
|
||||||
|
m_buffer_for_mono_lines(&arrays[POS_MONO_LINES],
|
||||||
|
NULL,
|
||||||
|
&m_bounding_box,
|
||||||
|
NULL, NULL),
|
||||||
|
m_buffer_for_colored_lines(&arrays[POS_COLORED_LINES],
|
||||||
|
NULL,
|
||||||
|
&m_bounding_box,
|
||||||
|
&arrays[COLOR_LINES],
|
||||||
|
NULL, NULL),
|
||||||
m_buffer_for_mono_faces(&arrays[POS_MONO_FACES],
|
m_buffer_for_mono_faces(&arrays[POS_MONO_FACES],
|
||||||
NULL,
|
NULL,
|
||||||
&m_bounding_box,
|
&m_bounding_box,
|
||||||
|
|
@ -270,6 +281,10 @@ public:
|
||||||
const CGAL::Color& acolor)
|
const CGAL::Color& acolor)
|
||||||
{ m_buffer_for_colored_segments.add_segment(p1, p2, acolor); }
|
{ m_buffer_for_colored_segments.add_segment(p1, p2, acolor); }
|
||||||
|
|
||||||
|
template<typename KPoint>
|
||||||
|
void add_line(const KPoint& p1, const KPoint& p2)
|
||||||
|
{ m_buffer_for_mono_lines.add_line(p1, p2); }
|
||||||
|
|
||||||
bool is_a_face_started() const
|
bool is_a_face_started() const
|
||||||
{
|
{
|
||||||
return m_buffer_for_mono_faces.is_a_face_started() ||
|
return m_buffer_for_mono_faces.is_a_face_started() ||
|
||||||
|
|
@ -467,6 +482,52 @@ protected:
|
||||||
|
|
||||||
rendering_program_p_l.release();
|
rendering_program_p_l.release();
|
||||||
|
|
||||||
|
// 3) LINE SHADER
|
||||||
|
|
||||||
|
// 3.1) Mono lines
|
||||||
|
vao[VAO_MONO_LINES].bind();
|
||||||
|
|
||||||
|
++bufn;
|
||||||
|
assert(bufn<NB_VBO_BUFFERS);
|
||||||
|
buffers[bufn].bind();
|
||||||
|
buffers[bufn].allocate(arrays[POS_MONO_LINES].data(),
|
||||||
|
static_cast<int>(arrays[POS_MONO_LINES].size()*sizeof(float)));
|
||||||
|
rendering_program_p_l.enableAttributeArray("vertex");
|
||||||
|
rendering_program_p_l.setAttributeArray("vertex",GL_FLOAT,0,3);
|
||||||
|
|
||||||
|
buffers[bufn].release();
|
||||||
|
|
||||||
|
rendering_program_p_l.disableAttributeArray("color");
|
||||||
|
|
||||||
|
vao[VAO_MONO_LINES].release();
|
||||||
|
|
||||||
|
// 3.2) Color lines
|
||||||
|
|
||||||
|
vao[VAO_COLORED_LINES].bind();
|
||||||
|
|
||||||
|
++bufn;
|
||||||
|
assert(bufn<NB_VBO_BUFFERS);
|
||||||
|
buffers[bufn].bind();
|
||||||
|
buffers[bufn].allocate(arrays[POS_COLORED_LINES].data(),
|
||||||
|
static_cast<int>(arrays[POS_COLORED_LINES].size()*sizeof(float)));
|
||||||
|
rendering_program_p_l.enableAttributeArray("vertex");
|
||||||
|
rendering_program_p_l.setAttributeBuffer("vertex",GL_FLOAT,0,3);
|
||||||
|
|
||||||
|
buffers[bufn].release();
|
||||||
|
|
||||||
|
++bufn;
|
||||||
|
assert(bufn<NB_VBO_BUFFERS);
|
||||||
|
buffers[bufn].bind();
|
||||||
|
buffers[bufn].allocate(arrays[COLOR_LINES].data(),
|
||||||
|
static_cast<int>(arrays[COLOR_LINES].size()*sizeof(float)));
|
||||||
|
rendering_program_p_l.enableAttributeArray("color");
|
||||||
|
rendering_program_p_l.setAttributeBuffer("color",GL_FLOAT,0,3);
|
||||||
|
buffers[bufn].release();
|
||||||
|
|
||||||
|
vao[VAO_COLORED_LINES].release();
|
||||||
|
|
||||||
|
rendering_program_p_l.release();
|
||||||
|
|
||||||
// 3) FACE SHADER
|
// 3) FACE SHADER
|
||||||
rendering_program_face.bind();
|
rendering_program_face.bind();
|
||||||
|
|
||||||
|
|
@ -702,6 +763,39 @@ protected:
|
||||||
rendering_program_p_l.release();
|
rendering_program_p_l.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(m_draw_lines)
|
||||||
|
{
|
||||||
|
rendering_program_p_l.bind();
|
||||||
|
|
||||||
|
vao[VAO_MONO_LINES].bind();
|
||||||
|
color.setRgbF((double)m_lines_mono_color.red()/(double)255,
|
||||||
|
(double)m_lines_mono_color.green()/(double)255,
|
||||||
|
(double)m_lines_mono_color.blue()/(double)255);
|
||||||
|
rendering_program_p_l.setAttributeValue("color",color);
|
||||||
|
glLineWidth(m_size_lines);
|
||||||
|
glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(arrays[POS_MONO_LINES].size()/3));
|
||||||
|
vao[VAO_MONO_SEGMENTS].release();
|
||||||
|
|
||||||
|
vao[VAO_COLORED_SEGMENTS].bind();
|
||||||
|
if (m_use_mono_color)
|
||||||
|
{
|
||||||
|
color.setRgbF((double)m_lines_mono_color.red()/(double)255,
|
||||||
|
(double)m_lines_mono_color.green()/(double)255,
|
||||||
|
(double)m_lines_mono_color.blue()/(double)255);
|
||||||
|
rendering_program_p_l.disableAttributeArray("color");
|
||||||
|
rendering_program_p_l.setAttributeValue("color",color);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rendering_program_p_l.enableAttributeArray("color");
|
||||||
|
}
|
||||||
|
glLineWidth(m_size_lines);
|
||||||
|
glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(arrays[POS_COLORED_LINES].size()/3));
|
||||||
|
vao[VAO_COLORED_LINES].release();
|
||||||
|
|
||||||
|
rendering_program_p_l.release();
|
||||||
|
}
|
||||||
|
|
||||||
if (m_draw_faces)
|
if (m_draw_faces)
|
||||||
{
|
{
|
||||||
rendering_program_face.bind();
|
rendering_program_face.bind();
|
||||||
|
|
@ -985,6 +1079,7 @@ protected:
|
||||||
protected:
|
protected:
|
||||||
bool m_draw_vertices;
|
bool m_draw_vertices;
|
||||||
bool m_draw_edges;
|
bool m_draw_edges;
|
||||||
|
bool m_draw_lines;
|
||||||
bool m_draw_faces;
|
bool m_draw_faces;
|
||||||
bool m_flatShading;
|
bool m_flatShading;
|
||||||
bool m_use_mono_color;
|
bool m_use_mono_color;
|
||||||
|
|
@ -992,9 +1087,11 @@ protected:
|
||||||
|
|
||||||
double m_size_points;
|
double m_size_points;
|
||||||
double m_size_edges;
|
double m_size_edges;
|
||||||
|
double m_size_lines;
|
||||||
|
|
||||||
CGAL::Color m_vertices_mono_color;
|
CGAL::Color m_vertices_mono_color;
|
||||||
CGAL::Color m_edges_mono_color;
|
CGAL::Color m_edges_mono_color;
|
||||||
|
CGAL::Color m_lines_mono_color;
|
||||||
CGAL::Color m_faces_mono_color;
|
CGAL::Color m_faces_mono_color;
|
||||||
QVector4D m_ambient_color;
|
QVector4D m_ambient_color;
|
||||||
|
|
||||||
|
|
@ -1009,12 +1106,15 @@ protected:
|
||||||
POS_COLORED_POINTS,
|
POS_COLORED_POINTS,
|
||||||
POS_MONO_SEGMENTS,
|
POS_MONO_SEGMENTS,
|
||||||
POS_COLORED_SEGMENTS,
|
POS_COLORED_SEGMENTS,
|
||||||
|
POS_MONO_LINES,
|
||||||
|
POS_COLORED_LINES,
|
||||||
POS_MONO_FACES,
|
POS_MONO_FACES,
|
||||||
POS_COLORED_FACES,
|
POS_COLORED_FACES,
|
||||||
END_POS,
|
END_POS,
|
||||||
BEGIN_COLOR=END_POS,
|
BEGIN_COLOR=END_POS,
|
||||||
COLOR_POINTS=BEGIN_COLOR,
|
COLOR_POINTS=BEGIN_COLOR,
|
||||||
COLOR_SEGMENTS,
|
COLOR_SEGMENTS,
|
||||||
|
COLOR_LINES,
|
||||||
COLOR_FACES,
|
COLOR_FACES,
|
||||||
END_COLOR,
|
END_COLOR,
|
||||||
BEGIN_NORMAL=END_COLOR,
|
BEGIN_NORMAL=END_COLOR,
|
||||||
|
|
@ -1031,6 +1131,8 @@ protected:
|
||||||
Buffer_for_vao<float> m_buffer_for_colored_points;
|
Buffer_for_vao<float> m_buffer_for_colored_points;
|
||||||
Buffer_for_vao<float> m_buffer_for_mono_segments;
|
Buffer_for_vao<float> m_buffer_for_mono_segments;
|
||||||
Buffer_for_vao<float> m_buffer_for_colored_segments;
|
Buffer_for_vao<float> m_buffer_for_colored_segments;
|
||||||
|
Buffer_for_vao<float> m_buffer_for_mono_lines;
|
||||||
|
Buffer_for_vao<float> m_buffer_for_colored_lines;
|
||||||
Buffer_for_vao<float> m_buffer_for_mono_faces;
|
Buffer_for_vao<float> m_buffer_for_mono_faces;
|
||||||
Buffer_for_vao<float> m_buffer_for_colored_faces;
|
Buffer_for_vao<float> m_buffer_for_colored_faces;
|
||||||
|
|
||||||
|
|
@ -1045,6 +1147,8 @@ protected:
|
||||||
VAO_COLORED_POINTS,
|
VAO_COLORED_POINTS,
|
||||||
VAO_MONO_SEGMENTS,
|
VAO_MONO_SEGMENTS,
|
||||||
VAO_COLORED_SEGMENTS,
|
VAO_COLORED_SEGMENTS,
|
||||||
|
VAO_MONO_LINES,
|
||||||
|
VAO_COLORED_LINES,
|
||||||
VAO_MONO_FACES,
|
VAO_MONO_FACES,
|
||||||
VAO_COLORED_FACES,
|
VAO_COLORED_FACES,
|
||||||
NB_VAO_BUFFERS
|
NB_VAO_BUFFERS
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,17 @@
|
||||||
|
|
||||||
#ifdef CGAL_USE_BASIC_VIEWER
|
#ifdef CGAL_USE_BASIC_VIEWER
|
||||||
|
|
||||||
|
#include <CGAL/Voronoi_diagram_2/basic.h>
|
||||||
|
#include <CGAL/Voronoi_diagram_2/Handle_adaptor.h>
|
||||||
|
#include <CGAL/Voronoi_diagram_2/Face.h>
|
||||||
|
#include <CGAL/Voronoi_diagram_2/Vertex.h>
|
||||||
|
#include <CGAL/Triangulation_utils_2.h>
|
||||||
|
#include <CGAL/Qt/Converter.h>
|
||||||
#include <CGAL/Random.h>
|
#include <CGAL/Random.h>
|
||||||
|
|
||||||
namespace CGAL
|
namespace CGAL
|
||||||
{
|
{
|
||||||
|
|
||||||
// Default color functor; user can change it to have its own face color
|
// Default color functor; user can change it to have its own face color
|
||||||
struct DefaultColorFunctorV2
|
struct DefaultColorFunctorV2
|
||||||
{
|
{
|
||||||
|
|
@ -51,6 +58,16 @@ class SimpleVoronoiDiagram2ViewerQt : public Basic_viewer_qt
|
||||||
typedef typename V2::Face_iterator Face_const_handle;
|
typedef typename V2::Face_iterator Face_const_handle;
|
||||||
typedef typename V2::Vertex_iterator Vertex_const_handle;
|
typedef typename V2::Vertex_iterator Vertex_const_handle;
|
||||||
typedef typename V2::Point_2 Point;
|
typedef typename V2::Point_2 Point;
|
||||||
|
typedef typename V2::Delaunay_vertex_handle Delaunay_vertex_const_handle;
|
||||||
|
typedef typename V2::Ccb_halfedge_circulator Ccb_halfedge_circulator;
|
||||||
|
typedef typename V2::Delaunay_geom_traits Delaunay_geom_traits;
|
||||||
|
|
||||||
|
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||||
|
typedef CGAL_VORONOI_DIAGRAM_2_INS::Face<V2> Face;
|
||||||
|
typedef CGAL_VORONOI_DIAGRAM_2_INS::Handle_adaptor<Face> Face_handle;
|
||||||
|
typedef CGAL_VORONOI_DIAGRAM_2_INS::Vertex<V2> Vertex;
|
||||||
|
typedef CGAL_VORONOI_DIAGRAM_2_INS::Handle_adaptor<Vertex> Vertex_handle;
|
||||||
|
typedef Triangulation_cw_ccw_2 CW_CCW_2;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Construct the viewer.
|
/// Construct the viewer.
|
||||||
|
|
@ -72,22 +89,56 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// void compute_face(Face_const_handle fh)
|
void compute_face(Face_const_handle fh)
|
||||||
// {
|
{
|
||||||
// CGAL::Color c=m_fcolor.run(v2, fh);
|
// CGAL::Color c=m_fcolor.run(v2, fh);
|
||||||
// face_begin(c);
|
// face_begin(c);
|
||||||
// add_point_in_face(fh->halfedge()->source()->point());
|
// Ccb_halfedge_circulator ec_start = fh->ccb();
|
||||||
// add_point_in_face(fh->halfedge()->source()->point());
|
// Ccb_halfedge_circulator ec = ec_start;
|
||||||
// add_point_in_face(fh->halfedge()->source()->point());
|
|
||||||
|
// do{
|
||||||
|
// if( ec->has_source() )
|
||||||
|
// add_point_in_face(ec->source()->point());
|
||||||
|
// else if(ec->has_target())
|
||||||
|
// add_point_in_face(ec->target()->point());
|
||||||
|
// } while(++ec != ec_start);
|
||||||
|
|
||||||
// face_end();
|
// face_end();
|
||||||
// }
|
}
|
||||||
|
|
||||||
void compute_edge(Halfedge_const_handle he)
|
void compute_edge(Halfedge_const_handle he)
|
||||||
{
|
{
|
||||||
if(he->is_segment())
|
if(he->is_segment()){
|
||||||
add_segment(he->source()->point(),
|
add_segment(he->source()->point(),
|
||||||
he->target()->point());
|
he->target()->point());
|
||||||
|
} else if(he->is_ray()){
|
||||||
|
Delaunay_vertex_const_handle v1 = he->up();
|
||||||
|
Delaunay_vertex_const_handle v2 = he->down();
|
||||||
|
Kernel::Vector_2 direction(v1->point().y()-v2->point().y(),
|
||||||
|
v2->point().x()-v1->point().x());
|
||||||
|
Kernel::Point_2 end_point;
|
||||||
|
if(he->has_source()){
|
||||||
|
end_point = he->source()->point();
|
||||||
|
} else {
|
||||||
|
end_point = he->target()->point();
|
||||||
|
}
|
||||||
|
Kernel::Ray_2 ray(end_point, direction);
|
||||||
|
CGAL::Bbox_3 bb;
|
||||||
|
if (bb==bounding_box()) // Case of "empty" bounding box
|
||||||
|
{ bb=Local_point(CGAL::ORIGIN).bbox();
|
||||||
|
bb=bb + Local_point(500,500,500).bbox(); // To avoid a warning from Qglviewer
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ bb=bounding_box(); }
|
||||||
|
Kernel::Iso_rectangle_2 clipping_rect(bb.xmin(), bb.ymin(),
|
||||||
|
bb.xmax(), bb.ymax());
|
||||||
|
Object o = CGAL::intersection(ray, clipping_rect);
|
||||||
|
typedef Kernel::Segment_2 Segment_2;
|
||||||
|
typedef Kernel::Point_2 Point_2;
|
||||||
|
if(const Segment_2 *s = CGAL::object_cast<Segment_2>(&o)){
|
||||||
|
add_segment(s->source(), s->target());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void compute_vertex(Vertex_const_handle vh)
|
void compute_vertex(Vertex_const_handle vh)
|
||||||
|
|
@ -97,12 +148,15 @@ protected:
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
// if (!m_nofaces)
|
if (!m_nofaces)
|
||||||
// {
|
{
|
||||||
// for (typename V2::Face_iterator it=v2.faces_begin();
|
for (typename V2::Face_iterator it=v2.faces_begin();
|
||||||
// it!=v2.faces_end(); ++it)
|
it!=v2.faces_end(); ++it)
|
||||||
// { compute_face(it); }
|
{ compute_face(it); }
|
||||||
// }
|
}
|
||||||
|
// for(Delaunay_vertex_const_handle it = v2.dual().finite_vertices_begin();
|
||||||
|
// it!=v2.dual().finite_vertices_end(); ++it)
|
||||||
|
// { compute_vertex(it);}
|
||||||
|
|
||||||
for (typename V2::Halfedge_iterator it=v2.halfedges_begin();
|
for (typename V2::Halfedge_iterator it=v2.halfedges_begin();
|
||||||
it!=v2.halfedges_end(); ++it)
|
it!=v2.halfedges_end(); ++it)
|
||||||
|
|
@ -130,6 +184,7 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
CGAL::Qt::Converter<Delaunay_geom_traits> convert;
|
||||||
const V2& v2;
|
const V2& v2;
|
||||||
bool m_nofaces;
|
bool m_nofaces;
|
||||||
const ColorFunctor& m_fcolor;
|
const ColorFunctor& m_fcolor;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue