1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 \*---------------------------------------------------------------------------*/
29 #include "octreeDataCell.H"
31 #include "primitiveMesh.H"
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 // Construct from components
37 Foam::octreeDataCell::octreeDataCell
40 const labelList& cellLabels,
41 const treeBoundBoxList& bbs
45 cellLabels_(cellLabels),
50 // Construct from mesh (assumes all cells)
51 Foam::octreeDataCell::octreeDataCell
57 cellLabels_(mesh_.nCells()),
63 vector(GREAT, GREAT, GREAT),
64 vector(-GREAT, -GREAT, -GREAT)
68 // Set one-one indexing
69 for (label i=0; i < mesh_.nCells(); i++)
74 const pointField& points = mesh_.points();
75 const faceList& faces = mesh_.faces();
76 const cellList& cells = mesh_.cells();
80 const labelList& facesi = cells[celli];
84 const labelList& pointsi = faces[facesi[facei]];
86 forAll(pointsi, pointi)
88 const point& p = points[pointsi[pointi]];
90 bbs_[celli].min() = min(bbs_[celli].min(), p);
91 bbs_[celli].max() = max(bbs_[celli].max(), p);
98 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
100 Foam::label Foam::octreeDataCell::getSampleType
102 octree<octreeDataCell>&,
106 return octree<octreeDataCell>::UNKNOWN;
110 bool Foam::octreeDataCell::overlaps
113 const treeBoundBox& cubeBb
116 return cubeBb.intersects(bbs_[index]);
120 bool Foam::octreeDataCell::contains
126 return mesh_.pointInCell(sample, cellLabels_[index]);
130 bool Foam::octreeDataCell::intersects
138 //Hack: don't know what to do here.
142 "octreeDataCell::intersects(const label, const point&,"
143 "const point&, point&)"
150 bool Foam::octreeDataCell::findTightest
154 treeBoundBox& tightest
158 // get nearest and furthest away vertex
160 bbs_[index].calcExtremities(sample, myNear, myFar);
162 const point dist = myFar - sample;
163 scalar myFarDist = mag(dist);
165 point tightestNear, tightestFar;
166 tightest.calcExtremities(sample, tightestNear, tightestFar);
168 scalar tightestFarDist = mag(tightestFar - sample);
170 if (tightestFarDist < myFarDist)
172 // Keep current tightest.
177 // Construct bb around sample and myFar
178 const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z()));
180 tightest.min() = sample - dist2;
181 tightest.max() = sample + dist2;
188 // Determine numerical value of sign of sample compared to shape at index
189 Foam::scalar Foam::octreeDataCell::calcSign
202 // Calculate nearest point on/in shapei
203 Foam::scalar Foam::octreeDataCell::calcNearest
210 nearest = mesh_.cellCentres()[cellLabels_[index]];
212 return mag(nearest - sample);
216 // Calculate nearest point on/in shapei
217 Foam::scalar Foam::octreeDataCell::calcNearest
220 const linePointRef& ln,
227 "octreeDataCell::calcNearest(const label, const linePointRef&"
228 ", point& linePt, point&)"
234 void Foam::octreeDataCell::write
240 os << cellLabels_[index] << " " << bbs_[index];
244 // ************************************************************************* //