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
BinaryMapBase Class Reference

#include <BinaryMapBase.h>

Inheritance diagram for BinaryMapBase:
TrapLineMap

Public Member Functions

 BinaryMapBase (unsigned int a_width, unsigned int a_height, unsigned int a_resolution, unsigned int a_noValues)
 
 ~BinaryMapBase ()
 
uint64 GetValue (unsigned a_x, unsigned a_y)
 
void SetValue (unsigned a_x, unsigned a_y, unsigned a_value)
 
void ClearValue (unsigned a_x, unsigned a_y)
 
void ClearMap ()
 

Protected Attributes

uint64m_map
 
unsigned int m_height
 
unsigned int m_width
 
unsigned int m_colourRes
 
unsigned int m_colourScaler
 
unsigned int m_resolution
 
unsigned int m_resolutionscaler
 
unsigned int m_maskbits
 
unsigned int m_maplength
 
uint64 m_mask
 

Constructor & Destructor Documentation

◆ BinaryMapBase()

BinaryMapBase::BinaryMapBase ( unsigned int  a_width,
unsigned int  a_height,
unsigned int  a_resolution,
unsigned int  a_noValues 
)
31 {
32  // Assign member variables
33  m_width = a_width;
34  m_height = a_height;
35  m_colourRes = a_noValues;
36  m_resolution = a_resolution;
37  // 2 = 1, 4 = 2, 8 = 3 etc..
39  unsigned int n=m_resolution;
40  do {
41  n = n >> 1;
43  } while (n>0);
45  m_colourScaler = 0;
46  n=m_colourRes;
47  do {
48  n = n >> 1;
50  } while (n>0);
52 
53  // The total number of 64bit integers needed is height x width / 64 (rounded up);
54  // But we need to take the resolution into account too - hence:
55  // ( (height x width)/(resolution*resolution) ) / 64, then add one in case there is a fractional part
56  // Then we also need to have the size of the colour resolution calculated in here.
57  m_maplength = ( ( ( m_width * m_height * m_colourScaler ) / ( m_resolution * m_resolution )) / 64 ) + 1;
58  // Need to adjust m_width & m_height to match resolution
61  m_map = new uint64[m_maplength];
62 
63  // create the mask
64  m_mask = m_colourRes-1;
66  ClearMap();
67 }

References ClearMap(), m_colourRes, m_colourScaler, m_height, m_map, m_maplength, m_mask, m_maskbits, m_resolution, m_resolutionscaler, and m_width.

◆ ~BinaryMapBase()

BinaryMapBase::~BinaryMapBase ( )
70 {
71  ;
72 }

Member Function Documentation

◆ ClearMap()

void BinaryMapBase::ClearMap ( )
75 {
76  for (unsigned int i = 0; i < m_maplength; i++) m_map[i]=0;
77 }

References m_map, and m_maplength.

Referenced by BinaryMapBase(), and TrapLineMap::Init().

◆ ClearValue()

void BinaryMapBase::ClearValue ( unsigned  a_x,
unsigned  a_y 
)

Avoids passing one parameter compared to SetValue(unsigned, unsigned, unsigned)

126 {
127  // To find an x/y co-ordinate:
128  // We need to find the 64-bit int that we are in, then the bit or bytes we need
129  unsigned int ref = ( ( ( a_y >> m_resolutionscaler ) * m_width ) + ( a_x >> m_resolutionscaler ) ) * m_colourScaler;
130  // ref holds the first bit of information we need, i.e. the location within m_map in terms of element number.
131  // Next we need to figure out which uint64 this is in.....
132  unsigned int index = ref >> 6; // ....so divide by 64
133  // get the value from this location to a temporary variable
134  uint64 newvalue = m_map[index];
135  // identify the bits we are interested in
136  uint64 bits = ( ref & 63 );
137  // Our mask is sized based on the colours represented 1 - binary, 2 - 4, 4 - 16 , 8 - 256 (NB only powers of 2 are allowed).
138  // The mask is created in the constructor.
139  // So we need to shift our mask to cover the correct bits.
140  uint64 mask = ~( m_mask << bits );
141  // Blank out any current values
142  newvalue = newvalue & mask;
143  m_map[index] = newvalue;
144  ;
145 }

References m_colourScaler, m_map, m_mask, m_resolutionscaler, and m_width.

◆ GetValue()

