FreeFOAM The Cross-Platform CFD Toolkit
octreeDataTriSurface.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::octreeDataTriSurface
26 
27 Description
28  Encapsulates data for octree searches on triSurface.
29 
30 SourceFiles
31  octreeDataTriSurface.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef octreeDataTriSurface_H
36 #define octreeDataTriSurface_H
37 
39 #include <OpenFOAM/labelList.H>
40 #include <OpenFOAM/point.H>
41 #include <triSurface/triSurface.H>
42 #include <OpenFOAM/linePointRef.H>
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward declaration of classes
50 template<class Type> class octree;
51 
52 /*---------------------------------------------------------------------------*\
53  Class octreeDataTriSurface Declaration
54 \*---------------------------------------------------------------------------*/
55 
57 {
58  // Static data
59 
60  //- tolerance on linear dimensions
61  static scalar tol;
62 
63  // Private data
64 
65  const triSurface& surface_;
66 
67  const treeBoundBoxList allBb_;
68 
69  // Extra data to speed up distance searches.
70  // Triangles expressed as base + spanning vectors
71  pointField base_;
72  pointField E0_;
73  pointField E1_;
74  scalarList a_;
75  scalarList b_;
76  scalarList c_;
77 
78 
79  // Private Static Functions
80 
81  //- fast triangle nearest point calculation. Returns point in E0, E1
82  // coordinate system: base + s*E0 + t*E1
83  static void nearestCoords
84  (
85  const point& base,
86  const point& E0,
87  const point& E1,
88  const scalar a,
89  const scalar b,
90  const scalar c,
91  const point& P,
92  scalar& s,
93  scalar& t
94  );
95 
96  //- Calculate bounding boxes for triangles
97  static treeBoundBoxList calcBb(const triSurface&);
98 
99  // Private Member Functions
100 
101  //- nearest point in xyz coord system
102  point nearestPoint(const label index, const point& P) const;
103 
104 public:
105 
106  // Declare name of the class and its debug switch
107  ClassName("octreeDataTriSurface");
108 
109 
110  // Constructors
111 
112  //- Construct from triSurface. Holds reference. Bounding box
113  // calculated from triangle points.
115 
116  //- Construct from triSurface and bounding box.
117  // Holds references.
119 
120 
121  // Member Functions
122 
123  // Access
124 
125  const triSurface& surface() const
126  {
127  return surface_;
128  }
129 
130  const treeBoundBoxList& allBb() const
131  {
132  return allBb_;
133  }
134 
135  label size() const
136  {
137  return allBb_.size();
138  }
139 
140  // Search
141 
142  //- Get type of sample
143  label getSampleType
144  (
146  const point&
147  ) const;
148 
149  //- Does (bb of) shape at index overlap bb
150  bool overlaps
151  (
152  const label index,
153  const treeBoundBox& sampleBb
154  ) const;
155 
156  //- Does shape at index contain sample
157  bool contains
158  (
159  const label index,
160  const point& sample
161  ) const;
162 
163  //- Segment (from start to end) intersection with shape
164  // at index. If intersects returns true and sets intersectionPoint
165  bool intersects
166  (
167  const label index,
168  const point& start,
169  const point& end,
170  point& intersectionPoint
171  ) const;
172 
173  //- Sets newTightest to bounding box (and returns true) if
174  // nearer to sample than tightest bounding box. Otherwise
175  // returns false.
176  bool findTightest
177  (
178  const label index,
179  const point& sample,
180  treeBoundBox& tightest
181  ) const;
182 
183  //- Given index get unit normal and calculate (numerical) sign
184  // of sample.
185  // Used to determine accuracy of calcNearest or inside/outside.
186  scalar calcSign
187  (
188  const label index,
189  const point& sample,
190  vector& n
191  ) const;
192 
193  //- Calculates nearest (to sample) point in shape.
194  // Returns point and mag(nearest - sample)
195  scalar calcNearest
196  (
197  const label index,
198  const point& sample,
199  point& nearest
200  ) const;
201 
202  //- Calculates nearest (to line segment) point in shape.
203  // Returns distance and both point.
204  scalar calcNearest
205  (
206  const label index,
207  const linePointRef& ln,
208  point& linePt, // nearest point on line
209  point& shapePt // nearest point on shape
210  ) const;
211 
212 
213  // Write
214 
215  // Write shape at index
216  void write(Ostream& os, const label index) const;
217 
218 
219  // IOstream Operators
220 
223 };
224 
225 
226 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227 
228 } // End namespace Foam
229 
230 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231 
232 
233 #endif
234 
235 // ************************ vim: set sw=4 sts=4 et: ************************ //