TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Octree_Double.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
16#ifndef Octree_Double_included
17#define Octree_Double_included
18
19#include <Octree_Int.h>
20#include <TRUSTTab.h>
21
22/*! @brief : Un octree permettant de chercher dans l'espace des elements ou des points decrits par des coordonnees reeles.
23 *
24 * Cet objet est base sur Octree_Int.
25 * Astuces:
26 * Pour chercher des points a epsilon pres on peut faire:
27 * 1) build_nodes(coord, include_virt, 0.)
28 * suivi de
29 * search_elements_box(center, epsilon, elements);
30 *
31 * 2) build_nodes(coord, include_virt, epsilon)
32 * suivi de
33 * search_elements(x,y,z,...)
34 * La premiere solution prend plus de temps pour construire l'octree mais la recherche est plus rapide
35 * La deuxieme, c'est inverse... et on peut choisir epsilon pour chaque point.
36 *
37 */
38template <typename _SIZE_>
40{
41public:
42 using int_t = _SIZE_;
43 using ArrOfInt_t = ArrOfInt_T<_SIZE_>;
44 using IntTab_t = IntTab_T<_SIZE_>;
45 using ArrOfDouble_t = ArrOfDouble_T<_SIZE_>;
46 using DoubleTab_t = DoubleTab_T<_SIZE_>;
47
48 void reset();
49
50 template<class _TAB_TYPE_>
51 void build_elements(const _TAB_TYPE_& coords, const IntTab_t& elements, const double epsilon, const bool include_virtual);
52
53 void build_nodes(const DoubleTab_t& coords, const bool include_virtual, const double epsilon = 0.);
54 int_t search_elements(double x, double y, double z, int_t& index) const;
55 int_t search_elements_box(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax, ArrOfInt_t& elements) const;
56 static int_t search_nodes_close_to(double x, double y, double z, const DoubleTab_t& coords, ArrOfInt_t& node_list, double epsilon);
57 int_t search_elements_box(const ArrOfDouble& center, const double radius, ArrOfInt_t& elements) const;
58 static int_t search_nodes_close_to(const ArrOfDouble& point, const DoubleTab_t& coords, ArrOfInt_t& node_list, double epsilon);
59 int dimension() const
60 {
61 assert(dim_ > 0);
62 return dim_;
63 }
64 inline const ArrOfInt_t& floor_elements() const { return octree_int_.floor_elements(); }
65
66protected:
67 inline bool integer_position(double x, int direction, int& ix) const;
68 inline bool integer_position_clip(double xmin, double xmax, int& x0, int& x1, int direction) const;
69
70 template<class _TAB_TYPE_>
71 void compute_origin_factors(const _TAB_TYPE_& coords, const double epsilon, const int include_virtual);
72
74 // Ces deux tableaux sont toujours de taille 3 par commodite
75 ArrOfDouble origin_, factor_;
76 int dim_ = 0;
77};
78
79//////////////////// INLINE METHODS /////////////////////////////
80
81/*! @brief Convertit une coordonnee reelle en coordonnee entiere pour l'octree_int
82 *
83 * Valeur de retour: 1 si ok, 0 si coordonnee hors de l'octree
84 */
85template <typename _SIZE_>
86inline bool Octree_Double_32_64<_SIZE_>::integer_position(double x, int direction, int& ix) const
87{
88 const double coord_max = (double) Octree_Int_32_64<_SIZE_>::coord_max_;
89 double rnd_x = (x - origin_[direction]) * factor_[direction];
90 // 0.49 permet d'accepter une coordonnee x egale a xmin ou xmax de l'octree,
91 // sinon pour un octree cree a partir de sommets, il y a un risque
92 // de ne pas trouver les coordonnees des points qu'on avait mis au bord de l'octree.
93 if (rnd_x >= -0.49 && rnd_x <= coord_max + 0.49)
94 {
95 ix = (int) floor(rnd_x + 0.5);
96 return true;
97 }
98 return false;
99}
100
101// Valeur de retour: 1 s'il y a une intersection non vide avec l'octree, 0 sinon
102template <typename _SIZE_>
103inline bool Octree_Double_32_64<_SIZE_>::integer_position_clip(double xmin, double xmax,
104 int& x0, int& x1,
105 int direction) const
106{
107 const double coord_max = (double) Octree_Int_32_64<_SIZE_>::coord_max_;
108 xmin = (xmin - origin_[direction]) * factor_[direction];
109 xmax = (xmax - origin_[direction]) * factor_[direction];
110 // pas de marge ici comme on cherche avec une boite, l'epsilon est deja
111 // dans la dimension de la boite.
112 if (xmin > coord_max || xmax < 0.)
113 return false;
114 if (xmin < .0)
115 x0 = 0;
116 else
117 x0 = (int) (floor(xmin+0.5));
118 if (xmax > coord_max)
120 else
121 x1 = (int) (floor(xmax+0.5));
122 return true;
123}
124
125
126//////////////////// TEMPLATE METHOD IMPL ////////////////////////
127
128#include <Octree_Double.tpp>
129
130using Octree_Double = Octree_Double_32_64<int>;
131using Octree_Double_64 = Octree_Double_32_64<trustIdType>;
132
133#endif
: Un octree permettant de chercher dans l'espace des elements ou des points decrits par des coordonne...
const ArrOfInt_t & floor_elements() const
bool integer_position(double x, int direction, int &ix) const
Convertit une coordonnee reelle en coordonnee entiere pour l'octree_int.
DoubleTab_T< _SIZE_ > DoubleTab_t
void compute_origin_factors(const _TAB_TYPE_ &coords, const double epsilon, const int include_virtual)
methode outil pour build_nodes et build_elements (calcul des facteurs de conversion entre reels et en...
static int_t search_nodes_close_to(const ArrOfDouble &point, const DoubleTab_t &coords, ArrOfInt_t &node_list, double epsilon)
Idem que search_nodes_close_to(double x, double y, double z, .
int dimension() const
static int_t search_nodes_close_to(double x, double y, double z, const DoubleTab_t &coords, ArrOfInt_t &node_list, double epsilon)
Methode hors classe Cherche parmi les sommets de la liste node_list ceux qui sont a une.
ArrOfInt_T< _SIZE_ > ArrOfInt_t
bool integer_position_clip(double xmin, double xmax, int &x0, int &x1, int direction) const
int_t search_elements_box(const ArrOfDouble &center, const double radius, ArrOfInt_t &elements) const
cherche tous les elements ou points ayant potentiellement une intersection non vide avec la boite don...
void build_nodes(const DoubleTab_t &coords, const bool include_virtual, const double epsilon=0.)
construit un octree contenant les points de coordonnees coords.
Octree_Int_32_64< int > octree_int_
ArrOfDouble_T< _SIZE_ > ArrOfDouble_t
int_t search_elements(double x, double y, double z, int_t &index) const
cherche les elements ou les points contenus dans l'octree_floor qui contient le point (x,...
int_t search_elements_box(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax, ArrOfInt_t &elements) const
cherche tous les elements ou points ayant potentiellement une intersection non vide avec la boite don...
IntTab_T< _SIZE_ > IntTab_t
void build_elements(const _TAB_TYPE_ &coords, const IntTab_t &elements, const double epsilon, const bool include_virtual)
Construit un octree a partir d'elements volumiques decrits par des ensembles de sommets.
: Un octree permettant de retrouver des objets ponctuels ou parallelipipediques dans un espace 1D,...
Definition Octree_Int.h:28
static const int coord_max_
Definition Octree_Int.h:48