Rev 1162 | Rev 1182 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1162 | Rev 1164 | ||
---|---|---|---|
Line 895... | Line 895... | ||
895 | age = iage==-1?1:init.value(row,iage).toDouble(); |
895 | age = iage==-1?1:init.value(row,iage).toDouble(); |
896 | 896 | ||
897 | int misses = 0; |
897 | int misses = 0; |
898 | int hits = 0; |
898 | int hits = 0; |
899 | while (hits < pxcount) { |
899 | while (hits < pxcount) { |
900 | int rnd_index = irandom(0, indices.count()-1); |
- | |
- | 900 | int rnd_index = irandom(0, indices.count()); |
|
901 | QPoint offset=stand_grid->grid().indexOf(indices[rnd_index]); |
901 | QPoint offset=stand_grid->grid().indexOf(indices[rnd_index]); |
902 | ResourceUnit *ru = GlobalSettings::instance()->model()->ru(stand_grid->grid().cellCenterPoint(offset)); |
902 | ResourceUnit *ru = GlobalSettings::instance()->model()->ru(stand_grid->grid().cellCenterPoint(offset)); |
903 | //
|
903 | //
|
904 | offset = offset * cPxPerHeight; // index of 10m patch -> to lif pixel coordinates |
904 | offset = offset * cPxPerHeight; // index of 10m patch -> to lif pixel coordinates |
905 | int in_p = irandom(0, cPxPerHeight*cPxPerHeight-1); // index of lif-pixel |
- | |
- | 905 | int in_p = irandom(0, cPxPerHeight*cPxPerHeight); // index of lif-pixel |
|
906 | 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); |
907 | SaplingCell *sc = GlobalSettings::instance()->model()->saplings()->cell(offset); |
908 | if (sc && sc->max_height()>height) { |
908 | if (sc && sc->max_height()>height) { |
909 | //if (!ru || ru->saplingHeightForInit(offset) > height) {
|
909 | //if (!ru || ru->saplingHeightForInit(offset) > height) {
|
910 | misses++; |
910 | misses++; |
Line 1009... | Line 1009... | ||
1009 | 1009 | ||
1010 | 1010 | ||
1011 | 1011 | ||
1012 | double hits = 0.; |
1012 | double hits = 0.; |
1013 | while (hits < pxcount) { |
1013 | while (hits < pxcount) { |
1014 | int rnd_index = irandom(0, min_lif_index-1); |
- | |
- | 1014 | int rnd_index = irandom(0, min_lif_index); |
|
1015 | if (iheightfrom!=-1) { |
1015 | if (iheightfrom!=-1) { |
1016 | height = limit(nrandom(height_from, height_to), 0.05,4.); |
1016 | height = limit(nrandom(height_from, height_to), 0.05,4.); |
1017 | if (age<=1.) |
1017 | if (age<=1.) |
1018 | 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 |
1019 | }
|
1019 | }
|
1020 | QPoint offset = GlobalSettings::instance()->model()->grid()->indexOf(lif_ptrs[rnd_index]); |
1020 | QPoint offset = GlobalSettings::instance()->model()->grid()->indexOf(lif_ptrs[rnd_index]); |
1021 | ResourceUnit *ru; |
1021 | ResourceUnit *ru; |
1022 | SaplingCell *sc = GlobalSettings::instance()->model()->saplings()->cell(offset, true, &ru); |
1022 | SaplingCell *sc = GlobalSettings::instance()->model()->saplings()->cell(offset, true, &ru); |
1023 | if (sc) { |
1023 | if (sc) { |
1024 | if (SaplingTree *st=sc->addSapling(static_cast<float>(height), static_cast<int>(age), species->index())) |
1024 | if (SaplingTree *st=sc->addSapling(static_cast<float>(height), static_cast<int>(age), species->index())) |
1025 | hits+=ru->resourceUnitSpecies(st->species_index)->species()->saplingGrowthParameters().representedStemNumberByHeight(st->height); |
- | |
- | 1025 | hits+=std::max(1., ru->resourceUnitSpecies(st->species_index)->species()->saplingGrowthParameters().representedStemNumberByHeight(st->height)); |
|
- | 1026 | else
|
|
- | 1027 | hits++; |
|
1026 | } else { |
1028 | } else { |
1027 | hits++; // avoid an infinite loop |
1029 | hits++; // avoid an infinite loop |
1028 | }
|
1030 | }
|
1029 | 1031 | ||
1030 | 1032 |