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 "searchableSurfaceWithGaps.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "Time.H"
00030 #include "ListOps.H"
00031
00032
00033
00034 namespace Foam
00035 {
00036
00037 defineTypeNameAndDebug(searchableSurfaceWithGaps, 0);
00038 addToRunTimeSelectionTable(searchableSurface, searchableSurfaceWithGaps, dict);
00039
00040 }
00041
00042
00043
00044
00045 Foam::Pair<Foam::vector> Foam::searchableSurfaceWithGaps::offsetVecs
00046 (
00047 const point& start,
00048 const point& end
00049 ) const
00050 {
00051 Pair<vector> offsets(vector::zero, vector::zero);
00052
00053 vector n(end-start);
00054
00055 scalar magN = mag(n);
00056
00057 if (magN > SMALL)
00058 {
00059 n /= magN;
00060
00061
00062
00063 scalar minMag = GREAT;
00064 direction minCmpt = 0;
00065
00066 for (direction cmpt = 0; cmpt < vector::nComponents; cmpt++)
00067 {
00068 if (mag(n[cmpt]) < minMag)
00069 {
00070 minMag = mag(n[cmpt]);
00071 minCmpt = cmpt;
00072 }
00073 }
00074
00075 offsets[0][minCmpt] = 1.0;
00076
00077 offsets[0] -= n[minCmpt]*n;
00078
00079 offsets[0] *= gap_/mag(offsets[0]);
00080
00081
00082
00083 offsets[1] = n ^ offsets[0];
00084 offsets[1] *= gap_;
00085 }
00086
00087 return offsets;
00088 }
00089
00090
00091 void Foam::searchableSurfaceWithGaps::offsetVecs
00092 (
00093 const pointField& start,
00094 const pointField& end,
00095 pointField& offset0,
00096 pointField& offset1
00097 ) const
00098 {
00099 offset0.setSize(start.size());
00100 offset1.setSize(start.size());
00101
00102 forAll(start, i)
00103 {
00104 const Pair<vector> offsets(offsetVecs(start[i], end[i]));
00105 offset0[i] = offsets[0];
00106 offset1[i] = offsets[1];
00107 }
00108 }
00109
00110
00111 Foam::label Foam::searchableSurfaceWithGaps::countMisses
00112 (
00113 const List<pointIndexHit>& info,
00114 labelList& missMap
00115 )
00116 {
00117 label nMiss = 0;
00118 forAll(info, i)
00119 {
00120 if (!info[i].hit())
00121 {
00122 nMiss++;
00123 }
00124 }
00125
00126 missMap.setSize(nMiss);
00127 nMiss = 0;
00128
00129 forAll(info, i)
00130 {
00131 if (!info[i].hit())
00132 {
00133 missMap[nMiss++] = i;
00134 }
00135 }
00136
00137 return nMiss;
00138 }
00139
00140
00141
00142 Foam::label Foam::searchableSurfaceWithGaps::countMisses
00143 (
00144 const List<pointIndexHit>& plusInfo,
00145 const List<pointIndexHit>& minInfo,
00146 labelList& missMap
00147 )
00148 {
00149 label nMiss = 0;
00150 forAll(plusInfo, i)
00151 {
00152 if (!plusInfo[i].hit() || !minInfo[i].hit())
00153 {
00154 nMiss++;
00155 }
00156 }
00157
00158 missMap.setSize(nMiss);
00159 nMiss = 0;
00160
00161 forAll(plusInfo, i)
00162 {
00163 if (!plusInfo[i].hit() || !minInfo[i].hit())
00164 {
00165 missMap[nMiss++] = i;
00166 }
00167 }
00168
00169 return nMiss;
00170 }
00171
00172
00173
00174
00175 Foam::searchableSurfaceWithGaps::searchableSurfaceWithGaps
00176 (
00177 const IOobject& io,
00178 const dictionary& dict
00179 )
00180 :
00181 searchableSurface(io),
00182 gap_(readScalar(dict.lookup("gap"))),
00183 subGeom_(1)
00184 {
00185 const word subGeomName(dict.lookup("surface"));
00186
00187 const searchableSurface& s =
00188 io.db().lookupObject<searchableSurface>(subGeomName);
00189
00190 subGeom_.set(0, &const_cast<searchableSurface&>(s));
00191 }
00192
00193
00194
00195
00196 Foam::searchableSurfaceWithGaps::~searchableSurfaceWithGaps()
00197 {}
00198
00199
00200
00201
00202 void Foam::searchableSurfaceWithGaps::findLine
00203 (
00204 const pointField& start,
00205 const pointField& end,
00206 List<pointIndexHit>& info
00207 ) const
00208 {
00209
00210
00211
00212
00213 surface().findLine(start, end, info);
00214
00215
00216 labelList compactMap;
00217 label nMiss = countMisses(info, compactMap);
00218
00219 if (returnReduce(nMiss, sumOp<label>()) > 0)
00220 {
00221
00222
00223
00224
00225 pointField compactStart(start, compactMap);
00226 pointField compactEnd(end, compactMap);
00227
00228
00229 pointField offset0, offset1;
00230 offsetVecs
00231 (
00232 compactStart,
00233 compactEnd,
00234 offset0,
00235 offset1
00236 );
00237
00238
00239
00240
00241
00242
00243
00244 const vectorField smallVec(SMALL*(compactEnd-compactStart));
00245
00246 List<pointIndexHit> plusInfo;
00247 surface().findLine
00248 (
00249 compactStart+offset0-smallVec,
00250 compactEnd+offset0+smallVec,
00251 plusInfo
00252 );
00253 List<pointIndexHit> minInfo;
00254 surface().findLine
00255 (
00256 compactStart-offset0-smallVec,
00257 compactEnd-offset0+smallVec,
00258 minInfo
00259 );
00260
00261
00262 forAll(plusInfo, i)
00263 {
00264 if (plusInfo[i].hit() && minInfo[i].hit())
00265 {
00266 info[compactMap[i]] = plusInfo[i];
00267 info[compactMap[i]].rawPoint() -= offset0[i];
00268 }
00269 }
00270
00271 labelList plusMissMap;
00272 nMiss = countMisses(plusInfo, minInfo, plusMissMap);
00273
00274 if (returnReduce(nMiss, sumOp<label>()) > 0)
00275 {
00276
00277
00278
00279
00280
00281
00282
00283 forAll(plusMissMap, i)
00284 {
00285 label mapI = plusMissMap[i];
00286 compactStart[i] = compactStart[mapI];
00287 compactEnd[i] = compactEnd[mapI];
00288 compactMap[i] = compactMap[mapI];
00289 offset0[i] = offset0[mapI];
00290 offset1[i] = offset1[mapI];
00291 }
00292 compactStart.setSize(plusMissMap.size());
00293 compactEnd.setSize(plusMissMap.size());
00294 compactMap.setSize(plusMissMap.size());
00295 offset0.setSize(plusMissMap.size());
00296 offset1.setSize(plusMissMap.size());
00297
00298 const vectorField smallVec(SMALL*(compactEnd-compactStart));
00299
00300 surface().findLine
00301 (
00302 compactStart+offset1-smallVec,
00303 compactEnd+offset1+smallVec,
00304 plusInfo
00305 );
00306 surface().findLine
00307 (
00308 compactStart-offset1-smallVec,
00309 compactEnd-offset1+smallVec,
00310 minInfo
00311 );
00312
00313
00314 forAll(plusInfo, i)
00315 {
00316 if (plusInfo[i].hit() && minInfo[i].hit())
00317 {
00318 info[compactMap[i]] = plusInfo[i];
00319 info[compactMap[i]].rawPoint() -= offset1[i];
00320 }
00321 }
00322 }
00323 }
00324 }
00325
00326
00327 void Foam::searchableSurfaceWithGaps::findLineAny
00328 (
00329 const pointField& start,
00330 const pointField& end,
00331 List<pointIndexHit>& info
00332 ) const
00333 {
00334
00335 findLine(start, end, info);
00336 }
00337
00338
00339 void Foam::searchableSurfaceWithGaps::findLineAll
00340 (
00341 const pointField& start,
00342 const pointField& end,
00343 List<List<pointIndexHit> >& info
00344 ) const
00345 {
00346
00347 List<pointIndexHit> nearestInfo;
00348 findLine(start, end, nearestInfo);
00349
00350 info.setSize(start.size());
00351 forAll(info, pointI)
00352 {
00353 if (nearestInfo[pointI].hit())
00354 {
00355 info[pointI].setSize(1);
00356 info[pointI][0] = nearestInfo[pointI];
00357 }
00358 else
00359 {
00360 info[pointI].clear();
00361 }
00362 }
00363 }
00364
00365
00366