1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 \*---------------------------------------------------------------------------*/
27 #include "octreeLine.H"
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 // Calculate sorted list of intersections
34 void Foam::octreeLine<Type>::calcSortedIntersections()
36 // Determine intersections and sort acc. to distance to start
38 const labelList& indices = currentLeaf_->indices();
40 sortedIntersections_.setSize(indices.size());
42 const vector direction = endPoint_ - realStartPoint_;
46 forAll(indices, elemI)
49 bool hit = tree_.shapes().intersects
57 if (hit && (indices[elemI] != lastElem_))
59 sortedIntersections_[nHits++] = pointHitSort
65 Foam::magSqr(pt - leafExitPoint_),
73 sortedIntersections_.setSize(nHits);
75 Foam::sort(sortedIntersections_);
78 //forAll(sortedIntersections_, i)
80 // Pout<< "calcSortedIntersections: After sorting:"
81 // << i << " distance:"
82 // << sortedIntersections_[i].inter().distance()
83 // << " index:" << sortedIntersections_[i].index()
91 lastElem_ = sortedIntersections_[nHits - 1].index();
93 //Pout<< "Storing lastElem_:" << lastElem_ << endl;
96 // Reset index into sortedIntersections_
101 // Searches for leaf with intersected elements. Return true if found; false
102 // otherwise. Sets currentLeaf_ and sortedIntersections_.
103 template <class Type>
104 bool Foam::octreeLine<Type>::getNextLeaf()
108 // No current leaf. Find first one.
109 // Note: search starts from top every time
111 point start(leafExitPoint_);
112 currentLeaf_ = tree_.findLeafLine(start, endPoint_, leafExitPoint_);
116 // No leaf found. Give up.
120 // Get intersections and sort.
121 calcSortedIntersections();
123 while (sortedIntersections_.empty());
129 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
131 template <class Type>
132 Foam::octreeLine<Type>::octreeLine
134 const octree<Type>& tree,
135 const point& startPoint,
136 const point& endPoint
140 startPoint_(startPoint),
142 realStartPoint_(startPoint),
143 leafExitPoint_(startPoint_),
145 sortedIntersections_(0),
151 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
153 template <class Type>
154 Foam::octreeLine<Type>::~octreeLine()
158 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
160 template <class Type>
161 bool Foam::octreeLine<Type>::getIntersection()
163 // Go to next element in sortedIntersections
167 if (sortedI_ >= sortedIntersections_.size())
169 // Past all sortedIntersections in current leaf. Go to next one.
172 // No valid leaf found
181 // ************************************************************************* //