FreeFOAM The Cross-Platform CFD Toolkit
octreeDataPointTreeLeaf.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 //#include <meshTools/octreeDataPointTreeLeaf.H>
30 #include <meshTools/treeLeaf.H>
31 
32 // * * * * * * * * * * * * * Template Specialisations * * * * * * * * * * * //
33 
34 template<>
36 (
37  const octreeDataPoint& shapes,
38  const point& sample
39 ) const
40 {
42  (
43  "Foam::treeLeaf<Foam::octreeDataPoint>::find("
44  "const octreeDataPoint& shapes,"
45  "const point& sample"
46  );
47 
48  return false;
49 }
50 
51 
52 template<>
54 (
55  const octreeDataPoint& shapes,
56  const point& sample,
57  treeBoundBox& tightest,
58  label& tightestI,
59  scalar& tightestDist
60 ) const
61 {
62  // Some aliases
63  const pointField& points = shapes.points();
64  point& tMin = tightest.min();
65  point& tMax = tightest.max();
66 
67  scalar minDist2 = sqr(tightestDist);
68 
69  label minIndex = -1;
70  forAll(indices_, i)
71  {
72  label pointi = indices_[i];
73  scalar dist = magSqr(points[pointi] - sample);
74 
75  if (dist < minDist2)
76  {
77  minDist2 = dist;
78  minIndex = pointi;
79  }
80  }
81 
82  if (minIndex != -1)
83  {
84  tightestDist = sqrt(minDist2);
85 
86  // New nearer. Update 'tightest' bounding box
87  tMin.x() = sample.x() - tightestDist;
88  tMin.y() = sample.y() - tightestDist;
89  tMin.z() = sample.z() - tightestDist;
90 
91  tMax.x() = sample.x() + tightestDist;
92  tMax.y() = sample.y() + tightestDist;
93  tMax.z() = sample.z() + tightestDist;
94 
95  tightestI = minIndex;
96 
97  return true;
98  }
99  else
100  {
101  // New no nearer so nothing changed
102  return false;
103  }
104 }
105 
106 
107 // ************************ vim: set sw=4 sts=4 et: ************************ //