Skip to content
Closed
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 @@ -91,7 +91,7 @@ Arr_naive_point_location<Arrangement>::locate(const Point_2& p) const
else if (! fh->is_unbounded() && fh->number_of_outer_ccbs() > 0)
{
// As we have already some other containing face, one face must be
// contained inside the other. Two check that, we select a
// contained inside the other. To check that, we select a
// representative vertex of inner_f and check whether it is contained
// in our current face.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class Td_active_edge : public Handle
//friend class declarations:

friend class Trapezoidal_decomposition_2<Traits>;
friend struct internal::Non_recursive_td_map_item_destructor<Traits>;

#ifdef CGAL_PM_FRIEND_CLASS
#if defined(__SUNPRO_CC) || defined(__PGI) || defined(__INTEL_COMPILER)
Expand All @@ -114,7 +115,10 @@ class Td_active_edge : public Handle
friend class In_face_iterator;
#endif
#endif

~Td_active_edge(){
if (this->refs()==1)
internal::Non_recursive_td_map_item_destructor<Traits>(*this);
}
/*! \class
* Inner class Data derived from Rep class
*/
Expand Down Expand Up @@ -281,6 +285,10 @@ class Td_active_edge : public Handle
/*! Access DAG node. */
Dag_node* dag_node() const {return ptr()->p_node; } //m_dag_node;}

bool is_last_reference() const
{
return this->refs()==1;
}

//@}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class Td_active_trapezoid : public Handle
//friend class declarations:

friend class Trapezoidal_decomposition_2<Traits>;
friend struct internal::Non_recursive_td_map_item_destructor<Traits>;

#ifdef CGAL_PM_FRIEND_CLASS
#if defined(__SUNPRO_CC) || defined(__PGI) || defined(__INTEL_COMPILER)
Expand Down Expand Up @@ -154,7 +155,14 @@ class Td_active_trapezoid : public Handle

Data* ptr() const { return (Data*)(PTR); }

public:

~Td_active_trapezoid(){
if (this->refs()==1)
internal::Non_recursive_td_map_item_destructor<Traits>(*this);
}

private:


#ifndef CGAL_TD_DEBUG
Expand Down Expand Up @@ -414,13 +422,23 @@ class Td_active_trapezoid : public Handle
/*! Access DAG node. */
Dag_node* dag_node() const {return ptr()->p_node; }

bool is_last_reference() const
{
return this->refs()==1;
}

void clear_neighbors()
{
set_lb(Td_map_item(0));
set_lt(Td_map_item(0));
set_rb(Td_map_item(0));
set_rt(Td_map_item(0));
}

void non_recursive_clear_neighbors()
{
internal::Non_recursive_td_map_item_destructor<Traits>(*this);
}

//@}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ class Td_active_vertex : public Handle {
Data(Vertex_const_handle _v, Halfedge_const_handle _cw_he,
Dag_node* _p_node) :
v(_v), cw_he(_cw_he), p_node(_p_node)
{}
{
CGAL_assertion( _cw_he==Halfedge_const_handle()
|| _cw_he->source() == v );
}

~Data() {}

Expand Down Expand Up @@ -176,9 +179,8 @@ class Td_active_vertex : public Handle {
*/
inline void set_cw_he(Halfedge_const_handle he)
{
ptr()->cw_he = ((cw_he() != Traits::empty_he_handle()) &&
(cw_he()->direction() != he->direction())) ?
he->twin() : he;
ptr()->cw_he = he->twin()->source()==ptr()->v ? he->twin() : he;
CGAL_assertion( ptr()->v == ptr()->cw_he->source() );
}

/*! Reset the first he going clockwise starting at 12 o'clock.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class Td_dag_node_base : public Handle

//bool operator!() const { return PTR == 0; } //MICHAL: maybe use ptr(), and also can change to is_null or something similar
bool is_null() const { return PTR == 0; }
protected:
Rep * ptr() const { return (Rep*) PTR; }
protected:
//Rep *& ptr() { return (Rep*) PTR; }
void set_ptr(Rep* rep) { PTR = rep; }

Expand Down Expand Up @@ -126,7 +126,7 @@ class Td_dag_node : public Td_dag_node_base<Traits>
public:
void operator()(Td_active_trapezoid& t) const
{
t.clear_neighbors();
t.non_recursive_clear_neighbors();
}

template < typename Tp >
Expand Down Expand Up @@ -209,7 +209,49 @@ class Td_dag_node : public Td_dag_node_base<Traits>
}

//d'tor
~Td_dag_node() { }
~Td_dag_node()
{
// The following code is used to avoid recursive calls to ~Handle
// Node being holding elements of type Td_dag_node_handle
if (!this->is_null() && this->refs()==1)
{
std::vector<Td_dag_node_handle> children;
if (!node()->m_left_child.is_null())
{
children.push_back(node()->m_left_child);
node()->m_left_child.reset();
}
if (!node()->m_right_child.is_null())
{
children.push_back(node()->m_right_child);
node()->m_right_child.reset();
}

while(!children.empty())
{
Td_dag_node_handle child = children.back();
children.pop_back();
Node* child_node = (Node*) child.ptr();

if (child_node != NULL)
{
if (child.refs()==1)
{
if (!child_node->m_left_child.is_null())
{
children.push_back(child_node->m_left_child);
child_node->m_left_child.reset();
}
if( !child_node->m_right_child.is_null() )
{
children.push_back(child_node->m_right_child);
child_node->m_right_child.reset();
}
}
}
}
}
}

//information retrieval

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,111 @@

namespace CGAL {

namespace internal{

// struct used to avoid recursive deletion of elements of
// Td_map_item. Td_active_edge and Td_active_edge_item are
// both refering to elements of the same type creating
// recursive call to ~Handle() if we let the regular
// calls of destructors. Here elements are copied in
// a vector and the true deletion is done when the vector
// is cleared.
template <class Traits>
struct Non_recursive_td_map_item_destructor
{
typedef typename Traits::Td_map_item Td_map_item;
typedef typename Traits::Td_active_trapezoid Td_active_trapezoid;
typedef typename Traits::Td_active_edge Td_active_edge;


struct Child_visitor
{
typedef void result_type;
std::vector<Td_map_item>& m_queue;

Child_visitor(std::vector<Td_map_item>& queue)
: m_queue(queue)
{}

void operator()(Td_active_trapezoid& item)
{
if (item.is_last_reference())
m_queue.push_back(item);
}

void operator()(Td_active_edge& item)
{
if (item.is_last_reference())
m_queue.push_back(item);
}

template <class T>
void operator()(T&) {} // nothing to do for the other types of the variant
};

struct Item_visitor
{
typedef void result_type;
Child_visitor& m_child_visitor;

Item_visitor(Child_visitor& child_visitor)
: m_child_visitor(child_visitor)
{}

void operator()(Td_active_trapezoid& item)
{
boost::apply_visitor(m_child_visitor, item.lb());
boost::apply_visitor(m_child_visitor, item.lt());
boost::apply_visitor(m_child_visitor, item.rb());
boost::apply_visitor(m_child_visitor, item.rt());
item.clear_neighbors();
}

void operator()(Td_active_edge& item)
{
boost::apply_visitor(m_child_visitor, item.next());
item.set_next(Td_map_item(0));
}

template <class T>
void operator()(T&) {} // nothing to do for the other types of the variant
};

std::vector<Td_map_item> queue;
Child_visitor child_visitor;
Item_visitor item_visitor;

Non_recursive_td_map_item_destructor(Td_active_trapezoid& item)
: child_visitor(queue)
, item_visitor(child_visitor)
{
item_visitor(item);

while (!queue.empty())
{
Td_map_item item = queue.back();
queue.pop_back();
boost::apply_visitor(item_visitor, item);
}
}

Non_recursive_td_map_item_destructor(Td_active_edge& item)
: child_visitor(queue)
, item_visitor(child_visitor)
{
item_visitor(item);

while (!queue.empty())
{
Td_map_item item = queue.back();
queue.pop_back();
boost::apply_visitor(item_visitor, item);
}
}
};

} // internal

/*! \class Trapezoidal_decomposition_2
* parameters Traits
* Description Implementation for a planar trapezoidal map also known as
Expand Down Expand Up @@ -1447,7 +1552,9 @@ class Trapezoidal_decomposition_2
{
if (do_rebuild && not_within_limits())
{
#ifdef CGAL_TD_DEBUG
std::cout << "starting over after " << number_of_curves() << std::flush;
#endif
start_over = true;
clear();
break;
Expand Down Expand Up @@ -1853,14 +1960,14 @@ class Trapezoidal_decomposition_2
ds->filter(representatives, Td_active_edge_item(*traits));

#ifndef CGAL_TD_DEBUG
CGAL_warning(sz == representatives.size());
CGAL_warning(sz <= representatives.size());
#else

unsigned long rep = representatives.size();
if (sz != rep) {
if (sz > rep) {
std::cerr << "\nnumber_of_curves()=" << sz;
std::cerr << "\nrepresentatives.size()=" << rep;
CGAL_assertion(number_of_curves()==representatives.size());
CGAL_assertion(number_of_curves()<=representatives.size());
}
#endif

Expand All @@ -1873,7 +1980,15 @@ class Trapezoidal_decomposition_2
}
}
if (! container.empty()) {
CGAL::cpp98::random_shuffle(container.begin(),container.end());
if (sz != representatives.size())
{
std::sort(container.begin(),container.end());
typename Halfedge_container::iterator last = std::unique(container.begin(), container.end());
container.erase(last, container.end());
}
CGAL_assertion(sz==container.size());

// CGAL::cpp98::random_shuffle(container.begin(),container.end()); // already done in insert()
}
return sz;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ deactivate_trapezoid(Dag_node& trpz_node, Dag_node* active_node) const
CGAL_precondition(traits->is_td_trapezoid(trpz_node.get_data()));
if (Td_active_trapezoid* trap =
boost::get<Td_active_trapezoid>(&trpz_node.get_data()))
trap->clear_neighbors();
trap->non_recursive_clear_neighbors();
trpz_node.set_data(Td_inactive_trapezoid());
if (active_node) trpz_node.set_left_child(*active_node);
}
Expand Down Expand Up @@ -510,10 +510,10 @@ update_vtx_cw_he_after_remove(Halfedge_const_handle old_he,

Halfedge_const_handle cw_he(boost::apply_visitor(cw_he_visitor(), vtx_item));
if ((old_he == cw_he) || (old_he->twin() == cw_he)) {
Halfedge_const_handle new_he = cw_he->twin()->prev();
if (new_he != old_he)
Halfedge_const_handle new_he = cw_he->twin()->next();
if (new_he != cw_he)
boost::apply_visitor(set_cw_he_visitor(new_he), vtx_item);
else boost::apply_visitor(reset_cw_he_visitor(), vtx_item);
else boost::apply_visitor(reset_cw_he_visitor(), vtx_item); // dangling edge removed
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
i 0
i 1
i 2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 8/5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2 2 3 1
2 2 1 0
4 3 0 0
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
./data/empty.zero ./data/point_location/segments/xcurves/test10.txt ./data/empty.zero ./data/point_location/segments/ops/test10.txt ./data/point_location/segments/queries/test10.txt
./data/empty.zero ./data/point_location/segments/xcurves/test11.txt ./data/empty.zero ./data/point_location/segments/ops/test11.txt ./data/point_location/segments/queries/test03.txt
./data/empty.zero ./data/point_location/segments/xcurves/test11.txt ./data/empty.zero ./data/point_location/segments/ops/test12.txt ./data/point_location/segments/queries/test03.txt
./data/empty.zero ./data/point_location/segments/xcurves/test12.txt ./data/empty.zero ./data/point_location/segments/ops/test02.txt ./data/point_location/segments/queries/test11.txt
10 changes: 10 additions & 0 deletions STL_Extension/include/CGAL/Handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ class Handle
return *this;
}

void reset()
{
if (PTR)
{
if (--PTR->count==0)
delete PTR;
PTR=0;
}
}

int
refs() const { return PTR->count; }

Expand Down