-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFlowAccu.cpp
73 lines (70 loc) · 1.28 KB
/
FlowAccu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "FlowAccu.h"
#include "utils.h"
bool FlowAccu::Allocate()
{
delete[] pData;
try
{
pData=new int[width*height];
Assign_NoData();
}
catch(const std::bad_alloc& e)
{
fprintf(stderr, "Failed to create memory for flow accumulation matrices!\n");
return false;
}
return true;
}
void FlowAccu::freeMem()
{
delete[] pData;
pData = NULL;
}
void FlowAccu::initialElementsNodata()
{
Assign_NoData();
}
int FlowAccu::asInt(unsigned int row, unsigned int col) const
{
return pData[row*width+col];
}
void FlowAccu::Set_Value(unsigned int row, unsigned int col, int z)
{
pData[row*width+col]=z;
}
bool FlowAccu::is_NoData(unsigned int row, unsigned int col) const
{
if (pData[row*width+col] == -9999) return true;
return false;
}
void FlowAccu::Assign_NoData()
{
for (int i=0; i<width*height; i++)
pData[i]=-9999;
}
unsigned int FlowAccu::Get_NY() const
{
return height;
}
unsigned int FlowAccu::Get_NX() const
{
return width;
}
int* FlowAccu::getData() const
{
return pData;
}
void FlowAccu::SetHeight(unsigned int height)
{
this->height = height;
}
void FlowAccu::SetWidth(unsigned int width)
{
this->width = width;
}
bool FlowAccu::is_InGrid(unsigned int row, unsigned int col) const
{
if ((row >=0 && row < height) && (col >= 0 && col < width))
return true;
return false;
}