FSubOctree.hpp 22 KB
Newer Older
1
// ===================================================================================
2
3
4
5
6
7
8
9
// Logiciel initial: ScalFmm Version 0.5
// Co-auteurs : Olivier Coulaud, Bérenger Bramas.
// Propriétaires : INRIA.
// Copyright © 2011-2012, diffusé sous les termes et conditions d’une licence propriétaire.
// Initial software: ScalFmm Version 0.5
// Co-authors: Olivier Coulaud, Bérenger Bramas.
// Owners: INRIA.
// Copyright © 2011-2012, spread under the terms and conditions of a proprietary license.
10
// ===================================================================================
11
12
#ifndef FSUBOCTREE_HPP
#define FSUBOCTREE_HPP
13

14
15

#include "../Utils/FGlobal.hpp"
BRAMAS Berenger's avatar
BRAMAS Berenger committed
16
#include "../Utils/FPoint.hpp"
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "../Utils/FAssertable.hpp"
#include "../Utils/FMath.hpp"

#include "FTreeCoordinate.hpp"


/**
 * @author Berenger Bramas (berenger.bramas@inria.fr)
 * @class FAbstractSubOctree
 * Please read the license
 *
 * This class is a sub-octree container.
 * This class is the main component of the octree.
 * 
 * This class does not have a main root. In fact, the root
 * is contained in the parent sub-octree.
 *
 * If the sub-octree is a middle suboctree, the leaf level is pointers
 * on other suboctrees.
 *
 * If the sub-octree is a bottom subtree then the leaf level is pointers on
 * lists<particle>
 *
 * This two situations are implemented in two different classes that inherite of FAbstractSubOctree.
 *
 * Please refere to testOctree.cpp to see an example
 * @warning Give the particleClass & cellClass
 */
berenger-bramas's avatar
berenger-bramas committed
45
template< class ParticleClass, class CellClass , class ContainerClass, class LeafClass>
46
47
48
49
50
51
class FAbstractSubOctree : protected FAssertable{
protected:

    CellClass*** cells;		            //< Potential cells, cells are allocated only if needed
    FAbstractSubOctree* const parent;       //< Parent suboctree (null for root)

52
    const int indexInParent;                //< This is the index of the current octree in the parent's array
53

54
55
    int leftLeafIndex;                      //< The leaf at the left position (this is the array index to start when iterate)
    int rightLeafIndex;                     //< The leaf at the right position (this is the last array index when iterate)
56
57
58
59

    const int subOctreeHeight;              //< Height of this suboctree
    const int subOctreePosition;	    //< Level of the current suboctree in the global tree (0 if node)

60
61
    const bool isLeafSubtree;               //< To know if a subtree is leaf or not (we prefere that to a virtual method)

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

    /**
     * This function compute the morton index for the last level of this suboctree.
     * suppose we have an index like : 000.010.111.001.101.110
     * and now considere that suboctree's height is 2, the morton index have to be cut as :
     * [000.010].[111.001].[101.110] each part correspond to a morton index a leaf level for the
     * different suboctrees.
     * This is why depending on the level of the octree we need to remove extra part on the left and
     * on the right.
     */
    MortonIndex getLeafIndex(const MortonIndex index, const int inTreeHeight) const {
        // Remove right useless part - used by child
        const MortonIndex fullIndex = index >> (3 * (inTreeHeight - (this->subOctreeHeight + this->subOctreePosition) ) );
        // Remove left extra data part - used by parent
        const MortonIndex treeLeafMask = ~(~0x00LL << (3 *  this->subOctreeHeight ));
        return treeLeafMask & fullIndex;
    }

    /**
     * This function creats all the intermediates cells between
     * a leaf and the root.
     * It is used after inserting a new leaf to have cells from leaf to root
     * when computing
     * @param arrayIndex the index at the leaf index of the new element
     */
87
    void createPreviousCells(MortonIndex arrayIndex, MortonIndex inLeafCellIndex, const FTreeCoordinate& treePosition){
88
        int indexLevel = this->subOctreeHeight - 1;
89
        int bottomToTop = 0;
90
        while(indexLevel >= 0 && !this->cells[indexLevel][arrayIndex]){
91
92
            CellClass* const newNode = new CellClass();
            newNode->setMortonIndex(inLeafCellIndex);
93

94
            newNode->setCoordinate(treePosition.getX() >> bottomToTop,
95
96
                                   treePosition.getY() >> bottomToTop,
                                   treePosition.getZ() >> bottomToTop);
97

98
99
            this->cells[indexLevel][arrayIndex] = newNode;

100
            --indexLevel;
101
            ++bottomToTop;
102
103
104
105
106
107
108
109
110
111
112

            arrayIndex >>= 3;
            inLeafCellIndex >>= 3;
        }
    }

    /**
      * This function is initializing variables when a new leaf is inserted in the tree
      * for example it updates the leaf array marges and calls createPreviousCells()
      * @param arrayIndex the position of the new leaf in the leafs array
      */
113
114
    void newLeafInserted(const int arrayIndex, const MortonIndex inLeafCellIndex,  const FTreeCoordinate& host){
        createPreviousCells(arrayIndex,inLeafCellIndex, host);
115
116
117
118
119
        // Update if this is the bottom left
        if(arrayIndex < this->leftLeafIndex) this->leftLeafIndex = arrayIndex;
        if(arrayIndex > this->rightLeafIndex) this->rightLeafIndex = arrayIndex;
    }

120
121
122
123
124
125
    /** Remove every cells from the array index
      * the leaf cell is removed, then we go upper and test,
      * does the upper cell do no have any more child, if tree remove
      * this cell too and go upper, etc.
      * @return true if there is no more cells in this tree
      */
126
    bool removeCellsFromLeaf( int arrayIndex ){
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
        // last array index
        int indexLevel = this->subOctreeHeight - 1;

        // Manage border limits
        if(arrayIndex == this->leftLeafIndex && arrayIndex == this->rightLeafIndex){
            // only one cells, return true
            return true;
        }
        else if(arrayIndex == this->leftLeafIndex){
            while( !this->cells[indexLevel][++this->leftLeafIndex] );
        }
        else if(arrayIndex == this->rightLeafIndex){
            while( !this->cells[indexLevel][--this->rightLeafIndex] );
        }

        // remove the last cells
        delete this->cells[indexLevel][arrayIndex];
        this->cells[indexLevel][arrayIndex] = 0;
        // progress upper
        --indexLevel;
        arrayIndex >>= 3;

        // to test if 8 child are empty
        CellClass* emptyArray[8];
        memset(emptyArray , 0, sizeof(CellClass*) * 8);

        // continue while we are not in the last level and our child are empty
        while(indexLevel >= 0 && memcmp(&this->cells[indexLevel+1][arrayIndex<<3], emptyArray, 8 * sizeof(CellClass*)) == 0 ){
            delete this->cells[indexLevel][arrayIndex];
            this->cells[indexLevel][arrayIndex] = 0;

            --indexLevel;
            arrayIndex >>= 3;
        }
        // return true if there is no more child == 0 cell at level 0
        return memcmp(this->cells[0], emptyArray, 8 * sizeof(CellClass*)) == 0;
    }

165
166
167
168
169
170
171
172
173
174
175
176
177
    /** Disable copy */
private:
    FAbstractSubOctree(const FAbstractSubOctree&){}
    FAbstractSubOctree& operator=(const FAbstractSubOctree&){return *this;}

public:
    /**
    * Constructor
    * Allocate the cells arrays to be able to create every potential cells
    * @param inParent the SubOctree parent (0 if node)
    * @param inSubOctreeHeight Height of this suboctree
    * @param inSubOctreePosition Level of the current suboctree in the global tree (1 if upper tree)
    */
178
    FAbstractSubOctree(FAbstractSubOctree* const inParent, const int inIndexInParent,
179
                       const int inSubOctreeHeight, const int inSubOctreePosition, const bool inIsLeafSubtree) :
180
                        cells(0), parent( inParent ), indexInParent(inIndexInParent), leftLeafIndex(1 << (3 * inSubOctreeHeight)), rightLeafIndex(-1),
181
                        subOctreeHeight( inSubOctreeHeight ), subOctreePosition( inSubOctreePosition ), isLeafSubtree(inIsLeafSubtree) {
182
183

        this->cells = new CellClass**[this->subOctreeHeight];
184
        fassert(this->cells, "Allocation failled", __LINE__, __FILE__);
185

berenger-bramas's avatar
berenger-bramas committed
186
187
        memset(this->cells, 0, sizeof(CellClass**) * subOctreeHeight);

188
        // We start at a sub-level - 8^1
189
        int cellsAtlevel = 8;
190
191
        for( int indexLevel = 0 ; indexLevel < this->subOctreeHeight ; ++indexLevel ){
            this->cells[indexLevel] = new CellClass*[cellsAtlevel];
192
            fassert(this->cells[indexLevel], "Allocation failled", __LINE__, __FILE__);
193

berenger-bramas's avatar
berenger-bramas committed
194
            memset(this->cells[indexLevel], 0, sizeof(CellClass*) * cellsAtlevel);
195
196
197
198
199
200
201
202
203
204

            cellsAtlevel <<= 3; // => * 8 >> 8^indexLevel
        }
    }

