Commit 09bc0b37 authored by Whitham D. Reeve II's avatar Whitham D. Reeve II

Code cleanup.

parent bafd5e1d
...@@ -22,8 +22,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -22,8 +22,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
import pycam.Plugins import pycam.Plugins
import pycam.Gui.OpenGLTools import pycam.Gui.OpenGLTools
import pycam.Utils.log
log = pycam.Utils.log.get_logger()
class OpenGLViewToolpath(pycam.Plugins.PluginBase): class OpenGLViewToolpath(pycam.Plugins.PluginBase):
...@@ -107,7 +106,7 @@ class OpenGLViewToolpath(pycam.Plugins.PluginBase): ...@@ -107,7 +106,7 @@ class OpenGLViewToolpath(pycam.Plugins.PluginBase):
finally: finally:
coords.unbind() coords.unbind()
## Dead code, remove at some time ## Simulate still depends on this pathway
def _draw_toolpath_moves(self, moves): def _draw_toolpath_moves(self, moves):
GL = self._GL GL = self._GL
GL.glDisable(GL.GL_LIGHTING) GL.glDisable(GL.GL_LIGHTING)
......
...@@ -34,8 +34,7 @@ import random ...@@ -34,8 +34,7 @@ import random
import os import os
import math import math
from itertools import groupby from itertools import groupby
import pycam.Utils.log
log = pycam.Utils.log.get_logger()
def _check_colinearity(p1, p2, p3): def _check_colinearity(p1, p2, p3):
v1 = pnormalized(psub(p2, p1)) v1 = pnormalized(psub(p2, p1))
...@@ -225,9 +224,12 @@ class Toolpath(object): ...@@ -225,9 +224,12 @@ class Toolpath(object):
return result.moves return result.moves
def _rotate_point(self, rp, sp, v, angle): def _rotate_point(self, rp, sp, v, angle):
x = (sp[0] * (v[1] ** 2 + v[2] ** 2) - v[0] * (sp[1] * v[1] + sp[2] * v[2] - v[0] * rp[0] - v[1] * rp[1] - v[2] * rp[2])) * (1 - math.cos(angle)) + rp[0] * math.cos(angle) + (-sp[2] * v[1] + sp[1] * v[2] - v[2] * rp[1] + v[1] * rp[2]) * math.sin(angle) vx = v[0]
y = (sp[1] * (v[0] ** 2 + v[2] ** 2) - v[1] * (sp[0] * v[0] + sp[2] * v[2] - v[0] * rp[0] - v[1] * rp[1] - v[2] * rp[2])) * (1 - math.cos(angle)) + rp[1] * math.cos(angle) + (sp[2] * v[0] - sp[0] * v[2] + v[2] * rp[0] - v[0] * rp[2]) * math.sin(angle) vy = v[1]
z = (sp[2] * (v[0] ** 2 + v[1] ** 2) - v[2] * (sp[0] * v[0] + sp[1] * v[1] - v[0] * rp[0] - v[1] * rp[1] - v[2] * rp[2])) * (1 - math.cos(angle)) + rp[2] * math.cos(angle) + (-sp[1] * v[0] + sp[0] * v[1] - v[1] * rp[0] + v[0] * rp[1]) * math.sin(angle) vz = v[2]
x = (sp[0] * (vy ** 2 + vz ** 2) - vx * (sp[1] * vy + sp[2] * vz - vx * rp[0] - vy * rp[1] - vz * rp[2])) * (1 - math.cos(angle)) + rp[0] * math.cos(angle) + (-sp[2] * vy + sp[1] * vz - vz * rp[1] + vy * rp[2]) * math.sin(angle)
y = (sp[1] * (vx ** 2 + vz ** 2) - vy * (sp[0] * vx + sp[2] * vz - vx * rp[0] - vy * rp[1] - vz * rp[2])) * (1 - math.cos(angle)) + rp[1] * math.cos(angle) + (sp[2] * vx - sp[0] * vz + vz * rp[0] - vx * rp[2]) * math.sin(angle)
z = (sp[2] * (vx ** 2 + vy ** 2) - vz * (sp[0] * vx + sp[1] * vy - vx * rp[0] - vy * rp[1] - vz * rp[2])) * (1 - math.cos(angle)) + rp[2] * math.cos(angle) + (-sp[1] * vx + sp[0] * vy - vy * rp[0] + vx * rp[1]) * math.sin(angle)
return (x,y,z) return (x,y,z)
def draw_direction_cone_mesh(self, p1, p2, position=0.5, precision=12, size=0.1): def draw_direction_cone_mesh(self, p1, p2, position=0.5, precision=12, size=0.1):
...@@ -261,10 +263,11 @@ class Toolpath(object): ...@@ -261,10 +263,11 @@ class Toolpath(object):
def get_moves_for_opengl(self, safety_height): def get_moves_for_opengl(self, safety_height):
if self.opengl_safety_height != safety_height: if self.opengl_safety_height != safety_height:
self.make_moves_for_opengl(safety_height) self.make_moves_for_opengl(safety_height)
self.make_vbo_for_moves2() self.make_vbo_for_moves()
return (self.opengl_coords, self.opengl_indices) return (self.opengl_coords, self.opengl_indices)
def make_vbo_for_moves2(self): # separate vertex coordinates from line definitions and convert to indices
def make_vbo_for_moves(self):
index = 0 index = 0
output = [] output = []
store_vertices = {} store_vertices = {}
...@@ -273,6 +276,8 @@ class Toolpath(object): ...@@ -273,6 +276,8 @@ class Toolpath(object):
indices = [] indices = []
triangles = [] triangles = []
triangle_indices = [] triangle_indices = []
# compress the lines into a centeral array containing all the vertices
# generate a matching index for each line
for idx in range(len(path[0]) - 1): for idx in range(len(path[0]) - 1):
point = path[0][idx] point = path[0][idx]
if not point in store_vertices: if not point in store_vertices:
...@@ -295,53 +300,13 @@ class Toolpath(object): ...@@ -295,53 +300,13 @@ class Toolpath(object):
triangle_indices.append(store_vertices[p]) triangle_indices.append(store_vertices[p])
triangle_indices = array(triangle_indices, dtype=numpy.int32) triangle_indices = array(triangle_indices, dtype=numpy.int32)
indices.append(store_vertices[path[0][-1]]) indices.append(store_vertices[path[0][-1]])
# this list comprehension removes consecutive duplicate points.
indices = array([x[0] for x in groupby(indices)],dtype=numpy.int32) indices = array([x[0] for x in groupby(indices)],dtype=numpy.int32)
output.append((indices, triangle_indices, path[1])) output.append((indices, triangle_indices, path[1]))
vertices = array(vertices, dtype=numpy.float32) vertices = array(vertices, dtype=numpy.float32)
self.opengl_coords = vbo.VBO(vertices) self.opengl_coords = vbo.VBO(vertices)
self.opengl_indices = output self.opengl_indices = output
# separate vertex coordinates from line definitions and convert to indices
#def make_vbo_for_moves(self):
# index = 0
# output = []
# store_vertices = {}
# vertices = []
# for path in self.opengl_lines:
# # compress the lines into a centeral array containing all the vertices
# # generate a matching index for each line
# indices = []
# for point in path[0]:
# if not point in store_vertices:
# store_vertices[point] = index
# vertices.insert(store_vertices[point], point)
# index += 1
# indices.append(store_vertices[point])
# # this list comprehension removes consecutive duplicate points.
# indices = array([x[0] for x in groupby(indices)],dtype=numpy.int32)
# # generate mesh for each direction cone
# # also put these vertices in the vertex array above
# # also generate indices for each triangle
# triangles = []
# for idx in range(len(path[0]) - 1):
# some_triangles =
# for triangle in some_triangles:
# triangles.append(triangle)
# triangle_indices = []
# for t in triangles:
# for p in t:
# if not p in store_vertices:
# store_vertices[p] = index
# vertices.insert(store_vertices[p], p)
# index += 1
# triangle_indices.append(store_vertices[p])
# triangle_indices = array(triangle_indices, dtype=numpy.int32)
# output.append((indices, triangle_indices, path[1]))
# vertices = array(vertices,dtype=numpy.float32)
# coords = vbo.VBO(vertices)
# self.opengl_coords = coords
# self.opengl_indices = output
#convert moves into lines for dispaly with opengl #convert moves into lines for dispaly with opengl
def make_moves_for_opengl(self, safety_height): def make_moves_for_opengl(self, safety_height):
......
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