initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / triSurface / octreeData / octreeDataTriSurface.H
blob4f11069bca79c2796b3c3bcbca06c8fafbd9020b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Class
26     Foam::octreeDataTriSurface
28 Description
29     Encapsulates data for octree searches on triSurface.
31 SourceFiles
32     octreeDataTriSurface.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef octreeDataTriSurface_H
37 #define octreeDataTriSurface_H
39 #include "treeBoundBoxList.H"
40 #include "labelList.H"
41 #include "point.H"
42 #include "triSurface.H"
43 #include "linePointRef.H"
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 namespace Foam
50 // Forward declaration of classes
51 template<class Type> class octree;
53 /*---------------------------------------------------------------------------*\
54                            Class octreeDataTriSurface Declaration
55 \*---------------------------------------------------------------------------*/
57 class octreeDataTriSurface
59     // Static data
61         //- tolerance on linear dimensions
62         static scalar tol;
64     // Private data
66         const triSurface& surface_;
68         const treeBoundBoxList allBb_;
70         // Extra data to speed up distance searches.
71         // Triangles expressed as base + spanning vectors
72         pointField base_;
73         pointField E0_;
74         pointField E1_;
75         scalarList a_;
76         scalarList b_;
77         scalarList c_;
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
85         (
86             const point& base,
87             const point& E0,
88             const point& E1,
89             const scalar a,
90             const scalar b,
91             const scalar c,
92             const point& P,
93             scalar& s,
94             scalar& t
95         );
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;
105 public:
107     // Declare name of the class and its debug switch
108     ClassName("octreeDataTriSurface");
111     // Constructors
113         //- Construct from triSurface. Holds reference. Bounding box
114         //  calculated from triangle points.
115         octreeDataTriSurface(const triSurface&);
117         //- Construct from triSurface and bounding box.
118         //  Holds references.
119         octreeDataTriSurface(const triSurface&, const treeBoundBoxList&);
122     // Member Functions
124         // Access
126             const triSurface& surface() const
127             {
128                 return surface_;
129             }
131             const treeBoundBoxList& allBb() const
132             {
133                 return allBb_;
134             }
136             label size() const
137             {
138                 return allBb_.size();
139             }
141         // Search
143             //- Get type of sample
144             label getSampleType
145             (
146                 const octree<octreeDataTriSurface>&,
147                 const point&
148             ) const;
150             //- Does (bb of) shape at index overlap bb
151             bool overlaps
152             (
153                 const label index,
154                 const treeBoundBox& sampleBb
155             ) const;
157             //- Does shape at index contain sample
158             bool contains
159             (
160                 const label index,
161                 const point& sample
162             ) const;
164             //- Segment (from start to end) intersection with shape
165             //  at index. If intersects returns true and sets intersectionPoint
166             bool intersects
167             (
168                 const label index,
169                 const point& start,
170                 const point& end,
171                 point& intersectionPoint
172             ) const;
174             //- Sets newTightest to bounding box (and returns true) if
175             //  nearer to sample than tightest bounding box. Otherwise
176             //  returns false.
177             bool findTightest
178             (
179                 const label index,
180                 const point& sample,
181                 treeBoundBox& tightest
182             ) const;
184             //- Given index get unit normal and calculate (numerical) sign 
185             //  of sample.
186             //  Used to determine accuracy of calcNearest or inside/outside.
187             scalar calcSign
188             (
189                 const label index,
190                 const point& sample,
191                 vector& n
192             ) const;
194             //- Calculates nearest (to sample) point in shape.
195             //  Returns point and mag(nearest - sample)
196             scalar calcNearest
197             (
198                 const label index,
199                 const point& sample,
200                 point& nearest
201             ) const;
203             //- Calculates nearest (to line segment) point in shape.
204             //  Returns distance and both point.
205             scalar calcNearest
206             (
207                 const label index,
208                 const linePointRef& ln,
209                 point& linePt,          // nearest point on line
210                 point& shapePt          // nearest point on shape
211             ) const;
214         // Write
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 #endif
236 // ************************************************************************* //