initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / octree / octreeDataCell.C
blobdf9bd9ef123f9813710b2b1f9afb8ab07cf2aefc
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Description
27 \*---------------------------------------------------------------------------*/
29 #include "octreeDataCell.H"
30 #include "polyMesh.H"
31 #include "primitiveMesh.H"
32 #include "treeNode.H"
34 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
36 // Construct from components
37 Foam::octreeDataCell::octreeDataCell
39     const polyMesh& mesh,
40     const labelList& cellLabels,
41     const treeBoundBoxList& bbs
44     mesh_(mesh),
45     cellLabels_(cellLabels),
46     bbs_(bbs)
50 // Construct from mesh (assumes all cells)
51 Foam::octreeDataCell::octreeDataCell
53     const polyMesh& mesh
56     mesh_(mesh),
57     cellLabels_(mesh_.nCells()),
58     bbs_
59     (
60         mesh_.nCells(),
61         treeBoundBox::invertedBox
62     )
64     // Set one-one indexing
65     for (label i=0; i < mesh_.nCells(); i++)
66     {
67         cellLabels_[i] = i;
68     }
70     const pointField& points = mesh_.points();
71     const faceList& faces = mesh_.faces();
72     const cellList& cells = mesh_.cells();
74     forAll(cells, celli)
75     {
76         const labelList& facesi = cells[celli];
78         forAll(facesi, facei)
79         {
80             const labelList& pointsi = faces[facesi[facei]];
82             forAll(pointsi, pointi)
83             {
84                 const point& p = points[pointsi[pointi]];
85                 
86                 bbs_[celli].min() = min(bbs_[celli].min(), p);
87                 bbs_[celli].max() = max(bbs_[celli].max(), p);
88             }
89         }
90     }
94 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
96 Foam::label Foam::octreeDataCell::getSampleType
98     octree<octreeDataCell>&,
99     const point&
100 ) const
102     return octree<octreeDataCell>::UNKNOWN;
106 bool Foam::octreeDataCell::overlaps
108     const label index,
109     const treeBoundBox& cubeBb
110 ) const
112     return cubeBb.overlaps(bbs_[index]);
116 bool Foam::octreeDataCell::contains
118     const label index,
119     const point& sample
120 ) const
122     return mesh_.pointInCell(sample, cellLabels_[index]);
126 bool Foam::octreeDataCell::intersects
128     const label,
129     const point&,
130     const point&,
131     point&
132 ) const
134     //Hack: don't know what to do here.
136     notImplemented
137     (
138         "octreeDataCell::intersects(const label, const point&,"
139         "const point&, point&)"
140     );
142     return false;
146 bool Foam::octreeDataCell::findTightest
148     const label index,
149     const point& sample,
150     treeBoundBox& tightest
151 ) const
154     // get nearest and furthest away vertex
155     point myNear, myFar;
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)
167     {
168         // Keep current tightest.
169         return false;
170     }
171     else
172     {
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;
179         return true;
180     }
184 // Determine numerical value of sign of sample compared to shape at index
185 Foam::scalar Foam::octreeDataCell::calcSign
187     const label,
188     const point&,
189     vector& n
190 ) const
192     n = vector::zero;
194     return GREAT;
198 // Calculate nearest point on/in shapei
199 Foam::scalar Foam::octreeDataCell::calcNearest
201     const label index,
202     const point& sample,
203     point& nearest
204 ) const
206     nearest = mesh_.cellCentres()[cellLabels_[index]];
208     return mag(nearest - sample);
212 // Calculate nearest point on/in shapei
213 Foam::scalar Foam::octreeDataCell::calcNearest
215     const label index,
216     const linePointRef& ln,
217     point& linePt,
218     point& shapePt
219 ) const
221     notImplemented
222     (
223         "octreeDataCell::calcNearest(const label, const linePointRef&"
224         ", point& linePt, point&)"
225     );
226     return GREAT;
228     
230 void Foam::octreeDataCell::write
232     Ostream& os,
233     const label index
234 ) const
236     os << cellLabels_[index] << " " << bbs_[index];
240 // ************************************************************************* //