treeDataPoint.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-2013 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::treeDataPoint
29 
30 Description
31  Holds (reference to) pointField. Encapsulation of data needed for
32  octree searches.
33  Used for searching for nearest point. No bounding boxes around points.
34  Only overlaps and calcNearest are implemented, rest makes little sense.
35 
36  Optionally works on subset of points.
37 
38 SourceFiles
39  treeDataPoint.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef treeDataPoint_H
44 #define treeDataPoint_H
45 
46 #include "pointField.H"
47 #include "treeBoundBox.H"
48 #include "linePointRef.H"
49 #include "volumeType.H"
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 
56 // Forward declarations
57 template<class Type> class indexedOctree;
58 
59 /*---------------------------------------------------------------------------*\
60  Class treeDataPoint Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class treeDataPoint
64 {
65  // Private Data
66 
67  const pointField& points_;
68 
69  //- Subset of points to work on (or empty)
70  const labelList pointLabels_;
71 
72  const bool useSubset_;
73 
74 public:
75 
76 
77  class findNearestOp
78  {
79  const indexedOctree<treeDataPoint>& tree_;
80 
81  public:
82 
84 
85  void operator()
86  (
87  const labelUList& indices,
88  const point& sample,
89 
90  scalar& nearestDistSqr,
91  label& minIndex,
92  point& nearestPoint
93  ) const;
94 
95  void operator()
96  (
97  const labelUList& indices,
98  const linePointRef& ln,
99 
100  treeBoundBox& tightest,
101  label& minIndex,
102  point& linePoint,
103  point& nearestPoint
104  ) const;
105  };
106 
107 
108  class findIntersectOp
109  {
110  public:
111 
113 
114  //- Calculate intersection of triangle with ray.
115  // Sets result accordingly
116  bool operator()
117  (
118  const label index,
119  const point& start,
120  const point& end,
121  point& intersectionPoint
122  ) const;
123  };
124 
125 
126  // Declare name of the class and its debug switch
127  ClassName("treeDataPoint");
128 
129 
130  // Constructors
131 
132  //- Construct from pointField
133  // \note Holds reference to the points!
134  explicit treeDataPoint(const pointField& points);
135 
136  //- Construct from subset of pointField, copies point ids
137  // \note Holds reference to the points!
139  (
140  const pointField& points,
141  const labelUList& pointLabels,
142  const bool useSubsetPoints = true
143  );
144 
145  //- Construct from subset of pointField, moves point ids
146  // \note Holds reference to the points!
148  (
149  const pointField& points,
151  const bool useSubsetPoints = true
152  );
153 
154 
155  // Member Functions
156 
157  // Access
158 
159  //- An empty effective point field?
160  inline bool empty() const
161  {
162  return
163  (
164  useSubset_
165  ? pointLabels_.empty()
166  : points_.empty()
167  );
168  }
169 
170  //- The effective point field size
171  inline label size() const
172  {
173  return
174  (
175  useSubset_
176  ? pointLabels_.size()
177  : points_.size()
178  );
179  }
180 
181  //- The original point field
182  inline const pointField& points() const
183  {
184  return points_;
185  }
186 
187  //- The original point ids
188  inline const labelList& pointLabels() const
189  {
190  return pointLabels_;
191  }
192 
193  //- Use a subset of points
194  inline bool useSubset() const
195  {
196  return useSubset_;
197  }
198 
199  //- The original (non-subset) point label
200  inline label pointLabel(const label index) const
201  {
202  return
203  (
204  useSubset_ && index >= 0
205  ? pointLabels_[index]
206  : index
207  );
208  }
209 
210  //- Point at specified index
211  inline const point& shapePoint(const label index) const
212  {
213  return
214  (
215  useSubset_
216  ? points_[pointLabels_[index]]
217  : points_[index]
218  );
219  }
220 
221  //- Representative point cloud for all shapes inside
222  //- (one point per shape)
223  pointField shapePoints() const;
224 
225 
226  // Search
227 
228  //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
229  // Only makes sense for closed surfaces.
231  (
233  const point& sample
234  ) const;
235 
236  //- Does (bb of) shape at index overlap bb
237  bool overlaps
238  (
239  const label index,
240  const treeBoundBox& sampleBb
241  ) const;
242 
243  //- Does shape at index overlap the sphere
244  bool overlaps
245  (
246  const label index,
247  const point& centre,
248  const scalar radiusSqr
249  ) const;
250 
251 
252  // Member Operators
253 
254  //- The point at the specified index
255  inline const point& operator[](const label index) const
256  {
257  return shapePoint(index);
258  }
259 };
260 
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 } // End namespace Foam
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 
269 #endif
270 
271 // ************************************************************************* //
Foam::treeDataPoint::shapePoint
const point & shapePoint(const label index) const
Point at specified index.
Definition: treeDataPoint.H:210
Foam::treeDataPoint::pointLabels
const labelList & pointLabels() const
The original point ids.
Definition: treeDataPoint.H:187
Foam::treeDataPoint::size
label size() const
The effective point field size.
Definition: treeDataPoint.H:170
Foam::treeDataPoint::points
const pointField & points() const
The original point field.
Definition: treeDataPoint.H:181
Foam::treeDataPoint::findIntersectOp::findIntersectOp
findIntersectOp(const indexedOctree< treeDataPoint > &tree)
Definition: treeDataPoint.C:87
Foam::treeDataPoint::useSubset
bool useSubset() const
Use a subset of points.
Definition: treeDataPoint.H:193
Foam::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:86
Foam::treeDataPoint::operator[]
const point & operator[](const label index) const
The point at the specified index.
Definition: treeDataPoint.H:254
Foam::treeDataPoint::treeDataPoint
treeDataPoint(const pointField &points)
Construct from pointField.
Definition: treeDataPoint.C:44
Foam::treeDataPoint
Holds (reference to) pointField. Encapsulation of data needed for octree searches....
Definition: treeDataPoint.H:62
volumeType.H
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::treeDataPoint::findIntersectOp
Definition: treeDataPoint.H:107
treeBoundBox.H
Foam::treeDataPoint::shapePoints
pointField shapePoints() const
Definition: treeDataPoint.C:95
Foam::indexedOctree
Non-pointer based hierarchical recursive searching.
Definition: treeDataEdge.H:50
Foam::treeDataPoint::ClassName
ClassName("treeDataPoint")
Foam::treeDataPoint::findNearestOp
Definition: treeDataPoint.H:76
os
OBJstream os(runTime.globalPath()/outputName)
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
Foam::treeDataPoint::findNearestOp::findNearestOp
findNearestOp(const indexedOctree< treeDataPoint > &tree)
Definition: treeDataPoint.C:78
pointField.H
Foam::treeDataPoint::pointLabel
label pointLabel(const label index) const
The original (non-subset) point label.
Definition: treeDataPoint.H:199
Foam::Vector< scalar >
Foam::List< label >
Foam::UList< label >
Foam::treeDataPoint::overlaps
bool overlaps(const label index, const treeBoundBox &sampleBb) const
Does (bb of) shape at index overlap bb.
Definition: treeDataPoint.C:117
Foam::line
A line primitive.
Definition: line.H:53
Foam::treeDataPoint::getVolumeType
volumeType getVolumeType(const indexedOctree< treeDataPoint > &os, const point &sample) const
Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
Definition: treeDataPoint.C:107
Foam::ln
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition: MSwindows.C:925
Foam::treeDataPoint::empty
bool empty() const
An empty effective point field?
Definition: treeDataPoint.H:159
sample
Minimal example by using system/controlDict.functions:
linePointRef.H