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 "octreeDataEdges.H"
00027
00028 #include <OpenFOAM/line.H>
00029 #include <OpenFOAM/labelList.H>
00030 #include "octree.H"
00031 #include <OpenFOAM/linePointRef.H>
00032 #include <OpenFOAM/pointHit.H>
00033
00034
00035
00036 defineTypeNameAndDebug(Foam::octreeDataEdges, 0);
00037
00038 Foam::scalar Foam::octreeDataEdges::tol(1E-6);
00039
00040
00041
00042
00043
00044
00045
00046
00047 Foam::octreeDataEdges::octreeDataEdges
00048 (
00049 const edgeList& edges,
00050 const pointField& points,
00051 const labelList& edgeLabels
00052 )
00053 :
00054 edges_(edges),
00055 points_(points),
00056 edgeLabels_(edgeLabels),
00057 allBb_(edgeLabels_.size())
00058 {
00059
00060 forAll(edgeLabels_, i)
00061 {
00062 label edgeI = edgeLabels_[i];
00063
00064 const edge& e = edges_[edgeI];
00065
00066 const point& a = points_[e.start()];
00067 const point& b = points_[e.end()];
00068
00069 allBb_[i].min() = min(a, b);
00070 allBb_[i].max() = max(a, b);
00071 }
00072 }
00073
00074
00075
00076 Foam::octreeDataEdges::octreeDataEdges(const octreeDataEdges& shapes)
00077 :
00078 edges_(shapes.edges()),
00079 points_(shapes.points()),
00080 edgeLabels_(shapes.edgeLabels()),
00081 allBb_(shapes.allBb())
00082 {}
00083
00084
00085
00086
00087 Foam::octreeDataEdges::~octreeDataEdges()
00088 {}
00089
00090
00091
00092
00093 Foam::label Foam::octreeDataEdges::getSampleType
00094 (
00095 const octree<octreeDataEdges>&,
00096 const point&
00097 ) const
00098 {
00099 return octree<octreeDataEdges>::UNKNOWN;
00100 }
00101
00102
00103 bool Foam::octreeDataEdges::overlaps
00104 (
00105 const label index,
00106 const treeBoundBox& sampleBb
00107 ) const
00108 {
00109 return sampleBb.overlaps(allBb_[index]);
00110 }
00111
00112
00113 bool Foam::octreeDataEdges::contains
00114 (
00115 const label,
00116 const point&
00117 ) const
00118 {
00119 notImplemented
00120 (
00121 "octreeDataEdges::contains(const label, const point&)"
00122 );
00123 return false;
00124 }
00125
00126
00127 bool Foam::octreeDataEdges::intersects
00128 (
00129 const label,
00130 const point&,
00131 const point&,
00132 point&
00133 ) const
00134 {
00135 notImplemented
00136 (
00137 "octreeDataEdges::intersects(const label, const point&"
00138 ", const point&, point&)"
00139 );
00140 return false;
00141 }
00142
00143
00144 bool Foam::octreeDataEdges::findTightest
00145 (
00146 const label index,
00147 const point& sample,
00148 treeBoundBox& tightest
00149 ) const
00150 {
00151
00152 point myNear, myFar;
00153 allBb_[index].calcExtremities(sample, myNear, myFar);
00154
00155 const point dist = myFar - sample;
00156 scalar myFarDist = mag(dist);
00157
00158 point tightestNear, tightestFar;
00159 tightest.calcExtremities(sample, tightestNear, tightestFar);
00160
00161 scalar tightestFarDist = mag(tightestFar - sample);
00162
00163 if (tightestFarDist < myFarDist)
00164 {
00165
00166 return false;
00167 }
00168 else
00169 {
00170
00171 const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z()));
00172
00173 tightest.min() = sample - dist2;
00174 tightest.max() = sample + dist2;
00175
00176 return true;
00177 }
00178 }
00179
00180
00181
00182 Foam::scalar Foam::octreeDataEdges::calcSign
00183 (
00184 const label,
00185 const point&,
00186 point& n
00187 ) const
00188 {
00189 n = vector::zero;
00190
00191 return 1;
00192 }
00193
00194
00195
00196 Foam::scalar Foam::octreeDataEdges::calcNearest
00197 (
00198 const label index,
00199 const point& sample,
00200 point& nearest
00201 ) const
00202 {
00203 const edge& e = edges_[edgeLabels_[index]];
00204
00205 pointHit nearHit = e.line(points_).nearestDist(sample);
00206
00207 nearest = nearHit.rawPoint();
00208
00209 return nearHit.distance();
00210 }
00211
00212
00213
00214 Foam::scalar Foam::octreeDataEdges::calcNearest
00215 (
00216 const label index,
00217 const linePointRef& sampleLine,
00218 point& sampleLinePt,
00219 point& shapePt
00220 ) const
00221 {
00222 const edge& e = edges_[edgeLabels_[index]];
00223
00224 linePointRef edgeLine(e.line(points_));
00225
00226 return edgeLine.nearestDist(sampleLine, shapePt, sampleLinePt);
00227 }
00228
00229
00230 void Foam::octreeDataEdges::write
00231 (
00232 Ostream& os,
00233 const label index
00234 ) const
00235 {
00236 os << edgeLabels_[index] << " " << allBb_[index];
00237 }
00238
00239
00240