FreeFOAM The Cross-Platform CFD Toolkit
octreeLine.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Class
25  Foam::octreeLine
26 
27 Description
28  Iterates over intersections of line with octree leaf elements.
29 
30  Used as in
31  @code
32  octree<octreeDataFace> oc( .. );
33 
34  octreeLine<octreeDataFace> lineSearch(oc, pStart, pEnd);
35 
36  while (lineSearch.getIntersection())
37  {
38  const point& pt = lineSearch.hitInfo().hitPoint();
39  ..
40  }
41  @endcode
42 
43 SourceFiles
44  octreeLine.C
45 
46 \*---------------------------------------------------------------------------*/
47 
48 #ifndef octreeLine_H
49 #define octreeLine_H
50 
51 #include <OpenFOAM/boolList.H>
52 #include <OpenFOAM/point.H>
53 #include "pointHitSort.H"
54 
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 // Forward declaration of classes
62 template<class Type> class octree;
63 template<class Type> class treeLeaf;
64 
65 
66 /*---------------------------------------------------------------------------*\
67  Class octreeLine Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 template <class Type>
72 {
73  // Private data
74 
75  //- Octree reference
76  const octree<Type>& tree_;
77 
78  //- Start of segment
79  const point startPoint_;
80 
81  //- End of segment
82  const point endPoint_;
83 
84  //- Start moved into bb
85  point realStartPoint_;
86 
87  //- Exit point of intersection with current treeLeaf
88  point leafExitPoint_;
89 
90  //- Current treeLeaf to be searched in.
91  const treeLeaf<Type>* currentLeaf_;
92 
93  //- Sorted list of intersections
94  List<pointHitSort> sortedIntersections_;
95 
96  //- index of last hit in previous treeLeaf. Used so if shape double
97  // it does not get counted twice. Note is not ok for concave shapes
98  label lastElem_;
99 
100  //- Current hit: index in sortedIntersections_
101  label sortedI_;
102 
103  // Private Member Functions
104 
105  //- Calculate sorted list of intersections
106  void calcSortedIntersections();
107 
108  //- Searches for leaf with intersected elements.
109  // Return true if found; false otherwise.
110  // Sets currentLeaf_ and sortedIntersections_
111  bool getNextLeaf();
112 
113 public:
114 
115  // Constructors
116 
117  //- Construct from components
118  octreeLine
119  (
120  const octree<Type>& tree,
121  const point& startPoint,
122  const point& endPoint
123  );
124 
125 
126  // Destructor
127 
128  ~octreeLine();
129 
130 
131  // Member Functions
132 
133  const octree<Type>& tree() const
134  {
135  return tree_;
136  }
137 
138  const point& leafExitPoint() const
139  {
140  return leafExitPoint_;
141  }
142 
143  const point& endPoint() const
144  {
145  return endPoint_;
146  }
147 
148  const point& startPoint() const
149  {
150  return startPoint_;
151  }
152 
154  {
155  return currentLeaf_;
156  }
157 
159  {
160  return sortedIntersections_;
161  }
162 
163  label hitIndex() const
164  {
165  return sortedIntersections_[sortedI_].index();
166  }
167 
168  const pointHit& hitInfo() const
169  {
170  return sortedIntersections_[sortedI_].inter();
171  }
172 
173 
174  //- go to next intersection. Return false if no intersections.
175  bool getIntersection();
176 
177 };
178 
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 } // End namespace Foam
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 #ifdef NoRepository
187 # include "octreeLine.C"
188 #endif
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 #endif
193 
194 // ************************ vim: set sw=4 sts=4 et: ************************ //