Commit a8090f92 authored by Guillaume Seguin's avatar Guillaume Seguin

Remove arrows support from GcodeModel, as we did not use it anyway

parent cbaa3062
...@@ -25,8 +25,6 @@ from pyglet.gl import * ...@@ -25,8 +25,6 @@ from pyglet.gl import *
from pyglet import gl from pyglet import gl
from pyglet.graphics.vertexbuffer import create_buffer, VertexBufferObject from pyglet.graphics.vertexbuffer import create_buffer, VertexBufferObject
from . import vector
from printrun.printrun_utils import install_locale from printrun.printrun_utils import install_locale
install_locale('pronterface') install_locale('pronterface')
...@@ -37,8 +35,8 @@ def compile_display_list(func, *options): ...@@ -37,8 +35,8 @@ def compile_display_list(func, *options):
glEndList() glEndList()
return display_list return display_list
def numpy2vbo(nparray, target = GL_ARRAY_BUFFER, usage = GL_STATIC_DRAW): def numpy2vbo(nparray, target = GL_ARRAY_BUFFER, usage = GL_STATIC_DRAW, use_vbos = True):
vbo = create_buffer(nparray.nbytes, target = target, usage = usage, vbo = True) vbo = create_buffer(nparray.nbytes, target = target, usage = usage, vbo = use_vbos)
vbo.bind() vbo.bind()
vbo.set_data(nparray.ctypes.data) vbo.set_data(nparray.ctypes.data)
return vbo return vbo
...@@ -203,15 +201,10 @@ class GcodeModel(Model): ...@@ -203,15 +201,10 @@ class GcodeModel(Model):
""" """
Model for displaying Gcode data. Model for displaying Gcode data.
""" """
# vertices for arrow to display the direction of movement
arrow = numpy.require([
[0.0, 0.0, 0.0],
[0.4, -0.1, 0.0],
[0.4, 0.1, 0.0],
], 'f')
color_printed = (0.2, 0.75, 0, 0.6) color_printed = (0.2, 0.75, 0, 0.6)
use_vbos = True
loaded = False loaded = False
def load_data(self, model_data, callback=None): def load_data(self, model_data, callback=None):
...@@ -232,11 +225,6 @@ class GcodeModel(Model): ...@@ -232,11 +225,6 @@ class GcodeModel(Model):
current_pos = (gline.current_x, gline.current_y, gline.current_z) current_pos = (gline.current_x, gline.current_y, gline.current_z)
vertex_list.append(current_pos) vertex_list.append(current_pos)
arrow = self.arrow
# position the arrow with respect to movement
arrow = vector.rotate(arrow, movement_angle(prev_pos, current_pos), 0.0, 0.0, 1.0)
arrow_list.extend(arrow)
vertex_color = self.movement_color(gline) vertex_color = self.movement_color(gline)
color_list.append(vertex_color) color_list.append(vertex_color)
...@@ -249,22 +237,11 @@ class GcodeModel(Model): ...@@ -249,22 +237,11 @@ class GcodeModel(Model):
callback(layer_idx + 1, num_layers) callback(layer_idx + 1, num_layers)
self.vertices = numpy.array(vertex_list, dtype = GLfloat) self.vertices = numpy.array(vertex_list, dtype = GLfloat)
self.colors = numpy.array(color_list, dtype = GLfloat) self.colors = numpy.array(color_list, dtype = GLfloat).repeat(2, 0)
self.arrows = numpy.array(arrow_list, dtype = GLfloat)
# by translating the arrow vertices outside of the loop, we achieve a
# significant performance gain thanks to numpy. it would be really nice
# if we could rotate in a similar fashion...
self.arrows = self.arrows + self.vertices[1::2].repeat(3, 0)
# for every pair of vertices of the model, there are 3 vertices for the arrow
assert len(self.arrows) == ((len(self.vertices) // 2) * 3), \
'The 2:3 ratio of model vertices to arrow vertices does not hold.'
self.max_layers = len(self.layer_stops) - 1 self.max_layers = len(self.layer_stops) - 1
self.num_layers_to_draw = self.max_layers self.num_layers_to_draw = self.max_layers
self.printed_until = -1 self.printed_until = -1
self.arrows_enabled = False
self.initialized = False self.initialized = False
self.loaded = True self.loaded = True
...@@ -275,7 +252,7 @@ class GcodeModel(Model): ...@@ -275,7 +252,7 @@ class GcodeModel(Model):
def copy(self): def copy(self):
copy = GcodeModel() copy = GcodeModel()
for var in ["vertices", "arrows", "colors", "max_layers", "num_layers_to_draw", "printed_until", "arrows_enabled", "layer_stops"]: for var in ["vertices", "colors", "max_layers", "num_layers_to_draw", "printed_until", "layer_stops"]:
setattr(copy, var, getattr(self, var)) setattr(copy, var, getattr(self, var))
copy.loaded = True copy.loaded = True
copy.initialized = False copy.initialized = False
...@@ -313,13 +290,8 @@ class GcodeModel(Model): ...@@ -313,13 +290,8 @@ class GcodeModel(Model):
# ------------------------------------------------------------------------ # ------------------------------------------------------------------------
def init(self): def init(self):
self.vertex_buffer = numpy2vbo(self.vertices) self.vertex_buffer = numpy2vbo(self.vertices, use_vbos = self.use_vbos)
self.vertex_color_buffer = numpy2vbo(self.colors.repeat(2, 0)) # each pair of vertices shares the color self.vertex_color_buffer = numpy2vbo(self.colors, use_vbos = self.use_vbos) # each pair of vertices shares the color
if self.arrows_enabled:
self.arrow_buffer = numpy2vbo(self.arrows)
self.arrow_color_buffer = numpy2vbo(self.colors.repeat(3, 0)) # each triplet of vertices shares the color
self.initialized = True self.initialized = True
def display(self, mode_2d=False): def display(self, mode_2d=False):
...@@ -330,9 +302,6 @@ class GcodeModel(Model): ...@@ -330,9 +302,6 @@ class GcodeModel(Model):
self._display_movements(mode_2d) self._display_movements(mode_2d)
if self.arrows_enabled:
self._display_arrows()
glDisableClientState(GL_COLOR_ARRAY) glDisableClientState(GL_COLOR_ARRAY)
glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_VERTEX_ARRAY)
glPopMatrix() glPopMatrix()
...@@ -377,24 +346,3 @@ class GcodeModel(Model): ...@@ -377,24 +346,3 @@ class GcodeModel(Model):
self.vertex_buffer.unbind() self.vertex_buffer.unbind()
self.vertex_color_buffer.unbind() self.vertex_color_buffer.unbind()
def _display_arrows(self):
self.arrow_buffer.bind()
has_vbo = isinstance(self.arrow_buffer, VertexBufferObject)
if has_vbo:
glVertexPointer(3, GL_FLOAT, 0, None)
else:
glVertexPointer(3, GL_FLOAT, 0, self.arrow_buffer.ptr)
self.arrow_color_buffer.bind()
if has_vbo:
glColorPointer(4, GL_FLOAT, 0, None)
else:
glColorPointer(4, GL_FLOAT, 0, self.arrow_color_buffer.ptr)
start = (self.layer_stops[self.num_layers_to_draw - 1] // 2) * 3
end = (self.layer_stops[self.num_layers_to_draw] // 2) * 3
glDrawArrays(GL_TRIANGLES, start, end - start)
self.arrow_buffer.unbind()
self.arrow_color_buffer.unbind()
# -*- coding: utf-8 -*-
# Copyright (C) 2011 Denis Kobozev
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from __future__ import division
import numpy
import math
_identity_matrix = [
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0],
]
_rotation_matrix_cache = {}
def identity_matrix():
return numpy.require(_identity_matrix[:], 'f')
def rotation_matrix(angle, x, y, z):
angle_r = math.radians(angle)
c = math.cos(angle_r)
s = math.sin(angle_r)
C = 1 - c
matrix = numpy.require([
[x ** 2 * C + c, x * y * C - z * s, x * z * C + y * s],
[y * x * C + z * s, y ** 2 * C + c, y * z * C - x * s],
[x * z * C - y * s, y * z * C + x * s, z ** 2 * C + c],
], 'f')
return matrix
def translate(vertices, x, y, z):
translated = vertices + numpy.array([x, y, z], 'f')
return translated
def rotate(vertices, angle, x, y, z):
key = (angle, x, y, z)
if key not in _rotation_matrix_cache:
_rotation_matrix_cache[key] = rotation_matrix(angle, x, y, z)
matrix = _rotation_matrix_cache[key]
rotated = numpy.dot(vertices, matrix)
return rotated
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment