initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / meshTools / octree / octreeDataCell.C
blob81a3600be946c86f078f87800e109ae10cea8f9d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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
62         (
63             vector(GREAT, GREAT, GREAT),
64             vector(-GREAT, -GREAT, -GREAT)
65         )
66     )
68     // Set one-one indexing
69     for (label i=0; i < mesh_.nCells(); i++)
70     {
71         cellLabels_[i] = i;
72     }
74     const pointField& points = mesh_.points();
75     const faceList& faces = mesh_.faces();
76     const cellList& cells = mesh_.cells();
78     forAll(cells, celli)
79     {
80         const labelList& facesi = cells[celli];
82         forAll(facesi, facei)
83         {
84             const labelList& pointsi = faces[facesi[facei]];
86             forAll(pointsi, pointi)
87             {
88                 const point& p = points[pointsi[pointi]];
89                 
90                 bbs_[celli].min() = min(bbs_[celli].min(), p);
91                 bbs_[celli].max() = max(bbs_[celli].max(), p);
92             }
93         }
94     }
98 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
100 Foam::label Foam::octreeDataCell::getSampleType
102     octree<octreeDataCell>&,
103     const point&
104 ) const
106     return octree<octreeDataCell>::UNKNOWN;
110 bool Foam::octreeDataCell::overlaps
112     const label index,
113     const treeBoundBox& cubeBb
114 ) const
116     return cubeBb.intersects(bbs_[index]);
120 bool Foam::octreeDataCell::contains
122     const label index,
123     const point& sample
124 ) const
126     return mesh_.pointInCell(sample, cellLabels_[index]);
130 bool Foam::octreeDataCell::intersects
132     const label,
133     const point&,
134     const point&,
135     point&
136 ) const
138     //Hack: don't know what to do here.
140     notImplemented
141     (
142         "octreeDataCell::intersects(const label, const point&,"
143         "const point&, point&)"
144     );
146     return false;
150 bool Foam::octreeDataCell::findTightest
152     const label index,
153     const point& sample,
154     treeBoundBox& tightest
155 ) const
158     // get nearest and furthest away vertex
159     point myNear, myFar;
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)
171     {
172         // Keep current tightest.
173         return false;
174     }
175     else
176     {
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;
183         return true;
184     }
188 // Determine numerical value of sign of sample compared to shape at index
189 Foam::scalar Foam::octreeDataCell::calcSign
191     const label,
192     const point&,
193     vector& n
194 ) const
196     n = vector::zero;
198     return GREAT;
202 // Calculate nearest point on/in shapei
203 Foam::scalar Foam::octreeDataCell::calcNearest
205     const label index,
206     const point& sample,
207     point& nearest
208 ) const
210     nearest = mesh_.cellCentres()[cellLabels_[index]];
212     return mag(nearest - sample);
216 // Calculate nearest point on/in shapei
217 Foam::scalar Foam::octreeDataCell::calcNearest
219     const label index,
220     const linePointRef& ln,
221     point& linePt,
222     point& shapePt
223 ) const
225     notImplemented
226     (
227         "octreeDataCell::calcNearest(const label, const linePointRef&"
228         ", point& linePt, point&)"
229     );
230     return GREAT;
232     
234 void Foam::octreeDataCell::write
236     Ostream& os,
237     const label index
238 ) const
240     os << cellLabels_[index] << " " << bbs_[index];
244 // ************************************************************************* //