Skip to content

Commit

Permalink
Using tkinter_gl for the inside view.
Browse files Browse the repository at this point in the history
  • Loading branch information
unhyperbolic committed Jan 31, 2024
1 parent 82d819b commit abf1b10
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 53 deletions.
2 changes: 2 additions & 0 deletions opengl/CyOpenGL.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ from math import sqrt, ceil, floor, pi, sin, cos, tan
from random import random
import time

from tkinter_gl import GLCanvas

Togl_dir = os.path.abspath(os.path.dirname(togl.__file__))

import tkinter as Tk_
Expand Down
36 changes: 21 additions & 15 deletions opengl/modern/simple_image_shader_widget.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class SimpleImageShaderWidget(RawOpenGLWidget):
class SimpleImageShaderWidget(GLCanvas):
"""
An image shader is a GLSL program that does all of its computation in
the fragment shader.
Expand Down Expand Up @@ -41,9 +41,10 @@ class SimpleImageShaderWidget(RawOpenGLWidget):
}
"""

def __init__(self, master,
**kw):
RawOpenGLWidget.__init__(self, master, **kw)
report_gl_errors = False

def __init__(self, parent, **kw):
super().__init__(parent, **kw)

self._vertex_buffer = VertexBuffer()
self._vertex_buffer.load(((3,-1), (-1,3), (-1,-1)))
Expand Down Expand Up @@ -153,8 +154,7 @@ class SimpleImageShaderWidget(RawOpenGLWidget):
raise Exception("Incomplete framebuffer")

# Render into the framebuffer
self.redraw(width, height,
skip_swap_buffers = True)
self.draw_impl(width, height)
glFinish()

# Allocate memory and read framebuffer into it
Expand Down Expand Up @@ -208,9 +208,8 @@ class SimpleImageShaderWidget(RawOpenGLWidget):

self.make_current()

self.redraw(width, height,
skip_swap_buffers = True,
include_depth_value = True)
self.draw_impl(width, height,
include_depth_value = True)
glFinish()

glReadPixels(x, height - y, 1, 1,
Expand All @@ -219,10 +218,9 @@ class SimpleImageShaderWidget(RawOpenGLWidget):

return (depth, width, height)

def redraw(self, width, height,
skip_swap_buffers = False,
include_depth_value = False):

def draw_impl(self, width, height,
include_depth_value = False):

if self.report_time_callback:
start_time = time.time()

Expand Down Expand Up @@ -260,8 +258,16 @@ class SimpleImageShaderWidget(RawOpenGLWidget):
glFinish()
self.report_time_callback(time.time() - start_time)

if not skip_swap_buffers:
self.swap_buffers()
def draw(self):
width = self.winfo_width()
height = self.winfo_height()

self.make_current()
self.draw_impl(width, height)
self.swap_buffers()

if self.report_gl_errors:
print_gl_errors("draw")

def get_uniform_bindings(self, view_width, view_height):
return {
Expand Down
26 changes: 13 additions & 13 deletions python/raytracing/finite_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self, container, manifold,

UniformDictController(
self.widget.ui_parameter_dict, 'fov',
update_function=self.widget.redraw_if_initialized,
update_function=self.widget.draw,
scale=self.fov_scale,
label=self.fov_label,
format_string='%.1f')
Expand Down Expand Up @@ -121,7 +121,7 @@ def create_cusp_areas_frame(self, parent):
return frame

def checkbox_update(self):
self.widget.redraw_if_initialized()
self.widget.draw()
self.focus_viewer()

def create_fillings_frame(self, parent):
Expand Down Expand Up @@ -207,7 +207,7 @@ def create_skeleton_frame(self, parent):
row=row,
left_end=0.0,
right_end=0.35,
update_function=self.widget.redraw_if_initialized,
update_function=self.widget.draw,
format_string='%.3f')

row += 1
Expand All @@ -219,7 +219,7 @@ def create_skeleton_frame(self, parent):
row=row,
left_end=0.0,
right_end=1.35,
update_function=self.widget.redraw_if_initialized,
update_function=self.widget.draw,
format_string='%.3f')

row += 1
Expand All @@ -231,7 +231,7 @@ def create_skeleton_frame(self, parent):
row=row,
left_end=0.0,
right_end=0.5,
update_function=self.widget.redraw_if_initialized)
update_function=self.widget.draw)

