mirror of https://github.com/CGAL/cgal
replaced Object
This commit is contained in:
parent
15e766a59d
commit
3f021c72df
|
|
@ -45,12 +45,13 @@ Arr_landmarks_point_location<Arr, Gen>::locate(const Point_2& p) const
|
||||||
// Use the generator and to find the closest landmark to the query point.
|
// Use the generator and to find the closest landmark to the query point.
|
||||||
result_type lm_location_obj;
|
result_type lm_location_obj;
|
||||||
const Point_2& landmark_point = lm_gen->closest_landmark(p, lm_location_obj);
|
const Point_2& landmark_point = lm_gen->closest_landmark(p, lm_location_obj);
|
||||||
|
#if CGAL_POINT_LOCATION_VERSION < 2
|
||||||
if (landmark_point == p) {
|
CGAL_assertion(lm_location_obj);
|
||||||
//the easy case, the query point and the landmark point
|
#endif
|
||||||
//are the same so return the landmark location
|
|
||||||
|
// If the query point and the landmark point are equal, return the landmark.
|
||||||
|
if (m_traits->equal_2_object()(landmark_point, p))
|
||||||
return lm_location_obj;
|
return lm_location_obj;
|
||||||
}
|
|
||||||
|
|
||||||
// Walk from the nearest_vertex to the point p, using walk algorithm,
|
// Walk from the nearest_vertex to the point p, using walk algorithm,
|
||||||
// and find the location of the query point p. Note that the set fo edges
|
// and find the location of the query point p. Note that the set fo edges
|
||||||
|
|
@ -59,19 +60,32 @@ Arr_landmarks_point_location<Arr, Gen>::locate(const Point_2& p) const
|
||||||
result_type out_obj;
|
result_type out_obj;
|
||||||
|
|
||||||
// Locate the arrangement feature that contains the landmark.
|
// Locate the arrangement feature that contains the landmark.
|
||||||
Vertex_const_handle vh;
|
const Vertex_const_handle* vh;
|
||||||
Halfedge_const_handle hh;
|
const Halfedge_const_handle* hh;
|
||||||
Face_const_handle fh;
|
const Face_const_handle* fh;
|
||||||
|
#if CGAL_POINT_LOCATION_VERSION < 2
|
||||||
if (CGAL::assign(vh, lm_location_obj))
|
if (vh = CGAL::object_cast<Vertex_const_handle>(&lm_location_obj))
|
||||||
out_obj = _walk_from_vertex(vh, p, crossed_edges);
|
out_obj = _walk_from_vertex(*vh, p, crossed_edges);
|
||||||
else if (CGAL::assign(hh, lm_location_obj))
|
else if (hh = CGAL::object_cast<Halfedge_const_handle>(&lm_location_obj))
|
||||||
out_obj = _walk_from_edge(hh, landmark_point, p, crossed_edges);
|
out_obj = _walk_from_edge(*hh, landmark_point, p, crossed_edges);
|
||||||
else if (CGAL::assign(fh, lm_location_obj))
|
else if (fh = CGAL::object_cast<Face_const_handle>(&lm_location_obj))
|
||||||
out_obj = _walk_from_face(fh, landmark_point, p, crossed_edges);
|
out_obj = _walk_from_face(*fh, landmark_point, p, crossed_edges);
|
||||||
else CGAL_error_msg("lm_location_obj of an unknown type.");
|
else CGAL_error_msg("lm_location_obj of an unknown type.");
|
||||||
|
#else
|
||||||
if (CGAL::assign(fh, out_obj)) {
|
if (vh = boost::get<Vertex_const_handle>(&(*lm_location_obj)))
|
||||||
|
out_obj = _walk_from_vertex(*vh, p, crossed_edges);
|
||||||
|
else if (hh = boost::get<Halfedge_const_handle>(&(*lm_location_obj)))
|
||||||
|
out_obj = _walk_from_edge(*hh, landmark_point, p, crossed_edges);
|
||||||
|
else if (fh = boost::get<Face_const_handle>(&(*lm_location_obj)))
|
||||||
|
out_obj = _walk_from_face(*fh, landmark_point, p, crossed_edges);
|
||||||
|
else CGAL_error_msg("lm_location_obj of an unknown type.");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CGAL_POINT_LOCATION_VERSION < 2
|
||||||
|
if (fh = CGAL::object_cast<Face_const_handle>(&out_obj)) {
|
||||||
|
#else
|
||||||
|
if (fh = boost::get<Face_const_handle>(&(*out_obj))) {
|
||||||
|
#endif
|
||||||
// If we reached here, we did not locate the query point in any of the
|
// If we reached here, we did not locate the query point in any of the
|
||||||
// holes inside the current face, so we conclude it is contained in this
|
// holes inside the current face, so we conclude it is contained in this
|
||||||
// face.
|
// face.
|
||||||
|
|
@ -80,8 +94,8 @@ Arr_landmarks_point_location<Arr, Gen>::locate(const Point_2& p) const
|
||||||
Isolated_vertex_const_iterator iso_verts_it;
|
Isolated_vertex_const_iterator iso_verts_it;
|
||||||
typename Traits_adaptor_2::Equal_2 equal = m_traits->equal_2_object();
|
typename Traits_adaptor_2::Equal_2 equal = m_traits->equal_2_object();
|
||||||
|
|
||||||
for (iso_verts_it = fh->isolated_vertices_begin();
|
for (iso_verts_it = (*fh)->isolated_vertices_begin();
|
||||||
iso_verts_it != fh->isolated_vertices_end(); ++iso_verts_it)
|
iso_verts_it != (*fh)->isolated_vertices_end(); ++iso_verts_it)
|
||||||
{
|
{
|
||||||
if (equal(p, iso_verts_it->point())) {
|
if (equal(p, iso_verts_it->point())) {
|
||||||
Vertex_const_handle ivh = iso_verts_it;
|
Vertex_const_handle ivh = iso_verts_it;
|
||||||
|
|
@ -103,8 +117,7 @@ _walk_from_vertex(Vertex_const_handle nearest_vertex,
|
||||||
const Point_2& p,
|
const Point_2& p,
|
||||||
Halfedge_set& crossed_edges) const
|
Halfedge_set& crossed_edges) const
|
||||||
{
|
{
|
||||||
Vertex_const_handle vh = nearest_vertex;
|
Vertex_const_handle vh = nearest_vertex;
|
||||||
|
|
||||||
CGAL_assertion_msg(! vh->is_at_open_boundary(),
|
CGAL_assertion_msg(! vh->is_at_open_boundary(),
|
||||||
"_walk_from_vertex() from a vertex at infinity.");
|
"_walk_from_vertex() from a vertex at infinity.");
|
||||||
|
|
||||||
|
|
@ -121,8 +134,7 @@ _walk_from_vertex(Vertex_const_handle nearest_vertex,
|
||||||
|
|
||||||
// if we walk from a vertex this means we are crossing the
|
// if we walk from a vertex this means we are crossing the
|
||||||
// halfedges that form a corridor in which seg is going through
|
// halfedges that form a corridor in which seg is going through
|
||||||
Halfedge_around_vertex_const_circulator curr_iter,next_iter,first;
|
Halfedge_around_vertex_const_circulator first = vh->incident_halfedges();
|
||||||
first = vh->incident_halfedges();
|
|
||||||
// Create an x-monotone curve connecting the point associated with the
|
// Create an x-monotone curve connecting the point associated with the
|
||||||
// vertex vp and the query point p.
|
// vertex vp and the query point p.
|
||||||
const Point_2& vp = vh->point();
|
const Point_2& vp = vh->point();
|
||||||
|
|
@ -130,15 +142,15 @@ _walk_from_vertex(Vertex_const_handle nearest_vertex,
|
||||||
m_traits->construct_x_monotone_curve_2_object()(vp, p);
|
m_traits->construct_x_monotone_curve_2_object()(vp, p);
|
||||||
const bool seg_dir_right =
|
const bool seg_dir_right =
|
||||||
(m_traits->compare_xy_2_object()(vp, p) == SMALLER);
|
(m_traits->compare_xy_2_object()(vp, p) == SMALLER);
|
||||||
bool eq_curr_iter, eq_next_iter;
|
Halfedge_around_vertex_const_circulator curr_iter = first;
|
||||||
curr_iter = first;
|
Halfedge_around_vertex_const_circulator next_iter = curr_iter;
|
||||||
next_iter = curr_iter;
|
|
||||||
++next_iter;
|
++next_iter;
|
||||||
typename Traits_adaptor_2::Is_between_cw_2 is_between_cw =
|
typename Traits_adaptor_2::Is_between_cw_2 is_between_cw =
|
||||||
m_traits->is_between_cw_2_object();
|
m_traits->is_between_cw_2_object();
|
||||||
// Traverse the halfedges around vp until we find the pair of adjacent
|
// Traverse the halfedges around vp until we find the pair of adjacent
|
||||||
// halfedges such as seg is located clockwise in between them.
|
// halfedges such as seg is located clockwise in between them.
|
||||||
do {
|
do {
|
||||||
|
bool eq_curr_iter, eq_next_iter;
|
||||||
if (is_between_cw(seg, seg_dir_right, curr_iter->curve(),
|
if (is_between_cw(seg, seg_dir_right, curr_iter->curve(),
|
||||||
(curr_iter->direction() == ARR_RIGHT_TO_LEFT),
|
(curr_iter->direction() == ARR_RIGHT_TO_LEFT),
|
||||||
next_iter->curve(),
|
next_iter->curve(),
|
||||||
|
|
@ -158,35 +170,47 @@ _walk_from_vertex(Vertex_const_handle nearest_vertex,
|
||||||
}
|
}
|
||||||
++curr_iter;
|
++curr_iter;
|
||||||
++next_iter;
|
++next_iter;
|
||||||
} while (curr_iter!=first);
|
} while (curr_iter != first);
|
||||||
|
|
||||||
// Locate the face around the vertex that contains the curve connecting
|
// Locate the face around the vertex that contains the curve connecting
|
||||||
// the vertex and the query point.
|
// the vertex and the query point.
|
||||||
bool new_vertex = false;
|
while (true) {
|
||||||
do {
|
bool new_vertex;
|
||||||
new_vertex = false;
|
|
||||||
result_type obj = _find_face_around_vertex(vh, p, new_vertex);
|
result_type obj = _find_face_around_vertex(vh, p, new_vertex);
|
||||||
|
|
||||||
Halfedge_const_handle hh;
|
|
||||||
Face_const_handle fh;
|
|
||||||
|
|
||||||
if (new_vertex) {
|
if (new_vertex) {
|
||||||
// We found a vertex closer to p: Continue using this vertex.
|
// We found a vertex closer to p; Continue using this vertex.
|
||||||
#if !defined(CGAL_NO_ASSERTIONS)
|
#if CGAL_POINT_LOCATION_VERSION < 2
|
||||||
bool rc =
|
const Vertex_const_handle* p_vh = object_cast<Vertex_const_handle>(&obj);
|
||||||
|
#else
|
||||||
|
const Vertex_const_handle* p_vh = boost::get<Vertex_const_handle>(&(*obj));
|
||||||
#endif
|
#endif
|
||||||
CGAL::assign(vh, obj);
|
CGAL_assertion(p_vh);
|
||||||
CGAL_assertion(rc);
|
vh = *p_vh;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
else if (CGAL::assign(hh, obj) || CGAL::assign(vh, obj))
|
|
||||||
// If p is located on an edge or on a vertex, return the object
|
// If p is located on an edge or on a vertex, return the object
|
||||||
// that wraps this arrangement feature.
|
// that wraps this arrangement feature.
|
||||||
|
#if CGAL_POINT_LOCATION_VERSION < 2
|
||||||
|
if (object_cast<Halfedge_const_handle>(&obj) ||
|
||||||
|
object_cast<Vertex_const_handle>(&obj))
|
||||||
|
#else
|
||||||
|
if (boost::get<Halfedge_const_handle>(&(*obj)) ||
|
||||||
|
boost::get<Vertex_const_handle>(&(*obj)))
|
||||||
|
#endif
|
||||||
return obj;
|
return obj;
|
||||||
else if (CGAL::assign(fh, obj))
|
|
||||||
|
#if CGAL_POINT_LOCATION_VERSION < 2
|
||||||
|
const Face_const_handle* p_fh = object_cast<Face_const_handle>(&obj);
|
||||||
|
#else
|
||||||
|
const Face_const_handle* p_fh = boost::get<Face_const_handle>(&(*obj));
|
||||||
|
#endif
|
||||||
|
if (p_fh)
|
||||||
// Walk to p from the face we have located:
|
// Walk to p from the face we have located:
|
||||||
return (_walk_from_face(fh, vh->point(), p, crossed_edges));
|
return _walk_from_face(*p_fh, vh->point(), p, crossed_edges);
|
||||||
else
|
|
||||||
CGAL_error_msg("_find_face_around_vertex() returned an unknown object.");
|
CGAL_error_msg("_find_face_around_vertex() returned an unknown object.");
|
||||||
} while (new_vertex);
|
}
|
||||||
|
|
||||||
// We should never reach here:
|
// We should never reach here:
|
||||||
CGAL_error();
|
CGAL_error();
|
||||||
|
|
@ -278,8 +302,7 @@ _find_face_around_vertex(Vertex_const_handle vh,
|
||||||
// Guard for an infinitive loop, in case we have completed a full
|
// Guard for an infinitive loop, in case we have completed a full
|
||||||
// traversal around v without locating a place for seg.
|
// traversal around v without locating a place for seg.
|
||||||
if (curr == first) {
|
if (curr == first) {
|
||||||
CGAL_assertion_msg
|
CGAL_error_msg("Completed a full cycle around v without locating seg.");
|
||||||
(false, "Completed a full cycle around v without locating seg.");
|
|
||||||
return result_return();
|
return result_return();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ public:
|
||||||
|
|
||||||
// Update the search structure.
|
// Update the search structure.
|
||||||
nn.clear();
|
nn.clear();
|
||||||
nn.init (nn_points.begin(), nn_points.end());
|
nn.init(nn_points.begin(), nn_points.end());
|
||||||
|
|
||||||
num_small_not_updated_changes = 0;
|
num_small_not_updated_changes = 0;
|
||||||
updated = true;
|
updated = true;
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ public:
|
||||||
|
|
||||||
/*! Constructor from a point. */
|
/*! Constructor from a point. */
|
||||||
NN_Point_2(const Point_2& p) :
|
NN_Point_2(const Point_2& p) :
|
||||||
m_point (p)
|
m_point(p)
|
||||||
{
|
{
|
||||||
// Obtain the coordinate approximations,
|
// Obtain the coordinate approximations,
|
||||||
Geometry_traits_2 m_traits;
|
Geometry_traits_2 m_traits;
|
||||||
|
|
@ -87,9 +87,9 @@ public:
|
||||||
|
|
||||||
/*! Constructor from a point and an its location in the arrangement. */
|
/*! Constructor from a point and an its location in the arrangement. */
|
||||||
NN_Point_2(const Point_2& p, const PL_result_type& obj) :
|
NN_Point_2(const Point_2& p, const PL_result_type& obj) :
|
||||||
m_point (p),
|
m_point(p),
|
||||||
m_object (obj)
|
m_object(obj)
|
||||||
{
|
{
|
||||||
// Obtain the coordinate approximations,
|
// Obtain the coordinate approximations,
|
||||||
Geometry_traits_2 m_traits;
|
Geometry_traits_2 m_traits;
|
||||||
m_vec[0] = m_traits.approximate_2_object()(p, 0);
|
m_vec[0] = m_traits.approximate_2_object()(p, 0);
|
||||||
|
|
@ -174,25 +174,23 @@ public:
|
||||||
* \pre The search tree is not initialized.
|
* \pre The search tree is not initialized.
|
||||||
*/
|
*/
|
||||||
template <class InputIterator>
|
template <class InputIterator>
|
||||||
void init (InputIterator begin, InputIterator end)
|
void init(InputIterator begin, InputIterator end)
|
||||||
{
|
{
|
||||||
CGAL_precondition_msg (m_tree == NULL,
|
CGAL_precondition_msg(m_tree == NULL,
|
||||||
"The search tree is already initialized.");
|
"The search tree is already initialized.");
|
||||||
|
|
||||||
if (begin != end)
|
if (begin != end) {
|
||||||
{
|
m_tree = new Tree(begin, end);
|
||||||
m_tree = new Tree (begin, end);
|
|
||||||
m_is_empty = false;
|
m_is_empty = false;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
m_tree = new Tree();
|
m_tree = new Tree();
|
||||||
m_is_empty = true;
|
m_is_empty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Clear the search tree. */
|
/*! Clear the search tree. */
|
||||||
void clear ()
|
void clear()
|
||||||
{
|
{
|
||||||
if (m_tree != NULL)
|
if (m_tree != NULL)
|
||||||
delete m_tree;
|
delete m_tree;
|
||||||
|
|
@ -210,18 +208,19 @@ public:
|
||||||
*/
|
*/
|
||||||
Point_2 find_nearest_neighbor(const Point_2& q, PL_result_type &obj) const
|
Point_2 find_nearest_neighbor(const Point_2& q, PL_result_type &obj) const
|
||||||
{
|
{
|
||||||
CGAL_precondition_msg (m_tree != NULL && ! m_is_empty,
|
CGAL_precondition_msg(m_tree != NULL && ! m_is_empty,
|
||||||
"The search tree is not initialized.");
|
"The search tree is not initialized.");
|
||||||
|
|
||||||
// Create an NN_Point_2 object from the query point and use it to
|
// Create an NN_Point_2 object from the query point and use it to
|
||||||
// query the search tree to find the nearest landmark point.
|
// query the search tree to find the nearest landmark point.
|
||||||
NN_Point_2 nn_query(q);
|
NN_Point_2 nn_query(q);
|
||||||
Neighbor_search search(*m_tree, nn_query, 1);
|
Neighbor_search search(*m_tree, nn_query, 1);
|
||||||
const NN_Point_2& nearest_p = search.begin()->first;
|
//const NN_Point_2& nearest_p = search.begin()->first;
|
||||||
|
NN_Point_2 nearest_p = search.begin()->first;
|
||||||
|
|
||||||
// Return the search result.
|
// Return the search result.
|
||||||
obj = nearest_p.object();
|
obj = nearest_p.object();
|
||||||
return (nearest_p.point());
|
return nearest_p.point();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ public:
|
||||||
|
|
||||||
// Update the search structure.
|
// Update the search structure.
|
||||||
this->nn.clear();
|
this->nn.clear();
|
||||||
this->nn.init (nnp_list.begin(), nnp_list.end());
|
this->nn.init(nnp_list.begin(), nnp_list.end());
|
||||||
|
|
||||||
this->num_small_not_updated_changes = 0;
|
this->num_small_not_updated_changes = 0;
|
||||||
this->updated = true;
|
this->updated = true;
|
||||||
|
|
@ -136,16 +136,15 @@ protected:
|
||||||
{
|
{
|
||||||
// Rebuild the landmark set only if the number of small
|
// Rebuild the landmark set only if the number of small
|
||||||
// changes is greater than sqrt(num_landmarks).
|
// changes is greater than sqrt(num_landmarks).
|
||||||
double nl = static_cast<double> (num_landmarks);
|
double nl = static_cast<double>(num_landmarks);
|
||||||
const int sqrt_num_landmarks =
|
const int sqrt_num_landmarks = static_cast<int> (std::sqrt (nl) + 0.5);
|
||||||
static_cast<int> (std::sqrt (nl) + 0.5);
|
|
||||||
|
|
||||||
this->num_small_not_updated_changes++;
|
this->num_small_not_updated_changes++;
|
||||||
if ((num_landmarks < 10) ||
|
if ((num_landmarks < 10) ||
|
||||||
(this->num_small_not_updated_changes >= sqrt_num_landmarks))
|
(this->num_small_not_updated_changes >= sqrt_num_landmarks))
|
||||||
{
|
{
|
||||||
clear_landmark_set();
|
clear_landmark_set();
|
||||||
build_landmark_set();//this->
|
build_landmark_set();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue