-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSOL_simplemat.h
125 lines (119 loc) · 2.63 KB
/
SOL_simplemat.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
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
#ifndef SOL_SIMPLE_MAT
#define SOL_SIMPLE_MAT
#include <iostream>
#include "opencv/cv.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "SOL_CONST.h"
using namespace std;
using namespace cv;
//Äîïóñòèìûå ãðàíèöû îïðåäåëèòåëÿ äëÿ ïîäñ÷¸òà îáðàòíîé ìàòðèöû:
#define DET_L 1e+30
#define DET_R 1e+50
class SimpleFMat
{
public:
Mat data;
SimpleFMat(Mat newdata)
{
data = newdata;
}
SimpleFMat(int rows, int cols)
{
data = /**(new */Mat(rows, cols, CV_64FC1)/*)*/;
///*
for (int i = 0; i < data.rows; i++)
{
for (int j = 0; j < data.cols; j++)
data.at<double>(i, j) = 0;
}
//*/
}
~SimpleFMat(void)
{
data.~Mat();
//free(&data);
}
double *operator [] (int i)
{
return &(*(data.begin<double>() + i * data.step1())); //ÒÓÒ ÊÀÊÀß-ÒÎ ËÀÆÀ!!!
}
friend std::ostream &operator << (std::ostream & os, const SimpleFMat &a)
{
for (int i = 0; i < a.data.rows; i++)
{
for (int j = 0; j < a.data.cols; j++)
{
double t = a.data.at<double>(i, j);
os << t << " ";
/*if (&(a.data.at<double>(i, j)) != &(a[i][j]))
cout << "Index mismatch in SimpleMat. Wrong [] operator!" << endl;*/
}
os << endl;
}
os << endl;
return os;
}
SimpleFMat operator + (const SimpleFMat & b)
{
return SimpleFMat(data + b.data);
}
SimpleFMat operator += (const SimpleFMat & b)
{
data += b.data;
return *this;
}
SimpleFMat operator - (const SimpleFMat & b)
{
return SimpleFMat(data - b.data);
}
SimpleFMat operator * (const SimpleFMat & b)
{
return SimpleFMat(data * b.data);
}
SimpleFMat operator = (const double val)
{
for (int i = 0; i < data.rows; i++)
for (int j = 0; j < data.cols; j++)
data.at<double>(i, j) = val;
return *this;
}
SimpleFMat operator /= (const double val)
{
for (int i = 0; i < data.rows; i++)
for (int j = 0; j < data.cols; j++)
data.at<double>(i, j) /= val;
return *this;
}
SimpleFMat operator *= (const double val)
{
for (int i = 0; i < data.rows; i++)
for (int j = 0; j < data.cols; j++)
data.at<double>(i, j) *= val;
return *this;
}
SimpleFMat t()
{
return Mat(data.t());
}
SimpleFMat inv()
{
double t = abs(determinant(data));
double mult = 1;
if (abs(t) < eps)
mult = 1e-4;
while ((abs(t) < eps) && (mult < 1e+4))
{
mult *= 2;
t = abs(determinant(data*mult));
}
if (abs(t) < eps)
{
cerr << "Error! Bad matrix. Can't inverse." << endl;
debug << "Error! Bad matrix. Can't inverse." << endl;
mult = 1;
}
return Mat((data*mult).inv() * mult);
}
};
#endif