Commit b46b2a15 authored by Dario Seyb's avatar Dario Seyb

Adressed comments:

- using compatible print statement
- not iterating over numpy arrays
parent 500a3109
This diff is collapsed.
......@@ -2,8 +2,8 @@
try:
from .openmesh_utils import *
except ImportError as error:
print 'OpenMesh not available'
print error
print('OpenMesh not available')
print(error)
from .context import *
from .immediate import *
......
......@@ -44,6 +44,7 @@ class Context(object):
assert(len(face_indices) > 0 and len(vertices) > 0)
vertices = np.array(vertices)
face_indices = np.array(face_indices)
mat = None
......@@ -94,11 +95,9 @@ class Context(object):
mesh_geom = three.BufferGeometry(attributes=attributes)
mesh_obj = three.Mesh(geometry=mesh_geom, material=mat)
for vert in vertices:
self.minCorner = np.minimum(self.minCorner, vert)
self.maxCorner = np.maximum(self.maxCorner, vert)
self.minCorner = np.minimum(self.minCorner, vertices.min(axis=0))
self.maxCorner = np.maximum(self.maxCorner, vertices.max(axis=0))
self.scene.add(mesh_obj)
return self
......@@ -117,6 +116,7 @@ class Context(object):
assert(len(edge_indices) > 0 and len(vertices) > 0)
vertices = np.array(vertices)
edge_indices = np.array(edge_indices)
resolved_attribs = resolve_attributes(edge_indices, [colors, uvs])
......@@ -142,15 +142,15 @@ class Context(object):
mesh_obj = three.LineSegments(geometry=geom, material=mat)
for vert in vertices:
self.minCorner = np.minimum(self.minCorner, vert)
self.maxCorner = np.maximum(self.maxCorner, vert)
self.minCorner = np.minimum(self.minCorner, vertices.min(axis=0))
self.maxCorner = np.maximum(self.maxCorner, vertices.max(axis=0))
self.scene.add(mesh_obj)
return self
def draw_vertices(self, vertices, colors=None, point_size=1, z_offset=0, perspective=False):
vertices = np.array(vertices)
matColor = colors
if colors is None:
......@@ -178,9 +178,8 @@ class Context(object):
geom = three.BufferGeometry(attributes=attributes)
mesh_obj = three.Points(geometry=geom, material=mat)
for vert in vertices:
self.minCorner = np.minimum(self.minCorner, vert)
self.maxCorner = np.maximum(self.maxCorner, vert)
self.minCorner = np.minimum(self.minCorner, vertices.min(axis=0))
self.maxCorner = np.maximum(self.maxCorner, vertices.max(axis=0))
self.scene.add(mesh_obj)
return self
......
......@@ -7,7 +7,7 @@ def stretch_vertices(vertices, face_indices):
for vidx in face:
stretched_verts.append(vertices[vidx])
return stretched_verts, range(0, len(stretched_verts))
return np.array(stretched_verts), np.arange(0, len(stretched_verts))
def resolve_attributes(face_indices, attribs):
......@@ -30,7 +30,7 @@ def stretch_attribute(face_indices, resolved_attrib):
for val in resolved_attrib:
stretched_attrib[val[0] * vs_per_face + val[1]] = val[2]
return stretched_attrib
return np.array(stretched_attrib)
def find(element, list_element):
index_element = np.where(list_element==element)
......
......@@ -50,7 +50,9 @@ def calculateFaceNormals(vertices, face_indices):
return FaceAttribute(values)
def calculatePointNormals(vertices, face_indices):
values = [(np.array([0.0, 0.0, 0.0]), 0)] * len(vertices)
normals = np.zeros_like(vertices)
counts = np.zeros(vertices.shape[0])
for face in face_indices:
v1 = np.array(vertices[face[0]])
v2 = np.array(vertices[face[1]])
......@@ -61,15 +63,15 @@ def calculatePointNormals(vertices, face_indices):
norm = np.cross(v12, v13)
values[face[0]] = ( values[face[0]][0] + norm, values[face[0]][1] + 1)
values[face[1]] = ( values[face[1]][0] + norm, values[face[1]][1] + 1)
values[face[2]] = ( values[face[2]][0] + norm, values[face[2]][1] + 1)
normals[face[0]] += norm
normals[face[1]] += norm
normals[face[2]] += norm
counts[face[0]] += 1
counts[face[1]] += 1
counts[face[2]] += 1
result = []
for val in values:
norm = val[0]/val[1]
norm = norm / np.linalg.norm(norm)
result.append(norm)
return PointAttribute(result)
\ No newline at end of file
normals /= counts.reshape(-1, 1)
normals /= np.linalg.norm(normals, axis=1).reshape(-1, 1)
return PointAttribute(normals)
\ No newline at end of file
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