initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / octree / octreeDataFace.H
blob0f0fef78cb5e15a71ef411120e1e1d2b599099fd
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::octreeDataFace
28 Description
29     Holds data for octree to work on mesh faces.
31     For example, calculate (in calcNearest) the correct intersection point
32     with a face.
34 SourceFiles
35     octreeDataFace.C
37 \*---------------------------------------------------------------------------*/
39 #ifndef octreeDataFace_H
40 #define octreeDataFace_H
42 #include "treeBoundBoxList.H"
43 #include "faceList.H"
44 #include "point.H"
45 #include "className.H"
46 #include "linePointRef.H"
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 namespace Foam
53 // Forward declaration of classes
54 class primitiveMesh;
55 template<class Type> class octree;
56 class polyPatch;
58 /*---------------------------------------------------------------------------*\
59                        Class octreeDataFace Declaration
60 \*---------------------------------------------------------------------------*/
62 class octreeDataFace
64     // Static data
66         //- tolerance on linear dimensions
67         static scalar tol;
70     // Private data
72         //- the mesh
73         const primitiveMesh& mesh_;
75         //- labels (in mesh indexing) of faces
76         labelList meshFaces_;
78         //- bbs for all above faces
79         treeBoundBoxList allBb_;
82     // Private Member Functions
84         //- Set allBb to tight fitting bounding box
85         void calcBb();
87 public:
89     // Declare name of the class and its debug switch
90     ClassName("octreeDataFace");
92     // Constructors
94         //- Construct from selected mesh faces.
95         octreeDataFace
96         (
97             const primitiveMesh&,
98             const labelList& meshFaces,
99             const treeBoundBoxList&
100         );
102         //- Construct from selected mesh faces. Tight fitting bounding boxes
103         //  generated internally.
104         octreeDataFace
105         (
106             const primitiveMesh&,
107             const labelList& meshFaces
108         );
110         //- Construct from selected mesh faces.
111         octreeDataFace
112         (
113             const primitiveMesh&,
114             const UList<const labelList*>&,
115             const UList<const treeBoundBoxList*>&
116         );
118         //- Construct from selected mesh faces.
119         //  Tight-fitting bounding boxes generated internally.
120         octreeDataFace(const primitiveMesh&, const UList<const labelList*>&);
122         //- Construct from all faces in patch.
123         //  Tight-fitting bounding boxes generated internally.
124         octreeDataFace(const polyPatch&);
126         //- Construct from all boundary faces.
127         //  Tight-fitting bounding boxes generated internally.
128         octreeDataFace(const primitiveMesh&);
130         //- Construct as copy
131         octreeDataFace(const octreeDataFace&);
134     // Destructor
136         ~octreeDataFace();
139     // Member Functions
141         // Access
143             const primitiveMesh& mesh() const
144             {
145                 return mesh_;
146             }
148             const labelList& meshFaces() const
149             {
150                 return meshFaces_;
151             }
153             const treeBoundBoxList& allBb() const
154             {
155                 return allBb_;
156             }
158             label size() const
159             {
160                 return allBb_.size();
161             }
164         // Search
166             //- Get type of sample
167             label getSampleType
168             (
169                 const octree<octreeDataFace>&,
170                 const point&
171             ) const;
173             //- Does (bb of) shape at index overlap bb
174             bool overlaps
175             (
176                 const label index,
177                 const treeBoundBox& sampleBb
178             ) const;
180             //- Does shape at index contain sample
181             bool contains(const label index, const point& sample) const;
183             //- Segment (from start to end) intersection with shape
184             //  at index. If intersects returns true and sets intersectionPoint
185             bool intersects
186             (
187                 const label index,
188                 const point& start,
189                 const point& end,
190                 point& intersectionPoint
191             ) const;
193             //- Sets newTightest to bounding box (and returns true) if
194             //  nearer to sample than tightest bounding box. Otherwise
195             //  returns false.
196             bool findTightest
197             (
198                 const label index,
199                 const point& sample,
200                 treeBoundBox& tightest
201             ) const;
203             //- Given index get unit normal and calculate (numerical) sign
204             //  of sample.
205             //  Used to determine accuracy of calcNearest or inside/outside.
206             scalar calcSign
207             (
208                 const label index,
209                 const point& sample,
210                 vector& n
211             ) const;
213             //- Calculates nearest (to sample) point in shape.
214             //  Returns point and mag(nearest - sample). Returns GREAT if
215             //  sample does not project onto (triangle decomposition) of face.
216             scalar calcNearest
217             (
218                 const label index,
219                 const point& sample,
220                 point& nearest
221             ) const;
223             //- Calculates nearest (to line segment) point in shape.
224             //  Returns distance and both point.
225             scalar calcNearest
226             (
227                 const label index,
228                 const linePointRef& ln,
229                 point& linePt,          // nearest point on line
230                 point& shapePt          // nearest point on shape
231             ) const;
234         // Write
236             //- Write shape at index
237             void write(Ostream& os, const label index) const;
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 } // End namespace Foam
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
248 #endif
250 // ************************************************************************* //