21 #ifndef __BOUNDING_BOX_TREE_3D_H 22 #define __BOUNDING_BOX_TREE_3D_H 26 #include <dolfin/common/constants.h> 27 #include "GenericBoundingBoxTree.h" 49 less_x_bbox(
const std::vector<double>& bboxes): bboxes(bboxes) {}
54 const double* bi = bboxes.data() + 6*i;
55 const double* bj = bboxes.data() + 6*j;
56 return bi[0] + bi[3] < bj[0] + bj[3];
67 less_y_bbox(
const std::vector<double>& bboxes): bboxes(bboxes) {}
72 const double* bi = bboxes.data() + 6*i;
73 const double* bj = bboxes.data() + 6*j;
74 return bi[1] + bi[4] < bj[1] + bj[4];
85 less_z_bbox(
const std::vector<double>& bboxes): bboxes(bboxes) {}
90 const double* bi = bboxes.data() + 6*i;
91 const double* bj = bboxes.data() + 6*j;
92 return bi[2] + bi[5] < bj[2] + bj[5];
97 std::size_t
gdim()
const {
return 3; }
109 const double eps0 = DOLFIN_EPS_LARGE*(b[3] - b[0]);
110 const double eps1 = DOLFIN_EPS_LARGE*(b[4] - b[1]);
111 const double eps2 = DOLFIN_EPS_LARGE*(b[5] - b[2]);
112 return (b[0] - eps0 <= x[0] && x[0] <= b[3] + eps0 &&
113 b[1] - eps1 <= x[1] && x[1] <= b[4] + eps1 &&
114 b[2] - eps2 <= x[2] && x[2] <= b[5] + eps2);
121 const double eps0 = DOLFIN_EPS_LARGE*(b[3] - b[0]);
122 const double eps1 = DOLFIN_EPS_LARGE*(b[4] - b[1]);
123 const double eps2 = DOLFIN_EPS_LARGE*(b[5] - b[2]);
124 return (b[0] - eps0 <= a[3] && a[0] <= b[3] + eps0 &&
125 b[1] - eps1 <= a[4] && a[1] <= b[4] + eps1 &&
126 b[2] - eps2 <= a[5] && a[2] <= b[5] + eps2);
131 unsigned int node)
const 141 if (x[0] < b[0]) r2 += (x[0] - b[0])*(x[0] - b[0]);
142 if (x[0] > b[3]) r2 += (x[0] - b[3])*(x[0] - b[3]);
143 if (x[1] < b[1]) r2 += (x[1] - b[1])*(x[1] - b[1]);
144 if (x[1] > b[4]) r2 += (x[1] - b[4])*(x[1] - b[4]);
145 if (x[2] < b[2]) r2 += (x[2] - b[2])*(x[2] - b[2]);
146 if (x[2] > b[5]) r2 += (x[2] - b[5])*(x[2] - b[5]);
153 unsigned int node)
const 156 return ((x[0] - p[0])*(x[0] - p[0]) +
157 (x[1] - p[1])*(x[1] - p[1]) +
158 (x[2] - p[2])*(x[2] - p[2]));
164 const std::vector<double>& leaf_bboxes,
165 const std::vector<unsigned int>::iterator&
begin,
166 const std::vector<unsigned int>::iterator&
end)
168 typedef std::vector<unsigned int>::const_iterator iterator;
172 const double* b = leaf_bboxes.data() + 6*(*it);
181 for (; it !=
end; ++it)
183 const double* b = leaf_bboxes.data() + 6*(*it);
184 if (b[0] < bbox[0]) bbox[0] = b[0];
185 if (b[1] < bbox[1]) bbox[1] = b[1];
186 if (b[2] < bbox[2]) bbox[2] = b[2];
187 if (b[3] > bbox[3]) bbox[3] = b[3];
188 if (b[4] > bbox[4]) bbox[4] = b[4];
189 if (b[5] > bbox[5]) bbox[5] = b[5];
193 const double x = bbox[3] - bbox[0];
194 const double y = bbox[4] - bbox[1];
195 const double z = bbox[5] - bbox[2];
208 const std::vector<Point>& points,
209 const std::vector<unsigned int>::iterator&
begin,
210 const std::vector<unsigned int>::iterator&
end)
212 typedef std::vector<unsigned int>::const_iterator iterator;
216 const double* p = points[*it].coordinates();
225 for (++it; it !=
end; ++it)
227 const double* p = points[*it].coordinates();
228 if (p[0] < bbox[0]) bbox[0] = p[0];
229 if (p[1] < bbox[1]) bbox[1] = p[1];
230 if (p[2] < bbox[2]) bbox[2] = p[2];
231 if (p[0] > bbox[3]) bbox[3] = p[0];
232 if (p[1] > bbox[4]) bbox[4] = p[1];
233 if (p[2] > bbox[5]) bbox[5] = p[2];
237 const double x = bbox[3] - bbox[0];
238 const double y = bbox[4] - bbox[1];
239 const double z = bbox[5] - bbox[2];
251 const std::vector<double>& leaf_bboxes,
252 const std::vector<unsigned int>::iterator&
begin,
253 const std::vector<unsigned int>::iterator& middle,
254 const std::vector<unsigned int>::iterator&
end)
259 std::nth_element(begin, middle, end,
less_x_bbox(leaf_bboxes));
262 std::nth_element(begin, middle, end,
less_y_bbox(leaf_bboxes));
265 std::nth_element(begin, middle, end,
less_z_bbox(leaf_bboxes));
double compute_squared_distance_point(const double *x, unsigned int node) const
Compute squared distance between point and point.
Definition: BoundingBoxTree3D.h:152
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: BoundingBoxTree3D.h:162
std::size_t gdim() const
Return geometric dimension.
Definition: BoundingBoxTree3D.h:97
Definition: GenericBoundingBoxTree.h:40
void begin(std::string msg,...)
Begin task (increase indentation level)
Definition: log.cpp:153
less_x_bbox(const std::vector< double > &bboxes)
Constructor.
Definition: BoundingBoxTree3D.h:49
bool operator()(unsigned int i, unsigned int j)
Comparison operator.
Definition: BoundingBoxTree3D.h:88
Less than operator in z-direction.
Definition: BoundingBoxTree3D.h:79
less_y_bbox(const std::vector< double > &bboxes)
Constructor.
Definition: BoundingBoxTree3D.h:67
const std::vector< double > & bboxes
Bounding boxes.
Definition: BoundingBoxTree3D.h:64
const double * get_bbox_coordinates(unsigned int node) const
Return bounding box coordinates for node.
Definition: BoundingBoxTree3D.h:100
const std::vector< double > & bboxes
Bounding boxes.
Definition: BoundingBoxTree3D.h:82
void end()
End task (decrease indentation level)
Definition: log.cpp:168
Less than operator in y-direction.
Definition: BoundingBoxTree3D.h:61
bool operator()(unsigned int i, unsigned int j)
Comparison operator.
Definition: BoundingBoxTree3D.h:52
double compute_squared_distance_bbox(const double *x, unsigned int node) const
Compute squared distance between point and bounding box.
Definition: BoundingBoxTree3D.h:130
bool point_in_bbox(const double *x, const unsigned int node) const
Check whether point (x) is in bounding box (node)
Definition: BoundingBoxTree3D.h:106
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: BoundingBoxTree3D.h:250
less_z_bbox(const std::vector< double > &bboxes)
Constructor.
Definition: BoundingBoxTree3D.h:85
bool operator()(unsigned int i, unsigned int j)
Comparison operator.
Definition: BoundingBoxTree3D.h:70
Comparison operators for sorting of bounding boxes.
Definition: BoundingBoxTree3D.h:43
bool bbox_in_bbox(const double *a, unsigned int node) const
Check whether bounding box (a) collides with bounding box (node)
Definition: BoundingBoxTree3D.h:118
std::vector< double > _bbox_coordinates
List of bounding box coordinates.
Definition: GenericBoundingBoxTree.h:118
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: BoundingBoxTree3D.h:206
const std::vector< double > & bboxes
Bounding boxes.
Definition: BoundingBoxTree3D.h:46
Specialization of bounding box implementation to 3D.
Definition: BoundingBoxTree3D.h:34