Subversion Repositories public iLand

Rev

Rev 1159 | Rev 1164 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1159 Rev 1162
Line 24... Line 24...
24
24
25
#include "grid.h"
25
#include "grid.h"
26
#include "model.h"
26
#include "model.h"
27
#include "resourceunit.h"
27
#include "resourceunit.h"
28
#include "speciesset.h"
28
#include "speciesset.h"
-
 
29
#include "species.h"
29
30
30
#include "helper.h"
31
#include "helper.h"
31
#include "random.h"
32
#include "random.h"
32
#include "expression.h"
33
#include "expression.h"
33
#include "expressionwrapper.h"
34
#include "expressionwrapper.h"
Line 901... Line 902...
901
           ResourceUnit *ru = GlobalSettings::instance()->model()->ru(stand_grid->grid().cellCenterPoint(offset));
902
           ResourceUnit *ru = GlobalSettings::instance()->model()->ru(stand_grid->grid().cellCenterPoint(offset));
902
           //
903
           //
903
           offset = offset * cPxPerHeight; // index of 10m patch -> to lif pixel coordinates
904
           offset = offset * cPxPerHeight; // index of 10m patch -> to lif pixel coordinates
904
           int in_p = irandom(0, cPxPerHeight*cPxPerHeight-1); // index of lif-pixel
905
           int in_p = irandom(0, cPxPerHeight*cPxPerHeight-1); // index of lif-pixel
905
           offset += QPoint(in_p / cPxPerHeight, in_p % cPxPerHeight);
906
           offset += QPoint(in_p / cPxPerHeight, in_p % cPxPerHeight);
-
 
907
           SaplingCell *sc = GlobalSettings::instance()->model()->saplings()->cell(offset);
-
 
908
           if (sc && sc->max_height()>height) {
906
           if (!ru || ru->saplingHeightForInit(offset) > height) {
909
           //if (!ru || ru->saplingHeightForInit(offset) > height) {
907
               misses++;
910
               misses++;
908
           } else {
911
           } else {
909
               // ok
912
               // ok
910
               hits++;
913
               hits++;
-
 
914
               if (sc)
-
 
915
                   sc->addSapling(height, age, species->index());
911
               ru->resourceUnitSpecies(species).changeSapling().addSapling(offset, height, age);
916
               //ru->resourceUnitSpecies(species).changeSapling().addSapling(offset, height, age);
912
           }
917
           }
913
           if (misses > 3*pxcount) {
918
           if (misses > 3*pxcount) {
914
               qDebug() << "tried to add" << pxcount << "saplings at stand" << stand_id << "but failed in finding enough free positions. Added" << hits << "and stopped.";
919
               qDebug() << "tried to add" << pxcount << "saplings at stand" << stand_id << "but failed in finding enough free positions. Added" << hits << "and stopped.";
915
               break;
920
               break;
916
           }
921
           }
Line 1011... Line 1016...
1011
                height = limit(nrandom(height_from, height_to), 0.05,4.);
1016
                height = limit(nrandom(height_from, height_to), 0.05,4.);
1012
                if (age<=1.)
1017
                if (age<=1.)
1013
                    age = qMax(qRound(height/4. * age4m),1); // assume a linear relationship between height and age
1018
                    age = qMax(qRound(height/4. * age4m),1); // assume a linear relationship between height and age
1014
            }
1019
            }
1015
            QPoint offset = GlobalSettings::instance()->model()->grid()->indexOf(lif_ptrs[rnd_index]);
1020
            QPoint offset = GlobalSettings::instance()->model()->grid()->indexOf(lif_ptrs[rnd_index]);
1016
-
 
-
 
1021
            ResourceUnit *ru;
1017
            ResourceUnit *ru = GlobalSettings::instance()->model()->ru(GlobalSettings::instance()->model()->grid()->cellCenterPoint(offset));
1022
            SaplingCell *sc = GlobalSettings::instance()->model()->saplings()->cell(offset, true, &ru);
1018
            if (ru) {
1023
            if (sc) {
1019
                ru->resourceUnitSpecies(species).changeSapling().addSapling(offset, static_cast<float>(height), static_cast<int>(age));
1024
                if (SaplingTree *st=sc->addSapling(static_cast<float>(height), static_cast<int>(age), species->index()))
1020
                hits += ru->resourceUnitSpecies(species).sapling().representedStemNumber(static_cast<float>(height));
1025
                    hits+=ru->resourceUnitSpecies(st->species_index)->species()->saplingGrowthParameters().representedStemNumberByHeight(st->height);
1021
            } else {
1026
            } else {
1022
                hits++; // avoid an infinite loop
1027
                hits++; // avoid an infinite loop
1023
            }
1028
            }
1024
1029
1025
1030