-
Notifications
You must be signed in to change notification settings - Fork 0
/
Map_Matrix.cpp
180 lines (151 loc) · 4.3 KB
/
Map_Matrix.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//#include "stdafx.h"
#include "Map_Matrix.h"
template <typename Numeric_Type>
Map_Matrix<Numeric_Type>::Map_Matrix(unsigned long maxRows, unsigned long maxColumns) :
ublas::matrix<Numeric_Type>(maxRows, maxColumns),
isHasNoDataValue(true),
noDataValue(-9999)
{
}
template <typename Numeric_Type>
Map_Matrix<Numeric_Type>::Map_Matrix(unsigned long maxRows, unsigned long maxColumns, Numeric_Type _val) :
ublas::matrix<Numeric_Type>(maxRows, maxColumns),
isHasNoDataValue(true),
noDataValue(-9999)
{
for (unsigned int i = 0; i < maxRows; i++)
{
for (unsigned int j = 0; j < maxColumns; j++)
{
this->at_element(i,j) = _val;
valuesContained[_val].numOccurence++;
}
}
}
template <typename Numeric_Type>
Map_Matrix<Numeric_Type>::Map_Matrix() :
ublas::matrix<Numeric_Type>(),
isHasNoDataValue(true),
noDataValue(-9999)
{
}
template <typename Numeric_Type>
Map_Matrix<Numeric_Type>::Map_Matrix(const Map_Matrix<Numeric_Type> & _mm) :
ublas::matrix<Numeric_Type>(_mm),
isHasNoDataValue(_mm.HasNoDataValue()),
noDataValue(_mm.NoDataValue()),
valuesContained(_mm.valuesContained)
{
}
template <typename Numeric_Type>
Map_Matrix<Numeric_Type>::Map_Matrix(const ublas::matrix<Numeric_Type> & _ublas, Numeric_Type null_val) :
ublas::matrix<Numeric_Type>(_ublas),
isHasNoDataValue(true),
noDataValue(null_val)
{
}
template <typename Numeric_Type>
Map_Matrix<Numeric_Type>::~Map_Matrix(void)
{
}
template <typename Numeric_Type>
unsigned long Map_Matrix<Numeric_Type>::NCols(void) const
{
return this->size2();
}
template <typename Numeric_Type>
unsigned long Map_Matrix<Numeric_Type>::NRows(void) const
{
return (this->size1());
}
template <typename Numeric_Type>
void Map_Matrix<Numeric_Type>::Redim(unsigned long nRows, unsigned long nCols)
{
this->resize(nRows, nCols);
valuesContained.clear();
for (unsigned int i = 0; i < nRows; i++)
{
for (unsigned int j = 0; j < nCols; j++)
{
Numeric_Type val = this->at_element(i,j);
valuesContained[val].numOccurence++;
}
}
}
template <typename Numeric_Type>
const Numeric_Type & Map_Matrix<Numeric_Type>::Get(int row_number, int col_number) const
{
return this->operator()(row_number, col_number);
}
template <typename Numeric_Type>
Numeric_Type & Map_Matrix<Numeric_Type>::Get(int row_number, int col_number)
{
return this->operator()(row_number, col_number);
}
template <typename Numeric_Type>
Numeric_Type * Map_Matrix<Numeric_Type>::get_data_ptr(void)
{
return &(this->data().operator[](0));
//return &(this->data().op);
}
template <typename Numeric_Type>
void Map_Matrix<Numeric_Type>::Set(int row_number, int col_number, Numeric_Type value)
{
Numeric_Type old_value = this->operator()(row_number, col_number);
valuesContained[old_value].numOccurence--;
this->operator()(row_number, col_number) = value;
valuesContained[value].numOccurence++;
}
template <typename Numeric_Type>
bool Map_Matrix<Numeric_Type>::HasNoDataValue() const
{
return (isHasNoDataValue);
}
template <typename Numeric_Type>
void Map_Matrix<Numeric_Type>::SetNoDataValue(Numeric_Type value)
{
this->noDataValue = value;
}
template <typename Numeric_Type>
void Map_Matrix<Numeric_Type>::SetNoDataValue(bool _hasNoDataVal, Numeric_Type _value)
{
this->isHasNoDataValue = _hasNoDataVal;
this->noDataValue = _value;
}
template <typename Numeric_Type>
Numeric_Type Map_Matrix<Numeric_Type>::NoDataValue() const
{
return (this->noDataValue);
}
template <typename Numeric_Type>
void Map_Matrix<Numeric_Type>::updateCategories()
{
valuesContained.clear();
for (unsigned int i = 0; i < this->NCols(); i++)
{
for (unsigned int j = 0; j < this->NRows(); j++)
{
Numeric_Type val = this->at_element(j,i);
valuesContained[val].numOccurence++;
}
}
}
template <typename Numeric_Type>
int Map_Matrix<Numeric_Type>::nCats() const
{
return (valuesContained.size());
}
template <typename Numeric_Type>
void Map_Matrix<Numeric_Type>::print()
{
std::cout << "\t";
for (unsigned int i = 0; i < this->NRows(); i++)
{
std::cout << "\t";
for (unsigned int j = 0; j < this->NCols(); j++)
{
std::cout << this->at_element(i,j) << " ";
}
std::cout << "\n";
}
}