10#include "../d3f_sss.h"
22 for (
int d = 0; d < dim; ++d)
24 if (a.max[d] < b.min[d] || a.min[d] > b.max[d])
39 for (
int d = 0; d < dim; ++d)
41 if (other.min[d] < bbox.min[d]) bbox.min[d] = other.min[d];
42 if (other.max[d] > bbox.max[d]) bbox.max[d] = other.max[d];
54 number max_len = box.max[0] - box.min[0];
56 for (
int d = 1; d < dim; ++d)
58 number len = box.max[d] - box.min[d];
78 for (
int d = 0; d < dim; ++d)
115template <
int dim,
typename TLineData>
126 std::vector<size_t> ids(lines.size());
127 for (
size_t i = 0; i < ids.size(); ++i)
138 std::vector<size_t>& out)
const
151 std::vector<size_t>& ids,
159 node->bbox = LineBoundingBox<dim>(
160 lines[ids[0]]->from_position(),
161 lines[ids[0]]->to_position());
163 for (
size_t i = 1; i < ids.size(); ++i)
166 lines[ids[i]]->from_position(),
167 lines[ids[i]]->to_position());
168 expand_bbox<dim>(node->bbox, bb);
180 int axis = longest_axis<dim>(node->bbox);
182 std::sort(ids.begin(), ids.end(),
183 [&](
size_t a,
size_t b)
185 return lines[a]->from_position()[axis] <
186 lines[b]->from_position()[axis];
190 size_t mid = ids.size() / 2;
191 std::vector<size_t> left(ids.begin(), ids.begin() + mid);
192 std::vector<size_t> right(ids.begin() + mid, ids.end());
194 node->left =
build_node(lines, left, depth + 1);
195 node->right =
build_node(lines, right, depth + 1);
204 std::vector<size_t>& out)
const
207 if (!node || !boxes_overlap<dim>(node->
bbox, box))
213 out.insert(out.end(),
232 template <
int dim,
typename TPo
intData,
typename TLineData = TPo
intData>
240 std::vector<SmartPtr<point_sss_type>>
ListP;
241 std::vector<SmartPtr<line_sss_type>>
ListL;
273 template <
typename TElem,
typename TAAPos,
typename TFVGeom>
parameterString p
Definition Biogas.lua:1
Iterator class to traverse line segments that intersect a specific grid element.
Definition river_sss.h:275
void advance()
Filters the BVH candidates to find true geometric intersections.
Definition river_sss.h:335
const MathVector< dim > & seg_start() const
Definition river_sss.h:321
TAAPos & m_aaPos
Definition river_sss.h:284
const MathVector< dim > & seg_end() const
Definition river_sss.h:322
std::vector< size_t > m_candidates
Potential matches identified by the BVH.
Definition river_sss.h:279
Grid & m_grid
Definition river_sss.h:283
MathVector< dim > m_ls
Definition river_sss.h:288
MathVector< dim > m_le
Definition river_sss.h:288
line_sss_type * operator*()
Definition river_sss.h:316
size_t m_co
Definition river_sss.h:286
bool is_over() const
Definition river_sss.h:314
const TFVGeom & m_geo
Definition river_sss.h:285
size_t m_pos
Current position in the candidate list.
Definition river_sss.h:280
TElem * m_elem
Definition river_sss.h:282
line_iterator & operator++()
Definition river_sss.h:324
master_type * m_sss
Definition river_sss.h:278
line_iterator(master_type *sss, TElem *elem, Grid &grid, TAAPos &aaPos, const TFVGeom &geo, size_t co)
Initializes the iterator and performs the initial spatial query.
Definition river_sss.h:294
Manager for Singular Sources and Sinks (SSS) using a BVH for spatial optimization.
Definition river_sss.h:234
std::vector< SmartPtr< point_sss_type > > ListP
List of point sources/sinks.
Definition river_sss.h:240
void build_spatial_index()
(Re)builds the spatial index for line segments.
Definition river_sss.h:261
line_sss_type * line(size_t i)
Definition river_sss.h:268
void add_point(SmartPtr< point_sss_type > p)
Definition river_sss.h:247
void add_line(SmartPtr< line_sss_type > l)
Definition river_sss.h:252
size_t num_lines() const
Definition river_sss.h:267
std::vector< SmartPtr< line_sss_type > > ListL
List of line sources/sinks.
Definition river_sss.h:241
LineBVHTree< dim, TLineData > m_bvh
The spatial index.
Definition river_sss.h:243
bool m_bvh_valid
Flag to track if the index needs rebuilding.
Definition river_sss.h:244
A Bounding Volume Hierarchy tree for efficient spatial querying of line segments.
Definition river_sss.h:117
SmartPtr< LineBVHNode< dim > > build_node(std::vector< SmartPtr< line_type > > &lines, std::vector< size_t > &ids, int depth)
Internal recursive function to build the tree nodes.
Definition river_sss.h:150
SmartPtr< LineBVHNode< dim > > m_root
Definition river_sss.h:144
void query_node(const LineBVHNode< dim > *node, const AABox< MathVector< dim > > &box, std::vector< size_t > &out) const
Internal recursive function for spatial querying.
Definition river_sss.h:202
void build(std::vector< SmartPtr< line_type > > &lines)
Builds the BVH from a vector of line segments.
Definition river_sss.h:124
void query(const AABox< MathVector< dim > > &box, std::vector< size_t > &out) const
Finds all line segments whose bounding boxes potentially overlap with the query box.
Definition river_sss.h:137
Specialization of the optimized SSS manager for river networks.
Definition river_sss.h:357
void CalculateBoundingBox(size_t npoints, const MathVector< dim > points[], MathVector< dim > &vMinBB, MathVector< dim > &vMaxBB)
bool boxes_overlap(const AABox< MathVector< dim > > &a, const AABox< MathVector< dim > > &b)
Checks if two Axis-Aligned Bounding Boxes (AABox) overlap.
Definition river_sss.h:19
void expand_bbox(AABox< MathVector< dim > > &bbox, const AABox< MathVector< dim > > &other)
Expands a bounding box to include another.
Definition river_sss.h:36
int longest_axis(const AABox< MathVector< dim > > &box)
Identifies the axis along which the bounding box has the largest extent. Used as a heuristic for spli...
Definition river_sss.h:51
AABox< MathVector< dim > > LineBoundingBox(const MathVector< dim > &a, const MathVector< dim > &b)
Computes the Axis-Aligned Bounding Box for a line segment.
Definition river_sss.h:73
SmartPtr< T, FreePolicy > make_sp(T *inst)
Node structure for the Bounding Volume Hierarchy (BVH).
Definition river_sss.h:100
SmartPtr< LineBVHNode > right
Right child node.
Definition river_sss.h:104
SmartPtr< LineBVHNode > left
Left child node.
Definition river_sss.h:103
std::vector< size_t > indices
Leaf only: indices into the original line list.
Definition river_sss.h:102
AABox< MathVector< dim > > bbox
Total bounding box of all lines in this node/subtree.
Definition river_sss.h:101
bool is_leaf() const
Definition river_sss.h:106