initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / indexedOctree / treeDataTriSurface.H
blob7a9d38c23d3e9b1a117d5484de603f4f48aab0eb
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::treeDataTriSurface
28 Description
29     Encapsulates data for (indexedOc)tree searches on triSurface.
31 SourceFiles
32     treeDataTriSurface.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef treeDataTriSurface_H
37 #define treeDataTriSurface_H
39 #include "triSurface.H"
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 namespace Foam
46 // Forward declaration of classes
47 class treeBoundBox;
48 class treeDataTriSurface;
49 template<class Type> class indexedOctree;
51 /*---------------------------------------------------------------------------*\
52                            Class treeDataTriSurface Declaration
53 \*---------------------------------------------------------------------------*/
55 class treeDataTriSurface
57     // Private data
59         const triSurface& surface_;
62     // Private Member Functions
64         //- fast triangle nearest point calculation. Returns point in E0, E1
65         //  coordinate system:  base + s*E0 + t*E1
66         static scalar nearestCoords
67         (
68             const point& base,
69             const point& E0,
70             const point& E1,
71             const scalar a,
72             const scalar b,
73             const scalar c,
74             const point& P,
75             scalar& s,
76             scalar& t
77         );
79 public:
81     // Declare name of the class and its debug switch
82     ClassName("treeDataTriSurface");
85     // Constructors
87         //- Construct from triSurface. Holds reference.
88         treeDataTriSurface(const triSurface&);
91     // Member Functions
93         // Access
95             const triSurface& surface() const
96             {
97                 return surface_;
98             }
100             label size() const
101             {
102                 return surface_.size();
103             }
105             //- Get representative point cloud for all shapes inside
106             //  (one point per shape)
107             pointField points() const;
110         // Search
112             //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
113             //  Only makes sense for closed surfaces.
114             label getVolumeType
115             (
116                 const indexedOctree<treeDataTriSurface>&,
117                 const point&
118             ) const;
120             //- Does (bb of) shape at index overlap bb
121             bool overlaps
122             (
123                 const label index,
124                 const treeBoundBox& sampleBb
125             ) const;
127             //- Calculates nearest (to sample) point in shape.
128             //  Returns actual point and distance (squared)
129             void findNearest
130             (
131                 const labelList& indices,
132                 const point& sample,
134                 scalar& nearestDistSqr,
135                 label& nearestIndex,
136                 point& nearestPoint
137             ) const;
139             //- Calculates nearest (to line) point in shape.
140             //  Returns point and distance (squared)
141             void findNearest
142             (
143                 const labelList& indices,
144                 const linePointRef& ln,
146                 treeBoundBox& tightest,
147                 label& minIndex,
148                 point& linePoint,
149                 point& nearestPoint
150             ) const;
152             //- Calculate intersection of triangle with ray. Sets result
153             //  accordingly
154             bool intersects
155             (
156                 const label index,
157                 const point& start,
158                 const point& end,
159                 point& result
160             ) const;
165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 } // End namespace Foam
169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 #endif
174 // ************************************************************************* //