1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Foam::octreeDataTriSurface
29 Encapsulates data for octree searches on triSurface.
32 octreeDataTriSurface.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef octreeDataTriSurface_H
37 #define octreeDataTriSurface_H
39 #include "treeBoundBoxList.H"
40 #include "labelList.H"
42 #include "triSurface.H"
43 #include "linePointRef.H"
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 // Forward declaration of classes
51 template<class Type> class octree;
53 /*---------------------------------------------------------------------------*\
54 Class octreeDataTriSurface Declaration
55 \*---------------------------------------------------------------------------*/
57 class octreeDataTriSurface
61 //- tolerance on linear dimensions
66 const triSurface& surface_;
68 const treeBoundBoxList allBb_;
70 // Extra data to speed up distance searches.
71 // Triangles expressed as base + spanning vectors
80 // Private Static Functions
82 //- fast triangle nearest point calculation. Returns point in E0, E1
83 // coordinate system: base + s*E0 + t*E1
84 static void nearestCoords
97 //- Calculate bounding boxes for triangles
98 static treeBoundBoxList calcBb(const triSurface&);
100 // Private Member Functions
102 //- nearest point in xyz coord system
103 point nearestPoint(const label index, const point& P) const;
107 // Declare name of the class and its debug switch
108 ClassName("octreeDataTriSurface");
113 //- Construct from triSurface. Holds reference. Bounding box
114 // calculated from triangle points.
115 octreeDataTriSurface(const triSurface&);
117 //- Construct from triSurface and bounding box.
119 octreeDataTriSurface(const triSurface&, const treeBoundBoxList&);
126 const triSurface& surface() const
131 const treeBoundBoxList& allBb() const
138 return allBb_.size();
143 //- Get type of sample
146 const octree<octreeDataTriSurface>&,
150 //- Does (bb of) shape at index overlap bb
154 const treeBoundBox& sampleBb
157 //- Does shape at index contain sample
164 //- Segment (from start to end) intersection with shape
165 // at index. If intersects returns true and sets intersectionPoint
171 point& intersectionPoint
174 //- Sets newTightest to bounding box (and returns true) if
175 // nearer to sample than tightest bounding box. Otherwise
181 treeBoundBox& tightest
184 //- Given index get unit normal and calculate (numerical) sign
186 // Used to determine accuracy of calcNearest or inside/outside.
194 //- Calculates nearest (to sample) point in shape.
195 // Returns point and mag(nearest - sample)
203 //- Calculates nearest (to line segment) point in shape.
204 // Returns distance and both point.
208 const linePointRef& ln,
209 point& linePt, // nearest point on line
210 point& shapePt // nearest point on shape
216 // Write shape at index
217 void write(Ostream& os, const label index) const;
220 // IOstream Operators
222 friend Istream& operator>>(Istream&, octreeDataTriSurface&);
223 friend Ostream& operator<<(Ostream&, const octreeDataTriSurface&);
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229 } // End namespace Foam
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 // ************************************************************************* //