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