uint64 BinaryMapBase::GetValue ( unsigned  a_x,
unsigned  a_y 
)
80 {
81  // To find an x/y co-ordinate:
82  // We need to find the 64-bit int that we are in, then the bit or bytes we need
83  unsigned int ref = ( ( ( a_y >> m_resolutionscaler ) * m_width ) + ( a_x >> m_resolutionscaler ) ) * m_colourScaler;
84  // ref holds the first bit of information we need, i.e. the location within m_map in terms of element number.
85  // Next we need to figure out which uint64 this is in.....
86  unsigned int index = ref >> 6; // ....so divide by 64
87  // get the value from this location to a temporary variable
88  uint64 returnvalue = m_map[index];
89  // identify the bits we are interested in
90  uint64 bits = ( ref & 63 );
91  // Our mask is sized based on the colours represented 1 - binary, 2 - 4, 4 - 16 , 8 - 256 (NB only powers of 2 are allowed).
92  // The mask is created in the constructor.
93  // So we need to shift our return value and mask it.
94  returnvalue = ( returnvalue >> bits ) & m_mask;
95  return returnvalue;
96 }

References m_colourScaler, m_map, m_mask, m_resolutionscaler, and m_width.

Referenced by TrapLineMap::IsTrap().

◆ SetValue()

void BinaryMapBase::SetValue ( unsigned  a_x,
unsigned  a_y,
unsigned  a_value 
)
99 {
100  // To find an x/y co-ordinate:
101  // We need to find the 64-bit int that we are in, then the bit or bytes we need
102  unsigned int ref = ( ( ( a_y >> m_resolutionscaler ) * m_width ) + ( a_x >> m_resolutionscaler ) ) * m_colourScaler;
103  // ref holds the first bit of information we need, i.e. the location within m_map in terms of element number.
104  // Next we need to figure out which uint64 this is in.....
105  unsigned int index = ref >> 6; // ....so divide by 64
106  // get the value from this location to a temporary variable
107  uint64 newvalue = m_map[index];
108  // identify the bits we are interested in
109  uint64 bits = ( ref & 63 );
110  // Our mask is sized based on the colours represented 1 - binary, 2 - 4, 4 - 16 , 8 - 256 (NB only powers of 2 are allowed).
111  // The mask is created in the constructor.
112  // So we need to shift our mask to cover the correct bits.
113  uint64 mask = ~( m_mask << bits );
114  // Blank out any current values
115  newvalue = newvalue & mask;
116  // Pop our new value in
117  uint64 value = a_value;
118  newvalue = newvalue | ( value << bits);
119  m_map[index] = newvalue;
120 }

References m_colourScaler, m_map, m_mask, m_resolutionscaler, and m_width.

Referenced by TrapLineMap::Init().

Member Data Documentation

◆ m_colourRes

unsigned int BinaryMapBase::m_colourRes
protected

Referenced by BinaryMapBase().

◆ m_colourScaler

unsigned int BinaryMapBase::m_colourScaler
protected

◆ m_height

unsigned int BinaryMapBase::m_height
protected

Referenced by BinaryMapBase().

◆ m_map

uint64* BinaryMapBase::m_map
protected

◆ m_maplength

unsigned int BinaryMapBase::m_maplength
protected

Referenced by BinaryMapBase(), and ClearMap().

◆ m_mask

uint64 BinaryMapBase::m_mask
protected

◆ m_maskbits

unsigned int BinaryMapBase::m_maskbits
protected

Referenced by BinaryMapBase().

◆ m_resolution

unsigned int BinaryMapBase::m_resolution
protected

Referenced by BinaryMapBase().

◆ m_resolutionscaler

unsigned int BinaryMapBase::m_resolutionscaler
protected

◆ m_width

unsigned int BinaryMapBase::m_width
protected

The documentation for this class was generated from the following files:
BinaryMapBase::m_maskbits
unsigned int m_maskbits
Definition: BinaryMapBase.h:45
BinaryMapBase::ClearMap
void ClearMap()
Definition: BinaryMapBase.cpp:74
BinaryMapBase::m_colourScaler
unsigned int m_colourScaler
Definition: BinaryMapBase.h:42
uint64
unsigned long long uint64
Definition: ALMaSS_Setup.h:35
BinaryMapBase::m_height
unsigned int m_height
Definition: BinaryMapBase.h:39
BinaryMapBase::m_colourRes
unsigned int m_colourRes
Definition: BinaryMapBase.h:41
BinaryMapBase::m_width
unsigned int m_width
Definition: BinaryMapBase.h:40
BinaryMapBase::m_resolution
unsigned int m_resolution
Definition: BinaryMapBase.h:43
BinaryMapBase::m_map
uint64 * m_map
Definition: BinaryMapBase.h:38
BinaryMapBase::m_mask
uint64 m_mask
Definition: BinaryMapBase.h:47
BinaryMapBase::m_maplength
unsigned int m_maplength
Definition: BinaryMapBase.h:46
BinaryMapBase::m_resolutionscaler
unsigned int m_resolutionscaler
Definition: BinaryMapBase.h:44