treeDataPrimitivePatch.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::treeDataPrimitivePatch
28 
29 Description
30  Encapsulation of data needed to search on PrimitivePatches
31 
32 SourceFiles
33  treeDataPrimitivePatch.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef treeDataPrimitivePatch_H
38 #define treeDataPrimitivePatch_H
39 
40 #include "treeBoundBoxList.H"
41 #include "volumeType.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // Forward declaration of classes
49 template<class Type> class indexedOctree;
50 
51 
52 /*---------------------------------------------------------------------------*\
53  Class treeDataPrimitivePatchName Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 TemplateName(treeDataPrimitivePatch);
57 
58 
59 /*---------------------------------------------------------------------------*\
60  Class treeDataPrimitivePatch Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 template<class PatchType>
65 :
66  public treeDataPrimitivePatchName
67 {
68  // Private data
69 
70  //- Underlying geometry
71  const PatchType& patch_;
72 
73  //- Whether to precalculate and store face bounding box
74  const bool cacheBb_;
75 
76  //- Tolerance to use for intersection tests
77  const scalar planarTol_;
78 
79  //- Face bounding boxes (valid only if cacheBb_)
80  treeBoundBoxList bbs_;
81 
82 
83  // Private Member Functions
84 
85  //- Initialise all member data
86  void update();
87 
88 
89 public:
90 
91 
92  class findNearestOp
93  {
95 
96  public:
97 
99 
100  void operator()
101  (
102  const labelUList& indices,
103  const point& sample,
104 
105  scalar& nearestDistSqr,
106  label& minIndex,
107  point& nearestPoint
108  ) const;
109 
110  //- Calculates nearest (to line) point in shape.
111  // Returns point and distance (squared)
112  void operator()
113  (
114  const labelUList& indices,
115  const linePointRef& ln,
116 
117  treeBoundBox& tightest,
118  label& minIndex,
119  point& linePoint,
120  point& nearestPoint
121  ) const;
122  };
123 
124 
125  class findIntersectOp
126  {
128 
129  public:
130 
132 
133  //- Calculate intersection of any face with ray.
134  // Sets result accordingly. Used to find first intersection.
135  bool operator()
136  (
137  const label index,
138  const point& start,
139  const point& end,
140  point& intersectionPoint
141  ) const;
142  };
143 
144 
145  class findAllIntersectOp
146  {
148 
149  DynamicList<label>& shapeMask_;
150 
151  public:
152 
154  (
156  DynamicList<label>& shapeMask
157  );
158 
159  //- Calculate intersection of unique face with ray.
160  // Sets result accordingly. Used to find all faces.
161  bool operator()
162  (
163  const label index,
164  const point& start,
165  const point& end,
166  point& intersectionPoint
167  ) const;
168  };
169 
170 
171  class findSelfIntersectOp
172  {
174 
175  const label edgeID_;
176 
177  public:
178 
180  (
182  const label edgeID
183  );
184 
185  //- Calculate intersection of face with edge of patch.
186  // Excludes faces that use edgeID. Used to find self intersection.
187  bool operator()
188  (
189  const label index,
190  const point& start,
191  const point& end,
192  point& intersectionPoint
193  ) const;
194  };
195 
196 
197  // Constructors
198 
199  //- Construct from patch.
201  (
202  const bool cacheBb,
203  const PatchType&,
204  const scalar planarTol
205  );
206 
207 
208  // Member Functions
209 
210  // Access
211 
212  label size() const
213  {
214  return patch_.size();
215  }
216 
217  //- Representative point cloud for all shapes inside
218  //- (one point per shape)
219  pointField shapePoints() const;
220 
221  //- Return access to the underlying patch
222  const PatchType& patch() const
223  {
224  return patch_;
225  }
226 
227 
228  // Search
229 
230  //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
231  // Only makes sense for closed surfaces.
233  (
235  const point&
236  ) const;
237 
238  //- Does shape at index overlap bb
239  bool overlaps
240  (
241  const label index,
242  const treeBoundBox& sampleBb
243  ) const;
244 
245  //- Does shape at index overlap sphere
246  bool overlaps
247  (
248  const label index,
249  const point& centre,
250  const scalar radiusSqr
251  ) const;
252 
253  //- Helper: find intersection of line with shapes
254  static bool findIntersection
255  (
257  const label index,
258  const point& start,
259  const point& end,
260  point& intersectionPoint
261  );
262 };
263 
264 
265 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266 
267 } // End namespace Foam
268 
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 
271 #ifdef NoRepository
272  #include "treeDataPrimitivePatch.C"
273 #endif
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 #endif
278 
279 // ************************************************************************* //
Foam::treeDataPrimitivePatch::getVolumeType
volumeType getVolumeType(const indexedOctree< treeDataPrimitivePatch< PatchType >> &, const point &) const
Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
Definition: treeDataPrimitivePatch.C:133
Foam::treeDataPrimitivePatch::findIntersectOp::findIntersectOp
findIntersectOp(const indexedOctree< treeDataPrimitivePatch > &tree)
Definition: treeDataPrimitivePatch.C:82
Foam::treeDataPrimitivePatch::patch
const PatchType & patch() const
Return access to the underlying patch.
Definition: treeDataPrimitivePatch.H:221
Foam::treeDataPrimitivePatch::findIntersection
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.
Definition: treeDataPrimitivePatch.C:576
Foam::treeDataPrimitivePatch::findNearestOp
Definition: treeDataPrimitivePatch.H:91
Foam::DynamicList< label >
Foam::treeDataPrimitivePatch::findIntersectOp
Definition: treeDataPrimitivePatch.H:124
treeDataPrimitivePatch.C
Foam::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:87
Foam::treeDataPrimitivePatch::overlaps
bool overlaps(const label index, const treeBoundBox &sampleBb) const
Does shape at index overlap bb.
Definition: treeDataPrimitivePatch.C:362
edgeID
label edgeID
Definition: boundaryProcessorFaPatchPoints.H:6
volumeType.H
Foam::treeDataPrimitivePatch::findAllIntersectOp::findAllIntersectOp
findAllIntersectOp(const indexedOctree< treeDataPrimitivePatch > &tree, DynamicList< label > &shapeMask)
Definition: treeDataPrimitivePatch.C:92
Foam::volumeType
An enumeration wrapper for classification of a location as being inside/outside of a volume.
Definition: volumeType.H:60
Foam::Field< vector >
Foam::indexedOctree
Non-pointer based hierarchical recursive searching.
Definition: treeDataEdge.H:50
Foam::treeDataPrimitivePatch::findSelfIntersectOp
Definition: treeDataPrimitivePatch.H:170
Foam::TemplateName
TemplateName(blendedSchemeBase)
Foam::treeDataPrimitivePatch::shapePoints
pointField shapePoints() const
Definition: treeDataPrimitivePatch.C:118
Foam::treeDataPrimitivePatch::size
label size() const
Definition: treeDataPrimitivePatch.H:211
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
treeBoundBoxList.H
Foam::treeDataPrimitivePatch::treeDataPrimitivePatch
treeDataPrimitivePatch(const bool cacheBb, const PatchType &, const scalar planarTol)
Construct from patch.
Definition: treeDataPrimitivePatch.C:56
Foam::treeDataPrimitivePatch::findNearestOp::findNearestOp
findNearestOp(const indexedOctree< treeDataPrimitivePatch > &tree)
Definition: treeDataPrimitivePatch.C:72
Foam::Vector< scalar >
Foam::treeDataPrimitivePatch
Encapsulation of data needed to search on PrimitivePatches.
Definition: treeDataPrimitivePatch.H:63
Foam::List< treeBoundBox >
Foam::UList< label >
Foam::treeDataPrimitivePatch::findSelfIntersectOp::findSelfIntersectOp
findSelfIntersectOp(const indexedOctree< treeDataPrimitivePatch > &tree, const label edgeID)
Definition: treeDataPrimitivePatch.C:105
Foam::line
A line primitive.
Definition: line.H:59
Foam::ln
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition: MSwindows.C:915
Foam::treeDataPrimitivePatch::findAllIntersectOp
Definition: treeDataPrimitivePatch.H:144