searchableBox.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  Copyright (C) 2018-2021 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::searchableBox
29 
30 Description
31  Searching on bounding box
32 
33  \heading Dictionary parameters
34  \table
35  Property | Description | Required | Default
36  type | box | selector |
37  min | Minimum point for bounding box | yes |
38  max | Maximum point for bounding box | yes |
39  span | Box width | cond'l |
40  \endtable
41 
42 Note
43  The order of precedence from the highest to the lowest is
44  \c min-max or \c min-span pair
45 
46 Note
47  Longer type name : \c searchableBox
48 
49 SourceFiles
50  searchableBox.C
51 
52 \*---------------------------------------------------------------------------*/
53 
54 #ifndef searchableBox_H
55 #define searchableBox_H
56 
57 #include "searchableSurface.H"
58 #include "treeBoundBox.H"
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
62 namespace Foam
63 {
64 
65 /*---------------------------------------------------------------------------*\
66  Class searchableBox Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 class searchableBox
70 :
71  public searchableSurface,
72  public treeBoundBox
73 {
74  // Private Member Data
75 
76  mutable wordList regions_;
77 
78 
79  // Private Member Functions
80 
81  //- Project onto component dir of planePt and update index() (=face)
82  void projectOntoCoordPlane
83  (
84  const direction dir,
85  const point& planePt,
87  ) const;
88 
89  //- Inherit findNearest from searchableSurface
91 
92  //- Returns miss or hit with face (0..5)
93  pointIndexHit findNearest
94  (
95  const point& bbMid,
96  const point& sample,
97  const scalar nearestDistSqr
98  ) const;
99 
100 
101  //- No copy construct
102  searchableBox(const searchableBox&) = delete;
103 
104  //- No copy assignment
105  void operator=(const searchableBox&) = delete;
106 
107 
108 public:
109 
110  //- Runtime type information
111  TypeName("searchableBox");
112 
113 
114  // Constructors
115 
116  //- Construct from components
117  searchableBox(const IOobject& io, const treeBoundBox& bb);
118 
119  //- Construct from dictionary (used by searchableSurface)
121  (
122  const IOobject& io,
123  const dictionary& dict
124  );
125 
126 
127  //- Destructor
128  virtual ~searchableBox() = default;
129 
130 
131  // Member Functions
132 
133  //- Names of regions
134  virtual const wordList& regions() const;
135 
136  //- Whether surface supports volume type (below)
137  virtual bool hasVolumeType() const
138  {
139  return true;
140  }
141  //- What is type of points outside bounds
142  virtual volumeType outsideVolumeType() const
143  {
144  return volumeType::OUTSIDE;
145  }
146 
147  //- Range of local indices that can be returned.
148  virtual label size() const
149  {
150  return 6;
151  }
152 
153  //- Get representative set of element coordinates
154  // Usually the element centres (should be of length size()).
155  virtual tmp<pointField> coordinates() const;
156 
157  //- Get bounding spheres (centre and radius squared), one per element.
158  // Any point on element is guaranteed to be inside.
159  virtual void boundingSpheres
160  (
161  pointField& centres,
162  scalarField& radiusSqr
163  ) const;
164 
165  //- Get the points that define the surface.
166  virtual tmp<pointField> points() const;
167 
168  // Does any part of the surface overlap the supplied bound box?
169  virtual bool overlaps(const boundBox& bb) const
170  {
171  return boundBox::overlaps(bb);
172  }
173 
174  // Single point queries.
175 
176  //- Calculate nearest point on surface.
177  // Returns
178  // - bool : any point found nearer than nearestDistSqr
179  // - label: relevant index in surface (=face 0..5)
180  // - point: actual nearest point found
181  pointIndexHit findNearest
182  (
183  const point& sample,
184  const scalar nearestDistSqr
185  ) const;
186 
187  //- Calculate nearest point on edge.
188  // Returns
189  // - bool : any point found nearer than nearestDistSqr
190  // - label: relevant index in surface(=?)
191  // - point: actual nearest point found
193  (
194  const point& sample,
195  const scalar nearestDistSqr
196  ) const;
197 
198  //- Find nearest to segment.
199  // Returns
200  // - bool : any point found?
201  // - label: relevant index in shapes (=face 0..5)
202  // - point: actual nearest point found
203  // sets:
204  // - tightest : bounding box
205  // - linePoint : corresponding nearest point on line
206  pointIndexHit findNearest
207  (
208  const linePointRef& ln,
209  treeBoundBox& tightest,
210  point& linePoint
211  ) const;
212 
213  //- Find nearest intersection of line between start and end.
215  (
216  const point& start,
217  const point& end
218  ) const;
219 
220  //- Find any intersection of line between start and end.
222  (
223  const point& start,
224  const point& end
225  ) const;
226 
227 
228  // Multiple point queries.
229 
230  virtual void findNearest
231  (
232  const pointField& sample,
233  const scalarField& nearestDistSqr,
235  ) const;
236 
237  virtual void findLine
238  (
239  const pointField& start,
240  const pointField& end,
242  ) const;
243 
244  virtual void findLineAny
245  (
246  const pointField& start,
247  const pointField& end,
249  ) const;
250 
251  //- Get all intersections in order from start to end.
252  virtual void findLineAll
253  (
254  const pointField& start,
255  const pointField& end,
257  ) const;
258 
259  //- From a set of points and indices get the region
260  virtual void getRegion
261  (
262  const List<pointIndexHit>&,
263  labelList& region
264  ) const;
265 
266  //- From a set of points and indices get the normal
267  virtual void getNormal
268  (
269  const List<pointIndexHit>&,
270  vectorField& normal
271  ) const;
272 
273  //- Determine type (inside/outside) for points.
274  virtual void getVolumeType
275  (
276  const pointField& points,
277  List<volumeType>& volType
278  ) const;
279 
280 
281  // regIOobject implementation
282 
283  bool writeData(Ostream&) const
284  {
286  return false;
287  }
288 };
289 
290 
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292 
293 } // End namespace Foam
294 
295 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
296 
297 #endif
298 
299 // ************************************************************************* //
Foam::searchableBox::size
virtual label size() const
Range of local indices that can be returned.
Definition: searchableBox.H:172
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::searchableBox::findLine
pointIndexHit findLine(const point &start, const point &end) const
Find nearest intersection of line between start and end.
Definition: searchableBox.C:404
searchableSurface.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::searchableBox::writeData
bool writeData(Ostream &) const
Pure virtual writeData function.
Definition: searchableBox.H:307
Foam::searchableBox::findLineAny
pointIndexHit findLineAny(const point &start, const point &end) const
Find any intersection of line between start and end.
Definition: searchableBox.C:467
Foam::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:86
Foam::IOobject::info
InfoProxy< IOobject > info() const
Return info proxy.
Definition: IOobject.H:689
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
Foam::boundBox::overlaps
bool overlaps(const boundBox &bb) const
Overlaps/touches boundingBox?
Definition: boundBoxI.H:221
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
Foam::searchableBox::getRegion
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
Definition: searchableBox.C:594
Foam::PointIndexHit
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:52
Foam::searchableBox::findNearestOnEdge
pointIndexHit findNearestOnEdge(const point &sample, const scalar nearestDistSqr) const
Calculate nearest point on edge.
Definition: searchableBox.C:322
Foam::volumeType
An enumeration wrapper for classification of a location as being inside/outside of a volume.
Definition: volumeType.H:60
Foam::Field< vector >
treeBoundBox.H
Foam::searchableSurface
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
Definition: searchableSurface.H:69
Foam::searchableBox::coordinates
virtual tmp< pointField > coordinates() const
Get representative set of element coordinates.
Definition: searchableBox.C:253
Foam::searchableBox::points
virtual tmp< pointField > points() const
Get the points that define the surface.
Definition: searchableBox.C:305
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
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::searchableSurface::findNearest
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const =0
Foam::searchableBox::getVolumeType
virtual void getVolumeType(const pointField &points, List< volumeType > &volType) const
Determine type (inside/outside) for points.
Definition: searchableBox.C:628
Foam::searchableBox::overlaps
virtual bool overlaps(const boundBox &bb) const
Does any part of the surface overlap the supplied bound box?
Definition: searchableBox.H:193
Foam::pointIndexHit
PointIndexHit< point > pointIndexHit
A PointIndexHit for 3D points.
Definition: pointIndexHit.H:46
Foam::Vector< scalar >
Foam::List< word >
Foam::searchableBox::outsideVolumeType
virtual volumeType outsideVolumeType() const
What is type of points outside bounds.
Definition: searchableBox.H:166
Foam::searchableBox::regions
virtual const wordList & regions() const
Names of regions.
Definition: searchableBox.C:242
Foam::searchableBox::~searchableBox
virtual ~searchableBox()=default
Destructor.
Foam::searchableBox::findLineAll
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const
Get all intersections in order from start to end.
Definition: searchableBox.C:527
Foam::searchableBox::TypeName
TypeName("searchableBox")
Runtime type information.
Foam::searchableBox::hasVolumeType
virtual bool hasVolumeType() const
Whether surface supports volume type (below)
Definition: searchableBox.H:161
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::line
A line primitive.
Definition: line.H:53
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
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::searchableBox
Searching on bounding box.
Definition: searchableBox.H:93
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::point
vector point
Point is a vector.
Definition: point.H:43
Foam::searchableBox::getNormal
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
Definition: searchableBox.C:605
Foam::searchableBox::boundingSpheres
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared), one per element.
Definition: searchableBox.C:271
Foam::volumeType::OUTSIDE
A location outside the volume.
Definition: volumeType.H:69
sample
Minimal example by using system/controlDict.functions: