-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix.h
78 lines (57 loc) · 1.68 KB
/
Matrix.h
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
//
// Matrix.h
// Convolve
#ifndef Convolve_Matrix_h
#define Convolve_Matrix_h
#include <assert.h>
typedef unsigned char uchar;
namespace Dog3d
{
// Dense matrix for computing finite difference derivatives
class Matrix
{
public:
Matrix() : m_data(NULL),
m_height(0),
m_width(0) {}
Matrix(Matrix &m) : m_data(NULL)
{
m_width = m.m_width;
m_height = m.m_height;
}
virtual ~Matrix();
void init()
{
m_data = new uchar[m_width * m_height];
assert(m_data);
}
void init(int width, int height);
inline void zero() { memset(m_data, 0, m_width*m_height*sizeof(uchar));}
// simple test routines
void identity();
void greyStreak();
// random data
void random();
// Computes finite difference derivatives (ie convolves in x,y directions with [-1 0 1])
void computeDx( Matrix &m, uchar &dxMin, uchar &dxMax ) const;
void computeDy( Matrix &m, uchar &dyMin, uchar &dyMax ) const;
// inline row accessors
inline const uchar *getRow(int i) const
{
return m_data + (i * m_width);
}
inline uchar *getRow(int i)
{
return m_data + (i * m_width);
}
inline int width() const { return m_width; }
inline int height() const { return m_height; }
private:
uchar *m_data;
int m_width;
int m_height;
};
}
// output a matrix in square form to a stream
std::ostream &operator<<(std::ostream &stream, const Dog3d::Matrix &m);
#endif