ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / meshTools / indexedOctree / treeDataPoint.C
blob7e381a75777b9feef7483fd4233c32214aca92e4
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
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
19     for more details.
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 "treeDataPoint.H"
27 #include "treeBoundBox.H"
28 #include "indexedOctree.H"
29 #include "triangleFuncs.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 defineTypeNameAndDebug(Foam::treeDataPoint, 0);
36 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
38 Foam::treeDataPoint::treeDataPoint(const pointField& points)
40     points_(points),
41     useSubset_(false)
45 Foam::treeDataPoint::treeDataPoint
47     const pointField& points,
48     const labelList& pointLabels
51     points_(points),
52     pointLabels_(pointLabels),
53     useSubset_(true)
57 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
59 Foam::pointField Foam::treeDataPoint::shapePoints() const
61     if (useSubset_)
62     {
63         return pointField(points_, pointLabels_);
64     }
65     else
66     {
67         return points_;
68     }
72 //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
73 //  Only makes sense for closed surfaces.
74 Foam::label Foam::treeDataPoint::getVolumeType
76     const indexedOctree<treeDataPoint>& oc,
77     const point& sample
78 ) const
80     return indexedOctree<treeDataPoint>::UNKNOWN;
84 // Check if any point on shape is inside cubeBb.
85 bool Foam::treeDataPoint::overlaps
87     const label index,
88     const treeBoundBox& cubeBb
89 ) const
91     label pointI = (useSubset_ ? pointLabels_[index] : index);
92     return cubeBb.contains(points_[pointI]);
96 // Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
97 // nearestPoint.
98 void Foam::treeDataPoint::findNearest
100     const labelUList& indices,
101     const point& sample,
103     scalar& nearestDistSqr,
104     label& minIndex,
105     point& nearestPoint
106 ) const
108     forAll(indices, i)
109     {
110         const label index = indices[i];
111         label pointI = (useSubset_ ? pointLabels_[index] : index);
113         const point& pt = points_[pointI];
115         scalar distSqr = magSqr(pt - sample);
117         if (distSqr < nearestDistSqr)
118         {
119             nearestDistSqr = distSqr;
120             minIndex = index;
121             nearestPoint = pt;
122         }
123     }
127 //- Calculates nearest (to line) point in shape.
128 //  Returns point and distance (squared)
129 void Foam::treeDataPoint::findNearest
131     const labelUList& indices,
132     const linePointRef& ln,
134     treeBoundBox& tightest,
135     label& minIndex,
136     point& linePoint,
137     point& nearestPoint
138 ) const
140     // Best so far
141     scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
143     forAll(indices, i)
144     {
145         const label index = indices[i];
146         label pointI = (useSubset_ ? pointLabels_[index] : index);
148         const point& shapePt = points_[pointI];
150         if (tightest.contains(shapePt))
151         {
152             // Nearest point on line
153             pointHit pHit = ln.nearestDist(shapePt);
154             scalar distSqr = sqr(pHit.distance());
156             if (distSqr < nearestDistSqr)
157             {
158                 nearestDistSqr = distSqr;
159                 minIndex = index;
160                 linePoint = pHit.rawPoint();
161                 nearestPoint = shapePt;
163                 {
164                     point& minPt = tightest.min();
165                     minPt = min(ln.start(), ln.end());
166                     minPt.x() -= pHit.distance();
167                     minPt.y() -= pHit.distance();
168                     minPt.z() -= pHit.distance();
169                 }
170                 {
171                     point& maxPt = tightest.max();
172                     maxPt = max(ln.start(), ln.end());
173                     maxPt.x() += pHit.distance();
174                     maxPt.y() += pHit.distance();
175                     maxPt.z() += pHit.distance();
176                 }
177             }
178         }
179     }
183 // ************************************************************************* //