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

added some basic bounds

parent a8559d26
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import meshvis\n",
"import openmesh as om\n",
"import numpy as np\n",
"\n",
"m = om.PolyMesh()\n",
"\n",
"om.read_mesh(m, 'models/bunny.obj')\n",
"\n",
"vertices = m.points()\n",
"faces = m.face_vertex_indices()\n",
"\n",
"\n",
"mesh = meshvis.Mesh(vertices, faces, \n",
" normals = meshvis.calculateFaceNormals(vertices, faces))\n",
"\n",
"ctx = meshvis.Context()\n",
"ctx.draw(mesh, shading='flat', clipping_planes=[meshvis.Plane((1.0, 0.0, 0.0) , 0)])\n",
"ctx.showBounds()\n",
"ctx.display()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
...@@ -21,8 +21,19 @@ ...@@ -21,8 +21,19 @@
"mesh = meshvis.Mesh(vertices, faces, \n", "mesh = meshvis.Mesh(vertices, faces, \n",
" normals = meshvis.calculateFaceNormals(vertices, faces))\n", " normals = meshvis.calculateFaceNormals(vertices, faces))\n",
"\n", "\n",
"meshvis.display(mesh, shading='flat', clipping_planes=[meshvis.Plane((1.0, 0.0, 0.0) , 0)])" "ctx = meshvis.Context()\n",
"ctx.draw(mesh, shading='flat', clipping_planes=[meshvis.Plane((1.0, 0.0, 0.0) , 0)])\n",
"ctx.display()\n",
"\n",
"ctx.setCameraPosition([0.2, 0, 0])"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {
......
...@@ -41,6 +41,8 @@ class Context(object): ...@@ -41,6 +41,8 @@ class Context(object):
self.click_picker.observe(on_picked, names=['point']) self.click_picker.observe(on_picked, names=['point'])
self.show_bounds = False
def draw(self, obj, shading='flat', z_offset=0.5, texture=None, point_size = 1, perspective = False, line_width = 1, clipping_planes = []): def draw(self, obj, shading='flat', z_offset=0.5, texture=None, point_size = 1, perspective = False, line_width = 1, clipping_planes = []):
""" """
Draw the given object. Not all named parameters are relevant for all object types. Draw the given object. Not all named parameters are relevant for all object types.
...@@ -234,6 +236,27 @@ class Context(object): ...@@ -234,6 +236,27 @@ class Context(object):
self.scene.add(mesh_obj) self.scene.add(mesh_obj)
return self return self
def setCameraPosition(self, position):
self.camera.position = tuple(position)
def showBounds(self):
self.show_bounds = True
def hideBounds(self):
self.show_bounds = False
def setBounds(self, val):
self.show_bounds = val
def draw_text(self, text, position=(0, 0, 0), color='white', size=100, height=1):
"""
Draw a text object at the specified location with a given height
"""
height *= len(text)
sm = three.SpriteMaterial(map=three.TextTexture(string=text, color=color, size=size, squareTexture=True))
sprite = three.Sprite(material=sm, position=tuple(position), scaleToTexture=True, scale=[height, height, 1])
self.scene.add(sprite)
def display(self): def display(self):
""" """
Display a window containing all the previous draw calls. Display a window containing all the previous draw calls.
...@@ -244,4 +267,18 @@ class Context(object): ...@@ -244,4 +267,18 @@ class Context(object):
self.camera.position = tuple( np.array(self.camera.position) * distance * 5) self.camera.position = tuple( np.array(self.camera.position) * distance * 5)
self.orbit_controls.target = tuple(center) self.orbit_controls.target = tuple(center)
if self.show_bounds:
extends = self.maxCorner - self.minCorner
boxEdges = [self.minCorner,
self.minCorner + [extends[0], 0, 0],
self.minCorner + [0, extends[1], 0],
self.minCorner + [0, 0, extends[2]]]
self.draw_edges(boxEdges, [[0, 1], [0, 2], [0, 3]], FaceAttribute([[1, 0, 0], [0, 1, 0], [0, 0, 1]]))
self.draw_text(str(map( lambda v: round(v, 3), self.minCorner)), self.minCorner - [0, extends[1]*0.1, 0], color = 'black', height=extends[1]/25)
self.draw_text(str(round(extends[0], 3)), (boxEdges[0] * 0.25 + boxEdges[1] * 0.75), color = 'black', height=extends[1]/20)
self.draw_text(str(round(extends[1], 3)), (boxEdges[0] * 0.25 + boxEdges[2] * 0.75), color = 'black', height=extends[1]/20)
self.draw_text(str(round(extends[2], 3)), (boxEdges[0] * 0.25 + boxEdges[3] * 0.75), color = 'black', height=extends[1]/20)
display(self.renderer) display(self.renderer)
\ 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