TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Octree_Int.h
1/****************************************************************************
2* Copyright (c) 2024, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15#ifndef Octree_Int_included
16#define Octree_Int_included
17
18#include <TRUSTArrays.h>
19#include <TRUSTTab.h>
20#include <ArrOfBit.h>
21
22template <typename _SIZE_> struct IntBoxData;
23
24/*! @brief : An octree allowing retrieval of point-like or parallelepiped-shaped objects in 1D, 2D or 3D space with integer coordinates
25 */
26template <typename _SIZE_>
28{
29public:
30 using int_t = _SIZE_;
31 using ArrOfInt_t = ArrOfInt_T<_SIZE_>;
32 using IntTab_t = IntTab_T<_SIZE_>;
33 using ArrOfDouble_t= ArrOfDouble_T<_SIZE_>;
34 using DoubleTab_t = DoubleTab_T<_SIZE_>;
35 using ArrsOfInt_t = ArrsOfInt_T<_SIZE_>;
37 using AOFlagS_ = TRUST_Vector<AOFlag_>; // A vector of arrays of small values (flags here)
38
39
40 void build(const int dimension, const IntTab_t& elements_boxes);
41 int_t search_elements(int x, int y, int z, int_t& floor_elements_index) const;
42 int_t search_elements_box(int xmin, int ymin, int zmin, int xmax, int ymax, int zmax, ArrOfInt_t& elements) const;
43 void reset();
44
45 inline const ArrOfInt_t& floor_elements() const { return floor_elements_; }
46
47 // The largest int allowed for coordinates (of the form 2^n - 1)
48 static const int coord_max_;
49 // First int of the upper half of the root octree (if coord_max_=2^n-1, half_width_=2^(n-1))
50 static const int root_octree_half_width_;
51
52protected:
53 int_t build_octree_recursively(const int octree_center_x, const int octree_center_y, const int octree_center_z,
54 const int octree_half_width,
55 const IntTab_t& elements_boxes,
56 ArrsOfInt_t& vect_elements_list,
57 const int level,
58 AOFlagS_& tmp_elem_flags);
59 int_t build_octree_floor(const ArrOfInt_t& elements_list);
60 int_t search_octree_floor(int x_pos, int y_pos, int z_pos) const;
61 void search_elements_box_floor(IntBoxData<_SIZE_>& boxdata, int_t octree_floor_id) const;
62 void search_elements_box_recursively(IntBoxData<_SIZE_>& boxdata, int_t octree_id, int cx, int cy, int cz, int half_width) const;
63
64 // An octree can be either empty, subdivided into nb_octrees other octrees,
65 // or an octree_floor containing a list of elements.
67
68 static inline int_t octree_id(int_t index, Octree_Type type);
69 static inline int_t octree_index(int_t octree_id, Octree_Type type);
71
72 // Octree_id of the root cube: can be EMPTY, OCTREE or FLOOR
74 // Number of stored elements (dimension(0) of the elements_boxes array)
76 // Array containing all cubes that are divided into sub-cubes.
77 // octree_structure_(i, j) describes the content of sub-cube j of cube i,
78 // for 0 <= j < number of sub-cubes per cube.
79 // An "octree_id" is a value X=octree_structure_(i,j) (octree identifier).
80 // The octree id encodes both the octree type and the index where
81 // it is stored in the arrays (see octree_id(int, Octree_Type))
83
84 // Array containing the list of elements of each final non-subdivided sub-cube.
85 // If X < 0, set i_debut = -X-1.
86 // floor_elements_(i_debut) = n = number of elements in this sub-cube
87 // floor_elements_[i_debut+j] = index of an element that crosses this sub-cube, for 1 <= j <= n
89};
90
91#endif
: An octree allowing retrieval of point-like or parallelepiped-shaped objects in 1D,...
Definition Octree_Int.h:28
int_t search_octree_floor(int x_pos, int y_pos, int z_pos) const
returns the octree_id of the octree_floor containing the vertex (x,y,z) (may return the EMPTY octree)
ArrOfDouble_T< _SIZE_ > ArrOfDouble_t
Definition Octree_Int.h:33
static Octree_Type octree_type(int_t octree_id)
Returns the type of an octree based on its octree_id.
void search_elements_box_recursively(IntBoxData< _SIZE_ > &boxdata, int_t octree_id, int cx, int cy, int cz, int half_width) const
recursively searches for elements included in the box boxdata for the given octree_id,...
int_t search_elements_box(int xmin, int ymin, int zmin, int xmax, int ymax, int zmax, ArrOfInt_t &elements) const
searches for elements potentially having a non-empty intersection with the box xmin....
ArrOfInt_T< _SIZE_ > ArrOfInt_t
Definition Octree_Int.h:31
IntTab_T< _SIZE_ > IntTab_t
Definition Octree_Int.h:32
ArrOfInt_t floor_elements_
Definition Octree_Int.h:88
int_t build_octree_recursively(const int octree_center_x, const int octree_center_y, const int octree_center_z, const int octree_half_width, const IntTab_t &elements_boxes, ArrsOfInt_t &vect_elements_list, const int level, AOFlagS_ &tmp_elem_flags)
octree_center_i is the first int of the upper half of the octree in direction i.
static const int root_octree_half_width_
Definition Octree_Int.h:50
static int_t octree_id(int_t index, Octree_Type type)
builds an octree_id (see octree_structure_)
TRUSTArray< int, _SIZE_ > AOFlag_
Definition Octree_Int.h:36
int_t root_octree_id_
Definition Octree_Int.h:73
IntTab_t octree_structure_
Definition Octree_Int.h:82
DoubleTab_T< _SIZE_ > DoubleTab_t
Definition Octree_Int.h:34
ArrsOfInt_T< _SIZE_ > ArrsOfInt_t
Definition Octree_Int.h:35
int_t search_elements(int x, int y, int z, int_t &floor_elements_index) const
returns the list of elements potentially containing the point (x,y,z). Returns n=number of elements i...
static int_t octree_index(int_t octree_id, Octree_Type type)
computes the index of the octree in octree_structure or floor_elements based on the type of the octre...
void search_elements_box_floor(IntBoxData< _SIZE_ > &boxdata, int_t octree_floor_id) const
adds elements from the octree_floor to boxdata.
const ArrOfInt_t & floor_elements() const
Definition Octree_Int.h:45
TRUST_Vector< AOFlag_ > AOFlagS_
Definition Octree_Int.h:37
static const int coord_max_
Definition Octree_Int.h:48
int_t build_octree_floor(const ArrOfInt_t &elements_list)
builds an octree_floor with the given list of elements and returns the octree_id of that octree_floor
void build(const int dimension, const IntTab_t &elements_boxes)
builds the octree.
Represents a an array of int/int64/double/... values.
Definition TRUSTArray.h:81
TRUST_Vector class.