File: testForest.cpp

package info (click to toggle)
mercator 0.2.5-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,848 kB
  • ctags: 553
  • sloc: sh: 8,328; cpp: 3,512; makefile: 94
file content (67 lines) | stat: -rw-r--r-- 2,330 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// This file may be redistributed and modified only under the terms of
// the GNU General Public License (See COPYING for details).
// Copyright (C) 2004 Alistair Riddoch

#include <Mercator/Forest.h>
#include <Mercator/Plant.h>
#include <Mercator/Area.h>

#include <iostream>

#include <cassert>

typedef WFMath::Point<2> Point2;

int main()
{
    {
        Mercator::Forest forest(4249162ul);

        // Forest is not yet populated
        assert(forest.getPlants().empty());
        forest.populate();
        // Forest has zero area, so even when populated it is empty
        assert(forest.getPlants().empty());

        Mercator::Area* ar = new Mercator::Area(1, false);
        WFMath::Polygon<2> p;
        
        p.addCorner(p.numCorners(), Point2(5, 8));
        p.addCorner(p.numCorners(), Point2(40, -1));
        p.addCorner(p.numCorners(), Point2(45, 16));
        p.addCorner(p.numCorners(), Point2(30, 28));
        p.addCorner(p.numCorners(), Point2(-2, 26));
        p.addCorner(p.numCorners(), Point2(1, 5));
        
        ar->setShape(p);
        forest.setArea(ar);

    //    assert(!forest.getBBox().isValid());
    //    assert(forest.getArea().isValid());
     //   forest.setArea(WFMath::AxisBox<2>(WFMath::Point<2>(-5, -5),
    //                                      WFMath::Point<2>(5, 5)));
 //       assert(forest.getBBox().isValid());
  //      assert(forest.getArea().isValid());

        forest.populate();
        // Forest should now contain some plants
        assert(!forest.getPlants().empty());

        const Mercator::Forest::PlantStore & ps = forest.getPlants();

        Mercator::Forest::PlantStore::const_iterator I = ps.begin();
        for(; I != ps.end(); ++I) {
            Mercator::Forest::PlantColumn::const_iterator J = I->second.begin();
            for(; J != I->second.end(); ++J) {
                const Mercator::Plant & p = J->second;
                std::cout << "Query found plant at [" << I->first
                          << ", " << J->first << "] with height "
                          << p.getHeight();
                std::cout << " displaced to "
                          << (WFMath::Vector<2>(I->first, J->first) +
                              p.getDisplacement())
                          << std::endl << std::flush;
            }
        }
    }
}