33 #ifndef __H__UG__lg_ntree__
34 #define __H__UG__lg_ntree__
45 template <
int world_dim>
66 "Make sure to pass an instance of NTreeGridData to lg_ntree::set_common_data");
81 template <
int tree_dim,
int world_dim,
class elem_t_,
class common_data_t_>
94 commonData.grid_ptr()->associated_elements(vrts, e);
96 assert(vrts.
size() > 0);
97 centerOut = commonData.position(vrts[0]);
98 for(
size_t i = 1; i < vrts.
size(); ++i)
99 VecAdd(centerOut, centerOut, commonData.position(vrts[i]));
107 commonData.grid_ptr()->associated_elements(vrts, e);
109 assert(vrts.
size() > 0);
110 boxOut.
min = boxOut.
max = commonData.position(vrts[0]);
111 for(
size_t i = 1; i < vrts.
size(); ++i)
112 boxOut =
box_t(boxOut, commonData.position(vrts[i]));
137 for(
int i = 0; i < world_dim; ++i){
138 if(box1.
min[i] > box2.
max[i] || box1.
max[i] < box2.
min[i])
154 boxOut =
box_t(box1, box2);
160 return ContainsPoint(e, point, commonData.position_accessor());
183 UG_THROW(
"intersects_ray not yet implemented for vertices");
195 UG_COND_THROW(!cd.grid_ptr(),
"No grid assigned to ntree::common_data.");
197 e, *cd.grid_ptr(), cd.position_accessor(),
209 UG_COND_THROW(!cd.grid_ptr(),
"No grid assigned to ntree::common_data.");
211 e, *cd.grid_ptr(), cd.position_accessor(),
223 UG_COND_THROW(!cd.grid_ptr(),
"No grid assigned to ntree::common_data.");
225 e, *cd.grid_ptr(), cd.position_accessor(),
231 template <
class elem_t>
240 boxesOut[0] =
box_t(box.
min, splitPoint);
241 boxesOut[1] =
box_t(splitPoint, box.
max);
246 template <
class elem_t>
255 vector_t splitPointYMin = splitPoint;
256 splitPointYMin.y() = box.
min.y();
257 vector_t splitPointYMax = splitPoint;
258 splitPointYMax.y() = box.
max.y();
259 boxesOut[0] =
box_t(box.
min, splitPointYMax);
260 boxesOut[1] =
box_t(splitPointYMin, box.
max);
265 template <
class elem_t>
274 boxesOut[0] =
box_t(box.
min, splitPoint);
279 boxesOut[3] =
box_t(splitPoint, box.
max);
284 template <
class elem_t>
293 vector_t splitPointZMin = splitPoint;
294 splitPointZMin.z() = box.
min.z();
295 vector_t splitPointZMax = splitPoint;
296 splitPointZMax.z() = box.
max.z();
298 boxesOut[0] =
box_t(box.
min, splitPointZMax);
303 boxesOut[3] =
box_t(splitPointZMin, box.
max);
307 template <
class elem_t>
316 boxesOut[0] =
box_t(box.
min, splitPoint);
318 vector_t(box.
max.x(), splitPoint.y(), splitPoint.z()));
320 vector_t(splitPoint.x(), box.
max.y(), splitPoint.z()));
325 vector_t(splitPoint.x(), splitPoint.y(), box.
max.z()));
330 boxesOut[7] =
box_t(splitPoint, box.
max);
336 template <
int tree_dim,
int world_dim,
class gr
id_elem_t>
337 class lg_ntree :
public ntree<tree_dim, world_dim, grid_elem_t*, NTreeGridData<world_dim> >
355 template <
class TIterator>
362 while(elemsBegin != elemsEnd){
bool valid() const
Definition: attachment_pipe.h:553
A generic specialization of IAttachment.
Definition: attachment_pipe.h:263
Base-class for edges.
Definition: grid_base_objects.h:397
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
bool access(Grid &grid, TAttachment &a)
Definition: grid.h:189
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
bool has_vertex_attachment(IAttachment &attachment)
Definition: grid.h:798
void attach_to_vertices(IAttachment &attachment, bool passOnValues)
Definition: grid.h:728
a mathematical Vector with N entries.
Definition: math_vector.h:97
Definition: lg_ntree.h:47
Attachment< position_t > position_attachment_t
Definition: lg_ntree.h:50
position_accessor_t m_aaPos
Definition: lg_ntree.h:75
Grid::VertexAttachmentAccessor< position_attachment_t > position_accessor_t
Definition: lg_ntree.h:51
const position_t & position(Vertex *v) const
Definition: lg_ntree.h:63
Grid * grid_ptr() const
Definition: lg_ntree.h:72
Grid * m_pGrid
Definition: lg_ntree.h:76
position_accessor_t position_accessor() const
Definition: lg_ntree.h:70
MathVector< world_dim > position_t
Definition: lg_ntree.h:49
NTreeGridData(Grid &grid, position_attachment_t aPos)
Definition: lg_ntree.h:55
NTreeGridData()
Definition: lg_ntree.h:53
Container which holds an array of pointers.
Definition: pointer_const_array.h:84
size_t size() const
returns the size of the associated array.
Definition: pointer_const_array_impl.hpp:106
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
Volumes are 3-dimensional objects.
Definition: grid_base_objects.h:754
Definition: lg_ntree.h:338
NTreeGridData< world_dim >::position_attachment_t position_attachment_t
Definition: lg_ntree.h:341
lg_ntree(Grid &grid, position_attachment_t aPos)
Definition: lg_ntree.h:346
lg_ntree()
Definition: lg_ntree.h:343
ntree< tree_dim, world_dim, grid_elem_t *, NTreeGridData< world_dim > > base_t
Definition: lg_ntree.h:340
NTreeGridData< world_dim > m_gridData
Definition: lg_ntree.h:371
void set_grid(Grid &grid, position_attachment_t aPos)
Definition: lg_ntree.h:350
void create_tree(TIterator elemsBegin, TIterator elemsEnd)
Definition: lg_ntree.h:356
The n-tree class can be used to construct space partitioning trees of dimensions 1,...
Definition: ntree.h:163
void add_element(const elem_t &elem)
adds an element to the tree.
Definition: ntree_impl.hpp:124
void clear()
Definition: ntree_impl.hpp:62
void rebalance()
rebalances the whole tree
Definition: ntree_impl.hpp:161
void set_common_data(const common_data_t &commonData)
sets the common-data which the tree passes on to callback methods
Definition: ntree_impl.hpp:86
UG_API bool ContainsPoint(const EdgeVertices *e, const vector_t &p, TAAPos aaPos)
Returns true if the given point lies on the given edge.
Definition: edge_util_impl.hpp:513
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define UG_THROW(msg)
Definition: error.h:57
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
double number
Definition: types.h:124
bool RayBoxIntersection(const vector_t &rayFrom, const vector_t &rayDir, const vector_t &boxMin, const vector_t &boxMax, number *tNearOut=NULL, number *tFarOut=NULL)
checks if a ray is intersecting a box
Definition: math_util_impl.hpp:754
void VecSubtract(vector_t &vOut, const vector_t &v1, const vector_t &v2)
subtracts v2 from v1 and stores the result in a vOut
Definition: math_vector_functions_common_impl.hpp:226
void VecAdd(vector_t &vOut, const vector_t &v1, const vector_t &v2)
adds two MathVector<N>s and stores the result in a third one
Definition: math_vector_functions_common_impl.hpp:185
void VecScale(vector_t &vOut, const vector_t &v, typename vector_t::value_type s)
scales a MathVector<N>
Definition: math_vector_functions_common_impl.hpp:252
const number SMALL
Definition: math_constants.h:41
bool RayElementIntersection(number &sminOut, number &smaxOut, const vector2 &from, const vector2 &dir, Edge *e, Grid &, Grid::VertexAttachmentAccessor< AVector2 > aaPos, number sml)
2d ray-element intersection for edges
Definition: ray_element_intersection_util.cpp:83
vector_t min
Definition: shapes.h:88
vector_t max
Definition: shapes.h:89
bool contains_point(const vector_t &point) const
returns true if the given point lies in the box or on its boundary
Definition: shapes_impl.h:120
Definition: lg_ntree.h:83
static bool intersects_ray(Edge *e, const vector_t &rayFrom, const vector_t &rayDir, const common_data_t &cd, number &s0out, number &s1out, number sml=SMALL)
Definition: lg_ntree.h:187
MathVector< world_dim > vector_t
Definition: lg_ntree.h:85
static bool intersects_ray(Vertex *e, const vector_t &rayFrom, const vector_t &rayDir, const common_data_t &cd, number &s0out, number &s1out)
Definition: lg_ntree.h:176
elem_t_ elem_t
Definition: lg_ntree.h:88
static void calculate_center(vector_t ¢erOut, const elem_t &e, const common_data_t &commonData)
Definition: lg_ntree.h:90
static void calculate_bounding_box(box_t &boxOut, const elem_t &e, const common_data_t &commonData)
Definition: lg_ntree.h:103
static bool intersects_ray(Face *e, const vector_t &rayFrom, const vector_t &rayDir, const common_data_t &cd, number &s0out, number &s1out, number sml=SMALL)
Definition: lg_ntree.h:201
number real_t
Definition: lg_ntree.h:84
static bool contains_point(const elem_t &e, const vector_t &point, const common_data_t &commonData)
Definition: lg_ntree.h:157
static void merge_boxes(box_t &boxOut, const box_t &box1, const box_t &box2)
returns the smallest box that contains both box1 and box2
Definition: lg_ntree.h:152
AABox< vector_t > box_t
Definition: lg_ntree.h:86
static bool intersects_ray(Volume *e, const vector_t &rayFrom, const vector_t &rayDir, const common_data_t &cd, number &s0out, number &s1out, number sml=SMALL)
Definition: lg_ntree.h:215
static bool box_box_intersection(const box_t &box1, const box_t &box2)
returns true if the given boxes intersect
Definition: lg_ntree.h:135
common_data_t_ common_data_t
Definition: lg_ntree.h:87
static bool box_contains_point(const box_t &box, const vector_t &point)
Definition: lg_ntree.h:129
static void grow_box(box_t &boxOut, const box_t &box, const vector_t &offset)
Definition: lg_ntree.h:115
static bool ray_box_intersection(const vector_t &from, const vector_t &dir, const box_t &box)
Definition: lg_ntree.h:144
static vector_t box_diagonal(const box_t &box)
Definition: lg_ntree.h:122
MathVector< 1 > vector_t
Definition: lg_ntree.h:235
static void split_box(box_t *boxesOut, const box_t &box, const vector_t &splitPoint)
Definition: lg_ntree.h:238
AABox< vector_t > box_t
Definition: lg_ntree.h:236
static void split_box(box_t *boxesOut, const box_t &box, const vector_t &splitPoint)
Definition: lg_ntree.h:253
AABox< vector_t > box_t
Definition: lg_ntree.h:251
MathVector< 2 > vector_t
Definition: lg_ntree.h:250
static void split_box(box_t *boxesOut, const box_t &box, const vector_t &splitPoint)
Definition: lg_ntree.h:272
AABox< vector_t > box_t
Definition: lg_ntree.h:270
MathVector< 2 > vector_t
Definition: lg_ntree.h:269
MathVector< 3 > vector_t
Definition: lg_ntree.h:288
AABox< vector_t > box_t
Definition: lg_ntree.h:289
static void split_box(box_t *boxesOut, const box_t &box, const vector_t &splitPoint)
Definition: lg_ntree.h:291
static void split_box(box_t *boxesOut, const box_t &box, const vector_t &splitPoint)
Definition: lg_ntree.h:314
MathVector< 3 > vector_t
Definition: lg_ntree.h:311
AABox< vector_t > box_t
Definition: lg_ntree.h:312
int vector_t
Definition: ntree.h:51
int box_t
Definition: ntree.h:52