initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / octree / octreeDataPoint.H
blob32e47097345141f2883cbbb34756b178e8969e1b
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::octreeDataPoint
28 Description
29     Encapsulation of data needed for octree searches.
31     Used for searching for nearest point. No bounding boxes around points.
32     Only overlaps and calcNearest are implemented, rest makes little sense.
33     Holds (reference to) pointField.
35 SourceFiles
36     octreeDataPoint.C
37     octreeDataPointTreaLeaf.H   (template specialization of treeleaf)
38     octreeDataPointTreeLeaf.C   (template specialization of treeleaf)
40 \*---------------------------------------------------------------------------*/
42 #ifndef octreeDataPoint_H
43 #define octreeDataPoint_H
45 #include "point.H"
46 #include "pointField.H"
47 #include "treeBoundBox.H"
48 #include "linePointRef.H"
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 namespace Foam
55 template<class Type> class octree;
57 /*---------------------------------------------------------------------------*\
58                            Class octreeDataPoint Declaration
59 \*---------------------------------------------------------------------------*/
61 class octreeDataPoint
63     // Private data
65         const pointField& points_;
67 public:
69     // Constructors
71         //- Construct from components. Holds reference to points!
72         octreeDataPoint(const pointField&);
75     // Member Functions
77         // Access
79             const pointField& points() const
80             {
81                 return points_;
82             }
84             label size() const
85             {
86                 return points_.size();
87             }
89         // Search
91             //- Get type of sample
92             label getSampleType
93             (
94                 const octree<octreeDataPoint>&,
95                 const point&
96             ) const;
98             //- Does (bb of) shape at index overlap bb
99             bool overlaps
100             (
101                 const label index,
102                 const treeBoundBox& sampleBb
103             ) const;
105             //- Does shape at index contain sample
106             bool contains
107             (
108                 const label index,
109                 const point& sample
110             ) const;
112             //- Segment (from start to end) intersection with shape
113             //  at index. If intersects returns true and sets intersectionPoint
114             bool intersects
115             (
116                 const label index,
117                 const point& start,
118                 const point& end,
119                 point& intersectionPoint
120             ) const;
122             //- Sets newTightest to bounding box (and returns true) if
123             //  nearer to sample than tightest bounding box. Otherwise
124             //  returns false.
125             bool findTightest
126             (
127                 const label index,
128                 const point& sample,
129                 treeBoundBox& tightest
130             ) const;
132             //- Given index get unit normal and calculate (numerical) sign
133             //  of sample.
134             //  Used to determine accuracy of calcNearest or inside/outside.
135             //  Note: always returns GREAT since no inside/outside.
136             scalar calcSign
137             (
138                 const label index,
139                 const point& sample,
140                 vector& n
141             ) const;
144             //- Calculates nearest (to sample) point on/in shape.
145             //  Returns point and mag(nearest - sample)
146             scalar calcNearest
147             (
148                 const label index,
149                 const point& sample,
150                 point& nearest
151             ) const;
153             //- Calculates nearest (to line segment) point in shape.
154             //  Returns distance and both point.
155             scalar calcNearest
156             (
157                 const label index,
158                 const linePointRef& ln,
159                 point& linePt,          // nearest point on line
160                 point& shapePt          // nearest point on shape
161             ) const;
165         // Write
167             //- Write shape at index
168             void write(Ostream& os, const label index) const;
171     // IOstream Operators
173         friend Ostream& operator<<(Ostream&, const octreeDataPoint&);
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 } // End namespace Foam
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 #endif
185 // ************************************************************************* //