    /**
    * Destructor
    * Delete cells arrays and allocated cells
    */
    virtual ~FAbstractSubOctree(){
205
206
        int mostRight = rightLeafIndex;
        int mostLeft = leftLeafIndex;
207
208

        for( int indexLevel = this->subOctreeHeight - 1 ; indexLevel >= 0 ; --indexLevel ){
209
            for( int indexCells = mostLeft ; indexCells <= mostRight ; ++indexCells ){
210
                if(this->cells[indexLevel][indexCells]){
211
                    delete this->cells[indexLevel][indexCells];
212
213
214
215
                }
            }

            delete [] this->cells[indexLevel];
216
217
            mostLeft  >>= 3;
            mostRight >>= 3;
218
219
220
221
222
223
224
225
226
227
228
229
        }

        delete [] this->cells;
    }


    /**
    * Insert a particle on the subtree
    * @param index the morton index of the particle to insert
    * @param inParticle the particle to insert (must inherite from FAbstractParticle)
    * @param inParticle the inTreeHeight the height of the tree
    */
230
    virtual void insert(const MortonIndex index, const FTreeCoordinate& host, const ParticleClass& inParticle, const int inTreeHeight) = 0;
231

232
233
234
235
236
237
    /**
      * Remove a leaf and every cells if needed
      * @return true if the subtree does not contains any more cells
      */
    virtual bool removeLeaf(const MortonIndex index, const int inTreeHeight) = 0;

238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
    ///////////////////////////////////////
    // This is the FOctree::Iterator Part
    ///////////////////////////////////////

    /** Suboctree height accessor (leaf level + 1)
      * @return subOctreeHeight */
    int getSubOctreeHeight() const{
        return subOctreeHeight;
    }

    /** Suboctree position in the real tree
      * @return subOctreePosition */
    int getSubOctreePosition() const {
        return subOctreePosition;
    }

    /** Return the more left leaf index
      * the smallest index on the leafs array
      * @return leftLeafIndex */
257
    int getLeftLeafIndex() const {
258
259
260
261
262
263
        return leftLeafIndex;
    }

    /** Return the more right leaf index
      * the biggest index on the leafs array
      * @return rightLeafIndex */
264
    int getRightLeafIndex() const {
265
266
267
268
269
270
271
        return rightLeafIndex;
    }

    /** Return the array of cells at a specious index
      * @param level the level to access cells array (must be < subOctreeHeight)
      * @return cells[level] */
    CellClass** cellsAt(const int level) const{
272
        fassert(level < subOctreeHeight, "Level out of memory", __LINE__, __FILE__);
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
        return cells[level];
    }

    /** To know if it is the root suboctree
      * @return true if has parent otherwise return false */
    bool hasParent() const {
        return parent;
    }

    /** To get access to the parent suboctree
      * @return parent */
    FAbstractSubOctree* getParent(){
        return parent;
    }

    /** To get access to the parent suboctree (const version)
      * @return parent */
    const FAbstractSubOctree* getParent() const{
        return parent;
    }

    /** To get the index of the current suboctree in the parent leafs array
      * This index can is part of the morton index of the cells contains
      * in this suboctree
      * @return indexInParent */
298
    int getIndexInParent() const{
299
300
        return indexInParent;
    }
301
302
303
304
305
306
307
308

