-
Notifications
You must be signed in to change notification settings - Fork 0
/
brush.cpp
192 lines (157 loc) · 5.28 KB
/
brush.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
181
182
183
184
185
186
187
188
189
190
191
192
#include "brush.h"
#include <QColor>
#include <QtGlobal>
SizedBrush::SizedBrush()
{
this->width = 10;
this->height = 10;
this->depth = 3;
}
void SizedBrush::setSize(int width, int height, int depth)
{
this->width = width;
this->height = height;
this->depth = depth;
}
PixelBrush::PixelBrush()
{
}
void PixelBrush::paint(QImage &qimg,
int x, int y, QColor highlightColor)
{
const qreal opacity = 0.6;
const qreal invOpacity = 0.99 - opacity;
const qreal cRd = highlightColor.redF() * opacity;
const qreal cGr = highlightColor.greenF() * opacity;
const qreal cBl = highlightColor.blueF() * opacity;
//TODO maybe skip rows by shifting i=0,j=0...
if (x < 0 || y < 0)
return;
if (x >= qimg.width() || y >= qimg.height())
return;
QColor pixColor = QColor::fromRgb( qimg.pixel(x, y) );
qreal r = pixColor.redF() * invOpacity + cRd;
qreal g = pixColor.greenF() * invOpacity + cGr;
qreal b = pixColor.blueF() * invOpacity + cBl;
QRgb qrgb = QColor::fromRgbF( r, g, b ).rgb();
qimg.setPixel( x, y, qrgb);
}
void PixelBrush::paint(Matrix3D<LabelType> &data, int x, int y, int z, LabelType label)
{
data.set(x, y, z, label);
}
CubeBrush::CubeBrush(){
//using superclass constructor
}
CubeBrush::CubeBrush(int width,int height, int depth)
{
this->width = width;
this->height = height;
this->depth = depth;
}
//TODO maybe template this or similar
void CubeBrush::paint(QImage &qimg,
int x, int y, QColor highlightColor)
{
const qreal opacity = 0.6;
const qreal invOpacity = 0.99 - opacity;
const qreal cRd = highlightColor.redF() * opacity;
const qreal cGr = highlightColor.greenF() * opacity;
const qreal cBl = highlightColor.blueF() * opacity;
for(int i = x-width;i<x+width;i++) {
for(int j = y-height; j<y+height; j++) {
//TODO maybe skip rows by shifting i=0,j=0...
if (i < 0 || j < 0)
continue;
if (i >= qimg.width() || j >= qimg.height())
continue;
QColor pixColor = QColor::fromRgb( qimg.pixel(i, j) );
qreal r = pixColor.redF() * invOpacity + cRd;
qreal g = pixColor.greenF() * invOpacity + cGr;
qreal b = pixColor.blueF() * invOpacity + cBl;
QRgb qrgb = QColor::fromRgbF( r, g, b ).rgb();
qimg.setPixel( i, j, qrgb);
}
}
}
void CubeBrush::paint(Matrix3D<LabelType> &data,
int x, int y, int z,
LabelType label)
{
for(int i = x-width;i<x+width;i++) {
for(int j = y-height; j<y+height; j++) {
for(int k = z-depth; k<z+depth; k++)
{
//TODO maybe skip rows by shifting i=0,j=0...
if (i < 0 || j < 0 || k < 0)
continue;
if (i >= data.width() || j >= data.height()
||k >= data.depth())
continue;
data.set(i, j, k, label);
}
}
}
}
SphereBrush::SphereBrush(){
//using superclass constructor
}
SphereBrush::SphereBrush(int width,int height, int depth)
{
this->width = width;
this->height = height;
this->depth = depth;
}
//TODO maybe template this or similar
void SphereBrush::paint(QImage &qimg,
int x, int y, QColor highlightColor)
{
const qreal opacity = 0.6;
const qreal invOpacity = 0.99 - opacity;
const qreal cRd = highlightColor.redF() * opacity;
const qreal cGr = highlightColor.greenF() * opacity;
const qreal cBl = highlightColor.blueF() * opacity;
for(int i = x - width;i < x+width; i++)
{
for(int j = y-height; j < y+height; j++)
{
//TODO maybe skip rows by shifting i=0,j=0...
if (i < 0 || j < 0)
continue;
if (i >= qimg.width() || j >= qimg.height())
continue;
if ( (i-x)*(i-x)/( (double)(width*width) )
+ (j-y)*(j-y)/( (double)(height*height) ) <= 1)
{
QColor pixColor = QColor::fromRgb( qimg.pixel(i, j) );
qreal r = pixColor.redF() * invOpacity + cRd;
qreal g = pixColor.greenF() * invOpacity + cGr;
qreal b = pixColor.blueF() * invOpacity + cBl;
QRgb qrgb = QColor::fromRgbF( r, g, b ).rgb();
qimg.setPixel( i, j, qrgb);
}
}
}
}
void SphereBrush::paint(Matrix3D<LabelType> &data,
int x, int y, int z,
LabelType label)
{
for(int i = x-width;i<x+width;i++) {
for(int j = y-height; j<y+height; j++) {
for(int k = z-depth; k<z+depth; k++)
{
//TODO maybe skip rows by shifting i=0,j=0...
if (i < 0 || j < 0 || k < 0)
continue;
if (i >= data.width() || j >= data.height()
||k >= data.depth())
continue;
if ( (i-x)*(i-x)/( (double)(width*width) )
+ (j-y)*(j-y)/( (double)(height*height) )
+ (k-z)*(k-z)/( (double)(depth*depth) ) <= 1)
data.set(i, j, k, label);
}
}
}
}