1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "octreeLine.H"
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 // Calculate sorted list of intersections
33 void Foam::octreeLine<Type>::calcSortedIntersections()
35 // Determine intersections and sort acc. to distance to start
37 const labelList& indices = currentLeaf_->indices();
39 sortedIntersections_.setSize(indices.size());
41 const vector direction = endPoint_ - realStartPoint_;
45 forAll(indices, elemI)
48 bool hit = tree_.shapes().intersects
56 if (hit && (indices[elemI] != lastElem_))
58 sortedIntersections_[nHits++] = pointHitSort
64 Foam::magSqr(pt - leafExitPoint_),
72 sortedIntersections_.setSize(nHits);
74 Foam::sort(sortedIntersections_);
77 //forAll(sortedIntersections_, i)
79 // Pout<< "calcSortedIntersections: After sorting:"
80 // << i << " distance:"
81 // << sortedIntersections_[i].inter().distance()
82 // << " index:" << sortedIntersections_[i].index()
90 lastElem_ = sortedIntersections_[nHits - 1].index();
92 //Pout<< "Storing lastElem_:" << lastElem_ << endl;
95 // Reset index into sortedIntersections_
100 // Searches for leaf with intersected elements. Return true if found; false
101 // otherwise. Sets currentLeaf_ and sortedIntersections_.
102 template <class Type>
103 bool Foam::octreeLine<Type>::getNextLeaf()
107 // No current leaf. Find first one.
108 // Note: search starts from top every time
110 point start(leafExitPoint_);
111 currentLeaf_ = tree_.findLeafLine(start, endPoint_, leafExitPoint_);
115 // No leaf found. Give up.
119 // Get intersections and sort.
120 calcSortedIntersections();
122 while (sortedIntersections_.empty());
128 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
130 template <class Type>
131 Foam::octreeLine<Type>::octreeLine
133 const octree<Type>& tree,
134 const point& startPoint,
135 const point& endPoint
139 startPoint_(startPoint),
141 realStartPoint_(startPoint),
142 leafExitPoint_(startPoint_),
144 sortedIntersections_(0),
150 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
152 template <class Type>
153 Foam::octreeLine<Type>::~octreeLine()
157 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
159 template <class Type>
160 bool Foam::octreeLine<Type>::getIntersection()
162 // Go to next element in sortedIntersections
166 if (sortedI_ >= sortedIntersections_.size())
168 // Past all sortedIntersections in current leaf. Go to next one.
171 // No valid leaf found
180 // ************************************************************************* //