    /** To know if this class has been inherited by a leaf subtree or middle subtree
      * Of course we can do a virtual method to do that but virtual method are slower
      * if we point to parent class to call the method
      */
    bool isLeafPart() const{
        return this->isLeafSubtree;
    }
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
};



/////////////////////////////////////////////////////////////////////////////////////
// Last level sub octree
/////////////////////////////////////////////////////////////////////////////////////

/**
 * @author Berenger Bramas (berenger.bramas@inria.fr)
 * @class FSubOctreeWithLeafs
 * Please read the license
 *
 * This class is an sub-octree container.
 * But this is the specialized bottom part, in fact the last level is composed by
 * a cells array (managing by abstract class) and lists of particles.
 *
 * Please refere to testOctree.cpp to see an example.
 * @warning Give the particleClass & cellClass
 */
berenger-bramas's avatar
berenger-bramas committed
329
template< class ParticleClass, class CellClass , class ContainerClass, class LeafClass>
330
class FSubOctreeWithLeafs : public FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass> {
331
private:
berenger-bramas's avatar
berenger-bramas committed
332
    typedef FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass> Parent;
333

berenger-bramas's avatar
berenger-bramas committed
334
    LeafClass** leafs;            //< Leafs array
335
336
337
338
339
340
341
342
343
344
345
346
347

    /** Disable copy */
    FSubOctreeWithLeafs(const FSubOctreeWithLeafs&){}
    FSubOctreeWithLeafs& operator=(const FSubOctreeWithLeafs&){return *this;}

public:     
    /**
    * Constructor
    * Allocate the leafs array
    * @param inParent the SubOctree parent (0 if node)
    * @param inSubOctreeHeight Height of this suboctree
    * @param inSubOctreePosition Level of the current suboctree in the global tree (1 if upper tree)
    */
348
    FSubOctreeWithLeafs(FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>* const inParent, const int inIndexInParent,
349
                        const int inSubOctreeHeight, const int inSubOctreePosition) :
350
                        FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>(inParent, inIndexInParent, inSubOctreeHeight, inSubOctreePosition, true) {
351

352
        const int cellsAtLeafLevel = 1 << (3 * inSubOctreeHeight);
353

berenger-bramas's avatar
berenger-bramas committed
354
        this->leafs = new LeafClass*[cellsAtLeafLevel];
355
        fassert(this->leafs, "Allocation failled", __LINE__, __FILE__);
356

berenger-bramas's avatar
berenger-bramas committed
357
        memset(leafs, 0, sizeof(LeafClass*) * cellsAtLeafLevel);
358
359
360
361
362
363
    }

    /**
    * Destructor dealloc all leafs & the leaf array
    */
    virtual ~FSubOctreeWithLeafs(){
berenger-bramas's avatar
berenger-bramas committed
364
        for( int indexLeaf = Parent::leftLeafIndex ; indexLeaf <= Parent::rightLeafIndex ; ++indexLeaf ){
365
366
367
368
369
370
371
372
373
374
            if(this->leafs[indexLeaf]){
                delete this->leafs[indexLeaf];
            }
        }
        delete [] this->leafs;
    }

    /**
    * Refer to FAbstractSubOctree::insert
    */
375
    void insert(const MortonIndex index, const FTreeCoordinate& host, const ParticleClass& inParticle, const int inTreeHeight){
376
        // Get the morton index for the leaf level
berenger-bramas's avatar
berenger-bramas committed
377
        const MortonIndex arrayIndex = Parent::getLeafIndex(index,inTreeHeight);
378
379
        // is there already a leaf?
        if( !this->leafs[arrayIndex] ){
berenger-bramas's avatar
berenger-bramas committed
380
            this->leafs[arrayIndex] = new LeafClass();
381

berenger-bramas's avatar
berenger-bramas committed
382
            Parent::newLeafInserted( int(arrayIndex) , index, host);
383
384
385
386
387
        }
        // add particle to leaf list
        this->leafs[arrayIndex]->push(inParticle);
    }

388
389
390
391
392
    /**
      * Remove a leaf and every cells if needed
      */
    bool removeLeaf(const MortonIndex index, const int inTreeHeight) {
        // Get the morton index for the leaf level
berenger-bramas's avatar
berenger-bramas committed
393
        const MortonIndex arrayIndex = Parent::getLeafIndex(index,inTreeHeight);
394
395
396
397
398
        if( this->leafs[arrayIndex] ){
            // remove container
            delete this->leafs[arrayIndex];
            this->leafs[arrayIndex] = 0;

berenger-bramas's avatar
berenger-bramas committed
399
            return Parent::removeCellsFromLeaf( int(arrayIndex) );
400
401
402
403
        }
        return false;
    }

404
405
406
    /** To get access to leafs elements
      * @param index the position of the leaf
      * @return the list of particles at this index */
berenger-bramas's avatar
berenger-bramas committed
407
408
    ContainerClass* getLeafSrc(const int index){
        LeafClass* const leaf = this->leafs[index];
409
410
411
412
413
414
        return (leaf ? leaf->getSrc(): 0);
    }

