|
|
|
@ -13,9 +13,12 @@ It should be split up into a few more separate files eventually...
|
|
|
|
|
Probably even into it's own module folder. |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
from OpenGL.GL import (glBegin, glClearColor, glColor3f, |
|
|
|
|
glEnd, GL_LINE_LOOP, GL_POINTS, |
|
|
|
|
glPointSize, glVertex3f, glViewport) |
|
|
|
|
import math |
|
|
|
|
|
|
|
|
|
from OpenGL.GL import (glBegin, glClearColor, glColor3f, glColor4f, |
|
|
|
|
glEnable, glEnd, GL_LINE_LOOP, GL_LINE_SMOOTH, |
|
|
|
|
GL_POINTS, glPointSize, glVertex3f, |
|
|
|
|
glViewport) |
|
|
|
|
|
|
|
|
|
from clusterview2.colors import Color, COLOR_TO_RGBA |
|
|
|
|
from clusterview2.exceptions import (handle_exceptions, |
|
|
|
@ -188,6 +191,11 @@ def paint_gl():
|
|
|
|
|
|
|
|
|
|
draw_points(PointManager.point_set) |
|
|
|
|
|
|
|
|
|
if (__current_context.mode is Mode.CLUSTERING and |
|
|
|
|
__current_context.clustering_solved): |
|
|
|
|
|
|
|
|
|
draw_mean_circles(PointManager.clusters) |
|
|
|
|
|
|
|
|
|
elif __current_context.mode is Mode.MOVE: |
|
|
|
|
# We have to repeatedly draw the points while we are showing the |
|
|
|
|
# move box. |
|
|
|
@ -388,3 +396,43 @@ def draw_points(point_set):
|
|
|
|
|
__clamp_y(point.y), |
|
|
|
|
0.0) # Z is currently fixed to 0 |
|
|
|
|
glEnd() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def draw_mean_circles(clusters: list): |
|
|
|
|
""" |
|
|
|
|
Draws a red circle for each mean. |
|
|
|
|
|
|
|
|
|
@param clusters The list of clusters created by k-means. |
|
|
|
|
""" |
|
|
|
|
global __current_context |
|
|
|
|
|
|
|
|
|
if __current_context is None: |
|
|
|
|
raise InvalidStateError('Drawing context must be set before setting ' + |
|
|
|
|
'drawing mode.') |
|
|
|
|
|
|
|
|
|
if len(clusters) == 0: |
|
|
|
|
raise InvalidStateError('Run clustering before drawing means.') |
|
|
|
|
|
|
|
|
|
radius = 0.02 |
|
|
|
|
segments = 100 |
|
|
|
|
|
|
|
|
|
glViewport(0, 0, __WIDTH, __HEIGHT) |
|
|
|
|
glEnable(GL_LINE_SMOOTH) |
|
|
|
|
|
|
|
|
|
for cluster in clusters: |
|
|
|
|
glBegin(GL_LINE_LOOP) |
|
|
|
|
|
|
|
|
|
blue = COLOR_TO_RGBA[Color.BLUE] |
|
|
|
|
glColor4f(blue[0], blue[1], blue[2], 0.5) |
|
|
|
|
|
|
|
|
|
mean = cluster.mean |
|
|
|
|
|
|
|
|
|
x = __clamp_x(cluster.mean.x) |
|
|
|
|
y = __clamp_y(cluster.mean.y) |
|
|
|
|
|
|
|
|
|
for i in range(0, segments): |
|
|
|
|
glVertex3f(x + (radius * math.cos(i * ((2 * math.pi)/segments))), |
|
|
|
|
y + (radius * math.sin(i * ((2 * math.pi)/segments))), |
|
|
|
|
0.0) |
|
|
|
|
|
|
|
|
|
glEnd() |
|
|
|
|