1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "octreeDataCell.H"
28 #include "primitiveMesh.H"
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 // Construct from components
34 Foam::octreeDataCell::octreeDataCell
37 const labelList& cellLabels,
38 const treeBoundBoxList& bbs
42 cellLabels_(cellLabels),
47 // Construct from mesh (assumes all cells)
48 Foam::octreeDataCell::octreeDataCell
54 cellLabels_(mesh_.nCells()),
58 treeBoundBox::invertedBox
61 // Set one-one indexing
62 for (label i=0; i < mesh_.nCells(); i++)
67 const pointField& points = mesh_.points();
68 const faceList& faces = mesh_.faces();
69 const cellList& cells = mesh_.cells();
73 const labelList& facesi = cells[celli];
77 const labelList& pointsi = faces[facesi[facei]];
79 forAll(pointsi, pointi)
81 const point& p = points[pointsi[pointi]];
83 bbs_[celli].min() = min(bbs_[celli].min(), p);
84 bbs_[celli].max() = max(bbs_[celli].max(), p);
91 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
93 Foam::label Foam::octreeDataCell::getSampleType
95 octree<octreeDataCell>&,
99 return octree<octreeDataCell>::UNKNOWN;
103 bool Foam::octreeDataCell::overlaps
106 const treeBoundBox& cubeBb
109 return cubeBb.overlaps(bbs_[index]);
113 bool Foam::octreeDataCell::contains
119 return mesh_.pointInCell(sample, cellLabels_[index]);
123 bool Foam::octreeDataCell::intersects
131 //Hack: don't know what to do here.
135 "octreeDataCell::intersects(const label, const point&,"
136 "const point&, point&)"
143 bool Foam::octreeDataCell::findTightest
147 treeBoundBox& tightest
151 // get nearest and furthest away vertex
153 bbs_[index].calcExtremities(sample, myNear, myFar);
155 const point dist = myFar - sample;
156 scalar myFarDist = mag(dist);
158 point tightestNear, tightestFar;
159 tightest.calcExtremities(sample, tightestNear, tightestFar);
161 scalar tightestFarDist = mag(tightestFar - sample);
163 if (tightestFarDist < myFarDist)
165 // Keep current tightest.
170 // Construct bb around sample and myFar
171 const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z()));
173 tightest.min() = sample - dist2;
174 tightest.max() = sample + dist2;
181 // Determine numerical value of sign of sample compared to shape at index
182 Foam::scalar Foam::octreeDataCell::calcSign
195 // Calculate nearest point on/in shapei
196 Foam::scalar Foam::octreeDataCell::calcNearest
203 nearest = mesh_.cellCentres()[cellLabels_[index]];
205 return mag(nearest - sample);
209 // Calculate nearest point on/in shapei
210 Foam::scalar Foam::octreeDataCell::calcNearest
213 const linePointRef& ln,
220 "octreeDataCell::calcNearest(const label, const linePointRef&"
221 ", point& linePt, point&)"
227 void Foam::octreeDataCell::write
233 os << cellLabels_[index] << " " << bbs_[index];
237 // ************************************************************************* //