ALMaSS Rabbit ODdox  1.00
The rabbit model description following ODdox protocol
rastermap.h
Go to the documentation of this file.
1 //
2 // rastermap.h
3 //
4 /*
5 *******************************************************************************************************
6 Copyright (c) 2011, Christopher John Topping, University of Aarhus
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 
33 using namespace std;
34 
35 // m_polymapping is a mapping from polygon numbers into
36 // the list of landscape elements, m_elems. When using this it is important that it is the poly num and not the
37 // map index that is used.
38 extern int *m_polymapping;
39 class Landscape;
40 
41 // #define to enable range checking of map coordinates.
42 //#define RASTERMAP_XY_RANGE
43 // Currently unused.
44 
45 class RasterMap
46 {
47  char m_id[12];
48  int *m_map;
49  int m_width;
50  int m_height;
51  int m_x;
52  int m_y;
54 
55 public:
56  // We want to force these to be inline functions.
57  int MapWidth( void ) { return m_width; }
58  int MapHeight( void ) { return m_height; }
59  int Get( int a_x, int a_y );
60  char* GetID( void ) { return m_id; }
61  int* GetMagicP( int a_x, int a_y );
62  void Put( int a_x, int a_y, int a_elem ) { m_map[ a_y * m_width + a_x ] = a_elem; }
63  RasterMap(const char* a_mapfile, Landscape * m_landscape);
64  ~RasterMap( void );
65  void Manipulation1();
67  int CellReplacementNeighbour(int a_x, int a_y, int a_polyref);
69  bool MissingCellReplace(int a_x, int a_y, bool a_fieldsonly);
71  bool MissingCellReplaceWrap(int a_x, int a_y, bool a_fieldsonly);
72 protected:
73  void Init1(const char* a_mapfile, Landscape * m_landscape);
74  void Init2(const char* a_mapfile, Landscape * m_landscape);
75 };
76 
77 
78 
79 inline int* RasterMap::GetMagicP( int a_x, int a_y )
80 {
81  return &m_map[ a_y * m_width + a_x ];
82 }
83 
84 
85 
86 inline int RasterMap::Get( int a_x, int a_y ) {
87  if (a_x<0 || a_x>=m_width ||
88  a_y<0 || a_y>=m_height ) {
90  "RasterMap::Get(): Coordinates out of range!", "" );
91  exit(1);
92  }
93  return m_map[ a_y * m_width + a_x ];
94 }
95 
96 #endif // RASTERMAP_H
97 
98 
99 
The landscape class containing all environmental and topographical data.
Definition: landscape.h:109
int MapWidth(void)
Definition: rastermap.h:57
Landscape * m_landscape
Definition: rastermap.h:53
int * m_polymapping
m_polymapping is a mapping from polygon numbers into the list of landscape elements, m_elems. When using this it is important that it is the poly num and not the map index that is used in calling.
Definition: Landscape.cpp:237
void Put(int a_x, int a_y, int a_elem)
Definition: rastermap.h:62
int MapHeight(void)
Definition: rastermap.h:58
char * GetID(void)
Definition: rastermap.h:60
int m_x
Definition: rastermap.h:51
int Get(int a_x, int a_y)
Definition: rastermap.h:86
int * GetMagicP(int a_x, int a_y)
Definition: rastermap.h:79
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
int m_y
Definition: rastermap.h:52
int m_height
Definition: rastermap.h:50
int * m_map
Definition: rastermap.h:48
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
int m_width
Definition: rastermap.h:49