Rev 1055 | Rev 1083 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1055 | Rev 1081 | ||
---|---|---|---|
Line 21... | Line 21... | ||
21 | #include "barkbeetlescript.h"
|
21 | #include "barkbeetlescript.h"
|
22 | 22 | ||
23 | #include "barkbeetlemodule.h"
|
23 | #include "barkbeetlemodule.h"
|
24 | #include "outputmanager.h"
|
24 | #include "outputmanager.h"
|
25 | #include "helper.h"
|
25 | #include "helper.h"
|
- | 26 | #include "spatialanalysis.h"
|
|
- | 27 | #include "scriptgrid.h"
|
|
26 | 28 | ||
27 | 29 | ||
28 | BarkBeetleScript::BarkBeetleScript(QObject *) |
30 | BarkBeetleScript::BarkBeetleScript(QObject *) |
29 | {
|
31 | {
|
30 | mBeetle = 0; |
32 | mBeetle = 0; |
Line 135... | Line 137... | ||
135 | qDebug() << "saved grid to " << filename; |
137 | qDebug() << "saved grid to " << filename; |
136 | return true; |
138 | return true; |
137 | }
|
139 | }
|
138 | qDebug() << "could not save gridToFile because" << type << "is not a valid grid."; |
140 | qDebug() << "could not save gridToFile because" << type << "is not a valid grid."; |
139 | return false; |
141 | return false; |
- | 142 | ||
- | 143 | }
|
|
- | 144 | ||
- | 145 | QJSValue BarkBeetleScript::grid(QString type) |
|
- | 146 | {
|
|
- | 147 | int idx = mBeetle->mLayers.indexOf(type); |
|
- | 148 | if (idx<0) |
|
- | 149 | qDebug() << "ERROR: BarkBeetleScript:grid(): invalid grid" << type; |
|
- | 150 | // this is a copy
|
|
- | 151 | Grid<double> *damage_grid = mBeetle->mLayers.grid(idx); |
|
- | 152 | ||
- | 153 | QJSValue g = ScriptGrid::createGrid(damage_grid, type); |
|
- | 154 | return g; |
|
- | 155 | }
|
|
- | 156 | ||
- | 157 | int BarkBeetleScript::damagedArea(int threshold, QString fileName) |
|
- | 158 | {
|
|
- | 159 | // get damage grid:
|
|
- | 160 | Grid<double> *damage_grid = mBeetle->mLayers.grid(mBeetle->mLayers.indexOf("dead")); |
|
- | 161 | SpatialAnalysis spat;
|
|
- | 162 | QVector<int> patches = spat.extractPatches(*damage_grid, fileName); |
|
- | 163 | int n=0, size=0; |
|
- | 164 | for (int i=0;i<patches.count();++i) |
|
- | 165 | if (patches[i]>threshold) { |
|
- | 166 | size+=patches[i]; |
|
- | 167 | n++; |
|
- | 168 | }
|
|
- | 169 | qDebug() << "BarkBeetleScript:damagedArea:" << n << "patches (area=" << size << ") above threshold" << threshold; |
|
- | 170 | delete damage_grid; |
|
- | 171 | return size; |
|
140 | 172 | ||
141 | }
|
173 | }
|
142 | 174 | ||
143 | bool BarkBeetleScript::simulate() |
175 | bool BarkBeetleScript::simulate() |
144 | {
|
176 | {
|