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