ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / meshTools / octree / treeLeaf.H
blob3de280a4568c22a8404f6656c12931efdb8e0ab9
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 Class
25     Foam::treeLeaf
27 Description
28     An octree treeLeaf.
30 SourceFiles
31     treeLeaf.C
32     octreeDataPointTreaLeaf.H       (specialization for points)
33     octreeDataPointTreeLeaf.C
34     octreeDataTriSurfaceTreeLeaf.H  (specialization for triSurface)
35     octreeDataTriSurfaceTreeLeaf.C
37 \*---------------------------------------------------------------------------*/
39 #ifndef treeLeaf_H
40 #define treeLeaf_H
42 #include "labelList.H"
43 #include "treeElem.H"
44 #include "boolList.H"
45 #include "linePointRef.H"
46 #include "HashSet.H"
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 namespace Foam
53 class treeBoundBox;
54 class Ostream;
56 template<class Type> class octree;
57 template<class Type> class treeLeaf;
59 // Forward declaration of friend functions and operators
61 template<class Type> Istream& operator>>(Istream&, treeLeaf<Type>&);
62 template<class Type> Ostream& operator<<(Ostream&, const treeLeaf<Type>&);
65 /*---------------------------------------------------------------------------*\
66                         Class treeLeafName Declaration
67 \*---------------------------------------------------------------------------*/
69 TemplateName(treeLeaf);
72 /*---------------------------------------------------------------------------*\
73                            Class treeLeaf Declaration
74 \*---------------------------------------------------------------------------*/
76 template <class Type>
77 class treeLeaf
79     public treeElem<Type>,
80     public treeLeafName
82     // Private data
84         // Keeps real size (at construction time indices_ might be untrimmed)
85         label size_;
87         // Indices of 'things' whose bb overlaps leaf bb.
88         labelList indices_;
91     // Private Member Functions
93         static void space(Ostream&, const label);
95         //- Disallow default bitwise copy construct
96         treeLeaf(const treeLeaf&);
98         //- Disallow default bitwise assignment
99         void operator=(const treeLeaf&);
102 public:
104     // Constructors
106         //- Construct with size
107         treeLeaf(const treeBoundBox& bb, const label size);
109         //- Construct from list
110         treeLeaf(const treeBoundBox& bb, const labelList& indices);
112         //- Construct from Istream
113         treeLeaf(Istream&);
116     //- Destructor
117     ~treeLeaf();
120     // Member Functions
122         // Access
124             label size() const
125             {
126                 return size_;
127             }
129             const labelList& indices() const
130             {
131                 return indices_;
132             }
134         // Edit
136             void insert(const label index)
137             {
138                 if (size_ >= indices_.size())
139                 {
140                     FatalErrorIn
141                     (
142                         "treeLeaf<Type>::insert(index)"
143                     )
144                         << "overflow"
145                         << "  size_ :" << size_
146                         << "  size():" << indices_.size()
147                         << abort(FatalError);
148                 }
149                 indices_[size_++] = index;
150             }
152             void trim()
153             {
154                 if (size_ == 0)
155                 {
156                     FatalErrorIn
157                     (
158                         "treeLeaf<Type>::trim()"
159                     )
160                         << "Trying to trim empty leaf: " << endl
161                         << "  size_ :" << size_
162                         << "  size():" << indices_.size()
163                         << abort(FatalError);
164                 }
165                 indices_.setSize(size_);
166             }
168             //- Take indices at refineLevel and distribute them to lower levels
169             treeLeaf<Type>* redistribute
170             (
171                 const label,
172                 octree<Type>&,
173                 const Type&
174             );
176             label setSubNodeType
177             (
178                 const label level,
179                 octree<Type>& top,
180                 const Type& shapes
181             ) const;
183         // Search
185             //- Get type of sample
186             label getSampleType
187             (
188                 const label level,
189                 const octree<Type>& top,
190                 const Type& shapes,
191                 const point& sample
192             ) const;
194             //- Find index of shape containing sample
195             label find
196             (
197                 const Type& shapes,
198                 const point& sample
199             ) const;
201             //- Find tightest fitting bounding box in leaf
202             bool findTightest
203             (
204                 const Type& shapes,
205                 const point& sample,
206                 treeBoundBox& tightest
207             ) const;
209             //- Find nearest point.
210             bool findNearest
211             (
212                 const Type& shapes,
213                 const point& sample,
214                 treeBoundBox& tightest,
215                 label& tightestI,
216                 scalar& tightestDist
217             ) const;
219             //- Find nearest shape to line
220             //  Returns true if found nearer shape and updates nearest and
221             //  tightest
222             bool findNearest
223             (
224                 const Type& shapes,
225                 const linePointRef& ln,
226                 treeBoundBox& tightest,
227                 label& tightestI,   // index of nearest shape
228                 point& linePoint,   // nearest point on line
229                 point& shapePoint   // nearest point on shape
230             ) const;
232             //- Find shapes not outside box. Return true if anything found.
233             bool findBox
234             (
235                 const Type& shapes,
236                 const boundBox& bb,
237                 labelHashSet& elements
238             ) const;
240         // Write
242             //- Debug: print a leaf
243             void printLeaf(Ostream&, const label) const;
245             //- Debug: Write bb in OBJ format
246             void writeOBJ
247             (
248                 Ostream& os,
249                 const label level,
250                 label& vertNo
251             ) const;
253             //- debug:
254             label countLeaf(Ostream&, const label) const;
257     // IOstream Operators
259         friend Istream& operator>> <Type>(Istream&, treeLeaf<Type>&);
260         friend Ostream& operator<< <Type>(Ostream&, const treeLeaf<Type>&);
264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266 } // End namespace Foam
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 #ifdef NoRepository
271 #   include "treeLeaf.C"
272 #endif
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 #include "octreeDataPointTreeLeaf.H"
277 #include "octreeDataTriSurfaceTreeLeaf.H"
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 #endif
283 // ************************************************************************* //