treeDataCell.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 "treeDataCell.H"
00028 #include "indexedOctree.H"
00029 #include "primitiveMesh.H"
00030
00031
00032
00033 defineTypeNameAndDebug(Foam::treeDataCell, 0);
00034
00035
00036
00037
00038 Foam::treeBoundBox Foam::treeDataCell::calcCellBb(const label cellI) const
00039 {
00040 const cellList& cells = mesh_.cells();
00041 const faceList& faces = mesh_.faces();
00042 const pointField& points = mesh_.points();
00043
00044 treeBoundBox cellBb
00045 (
00046 vector(GREAT, GREAT, GREAT),
00047 vector(-GREAT, -GREAT, -GREAT)
00048 );
00049
00050 const cell& cFaces = cells[cellI];
00051
00052 forAll(cFaces, cFaceI)
00053 {
00054 const face& f = faces[cFaces[cFaceI]];
00055
00056 forAll(f, fp)
00057 {
00058 const point& p = points[f[fp]];
00059
00060 cellBb.min() = min(cellBb.min(), p);
00061 cellBb.max() = max(cellBb.max(), p);
00062 }
00063 }
00064 return cellBb;
00065 }
00066
00067
00068
00069
00070
00071 Foam::treeDataCell::treeDataCell
00072 (
00073 const bool cacheBb,
00074 const primitiveMesh& mesh,
00075 const labelList& cellLabels
00076 )
00077 :
00078 mesh_(mesh),
00079 cellLabels_(cellLabels),
00080 cacheBb_(cacheBb)
00081 {
00082 if (cacheBb_)
00083 {
00084 bbs_.setSize(cellLabels_.size());
00085
00086 forAll(cellLabels_, i)
00087 {
00088 bbs_[i] = calcCellBb(cellLabels_[i]);
00089 }
00090 }
00091 }
00092
00093
00094 Foam::treeDataCell::treeDataCell
00095 (
00096 const bool cacheBb,
00097 const primitiveMesh& mesh
00098 )
00099 :
00100 mesh_(mesh),
00101 cellLabels_(identity(mesh_.nCells())),
00102 cacheBb_(cacheBb)
00103 {
00104 if (cacheBb_)
00105 {
00106 bbs_.setSize(cellLabels_.size());
00107
00108 forAll(cellLabels_, i)
00109 {
00110 bbs_[i] = calcCellBb(cellLabels_[i]);
00111 }
00112 }
00113 }
00114
00115
00116
00117
00118 Foam::pointField Foam::treeDataCell::points() const
00119 {
00120 pointField cc(cellLabels_.size());
00121
00122 forAll(cellLabels_, i)
00123 {
00124 cc[i] = mesh_.cellCentres()[cellLabels_[i]];
00125 }
00126
00127 return cc;
00128 }
00129
00130
00131
00132 bool Foam::treeDataCell::overlaps
00133 (
00134 const label index,
00135 const treeBoundBox& cubeBb
00136 ) const
00137 {
00138 if (cacheBb_)
00139 {
00140 return cubeBb.overlaps(bbs_[index]);
00141 }
00142 else
00143 {
00144 return cubeBb.overlaps(calcCellBb(cellLabels_[index]));
00145 }
00146 }
00147
00148
00149
00150
00151 void Foam::treeDataCell::findNearest
00152 (
00153 const labelList& indices,
00154 const point& sample,
00155
00156 scalar& nearestDistSqr,
00157 label& minIndex,
00158 point& nearestPoint
00159 ) const
00160 {
00161 forAll(indices, i)
00162 {
00163 label index = indices[i];
00164 label cellI = cellLabels_[index];
00165 scalar distSqr = magSqr(sample - mesh_.cellCentres()[cellI]);
00166
00167 if (distSqr < nearestDistSqr)
00168 {
00169 nearestDistSqr = distSqr;
00170 minIndex = index;
00171 nearestPoint = mesh_.cellCentres()[cellI];
00172 }
00173 }
00174 }
00175
00176
00177 bool Foam::treeDataCell::intersects
00178 (
00179 const label index,
00180 const point& start,
00181 const point& end,
00182 point& intersectionPoint
00183 ) const
00184 {
00185
00186 if (cacheBb_)
00187 {
00188 const treeBoundBox& cellBb = bbs_[index];
00189
00190 if ((cellBb.posBits(start) & cellBb.posBits(end)) != 0)
00191 {
00192
00193 return false;
00194 }
00195 }
00196 else
00197 {
00198 const treeBoundBox cellBb = calcCellBb(cellLabels_[index]);
00199
00200 if ((cellBb.posBits(start) & cellBb.posBits(end)) != 0)
00201 {
00202
00203 return false;
00204 }
00205 }
00206
00207
00208
00209
00210
00211
00212 scalar oldTol = intersection::setPlanarTol(0.0);
00213
00214 const cell& cFaces = mesh_.cells()[cellLabels_[index]];
00215
00216 const vector dir(end - start);
00217 scalar minDistSqr = magSqr(dir);
00218 bool hasMin = false;
00219
00220 forAll(cFaces, i)
00221 {
00222 const face& f = mesh_.faces()[cFaces[i]];
00223
00224 pointHit inter = f.ray
00225 (
00226 start,
00227 dir,
00228 mesh_.points(),
00229 intersection::HALF_RAY
00230 );
00231
00232 if (inter.hit() && sqr(inter.distance()) <= minDistSqr)
00233 {
00234
00235
00236
00237 minDistSqr = sqr(inter.distance());
00238 intersectionPoint = inter.hitPoint();
00239 hasMin = true;
00240 }
00241 }
00242
00243
00244 intersection::setPlanarTol(oldTol);
00245
00246 return hasMin;
00247 }
00248
00249
00250
Copyright © 2000-2009 OpenCFD Ltd