1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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()),
61 treeBoundBox::invertedBox
64 // Set one-one indexing
65 for (label i=0; i < mesh_.nCells(); i++)
70 const pointField& points = mesh_.points();
71 const faceList& faces = mesh_.faces();
72 const cellList& cells = mesh_.cells();
76 const labelList& facesi = cells[celli];
80 const labelList& pointsi = faces[facesi[facei]];
82 forAll(pointsi, pointi)
84 const point& p = points[pointsi[pointi]];
86 bbs_[celli].min() = min(bbs_[celli].min(), p);
87 bbs_[celli].max() = max(bbs_[celli].max(), p);
94 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
96 Foam::label Foam::octreeDataCell::getSampleType
98 octree<octreeDataCell>&,
102 return octree<octreeDataCell>::UNKNOWN;
106 bool Foam::octreeDataCell::overlaps
109 const treeBoundBox& cubeBb
112 return cubeBb.overlaps(bbs_[index]);
116 bool Foam::octreeDataCell::contains
122 return mesh_.pointInCell(sample, cellLabels_[index]);
126 bool Foam::octreeDataCell::intersects
134 //Hack: don't know what to do here.
138 "octreeDataCell::intersects(const label, const point&,"
139 "const point&, point&)"
146 bool Foam::octreeDataCell::findTightest
150 treeBoundBox& tightest
154 // get nearest and furthest away vertex
156 bbs_[index].calcExtremities(sample, myNear, myFar);
158 const point dist = myFar - sample;
159 scalar myFarDist = mag(dist);
161 point tightestNear, tightestFar;
162 tightest.calcExtremities(sample, tightestNear, tightestFar);
164 scalar tightestFarDist = mag(tightestFar - sample);
166 if (tightestFarDist < myFarDist)
168 // Keep current tightest.
173 // Construct bb around sample and myFar
174 const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z()));
176 tightest.min() = sample - dist2;
177 tightest.max() = sample + dist2;
184 // Determine numerical value of sign of sample compared to shape at index
185 Foam::scalar Foam::octreeDataCell::calcSign
198 // Calculate nearest point on/in shapei
199 Foam::scalar Foam::octreeDataCell::calcNearest
206 nearest = mesh_.cellCentres()[cellLabels_[index]];
208 return mag(nearest - sample);
212 // Calculate nearest point on/in shapei
213 Foam::scalar Foam::octreeDataCell::calcNearest
216 const linePointRef& ln,
223 "octreeDataCell::calcNearest(const label, const linePointRef&"
224 ", point& linePt, point&)"
230 void Foam::octreeDataCell::write
236 os << cellLabels_[index] << " " << bbs_[index];
240 // ************************************************************************* //