forked from cut-lip/DataGlyphDebug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSPC_SF.h
245 lines (214 loc) · 7.83 KB
/
SPC_SF.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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#ifndef SPC_SF_H
#define SPC_SF_H
// #pragma once
#include <vector>
#include "turtleg.h"
//#include "myglfuncs.h"
#include "oglutilities.h"
/*
float COLOR_0 = 0.0;
float COLOR_1 = 1.0;
float ALPHA_CROSS = 0.7;
float CROSS_SCALE = 0.2;
int CROSS_REDUCE = 2;
float SF_SEGMENT_CONSTANT = 0.5;
float SF_ANGLE_SCALE = 2.0;
float GLYPH_SCALE_FACTOR = 0.25;
float CROSS_SCALE_FACTOR = 0.07;
float R_MIN = 0.1;
float R_MAX = 1.0;
float T_MIN = 10.0;
float T_MAX = 85.0;
*/
// An individual SPC-SF glyph located in 2-D space
class SpcSfGlyph {
public:
// Constructor
SpcSfGlyph() {}
// Draw the three SPC coordinate pairs
void drawAxesSPC(Point2 pos2, Point2 pos3, std::vector<float>::iterator axes, GLfloat axisLength,
GLfloat glyphScaleFactor, bool dottedAxes)
{
// Initialize scaling params
GLYPH_SCALE_FACTOR = glyphScaleFactor;
// Isolate axes attributes
float x1 = *axes;// * GLYPH_SCALE_FACTOR;
float x2 = *++axes;// * GLYPH_SCALE_FACTOR;
float x3 = *++axes;// * GLYPH_SCALE_FACTOR;
float x4 = *++axes;// * GLYPH_SCALE_FACTOR;
float x5 = *++axes;// * GLYPH_SCALE_FACTOR;
float x6 = *++axes;// * GLYPH_SCALE_FACTOR;
if (dottedAxes)
{
// Enable line stipple
glPushAttrib(GL_ENABLE_BIT);
// glPushAttrib is done to return everything to normal after drawing
glLineStipple(3, 0xAAAA); // [1]
glEnable(GL_LINE_STIPPLE);
}
// 1st pair: origin (0 - X1, 0 - X2)
glColor4f(COLOR_0, COLOR_1, COLOR_0, ALPHA_CROSS); // Set color to light green
glBegin(GL_LINES); // Draw first cross vertical
glVertex2f(-x1,
-x2 - (((axisLength * GLYPH_SCALE_FACTOR) + CROSS_SCALE) / CROSS_REDUCE) + CROSS_SCALE_FACTOR);
glVertex2f(-x1,
-x2 + (((axisLength * GLYPH_SCALE_FACTOR) + CROSS_SCALE) / CROSS_REDUCE) + CROSS_SCALE_FACTOR);
glEnd(); // end horizontal line
glBegin(GL_LINES); // Draw first cross horizontal
glVertex2f(-x1 - (((axisLength * GLYPH_SCALE_FACTOR) + CROSS_SCALE) / CROSS_REDUCE) + CROSS_SCALE_FACTOR,
-x2);
glVertex2f(-x1 + (((axisLength * GLYPH_SCALE_FACTOR) + CROSS_SCALE) / CROSS_REDUCE) + CROSS_SCALE_FACTOR,
-x2);
glEnd(); // end vertical line
// 2nd pair: origin ( )
glColor4f(0.0, 0.7, 0.0, 0.7); // Set color to medium green
glBegin(GL_LINES); // Draw second cross vertical
glVertex2f(pos2.getx() - x3, pos2.gety() - x4 - (((axisLength * GLYPH_SCALE_FACTOR) + 0.2) / 2)+ CROSS_SCALE_FACTOR);
glVertex2f(pos2.getx() - x3, pos2.gety() - x4 + (((axisLength * GLYPH_SCALE_FACTOR) + 0.2) / 2)+ CROSS_SCALE_FACTOR);
glEnd();
glBegin(GL_LINES); // Draw second cross horizontal
glVertex2f(pos2.getx() - x3 - (((axisLength * GLYPH_SCALE_FACTOR) + 0.2) / 2)+ CROSS_SCALE_FACTOR, pos2.gety() - x4);
glVertex2f(pos2.getx() - x3 + (((axisLength * GLYPH_SCALE_FACTOR) + 0.2) / 2)+ CROSS_SCALE_FACTOR, pos2.gety() - x4);
glEnd();
// 3nd pair: origin ( )
glColor4f(0.0, 0.3, 0.0, 0.7); // Set color to dark green
glBegin(GL_LINES); // Draw third cross vertical
glVertex2f(pos3.getx() - x5, pos3.gety() - x6 - (((axisLength * GLYPH_SCALE_FACTOR) + 0.2) / 2) + CROSS_SCALE_FACTOR);
glVertex2f(pos3.getx() - x5, pos3.gety() - x6 + (((axisLength * GLYPH_SCALE_FACTOR) + 0.2) / 2) + CROSS_SCALE_FACTOR);
glEnd();
glBegin(GL_LINES); // Draw third cross horizontal
glVertex2f(pos3.getx() - x5 - (((axisLength * GLYPH_SCALE_FACTOR) + 0.2) / 2) + CROSS_SCALE_FACTOR, pos3.gety() - x6);
glVertex2f(pos3.getx() - x5 + (((axisLength * GLYPH_SCALE_FACTOR) + 0.2) / 2) + CROSS_SCALE_FACTOR, pos3.gety() - x6);
glEnd();
if (dottedAxes)
{
glPopAttrib();
}
}
// Draw 2-segment SF (Stick Figure) glyph
void drawGlyphSF(Point2* pos2, Point2* pos3,
std::vector<GLfloat>::iterator stick, bool benign, TurtleG turt, bool dynamicAngles, bool posAngle,
GLfloat glyphScaleFactor, GLfloat sfSegmentConstant, GLfloat sfAngleScale, bool ANGLE_FOCUS, bool birdFocus,
float colors[6] )
{
// Initialize scaling params
GLYPH_SCALE_FACTOR = glyphScaleFactor;
SF_SEGMENT_CONSTANT = sfSegmentConstant;
SF_ANGLE_SCALE = sfAngleScale;
// Determine color by class
if (benign)
{ // If class is benign
if (birdFocus)
{ // If bird focus is on, color
glColor4f(colors[0], colors[1], colors[2], 1.0);
}
else
{ // If bird focus is off, grey out
glColor4f(0.0, 0.0, 0.0, 0.3);
}
}
else
{ // If class is malignant
if (birdFocus)
{ // If bird focus is on, color
glColor4f(colors[0], colors[1], colors[2], 1.0);
}
else
{ // If bird focus is off, grey out
glColor4f(0.0, 0.0, 0.0, 0.3);
}
}
GLfloat ang1 = 0;
GLfloat dist1 = 0;
GLfloat ang2 = 0;
GLfloat dist2 = 0;
if (ANGLE_FOCUS)
{
ang1 = *stick;
dist1 = *(stick + 1);
ang2 = *(stick + 2);
dist2 = *(stick + 3);
}
else if (!ANGLE_FOCUS)
{
dist1 = *(stick + 2);
ang1 = *(stick + 3);
dist2 = *stick;
ang2 = *(stick + 1);
}
// First segment
if (posAngle)
{
turt.turnTo((normalizeAngle(ang1))); // Positive angle
}
else
{
turt.turnTo((-normalizeAngle(ang1))); // Negative angle
}
turt.forward(dist1, true);
*pos2 = turt.getCP();
//Determine color by class
//if (benign) glColor4f(0.0, 0.0, 0.8, 0.7);
//else glColor4f(0.8, 0.0, 0.0, 0.7);
// Determine color by class
if (benign)
{
if (birdFocus)
{
glColor4f(colors[3], colors[4], colors[5], 0.7);
}
else
{
glColor4f(0.0, 0.0, 0.0, 0.3);
}
}
else
{
if (birdFocus)
{
glColor4f(colors[3], colors[4], colors[5], 0.7);
}
else
{
glColor4f(0.0, 0.0, 0.0, 0.3);
}
}
//Second segment
if (dynamicAngles)
{
turt.turn(normalizeAngle(ang2)); // Dynamic angles
}
else
{
turt.turnTo(normalizeAngle(ang2)); // Static angles
}
turt.forward(dist2, true);
*pos3 = turt.getCP();
}
private:
float SF_SEGMENT_CONSTANT = 0.5;
float SF_ANGLE_SCALE = 2.0;
float GLYPH_SCALE_FACTOR = 0.25;
static constexpr float COLOR_0 = 0.0;
static constexpr float COLOR_1 = 1.0;
static constexpr float ALPHA_CROSS = 0.7;
static constexpr float CROSS_SCALE = 0.2;
static constexpr int CROSS_REDUCE = 2;
static constexpr float CROSS_SCALE_FACTOR = 0.07;
static constexpr float R_MIN = 0.1;
static constexpr float R_MAX = 1.0;
static constexpr float T_MIN = 10.0;
static constexpr float T_MAX = 85.0;
// Normalize data value to angle value
static GLfloat normalizeAngle(GLfloat m)
{
// Range 0-85 degrees
GLfloat rmin = R_MIN; // Min value data range
GLfloat rmax = R_MAX; // Max value data range
GLfloat tmin = T_MIN; // Min value target range
GLfloat tmax = T_MAX; // Max value target range
// Normalization formula
return (((m - rmin) / (rmax - rmin)) * (tmax - tmin)) + tmin;
}
};
#endif