Rev 1160 | Rev 1164 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1160 | Rev 1162 | ||
---|---|---|---|
Line 174... | Line 174... | ||
174 | (*i)->saplingStat().calculate((*i)->species(), const_cast<ResourceUnit*>(ru)); |
174 | (*i)->saplingStat().calculate((*i)->species(), const_cast<ResourceUnit*>(ru)); |
175 | (*i)->statistics().add(&((*i)->saplingStat())); |
175 | (*i)->statistics().add(&((*i)->saplingStat())); |
176 | }
|
176 | }
|
177 | }
|
177 | }
|
178 | 178 | ||
179 | SaplingCell *Saplings::cell(QPoint lif_coords, bool only_valid) |
- | |
- | 179 | SaplingCell *Saplings::cell(QPoint lif_coords, bool only_valid, ResourceUnit **rRUPtr) |
|
180 | {
|
180 | {
|
181 | FloatGrid *lif_grid = GlobalSettings::instance()->model()->grid(); |
181 | FloatGrid *lif_grid = GlobalSettings::instance()->model()->grid(); |
182 | 182 | ||
183 | // in this case, getting the actual cell is quite cumbersome: first, retrieve the resource unit, then the
|
183 | // in this case, getting the actual cell is quite cumbersome: first, retrieve the resource unit, then the
|
184 | // cell based on the offset of the given coordiantes relative to the corner of the resource unit.
|
184 | // cell based on the offset of the given coordiantes relative to the corner of the resource unit.
|
185 | ResourceUnit *ru = GlobalSettings::instance()->model()->ru(lif_grid->cellCenterPoint(lif_coords)); |
185 | ResourceUnit *ru = GlobalSettings::instance()->model()->ru(lif_grid->cellCenterPoint(lif_coords)); |
- | 186 | if (rRUPtr) |
|
- | 187 | *rRUPtr = ru; |
|
186 | 188 | ||
187 | if (ru) { |
189 | if (ru) { |
188 | QPoint local_coords = lif_coords - ru->cornerPointOffset(); |
190 | QPoint local_coords = lif_coords - ru->cornerPointOffset(); |
189 | int idx = local_coords.y() * cPxPerRU + local_coords.x(); |
191 | int idx = local_coords.y() * cPxPerRU + local_coords.x(); |
190 | DBGMODE( if (idx<0 || idx>=cPxPerHectare) |
192 | DBGMODE( if (idx<0 || idx>=cPxPerHectare) |
Line 193... | Line 195... | ||
193 | SaplingCell *s=&ru->saplingCellArray()[idx]; |
195 | SaplingCell *s=&ru->saplingCellArray()[idx]; |
194 | if (s && (!only_valid || s->state!=SaplingCell::CellInvalid)) |
196 | if (s && (!only_valid || s->state!=SaplingCell::CellInvalid)) |
195 | return s; |
197 | return s; |
196 | }
|
198 | }
|
197 | return 0; |
199 | return 0; |
- | 200 | }
|
|
- | 201 | ||
- | 202 | void Saplings::clearSaplings(const QRectF &rectangle, const bool remove_biomass) |
|
- | 203 | {
|
|
- | 204 | GridRunner<float> runner(GlobalSettings::instance()->model()->grid(), rectangle); |
|
- | 205 | ResourceUnit *ru; |
|
- | 206 | while (runner.next()) { |
|
- | 207 | SaplingCell *s = cell(runner.currentIndex(), true, &ru); |
|
- | 208 | if (s) { |
|
- | 209 | ||
- | 210 | for (int i=0;i<NSAPCELLS;++i) |
|
- | 211 | if (s->saplings[i].is_occupied()) { |
|
- | 212 | if (remove_biomass) { |
|
- | 213 | ResourceUnitSpecies *rus = ru->resourceUnitSpecies(s->saplings[i].species_index); |
|
- | 214 | if (!rus && !rus->species()) { |
|
- | 215 | qDebug() << "Saplings::clearSaplings(): invalid resource unit!!!"; |
|
- | 216 | return; |
|
- | 217 | }
|
|
- | 218 | rus->saplingStat().addCarbonOfDeadSapling( s->saplings[i].height / rus->species()->saplingGrowthParameters().hdSapling * 100.f ); |
|
- | 219 | }
|
|
- | 220 | s->saplings[i].clear(); |
|
- | 221 | }
|
|
- | 222 | s->checkState(); |
|
- | 223 | ||
- | 224 | }
|
|
- | 225 | }
|
|
198 | }
|
226 | }
|
199 | 227 | ||
200 | void Saplings::updateBrowsingPressure() |
228 | void Saplings::updateBrowsingPressure() |
201 | {
|
229 | {
|
202 | if (GlobalSettings::instance()->settings().valueBool("model.settings.browsing.enabled")) |
230 | if (GlobalSettings::instance()->settings().valueBool("model.settings.browsing.enabled")) |
Line 406... | Line 434... | ||
406 | 434 | ||
407 | 435 | ||
408 | GlobalSettings::instance()->systemStatistics()->saplingCount+=mLiving; |
436 | GlobalSettings::instance()->systemStatistics()->saplingCount+=mLiving; |
409 | GlobalSettings::instance()->systemStatistics()->newSaplings+=mAdded; |
437 | GlobalSettings::instance()->systemStatistics()->newSaplings+=mAdded; |
410 | 438 | ||
- | 439 | }
|
|
- | 440 | ||
- | 441 | double SaplingStat::livingStemNumber(const Species *species, double &rAvgDbh, double &rAvgHeight, double &rAvgAge) const |
|
- | 442 | {
|
|
- | 443 | rAvgHeight = averageHeight(); |
|
- | 444 | rAvgDbh = rAvgHeight / species->saplingGrowthParameters().hdSapling * 100.f; |
|
- | 445 | rAvgAge = averageAge(); |
|
- | 446 | double n= species->saplingGrowthParameters().representedStemNumber(rAvgDbh); |
|
- | 447 | return n; |
|
- | 448 | // *** old code (sapling.cpp) ***
|
|
- | 449 | // double total = 0.;
|
|
- | 450 | // double dbh_sum = 0.;
|
|
- | 451 | // double h_sum = 0.;
|
|
- | 452 | // double age_sum = 0.;
|
|
- | 453 | // const SaplingGrowthParameters &p = mRUS->species()->saplingGrowthParameters();
|
|
- | 454 | // for (QVector<SaplingTreeOld>::const_iterator it = mSaplingTrees.constBegin(); it!=mSaplingTrees.constEnd(); ++it) {
|
|
- | 455 | // float dbh = it->height / p.hdSapling * 100.f;
|
|
- | 456 | // if (dbh<1.) // minimum size: 1cm
|
|
- | 457 | // continue;
|
|
- | 458 | // double n = p.representedStemNumber(dbh); // one cohort on the pixel represents that number of trees
|
|
- | 459 | // dbh_sum += n*dbh;
|
|
- | 460 | // h_sum += n*it->height;
|
|
- | 461 | // age_sum += n*it->age.age;
|
|
- | 462 | // total += n;
|
|
- | 463 | // }
|
|
- | 464 | // if (total>0.) {
|
|
- | 465 | // dbh_sum /= total;
|
|
- | 466 | // h_sum /= total;
|
|
- | 467 | // age_sum /= total;
|
|
- | 468 | // }
|
|
- | 469 | // rAvgDbh = dbh_sum;
|
|
- | 470 | // rAvgHeight = h_sum;
|
|
- | 471 | // rAvgAge = age_sum;
|
|
- | 472 | // return total;
|
|
411 | }
|
473 | }
|