treeDataPrimitivePatch.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-2019 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::treeDataPrimitivePatch
26 
27 Description
28  Encapsulation of data needed to search on PrimitivePatches
29 
30 SourceFiles
31  treeDataPrimitivePatch.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef treeDataPrimitivePatch_H
36 #define treeDataPrimitivePatch_H
37 
38 #include "treeBoundBoxList.H"
39 #include "volumeType.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 // Forward declaration of classes
47 template<class Type> class indexedOctree;
48 
49 
50 /*---------------------------------------------------------------------------*\
51  Class treeDataPrimitivePatchName Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 TemplateName(treeDataPrimitivePatch);
55 
56 
57 /*---------------------------------------------------------------------------*\
58  Class treeDataPrimitivePatch Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 template<class PatchType>
63 :
64  public treeDataPrimitivePatchName
65 {
66  // Private Data
67 
68  //- Underlying geometry
69  const PatchType& patch_;
70 
71  //- Whether to precalculate and store face bounding box
72  const bool cacheBb_;
73 
74  //- Tolerance to use for intersection tests
75  const scalar planarTol_;
76 
77  //- Face bounding boxes (valid only if cacheBb_)
78  treeBoundBoxList bbs_;
79 
80 
81  // Private Member Functions
82 
83  //- Calculate face bounding box
84  static treeBoundBox calcBb(const pointField&, const face&);
85 
86  //- Initialise all member data
87  void update();
88 
89 
90 public:
91 
92 
93  class findNearestOp
94  {
96 
97  public:
98 
100 
101  void operator()
102  (
103  const labelUList& indices,
104  const point& sample,
105 
106  scalar& nearestDistSqr,
107  label& minIndex,
108  point& nearestPoint
109  ) const;
110 
111  //- Calculates nearest (to line) point in shape.
112  // Returns point and distance (squared)
113  void operator()
114  (
115  const labelUList& indices,
116  const linePointRef& ln,
117 
118  treeBoundBox& tightest,
119  label& minIndex,
120  point& linePoint,
121  point& nearestPoint
122  ) const;
123  };
124 
126  class findIntersectOp
127  {
129 
130  public:
131 
133 
134  //- Calculate intersection of any face with ray. Sets result
135  // accordingly. Used to find first intersection.
136  bool operator()
137  (
138  const label index,
139  const point& start,
140  const point& end,
141  point& intersectionPoint
142  ) const;
143  };
144 
146  class findAllIntersectOp
147  {
149 
150  DynamicList<label>& shapeMask_;
151 
152  public:
153 
155  (
157  DynamicList<label>& shapeMask
158  );
159 
160  //- Calculate intersection of unique face with ray. Sets result
161  // accordingly. Used to find all faces.
162  bool operator()
163  (
164  const label index,
165  const point& start,
166  const point& end,
167  point& intersectionPoint
168  ) const;
169  };
170 
172  class findSelfIntersectOp
173  {
175 
176  const label edgeID_;
177 
178  public:
179 
181  (
183  const label edgeID
184  );
185 
186  //- Calculate intersection of face with edge of patch. Excludes
187  // faces that use edgeID. Used to find self intersection.
188  bool operator()
189  (
190  const label index,
191  const point& start,
192  const point& end,
193  point& intersectionPoint
194  ) const;
195  };
196 
197 
198  // Constructors
199 
200  //- Construct from patch.
202  (
203  const bool cacheBb,
204  const PatchType&,
205  const scalar planarTol
206  );
207 
208 
209  // Member Functions
210 
211  // Access
213  label size() const
214  {
215  return patch_.size();
216  }
217 
218  //- Get representative point cloud for all shapes inside
219  // (one point per shape)
220  pointField shapePoints() const;
221 
222  //- Return access to the underlying patch
223  const PatchType& patch() const
224  {
225  return patch_;
226  }
227 
228 
229  // Search
230 
231  //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
232  // Only makes sense for closed surfaces.
234  (
236  const point&
237  ) const;
238 
239  //- Does shape at index overlap bb
240  bool overlaps
241  (
242  const label index,
243  const treeBoundBox& sampleBb
244  ) const;
245 
246  //- Does shape at index overlap sphere
247  bool overlaps
248  (
249  const label index,
250  const point& centre,
251  const scalar radiusSqr
252  ) const;
253 
254  //- Helper: find intersection of line with shapes
255  static bool findIntersection
256  (
258  const label index,
259  const point& start,
260  const point& end,
261  point& intersectionPoint
262  );
263 };
264 
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 } // End namespace Foam
269 
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271 
272 #ifdef NoRepository
273  #include "treeDataPrimitivePatch.C"
274 #endif
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 #endif
279 
280 // ************************************************************************* //
static bool findIntersection(const indexedOctree< treeDataPrimitivePatch< PatchType >> &tree, const label index, const point &start, const point &end, point &intersectionPoint)
Helper: find intersection of line with shapes.
A line primitive.
Definition: line.H:56
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
volumeType getVolumeType(const indexedOctree< treeDataPrimitivePatch< PatchType >> &, const point &) const
Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
findNearestOp(const indexedOctree< treeDataPrimitivePatch > &tree)
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
Encapsulation of data needed to search on PrimitivePatches.
TemplateName(FvFaceCellWave)
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition: POSIX.C:908
pointField shapePoints() const
Get representative point cloud for all shapes inside.
const PatchType & patch() const
Return access to the underlying patch.
bool overlaps(const label index, const treeBoundBox &sampleBb) const
Does shape at index overlap bb.
Non-pointer based hierarchical recursive searching.
Definition: treeDataEdge.H:47
treeDataPrimitivePatch(const bool cacheBb, const PatchType &, const scalar planarTol)
Construct from patch.
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:87
Namespace for OpenFOAM.