Debian Codegraph @

src/thirdparty/PoissonRecon/RegularTree.h

raw
1 /*
2 Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7
8 Redistributions of source code must retain the above copyright notice, this list of
9 conditions and the following disclaimer. Redistributions in binary form must reproduce
10 the above copyright notice, this list of conditions and the following disclaimer
11 in the documentation and/or other materials provided with the distribution.
12
13 Neither the name of the Johns Hopkins University nor the names of its contributors
14 may be used to endorse or promote products derived from this software without specific
15 prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
20 SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 DAMAGE.
27 */
28
29 #ifndef REGULAR_TREE_NODE_INCLUDED
30 #define REGULAR_TREE_NODE_INCLUDED
31
32 #include <functional>
33 #include <stdlib.h>
34 #include <math.h>
35 #include <algorithm>
36 #include "Streams.h"
37 #include "Allocator.h"
38 #include "BinaryNode.h"
39 #include "Window.h"
40 #include "MyMiscellany.h"
41 #include "Array.h"
42 #include "MyAtomic.h"
43
44 namespace PoissonRecon
45 {
46 template< unsigned int Dim , class NodeData , class DepthAndOffsetType >
47 struct RegularTreeNode
48 {
49 // This struct temporarily makes a node appear to be a root node by removing the parent reference
50 struct SubTreeExtractor
51 {
52 SubTreeExtractor( RegularTreeNode &root ) : _root(root)
53 {
54 _rootParent = _root.parent;
55 _root.parent = NULL;
56 _root.depthAndOffset( _depth , _offset );
57 int depth=0 , offset[Dim];
58 for( unsigned int d=0 ; d<Dim ; d++ ) offset[d] = 0;
59 RegularTreeNode::ResetDepthAndOffset( &_root , depth , offset );
60 }
61 SubTreeExtractor( RegularTreeNode *root ) : SubTreeExtractor( *root ){}
62 ~SubTreeExtractor( void )
63 {
64 RegularTreeNode::ResetDepthAndOffset( &_root , _depth , _offset );
65 _root.parent = _rootParent;
66 }
67 protected:
68 RegularTreeNode &_root , *_rootParent;
69 int _depth , _offset[Dim];
70 };
71
72 struct DepthAndOffset
73 {
74 DepthAndOffsetType depth , offset[Dim];
75 DepthAndOffset( void ){ depth = 0 , memset( offset , 0 , sizeof(DepthAndOffsetType) * Dim ); }
76 DepthAndOffset( DepthAndOffsetType d , const DepthAndOffsetType off[] ){ depth = d , memcpy( offset , off , sizeof(DepthAndOffsetType) * Dim ); }
77 bool operator == ( const DepthAndOffset &doff ) const
78 {
79 if( depth!=doff.depth ) return false;
80 for( int d=0 ; d<Dim ; d++ ) if( offset[d]!=doff.offset[d] ) return false;
81 return true;
82 }
83
84 friend std::ostream &operator << ( std::ostream &os , const DepthAndOffset &depthAndOffset )
85 {
86 os << "( " << depthAndOffset.offset[0];
87 for( unsigned int d=1 ; d<Dim ; d++ ) os << " , " << depthAndOffset.offset[d];
88 return os << " ) @ " << depthAndOffset.depth;
89 }
90 };
91 private:
92 DepthAndOffsetType _depth , _offset[Dim];
93 template< typename Initializer >
94 bool _initChildren ( Allocator< RegularTreeNode >* nodeAllocator , Initializer &initializer );
95 template< typename Initializer >
96 bool _initChildren_s( Allocator< RegularTreeNode >* nodeAllocator , Initializer &initializer );
97 public:
98
99 RegularTreeNode* parent;
100 RegularTreeNode* children;
101 NodeData nodeData;
102
103 RegularTreeNode( void );
104 static RegularTreeNode* NewBrood( Allocator< RegularTreeNode >* nodeAllocator )
105 {
106 auto initializer = []( RegularTreeNode & ){};
107 return NewBrood( nodeAllocator , initializer );
108 }
109
110 template< typename Initializer >
111 RegularTreeNode( Initializer &initializer );
112 template< typename Initializer >
113 static RegularTreeNode* NewBrood( Allocator< RegularTreeNode >* nodeAllocator , Initializer &initializer );
114 template< bool ThreadSafe >
115 bool initChildren( Allocator< RegularTreeNode >* nodeAllocator )
116 {
117 auto initializer = []( RegularTreeNode & ){};
118 return this->template initChildren< ThreadSafe >( nodeAllocator , initializer );
119 }
120 template< bool ThreadSafe , typename Initializer >
121 bool initChildren( Allocator< RegularTreeNode >* nodeAllocator , Initializer &initializer )
122 {
123 return ThreadSafe ? _initChildren_s( nodeAllocator , initializer ) : _initChildren( nodeAllocator , initializer );
124 }
125 void cleanChildren( bool deleteChildren );
126 static void ResetDepthAndOffset( RegularTreeNode* root , int d , int off[Dim] );
127 ~RegularTreeNode( void );
128
129 // KeepNodeFunctor looks like std::function< bool ( const RegularTreeNode * ) >
130 template< typename KeepNodeFunctor >
131 void copySubTree( RegularTreeNode &subTree , const KeepNodeFunctor &keepNodeFunctor , Allocator< RegularTreeNode > *nodeAllocator=NULL ) const;
132
133 template< typename KeepNodeFunctor >
134 Pointer( RegularTreeNode ) serializeSubTree( const KeepNodeFunctor &keepNodeFunctor , size_t &nodeCount ) const;
135
136 // The merge functor takes two objects of type NodeData and returns an object of type NodeData
137 // [NOTE] We are assuming that the merge functor is symmetric, f(a,b) = f(b,a), and implicity satisfies f(a) = a
138 template< class MergeFunctor >
139 void merge( RegularTreeNode* node , MergeFunctor& f );
140
141 void depthAndOffset( int& depth , int offset[Dim] ) const;
142 DepthAndOffset depthAndOffset( void ) const;
143 void centerIndex( int index[Dim] ) const;
144 int depth( void ) const;
145 template< class Real > void centerAndWidth( Point< Real , Dim >& center , Real& width ) const;
146 template< class Real > void startAndWidth( Point< Real , Dim >& start , Real& width ) const;
147 template< class Real > bool isInside( Point< Real , Dim > p ) const;
148
149 size_t leaves( void ) const;
150 size_t maxDepthLeaves( int maxDepth ) const;
151 size_t nodes( void ) const;
152 int maxDepth( void ) const;
153
154 const RegularTreeNode* root( void ) const;
155
156 /* These functions apply the functor to the node and all descendents, terminating either at a leaf or when the functor returns false. */
157 template< typename NodeFunctor /* = std::function< bool/void ( RegularTreeNode * ) > */ >
158 void processNodes( NodeFunctor nodeFunctor );
159 template< typename NodeFunctor /* = std::function< bool/void ( const RegularTreeNode * ) > */ >
160 void processNodes( NodeFunctor nodeFunctor ) const;
161 template< typename NodeFunctor /* = std::function< void ( RegularTreeNode * ) > */ >
162 void processLeaves( NodeFunctor nodeFunctor );
163 template< typename NodeFunctor /* = std::function< void ( const RegularTreeNode * ) > */ >
164 void processLeaves( NodeFunctor nodeFunctor ) const;
165 protected:
166 template< typename NodeFunctor /* = std::function< bool/void ( RegularTreeNode * ) > */ >
167 void _processChildNodes( NodeFunctor &nodeFunctor );
168 template< typename NodeFunctor /* = std::function< bool/void ( const RegularTreeNode * ) > */ >
169 void _processChildNodes( NodeFunctor &nodeFunctor ) const;
170 template< typename NodeFunctor /* = std::function< bool/void ( RegularTreeNode * ) > */ >
171 void _processChildLeaves( NodeFunctor &nodeFunctor );
172 template< typename NodeFunctor /* = std::function< bool/void ( const RegularTreeNode * ) > */ >
173 void _processChildLeaves( NodeFunctor &nodeFunctor ) const;
174 public:
175
176 void setFullDepth( int maxDepth , Allocator< RegularTreeNode >* nodeAllocator )
177 {
178 auto initializer = []( RegularTreeNode & ){};
179 return setFullDepth( nodeAllocator , initializer );
180 }
181 template< typename Initializer >
182 void setFullDepth( int maxDepth , Allocator< RegularTreeNode >* nodeAllocator , Initializer &initializer );
183
184 template< typename PruneChildrenFunctor >
185 void pruneChildren( const PruneChildrenFunctor pruneFunctor , bool deleteChildren );
186
187 void printLeaves( void ) const;
188 void printRange( void ) const;
189
190 template< class Real > static int ChildIndex( const Point< Real , Dim >& center , const Point< Real , Dim > &p );
191
192 // WriteNodeFunctor looks like std::function< bool ( const RegularTreeNode * ) >
193 template< typename WriteNodeFunctor >
194 bool write( BinaryStream &stream , bool serialize , const WriteNodeFunctor &writeNodeFunctor ) const;
195 bool write( BinaryStream &stream , bool serialize ) const { return write( stream , serialize , []( const RegularTreeNode * ){ return true; } ); }
196
197 template< typename Initializer >
198 bool read( BinaryStream &stream , Allocator< RegularTreeNode >* nodeAllocator , Initializer &initializer );
199 bool read( BinaryStream &stream , Allocator< RegularTreeNode >* nodeAllocator )
200 {
201 auto initializer = []( RegularTreeNode & ){};
202 return read( stream , nodeAllocator , initializer );
203 }
204
205 template< typename Pack > struct Neighbors{};
206
207 template< unsigned int ... Widths >
208 struct Neighbors< ParameterPack::UIntPack< Widths ... > >
209 {
210 using StaticWindow = Window::StaticWindow< RegularTreeNode * , Widths ... >;
211 StaticWindow neighbors;
212 Neighbors( void );
213 void clear( void );
214 };
215 template< typename Pack > struct ConstNeighbors{};
216 template< unsigned int ... Widths >
217 struct ConstNeighbors< ParameterPack::UIntPack< Widths ... > >
218 {
219 using StaticWindow = Window::StaticWindow< const RegularTreeNode * , Widths ... >;
220 StaticWindow neighbors;
221 ConstNeighbors( void );
222 void clear( void );
223 };
224
225 template< typename LeftPack , typename RightPack > struct NeighborKey{};
226 template< unsigned int ... LeftRadii , unsigned int ... RightRadii >
227 struct NeighborKey< ParameterPack::UIntPack< LeftRadii ... > , ParameterPack::UIntPack< RightRadii ... > >
228 {
229 protected:
230 static_assert( sizeof...(LeftRadii)==sizeof...(RightRadii) , "[ERROR] Left and right radii dimensions don't match" );
231 int _depth;
232
233 template< bool CreateNodes , bool ThreadSafe , typename NodeInitializer , unsigned int ... _PLeftRadii , unsigned int ... _PRightRadii , unsigned int ... _CLeftRadii , unsigned int ... _CRightRadii >
234 static unsigned int _NeighborsLoop( ParameterPack::UIntPack< _PLeftRadii ... > , ParameterPack::UIntPack< _PRightRadii ... > , ParameterPack::UIntPack< _CLeftRadii ... > , ParameterPack::UIntPack< _CRightRadii ... > , Window::ConstSlice< RegularTreeNode* , ( _PLeftRadii+_PRightRadii+1 ) ... > pNeighbors , Window::Slice< RegularTreeNode* , ( _CLeftRadii+_CRightRadii+1 ) ... > cNeighbors , int cIdx , Allocator< RegularTreeNode >* nodeAllocator , NodeInitializer &initializer );
235
236 template< bool CreateNodes , bool ThreadSafe , typename NodeInitializer , unsigned int ... _PLeftRadii , unsigned int ... _PRightRadii , unsigned int ... _CLeftRadii , unsigned int ... _CRightRadii >
237 static unsigned int _NeighborsLoop( ParameterPack::UIntPack< _PLeftRadii ... > , ParameterPack::UIntPack< _PRightRadii ... > , ParameterPack::UIntPack< _CLeftRadii ... > , ParameterPack::UIntPack< _CRightRadii ... > , Window::Slice< RegularTreeNode* , ( _PLeftRadii+_PRightRadii+1 ) ... > pNeighbors , Window::Slice< RegularTreeNode* , ( _CLeftRadii+_CRightRadii+1 ) ... > cNeighbors , int cIdx , Allocator< RegularTreeNode >* nodeAllocator , NodeInitializer &initializer );
238
239 template< bool CreateNodes , bool ThreadSafe , typename NodeInitializer , typename PLeft , typename PRight , typename CLeft , typename CRight > struct _Run{};
240
241 template< bool CreateNodes , bool ThreadSafe , typename NodeInitializer , unsigned int _PLeftRadius , unsigned int ... _PLeftRadii , unsigned int _PRightRadius , unsigned int ... _PRightRadii , unsigned int _CLeftRadius , unsigned int ... _CLeftRadii , unsigned int _CRightRadius , unsigned int ... _CRightRadii >
242 struct _Run< CreateNodes , ThreadSafe , NodeInitializer , ParameterPack::UIntPack< _PLeftRadius , _PLeftRadii ... > , ParameterPack::UIntPack< _PRightRadius , _PRightRadii ... > , ParameterPack::UIntPack< _CLeftRadius , _CLeftRadii ... > , ParameterPack::UIntPack< _CRightRadius , _CRightRadii ... > >
243 {
244 static unsigned int Run( Window::ConstSlice< RegularTreeNode* , _PLeftRadius+_PRightRadius+1 , ( _PLeftRadii+_PRightRadii+1 ) ... > pNeighbors , Window::Slice< RegularTreeNode* , _CLeftRadius+_CRightRadius+1 , ( _CLeftRadii+_CRightRadii+1 ) ... > cNeighbors , int* c , int cornerIndex , Allocator< RegularTreeNode >* nodeAllocator , NodeInitializer &initializer );
245 };
246 template< bool CreateNodes , bool ThreadSafe , typename NodeInitializer , unsigned int _PLeftRadius , unsigned int _PRightRadius , unsigned int _CLeftRadius , unsigned int _CRightRadius >
247 struct _Run< CreateNodes , ThreadSafe , NodeInitializer , ParameterPack::UIntPack< _PLeftRadius > , ParameterPack::UIntPack< _PRightRadius > , ParameterPack::UIntPack< _CLeftRadius > , ParameterPack::UIntPack< _CRightRadius > >
248 {
249 static unsigned int Run( Window::ConstSlice< RegularTreeNode* , _PLeftRadius+_PRightRadius+1 > pNeighbors , Window::Slice< RegularTreeNode* , _CLeftRadius+_CRightRadius+1 > cNeighbors , int* c , int cornerIndex , Allocator< RegularTreeNode >* nodeAllocator , NodeInitializer &initializer );
250 };
251 public:
252 static const unsigned int CenterIndex = Window::Index< ( LeftRadii + RightRadii + 1 ) ... >::template I< LeftRadii ... >();
253 typedef Neighbors< ParameterPack::UIntPack< ( LeftRadii + RightRadii + 1 ) ... > > NeighborType;
254 NeighborType* neighbors;
255
256
257 NeighborKey( void );
258 NeighborKey( const NeighborKey& key );
259 ~NeighborKey( void );
260
261 int depth( void ) const { return _depth; }
262 void set( int depth );
263
264 RegularTreeNode *center( unsigned int depth ){ return neighbors[depth].neighbors.data[ CenterIndex ]; }
265 const RegularTreeNode *center( unsigned int depth ) const { return neighbors[depth].neighbors.data[ CenterIndex ]; }
266
267 template< bool CreateNodes , bool ThreadSafe >
268 typename RegularTreeNode< Dim , NodeData , DepthAndOffsetType >::template Neighbors< ParameterPack::UIntPack< ( LeftRadii + RightRadii + 1 ) ... > >& getNeighbors( RegularTreeNode* node , Allocator< RegularTreeNode >* nodeAllocator )
269 {
270 auto initializer = []( RegularTreeNode & ){};
271 return getNeighbors< CreateNodes , ThreadSafe >( node , nodeAllocator , initializer );
272 }
273
274 template< bool CreateNodes , bool ThreadSafe , typename NodeInitializer >
275 typename RegularTreeNode< Dim , NodeData , DepthAndOffsetType >::template Neighbors< ParameterPack::UIntPack< ( LeftRadii + RightRadii + 1 ) ... > >& getNeighbors( RegularTreeNode* node , Allocator< RegularTreeNode >* nodeAllocator , NodeInitializer &nodeInitializer );
276
277 NeighborType& getNeighbors( const RegularTreeNode* node )
278 {
279 auto initializer = []( RegularTreeNode & ){};
280 return getNeighbors< false , false >( (RegularTreeNode*)node , NULL , initializer );
281 }
282
283 template< bool CreateNodes , bool ThreadSafe , unsigned int ... _LeftRadii , unsigned int ... _RightRadii >
284 void getNeighbors( ParameterPack::UIntPack< _LeftRadii ... > , ParameterPack::UIntPack< _RightRadii ... > , RegularTreeNode* node , Neighbors< ParameterPack::UIntPack< ( _LeftRadii + _RightRadii + 1 ) ... > >& neighbors , Allocator< RegularTreeNode >* nodeAllocator )
285 {
286 auto initializer = []( RegularTreeNode & ){};
287 return getNeighbors( ParameterPack::UIntPack< _LeftRadii ... >() , ParameterPack::UIntPack< _RightRadii ... >() , node , neighbors , nodeAllocator , initializer );
288 }
289
290 template< bool CreateNodes , bool ThreadSafe , typename NodeInitializer , unsigned int ... _LeftRadii , unsigned int ... _RightRadii >
291 void getNeighbors( ParameterPack::UIntPack< _LeftRadii ... > , ParameterPack::UIntPack< _RightRadii ... > , RegularTreeNode* node , Neighbors< ParameterPack::UIntPack< ( _LeftRadii + _RightRadii + 1 ) ... > >& neighbors , Allocator< RegularTreeNode >* nodeAllocator , NodeInitializer &initializer );
292
293 template< unsigned int ... _LeftRadii , unsigned int ... _RightRadii >
294 void getNeighbors( ParameterPack::UIntPack< _LeftRadii ... > , ParameterPack::UIntPack< _RightRadii ... > , const RegularTreeNode* node , Neighbors< ParameterPack::UIntPack< ( _LeftRadii + _RightRadii + 1 ) ... > >& neighbors )
295 {
296 auto initializer = []( RegularTreeNode & ){};
297 return getNeighbors< false , false >( ParameterPack::UIntPack< _LeftRadii ... >() , ParameterPack::UIntPack< _RightRadii ... >() , (RegularTreeNode*)node , NULL , initializer );
298 }
299
300 template< bool CreateNodes , bool ThreadSafe , unsigned int ... _LeftRadii , unsigned int ... _RightRadii >
301 void getNeighbors( ParameterPack::UIntPack< _LeftRadii ... > , ParameterPack::UIntPack< _RightRadii ... > , RegularTreeNode* node , Neighbors< ParameterPack::UIntPack< ( _LeftRadii + _RightRadii + 1 ) ... > >& pNeighbors , Neighbors< ParameterPack::UIntPack< ( _LeftRadii + _RightRadii + 1 ) ... > >& neighbors , Allocator< RegularTreeNode >* nodeAllocator )
302 {
303 auto initializer = []( RegularTreeNode & ){};
304 return getNeighbors( ParameterPack::UIntPack< _LeftRadii ... >() , ParameterPack::UIntPack< _RightRadii ... >() , node , pNeighbors , neighbors , nodeAllocator , initializer );
305 }
306
307 template< bool CreateNodes , bool ThreadSafe , typename NodeInitializer , unsigned int ... _LeftRadii , unsigned int ... _RightRadii >
308 void getNeighbors( ParameterPack::UIntPack< _LeftRadii ... > , ParameterPack::UIntPack< _RightRadii ... > , RegularTreeNode* node , Neighbors< ParameterPack::UIntPack< ( _LeftRadii + _RightRadii + 1 ) ... > >& pNeighbors , Neighbors< ParameterPack::UIntPack< ( _LeftRadii + _RightRadii + 1 ) ... > >& neighbors , Allocator< RegularTreeNode >* nodeAllocator , NodeInitializer &initializer );
309
310 template< unsigned int ... _LeftRadii , unsigned int ... _RightRadii >
311 void getNeighbors( ParameterPack::UIntPack< _LeftRadii ... > , ParameterPack::UIntPack< _RightRadii ... > , const RegularTreeNode* node , Neighbors< ParameterPack::UIntPack< ( _LeftRadii + _RightRadii + 1 ) ... > >& pNeighbors , Neighbors< ParameterPack::UIntPack< ( _LeftRadii + _RightRadii + 1 ) ... > >& neighbors )
312 {
313 auto initializer = []( RegularTreeNode & ){};
314 return getNeighbors< false , false >( ParameterPack::UIntPack< _LeftRadii ... >() , ParameterPack::UIntPack< _RightRadii ... >() , (RegularTreeNode*)node , NULL , initializer );
315 }
316
317 template< bool CreateNodes , bool ThreadSafe >
318 unsigned int getChildNeighbors( int cIdx , int d , NeighborType& childNeighbors , Allocator< RegularTreeNode >* nodeAllocator ) const
319 {
320 auto initializer = []( RegularTreeNode & ){};
321 return getChildNeighbors( cIdx , d , childNeighbors , nodeAllocator , initializer );
322 }
323
324 template< bool CreateNodes , bool ThreadSafe , typename NodeInitializer >
325 unsigned int getChildNeighbors( int cIdx , int d , NeighborType& childNeighbors , Allocator< RegularTreeNode >* nodeAllocator , NodeInitializer &initializer ) const;
326
327 unsigned int getChildNeighbors( int cIdx , int d , NeighborType& childNeighbors ) const
328 {
329 auto initializer = []( RegularTreeNode & ){};
330 return getChildNeighbors< false , false >( cIdx , d , childNeighbors , NULL , initializer );
331 }
332
333 template< bool CreateNodes , bool ThreadSafe , class Real >
334 unsigned int getChildNeighbors( Point< Real , Dim > p , int d , NeighborType& childNeighbors , Allocator< RegularTreeNode >* nodeAllocator ) const
335 {
336 auto initializer = []( RegularTreeNode & ){};
337 return getChildNeighbors( p , d , childNeighbors , nodeAllocator , initializer );
338 }
339
340 template< bool CreateNodes , bool ThreadSafe , typename NodeInitializer , class Real >
341 unsigned int getChildNeighbors( Point< Real , Dim > p , int d , NeighborType& childNeighbors , Allocator< RegularTreeNode >* nodeAllocator , NodeInitializer &initializer ) const;
342
343 template< class Real >
344 unsigned int getChildNeighbors( Point< Real , Dim > p , int d , NeighborType& childNeighbors ) const
345 {
346 auto initializer = []( RegularTreeNode & ){};
347 return getChildNeighbors< false , false , Real >( p , d , childNeighbors , NULL , initializer );
348 }
349
350 void setLeafNeighbors( RegularTreeNode *node , Window::StaticWindow< RegularTreeNode * , ( LeftRadii + RightRadii + 1 ) ... > &leaves );
351 };
352
353 template< typename LeftPack , typename RightPack > struct ConstNeighborKey{};
354
355 template< unsigned int ... LeftRadii , unsigned int ... RightRadii >
356 struct ConstNeighborKey< ParameterPack::UIntPack< LeftRadii ... > , ParameterPack::UIntPack< RightRadii ... > >
357 {
358 protected:
359 static_assert( sizeof...(LeftRadii)==sizeof...(RightRadii) , "[ERROR] Left and right radii dimensions don't match" );
360 int _depth;
361
362 template< unsigned int ... _PLeftRadii , unsigned int ... _PRightRadii , unsigned int ... _CLeftRadii , unsigned int ... _CRightRadii >
363 static unsigned int _NeighborsLoop( ParameterPack::UIntPack< _PLeftRadii ... > , ParameterPack::UIntPack< _PRightRadii ... > , ParameterPack::UIntPack< _CLeftRadii ... > , ParameterPack::UIntPack< _CRightRadii ... > , Window::ConstSlice< const RegularTreeNode* , ( _PLeftRadii+_PRightRadii+1 ) ... > pNeighbors , Window::Slice< const RegularTreeNode* , ( _CLeftRadii+_CRightRadii+1 ) ... > cNeighbors , int cIdx );
364 template< unsigned int ... _PLeftRadii , unsigned int ... _PRightRadii , unsigned int ... _CLeftRadii , unsigned int ... _CRightRadii >
365 static unsigned int _NeighborsLoop( ParameterPack::UIntPack< _PLeftRadii ... > , ParameterPack::UIntPack< _PRightRadii ... > , ParameterPack::UIntPack< _CLeftRadii ... > , ParameterPack::UIntPack< _CRightRadii ... > , Window::Slice< const RegularTreeNode* , ( _PLeftRadii+_PRightRadii+1 ) ... > pNeighbors , Window::Slice< const RegularTreeNode* , ( _CLeftRadii+_CRightRadii+1 ) ... > cNeighbors , int cIdx );
366
367 template< typename PLeft , typename PRight , typename CLeft , typename CRight > struct _Run{};
368
369 template< unsigned int _PLeftRadius , unsigned int ... _PLeftRadii , unsigned int _PRightRadius , unsigned int ... _PRightRadii , unsigned int _CLeftRadius , unsigned int ... _CLeftRadii , unsigned int _CRightRadius , unsigned int ... _CRightRadii >
370 struct _Run< ParameterPack::UIntPack< _PLeftRadius , _PLeftRadii ... > , ParameterPack::UIntPack< _PRightRadius , _PRightRadii ... > , ParameterPack::UIntPack< _CLeftRadius , _CLeftRadii ... > , ParameterPack::UIntPack< _CRightRadius , _CRightRadii ... > >
371 {
372 static unsigned int Run( Window::ConstSlice< const RegularTreeNode* , _PLeftRadius + _PRightRadius + 1 , ( _PLeftRadii+_PRightRadii+1 ) ... > pNeighbors , Window::Slice< const RegularTreeNode* , _CLeftRadius + _CRightRadius + 1 , ( _CLeftRadii+_CRightRadii+1 ) ... > cNeighbors , int* c , int cornerIndex );
373 };
374 template< unsigned int _PLeftRadius , unsigned int _PRightRadius , unsigned int _CLeftRadius , unsigned int _CRightRadius >
375 struct _Run< ParameterPack::UIntPack< _PLeftRadius > , ParameterPack::UIntPack< _PRightRadius > , ParameterPack::UIntPack< _CLeftRadius > , ParameterPack::UIntPack< _CRightRadius > >
376 {
377 static unsigned int Run( Window::ConstSlice< const RegularTreeNode* , _PLeftRadius+_PRightRadius+1 > pNeighbors , Window::Slice< const RegularTreeNode* , _CLeftRadius+_CRightRadius+1 > cNeighbors , int* c , int cornerIndex );
378 };
379
380 public:
381 static const unsigned int CenterIndex = Window::Index< ( LeftRadii + RightRadii + 1 ) ... >::template I< LeftRadii ... >();
382 typedef ConstNeighbors< ParameterPack::UIntPack< ( LeftRadii + RightRadii + 1 ) ... > > NeighborType;
383 NeighborType* neighbors;
384
385 ConstNeighborKey( void );
386 ConstNeighborKey( const ConstNeighborKey& key );
387 ~ConstNeighborKey( void );
388 ConstNeighborKey& operator = ( const ConstNeighborKey& key );
389
390 int depth( void ) const { return _depth; }
391 void set( int depth );
392 const RegularTreeNode *center( unsigned int depth ) const { return neighbors[depth].neighbors.data[ CenterIndex ]; }
393
394 typename RegularTreeNode< Dim , NodeData , DepthAndOffsetType >::template ConstNeighbors< ParameterPack::UIntPack< ( LeftRadii + RightRadii + 1 ) ... > >& getNeighbors( const RegularTreeNode* node );
395 template< unsigned int ... _LeftRadii , unsigned int ... _RightRadii >
396 void getNeighbors( ParameterPack::UIntPack< _LeftRadii ... > , ParameterPack::UIntPack< _RightRadii ... > , const RegularTreeNode* node , ConstNeighbors< ParameterPack::UIntPack< ( _LeftRadii + _RightRadii + 1 ) ... > >& neighbors );
397 template< unsigned int ... _LeftRadii , unsigned int ... _RightRadii >
398 void getNeighbors( ParameterPack::UIntPack< _LeftRadii ... > , ParameterPack::UIntPack< _RightRadii ... > , const RegularTreeNode* node , ConstNeighbors< ParameterPack::UIntPack< ( _LeftRadii + _RightRadii + 1 ) ... > >& pNeighbors , ConstNeighbors< ParameterPack::UIntPack< ( _LeftRadii + _RightRadii + 1 ) ... > >& neighbors );
399 unsigned int getChildNeighbors( int cIdx , int d , NeighborType& childNeighbors ) const;
400 template< class Real >
401 unsigned int getChildNeighbors( Point< Real , Dim > p , int d , ConstNeighbors< ParameterPack::UIntPack< ( LeftRadii + RightRadii + 1 ) ... > >& childNeighbors ) const;
402
403 void setLeafNeighbors( const RegularTreeNode *node , Window::StaticWindow< RegularTreeNode * , ( LeftRadii + RightRadii + 1 ) ... > &leaves );
404 };
405
406 int width( int maxDepth ) const;
407 };
408
409 #include "RegularTree.inl"
410 }
411
412 #endif // REGULAR_TREE_NODE_INCLUDED