return frame

Expand All @@ -251,7 +251,7 @@ def create_quality_frame(self, parent):
row=row,
left_end=1,
right_end=100,
update_function=self.widget.redraw_if_initialized)
update_function=self.widget.draw)

row += 1
UniformDictController.create_horizontal_scale(
Expand All @@ -262,7 +262,7 @@ def create_quality_frame(self, parent):
row=row,
left_end=1.0,
right_end=28.0,
update_function=self.widget.redraw_if_initialized)
update_function=self.widget.draw)

row += 1
UniformDictController.create_horizontal_scale(
Expand All @@ -273,7 +273,7 @@ def create_quality_frame(self, parent):
row=row,
left_end=1.0,
right_end=4.25,
update_function=self.widget.redraw_if_initialized)
update_function=self.widget.draw)

return frame

Expand All @@ -295,7 +295,7 @@ def create_light_frame(self, parent):
row=row,
left_end=0.0,
right_end=0.25,
update_function=self.widget.redraw_if_initialized,
update_function=self.widget.draw,
format_string='%.3f')
row += 1

Expand All @@ -307,7 +307,7 @@ def create_light_frame(self, parent):
row=row,
left_end=0.3,
right_end=4.0,
update_function=self.widget.redraw_if_initialized)
update_function=self.widget.draw)

row += 1
UniformDictController.create_horizontal_scale(
Expand All @@ -318,7 +318,7 @@ def create_light_frame(self, parent):
row=row,
left_end=0.1,
right_end=2.0,
update_function=self.widget.redraw_if_initialized)
update_function=self.widget.draw)

row += 1
UniformDictController.create_horizontal_scale(
Expand All @@ -329,7 +329,7 @@ def create_light_frame(self, parent):
row=row,
left_end=0.3,
right_end=3.0,
update_function=self.widget.redraw_if_initialized)
update_function=self.widget.draw)

return frame

Expand Down Expand Up @@ -578,7 +578,7 @@ def redraw(self):
self.widget.view_state = self.widget.raytracing_data.update_view_state(
self.widget.view_state, self.m)

self.widget.redraw_if_initialized()
self.widget.draw()
self.widget.after(250, self.redraw)


Expand Down
8 changes: 4 additions & 4 deletions python/raytracing/hyperboloid_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class HyperboloidNavigation:
IdealRaytracingData. This is needed to update data
such as the view matrix
using self.raytracing_data.update_view_state(...).
- self.redraw_if_initialized() to redraw.
- self.draw() to redraw.
- self.read_depth_value(x, y) to return the depth value at a pixel.
It is used for orbiting about that point.
- self.compute_translation_and_inverse_from_pick_point(size, xy, depth)
Expand Down Expand Up @@ -317,7 +317,7 @@ def process_key_events_and_redraw(self):
self.view_state, m)

# Redraw
self.redraw_if_initialized()
self.draw()

# And schedule another call of this function.
# If we don't leave Tk a couple of milliseconds in between,
Expand Down Expand Up @@ -383,7 +383,7 @@ def tkKeyPress(self, event):
self.view = (self.view + 1) % 3
print("Color for rays that have not hit geometry:",
_viewModes[self.view])
self.redraw_if_initialized()
self.draw()

if event.keysym == 'p':
from snappy.CyOpenGL import get_gl_string
Expand Down Expand Up @@ -507,7 +507,7 @@ def tkButtonMotion1(self, event):
else:
return

self.redraw_if_initialized()
self.draw()

def tkButtonRelease1(self, event):
self.mouse_mode = None
Expand Down
32 changes: 16 additions & 16 deletions python/raytracing/inside_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self, container, manifold,
self.view_scale_slider,
self.view_scale_label,
self.view_scale_value_label,
update_function=self.widget.redraw_if_initialized)
update_function=self.widget.draw)

self.widget.report_time_callback = FpsLabelUpdater(
self.fps_label)
Expand Down Expand Up @@ -230,7 +230,7 @@ def create_cusps_frame(self, parent):

def perspective_type_changed(self):
self.view_scale_controller.update()
self.widget.redraw_if_initialized()
self.widget.draw()

def set_perspective_type_and_view_scale(self, perspective_type, view_scale):
self.widget.ui_uniform_dict['perspectiveType'][1] = perspective_type
Expand All @@ -252,7 +252,7 @@ def set_camera_cusp_view(self, which_cusp):
self.set_perspective_type_and_view_scale(1, extra_scale * view_scale)

def checkbox_update(self):
self.widget.redraw_if_initialized()
self.widget.draw()
self.focus_viewer()

def create_fillings_frame(self, parent):
Expand Down Expand Up @@ -420,7 +420,7 @@ def create_eyeball_frame(self, parent):
text='Freeze camera body',
row=row,
column=0,
update_function=self.widget.redraw_if_initialized,
update_function=self.widget.draw,
gridargs = {'padx' : 8}).checkbox
ToolTip(freeze_checkbox,
msg=("Keep paper plane/eyeball at the same position "
Expand All @@ -434,7 +434,7 @@ def create_eyeball_frame(self, parent):
text='Crosshairs',
row=row,
column=1,
update_function=self.widget.redraw_if_initialized,
update_function=self.widget.draw,
gridargs = {'padx' : 8})

row += 1
Expand All @@ -458,7 +458,7 @@ def create_skeleton_frame(self, parent):
row=row,
left_end=0.0,
right_end=0.35,
update_function=self.widget.redraw_if_initialized,
update_function=self.widget.draw,
format_string='%.3f').scale
ToolTip(scale,
msg=("Partially show faces of the tetrahedra."))
Expand Down Expand Up @@ -486,7 +486,7 @@ def create_skeleton_frame(self, parent):
row=row,
left_end=0.0,
right_end=0.2,
update_function=self.widget.redraw_if_initialized,
update_function=self.widget.draw,
format_string='%.3f'))
row += 1

Expand All @@ -499,7 +499,7 @@ def create_skeleton_frame(self, parent):
text='desaturate',
row=row,
column=1,
update_function=self.widget.redraw_if_initialized)
update_function=self.widget.draw)
row += 1

return frame
Expand All @@ -520,7 +520,7 @@ def create_quality_frame(self, parent):
row=row,
left_end=1,
right_end=150,
update_function=self.widget.redraw_if_initialized)
update_function=self.widget.draw)

row += 1
UniformDictController.create_horizontal_scale(
Expand All @@ -531,7 +531,7 @@ def create_quality_frame(self, parent):
row=row,
left_end=1.0,
right_end=28.0,
update_function=self.widget.redraw_if_initialized)
update_function=self.widget.draw)

row += 1
UniformDictController.create_horizontal_scale(
Expand All @@ -542,7 +542,7 @@ def create_quality_frame(self, parent):
row=row,
left_end=1.0,
right_end=4.25,
update_function=self.widget.redraw_if_initialized)
update_function=self.widget.draw)

return frame

Expand All @@ -564,7 +564,7 @@ def create_light_frame(self, parent):
row=row,
left_end=0.0,
right_end=0.25,
update_function=self.widget.redraw_if_initialized,
update_function=self.widget.draw,
format_string='%.3f')
row += 1

Expand All @@ -576,7 +576,7 @@ def create_light_frame(self, parent):
row=row,
left_end=0.3,
right_end=4.0,
update_function=self.widget.redraw_if_initialized)
update_function=self.widget.draw)

row += 1
UniformDictController.create_horizontal_scale(
Expand All @@ -587,7 +587,7 @@ def create_light_frame(self, parent):
row=row,
left_end=0.1,
right_end=2.0,
update_function=self.widget.redraw_if_initialized)
update_function=self.widget.draw)

row += 1
UniformDictController.create_horizontal_scale(
Expand All @@ -598,7 +598,7 @@ def create_light_frame(self, parent):
row=row,
left_end=0.3,
right_end=3.0,
update_function=self.widget.redraw_if_initialized)
update_function=self.widget.draw)

return frame

Expand Down Expand Up @@ -944,7 +944,7 @@ def redraw(self):
self.widget.view_state = self.widget.raytracing_data.update_view_state(
self.widget.view_state, self.m)

self.widget.redraw_if_initialized()
self.widget.draw()
self.widget.after(250, self.redraw)


Expand Down
Loading

0 comments on commit abf1b10

Please sign in to comment.