Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class Reflex_vertex_searcher : public Modifier_base<typename Nef_::SNC_structure
typedef typename SNC_structure::SHalfloop_handle SHalfloop_handle;
typedef typename SNC_structure::SFace_handle SFace_handle;

typedef typename SNC_structure::SVertex_handle SVertex_handle;
typedef typename SNC_structure::SVertex_handle SVertex_handle;
typedef typename SNC_structure::Object_handle Object_handle;

typedef typename SNC_structure::Vertex_iterator Vertex_iterator;
typedef typename SNC_structure::Volume_iterator Volume_iterator;
Expand Down
51 changes: 49 additions & 2 deletions Nef_2/include/CGAL/Nef_2/Object_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,59 @@

#include <CGAL/license/Nef_2.h>


#ifdef CGAL_NEF_USE_ANY_OBJECT
#include <CGAL/Object.h>
#include <type_traits>
#include <utility>
#else
#include <variant>
#endif

namespace CGAL {

typedef Object Object_handle;
template <typename... Args>
struct Type_pack {};

#ifdef CGAL_NEF_USE_ANY_OBJECT

template <typename U>
struct Object_handle : Object
{
using Object::Object;

template <typename T, typename = std::void_t
<typename std::iterator_traits<std::decay_t<T>>::value_type>>
Object_handle(T&& t)
: Object(std::forward<T>(t), Object::private_tag{})
{}
};

template <typename T, typename U>
inline bool assign(T& t, const Object_handle<U>& o) { return o.assign(t); }

#else

template <typename U>
struct Object_handle;

template <typename... Args>
struct Object_handle<Type_pack<Args...>>
: std::variant<std::monostate, Args...> {
using std::variant<std::monostate, Args...>::variant;
// needed for compatabiity with CGAL::Object API
bool empty() const
{ return std::holds_alternative<std::monostate>(*this); }
};

template <typename T, typename U>
inline bool assign(T& t, const Object_handle<U>& oh) {
const auto* p = std::get_if<T>(&oh);
if (!p) return false;
t = *p;
return true;
}

#endif

} //namespace CGAL

Expand Down
7 changes: 7 additions & 0 deletions Nef_2/include/CGAL/Nef_2/PM_const_decorator.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <string>
#include <list>
#include <sstream>
#include <CGAL/Nef_2/Object_handle.h>
#include <CGAL/Nef_2/Object_index.h>
#include <CGAL/Nef_2/iterator_tools.h>
#undef CGAL_NEF_DEBUG
Expand Down Expand Up @@ -158,6 +159,12 @@ typedef typename HDS::Face_handle Face_handle;
typedef typename HDS::Face_const_handle Face_const_handle;
typedef typename HDS::Face_const_iterator Face_const_iterator;

typedef typename CGAL::Type_pack<Vertex_handle, Vertex_const_handle,
Halfedge_handle, Halfedge_const_handle,
Face_handle, Face_const_handle>
Object;

typedef typename CGAL::Object_handle<Object> Object_handle;

/*{\Mtext Local types are handles, iterators and circulators of the
following kind: |Vertex_const_handle|,
Expand Down
5 changes: 3 additions & 2 deletions Nef_2/include/CGAL/Nef_2/PM_decorator.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ decorator to examine and modify a plane map. |\Mvar| inherits from
typedef typename Base::Isolated_vertex_const_iterator Isolated_vertex_const_iterator;
typedef typename Base::Point_const_iterator Point_const_iterator;
typedef typename Base::Mark Mark;
typedef typename Base::Point Point;
typedef typename Base::GenPtr GenPtr;
typedef typename Base::Point Point;
typedef typename Base::GenPtr GenPtr;
typedef typename Base::Object_handle Object_handle;

/*{\Mtext Local types are handles, iterators and circulators of the following
kind: |Vertex_handle|, |Vertex_iterator|, |Halfedge_handle|,
Expand Down
60 changes: 30 additions & 30 deletions Nef_2/include/CGAL/Nef_2/PM_point_locator.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class PM_naive_point_locator : public PM_decorator_ {
|Halfedge_const_handle|, |Halfedge_const_iterator|, |Face_const_handle|,
|Face_const_iterator|.}*/

