23 #ifndef __BOUNDING_BOX_TREE_2D_H 24 #define __BOUNDING_BOX_TREE_2D_H 28 #include <dolfin/common/constants.h> 29 #include "GenericBoundingBoxTree.h" 48 less_x(
const std::vector<double>& bboxes): bboxes(bboxes) {}
53 const double* bi = bboxes.data() + 4*i;
54 const double* bj = bboxes.data() + 4*j;
55 return bi[0] + bi[2] < bj[0] + bj[2];
67 less_y(
const std::vector<double>& bboxes): bboxes(bboxes) {}
72 const double* bi = bboxes.data() + 4*i;
73 const double* bj = bboxes.data() + 4*j;
74 return bi[1] + bi[3] < bj[1] + bj[3];
79 std::size_t
gdim()
const {
return 2; }
91 const double eps0 = DOLFIN_EPS_LARGE*(b[2] - b[0]);
92 const double eps1 = DOLFIN_EPS_LARGE*(b[3] - b[1]);
93 return (b[0] - eps0 <= x[0] && x[0] <= b[2] + eps0 &&
94 b[1] - eps1 <= x[1] && x[1] <= b[3] + eps1);
101 const double eps0 = DOLFIN_EPS_LARGE*(b[2] - b[0]);
102 const double eps1 = DOLFIN_EPS_LARGE*(b[3] - b[1]);
103 return (b[0] - eps0 <= a[2] && a[0] <= b[2] + eps0 &&
104 b[1] - eps1 <= a[3] && a[1] <= b[3] + eps1);
109 unsigned int node)
const 119 if (x[0] < b[0]) r2 += (x[0] - b[0])*(x[0] - b[0]);
120 if (x[0] > b[2]) r2 += (x[0] - b[2])*(x[0] - b[2]);
121 if (x[1] < b[1]) r2 += (x[1] - b[1])*(x[1] - b[1]);
122 if (x[1] > b[3]) r2 += (x[1] - b[3])*(x[1] - b[3]);
129 unsigned int node)
const 132 return (x[0] - p[0])*(x[0] - p[0]) + (x[1] - p[1])*(x[1] - p[1]);
138 const std::vector<double>& leaf_bboxes,
139 const std::vector<unsigned int>::iterator&
begin,
140 const std::vector<unsigned int>::iterator&
end)
142 typedef std::vector<unsigned int>::const_iterator iterator;
146 const double* b = leaf_bboxes.data() + 4*(*it);
153 for (++it; it !=
end; ++it)
155 const double* b = leaf_bboxes.data() + 4*(*it);
156 if (b[0] < bbox[0]) bbox[0] = b[0];
157 if (b[1] < bbox[1]) bbox[1] = b[1];
158 if (b[2] > bbox[2]) bbox[2] = b[2];
159 if (b[3] > bbox[3]) bbox[3] = b[3];
163 const double x = bbox[2] - bbox[0];
164 const double y = bbox[3] - bbox[1];
175 const std::vector<Point>& points,
176 const std::vector<unsigned int>::iterator&
begin,
177 const std::vector<unsigned int>::iterator&
end)
179 typedef std::vector<unsigned int>::const_iterator iterator;
183 const double* p = points[*it].coordinates();
190 for (; it !=
end; ++it)
192 const double* p = points[*it].coordinates();
193 if (p[0] < bbox[0]) bbox[0] = p[0];
194 if (p[1] < bbox[1]) bbox[1] = p[1];
195 if (p[0] > bbox[2]) bbox[2] = p[0];
196 if (p[1] > bbox[3]) bbox[3] = p[1];
200 const double x = bbox[2] - bbox[0];
201 const double y = bbox[3] - bbox[1];
211 const std::vector<double>& leaf_bboxes,
212 const std::vector<unsigned int>::iterator&
begin,
213 const std::vector<unsigned int>::iterator& middle,
214 const std::vector<unsigned int>::iterator&
end)
217 std::nth_element(begin, middle, end,
less_x(leaf_bboxes));
219 std::nth_element(begin, middle, end,
less_y(leaf_bboxes));
bool operator()(unsigned int i, unsigned int j)
Comparison operator.
Definition: BoundingBoxTree2D.h:51
bool operator()(unsigned int i, unsigned int j)
Comparison operator.
Definition: BoundingBoxTree2D.h:70
Definition: BoundingBoxTree2D.h:42
Definition: GenericBoundingBoxTree.h:40
std::size_t gdim() const
Return geometric dimension.
Definition: BoundingBoxTree2D.h:79
void begin(std::string msg,...)
Begin task (increase indentation level)
Definition: log.cpp:153
bool point_in_bbox(const double *x, unsigned int node) const
Check whether point (x) is in bounding box (node)
Definition: BoundingBoxTree2D.h:88
const double * get_bbox_coordinates(unsigned int node) const
Return bounding box coordinates for node.
Definition: BoundingBoxTree2D.h:82
void sort_bboxes(std::size_t axis, const std::vector< double > &leaf_bboxes, const std::vector< unsigned int >::iterator &begin, const std::vector< unsigned int >::iterator &middle, const std::vector< unsigned int >::iterator &end)
Sort leaf bounding boxes along given axis.
Definition: BoundingBoxTree2D.h:210
bool bbox_in_bbox(const double *a, unsigned int node) const
Check whether bounding box (a) collides with bounding box (node)
Definition: BoundingBoxTree2D.h:98
void end()
End task (decrease indentation level)
Definition: log.cpp:168
double compute_squared_distance_point(const double *x, unsigned int node) const
Compute squared distance between point and point.
Definition: BoundingBoxTree2D.h:128
void compute_bbox_of_points(double *bbox, std::size_t &axis, const std::vector< Point > &points, const std::vector< unsigned int >::iterator &begin, const std::vector< unsigned int >::iterator &end)
Compute bounding box of points.
Definition: BoundingBoxTree2D.h:173
Specialization of bounding box implementation to 2D.
Definition: BoundingBoxTree2D.h:36
double compute_squared_distance_bbox(const double *x, unsigned int node) const
Compute squared distance between point and bounding box.
Definition: BoundingBoxTree2D.h:108
const std::vector< double > & bboxes
Bounding boxes.
Definition: BoundingBoxTree2D.h:45
less_x(const std::vector< double > &bboxes)
Constructor.
Definition: BoundingBoxTree2D.h:48
less_y(const std::vector< double > &bboxes)
Constructor.
Definition: BoundingBoxTree2D.h:67
void compute_bbox_of_bboxes(double *bbox, std::size_t &axis, const std::vector< double > &leaf_bboxes, const std::vector< unsigned int >::iterator &begin, const std::vector< unsigned int >::iterator &end)
Compute bounding box of bounding boxes.
Definition: BoundingBoxTree2D.h:136
std::vector< double > _bbox_coordinates
List of bounding box coordinates.
Definition: GenericBoundingBoxTree.h:118
const std::vector< double > & bboxes
Bounding boxes.
Definition: BoundingBoxTree2D.h:64
Definition: BoundingBoxTree2D.h:61