Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
threevis
threevis
Commits
b46b2a15
Commit
b46b2a15
authored
Feb 01, 2018
by
Dario Seyb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adressed comments:
- using compatible print statement - not iterating over numpy arrays
parent
500a3109
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
50 deletions
+51
-50
examples/Untitled.ipynb
examples/Untitled.ipynb
+25
-25
meshvis/__init__.py
meshvis/__init__.py
+2
-2
meshvis/context.py
meshvis/context.py
+10
-11
meshvis/indexed_attribute.py
meshvis/indexed_attribute.py
+2
-2
meshvis/mesh_helper.py
meshvis/mesh_helper.py
+12
-10
No files found.
examples/Untitled.ipynb
View file @
b46b2a15
...
...
@@ -10,7 +10,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "
5e9d661e009a4fb09c814903991f9d6
4",
"model_id": "
337ba11c9c9f401993a7bb178c6078a
4",
"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.7
983868
, 0.
7
07
7272 , 0.58422494
],\n",
" [0.7
983868
, 0.
7
07
7272 , 0.58422494
],\n",
" [0.7
983868
, 0.
7
07
7272 , 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.7
165939
, 0.
1
07
31844, 0.02947531
],\n",
" [0.7
165939
, 0.
1
07
31844, 0.02947531
],\n",
" [0.7
165939
, 0.
1
07
31844, 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.9
6335536, 0.9093364 , 0.21515547
],\n",
" [0.9
6335536, 0.9093364 , 0.21515547
],\n",
" [0.
5754378
, 0.8
5
59
4815, 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.9
276281 , 0.68196 , 0.25753966
],\n",
" [0.9
276281 , 0.68196 , 0.25753966
],\n",
" [0.
85570014
, 0.8
2
59
304 , 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.7
983868
, 0.
7
07
7272 , 0.58422494
],\n",
" [0.7
983868
, 0.
7
07
7272 , 0.58422494
],\n",
" [0.7
983868
, 0.
7
07
7272 , 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.7
165939
, 0.
1
07
31844, 0.02947531
],\n",
" [0.7
165939
, 0.
1
07
31844, 0.02947531
],\n",
" [0.7
165939
, 0.
1
07
31844, 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.9
6335536, 0.9093364 , 0.21515547
],\n",
" [0.9
6335536, 0.9093364 , 0.21515547
],\n",
" [0.
5754378
, 0.8
5
59
4815, 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.9
276281 , 0.68196 , 0.25753966
],\n",
" [0.9
276281 , 0.68196 , 0.25753966
],\n",
" [0.
85570014
, 0.8
2
59
304 , 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",
...
...
meshvis/__init__.py
View file @
b46b2a15
...
...
@@ -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
*
...
...
meshvis/context.py
View file @
b46b2a15
...
...
@@ -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
...
...
meshvis/indexed_attribute.py
View file @
b46b2a15
...
...
@@ -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
.
a
range
(
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
)
...
...
meshvis/mesh_helper.py
View file @
b46b2a15
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment