initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / meshTools / octree / octreeLine.H
blob6bc5fafb6a79d32e88977c438c51d3c6e69b53d9
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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::octreeLine
28 Description
29     Iterates over intersections of line with octree leaf elements.
31     Used as in
32     @code
33         octree<octreeDataFace> oc( .. );
35         octreeLine<octreeDataFace> lineSearch(oc, pStart, pEnd);
37         while (lineSearch.getIntersection())
38         {
39             const point& pt = lineSearch.hitInfo().hitPoint();
40             ..
41         }
42     @endcode
44 SourceFiles
45     octreeLine.C
47 \*---------------------------------------------------------------------------*/
49 #ifndef octreeLine_H
50 #define octreeLine_H
52 #include "boolList.H"
53 #include "point.H"
54 #include "pointHitSort.H"
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 namespace Foam
62 // Forward declaration of classes
63 template<class Type> class octree;
64 template<class Type> class treeLeaf;
67 /*---------------------------------------------------------------------------*\
68                            Class octreeLine Declaration
69 \*---------------------------------------------------------------------------*/
71 template <class Type>
72 class octreeLine
74     // Private data
76         //- Octree reference
77         const octree<Type>& tree_;
79         //- Start of segment
80         const point startPoint_;
82         //- End of segment
83         const point endPoint_;
85         //- Start moved into bb
86         point realStartPoint_;
88         //- Exit point of intersection with current treeLeaf
89         point leafExitPoint_;
91         //- Current treeLeaf to be searched in.
92         const treeLeaf<Type>* currentLeaf_;
94         //- Sorted list of intersections
95         List<pointHitSort> sortedIntersections_;
97         //- index of last hit in previous treeLeaf. Used so if shape double
98         //  it does not get counted twice. Note is not ok for concave shapes
99         label lastElem_;
101         //- Current hit: index in sortedIntersections_
102         label sortedI_;
104     // Private Member Functions
106         //- Calculate sorted list of intersections
107         void calcSortedIntersections();
109         //- Searches for leaf with intersected elements.
110         //  Return true if found; false otherwise.
111         //  Sets currentLeaf_ and sortedIntersections_
112         bool getNextLeaf();
114 public:
116     // Constructors
118         //- Construct from components
119         octreeLine
120         (
121             const octree<Type>& tree,
122             const point& startPoint,
123             const point& endPoint
124         );
127     // Destructor
129         ~octreeLine();
132     // Member Functions
134         const octree<Type>& tree() const
135         {
136             return tree_;
137         }
139         const point& leafExitPoint() const
140         {
141             return leafExitPoint_;
142         }
144         const point& endPoint() const
145         {
146             return endPoint_;
147         }
149         const point& startPoint() const
150         {
151             return startPoint_;
152         }
154         const treeLeaf<Type>* currentLeaf() const
155         {
156             return currentLeaf_;
157         }
159         const List<pointHitSort>& sortedIntersections() const
160         {
161             return sortedIntersections_;
162         }
164         label hitIndex() const
165         {
166             return sortedIntersections_[sortedI_].index();
167         }
169         const pointHit& hitInfo() const
170         {
171             return sortedIntersections_[sortedI_].inter();
172         }
175         //- go to next intersection. Return false if no intersections.
176         bool getIntersection();
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 } // End namespace Foam
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187 #ifdef NoRepository
188 #   include "octreeLine.C"
189 #endif
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 #endif
195 // ************************************************************************* //