#include <rastermap.h>
|
int | CellReplacementNeighbour (int a_x, int a_y, int a_polyref) |
| A method for helping remove tiny polygons. More...
|
|
int | Get (int a_x, int a_y) |
|
char * | GetID (void) |
|
int * | GetMagicP (int a_x, int a_y) |
|
void | Manipulation1 () |
|
int | MapHeight (void) |
|
int | MapWidth (void) |
|
bool | MissingCellReplace (int a_x, int a_y, bool a_fieldsonly) |
| A method for removing missing polygons. More...
|
|
bool | MissingCellReplaceWrap (int a_x, int a_y, bool a_fieldsonly) |
| A method for removing missing polygons - tests for edge conditions. More...
|
|
void | Put (int a_x, int a_y, int a_elem) |
|
| RasterMap (const char *a_mapfile, Landscape *m_landscape) |
|
| ~RasterMap (void) |
|
Definition at line 40 of file rastermap.h.
◆ RasterMap()
RasterMap::RasterMap |
( |
const char * |
a_mapfile, |
|
|
Landscape * |
m_landscape |
|
) |
| |
Definition at line 46 of file rastermap.cpp.
51 IFile = fopen(a_mapfile,
"rb");
57 fread(
m_id, 1, 12, IFile);
59 if (strcmp(
m_id,
"An LSB File") == 0 )
Init1(a_mapfile, a_landscape);
else Init2(a_mapfile, a_landscape);
References cfg_manipulation1_on, g_msg, CfgBool::value(), MapErrorMsg::Warn(), and WARN_FILE.
◆ ~RasterMap()
RasterMap::~RasterMap |
( |
void |
| ) |
|
◆ CellReplacementNeighbour()
int RasterMap::CellReplacementNeighbour |
( |
int |
a_x, |
|
|
int |
a_y, |
|
|
int |
a_polyref |
|
) |
| |
A method for helping remove tiny polygons.
Replaces a cell value with the most common value from the surrounding 8 cells. If near the edge nothing is done. Return value is the new value of the cell or -1 if nothing is done. First tests to make sure that the polygon we are removing is at these coords.
Definition at line 225 of file rastermap.cpp.
233 if ((a_x < 1) || (a_x >
m_width - 2) || (a_y < 1) || (a_y >
m_height - 2))
return -1;
234 int toreplace =
Get(a_x, a_y);
235 if (toreplace != a_polyref)
237 g_msg->
Warn(
"RasterMap::CellReplacementNeighbour: x,y pair does not match polyref ", a_polyref);
240 int surroundingcells[8];
241 surroundingcells[0] =
Get(a_x - 1, a_y - 1);
242 surroundingcells[1] =
Get(a_x , a_y - 1);
243 surroundingcells[2] =
Get(a_x + 1, a_y - 1);
244 surroundingcells[3] =
Get(a_x - 1, a_y);
245 surroundingcells[4] =
Get(a_x + 1, a_y);
246 surroundingcells[5] =
Get(a_x - 1, a_y + 1);
247 surroundingcells[6] =
Get(a_x , a_y + 1);
248 surroundingcells[7] =
Get(a_x + 1, a_y + 1);
251 for (
int i = 0; i < 8; i++)
254 for (
int j = 0; j < 8; j++)
256 if (surroundingcells[j] == surroundingcells[i]) count[i]++;
261 for (
int i = 0; i < 8; i++)
263 if (count[i]>found) index = i;
269 Put(a_x, a_y, surroundingcells[index]);
References g_msg, and MapErrorMsg::Warn().
◆ Get()
int RasterMap::Get |
( |
int |
a_x, |
|
|
int |
a_y |
|
) |
| |
|
inline |
Definition at line 81 of file rastermap.h.
References g_msg, MapErrorMsg::Warn(), WARN_BUG, and MapErrorMsg::WarnAddInfo().
Referenced by Landscape::GetActualGooseGrazingForage(), Landscape::IncOsmiaNest(), Landscape::ReleaseOsmiaNest(), Landscape::SupplyBirdMaizeForage(), Landscape::SupplyBirdSeedForage(), Landscape::SupplyCentroidX(), Landscape::SupplyCentroidY(), Landscape::SupplyCountryDesig(), Landscape::SupplyDeadBiomass(), Landscape::SupplyElementSubType(), Landscape::SupplyElementType(), Landscape::SupplyElementTypeCC(), Landscape::SupplyFarmOwner(), Landscape::SupplyFarmOwnerIndex(), Landscape::SupplyFarmType(), Landscape::SupplyGrazingPressure(), Landscape::SupplyGreenBiomass(), Landscape::SupplyHasTramlines(), Landscape::SupplyInsects(), Landscape::SupplyJustSprayed(), Landscape::SupplyLAGreen(), Landscape::SupplyLastSownVeg(), Landscape::SupplyLastTreatment(), Landscape::SupplyLATotal(), Landscape::SupplyLEHigh(), Landscape::SupplyNectar(), Landscape::SupplyOpenness(), Landscape::SupplyOptFarmType(), Landscape::SupplyOsmiaNest(), Landscape::SupplyPollen(), Landscape::SupplyPolyRef(), Landscape::SupplyPolyRefCC(), Landscape::SupplyPolyRefIndex(), Landscape::SupplySoilType(), Landscape::SupplySoilTypeR(), Landscape::SupplyTotalNectar(), Landscape::SupplyTotalPollen(), Landscape::SupplyTrafficLoad(), Landscape::SupplyVegAge(), Landscape::SupplyVegBiomass(), Landscape::SupplyVegCover(), Landscape::SupplyVegDensity(), Landscape::SupplyVegDigestability(), Landscape::SupplyVegHeight(), Landscape::SupplyVegPatchy(), Landscape::SupplyVegType(), Landscape::SupplyWeedBiomass(), and Pesticide::TwinMapSpray().
◆ GetID()
char* RasterMap::GetID |
( |
void |
| ) |
|
|
inline |
◆ GetMagicP()
int * RasterMap::GetMagicP |
( |
int |
a_x, |
|
|
int |
a_y |
|
) |
| |
|
inline |
◆ Init1()
void RasterMap::Init1 |
( |
const char * |
a_mapfile, |
|
|
Landscape * |
m_landscape |
|
) |
| |
|
protected |
Definition at line 66 of file rastermap.cpp.
73 IFile = fopen(a_mapfile,
"rb");
79 fread(
m_id, 1, 12, IFile);
80 fread(&
m_width, 1,
sizeof(
int), IFile);
86 "RasterMap::RasterMap(): Out of memory.",
"");
93 for (
int x = 0; x <
m_x; x++) {
94 for (
int y = 0; y <
m_y; y++) {
102 sprintf(error_num,
"%d",
Get(x, y));
103 g_msg->
Warn(
WARN_FILE,
"RasterMap::RasterMap(): Unknown polygon map number (could be a hole):", error_num);
115 sprintf(error_num,
"%d",
Get(x, y));
116 g_msg->
Warn(
WARN_FILE,
"RasterMap::RasterMap():" " Unknown polygon ref number:", error_num);
References cfg_rectangularmaps_on, g_msg, CfgBool::value(), MapErrorMsg::Warn(), WARN_FATAL, and WARN_FILE.
◆ Init2()
void RasterMap::Init2 |
( |
const char * |
a_mapfile, |
|
|
Landscape * |
m_landscape |
|
) |
| |
|
protected |
Definition at line 124 of file rastermap.cpp.
129 ifstream IFile(a_mapfile, ios::binary);
130 if (!IFile.is_open()) {
136 IFile.read((
char*)&
m_width,
sizeof (
int));
137 IFile.read((
char*)&
m_height,
sizeof (
int));
141 "RasterMap::RasterMap(): Out of memory.",
"");
149 int lastref = 99999999;
150 for (
int x = 0; x<
m_x; x++)
152 for (
int y = 0; y<
m_y; y++)
157 if (lastref>=0)
Put(x, y, lastref);
159 sprintf(error_num,
"%d",
Get(x, y));
160 g_msg->
Warn(
WARN_FILE,
"RasterMap::RasterMap(): Unknown polygon map number (could be a hole):", error_num);
171 sprintf(error_num,
"%d",
Get(x, y));
172 g_msg->
Warn(
WARN_FILE,
"RasterMap::RasterMap():" " Unknown polygon ref number:", error_num);
References g_msg, MapErrorMsg::Warn(), WARN_FATAL, WARN_FILE, and MapErrorMsg::WarnAddInfo().
◆ Manipulation1()
void RasterMap::Manipulation1 |
( |
| ) |
|
Definition at line 185 of file rastermap.cpp.
189 o1=fopen(
"RasterDump1.lsb",
"wb");
190 o2=fopen(
"RasterDump2.lsb",
"wb");
193 fwrite( l_id, 1, 12, o1 );
194 fwrite( & new_height, 1,
sizeof(
int ), o1 );
195 for (
int y=0; y<
m_width; y++ ) {
196 for (
int x = 0; x <
m_width ; x++ ) {
197 int l_poly =
Get(x,y);
198 fwrite( & l_poly, 1,
sizeof(
int ), o1 );
199 fwrite( & l_poly, 1,
sizeof(
int ), o1 );
201 for (
int x = 0; x <
m_width ; x++ ) {
202 int l_poly =
Get(x,y);
203 fwrite( & l_poly, 1,
sizeof(
int ), o1 );
204 fwrite( & l_poly, 1,
sizeof(
int ), o1 );
209 fwrite( l_id, 1, 12, o2 );
210 fwrite( &new_height, 1,
sizeof(
int ), o2 );
211 for (
int m=0; m<multiply; m++) {
212 for (
int y=0; y<
m_width; y++ ) {
213 for (
int mm=0; mm<multiply; mm++) {
214 for (
int x = 0; x <
m_width ; x++ ) {
215 int l_poly =
Get(x,y);
216 fwrite( & l_poly, 1,
sizeof(
int ), o2 );
References cfg_rastermapmanipmultiply, and CfgInt::value().
◆ MapHeight()
int RasterMap::MapHeight |
( |
void |
| ) |
|
|
inline |
◆ MapWidth()
int RasterMap::MapWidth |
( |
void |
| ) |
|
|
inline |
◆ MissingCellReplace()
bool RasterMap::MissingCellReplace |
( |
int |
a_x, |
|
|
int |
a_y, |
|
|
bool |
a_fieldsonly |
|
) |
| |
A method for removing missing polygons.
Definition at line 273 of file rastermap.cpp.
275 int surroundingcells[8];
276 surroundingcells[0] =
Get(a_x - 1, a_y - 1);
277 surroundingcells[1] =
Get(a_x, a_y - 1);
278 surroundingcells[2] =
Get(a_x + 1, a_y - 1);
279 surroundingcells[3] =
Get(a_x - 1, a_y);
280 surroundingcells[4] =
Get(a_x + 1, a_y);
281 surroundingcells[5] =
Get(a_x - 1, a_y + 1);
282 surroundingcells[6] =
Get(a_x, a_y + 1);
283 surroundingcells[7] =
Get(a_x + 1, a_y + 1);
287 unsigned offset = (unsigned)(((
double)rand() / RAND_MAX + 1) * 8);
288 for (
unsigned i = 0; i < 8; i++)
293 Put(a_x, a_y, surroundingcells[(i + offset) % 8]);
◆ MissingCellReplaceWrap()
bool RasterMap::MissingCellReplaceWrap |
( |
int |
a_x, |
|
|
int |
a_y, |
|
|
bool |
a_fieldsonly |
|
) |
| |
A method for removing missing polygons - tests for edge conditions.
Definition at line 302 of file rastermap.cpp.
304 int surroundingcells[8];
305 if (a_x >= 1 && a_y >= 1) surroundingcells[0] =
Get(a_x - 1, a_y - 1);
else surroundingcells[0] =
Get(a_x, a_y);
306 if (a_y >= 1) surroundingcells[1] =
Get(a_x, a_y - 1);
else surroundingcells[1] =
Get(a_x, a_y);
307 if (a_x < m_width-1 && a_y >= 1) surroundingcells[2] =
Get(a_x + 1, a_y - 1);
else surroundingcells[2] =
Get(a_x, a_y);
308 if (a_x >= 1) surroundingcells[3] =
Get(a_x - 1, a_y);
else surroundingcells[3] =
Get(a_x, a_y);
309 if (a_x <
m_width-1) surroundingcells[4] =
Get(a_x + 1, a_y);
else surroundingcells[4] =
Get(a_x, a_y);
310 if (a_x >= 1 && a_y <
m_height-1) surroundingcells[5] =
Get(a_x - 1, a_y + 1);
else surroundingcells[5] =
Get(a_x, a_y);
311 if (a_y <
m_height-1) surroundingcells[6] =
Get(a_x, a_y + 1);
else surroundingcells[6] =
Get(a_x, a_y);
312 if (a_x <
m_width-1 && a_y <
m_height-1) surroundingcells[7] =
Get(a_x + 1, a_y + 1);
else surroundingcells[7] =
Get(a_x, a_y);
316 unsigned offset = (unsigned)(((
double)rand() / RAND_MAX + 1) * 8);
317 for (
unsigned i = 0; i < 8; i++)
324 Put(a_x, a_y, surroundingcells[(i + offset) % 8]);
References tole_Field, tole_Orchard, tole_PermanentSetaside, tole_PermPasture, tole_PermPastureLowYield, tole_PermPastureTussocky, tole_PermPastureTussockyWet, and tole_Vildtager.
◆ Put()
void RasterMap::Put |
( |
int |
a_x, |
|
|
int |
a_y, |
|
|
int |
a_elem |
|
) |
| |
|
inline |
◆ m_height
◆ m_id
◆ m_landscape
◆ m_map
◆ m_width
◆ m_x
◆ m_y
The documentation for this class was generated from the following files: