octreeLine.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "octreeLine.H"
00028 #include "octree.H"
00029
00030
00031
00032
00033 template <class Type>
00034 void Foam::octreeLine<Type>::calcSortedIntersections()
00035 {
00036
00037
00038 const labelList& indices = currentLeaf_->indices();
00039
00040 sortedIntersections_.setSize(indices.size());
00041
00042 const vector direction = endPoint_ - realStartPoint_;
00043
00044 label nHits = 0;
00045
00046 forAll(indices, elemI)
00047 {
00048 point pt;
00049 bool hit = tree_.shapes().intersects
00050 (
00051 indices[elemI],
00052 realStartPoint_,
00053 direction,
00054 pt
00055 );
00056
00057 if (hit && (indices[elemI] != lastElem_))
00058 {
00059 sortedIntersections_[nHits++] = pointHitSort
00060 (
00061 pointHit
00062 (
00063 true,
00064 pt,
00065 Foam::magSqr(pt - leafExitPoint_),
00066 false
00067 ),
00068 indices[elemI]
00069 );
00070 }
00071 }
00072
00073 sortedIntersections_.setSize(nHits);
00074
00075 Foam::sort(sortedIntersections_);
00076
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 lastElem_ = -1;
00088
00089 if (nHits > 0)
00090 {
00091 lastElem_ = sortedIntersections_[nHits - 1].index();
00092
00093
00094 }
00095
00096
00097 sortedI_ = -1;
00098 }
00099
00100
00101
00102
00103 template <class Type>
00104 bool Foam::octreeLine<Type>::getNextLeaf()
00105 {
00106 do
00107 {
00108
00109
00110
00111 point start(leafExitPoint_);
00112 currentLeaf_ = tree_.findLeafLine(start, endPoint_, leafExitPoint_);
00113
00114 if (!currentLeaf_)
00115 {
00116
00117 return false;
00118 }
00119
00120
00121 calcSortedIntersections();
00122 }
00123 while (sortedIntersections_.empty());
00124
00125 return true;
00126 }
00127
00128
00129
00130
00131 template <class Type>
00132 Foam::octreeLine<Type>::octreeLine
00133 (
00134 const octree<Type>& tree,
00135 const point& startPoint,
00136 const point& endPoint
00137 )
00138 :
00139 tree_(tree),
00140 startPoint_(startPoint),
00141 endPoint_(endPoint),
00142 realStartPoint_(startPoint),
00143 leafExitPoint_(startPoint_),
00144 currentLeaf_(NULL),
00145 sortedIntersections_(0),
00146 lastElem_(-1),
00147 sortedI_(-1)
00148 {}
00149
00150
00151
00152
00153 template <class Type>
00154 Foam::octreeLine<Type>::~octreeLine()
00155 {}
00156
00157
00158
00159
00160 template <class Type>
00161 bool Foam::octreeLine<Type>::getIntersection()
00162 {
00163
00164
00165 sortedI_++;
00166
00167 if (sortedI_ >= sortedIntersections_.size())
00168 {
00169
00170 if (!getNextLeaf())
00171 {
00172
00173 return false;
00174 }
00175 sortedI_ = 0;
00176 }
00177
00178 return true;
00179 }
00180
00181
Copyright © 2000-2009 OpenCFD Ltd