18
18
// Author(s) : Idit Haran <haranidi@post.tau.ac.il>
19
19
// Ron Wein <wein@post.tau.ac.il>
20
#ifndef CGAL_ARR_LM_GRID_GENERATOR_H
21
#define CGAL_ARR_LM_GRID_GENERATOR_H
21
#ifndef CGAL_ARR_LANDMARKS_GRID_GENERATOR_H
22
#define CGAL_ARR_LANDMARKS_GRID_GENERATOR_H
24
25
* Definition of the Arr_grid_landmarks_generator<Arrangement> template.
73
74
typedef Arr_traits_basic_adaptor_2<Geometry_traits_2> Traits_adaptor_2;
76
const Traits_adaptor_2* m_traits;
77
unsigned int num_landmarks;
80
ANT x_min, y_min; // Bounding box for the
81
ANT x_max, y_max; // arrangement vertices.
82
ANT step_x, step_y; // Grid step sizes.
85
bool fixed_number_of_lm; // indicates if the constructor got
86
// number of landmarks as parameter
77
const Traits_adaptor_2* m_traits;
78
unsigned int num_landmarks;
81
ANT x_min, y_min; // Bounding box for the
82
ANT x_max, y_max; // arrangement vertices.
83
ANT step_x, step_y; // Grid step sizes.
86
bool fixed_number_of_lm; // indicates if the constructor got
87
// number of landmarks as parameter
89
90
/*! Copy constructor - not supported. */
93
94
Self& operator=(const Self&);
97
/*! Constructor from an arrangement.
98
* \param arr (in) The arrangement.
97
100
Arr_grid_landmarks_generator(const Arrangement_2& arr) :
102
m_traits(static_cast<const Traits_adaptor_2*>(arr.geometry_traits())),
100
104
fixed_number_of_lm(false)
102
m_traits = static_cast<const Traits_adaptor_2*>(arr.geometry_traits());
103
106
build_landmark_set();//this->
106
109
Arr_grid_landmarks_generator(const Arrangement_2& arr,
107
110
unsigned int n_landmarks) :
112
m_traits(static_cast<const Traits_adaptor_2*>(arr.geometry_traits())),
109
113
num_landmarks(n_landmarks),
110
114
fixed_number_of_lm(true)
112
m_traits = static_cast<const Traits_adaptor_2*>(arr.geometry_traits());
113
116
build_landmark_set();//this->
117
* Create the landmarks set (choosing the landmarks),
119
/*! Create the landmarks set (choosing the landmarks),
118
120
* and store them in the nearest neighbor search structure.
120
122
virtual void build_landmark_set()
122
124
// Create a set of points on a grid.
124
126
_create_points_set(points);
125
127
// Locate the landmarks in the arrangement using batched point-location
126
128
// global function. Note that the resulting pairs are returned sorted by
140
141
this->updated = false;
144
* Get the nearest neighbor (landmark) to the given point.
144
/*! Obtain the nearest neighbor (landmark) to the given point.
145
145
* \param q The query point.
146
* \param obj Output: The location of the nearest landmark point in the
147
* arrangement (a vertex, halfedge, or face handle).
146
* \param obj (out) The location of the nearest landmark point in the
147
* arrangement (a vertex, halfedge, or face handle).
148
148
* \return The nearest landmark point.
150
150
virtual Point_2 closest_landmark(const Point_2& q, PL_result_type& obj)
152
152
CGAL_assertion(this->updated);
154
154
// Calculate the index of the nearest grid point point to q.
155
const ANT qx = m_traits->approximate_2_object()(q, 0);
156
const ANT qy = m_traits->approximate_2_object()(q, 1);
160
if (CGAL::compare(qx, x_min) == SMALLER)
162
else if (CGAL::compare(qx, x_max) == LARGER)
165
i = static_cast<int>(((qx - x_min) / step_x) + 0.5);
167
if (CGAL::compare(qy, y_min) == SMALLER)
169
else if (CGAL::compare(qy, y_max) == LARGER)
172
j = static_cast<int>(((qy - y_min) / step_y) + 0.5);
174
index = sqrt_n * i + j;
155
typename Geometry_traits_2::Approximate_2 approximate =
156
m_traits->approximate_2_object();
157
const ANT qx = approximate(q, 0);
158
const ANT qy = approximate(q, 1);
159
unsigned int i = (CGAL::compare(qx, x_min) == SMALLER) ? 0 :
160
(CGAL::compare(qx, x_max) == LARGER) ? (sqrt_n - 1) :
161
static_cast<int>(((qx - x_min) / step_x) + 0.5);
162
unsigned int j = (CGAL::compare(qy, y_min) == SMALLER) ? 0 :
163
(CGAL::compare(qy, y_max) == LARGER) ? (sqrt_n - 1) :
164
static_cast<int>(((qy - y_min) / step_y) + 0.5);
165
unsigned int index = sqrt_n * i + j;
176
167
// Return the result.
177
168
obj = lm_pairs[index].second;
207
Vertex_const_iterator left, right, top, bottom;
197
Vertex_const_iterator left, right, top, bottom;
209
199
left = right = top = bottom = vit;
211
for (++vit; vit != arr->vertices_end(); ++vit)
201
for (++vit; vit != arr->vertices_end(); ++vit) {
213
202
x = m_traits->approximate_2_object()(vit->point(), 0);
214
203
y = m_traits->approximate_2_object()(vit->point(), 1);
216
if (CGAL::compare(x, x_min) == SMALLER)
205
if (CGAL::compare(x, x_min) == SMALLER) {
221
else if (CGAL::compare(x, x_max) == LARGER)
209
else if (CGAL::compare(x, x_max) == LARGER) {
227
if (CGAL::compare(y, y_min) == SMALLER)
214
if (CGAL::compare(y, y_min) == SMALLER) {
232
else if (CGAL::compare(y, y_max) == LARGER)
218
else if (CGAL::compare(y, y_max) == LARGER) {
249
234
CGAL_assertion(sqrt_n > 1);
251
236
// Calculate the step sizes for the grid.
252
ANT delta_x = m_traits->approximate_2_object()(right->point(), 0) -
253
m_traits->approximate_2_object()(left->point(), 0);
254
ANT delta_y = m_traits->approximate_2_object()(top->point(), 1) -
255
m_traits->approximate_2_object()(bottom->point(), 1);
257
if (CGAL::sign(delta_x) == CGAL::ZERO)
260
if (CGAL::sign(delta_y) == CGAL::ZERO)
237
ANT delta_x = m_traits->approximate_2_object()(right->point(), 0) -
238
m_traits->approximate_2_object()(left->point(), 0);
239
ANT delta_y = m_traits->approximate_2_object()(top->point(), 1) -
240
m_traits->approximate_2_object()(bottom->point(), 1);
242
if (CGAL::sign(delta_x) == CGAL::ZERO) delta_x = delta_y;
243
if (CGAL::sign(delta_y) == CGAL::ZERO) delta_y = delta_x;
263
244
CGAL_assertion((CGAL::sign(delta_x) == CGAL::POSITIVE) &&
264
245
(CGAL::sign(delta_y) == CGAL::POSITIVE));
266
246
step_x = delta_x / (sqrt_n - 1);
267
247
step_y = delta_y / (sqrt_n - 1);