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 #include "treeDataEdge.H"
00027 #include "indexedOctree.H"
00028
00029
00030
00031 defineTypeNameAndDebug(Foam::treeDataEdge, 0);
00032
00033
00034
00035
00036 Foam::treeBoundBox Foam::treeDataEdge::calcBb(const label edgeI) const
00037 {
00038 const edge& e = edges_[edgeI];
00039 const point& p0 = points_[e[0]];
00040 const point& p1 = points_[e[1]];
00041
00042 return treeBoundBox(min(p0, p1), max(p0, p1));
00043 }
00044
00045
00046
00047
00048
00049 Foam::treeDataEdge::treeDataEdge
00050 (
00051 const bool cacheBb,
00052 const edgeList& edges,
00053 const pointField& points,
00054 const labelList& edgeLabels
00055 )
00056 :
00057 edges_(edges),
00058 points_(points),
00059 edgeLabels_(edgeLabels),
00060 cacheBb_(cacheBb)
00061 {
00062 if (cacheBb_)
00063 {
00064 bbs_.setSize(edgeLabels_.size());
00065
00066 forAll(edgeLabels_, i)
00067 {
00068 bbs_[i] = calcBb(edgeLabels_[i]);
00069 }
00070 }
00071 }
00072
00073
00074
00075
00076 Foam::pointField Foam::treeDataEdge::points() const
00077 {
00078 pointField eMids(edgeLabels_.size());
00079
00080 forAll(edgeLabels_, i)
00081 {
00082 const edge& e = edges_[edgeLabels_[i]];
00083
00084 eMids[i] = e.centre(points_);
00085 }
00086 return eMids;
00087 }
00088
00089
00090
00091
00092 Foam::label Foam::treeDataEdge::getVolumeType
00093 (
00094 const indexedOctree<treeDataEdge>& oc,
00095 const point& sample
00096 ) const
00097 {
00098 return indexedOctree<treeDataEdge>::UNKNOWN;
00099 }
00100
00101
00102
00103 bool Foam::treeDataEdge::overlaps
00104 (
00105 const label index,
00106 const treeBoundBox& cubeBb
00107 ) const
00108 {
00109 if (cacheBb_)
00110 {
00111 return cubeBb.overlaps(bbs_[index]);
00112 }
00113 else
00114 {
00115 return cubeBb.overlaps(calcBb(edgeLabels_[index]));
00116 }
00117 }
00118
00119
00120
00121
00122 void Foam::treeDataEdge::findNearest
00123 (
00124 const labelList& indices,
00125 const point& sample,
00126
00127 scalar& nearestDistSqr,
00128 label& minIndex,
00129 point& nearestPoint
00130 ) const
00131 {
00132 forAll(indices, i)
00133 {
00134 label index = indices[i];
00135
00136 const edge& e = edges_[edgeLabels_[index]];
00137
00138 pointHit nearHit = e.line(points_).nearestDist(sample);
00139
00140 scalar distSqr = sqr(nearHit.distance());
00141
00142 if (distSqr < nearestDistSqr)
00143 {
00144 nearestDistSqr = distSqr;
00145 minIndex = index;
00146 nearestPoint = nearHit.rawPoint();
00147 }
00148 }
00149 }
00150
00151
00152
00153
00154 void Foam::treeDataEdge::findNearest
00155 (
00156 const labelList& indices,
00157 const linePointRef& ln,
00158
00159 treeBoundBox& tightest,
00160 label& minIndex,
00161 point& linePoint,
00162 point& nearestPoint
00163 ) const
00164 {
00165
00166 scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
00167
00168 forAll(indices, i)
00169 {
00170 label index = indices[i];
00171
00172 const edge& e = edges_[edgeLabels_[index]];
00173
00174
00175
00176
00177 point ePoint, lnPt;
00178 scalar dist = e.line(points_).nearestDist(ln, ePoint, lnPt);
00179 scalar distSqr = sqr(dist);
00180
00181 if (distSqr < nearestDistSqr)
00182 {
00183 nearestDistSqr = distSqr;
00184 minIndex = index;
00185 linePoint = lnPt;
00186 nearestPoint = ePoint;
00187
00188 {
00189 point& minPt = tightest.min();
00190 minPt = min(ln.start(), ln.end());
00191 minPt.x() -= dist;
00192 minPt.y() -= dist;
00193 minPt.z() -= dist;
00194 }
00195 {
00196 point& maxPt = tightest.max();
00197 maxPt = max(ln.start(), ln.end());
00198 maxPt.x() += dist;
00199 maxPt.y() += dist;
00200 maxPt.z() += dist;
00201 }
00202 }
00203 }
00204 }
00205
00206
00207