Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / meshTools / octree / octreeDataFace.H
blob93c2f5e5fbc8bb49b4bd0d689ab216fbed357b3b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::octreeDataFace
27 Description
28     Holds data for octree to work on mesh faces.
30     For example, calculate (in calcNearest) the correct intersection point
31     with a face.
33 SourceFiles
34     octreeDataFace.C
36 \*---------------------------------------------------------------------------*/
38 #ifndef octreeDataFace_H
39 #define octreeDataFace_H
41 #include "treeBoundBoxList.H"
42 #include "faceList.H"
43 #include "point.H"
44 #include "className.H"
45 #include "linePointRef.H"
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 namespace Foam
52 // Forward declaration of classes
53 class primitiveMesh;
54 template<class Type> class octree;
55 class polyPatch;
57 /*---------------------------------------------------------------------------*\
58                        Class octreeDataFace Declaration
59 \*---------------------------------------------------------------------------*/
61 class octreeDataFace
63     // Static data
65         //- tolerance on linear dimensions
66         static scalar tol;
69     // Private data
71         //- the mesh
72         const primitiveMesh& mesh_;
74         //- labels (in mesh indexing) of faces
75         labelList meshFaces_;
77         //- bbs for all above faces
78         treeBoundBoxList allBb_;
81     // Private Member Functions
83         //- Set allBb to tight fitting bounding box
84         void calcBb();
86 public:
88     // Declare name of the class and its debug switch
89     ClassName("octreeDataFace");
91     // Constructors
93         //- Construct from selected mesh faces.
94         octreeDataFace
95         (
96             const primitiveMesh&,
97             const labelList& meshFaces,
98             const treeBoundBoxList&
99         );
101         //- Construct from selected mesh faces. Tight fitting bounding boxes
102         //  generated internally.
103         octreeDataFace
104         (
105             const primitiveMesh&,
106             const labelList& meshFaces
107         );
109         //- Construct from selected mesh faces.
110         octreeDataFace
111         (
112             const primitiveMesh&,
113             const UList<const labelList*>&,
114             const UList<const treeBoundBoxList*>&
115         );
117         //- Construct from selected mesh faces.
118         //  Tight-fitting bounding boxes generated internally.
119         octreeDataFace(const primitiveMesh&, const UList<const labelList*>&);
121         //- Construct from all faces in patch.
122         //  Tight-fitting bounding boxes generated internally.
123         octreeDataFace(const polyPatch&);
125         //- Construct from all boundary faces.
126         //  Tight-fitting bounding boxes generated internally.
127         octreeDataFace(const primitiveMesh&);
129         //- Construct as copy
130         octreeDataFace(const octreeDataFace&);
133     //- Destructor
134     ~octreeDataFace();
137     // Member Functions
139         // Access
141             const primitiveMesh& mesh() const
142             {
143                 return mesh_;
144             }
146             const labelList& meshFaces() const
147             {
148                 return meshFaces_;
149             }
151             const treeBoundBoxList& allBb() const
152             {
153                 return allBb_;
154             }
156             label size() const
157             {
158                 return allBb_.size();
159             }
162         // Search
164             //- Get type of sample
165             label getSampleType
166             (
167                 const octree<octreeDataFace>&,
168                 const point&
169             ) const;
171             //- Does (bb of) shape at index overlap bb
172             bool overlaps
173             (
174                 const label index,
175                 const treeBoundBox& sampleBb
176             ) const;
178             //- Does shape at index contain sample
179             bool contains(const label index, const point& sample) const;
181             //- Segment (from start to end) intersection with shape
182             //  at index. If intersects returns true and sets intersectionPoint
183             bool intersects
184             (
185                 const label index,
186                 const point& start,
187                 const point& end,
188                 point& intersectionPoint
189             ) const;
191             //- Sets newTightest to bounding box (and returns true) if
192             //  nearer to sample than tightest bounding box. Otherwise
193             //  returns false.
194             bool findTightest
195             (
196                 const label index,
197                 const point& sample,
198                 treeBoundBox& tightest
199             ) const;
201             //- Given index get unit normal and calculate (numerical) sign
202             //  of sample.
203             //  Used to determine accuracy of calcNearest or inside/outside.
204             scalar calcSign
205             (
206                 const label index,
207                 const point& sample,
208                 vector& n
209             ) const;
211             //- Calculates nearest (to sample) point in shape.
212             //  Returns point and mag(nearest - sample). Returns GREAT if
213             //  sample does not project onto (triangle decomposition) of face.
214             scalar calcNearest
215             (
216                 const label index,
217                 const point& sample,
218                 point& nearest
219             ) const;
221             //- Calculates nearest (to line segment) point in shape.
222             //  Returns distance and both point.
223             scalar calcNearest
224             (
225                 const label index,
226                 const linePointRef& ln,
227                 point& linePt,          // nearest point on line
228                 point& shapePt          // nearest point on shape
229             ) const;
232         // Write
234             //- Write shape at index
235             void write(Ostream& os, const label index) const;
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 } // End namespace Foam
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246 #endif
248 // ************************************************************************* //