initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / meshTools / octree / treeLeaf.H
blob8f10146e75206cd98707ea47c2aaf0627097c87e
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 Class
26     Foam::treeLeaf
28 Description
29     An octree treeLeaf.
31 SourceFiles
32     treeLeaf.C
33     octreeDataPointTreaLeaf.H       (specialization for points only )
34     octreeDataPointTreeLeaf.C       (   ,,                          )
36 \*---------------------------------------------------------------------------*/
38 #ifndef treeLeaf_H
39 #define treeLeaf_H
41 #include "labelList.H"
42 #include "treeElem.H"
43 #include "boolList.H"
44 #include "linePointRef.H"
45 #include "labelHashSet.H"
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 namespace Foam
52 class treeBoundBox;
53 class Ostream;
55 template<class Type> class octree;
56 template<class Type> class treeLeaf;
58 // Forward declaration of friend functions and operators
60 template<class Type> Istream& operator>>(Istream&, treeLeaf<Type>&);
61 template<class Type> Ostream& operator<<(Ostream&, const treeLeaf<Type>&);
64 /*---------------------------------------------------------------------------*\
65                         Class treeLeafName Declaration
66 \*---------------------------------------------------------------------------*/
68 TemplateName(treeLeaf);
71 /*---------------------------------------------------------------------------*\
72                            Class treeLeaf Declaration
73 \*---------------------------------------------------------------------------*/
75 template <class Type>
76 class treeLeaf
78     public treeElem<Type>,
79     public treeLeafName
81     // Private data
83         // Keeps real size (at construction time indices_ might be untrimmed)
84         label size_;
86         // Indices of 'things' whose bb overlaps leaf bb.
87         labelList indices_;
90     // Private Member Functions
92         static void space(Ostream&, const label);
94         //- Disallow default bitwise copy construct
95         treeLeaf(const treeLeaf&);
97         //- Disallow default bitwise assignment
98         void operator=(const treeLeaf&);
101 public:
103     // Constructors
105         //- Construct with size
106         treeLeaf(const treeBoundBox& bb, const label size);
108         //- Construct from list
109         treeLeaf(const treeBoundBox& bb, const labelList& indices);
111         //- Construct from Istream
112         treeLeaf(Istream&);
115     // 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"
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 #endif
282 // ************************************************************************* //