Fix tutorials: coupled/conjugateHeatFoam/conjugateCavity: fix Allrun file
[OpenFOAM-1.6-ext.git] / src / meshTools / indexedOctree / treeDataPoint.C
blob3368cd27663dcfb4815492ea0d871a88de323113
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 "treeDataPoint.H"
30 #include "treeBoundBox.H"
31 #include "indexedOctree.H"
32 #include "polyMesh.H"
33 #include "triangleFuncs.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(Foam::treeDataPoint, 0);
40 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
42 // Construct from components
43 Foam::treeDataPoint::treeDataPoint(const pointField& points)
45     points_(points)
49 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
51 Foam::pointField Foam::treeDataPoint::points() const
53     return points_;
57 //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
58 //  Only makes sense for closed surfaces.
59 Foam::label Foam::treeDataPoint::getVolumeType
61     const indexedOctree<treeDataPoint>& oc,
62     const point& sample
63 ) const
65     return indexedOctree<treeDataPoint>::UNKNOWN;
69 // Check if any point on shape is inside cubeBb.
70 bool Foam::treeDataPoint::overlaps
72     const label index,
73     const treeBoundBox& cubeBb
74 ) const
76     return cubeBb.contains(points_[index]);
80 // Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
81 // nearestPoint.
82 void Foam::treeDataPoint::findNearest
84     const labelList& indices,
85     const point& sample,
87     scalar& nearestDistSqr,
88     label& minIndex,
89     point& nearestPoint
90 ) const
92     forAll(indices, i)
93     {
94         label index = indices[i];
96         const point& pt = points_[index];
98         scalar distSqr = magSqr(pt - sample);
100         if (distSqr < nearestDistSqr)
101         {
102             nearestDistSqr = distSqr;
103             minIndex = index;
104             nearestPoint = pt;
105         }
106     }
110 //- Calculates nearest (to line) point in shape.
111 //  Returns point and distance (squared)
112 void Foam::treeDataPoint::findNearest
114     const labelList& indices,
115     const linePointRef& ln,
117     treeBoundBox& tightest,
118     label& minIndex,
119     point& linePoint,
120     point& nearestPoint
121 ) const
123     // Best so far
124     scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
126     forAll(indices, i)
127     {
128         label index = indices[i];
130         const point& shapePt = points_[index];
132         if (tightest.contains(shapePt))
133         {
134             // Nearest point on line
135             pointHit pHit = ln.nearestDist(shapePt);
136             scalar distSqr = sqr(pHit.distance());
138             if (distSqr < nearestDistSqr)
139             {
140                 nearestDistSqr = distSqr;
141                 minIndex = index;
142                 linePoint = pHit.rawPoint();
143                 nearestPoint = shapePt;
145                 {
146                     point& minPt = tightest.min();
147                     minPt = min(ln.start(), ln.end());
148                     minPt.x() -= pHit.distance();
149                     minPt.y() -= pHit.distance();
150                     minPt.z() -= pHit.distance();
151                 }
152                 {
153                     point& maxPt = tightest.max();
154                     maxPt = max(ln.start(), ln.end());
155                     maxPt.x() += pHit.distance();
156                     maxPt.y() += pHit.distance();
157                     maxPt.z() += pHit.distance();
158                 }
159             }
160         }
161     }
165 // ************************************************************************* //