FreeFOAM The Cross-Platform CFD Toolkit
octreeDataEdges.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 \*---------------------------------------------------------------------------*/
25 
26 #include "octreeDataEdges.H"
27 
28 #include <OpenFOAM/line.H>
29 #include <OpenFOAM/labelList.H>
30 #include "octree.H"
31 #include <OpenFOAM/linePointRef.H>
32 #include <OpenFOAM/pointHit.H>
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
37 
38 Foam::scalar Foam::octreeDataEdges::tol(1E-6);
39 
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
46 // Construct from selected edges. Bounding box calculated.
48 (
49  const edgeList& edges,
50  const pointField& points,
51  const labelList& edgeLabels
52 )
53 :
54  edges_(edges),
55  points_(points),
56  edgeLabels_(edgeLabels),
57  allBb_(edgeLabels_.size())
58 {
59  // Generate tight fitting bounding box
60  forAll(edgeLabels_, i)
61  {
62  label edgeI = edgeLabels_[i];
63 
64  const edge& e = edges_[edgeI];
65 
66  const point& a = points_[e.start()];
67  const point& b = points_[e.end()];
68 
69  allBb_[i].min() = min(a, b);
70  allBb_[i].max() = max(a, b);
71  }
72 }
73 
74 
75 // Construct as copy
77 :
78  edges_(shapes.edges()),
79  points_(shapes.points()),
80  edgeLabels_(shapes.edgeLabels()),
81  allBb_(shapes.allBb())
82 {}
83 
84 
85 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
86 
88 {}
89 
90 
91 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
92 
94 (
96  const point&
97 ) const
98 {
100 }
101 
102 
104 (
105  const label index,
106  const treeBoundBox& sampleBb
107 ) const
108 {
109  return sampleBb.overlaps(allBb_[index]);
110 }
111 
112 
114 (
115  const label,
116  const point&
117 ) const
118 {
120  (
121  "octreeDataEdges::contains(const label, const point&)"
122  );
123  return false;
124 }
125 
126 
128 (
129  const label,
130  const point&,
131  const point&,
132  point&
133 ) const
134 {
136  (
137  "octreeDataEdges::intersects(const label, const point&"
138  ", const point&, point&)"
139  );
140  return false;
141 }
142 
143 
145 (
146  const label index,
147  const point& sample,
148  treeBoundBox& tightest
149 ) const
150 {
151  // Get nearest and furthest away vertex
152  point myNear, myFar;
153  allBb_[index].calcExtremities(sample, myNear, myFar);
154 
155  const point dist = myFar - sample;
156  scalar myFarDist = mag(dist);
157 
158  point tightestNear, tightestFar;
159  tightest.calcExtremities(sample, tightestNear, tightestFar);
160 
161  scalar tightestFarDist = mag(tightestFar - sample);
162 
163  if (tightestFarDist < myFarDist)
164  {
165  // Keep current tightest.
166  return false;
167  }
168  else
169  {
170  // Construct bb around sample and myFar
171  const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z()));
172 
173  tightest.min() = sample - dist2;
174  tightest.max() = sample + dist2;
175 
176  return true;
177  }
178 }
179 
180 
181 // Determine numerical value of sign of sample compared to shape at index
183 (
184  const label,
185  const point&,
186  point& n
187 ) const
188 {
189  n = vector::zero;
190 
191  return 1;
192 }
193 
194 
195 // Calculate nearest point on/in shapei
197 (
198  const label index,
199  const point& sample,
200  point& nearest
201 ) const
202 {
203  const edge& e = edges_[edgeLabels_[index]];
204 
205  pointHit nearHit = e.line(points_).nearestDist(sample);
206 
207  nearest = nearHit.rawPoint();
208 
209  return nearHit.distance();
210 }
211 
212 
213 // Calculate nearest point on/in shapei
215 (
216  const label index,
217  const linePointRef& sampleLine,
218  point& sampleLinePt,
219  point& shapePt
220 ) const
221 {
222  const edge& e = edges_[edgeLabels_[index]];
223 
224  linePointRef edgeLine(e.line(points_));
225 
226  return edgeLine.nearestDist(sampleLine, shapePt, sampleLinePt);
227 }
228 
229 
231 (
232  Ostream& os,
233  const label index
234 ) const
235 {
236  os << edgeLabels_[index] << " " << allBb_[index];
237 }
238 
239 
240 // ************************ vim: set sw=4 sts=4 et: ************************ //