OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

octreeLine.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::octreeLine
00027 
00028 Description
00029     Iterates over intersections of line with octree leaf elements.
00030 
00031     Used as in
00032     @code
00033         octree<octreeDataFace> oc( .. );
00034 
00035         octreeLine<octreeDataFace> lineSearch(oc, pStart, pEnd);
00036 
00037         while (lineSearch.getIntersection())
00038         {
00039             const point& pt = lineSearch.hitInfo().hitPoint();
00040             ..
00041         }
00042     @endcode
00043 
00044 SourceFiles
00045     octreeLine.C
00046 
00047 \*---------------------------------------------------------------------------*/
00048 
00049 #ifndef octreeLine_H
00050 #define octreeLine_H
00051 
00052 #include "boolList.H"
00053 #include "point.H"
00054 #include "pointHitSort.H"
00055 
00056 
00057 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00058 
00059 namespace Foam
00060 {
00061 
00062 // Forward declaration of classes
00063 template<class Type> class octree;
00064 template<class Type> class treeLeaf;
00065 
00066 
00067 /*---------------------------------------------------------------------------*\
00068                            Class octreeLine Declaration
00069 \*---------------------------------------------------------------------------*/
00070 
00071 template <class Type>
00072 class octreeLine
00073 {
00074     // Private data
00075 
00076         //- Octree reference
00077         const octree<Type>& tree_;
00078 
00079         //- Start of segment
00080         const point startPoint_;
00081 
00082         //- End of segment
00083         const point endPoint_;
00084 
00085         //- Start moved into bb
00086         point realStartPoint_;
00087 
00088         //- Exit point of intersection with current treeLeaf
00089         point leafExitPoint_;
00090 
00091         //- Current treeLeaf to be searched in.
00092         const treeLeaf<Type>* currentLeaf_;
00093 
00094         //- Sorted list of intersections
00095         List<pointHitSort> sortedIntersections_;
00096 
00097         //- index of last hit in previous treeLeaf. Used so if shape double
00098         //  it does not get counted twice. Note is not ok for concave shapes
00099         label lastElem_;
00100 
00101         //- Current hit: index in sortedIntersections_
00102         label sortedI_;
00103 
00104     // Private Member Functions
00105 
00106         //- Calculate sorted list of intersections
00107         void calcSortedIntersections();
00108 
00109         //- Searches for leaf with intersected elements.
00110         //  Return true if found; false otherwise.
00111         //  Sets currentLeaf_ and sortedIntersections_
00112         bool getNextLeaf();
00113 
00114 public:
00115 
00116     // Constructors
00117 
00118         //- Construct from components
00119         octreeLine
00120         (
00121             const octree<Type>& tree,
00122             const point& startPoint,
00123             const point& endPoint
00124         );
00125 
00126 
00127     // Destructor
00128 
00129         ~octreeLine();
00130 
00131 
00132     // Member Functions
00133 
00134         const octree<Type>& tree() const
00135         {
00136             return tree_;
00137         }
00138 
00139         const point& leafExitPoint() const
00140         {
00141             return leafExitPoint_;
00142         }
00143 
00144         const point& endPoint() const
00145         {
00146             return endPoint_;
00147         }
00148 
00149         const point& startPoint() const
00150         {
00151             return startPoint_;
00152         }
00153 
00154         const treeLeaf<Type>* currentLeaf() const
00155         {
00156             return currentLeaf_;
00157         }
00158 
00159         const List<pointHitSort>& sortedIntersections() const
00160         {
00161             return sortedIntersections_;
00162         }
00163 
00164         label hitIndex() const
00165         {
00166             return sortedIntersections_[sortedI_].index();
00167         }
00168 
00169         const pointHit& hitInfo() const
00170         {
00171             return sortedIntersections_[sortedI_].inter();
00172         }
00173 
00174 
00175         //- go to next intersection. Return false if no intersections.
00176         bool getIntersection();
00177 
00178 };
00179 
00180 
00181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00182 
00183 } // End namespace Foam
00184 
00185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00186 
00187 #ifdef NoRepository
00188 #   include "octreeLine.C"
00189 #endif
00190 
00191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00192 
00193 #endif
00194 
00195 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd