1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "triSurfaceSearch.H"
27 #include "indexedOctree.H"
29 #include "treeDataTriSurface.H"
30 #include "triSurface.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 const point triSurfaceSearch::greatPoint(GREAT, GREAT, GREAT);
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 // Construct from surface. Holds reference!
47 triSurfaceSearch::triSurfaceSearch(const triSurface& surface)
52 // Random number generator. Bit dodgy since not exactly random ;-)
55 // Slightly extended bb. Slightly off-centred just so on symmetric
56 // geometry there are less face/edge aligned items.
59 treeBoundBox(surface_.points(), surface_.meshPoints()).extend
65 treeBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
66 treeBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
70 new indexedOctree<treeDataTriSurface>
72 treeDataTriSurface(surface_),
82 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
84 // Determine inside/outside for samples
85 boolList triSurfaceSearch::calcInside(const pointField& samples) const
87 boolList inside(samples.size());
89 forAll(samples, sampleI)
91 const point& sample = samples[sampleI];
93 if (!tree().bb().contains(sample))
95 inside[sampleI] = false;
99 tree().getVolumeType(sample)
100 == indexedOctree<treeDataTriSurface>::INSIDE
103 inside[sampleI] = true;
107 inside[sampleI] = false;
115 labelList triSurfaceSearch::calcNearestTri
117 const pointField& samples,
121 labelList nearest(samples.size());
123 const scalar nearestDistSqr = 0.25*magSqr(span);
125 pointIndexHit hitInfo;
127 forAll(samples, sampleI)
129 hitInfo = tree().findNearest(samples[sampleI], nearestDistSqr);
133 nearest[sampleI] = hitInfo.index();
137 nearest[sampleI] = -1;
145 // Nearest point on surface
146 tmp<pointField> triSurfaceSearch::calcNearest
148 const pointField& samples,
152 const scalar nearestDistSqr = 0.25*magSqr(span);
154 tmp<pointField> tnearest(new pointField(samples.size()));
155 pointField& nearest = tnearest();
157 pointIndexHit hitInfo;
159 forAll(samples, sampleI)
161 hitInfo = tree().findNearest(samples[sampleI], nearestDistSqr);
165 nearest[sampleI] = hitInfo.hitPoint();
169 nearest[sampleI] = greatPoint;
177 pointIndexHit triSurfaceSearch::nearest
183 const scalar nearestDistSqr = 0.25*magSqr(span);
185 return tree().findNearest(pt, nearestDistSqr);
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 } // End namespace Foam
193 // ************************************************************************* //