testOctreeIter.cpp 4.1 KB
Newer Older
1
// See LICENCE file at project root
2 3 4

#include <iostream>

5 6
#include <cstdio>
#include <cstdlib>
7 8 9
#include <time.h>


10
#include "../../Src/Utils/FParameters.hpp"
11

12 13 14
#include "../../Src/Containers/FOctree.hpp"
#include "../../Src/Containers/FVector.hpp"
#include "../../Src/Components/FSimpleLeaf.hpp"
15

BRAMAS Berenger's avatar
BRAMAS Berenger committed
16
#include "../../Src/Utils/FAssert.hpp"
17
#include "../../Src/Utils/FPoint.hpp"
18

19
#include "../../Src/Components/FBasicParticleContainer.hpp"
20
#include "../../Src/Components/FBasicCell.hpp"
21

22
#include "../../Src/Utils/FTic.hpp"
berenger-bramas's avatar
berenger-bramas committed
23

24 25
#include "../../Src/Utils/FParameterNames.hpp"

26 27
/**
* In this file we show how to use octree with iteration
berenger-bramas's avatar
berenger-bramas committed
28
* This is a good example to understand FOctree::Iterator.
29
*/
30

31
int main(int argc, char ** argv){
32 33 34 35 36
    FHelpDescribeAndExit(argc, argv,
                         "Show how to iterate on an octree (only the code is interesting)",
                         FParameterDefinitions::NbParticles, FParameterDefinitions::OctreeHeight,
                         FParameterDefinitions::OctreeSubHeight);

37
    typedef double FReal;
38
    typedef FBasicParticleContainer<FReal,0,FReal>     ContainerClass;
39
    typedef FSimpleLeaf<FReal, ContainerClass >                     LeafClass;
40
    typedef FOctree<FReal, FBasicCell, ContainerClass , LeafClass >  OctreeClass;
41 42 43 44 45 46
    ///////////////////////What we do/////////////////////////////
    std::cout << ">> This executable is useless to execute.\n";
    std::cout << ">> It is only interesting to wath the code to understand\n";
    std::cout << ">> how to use octree iterator.\n";
    //////////////////////////////////////////////////////////////

47 48
    const int NbLevels = FParameters::getValue(argc,argv,FParameterDefinitions::OctreeHeight.options, 9);
    const int NbSubLevels = FParameters::getValue(argc,argv,FParameterDefinitions::OctreeSubHeight.options, 3);
49
    const FSize NbPart = FParameters::getValue(argc,argv,FParameterDefinitions::NbParticles.options, FSize(2000000));
50 51

    FTic counterTime;
52

BRAMAS Berenger's avatar
BRAMAS Berenger committed
53
    srand48 ( 1 ); // volontary set seed to constant
54
    // -----------------------------------------------------
55

56
    OctreeClass tree(NbLevels, NbSubLevels, 1.0, FPoint<FReal>(0.5,0.5,0.5));
57

58 59 60 61
    // -----------------------------------------------------
    std::cout << "Creating and inserting " << NbPart << " particles ..." << std::endl;
    counterTime.tic();
    {
62
        FPoint<FReal> particle;
63
        for(long idxPart = 0 ; idxPart < NbPart ; ++idxPart){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
64
            particle.setPosition(FReal(drand48()),FReal(drand48()),FReal(drand48()));
65 66 67 68 69
            tree.insert(particle);
        }
    }
    counterTime.tac();
    std::cout << "Done  " << "(" << counterTime.elapsed() << "s)." << std::endl;
70

71 72
    // -----------------------------------------------------
    {
73
        std::cout << "Itering on Cells ..." << std::endl;
berenger-bramas's avatar
berenger-bramas committed
74
        counterTime.tic();
75 76 77 78 79 80 81 82

        OctreeClass::Iterator octreeIterator(&tree);
        octreeIterator.gotoBottomLeft();
        for(int idxLevel = NbLevels - 1 ; idxLevel >= 1 ; --idxLevel ){
            int counter = 0;
            do{
                ++counter;
                //counter += octreeIterator.getCurrentList()->getSize();
83
            } while(octreeIterator.moveRight());           
84 85 86
            octreeIterator.moveUp();
            octreeIterator.gotoLeft();
            std::cout << "Cells at this level " << counter << " ...\n";
87
        }
berenger-bramas's avatar
berenger-bramas committed
88 89
        counterTime.tac();
        std::cout << "Done  " << "(" << counterTime.elapsed() << "s)." << std::endl;
90 91 92 93 94
    }
    // -----------------------------------------------------
    {
        std::cout << "Itering on particles fast ..." << std::endl;
        counterTime.tic();
95

96 97 98 99 100 101 102 103 104 105
        OctreeClass::Iterator octreeIterator(&tree);
        octreeIterator.gotoBottomLeft();

        OctreeClass::Iterator avoidGoLeft(octreeIterator);

        for(int idx = 0 ; idx < NbLevels - 1; ++idx ){
            do{
            } while(octreeIterator.moveRight());
            avoidGoLeft.moveUp();
            octreeIterator = avoidGoLeft;
106
        }
107 108 109 110
        counterTime.tac();
        std::cout << "Done  " << "(" << counterTime.elapsed() << "s)." << std::endl;
    }
    // -----------------------------------------------------
111

112
    return 0;
113 114 115
}


116