File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/extensions/ams.js
ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Rastermap.h
Go to the documentation of this file.
1 //
2 // rastermap.h
3 //
4 /*
5 *******************************************************************************************************
6 Copyright (c) 2011, Christopher John Topping, Aarhus University
7 All rights reserved.
8 
9 Redistribution and use in source and binary forms, with or without modification, are permitted provided
10 that the following conditions are met:
11 
12 Redistributions of source code must retain the above copyright notice, this list of conditions and the
13 following disclaimer.
14 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
15 the following disclaimer in the documentation and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
20 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 ********************************************************************************************************
26 */
27 
28 #ifndef RASTERMAP_H
29 #define RASTERMAP_H
30 
31 #include <cstdlib>
32 using namespace std;
33 
34 class Landscape;
35 
36 // #define to enable range checking of map coordinates.
37 //#define RASTERMAP_XY_RANGE
38 // Currently unused.
39 
40 class RasterMap
41 {
43  char m_id[12];
45  int *m_map;
47  int m_width;
49  int m_height;
52 
53 public:
54  // We want to force these to be inline functions.
55  int MapWidth( void ) { return m_width; }
56  int MapHeight( void ) { return m_height; }
57  int Get( int a_x, int a_y );
58  char* GetID( void ) { return m_id; }
59  int* GetMagicP( int a_x, int a_y );
60  void Put( int a_x, int a_y, int a_elem ) { m_map[ a_y * m_width + a_x ] = a_elem; }
61  RasterMap(const char* a_mapfile, Landscape * m_landscape);
62  ~RasterMap( void );
64  int CellReplacementNeighbour(int a_x, int a_y, int a_polyref);
66  bool MissingCellReplace(int a_x, int a_y, bool a_fieldsonly);
68  bool MissingCellReplaceWrap(int a_x, int a_y, bool a_fieldsonly);
69 protected:
70  void Init(const char* a_mapfile, Landscape * m_landscape);
71 };
72 
73 
74 
75 inline int* RasterMap::GetMagicP( int a_x, int a_y )
76 {
77  return &m_map[ a_y * m_width + a_x ];
78 }
79 
80 
81 
82 inline int RasterMap::Get( int a_x, int a_y ) {
83 #ifndef DNDEBUG
84  if (a_x<0 || a_x>=m_width ||
85  a_y<0 || a_y>=m_height ) {
86  g_msg->Warn( WARN_BUG, "RasterMap::Get(): Coordinates out of range!", "" );
87  g_msg->WarnAddInfo(WARN_BUG, "X Coord ", a_x);
88  g_msg->WarnAddInfo(WARN_BUG, "Y Coord ", a_y);
89  g_msg->WarnAddInfo(WARN_BUG, "X max ", m_width);
90  g_msg->WarnAddInfo(WARN_BUG, "Y max ", m_height);
91  exit(1);
92  }
93 #endif
94  return m_map[ a_y * m_width + a_x ];
95 }
96 
97 #endif // RASTERMAP_H
98 
99 
100 
RasterMap::GetID
char * GetID(void)
Definition: Rastermap.h:58
WARN_FILE
Definition: MapErrorMsg.h:37
RasterMap::m_landscape
Landscape * m_landscape
A pointer to the parent landscape class.
Definition: Rastermap.h:51
RasterMap::MapHeight
int MapHeight(void)
Definition: Rastermap.h:56
MapErrorMsg::WarnAddInfo
void WarnAddInfo(MapErrorState a_level, std::string a_add1, std::string a_add2)
Definition: MapErrorMsg.cpp:160
RasterMap::Get
int Get(int a_x, int a_y)
Definition: Rastermap.h:82
tole_PermPastureTussockyWet
Definition: LandscapeFarmingEnums.h:122
WARN_FATAL
Definition: MapErrorMsg.h:35
RasterMap::~RasterMap
~RasterMap(void)
Definition: Rastermap.cpp:147
RasterMap::Put
void Put(int a_x, int a_y, int a_elem)
Definition: Rastermap.h:60
tole_PermanentSetaside
Definition: LandscapeFarmingEnums.h:68
RasterMap::GetMagicP
int * GetMagicP(int a_x, int a_y)
Definition: Rastermap.h:75
Configurator.h
TTypesOfLandscapeElement
TTypesOfLandscapeElement
Values that represent the types of landscape polygon that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:57
Landscape
The landscape class containing all environmental and topographical data.
Definition: Landscape.h:142
RasterMap::m_height
int m_height
The height of the landscape.
Definition: Rastermap.h:49
tole_PermPastureLowYield
Definition: LandscapeFarmingEnums.h:66
RasterMap::m_map
int * m_map
The raster of the landscape.
Definition: Rastermap.h:45
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
RasterMap::MissingCellReplace
bool MissingCellReplace(int a_x, int a_y, bool a_fieldsonly)
A method for removing missing polygons.
Definition: Rastermap.cpp:201
tole_PermPastureTussocky
Definition: LandscapeFarmingEnums.h:67
RasterMap::m_width
int m_width
The width of the landscape.
Definition: Rastermap.h:47
RasterMap::Init
void Init(const char *a_mapfile, Landscape *m_landscape)
Definition: Rastermap.cpp:58
MapErrorMsg.h
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
tole_Orchard
Definition: LandscapeFarmingEnums.h:93
RasterMap::MissingCellReplaceWrap
bool MissingCellReplaceWrap(int a_x, int a_y, bool a_fieldsonly)
A method for removing missing polygons - tests for edge conditions.
Definition: Rastermap.cpp:230
tole_Field
Definition: LandscapeFarmingEnums.h:65
RasterMap::CellReplacementNeighbour
int CellReplacementNeighbour(int a_x, int a_y, int a_polyref)
A method for helping remove tiny polygons.
Definition: Rastermap.cpp:153
tole_Vildtager
Definition: LandscapeFarmingEnums.h:121
Rastermap.h
g_random_fnc
int g_random_fnc(const int a_range)
Definition: ALMaSS_Random.cpp:74
RasterMap
Definition: Rastermap.h:40
RasterMap::MapWidth
int MapWidth(void)
Definition: Rastermap.h:55
RasterMap::RasterMap
RasterMap(const char *a_mapfile, Landscape *m_landscape)
Definition: Rastermap.cpp:42
count
Definition: SubPopulation.h:48
WARN_BUG
Definition: MapErrorMsg.h:34
tole_PermPasture
Definition: LandscapeFarmingEnums.h:69