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

fixed point attributes for edges

parent 809bfbc8
......@@ -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