searchableSurfaceWithGaps.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-2017 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::searchableSurfaceWithGaps
28 
29 Description
30  searchableSurface using multiple slightly shifted underlying surfaces
31  to make sure pierces don't go through gaps:
32  - shift test vector with two small vectors (of size gap_) perpendicular
33  to the original.
34  Test with + and - this vector. Only if both register a hit is it seen
35  as one.
36  - extend the test vector slightly (with SMALL) to account for numerical
37  inaccuracies.
38 
39  \verbatim
40  sphere.stl
41  {
42  type triSurfaceMesh;
43  }
44 
45  sphere
46  {
47  type searchableSurfaceWithGaps;
48  surface sphere.stl; // Underlying surface
49  gap 1e-3; // Perturb distance
50  }
51  \endverbatim
52 
53  \heading Dictionary parameters
54  \table
55  Property | Description | Required | Default
56  type | searchableSurfaceWithGaps | selector |
57  surface | Name of the underlying surface | yes |
58  gap | Gap tolerance in meters | yes |
59  \endtable
60 
61 SourceFiles
62  searchableSurfaceWithGaps.C
63 
64 \*---------------------------------------------------------------------------*/
65 
66 #ifndef searchableSurfaceWithGaps_H
67 #define searchableSurfaceWithGaps_H
68 
69 #include "searchableSurface.H"
70 #include "UPtrList.H"
71 #include "Pair.H"
72 
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74 
75 namespace Foam
76 {
77 
78 /*---------------------------------------------------------------------------*\
79  Class searchableSurfaceWithGaps Declaration
80 \*---------------------------------------------------------------------------*/
81 
82 class searchableSurfaceWithGaps
83 :
84  public searchableSurface
85 {
86 private:
87 
88  // Private Member Data
89 
90  //- Gap size in metre
91  const scalar gap_;
92 
93  //- Underlying geometry (size 1)
94  UPtrList<searchableSurface> subGeom_;
95 
96 
97  // Private Member Functions
98 
99  Pair<vector> offsetVecs(const point&, const point&) const;
100 
101  void offsetVecs
102  (
103  const pointField& start,
104  const pointField& end,
105  pointField& offset0,
106  pointField& offset1
107  ) const;
108 
109  static label countMisses
110  (
111  const List<pointIndexHit>& info,
112  labelList& missMap
113  );
114 
115  static label countMisses
116  (
117  const List<pointIndexHit>& plusInfo,
118  const List<pointIndexHit>& minInfo,
119  labelList& missMap
120  );
121 
122 
123  //- No copy construct
125 
126  //- No copy assignment
127  void operator=(const searchableSurfaceWithGaps&) = delete;
128 
129 
130 public:
131 
132  //- Runtime type information
133  TypeName("searchableSurfaceWithGaps");
134 
135 
136  // Constructors
137 
138  //- Construct from dictionary (used by searchableSurface)
140  (
141  const IOobject& io,
142  const dictionary& dict
143  );
144 
145  //- Destructor
146  virtual ~searchableSurfaceWithGaps() = default;
147 
148 
149  // Member Functions
150 
151  //- The underlying searchableSurface
152  const searchableSurface& surface() const
153  {
154  return subGeom_[0];
155  }
156 
157  //- Name of regions
158  virtual const wordList& regions() const
159  {
160  return surface().regions();
161  }
162 
163  //- Whether supports volume type (below)
164  virtual bool hasVolumeType() const
165  {
166  return surface().hasVolumeType();
167  }
168 
169  //- What is type of points outside bounds
170  virtual volumeType outsideVolumeType() const
171  {
172  return surface().outsideVolumeType();
173  }
174 
175  //- Range of local indices that can be returned.
176  virtual label size() const
177  {
178  return surface().size();
179  }
180 
181  //- Get representative set of element coordinates
182  // Usually the element centres (should be of length size()).
183  virtual tmp<pointField> coordinates() const
184  {
185  return surface().coordinates();
186  }
187 
188  //- Get bounding spheres (centre and radius squared), one per element.
189  // Any point on element is guaranteed to be inside.
190  virtual void boundingSpheres
191  (
192  pointField& centres,
193  scalarField& radiusSqr
194  ) const
195  {
196  surface().boundingSpheres(centres, radiusSqr);
197  }
198 
199  //- Get the points that define the surface.
200  virtual tmp<pointField> points() const
201  {
202  return surface().points();
203  }
204 
205  //- Does any part of the surface overlap the supplied bound box?
206  // Note: use perturbed surface? Since uses boundbox of points and
207  // not actual intersection chosen to use unperturbed surface.
208  virtual bool overlaps(const boundBox& bb) const
209  {
210  return surface().overlaps(bb);
211  }
212 
213 
214  // Multiple point queries.
215 
216  //- Find nearest on original surface. Note:does not use perturbation
217  // and hence might be inconsistent with intersections.
218  virtual void findNearest
219  (
220  const pointField& sample,
221  const scalarField& nearestDistSqr,
223  ) const
224  {
226  (
227  sample,
228  nearestDistSqr,
229  info
230  );
231  }
232 
233  virtual void findLine
234  (
235  const pointField& start,
236  const pointField& end,
238  ) const;
239 
240  virtual void findLineAny
241  (
242  const pointField& start,
243  const pointField& end,
245  ) const;
246 
247  //- Get all intersections in order from start to end.
248  virtual void findLineAll
249  (
250  const pointField& start,
251  const pointField& end,
253  ) const;
254 
255  //- From a set of points and indices get the region
256  virtual void getRegion
257  (
258  const List<pointIndexHit>& info,
259  labelList& region
260  ) const
261  {
262  surface().getRegion(info, region);
263  }
264 
265  //- From a set of points and indices get the normal
266  virtual void getNormal
267  (
268  const List<pointIndexHit>& info,
269  vectorField& normal
270  ) const
271  {
272  surface().getNormal(info, normal);
273  }
274 
275  //- Determine type (inside/outside/mixed) for points.
276  // Unknown if cannot be determined (e.g. non-manifold surface)
277  virtual void getVolumeType
278  (
279  const pointField& samples,
281  ) const
282  {
284  }
285 
286 
287  // Other
288 
289  //- Set bounds of surface. Bounds currently set as list of
290  // bounding boxes. The bounds are hints to the surface as for
291  // the range of queries it can expect. faceMap/pointMap can be
292  // set if the surface has done any redistribution.
293  //virtual void distribute
294  //(
295  // const List<treeBoundBox>& bbs,
296  // const bool keepNonLocal,
297  // autoPtr<mapDistribute>& faceMap,
298  // autoPtr<mapDistribute>& pointMap
299  //)
300  //{
301  // subGeom_[0].distribute(bbs, keepNonLocal, faceMap, pointMap);
302  //}
303 
304  //- WIP. Store element-wise field.
305  virtual void setField(const labelList& values)
306  {
307  subGeom_[0].setField(values);
308  }
309 
310  //- WIP. From a set of hits (points and
311  // indices) get the specified field. Misses do not get set. Return
312  // empty field if not supported.
313  virtual void getField
314  (
315  const List<pointIndexHit>& info,
317  ) const
318  {
320  }
321 
322  // regIOobject implementation
323 
324  bool writeData(Ostream& os) const
325  {
326  return surface().writeData(os);
327  }
328 
329 };
330 
331 
332 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
333 
334 } // End namespace Foam
335 
336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
337 
338 #endif
339 
340 // ************************************************************************* //
Foam::searchableSurfaceWithGaps::findNearest
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &info) const
Find nearest on original surface. Note:does not use perturbation.
Definition: searchableSurfaceWithGaps.H:238
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
UPtrList.H
Foam::searchableSurfaceWithGaps::coordinates
virtual tmp< pointField > coordinates() const
Get representative set of element coordinates.
Definition: searchableSurfaceWithGaps.H:202
Foam::searchableSurfaceWithGaps::getField
virtual void getField(const List< pointIndexHit > &info, labelList &values) const
WIP. From a set of hits (points and.
Definition: searchableSurfaceWithGaps.H:333
searchableSurface.H
Foam::searchableSurface::getNormal
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const =0
From a set of points and indices get the normal.
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::searchableSurfaceWithGaps::~searchableSurfaceWithGaps
virtual ~searchableSurfaceWithGaps()=default
Destructor.
Foam::searchableSurface::coordinates
virtual tmp< pointField > coordinates() const =0
Get representative set of element coordinates.
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::searchableSurfaceWithGaps::findLineAll
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const
Get all intersections in order from start to end.
Definition: searchableSurfaceWithGaps.C:341
Foam::searchableSurfaceWithGaps::outsideVolumeType
virtual volumeType outsideVolumeType() const
What is type of points outside bounds.
Definition: searchableSurfaceWithGaps.H:189
Foam::regIOobject::writeData
virtual bool writeData(Ostream &) const =0
Pure virtual writeData function.
Foam::searchableSurfaceWithGaps::size
virtual label size() const
Range of local indices that can be returned.
Definition: searchableSurfaceWithGaps.H:195
Pair.H
Foam::searchableSurface::size
virtual label size() const =0
Range of local indices that can be returned.
Foam::IOobject::info
InfoProxy< IOobject > info() const
Return info proxy.
Definition: IOobject.H:540
Foam::searchableSurface::getRegion
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const =0
From a set of points and indices get the region.
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::searchableSurface::regions
virtual const wordList & regions() const =0
Names of regions.
Foam::searchableSurface::points
virtual tmp< pointField > points() const =0
Get the points that define the surface.
Foam::searchableSurface::overlaps
virtual bool overlaps(const boundBox &bb) const =0
Does any part of the surface overlap the supplied bound box?
Foam::searchableSurface
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
Definition: searchableSurface.H:69
Foam::UPtrList
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: UPtrList.H:62
samples
scalarField samples(nIntervals, Zero)
Foam::searchableSurfaceWithGaps::getNormal
virtual void getNormal(const List< pointIndexHit > &info, vectorField &normal) const
From a set of points and indices get the normal.
Definition: searchableSurfaceWithGaps.H:286
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:121
Foam::searchableSurface::hasVolumeType
virtual bool hasVolumeType() const
Whether supports volume type (below).
Definition: searchableSurface.C:76
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam::searchableSurface::outsideVolumeType
virtual volumeType outsideVolumeType() const =0
If surface supports volume queries, what is type of points outside.
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::searchableSurfaceWithGaps::writeData
bool writeData(Ostream &os) const
Pure virtual writeData function.
Definition: searchableSurfaceWithGaps.H:343
Foam::searchableSurfaceWithGaps::regions
virtual const wordList & regions() const
Name of regions.
Definition: searchableSurfaceWithGaps.H:177
Foam::searchableSurfaceWithGaps::surface
const searchableSurface & surface() const
The underlying searchableSurface.
Definition: searchableSurfaceWithGaps.H:171
Foam::searchableSurfaceWithGaps::getRegion
virtual void getRegion(const List< pointIndexHit > &info, labelList &region) const
From a set of points and indices get the region.
Definition: searchableSurfaceWithGaps.H:276
Foam::Pair
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:54
Foam::searchableSurfaceWithGaps::findLineAny
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
Definition: searchableSurfaceWithGaps.C:329
Foam::Vector< scalar >
Foam::searchableSurfaceWithGaps::findLine
virtual void findLine(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Find first intersection on segment from start to end.
Definition: searchableSurfaceWithGaps.C:204
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::searchableSurfaceWithGaps::points
virtual tmp< pointField > points() const
Get the points that define the surface.
Definition: searchableSurfaceWithGaps.H:219
Foam::searchableSurfaceWithGaps::setField
virtual void setField(const labelList &values)
Set bounds of surface. Bounds currently set as list of.
Definition: searchableSurfaceWithGaps.H:324
Foam::searchableSurfaceWithGaps::getVolumeType
virtual void getVolumeType(const pointField &samples, List< volumeType > &info) const
Determine type (inside/outside/mixed) for points.
Definition: searchableSurfaceWithGaps.H:297
Foam::searchableSurfaceWithGaps::boundingSpheres
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared), one per element.
Definition: searchableSurfaceWithGaps.H:210
Foam::searchableSurfaceWithGaps
searchableSurface using multiple slightly shifted underlying surfaces to make sure pierces don't go t...
Definition: searchableSurfaceWithGaps.H:101
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::searchableSurface::boundingSpheres
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const =0
Get bounding spheres (centre and radius squared), one per element.
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::searchableSurfaceWithGaps::overlaps
virtual bool overlaps(const boundBox &bb) const
Does any part of the surface overlap the supplied bound box?
Definition: searchableSurfaceWithGaps.H:227
Foam::searchableSurface::getField
virtual void getField(const List< pointIndexHit > &, labelList &values) const
WIP. From a set of hits (points and.
Definition: searchableSurface.H:387
Foam::searchableSurface::getVolumeType
virtual void getVolumeType(const pointField &, List< volumeType > &) const =0
Determine type (inside/outside) for point.
Foam::searchableSurfaceWithGaps::hasVolumeType
virtual bool hasVolumeType() const
Whether supports volume type (below)
Definition: searchableSurfaceWithGaps.H:183
Foam::searchableSurfaceWithGaps::TypeName
TypeName("searchableSurfaceWithGaps")
Runtime type information.