initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / octree / treeLeaf.H
blob76b22d4c0d1fe3a69605dd06af5cf7cd5f20535e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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)
34     octreeDataPointTreeLeaf.C
35     octreeDataTriSurfaceTreeLeaf.H  (specialization for triSurface)
36     octreeDataTriSurfaceTreeLeaf.C
38 \*---------------------------------------------------------------------------*/
40 #ifndef treeLeaf_H
41 #define treeLeaf_H
43 #include "labelList.H"
44 #include "treeElem.H"
45 #include "boolList.H"
46 #include "linePointRef.H"
47 #include "HashSet.H"
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 namespace Foam
54 class treeBoundBox;
55 class Ostream;
57 template<class Type> class octree;
58 template<class Type> class treeLeaf;
60 // Forward declaration of friend functions and operators
62 template<class Type> Istream& operator>>(Istream&, treeLeaf<Type>&);
63 template<class Type> Ostream& operator<<(Ostream&, const treeLeaf<Type>&);
66 /*---------------------------------------------------------------------------*\
67                         Class treeLeafName Declaration
68 \*---------------------------------------------------------------------------*/
70 TemplateName(treeLeaf);
73 /*---------------------------------------------------------------------------*\
74                            Class treeLeaf Declaration
75 \*---------------------------------------------------------------------------*/
77 template <class Type>
78 class treeLeaf
80     public treeElem<Type>,
81     public treeLeafName
83     // Private data
85         // Keeps real size (at construction time indices_ might be untrimmed)
86         label size_;
88         // Indices of 'things' whose bb overlaps leaf bb.
89         labelList indices_;
92     // Private Member Functions
94         static void space(Ostream&, const label);
96         //- Disallow default bitwise copy construct
97         treeLeaf(const treeLeaf&);
99         //- Disallow default bitwise assignment
100         void operator=(const treeLeaf&);
103 public:
105     // Constructors
107         //- Construct with size
108         treeLeaf(const treeBoundBox& bb, const label size);
110         //- Construct from list
111         treeLeaf(const treeBoundBox& bb, const labelList& indices);
113         //- Construct from Istream
114         treeLeaf(Istream&);
117     // Destructor
119         ~treeLeaf();
122     // Member Functions
124         // Access
126             label size() const
127             {
128                 return size_;
129             }
131             const labelList& indices() const
132             {
133                 return indices_;
134             }
136         // Edit
138             void insert(const label index)
139             {
140                 if (size_ >= indices_.size())
141                 {
142                     FatalErrorIn
143                     (
144                         "treeLeaf<Type>::insert(index)"
145                     )
146                         << "overflow"
147                         << "  size_ :" << size_
148                         << "  size():" << indices_.size()
149                         << abort(FatalError);
150                 }
151                 indices_[size_++] = index;
152             }
154             void trim()
155             {
156                 if (size_ == 0)
157                 {
158                     FatalErrorIn
159                     (
160                         "treeLeaf<Type>::trim()"
161                     )
162                         << "Trying to trim empty leaf: " << endl
163                         << "  size_ :" << size_
164                         << "  size():" << indices_.size()
165                         << abort(FatalError);
166                 }
167                 indices_.setSize(size_);
168             }
170             //- Take indices at refineLevel and distribute them to lower levels
171             treeLeaf<Type>* redistribute
172             (
173                 const label,
174                 octree<Type>&,
175                 const Type&
176             );
178             label setSubNodeType
179             (
180                 const label level,
181                 octree<Type>& top,
182                 const Type& shapes
183             ) const;
185         // Search
187             //- Get type of sample
188             label getSampleType
189             (
190                 const label level,
191                 const octree<Type>& top,
192                 const Type& shapes,
193                 const point& sample
194             ) const;
196             //- Find index of shape containing sample
197             label find
198             (
199                 const Type& shapes,
200                 const point& sample
201             ) const;
203             //- Find tightest fitting bounding box in leaf
204             bool findTightest
205             (
206                 const Type& shapes,
207                 const point& sample,
208                 treeBoundBox& tightest
209             ) const;
211             //- Find nearest point.
212             bool findNearest
213             (
214                 const Type& shapes,
215                 const point& sample,
216                 treeBoundBox& tightest,
217                 label& tightestI,
218                 scalar& tightestDist
219             ) const;
221             //- Find nearest shape to line
222             //  Returns true if found nearer shape and updates nearest and
223             //  tightest
224             bool findNearest
225             (
226                 const Type& shapes,
227                 const linePointRef& ln,
228                 treeBoundBox& tightest,
229                 label& tightestI,   // index of nearest shape
230                 point& linePoint,   // nearest point on line
231                 point& shapePoint   // nearest point on shape
232             ) const;
234             //- Find shapes not outside box. Return true if anything found.
235             bool findBox
236             (
237                 const Type& shapes,
238                 const boundBox& bb,
239                 labelHashSet& elements
240             ) const;
242         // Write
244             //- Debug: print a leaf
245             void printLeaf(Ostream&, const label) const;
247             //- Debug: Write bb in OBJ format
248             void writeOBJ
249             (
250                 Ostream& os,
251                 const label level,
252                 label& vertNo
253             ) const;
255             //- debug:
256             label countLeaf(Ostream&, const label) const;
259     // IOstream Operators
261         friend Istream& operator>> <Type>(Istream&, treeLeaf<Type>&);
262         friend Ostream& operator<< <Type>(Ostream&, const treeLeaf<Type>&);
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 } // End namespace Foam
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 #ifdef NoRepository
273 #   include "treeLeaf.C"
274 #endif
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
278 #include "octreeDataPointTreeLeaf.H"
279 #include "octreeDataTriSurfaceTreeLeaf.H"
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 #endif
285 // ************************************************************************* //