triSurfaceSearch.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 "triSurfaceSearch.H"
00028 #include "indexedOctree.H"
00029 #include "boolList.H"
00030 #include "treeDataTriSurface.H"
00031 #include "triSurface.H"
00032 #include "line.H"
00033 #include "cpuTime.H"
00034
00035
00036
00037 namespace Foam
00038 {
00039
00040
00041
00042 const point triSurfaceSearch::greatPoint(GREAT, GREAT, GREAT);
00043
00044
00045
00046
00047
00048 triSurfaceSearch::triSurfaceSearch(const triSurface& surface)
00049 :
00050 surface_(surface),
00051 treePtr_(NULL)
00052 {
00053
00054 Random rndGen(65431);
00055
00056
00057
00058 treeBoundBox treeBb
00059 (
00060 treeBoundBox(surface_.points(), surface_.meshPoints()).extend
00061 (
00062 rndGen,
00063 1E-4
00064 )
00065 );
00066 treeBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
00067 treeBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
00068
00069 treePtr_.reset
00070 (
00071 new indexedOctree<treeDataTriSurface>
00072 (
00073 treeDataTriSurface(surface_),
00074 treeBb,
00075 8,
00076 10,
00077 3.0
00078 )
00079 );
00080 }
00081
00082
00083
00084
00085
00086 boolList triSurfaceSearch::calcInside(const pointField& samples) const
00087 {
00088 boolList inside(samples.size());
00089
00090 forAll(samples, sampleI)
00091 {
00092 const point& sample = samples[sampleI];
00093
00094 if (!tree().bb().contains(sample))
00095 {
00096 inside[sampleI] = false;
00097 }
00098 else if
00099 (
00100 tree().getVolumeType(sample)
00101 == indexedOctree<treeDataTriSurface>::INSIDE
00102 )
00103 {
00104 inside[sampleI] = true;
00105 }
00106 else
00107 {
00108 inside[sampleI] = false;
00109 }
00110 }
00111 return inside;
00112 }
00113
00114
00115 labelList triSurfaceSearch::calcNearestTri
00116 (
00117 const pointField& samples,
00118 const vector& span
00119 ) const
00120 {
00121 labelList nearest(samples.size());
00122
00123 const scalar nearestDistSqr = 0.25*magSqr(span);
00124
00125 pointIndexHit hitInfo;
00126
00127 forAll(samples, sampleI)
00128 {
00129 hitInfo = tree().findNearest(samples[sampleI], nearestDistSqr);
00130
00131 if (hitInfo.hit())
00132 {
00133 nearest[sampleI] = hitInfo.index();
00134 }
00135 else
00136 {
00137 nearest[sampleI] = -1;
00138 }
00139 }
00140
00141 return nearest;
00142 }
00143
00144
00145
00146 tmp<pointField> triSurfaceSearch::calcNearest
00147 (
00148 const pointField& samples,
00149 const vector& span
00150 ) const
00151 {
00152 const scalar nearestDistSqr = 0.25*magSqr(span);
00153
00154 tmp<pointField> tnearest(new pointField(samples.size()));
00155 pointField& nearest = tnearest();
00156
00157 pointIndexHit hitInfo;
00158
00159 forAll(samples, sampleI)
00160 {
00161 hitInfo = tree().findNearest(samples[sampleI], nearestDistSqr);
00162
00163 if (hitInfo.hit())
00164 {
00165 nearest[sampleI] = hitInfo.hitPoint();
00166 }
00167 else
00168 {
00169 nearest[sampleI] = greatPoint;
00170 }
00171 }
00172
00173 return tnearest;
00174 }
00175
00176
00177 pointIndexHit triSurfaceSearch::nearest(const point& pt, const vector& span)
00178 const
00179 {
00180 const scalar nearestDistSqr = 0.25*magSqr(span);
00181
00182 return tree().findNearest(pt, nearestDistSqr);
00183 }
00184
00185
00186
00187
00188 }
00189
00190
Copyright © 2000-2009 OpenCFD Ltd