treeDataCell.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::treeDataCell
26 
27 Description
28  Encapsulation of data needed to search in/for cells. Used to find the
29  cell containing a point (e.g. cell-cell mapping).
30 
31 SourceFiles
32  treeDataCell.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef treeDataCell_H
37 #define treeDataCell_H
38 
39 #include "polyMesh.H"
40 #include "treeBoundBoxList.H"
41 #include "volumeType.H"
42 #include "pointInCell.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward declaration of classes
50 template<class Type> class indexedOctree;
51 
52 /*---------------------------------------------------------------------------*\
53  Class treeDataCell Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 class treeDataCell
57 {
58  // Private Data
59 
60  //- Reference to the mesh
61  const polyMesh& mesh_;
62 
63  //- Subset of cells to work on
64  const labelList cellLabels_;
65 
66  //- Whether to precalculate and store cell bounding box
67  const bool cacheBb_;
68 
69  //- Cell bounding boxes (valid only if cacheBb_)
70  treeBoundBoxList bbs_;
71 
72 
73  // Private Member Functions
74 
75  //- Initialise all member data
76  void update();
77 
78 
79 public:
80 
81 
82  class findNearestOp
83  {
84  const indexedOctree<treeDataCell>& tree_;
85 
86  public:
87 
89 
90  void operator()
91  (
92  const labelUList& indices,
93  const point& sample,
94 
95  scalar& nearestDistSqr,
96  label& minIndex,
97  point& nearestPoint
98  ) const;
99 
100  void operator()
101  (
102  const labelUList& indices,
103  const linePointRef& ln,
104 
105  treeBoundBox& tightest,
106  label& minIndex,
107  point& linePoint,
108  point& nearestPoint
109  ) const;
110  };
111 
112 
113  class findIntersectOp
114  {
115  const indexedOctree<treeDataCell>& tree_;
116 
117  public:
118 
120 
121  bool operator()
122  (
123  const label index,
124  const point& start,
125  const point& end,
126  point& intersectionPoint
127  ) const;
128  };
129 
130 
131  // Declare name of the class and its debug switch
132  ClassName("treeDataCell");
133 
134 
135  // Constructors
136 
137  //- Construct from mesh and subset of cells.
138  treeDataCell(const bool cacheBb, const polyMesh&, const labelUList&);
139 
140  //- Move construct from mesh and subset of cells, transferring contents
141  treeDataCell(const bool cacheBb, const polyMesh&, labelList&&);
142 
143  //- Construct from mesh. Uses all cells in mesh.
144  treeDataCell(const bool cacheBb, const polyMesh&);
145 
146 
147  // Member Functions
148 
149  // Access
150 
151  inline const labelList& cellLabels() const
152  {
153  return cellLabels_;
154  }
155 
156  inline const polyMesh& mesh() const
157  {
158  return mesh_;
159  }
160 
161  inline label size() const
162  {
163  return cellLabels_.size();
164  }
165 
166  //- Get representative point cloud for all shapes inside
167  // (one point per shape)
168  pointField shapePoints() const;
169 
170 
171  // Search
172 
173  //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
174  // Only makes sense for closed surfaces.
176  (
178  const point&
179  ) const
180  {
182  return volumeType::unknown;
183  }
184 
185  //- Does (bb of) shape at index overlap bb
186  bool overlaps
187  (
188  const label index,
189  const treeBoundBox& sampleBb
190  ) const;
191 
192  //- Does shape at index contain sample?
193  bool contains
194  (
195  const label index,
196  const point& sample,
197  const pointInCellShapes
198  ) const;
199 };
200 
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 } // End namespace Foam
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 
209 #endif
210 
211 // ************************************************************************* //
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Non-pointer based hierarchical recursive searching.
Definition: indexedOctree.H:72
A line primitive.
Definition: line.H:71
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:90
findIntersectOp(const indexedOctree< treeDataCell > &tree)
Definition: treeDataCell.C:118
findNearestOp(const indexedOctree< treeDataCell > &tree)
Definition: treeDataCell.C:109
Encapsulation of data needed to search in/for cells. Used to find the cell containing a point (e....
Definition: treeDataCell.H:56
bool overlaps(const label index, const treeBoundBox &sampleBb) const
Does (bb of) shape at index overlap bb.
Definition: treeDataCell.C:142
ClassName("treeDataCell")
treeDataCell(const bool cacheBb, const polyMesh &, const labelUList &)
Construct from mesh and subset of cells.
Definition: treeDataCell.C:65
bool contains(const label index, const point &sample, const pointInCellShapes) const
Does shape at index contain sample?
Definition: treeDataCell.C:166
volumeType getVolumeType(const indexedOctree< treeDataCell > &, const point &) const
Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
Definition: treeDataCell.H:175
label size() const
Definition: treeDataCell.H:160
const labelList & cellLabels() const
Definition: treeDataCell.H:150
const polyMesh & mesh() const
Definition: treeDataCell.H:155
pointField shapePoints() const
Get representative point cloud for all shapes inside.
Definition: treeDataCell.C:128
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
pointInCellShapes
Enumeration for the sub-shapes used to perform the inside calculation.
Definition: pointInCell.H:52
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition: POSIX.C:908
Function for determining if a point is within a cell of a polyMesh.