Commit b46b2a15 authored by Dario Seyb's avatar Dario Seyb

Adressed comments:

- using compatible print statement
- not iterating over numpy arrays
parent 500a3109
......@@ -10,7 +10,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5e9d661e009a4fb09c814903991f9d64",
"model_id": "337ba11c9c9f401993a7bb178c6078a4",
"version_major": 2,
"version_minor": 0
},
......@@ -30,13 +30,13 @@
"</p>\n"
],
"text/plain": [
"Renderer(background='#dddddd', camera=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(0.6647806977667302, 0.6647806977667302, 0.6647806977667302), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), controls=[OrbitControls(controlling=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(0.6647806977667302, 0.6647806977667302, 0.6647806977667302), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), target=(-0.016805611188265124, 0.10981325821101032, -0.0013969168554233066)), Picker(controlling=Scene(background=u'#dddddd', children=(AmbientLight(color=u'#aaaaaa', quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(0.6647806977667302, 0.6647806977667302, 0.6647806977667302), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), Mesh(geometry=BufferGeometry(attributes={'color': BufferAttribute(array=array([[0.5322303 , 0.6005609 , 0.22991498],\n",
" [0.5322303 , 0.6005609 , 0.22991498],\n",
" [0.5322303 , 0.6005609 , 0.22991498],\n",
"Renderer(background='#dddddd', camera=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(0.6647806977667302, 0.6647806977667302, 0.6647806977667302), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), controls=[OrbitControls(controlling=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(0.6647806977667302, 0.6647806977667302, 0.6647806977667302), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), target=(-0.016805611188265124, 0.10981325821101032, -0.0013969168554233066)), Picker(controlling=Scene(background=u'#dddddd', children=(AmbientLight(color=u'#aaaaaa', quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(0.6647806977667302, 0.6647806977667302, 0.6647806977667302), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), Mesh(geometry=BufferGeometry(attributes={'color': BufferAttribute(array=array([[0.43404183, 0.0136816 , 0.8130607 ],\n",
" [0.43404183, 0.0136816 , 0.8130607 ],\n",
" [0.43404183, 0.0136816 , 0.8130607 ],\n",
" ...,\n",
" [0.7983868 , 0.7077272 , 0.58422494],\n",
" [0.7983868 , 0.7077272 , 0.58422494],\n",
" [0.7983868 , 0.7077272 , 0.58422494]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 14901, 14902, 14903], dtype=uint16), normalized=False), 'normal': BufferAttribute(array=array([[-0.8607535 , 0.1269212 , -0.4929447 ],\n",
" [0.7165939 , 0.10731844, 0.02947531],\n",
" [0.7165939 , 0.10731844, 0.02947531],\n",
" [0.7165939 , 0.10731844, 0.02947531]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 14901, 14902, 14903], dtype=uint16), normalized=False), 'normal': BufferAttribute(array=array([[-0.8607535 , 0.1269212 , -0.4929447 ],\n",
" [-0.8924592 , -0.02002691, -0.45068336],\n",
" [-0.8525913 , -0.13340487, -0.50526357],\n",
" ...,\n",
......@@ -48,13 +48,13 @@
" ...,\n",
" [-0.05290982, 0.05704307, 0.02098841],\n",
" [-0.05816759, 0.05998519, 0.02260606],\n",
" [-0.0550398 , 0.0573097 , 0.0169909 ]], dtype=float32), normalized=False)}), material=MeshLambertMaterial(alphaMap=None, aoMap=None, color=u'white', emissiveMap=None, envMap=None, lightMap=None, map=None, polygonOffset=True, polygonOffsetFactor=0.5, polygonOffsetUnits=0.1, specularMap=None, vertexColors='VertexColors'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), LineSegments(geometry=BufferGeometry(attributes={'color': BufferAttribute(array=array([[0.96335536, 0.9093364 , 0.21515547],\n",
" [0.96335536, 0.9093364 , 0.21515547],\n",
" [0.5754378 , 0.85594815, 0.9406462 ],\n",
" [-0.0550398 , 0.0573097 , 0.0169909 ]], dtype=float32), normalized=False)}), material=MeshLambertMaterial(alphaMap=None, aoMap=None, color=u'white', emissiveMap=None, envMap=None, lightMap=None, map=None, polygonOffset=True, polygonOffsetFactor=0.5, polygonOffsetUnits=0.1, specularMap=None, vertexColors='VertexColors'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), LineSegments(geometry=BufferGeometry(attributes={'color': BufferAttribute(array=array([[0.9276281 , 0.68196 , 0.25753966],\n",
" [0.9276281 , 0.68196 , 0.25753966],\n",
" [0.85570014, 0.8259304 , 0.57208616],\n",
" ...,\n",
" [0.06893933, 0.64734125, 0.8833534 ],\n",
" [0.95521915, 0.6979847 , 0.04272681],\n",
" [0.95521915, 0.6979847 , 0.04272681]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 14943, 14944, 14945], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-0.08656194, 0.14249188, 0.00843268],\n",
" [0.14575003, 0.9981117 , 0.8627156 ],\n",
" [0.601416 , 0.23257364, 0.60186046],\n",
" [0.601416 , 0.23257364, 0.60186046]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 14943, 14944, 14945], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-0.08656194, 0.14249188, 0.00843268],\n",
" [-0.08969839, 0.13971257, 0.01377476],\n",
" [-0.08969839, 0.13971257, 0.01377476],\n",
" ...,\n",
......@@ -72,13 +72,13 @@
" ...,\n",
" [-0.01389549, 0.16787168, -0.02189723],\n",
" [-0.069413 , 0.15121847, -0.04453854],\n",
" [-0.0550398 , 0.0573097 , 0.0169909 ]], dtype=float32), normalized=False)}), material=PointsMaterial(color=u'red', map=None, size=4.0, sizeAttenuation=False), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0))), fog=None, overrideMaterial=None, quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), event=u'dblclick', object=None)], scene=Scene(background=u'#dddddd', children=(AmbientLight(color=u'#aaaaaa', quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(0.6647806977667302, 0.6647806977667302, 0.6647806977667302), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), Mesh(geometry=BufferGeometry(attributes={'color': BufferAttribute(array=array([[0.5322303 , 0.6005609 , 0.22991498],\n",
" [0.5322303 , 0.6005609 , 0.22991498],\n",
" [0.5322303 , 0.6005609 , 0.22991498],\n",
" [-0.0550398 , 0.0573097 , 0.0169909 ]], dtype=float32), normalized=False)}), material=PointsMaterial(color=u'red', map=None, size=4.0, sizeAttenuation=False), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0))), fog=None, overrideMaterial=None, quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), event=u'dblclick', object=None)], scene=Scene(background=u'#dddddd', children=(AmbientLight(color=u'#aaaaaa', quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(0.6647806977667302, 0.6647806977667302, 0.6647806977667302), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), Mesh(geometry=BufferGeometry(attributes={'color': BufferAttribute(array=array([[0.43404183, 0.0136816 , 0.8130607 ],\n",
" [0.43404183, 0.0136816 , 0.8130607 ],\n",
" [0.43404183, 0.0136816 , 0.8130607 ],\n",
" ...,\n",
" [0.7983868 , 0.7077272 , 0.58422494],\n",
" [0.7983868 , 0.7077272 , 0.58422494],\n",
" [0.7983868 , 0.7077272 , 0.58422494]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 14901, 14902, 14903], dtype=uint16), normalized=False), 'normal': BufferAttribute(array=array([[-0.8607535 , 0.1269212 , -0.4929447 ],\n",
" [0.7165939 , 0.10731844, 0.02947531],\n",
" [0.7165939 , 0.10731844, 0.02947531],\n",
" [0.7165939 , 0.10731844, 0.02947531]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 14901, 14902, 14903], dtype=uint16), normalized=False), 'normal': BufferAttribute(array=array([[-0.8607535 , 0.1269212 , -0.4929447 ],\n",
" [-0.8924592 , -0.02002691, -0.45068336],\n",
" [-0.8525913 , -0.13340487, -0.50526357],\n",
" ...,\n",
......@@ -90,13 +90,13 @@
" ...,\n",
" [-0.05290982, 0.05704307, 0.02098841],\n",
" [-0.05816759, 0.05998519, 0.02260606],\n",
" [-0.0550398 , 0.0573097 , 0.0169909 ]], dtype=float32), normalized=False)}), material=MeshLambertMaterial(alphaMap=None, aoMap=None, color=u'white', emissiveMap=None, envMap=None, lightMap=None, map=None, polygonOffset=True, polygonOffsetFactor=0.5, polygonOffsetUnits=0.1, specularMap=None, vertexColors='VertexColors'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), LineSegments(geometry=BufferGeometry(attributes={'color': BufferAttribute(array=array([[0.96335536, 0.9093364 , 0.21515547],\n",
" [0.96335536, 0.9093364 , 0.21515547],\n",
" [0.5754378 , 0.85594815, 0.9406462 ],\n",
" [-0.0550398 , 0.0573097 , 0.0169909 ]], dtype=float32), normalized=False)}), material=MeshLambertMaterial(alphaMap=None, aoMap=None, color=u'white', emissiveMap=None, envMap=None, lightMap=None, map=None, polygonOffset=True, polygonOffsetFactor=0.5, polygonOffsetUnits=0.1, specularMap=None, vertexColors='VertexColors'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), LineSegments(geometry=BufferGeometry(attributes={'color': BufferAttribute(array=array([[0.9276281 , 0.68196 , 0.25753966],\n",
" [0.9276281 , 0.68196 , 0.25753966],\n",
" [0.85570014, 0.8259304 , 0.57208616],\n",
" ...,\n",
" [0.06893933, 0.64734125, 0.8833534 ],\n",
" [0.95521915, 0.6979847 , 0.04272681],\n",
" [0.95521915, 0.6979847 , 0.04272681]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 14943, 14944, 14945], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-0.08656194, 0.14249188, 0.00843268],\n",
" [0.14575003, 0.9981117 , 0.8627156 ],\n",
" [0.601416 , 0.23257364, 0.60186046],\n",
" [0.601416 , 0.23257364, 0.60186046]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 14943, 14944, 14945], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-0.08656194, 0.14249188, 0.00843268],\n",
" [-0.08969839, 0.13971257, 0.01377476],\n",
" [-0.08969839, 0.13971257, 0.01377476],\n",
" ...,\n",
......
......@@ -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