FreeFOAM The Cross-Platform CFD Toolkit
octreeDataFace.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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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::octreeDataFace
26 
27 Description
28  Holds data for octree to work on mesh faces.
29 
30  For example, calculate (in calcNearest) the correct intersection point
31  with a face.
32 
33 SourceFiles
34  octreeDataFace.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef octreeDataFace_H
39 #define octreeDataFace_H
40 
41 #include "treeBoundBoxList.H"
42 #include <OpenFOAM/faceList.H>
43 #include <OpenFOAM/point.H>
44 #include <OpenFOAM/className.H>
45 #include <OpenFOAM/linePointRef.H>
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward declaration of classes
53 class primitiveMesh;
54 template<class Type> class octree;
55 class polyPatch;
56 
57 /*---------------------------------------------------------------------------*\
58  Class octreeDataFace Declaration
59 \*---------------------------------------------------------------------------*/
60 
62 {
63  // Static data
64 
65  //- tolerance on linear dimensions
66  static scalar tol;
67 
68 
69  // Private data
70 
71  //- the mesh
72  const primitiveMesh& mesh_;
73 
74  //- labels (in mesh indexing) of faces
75  labelList meshFaces_;
76 
77  //- bbs for all above faces
78  treeBoundBoxList allBb_;
79 
80 
81  // Private Member Functions
82 
83  //- Set allBb to tight fitting bounding box
84  void calcBb();
85 
86 public:
87 
88  // Declare name of the class and its debug switch
89  ClassName("octreeDataFace");
90 
91  // Constructors
92 
93  //- Construct from selected mesh faces.
95  (
96  const primitiveMesh&,
97  const labelList& meshFaces,
98  const treeBoundBoxList&
99  );
100 
101  //- Construct from selected mesh faces. Tight fitting bounding boxes
102  // generated internally.
104  (
105  const primitiveMesh&,
106  const labelList& meshFaces
107  );
108 
109  //- Construct from selected mesh faces.
111  (
112  const primitiveMesh&,
115  );
116 
117  //- Construct from selected mesh faces.
118  // Tight-fitting bounding boxes generated internally.
120 
121  //- Construct from all faces in patch.
122  // Tight-fitting bounding boxes generated internally.
123  octreeDataFace(const polyPatch&);
124 
125  //- Construct from all boundary faces.
126  // Tight-fitting bounding boxes generated internally.
128 
129  //- Construct as copy
131 
132 
133  // Destructor
134 
135  ~octreeDataFace();
136 
137 
138  // Member Functions
139 
140  // Access
141 
142  const primitiveMesh& mesh() const
143  {
144  return mesh_;
145  }
146 
147  const labelList& meshFaces() const
148  {
149  return meshFaces_;
150  }
151 
152  const treeBoundBoxList& allBb() const
153  {
154  return allBb_;
155  }
156 
157  label size() const
158  {
159  return allBb_.size();
160  }
161 
162 
163  // Search
164 
165  //- Get type of sample
166  label getSampleType
167  (
168  const octree<octreeDataFace>&,
169  const point&
170  ) const;
171 
172  //- Does (bb of) shape at index overlap bb
173  bool overlaps
174  (
175  const label index,
176  const treeBoundBox& sampleBb
177  ) const;
178 
179  //- Does shape at index contain sample
180  bool contains(const label index, const point& sample) const;
181 
182  //- Segment (from start to end) intersection with shape
183  // at index. If intersects returns true and sets intersectionPoint
184  bool intersects
185  (
186  const label index,
187  const point& start,
188  const point& end,
189  point& intersectionPoint
190  ) const;
191 
192  //- Sets newTightest to bounding box (and returns true) if
193  // nearer to sample than tightest bounding box. Otherwise
194  // returns false.
195  bool findTightest
196  (
197  const label index,
198  const point& sample,
199  treeBoundBox& tightest
200  ) const;
201 
202  //- Given index get unit normal and calculate (numerical) sign
203  // of sample.
204  // Used to determine accuracy of calcNearest or inside/outside.
205  scalar calcSign
206  (
207  const label index,
208  const point& sample,
209  vector& n
210  ) const;
211 
212  //- Calculates nearest (to sample) point in shape.
213  // Returns point and mag(nearest - sample). Returns GREAT if
214  // sample does not project onto (triangle decomposition) of face.
215  scalar calcNearest
216  (
217  const label index,
218  const point& sample,
219  point& nearest
220  ) const;
221 
222  //- Calculates nearest (to line segment) point in shape.
223  // Returns distance and both point.
224  scalar calcNearest
225  (
226  const label index,
227  const linePointRef& ln,
228  point& linePt, // nearest point on line
229  point& shapePt // nearest point on shape
230  ) const;
231 
232 
233  // Write
234 
235  //- Write shape at index
236  void write(Ostream& os, const label index) const;
237 };
238 
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 } // End namespace Foam
243 
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245 
246 
247 #endif
248 
249 // ************************ vim: set sw=4 sts=4 et: ************************ //