Octree search Windows port updates
[foam-extend-3.2.git] / src / meshTools / triSurface / octreeData / octreeDataTriSurfaceTreeLeaf.C
blob96e7722f880167e707248a0927aed57ad60b22e7
1 /*---------------------------------------------------------------------------*\\r
2   =========                 |\r
3   \\      /  F ield         | foam-extend: Open Source CFD\r
4    \\    /   O peration     | Version:     3.2\r
5     \\  /    A nd           | Web:         http://www.foam-extend.org\r
6      \\/     M anipulation  | For copyright notice see file Copyright\r
7 -------------------------------------------------------------------------------\r
8 License\r
9     This file is part of foam-extend.\r
11     foam-extend is free software: you can redistribute it and/or modify it\r
12     under the terms of the GNU General Public License as published by the\r
13     Free Software Foundation, either version 3 of the License, or (at your\r
14     option) any later version.\r
16     foam-extend is distributed in the hope that it will be useful, but\r
17     WITHOUT ANY WARRANTY; without even the implied warranty of\r
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
19     General Public License for more details.\r
21     You should have received a copy of the GNU General Public License\r
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.\r
24 Description\r
26 \*---------------------------------------------------------------------------*/\r
28 #include "octreeDataTriSurface.H"\r
29 #include "octreeDataTriSurfaceTreeLeaf.H"\r
31 // * * * * * * * * * * * * * Template Specialisations  * * * * * * * * * * * //\r
33 template<>\r
34 bool Foam::treeLeaf<Foam::octreeDataTriSurface>::findNearest\r
35 (\r
36     const octreeDataTriSurface& shapes,\r
37     const point& sample,\r
38     treeBoundBox& tightest,\r
39     label& tightestI,\r
40     scalar& tightestDist\r
41 ) const\r
42 {\r
43     // Some aliases\r
44     const treeBoundBoxList& allBb = shapes.allBb();\r
45     point& min = tightest.min();\r
46     point& max = tightest.max();\r
48     point nearest;\r
50     bool changed = false;\r
51     forAll(indices_, i)\r
52     {\r
53         label faceI = indices_[i];\r
55         // Quick rejection test.\r
56         if (tightest.overlaps(allBb[faceI]))\r
57         {\r
58             // Full calculation\r
59             scalar dist = shapes.calcNearest(faceI, sample, nearest);\r
61             if (dist < tightestDist)\r
62             {\r
63                 // Update bb (centered around sample, span is dist)\r
64                 min.x() = sample.x() - dist;\r
65                 min.y() = sample.y() - dist;\r
66                 min.z() = sample.z() - dist;\r
68                 max.x() = sample.x() + dist;\r
69                 max.y() = sample.y() + dist;\r
70                 max.z() = sample.z() + dist;\r
72                 tightestI = faceI;\r
73                 tightestDist = dist;\r
75                 changed = true;\r
76             }\r
77         }\r
78     }\r
79     return changed;\r
80 }\r
83 // ************************************************************************* //\r