mirror of https://github.com/CGAL/cgal
draw nef3 review
This commit is contained in:
parent
1e8ef8f05a
commit
58fead22b1
|
|
@ -7,7 +7,7 @@
|
||||||
# Careful when modifying
|
# Careful when modifying
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.1...3.23)
|
cmake_minimum_required(VERSION 3.1...3.23)
|
||||||
project(CGAL_basic_viewers)
|
project(CGAL_basic_viewers_Examples)
|
||||||
|
|
||||||
#CGAL_Qt5 is needed for the drawing.
|
#CGAL_Qt5 is needed for the drawing.
|
||||||
find_package(CGAL REQUIRED OPTIONAL_COMPONENTS Qt5)
|
find_package(CGAL REQUIRED OPTIONAL_COMPONENTS Qt5)
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,10 @@
|
||||||
#ifndef DRAW_NEF_3_H
|
#ifndef DRAW_NEF_3_H
|
||||||
#define DRAW_NEF_3_H
|
#define DRAW_NEF_3_H
|
||||||
|
|
||||||
#include <CGAL/Graphic_buffer.h>
|
|
||||||
#include <CGAL/Drawing_functor.h>
|
|
||||||
#include <CGAL/license/Nef_3.h>
|
#include <CGAL/license/Nef_3.h>
|
||||||
#include <CGAL/Qt/Basic_viewer_qt.h>
|
#include <CGAL/Qt/Basic_viewer_qt.h>
|
||||||
|
#include <CGAL/Graphic_buffer.h>
|
||||||
#ifdef CGAL_USE_BASIC_VIEWER
|
#include <CGAL/Drawing_functor.h>
|
||||||
|
|
||||||
#include <CGAL/Qt/init_ogl_context.h>
|
|
||||||
#include <CGAL/Nef_3/SNC_iteration.h>
|
#include <CGAL/Nef_3/SNC_iteration.h>
|
||||||
#include <CGAL/circulator.h>
|
#include <CGAL/circulator.h>
|
||||||
#include <CGAL/Random.h>
|
#include <CGAL/Random.h>
|
||||||
|
|
@ -40,18 +36,18 @@ typedef Local_kernel::Vector_3 Local_vector;
|
||||||
template <class Nef_Polyhedron>
|
template <class Nef_Polyhedron>
|
||||||
Local_vector get_face_normal(typename Nef_Polyhedron::SHalfedge_const_handle she)
|
Local_vector get_face_normal(typename Nef_Polyhedron::SHalfedge_const_handle she)
|
||||||
{
|
{
|
||||||
typedef typename Nef_Polyhedron::SHalfedge_around_facet_const_circulator SHalfedge_around_facet_const_circulator;
|
typename Nef_Polyhedron::SHalfedge_around_facet_const_circulator he(she), end(he);
|
||||||
|
|
||||||
SHalfedge_around_facet_const_circulator he(she);
|
|
||||||
Local_vector normal=CGAL::NULL_VECTOR;
|
Local_vector normal=CGAL::NULL_VECTOR;
|
||||||
SHalfedge_around_facet_const_circulator end = he;
|
|
||||||
unsigned int nb=0;
|
unsigned int nb=0;
|
||||||
|
|
||||||
|
using GU=internal::Geom_utils<typename Kernel_traits
|
||||||
|
<typename Nef_Polyhedron::Point_3>::Kernel,
|
||||||
|
Local_kernel>;
|
||||||
CGAL_For_all(he, end)
|
CGAL_For_all(he, end)
|
||||||
{
|
{
|
||||||
internal::newell_single_step_3(Basic_viewer_qt<>::get_local_point
|
internal::newell_single_step_3(GU::get_local_point(he->next()->source()->
|
||||||
(he->next()->source()->center_vertex()->point()),
|
center_vertex()->point()),
|
||||||
Basic_viewer_qt<>::get_local_point(he->source()->center_vertex()->
|
GU::get_local_point(he->source()->center_vertex()->
|
||||||
point()), normal);
|
point()), normal);
|
||||||
++nb;
|
++nb;
|
||||||
}
|
}
|
||||||
|
|
@ -63,23 +59,21 @@ Local_vector get_face_normal(typename Nef_Polyhedron::SHalfedge_const_handle she
|
||||||
template <class Nef_Polyhedron>
|
template <class Nef_Polyhedron>
|
||||||
Local_vector get_vertex_normal(typename Nef_Polyhedron::Vertex_const_handle vh)
|
Local_vector get_vertex_normal(typename Nef_Polyhedron::Vertex_const_handle vh)
|
||||||
{
|
{
|
||||||
typedef typename Nef_Polyhedron::SHalfedge_const_handle SHalfedge_const_handle;
|
typename Nef_Polyhedron::SHalfedge_const_iterator it=vh->shalfedges_begin();
|
||||||
typedef typename Nef_Polyhedron::SHalfedge_const_iterator SHalfedge_const_iterator;
|
typename Nef_Polyhedron::SHalfedge_const_handle end=it;
|
||||||
|
|
||||||
Local_vector normal=CGAL::NULL_VECTOR;
|
Local_vector normal=CGAL::NULL_VECTOR;
|
||||||
|
do
|
||||||
SHalfedge_const_iterator it = vh->shalfedges_begin();
|
{
|
||||||
SHalfedge_const_handle end = it;
|
|
||||||
do {
|
|
||||||
Local_vector n=get_face_normal<Nef_Polyhedron>(it);
|
Local_vector n=get_face_normal<Nef_Polyhedron>(it);
|
||||||
normal=typename Local_kernel::Construct_sum_of_vectors_3()(normal, n);
|
normal=typename Local_kernel::Construct_sum_of_vectors_3()(normal, n);
|
||||||
it=it->snext();
|
it=it->snext();
|
||||||
} while( it != end );
|
}
|
||||||
|
while(it!=end);
|
||||||
|
|
||||||
if (!typename Local_kernel::Equal_3()(normal, CGAL::NULL_VECTOR))
|
if (!typename Local_kernel::Equal_3()(normal, CGAL::NULL_VECTOR))
|
||||||
{
|
{
|
||||||
normal = (typename Local_kernel::Construct_scaled_vector_3()(
|
normal=(typename Local_kernel::Construct_scaled_vector_3()
|
||||||
normal, 1.0 / CGAL::sqrt(normal.squared_length())));
|
(normal, 1.0/CGAL::sqrt(normal.squared_length())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return normal;
|
return normal;
|
||||||
|
|
@ -101,46 +95,58 @@ class Nef_Visitor {
|
||||||
public:
|
public:
|
||||||
Nef_Visitor(const Nef_Polyhedron&_nef,
|
Nef_Visitor(const Nef_Polyhedron&_nef,
|
||||||
CGAL::Graphic_buffer<BufferType>& _graphic_buffer,
|
CGAL::Graphic_buffer<BufferType>& _graphic_buffer,
|
||||||
const DrawingFunctor &_drawing_functor)
|
const DrawingFunctor&_drawing_functor) :
|
||||||
: n_faces(0), n_edges(0),
|
n_faces(0), n_edges(0),
|
||||||
nef(_nef),
|
nef(_nef),
|
||||||
graphic_buffer(_graphic_buffer),
|
graphic_buffer(_graphic_buffer),
|
||||||
drawing_functor(_drawing_functor) {}
|
drawing_functor(_drawing_functor)
|
||||||
|
{}
|
||||||
|
|
||||||
void visit(Vertex_const_handle vh) {
|
void visit(Vertex_const_handle vh)
|
||||||
graphic_buffer.add_point(vh->point());
|
{
|
||||||
|
if (!drawing_functor.are_vertices_enabled() ||
|
||||||
|
!drawing_functor.draw_vertex(nef, vh))
|
||||||
|
{ return; }
|
||||||
|
|
||||||
|
if(drawing_functor.colored_vertex(nef, vh))
|
||||||
|
{ graphic_buffer.add_point(vh->point(),
|
||||||
|
drawing_functor.vertex_color(nef, vh)); }
|
||||||
|
else
|
||||||
|
{ graphic_buffer.add_point(vh->point()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void visit(Halffacet_const_handle opposite_facet)
|
void visit(Halffacet_const_handle opposite_facet)
|
||||||
{
|
{
|
||||||
Halffacet_const_handle f = opposite_facet->twin();
|
if (!drawing_functor.are_faces_enabled() ||
|
||||||
|
!drawing_functor.draw_face(nef, opposite_facet))
|
||||||
|
{ return; }
|
||||||
|
|
||||||
|
Halffacet_const_handle f=opposite_facet->twin();
|
||||||
if (facets_done.find(f)!=facets_done.end() ||
|
if (facets_done.find(f)!=facets_done.end() ||
|
||||||
facets_done.find(opposite_facet) != facets_done.end()) {
|
facets_done.find(opposite_facet)!=facets_done.end())
|
||||||
return;
|
{ return; }
|
||||||
}
|
|
||||||
|
|
||||||
SHalfedge_const_handle se;
|
SHalfedge_const_handle se;
|
||||||
Halffacet_cycle_const_iterator fc = f->facet_cycles_begin();
|
Halffacet_cycle_const_iterator fc = f->facet_cycles_begin();
|
||||||
|
|
||||||
se = SHalfedge_const_handle(fc); // non-zero if shalfedge is returned
|
se = SHalfedge_const_handle(fc); // non-zero if shalfedge is returned
|
||||||
if(se==0)
|
if(se==0)
|
||||||
{ //return if not-shalfedge
|
{ return; } //return if not-shalfedge
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(drawing_functor.colored_face(nef, f)) {
|
if(drawing_functor.colored_face(nef, f))
|
||||||
CGAL::IO::Color c = drawing_functor.face_color(nef, f);
|
{ graphic_buffer.face_begin(drawing_functor.face_color(nef, f)); }
|
||||||
graphic_buffer.face_begin(c);
|
else
|
||||||
}
|
{ graphic_buffer.face_begin(); }
|
||||||
|
|
||||||
SHalfedge_around_facet_const_circulator hc_start(se);
|
SHalfedge_around_facet_const_circulator hc_start(se);
|
||||||
SHalfedge_around_facet_const_circulator hc_end(hc_start);
|
SHalfedge_around_facet_const_circulator hc_end(hc_start);
|
||||||
Vertex_const_handle lastvh;
|
Vertex_const_handle lastvh;
|
||||||
CGAL_For_all(hc_start, hc_end) {
|
CGAL_For_all(hc_start, hc_end)
|
||||||
|
{
|
||||||
Vertex_const_handle vh=hc_start->source()->center_vertex();
|
Vertex_const_handle vh=hc_start->source()->center_vertex();
|
||||||
lastvh=vh;
|
lastvh=vh;
|
||||||
graphic_buffer.add_point_in_face(vh->point(), draw_function_for_nef_polyhedron::get_vertex_normal<Nef_Polyhedron>(vh));
|
graphic_buffer.add_point_in_face(vh->point(),
|
||||||
|
get_vertex_normal<Nef_Polyhedron>(vh));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now iterate through holes of the face
|
// Now iterate through holes of the face
|
||||||
|
|
@ -150,34 +156,43 @@ public:
|
||||||
se = SHalfedge_const_handle(fc);
|
se = SHalfedge_const_handle(fc);
|
||||||
hc_start=se;
|
hc_start=se;
|
||||||
hc_end=hc_start;
|
hc_end=hc_start;
|
||||||
CGAL_For_all(hc_start, hc_end) {
|
CGAL_For_all(hc_start, hc_end)
|
||||||
|
{
|
||||||
Vertex_const_handle vh=hc_start->source()->center_vertex();
|
Vertex_const_handle vh=hc_start->source()->center_vertex();
|
||||||
graphic_buffer.add_point_in_face(vh->point(), draw_function_for_nef_polyhedron::get_vertex_normal<Nef_Polyhedron>(vh));
|
graphic_buffer.add_point_in_face(vh->point(),
|
||||||
|
get_vertex_normal<Nef_Polyhedron>(vh));
|
||||||
}
|
}
|
||||||
graphic_buffer.add_point_in_face(hc_start->source()->center_vertex()->point(),
|
graphic_buffer.add_point_in_face(hc_start->source()->center_vertex()->point(),
|
||||||
draw_function_for_nef_polyhedron::get_vertex_normal<Nef_Polyhedron>(hc_start->source()->center_vertex()));
|
get_vertex_normal<Nef_Polyhedron>
|
||||||
graphic_buffer.add_point_in_face(lastvh->point(), draw_function_for_nef_polyhedron::get_vertex_normal<Nef_Polyhedron>(lastvh));
|
(hc_start->source()->center_vertex()));
|
||||||
|
graphic_buffer.add_point_in_face(lastvh->point(),
|
||||||
|
get_vertex_normal<Nef_Polyhedron>(lastvh));
|
||||||
++fc;
|
++fc;
|
||||||
}
|
}
|
||||||
|
|
||||||
graphic_buffer.face_end();
|
graphic_buffer.face_end();
|
||||||
facets_done[f]=true;
|
facets_done[f]=true;
|
||||||
n_faces++;
|
++n_faces;
|
||||||
}
|
}
|
||||||
|
|
||||||
void visit(Halfedge_const_handle he)
|
void visit(Halfedge_const_handle he)
|
||||||
{
|
{
|
||||||
|
if (!drawing_functor.are_edges_enabled() ||
|
||||||
|
!drawing_functor.draw_edge(nef, he))
|
||||||
|
{ return; }
|
||||||
|
|
||||||
Halfedge_const_handle twin=he->twin();
|
Halfedge_const_handle twin=he->twin();
|
||||||
if (edges_done.find(he)!=edges_done.end() ||
|
if (edges_done.find(he)!=edges_done.end() ||
|
||||||
edges_done.find(twin)!=edges_done.end())
|
edges_done.find(twin)!=edges_done.end())
|
||||||
{
|
{ return; } // Edge already added
|
||||||
// Edge already added
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
graphic_buffer.add_segment(he->source()->point(), he->target()->point());
|
if(drawing_functor.colored_edge(nef, he))
|
||||||
|
{ graphic_buffer.add_segment(he->source()->point(), he->target()->point(),
|
||||||
|
drawing_functor.edge_color(nef, he)); }
|
||||||
|
else
|
||||||
|
{ graphic_buffer.add_segment(he->source()->point(), he->target()->point()); }
|
||||||
edges_done[he]=true;
|
edges_done[he]=true;
|
||||||
n_edges++;
|
++n_edges;
|
||||||
}
|
}
|
||||||
|
|
||||||
void visit(SHalfedge_const_handle ) {}
|
void visit(SHalfedge_const_handle ) {}
|
||||||
|
|
@ -194,8 +209,9 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename BufferType=float, class Nef_Polyhedron, class DrawingFunctor>
|
template <typename BufferType=float, class Nef_Polyhedron, class DrawingFunctor>
|
||||||
void compute_elements(const Nef_Polyhedron &nef, CGAL::Graphic_buffer<BufferType> &graphic_buffer,
|
void compute_elements(const Nef_Polyhedron &nef,
|
||||||
const DrawingFunctor &m_drawing_functor)
|
CGAL::Graphic_buffer<BufferType> &graphic_buffer,
|
||||||
|
const DrawingFunctor &drawing_functor)
|
||||||
{
|
{
|
||||||
|
|
||||||
typedef typename Nef_Polyhedron::Volume_const_iterator Volume_const_iterator;
|
typedef typename Nef_Polyhedron::Volume_const_iterator Volume_const_iterator;
|
||||||
|
|
@ -203,15 +219,13 @@ void compute_elements(const Nef_Polyhedron &nef, CGAL::Graphic_buffer<BufferType
|
||||||
typedef typename Nef_Polyhedron::SFace_const_handle SFace_const_handle;
|
typedef typename Nef_Polyhedron::SFace_const_handle SFace_const_handle;
|
||||||
|
|
||||||
Volume_const_iterator c;
|
Volume_const_iterator c;
|
||||||
|
Nef_Visitor<Nef_Polyhedron, DrawingFunctor, BufferType>
|
||||||
Nef_Visitor<Nef_Polyhedron, DrawingFunctor, BufferType> V(nef, graphic_buffer, m_drawing_functor);
|
V(nef, graphic_buffer, drawing_functor);
|
||||||
CGAL_forall_volumes(c, nef)
|
CGAL_forall_volumes(c, nef)
|
||||||
{
|
{
|
||||||
Shell_entry_const_iterator it;
|
Shell_entry_const_iterator it;
|
||||||
CGAL_forall_shells_of(it, c)
|
CGAL_forall_shells_of(it, c)
|
||||||
{
|
{ nef.visit_shell_objects(SFace_const_handle(it), V); }
|
||||||
nef.visit_shell_objects(SFace_const_handle(it), V);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
graphic_buffer.negate_all_normals();
|
graphic_buffer.negate_all_normals();
|
||||||
|
|
@ -219,65 +233,75 @@ void compute_elements(const Nef_Polyhedron &nef, CGAL::Graphic_buffer<BufferType
|
||||||
|
|
||||||
} // namespace draw_function_for_nef_polyhedron
|
} // namespace draw_function_for_nef_polyhedron
|
||||||
|
|
||||||
template <typename BufferType = float, class Nef_Polyhedron, class DrawingFunctor>
|
#define CGAL_NEF3_TYPE Nef_polyhedron_3<Kernel_, Items_, Mark_>
|
||||||
void add_in_graphic_buffer(const Nef_Polyhedron &nef,
|
|
||||||
|
// add_in_graphic_buffer
|
||||||
|
template <typename Kernel_, typename Items_, typename Mark_,
|
||||||
|
typename BufferType=float, class DrawingFunctor>
|
||||||
|
void add_in_graphic_buffer(const CGAL_NEF3_TYPE &anef,
|
||||||
CGAL::Graphic_buffer<BufferType> &graphic_buffer,
|
CGAL::Graphic_buffer<BufferType> &graphic_buffer,
|
||||||
const DrawingFunctor &m_drawing_functor) {
|
const DrawingFunctor &drawing_functor)
|
||||||
draw_function_for_nef_polyhedron::compute_elements(nef, graphic_buffer, m_drawing_functor);
|
{
|
||||||
|
draw_function_for_nef_polyhedron::compute_elements(anef,
|
||||||
|
graphic_buffer,
|
||||||
|
drawing_functor);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename BufferType = float, class Nef_Polyhedron>
|
template <typename Kernel_, typename Items_, typename Mark_,
|
||||||
void add_in_graphic_buffer(const Nef_Polyhedron &nef, CGAL::Graphic_buffer<BufferType> &graphic_buffer) {
|
typename BufferType=float>
|
||||||
|
void add_in_graphic_buffer(const CGAL_NEF3_TYPE &anef,
|
||||||
|
CGAL::Graphic_buffer<BufferType> &graphic_buffer)
|
||||||
|
{
|
||||||
// Default functor; user can add his own functor.
|
// Default functor; user can add his own functor.
|
||||||
Drawing_functor<Nef_Polyhedron,
|
Drawing_functor<CGAL_NEF3_TYPE,
|
||||||
typename Nef_Polyhedron::Vertex_const_handle /*vh*/,
|
typename CGAL_NEF3_TYPE::Vertex_const_handle /*vh*/,
|
||||||
typename Nef_Polyhedron::Halfedge_const_handle /*eh*/,
|
typename CGAL_NEF3_TYPE::Halfedge_const_handle /*eh*/,
|
||||||
typename Nef_Polyhedron::Halffacet_const_handle /*fh*/>
|
typename CGAL_NEF3_TYPE::Halffacet_const_handle /*fh*/>
|
||||||
drawing_functor;
|
drawing_functor;
|
||||||
|
|
||||||
drawing_functor.colored_face = [] (const Nef_Polyhedron&,
|
drawing_functor.colored_face = [] (const CGAL_NEF3_TYPE&,
|
||||||
typename Nef_Polyhedron::Halffacet_const_handle fh) -> bool
|
typename CGAL_NEF3_TYPE::Halffacet_const_handle) -> bool
|
||||||
{
|
{ return true; };
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
drawing_functor.face_color = [] (const Nef_Polyhedron&,
|
drawing_functor.face_color = [] (const CGAL_NEF3_TYPE&,
|
||||||
typename Nef_Polyhedron::Halffacet_const_handle fh) -> CGAL::IO::Color
|
typename CGAL_NEF3_TYPE::Halffacet_const_handle fh) -> CGAL::IO::Color
|
||||||
{
|
{
|
||||||
if (fh==nullptr) // use to get the mono color
|
if (fh==nullptr) // use to get the mono color
|
||||||
return CGAL::IO::Color(100, 125, 200); // R G B between 0-255
|
{ return CGAL::IO::Color(100, 125, 200); }
|
||||||
|
|
||||||
CGAL::Random random((unsigned int)(std::size_t)(&(*fh)));
|
CGAL::Random random((unsigned int)(std::size_t)(&(*fh)));
|
||||||
return get_random_color(random);
|
return get_random_color(random);
|
||||||
};
|
};
|
||||||
|
|
||||||
add_in_graphic_buffer(nef, graphic_buffer, drawing_functor);
|
add_in_graphic_buffer(anef, graphic_buffer, drawing_functor);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CGAL_NEF3_TYPE Nef_polyhedron_3<Kernel_, Items_, Mark_>
|
#ifdef CGAL_USE_BASIC_VIEWER
|
||||||
|
|
||||||
|
// Specialization of draw function
|
||||||
template <typename Kernel_, typename Items_, typename Mark_,
|
template <typename Kernel_, typename Items_, typename Mark_,
|
||||||
typename BufferType=float, class DrawingFunctor>
|
typename BufferType=float, class DrawingFunctor>
|
||||||
void draw(const CGAL_NEF3_TYPE &anef,
|
void draw(const CGAL_NEF3_TYPE &anef,
|
||||||
const DrawingFunctor &drawing_functor,
|
const DrawingFunctor &drawing_functor,
|
||||||
bool nofill = false) {
|
const char *title="Nef Polyhedron Viewer")
|
||||||
|
{
|
||||||
CGAL::Graphic_buffer<BufferType> buffer;
|
CGAL::Graphic_buffer<BufferType> buffer;
|
||||||
add_in_graphic_buffer(anef, buffer, drawing_functor);
|
add_in_graphic_buffer(anef, buffer, drawing_functor);
|
||||||
draw_buffer(buffer);
|
draw_buffer(buffer, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Kernel_, typename Items_, typename Mark_, typename BufferType = float>
|
template <typename Kernel_, typename Items_, typename Mark_,
|
||||||
|
typename BufferType=float>
|
||||||
void draw(const CGAL_NEF3_TYPE &anef,
|
void draw(const CGAL_NEF3_TYPE &anef,
|
||||||
const char *title = "Nef Polyhedron Viewer",
|
const char *title="Nef Polyhedron Viewer")
|
||||||
bool nofill = false) {
|
{
|
||||||
CGAL::Graphic_buffer<BufferType> buffer;
|
CGAL::Graphic_buffer<BufferType> buffer;
|
||||||
add_in_graphic_buffer(anef, buffer);
|
add_in_graphic_buffer(anef, buffer);
|
||||||
draw_buffer(buffer);
|
draw_buffer(buffer, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // End namespace CGAL
|
|
||||||
|
|
||||||
#endif // CGAL_USE_BASIC_VIEWER
|
#endif // CGAL_USE_BASIC_VIEWER
|
||||||
|
|
||||||
|
} // End namespace CGAL
|
||||||
|
|
||||||
#endif // DRAW_NEF_3_H
|
#endif // DRAW_NEF_3_H
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue