-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracing.cpp
115 lines (88 loc) · 2.42 KB
/
tracing.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
#include "tracing.h"
int TracingLayerData::getXDim() const
{
return data.size[2];
}
int TracingLayerData::getYDim() const
{
return data.size[1];
}
int TracingLayerData::getZDim() const
{
return data.size[0];
}
bool TracingLayerData::isLoaded() const
{
return data.empty();
}
cv::Mat TracingLayerData::getRegion(std::vector<cv::Range> region, bool clone)
{
if (data.empty() || region.size() != 3)
return cv::Mat();
if (clone)
return cv::Mat(data, region.data()).clone();
else
return cv::Mat(data, region.data());
}
cv::Mat TracingLayerData::getAxialSlice(int z, bool clone)
{
if (data.empty() || z < 0 || z >= getZDim())
return cv::Mat();
const cv::Range region[] = { cv::Range(z, z + 1), cv::Range::all(), cv::Range::all() };
cv::Mat ret;
if (clone)
ret = cv::Mat(data, region).clone();
else
ret = cv::Mat(data, region);
int dims[] = { data.size[1], data.size[2] };
return ret.reshape(0, 2, dims);
}
cv::Mat TracingLayerData::getCoronalSlice(int y, bool clone)
{
if (data.empty() || y < 0 || y >= getYDim())
return cv::Mat();
const cv::Range region[] = { cv::Range::all(), cv::Range(y, y + 1), cv::Range::all() };
cv::Mat ret;
if (clone)
ret = cv::Mat(data, region).clone();
else
ret = cv::Mat(data, region);
int dims[] = { data.size[0], data.size[2] };
return ret.reshape(0, 2, dims);
}
cv::Mat TracingLayerData::getSaggitalSlice(int x, bool clone)
{
if (data.empty() || x < 0 || x >= getXDim())
return cv::Mat();
const cv::Range region[] = { cv::Range::all(), cv::Range::all(), cv::Range(x, x + 1) };
cv::Mat ret;
if (clone)
ret = cv::Mat(data, region).clone();
else
ret = cv::Mat(data, region);
int dims[] = { data.size[0], data.size[1] };
return ret.reshape(0, 2, dims);
}
unsigned char &TracingLayerData::at(int x, int y, int z)
{
return data.at<unsigned char>(z, y, x);
}
void TracingLayerData::set(int x, int y, int z)
{
data.at<unsigned char>(z, y, x) = 255;
}
void TracingLayerData::reset(int x, int y, int z)
{
data.at<unsigned char>(z, y, x) = 0;
}
void TracingLayerData::load(int x, int y, int z)
{
data = cv::Mat({z, y, x}, CV_8UC1, cv::Scalar(0));
time.resize(z);
}
const NumericType *TracingLayerData::getType() const
{
if (data.empty())
return NULL;
return NumericType::OpenCV(data.type());
}