    /** To get access to leafs elements
      * @param index the position of the leaf
      * @return the list of particles at this index */
berenger-bramas's avatar
berenger-bramas committed
415
416
    ContainerClass* getLeafTargets(const int index){
        LeafClass* const leaf = this->leafs[index];
417
418
419
420
421
422
        return (leaf ? leaf->getTargets(): 0);
    }

    /** To get access to leafs elements
      * @param index the position of the leaf
      * @return the list of particles at this index */
berenger-bramas's avatar
berenger-bramas committed
423
424
    const ContainerClass* getLeafSrc(const int index) const {
        LeafClass* const leaf = this->leafs[index];
425
426
427
428
429
430
        return (leaf ? leaf->getSrc(): 0);
    }

    /** To get access to leafs elements
      * @param index the position of the leaf
      * @return the list of particles at this index */
berenger-bramas's avatar
berenger-bramas committed
431
432
    const ContainerClass* getLeafTargets(const int index) const {
        LeafClass* const leaf = this->leafs[index];
433
434
435
        return (leaf ? leaf->getTargets() : 0);
    }

436
437
438
    LeafClass* getLeaf(const int index){
        return this->leafs[index];
    }
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
};



/////////////////////////////////////////////////////////////////////////////////////
// Middle level sub octree
/////////////////////////////////////////////////////////////////////////////////////

/**
 * @author Berenger Bramas (berenger.bramas@inria.fr)
 * @class FSubOctree
 * Please read the license
 *
 * This class is an sub-octree container.
 * This is the middle level specialized suboctree, it means that it does not contain
 * leaf but pointers to other suboctree.
 * These suboctrees at the last level can be FSubOctree of FSubOctreeWithLeafs depending
 * if they are at the bottom of the tree or not
 *
 * @warning Give the particleClass & cellClass
 */
berenger-bramas's avatar
berenger-bramas committed
460
template< class ParticleClass, class CellClass , class ContainerClass, class LeafClass>
461
class FSubOctree : public FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass> {
462
private:
berenger-bramas's avatar
berenger-bramas committed
463
464
465
    typedef FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass> Parent;

    Parent** subleafs;    //< Last levels is composed of suboctree
466
467
468
469
470
471
472
473
474
475
476
477
478

    /** Disable copy */
    FSubOctree(const FSubOctree&){}
    FSubOctree& operator=(const FSubOctree&){return *this;}

public:	
    /**
    * Constructor
    * Allocate the subleafs array
    * @param inParent the SubOctree parent (0 if node)
    * @param inSubOctreeHeight Height of this suboctree
    * @param inSubOctreePosition Level of the current suboctree in the global tree (0 if upper tree)
    */
479
    FSubOctree(FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>* const inParent,  const int inIndexInParent,
480
               const int inSubOctreeHeight, const int inSubOctreePosition) :
481
            FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>(inParent, inIndexInParent, inSubOctreeHeight, inSubOctreePosition, false) {
482

483
        const int cellsAtLeafLevel = 1 << (3 * inSubOctreeHeight);
berenger-bramas's avatar
berenger-bramas committed
484
485

        this->subleafs = new Parent*[cellsAtLeafLevel];
486
        fassert(this->subleafs, "Allocation failled", __LINE__, __FILE__);
487

berenger-bramas's avatar
berenger-bramas committed
488
        memset(subleafs, 0, sizeof(Parent**) * cellsAtLeafLevel);
489
490
491
492
493
494
    }

