Commit 4fa60dec authored by Dario Seyb's avatar Dario Seyb

fixed point attributes for edges

parent 809bfbc8
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {
"scrolled": true
},
......@@ -11,21 +11,197 @@
"name": "stdout",
"output_type": "stream",
"text": [
"False\n",
"[]\n"
"True\n",
"[[0. 0. 0.]\n",
" [0. 0. 1.]\n",
" [0. 1. 0.]\n",
" [0. 1. 1.]\n",
" [1. 0. 0.]\n",
" [1. 0. 1.]\n",
" [1. 1. 0.]\n",
" [1. 1. 1.]]\n",
"None\n"
]
},
{
"ename": "AssertionError",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAssertionError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-1-8563f6e01c24>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 11\u001b[0m ctx.draw_faces(m.points(), m.face_vertex_indices(), \n\u001b[0;32m 12\u001b[0m \u001b[1;31m#normals = meshvis.FaceAttribute(m.face_normals()),\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 13\u001b[1;33m colors = meshvis.UniformAttribute([1, 0, 1]))\n\u001b[0m\u001b[0;32m 14\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 15\u001b[0m \u001b[0mctx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdraw_edges\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mm\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpoints\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mm\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mev_indices\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\dev\\meshvis\\meshvis\\context.pyc\u001b[0m in \u001b[0;36mdraw_faces\u001b[1;34m(self, vertices, face_indices, normals, colors, uvs, shading, z_offset)\u001b[0m\n\u001b[0;32m 30\u001b[0m shading='flat', z_offset=0.5): \n\u001b[0;32m 31\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 32\u001b[1;33m \u001b[1;32massert\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mface_indices\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m0\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvertices\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 33\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 34\u001b[0m \u001b[0mface_indices\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mface_indices\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mAssertionError\u001b[0m: "
]
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1ea49c4c164949ad8a93edcc55f5f701",
"version_major": 2,
"version_minor": 0
},
"text/html": [
"<p>Failed to display Jupyter Widget of type <code>Renderer</code>.</p>\n",
"<p>\n",
" If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n",
" that the widgets JavaScript is still loading. If this message persists, it\n",
" likely means that the widgets JavaScript library is either not installed or\n",
" not enabled. See the <a href=\"https://ipywidgets.readthedocs.io/en/stable/user_install.html\">Jupyter\n",
" Widgets Documentation</a> for setup instructions.\n",
"</p>\n",
"<p>\n",
" If you're reading this message in another frontend (for example, a static\n",
" rendering on GitHub or <a href=\"https://nbviewer.jupyter.org/\">NBViewer</a>),\n",
" it may mean that your frontend doesn't currently support widgets.\n",
"</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=(3.0, 3.0, 3.0), 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=(3.0, 3.0, 3.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)))], 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=(3.0, 3.0, 3.0), 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([[1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,\n",
" 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,\n",
" 34, 35], dtype=uint16), normalized=False), 'normal': BufferAttribute(array=array([[ 0., 0., -1.],\n",
" [ 0., 0., -1.],\n",
" [ 0., 0., -1.],\n",
" [ 0., 0., -1.],\n",
" [ 0., 0., -1.],\n",
" [ 0., 0., -1.],\n",
" [-1., 0., 0.],\n",
" [-1., 0., 0.],\n",
" [-1., 0., 0.],\n",
" [-1., 0., 0.],\n",
" [-1., 0., 0.],\n",
" [-1., 0., 0.],\n",
" [ 0., 1., 0.],\n",
" [ 0., 1., 0.],\n",
" [ 0., 1., 0.],\n",
" [ 0., 1., 0.],\n",
" [ 0., 1., 0.],\n",
" [ 0., 1., 0.],\n",
" [ 1., 0., 0.],\n",
" [ 1., 0., 0.],\n",
" [ 1., 0., 0.],\n",
" [ 1., 0., 0.],\n",
" [ 1., 0., 0.],\n",
" [ 1., 0., 0.],\n",
" [ 0., -1., 0.],\n",
" [ 0., -1., 0.],\n",
" [ 0., -1., 0.],\n",
" [ 0., -1., 0.],\n",
" [ 0., -1., 0.],\n",
" [ 0., -1., 0.],\n",
" [ 0., 0., 1.],\n",
" [ 0., 0., 1.],\n",
" [ 0., 0., 1.],\n",
" [ 0., 0., 1.],\n",
" [ 0., 0., 1.],\n",
" [ 0., 0., 1.]], dtype=float32)), 'position': BufferAttribute(array=array([[0., 0., 0.],\n",
" [1., 1., 0.],\n",
" [1., 0., 0.],\n",
" [0., 0., 0.],\n",
" [0., 1., 0.],\n",
" [1., 1., 0.],\n",
" [0., 0., 0.],\n",
" [0., 1., 1.],\n",
" [0., 1., 0.],\n",
" [0., 0., 0.],\n",
" [0., 0., 1.],\n",
" [0., 1., 1.],\n",
" [0., 1., 0.],\n",
" [1., 1., 1.],\n",
" [1., 1., 0.],\n",
" [0., 1., 0.],\n",
" [0., 1., 1.],\n",
" [1., 1., 1.],\n",
" [1., 0., 0.],\n",
" [1., 1., 0.],\n",
" [1., 1., 1.],\n",
" [1., 0., 0.],\n",
" [1., 1., 1.],\n",
" [1., 0., 1.],\n",
" [0., 0., 0.],\n",
" [1., 0., 0.],\n",
" [1., 0., 1.],\n",
" [0., 0., 0.],\n",
" [1., 0., 1.],\n",
" [0., 0., 1.],\n",
" [0., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 1., 1.],\n",
" [0., 0., 1.],\n",
" [1., 1., 1.],\n",
" [0., 1., 1.]], 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={'index': BufferAttribute(array=array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,\n",
" 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,\n",
" 34, 35], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[0., 0., 0.],\n",
" [1., 1., 0.],\n",
" [1., 1., 0.],\n",
" [1., 0., 0.],\n",
" [1., 0., 0.],\n",
" [0., 0., 0.],\n",
" [0., 0., 0.],\n",
" [0., 1., 0.],\n",
" [0., 1., 0.],\n",
" [1., 1., 0.],\n",
" [0., 0., 0.],\n",
" [0., 1., 1.],\n",
" [0., 1., 1.],\n",
" [0., 1., 0.],\n",
" [0., 0., 0.],\n",
" [0., 0., 1.],\n",
" [0., 0., 1.],\n",
" [0., 1., 1.],\n",
" [0., 1., 0.],\n",
" [1., 1., 1.],\n",
" [1., 1., 1.],\n",
" [1., 1., 0.],\n",
" [0., 1., 1.],\n",
" [1., 1., 1.],\n",
" [1., 1., 1.],\n",
" [1., 0., 0.],\n",
" [1., 1., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 1.],\n",
" [1., 0., 0.],\n",
" [1., 0., 1.],\n",
" [0., 0., 0.],\n",
" [1., 0., 1.],\n",
" [0., 0., 1.],\n",
" [1., 1., 1.],\n",
" [0., 0., 1.]], dtype=float32), normalized=False)}), material=LineBasicMaterial(color=u'#000000'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), Points(geometry=BufferGeometry(attributes={'position': BufferAttribute(array=array([[0., 0., 0.],\n",
" [0., 0., 1.],\n",
" [0., 1., 0.],\n",
" [0., 1., 1.],\n",
" [1., 0., 0.],\n",
" [1., 0., 1.],\n",
" [1., 1., 0.],\n",
" [1., 1., 1.]], dtype=float32), normalized=False)}), material=PointsMaterial(color=u'red', map=None, size=2.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)), shadowMap=WebGLShadowMap())"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
......@@ -52,11 +228,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "IndexError",
"evalue": "index 2 is out of bounds for axis 0 with size 2",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-3-0676bf9d977f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 14\u001b[0m meshvis.display_edges([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], \n\u001b[0;32m 15\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 16\u001b[1;33m colors = meshvis.FaceAttribute(vcolors))\n\u001b[0m",
"\u001b[1;32mc:\\dev\\meshvis\\meshvis\\immediate.pyc\u001b[0m in \u001b[0;36mdisplay_edges\u001b[1;34m(vertices, edge_indices, colors, uvs, z_offset)\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdisplay_edges\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvertices\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0medge_indices\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolors\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0muvs\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mz_offset\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[0mContext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdraw_edges\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvertices\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0medge_indices\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolors\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0muvs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mz_offset\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdisplay\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdisplay_vertices\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvertices\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolors\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mpoint_size\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mz_offset\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mperspective\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mFalse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\dev\\meshvis\\meshvis\\context.pyc\u001b[0m in \u001b[0;36mdraw_edges\u001b[1;34m(self, vertices, edge_indices, colors, uvs, z_offset)\u001b[0m\n\u001b[0;32m 95\u001b[0m \u001b[0medge_indices\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0medge_indices\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 96\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 97\u001b[1;33m \u001b[0mresolved_attribs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresolve_attributes\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0medge_indices\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mcolors\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0muvs\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 98\u001b[0m \u001b[0mresolved_colors\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresolved_attribs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 99\u001b[0m \u001b[0mresolved_uvs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresolved_attribs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\dev\\meshvis\\meshvis\\indexed_attribute.pyc\u001b[0m in \u001b[0;36mresolve_attributes\u001b[1;34m(face_indices, attribs)\u001b[0m\n\u001b[0;32m 19\u001b[0m \u001b[1;32mcontinue\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 20\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 21\u001b[1;33m \u001b[0mresolved_attrib\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mattrib\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mresolve\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mface_indices\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 22\u001b[0m \u001b[0mfinal_attributes\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstretch_attribute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mface_indices\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mresolved_attrib\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 23\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\dev\\meshvis\\meshvis\\indexed_attribute.pyc\u001b[0m in \u001b[0;36mresolve\u001b[1;34m(self, face_indices)\u001b[0m\n\u001b[0;32m 88\u001b[0m \u001b[0midx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mindices\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 89\u001b[0m \u001b[1;31m# Add value for all vertices in the face\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 90\u001b[1;33m \u001b[1;32mfor\u001b[0m \u001b[0mf_vidx\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mface_indices\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0midx\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 91\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0midx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mf_vidx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mval\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 92\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mIndexError\u001b[0m: index 2 is out of bounds for axis 0 with size 2"
]
}
],
"source": [
"\n",
"import meshvis\n",
"vcolors = [\n",
" [1, 0, 0],\n",
" [0, 1, 0],\n",
......@@ -71,7 +263,7 @@
"\n",
"meshvis.display_edges([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], \n",
" [[0, 1], [2,3]], \n",
" colors = meshvis.FaceAttribute(fcolors))"
" colors = meshvis.PointAttribute(vcolors))"
]
},
{
......@@ -115,7 +307,7 @@
"\n",
"ctx = meshvis.Context(width=300, height=300)\n",
"\n",
"ctx.draw_faces(verts, indices, colors= meshvis.FaceAttribute(fcolors))\n",
"ctx.draw_faces(verts, indices, colors= meshvis.PointAttribute(vcolors))\n",
"\n",
"ctx.draw_vertices(verts, point_size=5, colors=vcolors)\n",
"\n",
......
......@@ -19,13 +19,14 @@
" [1. 0. 0.]\n",
" [1. 0. 1.]\n",
" [1. 1. 0.]\n",
" [1. 1. 1.]]\n"
" [1. 1. 1.]]\n",
"None\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d262c2ae7df445cd9a0deff1d699bc72",
"model_id": "1ea49c4c164949ad8a93edcc55f5f701",
"version_major": 2,
"version_minor": 0
},
......@@ -227,11 +228,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "IndexError",
"evalue": "index 2 is out of bounds for axis 0 with size 2",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-3-0676bf9d977f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 14\u001b[0m meshvis.display_edges([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], \n\u001b[0;32m 15\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 16\u001b[1;33m colors = meshvis.FaceAttribute(vcolors))\n\u001b[0m",
"\u001b[1;32mc:\\dev\\meshvis\\meshvis\\immediate.pyc\u001b[0m in \u001b[0;36mdisplay_edges\u001b[1;34m(vertices, edge_indices, colors, uvs, z_offset)\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdisplay_edges\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvertices\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0medge_indices\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolors\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0muvs\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mz_offset\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[0mContext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdraw_edges\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvertices\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0medge_indices\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolors\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0muvs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mz_offset\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdisplay\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdisplay_vertices\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvertices\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolors\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mpoint_size\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mz_offset\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mperspective\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mFalse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\dev\\meshvis\\meshvis\\context.pyc\u001b[0m in \u001b[0;36mdraw_edges\u001b[1;34m(self, vertices, edge_indices, colors, uvs, z_offset)\u001b[0m\n\u001b[0;32m 95\u001b[0m \u001b[0medge_indices\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0medge_indices\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 96\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 97\u001b[1;33m \u001b[0mresolved_attribs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresolve_attributes\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0medge_indices\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mcolors\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0muvs\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 98\u001b[0m \u001b[0mresolved_colors\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresolved_attribs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 99\u001b[0m \u001b[0mresolved_uvs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresolved_attribs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\dev\\meshvis\\meshvis\\indexed_attribute.pyc\u001b[0m in \u001b[0;36mresolve_attributes\u001b[1;34m(face_indices, attribs)\u001b[0m\n\u001b[0;32m 19\u001b[0m \u001b[1;32mcontinue\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 20\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 21\u001b[1;33m \u001b[0mresolved_attrib\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mattrib\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mresolve\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mface_indices\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 22\u001b[0m \u001b[0mfinal_attributes\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstretch_attribute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mface_indices\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mresolved_attrib\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 23\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\dev\\meshvis\\meshvis\\indexed_attribute.pyc\u001b[0m in \u001b[0;36mresolve\u001b[1;34m(self, face_indices)\u001b[0m\n\u001b[0;32m 88\u001b[0m \u001b[0midx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mindices\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 89\u001b[0m \u001b[1;31m# Add value for all vertices in the face\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 90\u001b[1;33m \u001b[1;32mfor\u001b[0m \u001b[0mf_vidx\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mface_indices\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0midx\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 91\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0midx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mf_vidx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mval\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 92\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mIndexError\u001b[0m: index 2 is out of bounds for axis 0 with size 2"
]
}
],
"source": [
"\n",
"import meshvis\n",
"vcolors = [\n",
" [1, 0, 0],\n",
" [0, 1, 0],\n",
......@@ -246,7 +263,7 @@
"\n",
"meshvis.display_edges([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], \n",
" [[0, 1], [2,3]], \n",
" colors = meshvis.FaceAttribute(fcolors))"
" colors = meshvis.PointAttribute(vcolors))"
]
},
{
......@@ -290,7 +307,7 @@
"\n",
"ctx = meshvis.Context(width=300, height=300)\n",
"\n",
"ctx.draw_faces(verts, indices, colors= meshvis.FaceAttribute(fcolors))\n",
"ctx.draw_faces(verts, indices, colors= meshvis.PointAttribute(vcolors))\n",
"\n",
"ctx.draw_vertices(verts, point_size=5, colors=vcolors)\n",
"\n",
......
......@@ -90,6 +90,9 @@ class Context(object):
if edge_indices is None:
edge_indices = zip(np.arange(0, len(vertices)-1), np.arange(1, len(vertices)))
assert(len(edge_indices) > 0 and len(vertices) > 0)
edge_indices = np.array(edge_indices)
resolved_attribs = resolve_attributes(edge_indices, [colors, uvs])
resolved_colors = resolved_attribs[0]
......
......@@ -73,7 +73,7 @@ class PointAttribute(IndexedAttribute):
# if yes, add value for vertex in that face
if idx_in_face is not None:
result.append((f_idx, idx_in_face, val))
return result
class FaceAttribute(IndexedAttribute):
......
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