21 #ifndef __GENERIC_BOUNDING_BOX_TREE_H 22 #define __GENERIC_BOUNDING_BOX_TREE_H 28 #include <dolfin/geometry/Point.h> 51 static std::shared_ptr<GenericBoundingBoxTree>
create(
unsigned int dim);
54 void build(
const Mesh& mesh, std::size_t tdim);
57 void build(
const std::vector<Point>& points);
60 std::vector<unsigned int>
64 std::pair<std::vector<unsigned int>, std::vector<unsigned int> >
68 std::vector<unsigned int>
70 const Mesh& mesh)
const;
73 std::vector<unsigned int>
77 std::pair<std::vector<unsigned int>, std::vector<unsigned int> >
79 const Mesh& mesh_A,
const Mesh& mesh_B)
const;
86 const Mesh& mesh)
const;
90 const Mesh& mesh)
const;
96 std::string
str(
bool verbose=
false);
132 unsigned int _build(
const std::vector<double>& leaf_bboxes,
133 const std::vector<unsigned int>::iterator&
begin,
134 const std::vector<unsigned int>::iterator&
end,
138 unsigned int _build(
const std::vector<Point>& points,
139 const std::vector<unsigned int>::iterator&
begin,
140 const std::vector<unsigned int>::iterator&
end,
153 std::vector<unsigned int>& entities,
162 std::vector<unsigned int>& entities_A,
163 std::vector<unsigned int>& entities_B,
185 unsigned int& closest_entity,
193 unsigned int& closest_point,
204 std::size_t
gdim)
const;
208 const std::vector<Point>& points,
209 const std::vector<unsigned int>::iterator&
begin,
210 const std::vector<unsigned int>::iterator& middle,
211 const std::vector<unsigned int>::iterator&
end);
219 _bboxes.push_back(bbox);
222 for (std::size_t i = 0; i < 2*
gdim; ++i)
223 _bbox_coordinates.push_back(b[i]);
225 return _bboxes.size() - 1;
231 return _bboxes[node];
237 return _bboxes.size();
246 _bboxes.push_back(bbox);
250 for (std::size_t i = 0; i <
gdim; ++i)
251 _bbox_coordinates.push_back(x[i]);
252 for (std::size_t i = 0; i <
gdim; ++i)
253 _bbox_coordinates.push_back(x[i]);
255 return _bboxes.size() - 1;
279 const double* pi = points[i].coordinates();
280 const double* pj = points[j].coordinates();
281 return pi[0] < pj[0];
299 const double* pi = points[i].coordinates();
300 const double* pj = points[j].coordinates();
301 return pi[1] < pj[1];
319 const double* pi = points[i].coordinates();
320 const double* pj = points[j].coordinates();
321 return pi[2] < pj[2];
328 virtual std::size_t
gdim()
const = 0;
339 bbox_in_bbox(
const double* a,
unsigned int node)
const = 0;
353 const std::vector<double>& leaf_bboxes,
354 const std::vector<unsigned int>::iterator&
begin,
355 const std::vector<unsigned int>::iterator&
end) = 0;
361 const std::vector<Point>& points,
362 const std::vector<unsigned int>::iterator& begin,
363 const std::vector<unsigned int>::iterator& end) = 0;
368 const std::vector<double>& leaf_bboxes,
369 const std::vector<unsigned int>::iterator& begin,
370 const std::vector<unsigned int>::iterator& middle,
371 const std::vector<unsigned int>::iterator& end) = 0;
374 void tree_print(std::stringstream& s,
unsigned int i);
unsigned int child_0
Child 0.
Definition: GenericBoundingBoxTree.h:106
std::vector< unsigned int > compute_collisions(const Point &point) const
Compute all collisions between bounding boxes and Point
Definition: GenericBoundingBoxTree.cpp:150
unsigned int add_bbox(const BBox &bbox, const double *b, std::size_t gdim)
Add bounding box and coordinates.
Definition: GenericBoundingBoxTree.h:214
std::shared_ptr< GenericBoundingBoxTree > _global_tree
Global tree for mesh ownership of each process (same on all processes)
Definition: GenericBoundingBoxTree.h:124
std::pair< unsigned int, double > compute_closest_entity(const Point &point, const Mesh &mesh) const
Compute closest entity and distance to Point
Definition: GenericBoundingBoxTree.cpp:257
Definition: GenericBoundingBoxTree.h:308
GenericBoundingBoxTree()
Constructor.
Definition: GenericBoundingBoxTree.cpp:40
std::shared_ptr< GenericBoundingBoxTree > _point_search_tree
Point search tree used to accelerate distance queries.
Definition: GenericBoundingBoxTree.h:121
Definition: GenericBoundingBoxTree.h:40
bool operator()(unsigned int i, unsigned int j)
Comparison operator.
Definition: GenericBoundingBoxTree.h:277
void begin(std::string msg,...)
Begin task (increase indentation level)
Definition: log.cpp:153
less_y_point(const std::vector< Point > &points)
Constructor.
Definition: GenericBoundingBoxTree.h:294
Definition: GenericBoundingBoxTree.h:268
virtual double compute_squared_distance_bbox(const double *x, unsigned int node) const =0
Compute squared distance between point and bounding box.
void build(const Mesh &mesh, std::size_t tdim)
Build bounding box tree for mesh entities of given dimension.
Definition: GenericBoundingBoxTree.cpp:70
std::string str(bool verbose=false)
Print out for debugging.
Definition: GenericBoundingBoxTree.cpp:778
std::pair< unsigned int, double > compute_closest_point(const Point &point) const
Compute closest point and distance to Point
Definition: GenericBoundingBoxTree.cpp:297
bool is_leaf(const BBox &bbox, unsigned int node) const
Check whether bounding box is a leaf node.
Definition: GenericBoundingBoxTree.h:259
unsigned int compute_first_collision(const Point &point) const
Compute first collision between bounding boxes and Point
Definition: GenericBoundingBoxTree.cpp:234
void sort_points(std::size_t axis, const std::vector< Point > &points, const std::vector< unsigned int >::iterator &begin, const std::vector< unsigned int >::iterator &middle, const std::vector< unsigned int >::iterator &end)
Sort points along given axis.
Definition: GenericBoundingBoxTree.cpp:759
void clear()
Clear existing data if any.
Definition: GenericBoundingBoxTree.cpp:324
void end()
End task (decrease indentation level)
Definition: log.cpp:168
const std::vector< Point > & points
Points.
Definition: GenericBoundingBoxTree.h:291
less_x_point(const std::vector< Point > &points)
Constructor.
Definition: GenericBoundingBoxTree.h:274
virtual double compute_squared_distance_point(const double *x, unsigned int node) const =0
Compute squared distance between point and point.
virtual 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)=0
Compute bounding box of points.
virtual const double * get_bbox_coordinates(unsigned int node) const =0
Return bounding box coordinates for node.
std::size_t _tdim
Topological dimension of leaf entities.
Definition: GenericBoundingBoxTree.h:112
virtual bool point_in_bbox(const double *x, unsigned int node) const =0
Check whether point (x) is in bounding box (node)
const std::vector< Point > & points
Points.
Definition: GenericBoundingBoxTree.h:271
virtual bool bbox_in_bbox(const double *a, unsigned int node) const =0
Check whether bounding box (a) collides with bounding box (node)
std::vector< unsigned int > compute_process_collisions(const Point &point) const
Compute all collisions between processes and Point
Definition: GenericBoundingBoxTree.cpp:199
Definition: GenericBoundingBoxTree.h:103
virtual 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)=0
Compute bounding box of bounding boxes.
unsigned int child_1
Child 1.
Definition: GenericBoundingBoxTree.h:108
double * coordinates()
Definition: Point.h:132
virtual ~GenericBoundingBoxTree()
Destructor.
Definition: GenericBoundingBoxTree.h:48
unsigned int compute_first_entity_collision(const Point &point, const Mesh &mesh) const
Compute first collision between entities and Point
Definition: GenericBoundingBoxTree.cpp:241
std::vector< unsigned int > compute_entity_collisions(const Point &point, const Mesh &mesh) const
Compute all collisions between entities and Point
Definition: GenericBoundingBoxTree.cpp:180
Definition: MeshEntity.h:42
Definition: GenericBoundingBoxTree.h:288
unsigned int add_point(const BBox &bbox, const Point &point, std::size_t gdim)
Add bounding box and point coordinates.
Definition: GenericBoundingBoxTree.h:241
void compute_bbox_of_entity(double *b, const MeshEntity &entity, std::size_t gdim) const
Compute bounding box of mesh entity.
Definition: GenericBoundingBoxTree.cpp:727
static std::shared_ptr< GenericBoundingBoxTree > create(unsigned int dim)
Factory function returning (empty) tree of appropriate dimension.
Definition: GenericBoundingBoxTree.cpp:46
std::vector< BBox > _bboxes
List of bounding boxes (parent-child-entity relations)
Definition: GenericBoundingBoxTree.h:115
virtual 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)=0
Sort leaf bounding boxes along given axis.
bool operator()(unsigned int i, unsigned int j)
Comparison operator.
Definition: GenericBoundingBoxTree.h:297
unsigned int num_bboxes() const
Return number of bounding boxes.
Definition: GenericBoundingBoxTree.h:235
std::vector< double > _bbox_coordinates
List of bounding box coordinates.
Definition: GenericBoundingBoxTree.h:118
void tree_print(std::stringstream &s, unsigned int i)
Print out recursively, for debugging.
Definition: GenericBoundingBoxTree.cpp:785
bool operator()(unsigned int i, unsigned int j)
Comparison operator.
Definition: GenericBoundingBoxTree.h:317
const BBox & get_bbox(unsigned int node) const
Return bounding box for given node.
Definition: GenericBoundingBoxTree.h:229
less_z_point(const std::vector< Point > &points)
Constructor.
Definition: GenericBoundingBoxTree.h:314
virtual std::size_t gdim() const =0
Return geometric dimension.
unsigned int _build(const std::vector< double > &leaf_bboxes, const std::vector< unsigned int >::iterator &begin, const std::vector< unsigned int >::iterator &end, std::size_t gdim)
Build bounding box tree for entities (recursive)
Definition: GenericBoundingBoxTree.cpp:333
const std::vector< Point > & points
Points.
Definition: GenericBoundingBoxTree.h:311
void build_point_search_tree(const Mesh &mesh) const
Compute point search tree if not already done.
Definition: GenericBoundingBoxTree.cpp:707