    /**
    * Destructor dealloc all suboctrees leafs & leafs array
    */
    virtual ~FSubOctree(){
berenger-bramas's avatar
berenger-bramas committed
495
        for( int indexLeaf = Parent::leftLeafIndex ; indexLeaf <= Parent::rightLeafIndex ; ++indexLeaf ){
496
497
498
499
500
501
502
503
            if(this->subleafs[indexLeaf]) delete this->subleafs[indexLeaf];
        }
        delete [] this->subleafs;
    }

    /**
    * Refer to FAbstractSubOctree::insert
    */
504
    void insert(const MortonIndex index, const FTreeCoordinate& host, const ParticleClass& inParticle, const int inTreeHeight){
505
506
        // We need the morton index at the bottom level of this sub octree
        // so we remove the right side
berenger-bramas's avatar
berenger-bramas committed
507
        const MortonIndex arrayIndex = Parent::getLeafIndex(index,inTreeHeight);
508
509
510
511
512
513
514
515
        // Is there already a leaf?
        if( !this->subleafs[arrayIndex] ){
            // We need to create leaf sub octree
            const int nextSubOctreePosition = this->subOctreePosition + this->subOctreeHeight;
            const int nextSubOctreeHeight = FMath::Min(inTreeHeight - nextSubOctreePosition, this->subOctreeHeight);

            // Next suboctree is a middle suboctree
            if(inTreeHeight > nextSubOctreeHeight + nextSubOctreePosition){
516
                this->subleafs[arrayIndex] = new FSubOctree(this,int(arrayIndex),nextSubOctreeHeight,nextSubOctreePosition);
517
518
519
            }
            // Or next suboctree contains the reail leaf!
            else{
520
                this->subleafs[arrayIndex] = new FSubOctreeWithLeafs<ParticleClass,CellClass,ContainerClass,LeafClass>(this,int(arrayIndex),nextSubOctreeHeight,nextSubOctreePosition);
521
522
            }

523
524
525
526
527
            const FTreeCoordinate hostAtLevel(
                        host.getX() >> (inTreeHeight - nextSubOctreePosition ),
                        host.getY() >> (inTreeHeight - nextSubOctreePosition ),
                        host.getZ() >> (inTreeHeight - nextSubOctreePosition ));

528
            // We need to inform parent class
berenger-bramas's avatar
berenger-bramas committed
529
            Parent::newLeafInserted( int(arrayIndex), index >> (3 * (inTreeHeight-nextSubOctreePosition) ), hostAtLevel);
530
531
        }
        // Ask next suboctree to insert the particle
532
        this->subleafs[arrayIndex]->insert( index, host, inParticle, inTreeHeight);
533
534
    }

535
536
537
538
539
    /**
      * Remove a leaf and every cells if needed
      */
    bool removeLeaf(const MortonIndex index, const int inTreeHeight) {
        // Get the morton index for the leaf level
berenger-bramas's avatar
berenger-bramas committed
540
        const MortonIndex arrayIndex = Parent::getLeafIndex(index,inTreeHeight);
541
542
543
544
545
        if( this->subleafs[arrayIndex]->removeLeaf(index, inTreeHeight) ){
            // remove container
            delete this->subleafs[arrayIndex];
            this->subleafs[arrayIndex] = 0;

berenger-bramas's avatar
berenger-bramas committed
546
            return Parent::removeCellsFromLeaf( int(arrayIndex) );
547
548
549
550
        }
        return false;
    }

551
552
553
    /** To get access to leafs elements (child suboctree)
      * @param index the position of the leaf/child suboctree
      * @return child at this index */
554
    FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>* leafs(const int index) {
555
556
557
558
559
560
        return this->subleafs[index];
    }

    /** To get access to leafs elements (child suboctree)
      * @param index the position of the leaf/child suboctree
      * @return child at this index */
561
    const FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>* leafs(const int index) const {
562
563
564
565
566
567
        return this->subleafs[index];
    }
};


#endif //FSUBOCTREE_HPP
568