pygel3d.gl_display
This modules provides an OpenGL based viewer for graphs and meshes
1""" This modules provides an OpenGL based viewer for graphs and meshes """ 2from pygel3d import hmesh, graph, lib_py_gel 3import ctypes as ct 4import numpy as np 5from os import getcwd, chdir 6 7try: 8 lib_py_gel.GLManifoldViewer_new.restype = ct.c_void_p 9 lib_py_gel.GLManifoldViewer_delete.argtypes = (ct.c_void_p,) 10 lib_py_gel.GLManifoldViewer_display.argtypes = (ct.c_void_p,ct.c_void_p,ct.c_void_p,ct.c_char,ct.c_bool, ct.POINTER(ct.c_float*3), ct.POINTER(ct.c_double),ct.c_bool,ct.c_bool) 11 lib_py_gel.GLManifoldViewer_get_annotation_points.restype = ct.c_size_t 12 lib_py_gel.GLManifoldViewer_get_annotation_points.argtypes = (ct.c_void_p, ct.POINTER(ct.POINTER(ct.c_double))) 13 lib_py_gel.GLManifoldViewer_set_annotation_points.argtypes = (ct.c_void_p, ct.c_int, ct.POINTER(ct.c_double)) 14 lib_py_gel.GLManifoldViewer_event_loop.argtypes = (ct.c_bool,) 15 class Viewer: 16 """ An OpenGL Viewer for Manifolds and Graphs. Having created an instance of this 17 class, call display to show a mesh or a graph. The display function is flexible, 18 allowing several types of interactive visualization. Each instance of this 19 class corresponds to a single window, but you can have several 20 GLManifoldViewer and hence also several windows showing different 21 visualizations. """ 22 def __init__(self): 23 current_directory = getcwd() 24 self.obj = lib_py_gel.GLManifoldViewer_new() 25 chdir(current_directory) # Necessary because init_glfw changes cwd 26 def __del__(self): 27 lib_py_gel.GLManifoldViewer_delete(self.obj) 28 def display(self, m, g=None, mode='w', smooth=True, bg_col=[0.3,0.3,0.3], data=None, reset_view=False, once=False): 29 """ Display a mesh 30 31 Args: 32 --- 33 - m : the Manifold mesh or Graph we want to show. 34 - g : the Graph we want to show. If you only want to show a graph, you 35 can simply pass the graph as m, so the g argument is relevant only if 36 you need to show both a Manifold _and_ a Graph. 37 - mode : a single character that determines how the mesh is visualized: 38 'w' - wireframe, 39 'i' - isophote, 40 'g' - glazed (try it and see), 41 's' - scalar field, 42 'l' - line field, 43 'n' - normal. 44 'x' - xray or ghost rendering. Useful to show Manifold on top of Graph 45 - smooth : if True we use vertex normals. Otherwise, face normals. 46 - bg_col : background color. 47 - data : per vertex data for visualization. scalar or vector field. 48 - reset_view : if False view is as left in the previous display call. If 49 True, the view is reset to the default. 50 - once : if True we immediately exit the event loop and return. However, 51 the window stays and if the event loop is called from this or any 52 other viewer, the window will still be responsive. 53 54 Interactive controls: 55 --- 56 When a viewer window is displayed on the screen, you can naviagate with 57 the mouse: Left mouse button rotates, right mouse button is used for 58 zooming and (if shift is pressed) for panning. If you hold control, any 59 mouse button will pick a point on the 3D model. Up to 19 of these points 60 have unique colors. If you pick an already placed annotation point it 61 will be removed and can now be placed elsewhere. Hit space bar to clear 62 the annotation points. Hitting ESC exits the event loop causing control 63 to return to the script. 64 """ 65 data_ct = np.array(data,dtype=ct.c_double).ctypes 66 data_a = data_ct.data_as(ct.POINTER(ct.c_double)) 67 bg_col_ct = np.array(bg_col,dtype=ct.c_float).ctypes 68 bg_col_a = bg_col_ct.data_as(ct.POINTER(ct.c_float*3)) 69 if isinstance(m,graph.Graph): 70 g = m 71 m = None 72 if isinstance(m,hmesh.Manifold) and isinstance(g,graph.Graph): 73 lib_py_gel.GLManifoldViewer_display(self.obj, m.obj, g.obj, ct.c_char(mode.encode('ascii')),smooth,bg_col_a,data_a,reset_view,once) 74 elif isinstance(m,hmesh.Manifold): 75 lib_py_gel.GLManifoldViewer_display(self.obj, m.obj, 0, ct.c_char(mode.encode('ascii')),smooth,bg_col_a,data_a,reset_view,once) 76 elif isinstance(g,graph.Graph): 77 lib_py_gel.GLManifoldViewer_display(self.obj, 0, g.obj, ct.c_char(mode.encode('ascii')),smooth,bg_col_a,data_a,reset_view,once) 78 79 def annotation_points(self): 80 """ Retrieve a vector of annotation points. This vector is not a copy, 81 so any changes made to the points will be reflected in the viewer. """ 82 pos = ct.POINTER(ct.c_double)() 83 n = lib_py_gel.GLManifoldViewer_get_annotation_points(self.obj, ct.byref(pos)) 84 if n == 0: 85 return None 86 return np.ctypeslib.as_array(pos,(n,3)) 87 def set_annotation_points(self, pts): 88 n = int(np.size(pts)/3) 89 pts_ct = np.array(pts,dtype=ct.c_double).ctypes 90 pts_a = pts_ct.data_as(ct.POINTER(ct.c_double)) 91 lib_py_gel.GLManifoldViewer_set_annotation_points(self.obj, n, pts_a) 92 @staticmethod 93 def event_loop(): 94 """ Explicit call to the event loop. This function enters the event loop. 95 Call it if you want to turn on interactivity in the currently displayed 96 window.""" 97 lib_py_gel.GLManifoldViewer_event_loop(False) 98except AttributeError: 99 pass
16 class Viewer: 17 """ An OpenGL Viewer for Manifolds and Graphs. Having created an instance of this 18 class, call display to show a mesh or a graph. The display function is flexible, 19 allowing several types of interactive visualization. Each instance of this 20 class corresponds to a single window, but you can have several 21 GLManifoldViewer and hence also several windows showing different 22 visualizations. """ 23 def __init__(self): 24 current_directory = getcwd() 25 self.obj = lib_py_gel.GLManifoldViewer_new() 26 chdir(current_directory) # Necessary because init_glfw changes cwd 27 def __del__(self): 28 lib_py_gel.GLManifoldViewer_delete(self.obj) 29 def display(self, m, g=None, mode='w', smooth=True, bg_col=[0.3,0.3,0.3], data=None, reset_view=False, once=False): 30 """ Display a mesh 31 32 Args: 33 --- 34 - m : the Manifold mesh or Graph we want to show. 35 - g : the Graph we want to show. If you only want to show a graph, you 36 can simply pass the graph as m, so the g argument is relevant only if 37 you need to show both a Manifold _and_ a Graph. 38 - mode : a single character that determines how the mesh is visualized: 39 'w' - wireframe, 40 'i' - isophote, 41 'g' - glazed (try it and see), 42 's' - scalar field, 43 'l' - line field, 44 'n' - normal. 45 'x' - xray or ghost rendering. Useful to show Manifold on top of Graph 46 - smooth : if True we use vertex normals. Otherwise, face normals. 47 - bg_col : background color. 48 - data : per vertex data for visualization. scalar or vector field. 49 - reset_view : if False view is as left in the previous display call. If 50 True, the view is reset to the default. 51 - once : if True we immediately exit the event loop and return. However, 52 the window stays and if the event loop is called from this or any 53 other viewer, the window will still be responsive. 54 55 Interactive controls: 56 --- 57 When a viewer window is displayed on the screen, you can naviagate with 58 the mouse: Left mouse button rotates, right mouse button is used for 59 zooming and (if shift is pressed) for panning. If you hold control, any 60 mouse button will pick a point on the 3D model. Up to 19 of these points 61 have unique colors. If you pick an already placed annotation point it 62 will be removed and can now be placed elsewhere. Hit space bar to clear 63 the annotation points. Hitting ESC exits the event loop causing control 64 to return to the script. 65 """ 66 data_ct = np.array(data,dtype=ct.c_double).ctypes 67 data_a = data_ct.data_as(ct.POINTER(ct.c_double)) 68 bg_col_ct = np.array(bg_col,dtype=ct.c_float).ctypes 69 bg_col_a = bg_col_ct.data_as(ct.POINTER(ct.c_float*3)) 70 if isinstance(m,graph.Graph): 71 g = m 72 m = None 73 if isinstance(m,hmesh.Manifold) and isinstance(g,graph.Graph): 74 lib_py_gel.GLManifoldViewer_display(self.obj, m.obj, g.obj, ct.c_char(mode.encode('ascii')),smooth,bg_col_a,data_a,reset_view,once) 75 elif isinstance(m,hmesh.Manifold): 76 lib_py_gel.GLManifoldViewer_display(self.obj, m.obj, 0, ct.c_char(mode.encode('ascii')),smooth,bg_col_a,data_a,reset_view,once) 77 elif isinstance(g,graph.Graph): 78 lib_py_gel.GLManifoldViewer_display(self.obj, 0, g.obj, ct.c_char(mode.encode('ascii')),smooth,bg_col_a,data_a,reset_view,once) 79 80 def annotation_points(self): 81 """ Retrieve a vector of annotation points. This vector is not a copy, 82 so any changes made to the points will be reflected in the viewer. """ 83 pos = ct.POINTER(ct.c_double)() 84 n = lib_py_gel.GLManifoldViewer_get_annotation_points(self.obj, ct.byref(pos)) 85 if n == 0: 86 return None 87 return np.ctypeslib.as_array(pos,(n,3)) 88 def set_annotation_points(self, pts): 89 n = int(np.size(pts)/3) 90 pts_ct = np.array(pts,dtype=ct.c_double).ctypes 91 pts_a = pts_ct.data_as(ct.POINTER(ct.c_double)) 92 lib_py_gel.GLManifoldViewer_set_annotation_points(self.obj, n, pts_a) 93 @staticmethod 94 def event_loop(): 95 """ Explicit call to the event loop. This function enters the event loop. 96 Call it if you want to turn on interactivity in the currently displayed 97 window.""" 98 lib_py_gel.GLManifoldViewer_event_loop(False)
An OpenGL Viewer for Manifolds and Graphs. Having created an instance of this class, call display to show a mesh or a graph. The display function is flexible, allowing several types of interactive visualization. Each instance of this class corresponds to a single window, but you can have several GLManifoldViewer and hence also several windows showing different visualizations.
29 def display(self, m, g=None, mode='w', smooth=True, bg_col=[0.3,0.3,0.3], data=None, reset_view=False, once=False): 30 """ Display a mesh 31 32 Args: 33 --- 34 - m : the Manifold mesh or Graph we want to show. 35 - g : the Graph we want to show. If you only want to show a graph, you 36 can simply pass the graph as m, so the g argument is relevant only if 37 you need to show both a Manifold _and_ a Graph. 38 - mode : a single character that determines how the mesh is visualized: 39 'w' - wireframe, 40 'i' - isophote, 41 'g' - glazed (try it and see), 42 's' - scalar field, 43 'l' - line field, 44 'n' - normal. 45 'x' - xray or ghost rendering. Useful to show Manifold on top of Graph 46 - smooth : if True we use vertex normals. Otherwise, face normals. 47 - bg_col : background color. 48 - data : per vertex data for visualization. scalar or vector field. 49 - reset_view : if False view is as left in the previous display call. If 50 True, the view is reset to the default. 51 - once : if True we immediately exit the event loop and return. However, 52 the window stays and if the event loop is called from this or any 53 other viewer, the window will still be responsive. 54 55 Interactive controls: 56 --- 57 When a viewer window is displayed on the screen, you can naviagate with 58 the mouse: Left mouse button rotates, right mouse button is used for 59 zooming and (if shift is pressed) for panning. If you hold control, any 60 mouse button will pick a point on the 3D model. Up to 19 of these points 61 have unique colors. If you pick an already placed annotation point it 62 will be removed and can now be placed elsewhere. Hit space bar to clear 63 the annotation points. Hitting ESC exits the event loop causing control 64 to return to the script. 65 """ 66 data_ct = np.array(data,dtype=ct.c_double).ctypes 67 data_a = data_ct.data_as(ct.POINTER(ct.c_double)) 68 bg_col_ct = np.array(bg_col,dtype=ct.c_float).ctypes 69 bg_col_a = bg_col_ct.data_as(ct.POINTER(ct.c_float*3)) 70 if isinstance(m,graph.Graph): 71 g = m 72 m = None 73 if isinstance(m,hmesh.Manifold) and isinstance(g,graph.Graph): 74 lib_py_gel.GLManifoldViewer_display(self.obj, m.obj, g.obj, ct.c_char(mode.encode('ascii')),smooth,bg_col_a,data_a,reset_view,once) 75 elif isinstance(m,hmesh.Manifold): 76 lib_py_gel.GLManifoldViewer_display(self.obj, m.obj, 0, ct.c_char(mode.encode('ascii')),smooth,bg_col_a,data_a,reset_view,once) 77 elif isinstance(g,graph.Graph): 78 lib_py_gel.GLManifoldViewer_display(self.obj, 0, g.obj, ct.c_char(mode.encode('ascii')),smooth,bg_col_a,data_a,reset_view,once)
Display a mesh
Args:
- m : the Manifold mesh or Graph we want to show.
- g : the Graph we want to show. If you only want to show a graph, you can simply pass the graph as m, so the g argument is relevant only if you need to show both a Manifold _and_ a Graph.
- mode : a single character that determines how the mesh is visualized: 'w' - wireframe, 'i' - isophote, 'g' - glazed (try it and see), 's' - scalar field, 'l' - line field, 'n' - normal. 'x' - xray or ghost rendering. Useful to show Manifold on top of Graph
- smooth : if True we use vertex normals. Otherwise, face normals.
- bg_col : background color.
- data : per vertex data for visualization. scalar or vector field.
- reset_view : if False view is as left in the previous display call. If True, the view is reset to the default.
- once : if True we immediately exit the event loop and return. However, the window stays and if the event loop is called from this or any other viewer, the window will still be responsive.
Interactive controls:
When a viewer window is displayed on the screen, you can naviagate with the mouse: Left mouse button rotates, right mouse button is used for zooming and (if shift is pressed) for panning. If you hold control, any mouse button will pick a point on the 3D model. Up to 19 of these points have unique colors. If you pick an already placed annotation point it will be removed and can now be placed elsewhere. Hit space bar to clear the annotation points. Hitting ESC exits the event loop causing control to return to the script.
80 def annotation_points(self): 81 """ Retrieve a vector of annotation points. This vector is not a copy, 82 so any changes made to the points will be reflected in the viewer. """ 83 pos = ct.POINTER(ct.c_double)() 84 n = lib_py_gel.GLManifoldViewer_get_annotation_points(self.obj, ct.byref(pos)) 85 if n == 0: 86 return None 87 return np.ctypeslib.as_array(pos,(n,3))
Retrieve a vector of annotation points. This vector is not a copy, so any changes made to the points will be reflected in the viewer.
93 @staticmethod 94 def event_loop(): 95 """ Explicit call to the event loop. This function enters the event loop. 96 Call it if you want to turn on interactivity in the currently displayed 97 window.""" 98 lib_py_gel.GLManifoldViewer_event_loop(False)
Explicit call to the event loop. This function enters the event loop. Call it if you want to turn on interactivity in the currently displayed window.