typedef CGAL::Object_handle Object_handle;
typedef typename PM_decorator_::Object_handle Object_handle;
/*{\Mtypemember a generic handle to an object of the underlying plane
map. The kind of the object |(vertex, halfedge,face)| can be determined and
the object assigned by the three functions:\\
Expand Down Expand Up @@ -221,13 +221,13 @@ class PM_naive_point_locator : public PM_decorator_ {
const Point& p = K.source(s);
Vertex_const_iterator vit;
for(vit = this->vertices_begin(); vit != this->vertices_end(); ++vit) {
if ( p == point(vit) ) return make_object(vit);
if ( p == point(vit) ) return Object_handle(vit);
}
Halfedge_const_iterator eit;
for(eit = this->halfedges_begin(); eit != this->halfedges_end(); ++(++eit)) {
// we only have to check each second halfedge
if ( K.contains(segment(eit),p) )
return make_object(eit);
return Object_handle(eit);
}
Vertex_const_handle v_res;
Halfedge_const_handle e_res;
Expand Down Expand Up @@ -278,9 +278,9 @@ class PM_naive_point_locator : public PM_decorator_ {
}

if ( e_res != Halfedge_const_handle() )
return make_object((Face_const_handle)(face(e_res)));
return Object_handle((Face_const_handle)(face(e_res)));
else
return make_object((Face_const_handle)(face(v_res)));
return Object_handle((Face_const_handle)(face(v_res)));
}


Expand Down Expand Up @@ -314,7 +314,7 @@ class PM_naive_point_locator : public PM_decorator_ {
if ( !K.contains(ss,pv) ) continue;
CGAL_NEF_TRACEN("candidate "<<pv);
if ( M(v) ) {
h = make_object(v); // store vertex
h = Object_handle(v); // store vertex
ss = K.construct_segment(p,pv); // shorten
continue;
}
Expand All @@ -323,13 +323,13 @@ class PM_naive_point_locator : public PM_decorator_ {
Halfedge_const_handle e = out_wedge(v,d,collinear);
if ( collinear ) {
if ( M(e) ) {
h = make_object(e);
h = Object_handle(e);
ss = K.construct_segment(p,pv);
}
continue;
}
if ( M(face(e)) ) {
h = make_object(face(e));
h = Object_handle(face(e));
ss = K.construct_segment(p,pv);
}
} // all vertices
Expand All @@ -348,10 +348,10 @@ class PM_naive_point_locator : public PM_decorator_ {
e_res = (o2 > 0 ? e : twin(e));
// o2 > 0 => te left of s and se right of s => p left of e
if ( M(e_res) ) {
h = make_object(e_res);
h = Object_handle(e_res);
ss = K.construct_segment(p,p_res);
} else if ( M(face(twin(e_res))) ) {
h = make_object(face(twin(e_res)));
h = Object_handle(face(twin(e_res)));
ss = K.construct_segment(p,p_res);
}
}
Expand Down Expand Up @@ -522,14 +522,14 @@ class PM_point_locator : public


Object_handle input_object(Vertex_const_handle v) const
{ return make_object(input_vertex(v)); }
{ return Object_handle(input_vertex(v)); }

Object_handle input_object(Halfedge_const_handle e) const
{ Halfedge_const_handle e_org = input_halfedge(e);
if ( e_org != Halfedge_const_handle() )
return make_object( e_org );
return Object_handle( e_org );
// now e_org is not existing
return make_object( input_face(e) );
return Object_handle( input_face(e) );
}

/*{\Mimplementation
Expand Down Expand Up @@ -707,14 +707,14 @@ class PM_point_locator : public
if ( assign(e_triang,h) ) {
Halfedge_const_handle e = input_halfedge(e_triang);
if ( e == Halfedge_const_handle() ) // inserted during triangulation
return make_object(input_face(e_triang));
return Object_handle(input_face(e_triang));
int orientation_ = this->K.orientation(segment(e),p);
if ( orientation_ == 0 ) return make_object(e);
if ( orientation_ < 0 ) return make_object(face(twin(e)));
if ( orientation_ > 0 ) return make_object(face(e));
if ( orientation_ == 0 ) return Object_handle(e);
if ( orientation_ < 0 ) return Object_handle(face(twin(e)));
if ( orientation_ > 0 ) return Object_handle(face(e));
}
CGAL_assertion(!check_tag(typename Is_extended_kernel<Geometry>::value_type()));
return make_object(Face_const_handle(faces_begin()));
return Object_handle(Face_const_handle(faces_begin()));
// CGAL_error(); return h; // compiler warning
}

Expand Down Expand Up @@ -810,7 +810,7 @@ class PM_point_locator : public
// now p left of e
CGAL_NEF_TRACEN("in face at "<<PE(e));
if ( M(input_face(e)) ) // face mark
return make_object(input_face(e));
return Object_handle(input_face(e));

const Point& p1 = CT.point(CT.source(e));
const Point& p2 = CT.point(CT.target(e));
Expand Down Expand Up @@ -850,7 +850,7 @@ class PM_point_locator : public
case VERTEX:
{ CGAL_NEF_TRACEN("vertex "<<CT.point(v));
Vertex_const_handle v_org = input_vertex(v);
if ( M(v_org) ) return make_object(v_org);
if ( M(v_org) ) return Object_handle(v_org);
if ( CT.point(v) == s.target() ) return Object_handle();
// stop walking at s.target(), or determine next object on s:
bool collinear;
Expand All @@ -859,7 +859,7 @@ class PM_point_locator : public
{ e = e_out; current = EDGE_COLLINEAR; }
else { // ray shoot in wedge left of e_out
if ( M(input_face(e_out)) )
return make_object(input_face(e_out));
return Object_handle(input_face(e_out));
e = CT.twin(CT.next(e_out)); current = EDGE_CROSSING;
}
}
Expand All @@ -871,8 +871,8 @@ class PM_point_locator : public
return Object_handle();
Halfedge_const_handle e_org = input_halfedge(e);
if ( e_org != Halfedge_const_handle() ) { // not a CT edge
if ( M(e_org) ) return make_object(e_org);
if ( M(face(e_org)) ) return make_object(face(e_org));
if ( M(e_org) ) return Object_handle(e_org);
if ( M(face(e_org)) ) return Object_handle(face(e_org));
}
Vertex_const_handle v_cand = CT.target(CT.next(e));
CGAL_NEF_TRACEN("v_cand "<<PV(v_cand));
Expand All @@ -893,10 +893,10 @@ class PM_point_locator : public
Halfedge_const_handle e_org = input_halfedge(e);
if ( e_org == Halfedge_const_handle() ) { // a CT edge
if ( M(input_face(e)) )
return make_object(input_face(e));
return Object_handle(input_face(e));
} else { // e_org is not a CT edge
if ( M(e_org) )
return make_object(e_org);
return Object_handle(e_org);
}
if ( this->K.strictly_ordered_along_line(
CT.point(CT.source(e)),s.target(),CT.point(CT.target(e))) )
Expand Down Expand Up @@ -999,7 +999,7 @@ PM_point_locator<PMD,GEO>::walk_in_triangulation(const Point& q) const

Halfedge_const_handle e;
const Point& p = CT.point(v);
if ( p == q ) return make_object(v);
if ( p == q ) return Object_handle(v);
// Segment s = this->K.construct_segment(p,q);
Direction dir = this->K.construct_direction(p,q);
object_kind current = VERTEX;
Expand All @@ -1008,7 +1008,7 @@ PM_point_locator<PMD,GEO>::walk_in_triangulation(const Point& q) const
{
CGAL_NEF_TRACEN("vertex "<<CT.point(v));
if ( CT.point(v) == q )
return make_object(v); // stop walking at q
return Object_handle(v); // stop walking at q
bool collinear;
Halfedge_const_handle e_out = CT.out_wedge(v,dir,collinear);
if (collinear) // ray shoot via e_out
Expand All @@ -1021,13 +1021,13 @@ PM_point_locator<PMD,GEO>::walk_in_triangulation(const Point& q) const
case EDGE_CROSSING:
{ CGAL_NEF_TRACEN("crossing edge "<<CT.segment(e));
if ( !(this->K.orientation(CT.segment(e),q) > 0) ) // q not left of e
return make_object(e);
return Object_handle(e);
Vertex_const_handle v_cand = CT.target(CT.next(e));
int orientation_ = this->K.orientation(p,q,CT.point(v_cand));
switch( orientation_ ) {
case 0: // collinear
if ( this->K.strictly_ordered_along_line(p,q,CT.point(v_cand)) )
return make_object(e);
return Object_handle(e);
v = v_cand; current = VERTEX; break;
case +1: // left_turn
e = twin(next(e)); current = EDGE_CROSSING; break;
Expand All @@ -1041,7 +1041,7 @@ PM_point_locator<PMD,GEO>::walk_in_triangulation(const Point& q) const
{ CGAL_NEF_TRACEN("collinear edge "<<CT.segment(e));
if ( this->K.strictly_ordered_along_line(
CT.point(CT.source(e)),q,CT.point(CT.target(e))) )
return make_object(e);
return Object_handle(e);
v = CT.target(e); current = VERTEX;
}

Expand Down
16 changes: 5 additions & 11 deletions Nef_3/include/CGAL/Nef_3/SNC_decorator.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ class SNC_decorator : public SNC_const_decorator<Map> {

template <typename H>
void store_boundary_object(H h, Halffacet_handle f) const
{ f->boundary_entry_objects().push_back(make_object(h));
{ f->boundary_entry_objects().emplace_back(h);
sncp()->store_boundary_item(h, --(f->facet_cycles_end()));
}

template <typename H>
void store_as_first_boundary_object(H h, Halffacet_handle f) const
{ f->boundary_entry_objects().push_front(make_object(h));
{ f->boundary_entry_objects().push_front(Object_handle(h));
sncp()->store_boundary_item(h, --(f->facet_cycles_end()));
}

Expand Down Expand Up @@ -260,16 +260,10 @@ class SNC_decorator : public SNC_const_decorator<Map> {
}

template <typename H>
void store_boundary_object(H h, Volume_handle c, bool at_front = false) const
void store_boundary_object(H h, Volume_handle c) const
{
if(at_front) {
c->shell_entry_objects().push_front(make_object(h));
sncp()->store_boundary_item(h, c->shells_begin());
}
else {
c->shell_entry_objects().push_back(make_object(h));
sncp()->store_boundary_item(h, --(c->shells_end()));
}
c->shell_entry_objects().emplace_back(h);
sncp()->store_boundary_item(h, --(c->shells_end()));
}

template<typename SNCD_>
Expand Down
10 changes: 5 additions & 5 deletions Nef_3/include/CGAL/Nef_3/SNC_external_structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ class SNC_external_structure_base : public SNC_decorator<SNC_structure_>
" has plane " << h << " has circle " << e->circle() <<
" has signum " << sign_of(h));
if ( sign_of(h)<0 ) continue;
M[normalized(h)].push_back(make_object(e->twin()));
M[normalized(h)].emplace_back(e->twin());
CGAL_NEF_TRACEN(" normalized as " << normalized(h));
/*
Unique_hash_map<SHalfedge_handle, bool> Done(false);
Expand All @@ -688,7 +688,7 @@ class SNC_external_structure_base : public SNC_decorator<SNC_structure_>
}
SHalfedge_around_facet_circulator sfc(e), send(sfc);
CGAL_For_all(sfc, send) {
M[normalized(h)].push_back(make_object(e->twin()));
M[normalized(h)].emplace_back(e->twin());
Done[sfc] = true;
Done[sfc->twin()] = true;
CGAL_NEF_TRACEN(" normalized as " << normalized(h));
Expand All @@ -701,7 +701,7 @@ class SNC_external_structure_base : public SNC_decorator<SNC_structure_>
Plane_3 h = c.plane_through(l->incident_sface()->center_vertex()->point());
if ( sign_of(h)<0 ) continue;
// CGAL_assertion( h == normalized(h));
M[normalized(h)].push_back(make_object(l->twin()));
M[normalized(h)].emplace_back(l->twin());
}

#ifdef CGAL_NEF3_TIMER_PLANE_SWEEPS
Expand Down Expand Up @@ -1181,13 +1181,13 @@ class SNC_external_structure<SNC_indexed_items, SNC_structure_>
CGAL_forall_shalfedges(e,*this->sncp()) {
if(e->get_index() > e->twin()->get_index())
continue;
M[e->get_index()].push_back(make_object(e));
M[e->get_index()].emplace_back(e);
}
SHalfloop_iterator l;
CGAL_forall_shalfloops(l,*this->sncp()) {
if(l->get_index() > l->twin()->get_index())
continue;
M[l->get_index()].push_back(make_object(l));
M[l->get_index()].emplace_back(l);
}

#ifdef CGAL_NEF3_TIMER_PLANE_SWEEPS
Expand Down
Loading
Loading