Skip to content

Commit

Permalink
PR for 134
Browse files Browse the repository at this point in the history
  • Loading branch information
ryliewalsh authored Mar 23, 2024
1 parent 5226606 commit 3607bed
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 230 deletions.
53 changes: 5 additions & 48 deletions GoVizzy/GoVizzy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,60 +24,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "09026008-ce47-49d7-9fca-4b7c123022d1",
"metadata": {},
"outputs": [],
"source": [
"from widgets import form\n",
"from GoVizzy import plotting, meshes\n",
"from UI import DisplayUI\n",
"import fileInput\n",
"import ipyvolume as ipv\n",
"import numpy as np\n",
"from cube_viskit import Cube"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "67faad66-2beb-4746-b0a4-21689ddc78d3",
"metadata": {},
"outputs": [],
"source": [
"%run Main.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ef52d91c-9d81-41db-953b-78f7ef718f24",
"metadata": {},
"outputs": [],
"source": [
"# Load Cube File\n",
"cube: Cube = Cube()\n",
"cube.load_cube(\"data/rhopol.cube\")\n",
"visualizer = plotting.Visualizer(cube)\n",
"# Display Cube File\n",
"visualizer.display_cell()\n",
"meshes.plot_atoms(cube)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "863d988e-36c3-463b-9b3f-d68e27ceb757",
"metadata": {},
"outputs": [],

"source": [
"form"
"%run Main.py\n"
]
},
{
"cell_type": "code",
"execution_count": null,

"id": "ac529fb6-4f90-487b-8241-bf87dd1d14f3",

"metadata": {},
"outputs": [],
"source": []
Expand All @@ -99,7 +56,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion GoVizzy/GoVizzy/meshes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from widgets import color
from UI.widgets import color
from cube_viskit import Cube
import ipywidgets as widgets
import ipyvolume as ipv
Expand Down
10 changes: 5 additions & 5 deletions GoVizzy/GoVizzy/plotting.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from widgets import color, slice_x_slider, slice_y_slider, slice_z_slider
from UI.widgets import color, slice_x_slider, slice_y_slider, slice_z_slider
from cube_viskit import Cube
import ipywidgets as widgets
import ipyvolume as ipv
Expand Down Expand Up @@ -96,9 +96,9 @@ def display_cell(self):
"""
cube = self.cube
ipv.figure()
transfer = ipv.pylab.transfer_function(level=[0.03, 0.5, 0.47], opacity=[0.05, 0.09, 0.1], level_width=0.1, controls=True)
transfer = ipv.pylab.transfer_function(level=[0.03, 0.5, 0.47], opacity=[0.05, 0.09, 0.1], level_width=0.1, controls=False)
ipv.style.background_color(color.value)
ipv.pylab.volshow(cube.data3D, ambient_coefficient=0.8, lighting=True, tf=transfer, controls=True)
ipv.pylab.volshow(cube.data3D, ambient_coefficient=0.8, lighting=True, tf=transfer, controls=False)
ipv.show()

def display_cell_slices(self):
Expand All @@ -108,9 +108,9 @@ def display_cell_slices(self):
"""
cube = self.cube
fig = ipv.figure()
transfer = ipv.pylab.transfer_function(level=[0.03, 0.5, 0.47], opacity=[0.05, 0.09, 0.1], level_width=0.1, controls=True)
transfer = ipv.pylab.transfer_function(level=[0.03, 0.5, 0.47], opacity=[0.05, 0.09, 0.1], level_width=0.1, controls=False)
ipv.style.background_color(color.value)
volume = ipv.pylab.volshow(cube.data3D, ambient_coefficient=0.8, lighting=True, tf=transfer, controls=True)
volume = ipv.pylab.volshow(cube.data3D, ambient_coefficient=0.8, lighting=True, tf=transfer, controls=False)

# Create planes, with textures set to the volume info
slice_x = ipv.plot_plane('x', volume=volume, description="Slice X", description_color="black", icon="mdi-knife", x_offset=70)
Expand Down
11 changes: 5 additions & 6 deletions GoVizzy/Main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fileInput
from GoVizzy import fileInput
import ipywidgets as widgets
import os
import cube_viskit as cv
Expand All @@ -10,15 +10,14 @@
import sys



# Define a text input widget
file_input = widgets.Text(description='File Name:')

# Define a submit button widget
submit_button = widgets.Button(description='Submit')

# Define the app layout
options = ['Static Image', 'Grid Points', 'Volumetric']


display_box = Output(layout=Layout(width="70%", height="100px"))
additional_box = Output(layout=Layout(width="30%", height="300px"))
Expand All @@ -38,17 +37,17 @@ def handle_submit_button_clicked(b):
new_cube.load_cube(destination_path)
DisplayUI.show_ui()
DisplayUI.display_cube(new_cube)
DisplayUI.display_app(display_box, additional_box)
DisplayUI.display_cell_data(new_cube)
DisplayUI.display_app()
file_input.layout.visibility = 'hidden' # Hide the file input widget
submit_button.layout.visibility = 'hidden' # Hide the submit button widget


# Handlers for dropdown change and button clicks
DisplayUI.dropdown.observe(

lambda change: DisplayUI.handle_dropdown_change(change, new_cube),
names='value'
)
)
DisplayUI.newCube_button.on_click(handle_newCube_click)


Expand Down
159 changes: 83 additions & 76 deletions GoVizzy/UI/DisplayUI.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
from widgets import slice_x_slider, slice_y_slider, slice_z_slider
from UI.widgets import slice_x_slider, slice_y_slider, slice_z_slider
import ipywidgets as widgets
from ipywidgets import Dropdown, VBox, HBox, Output, ColorPicker, AppLayout, Layout, Label, Button
import ipyvolume as ipv
import matplotlib.pyplot as plt
import GoVizzy.plotting
from GoVizzy import plotting, meshes

# Define globals
selected_option = 'Volumetric'
options = ['Static Image', 'Grid Points', 'Volumetric']
dropdown = Dropdown(options=options, value=options[2], description='Options:')
large_box = Output(layout=Layout(width="75%", height="100px"))
selected_option ='Slice Options'
options = ['Slice Options', 'Mesh Options', 'Color Options']
dropdown = Dropdown(options=options, value=options[0], layout=Layout(margin='5px 0 0 5px'));
large_box = Output(layout=Layout(width="70%", height="100%"))
additional_box = Output(layout=Layout(width="200px", height="300px"))
slice_picker = Output(layout=Layout(width="200px", height="100px", border='1px solid black'))
slice_picker_descr = widgets.Label(value="Slice Picker", layout=Layout(margin='5px 0 0 5px'))
exit_button = widgets.Button(description='[X]', button_style='danger')
exit_button.layout.margin = '0 0 0 auto' # Add margin to the left to push it to the right


newCube_button = Button(description='New Cube Button', layout=Layout(width="200px", height="100px", border='1px solid black'))
newCube_button = Button(description='New Cube', layout=Layout(width="200px", height="100px", border='1px solid black'))
# Displays logo and hides the app output
def show_menu():

Expand All @@ -31,13 +30,13 @@ def show_menu():
large_box.clear_output(wait=True)
large_box.layout = Layout(width="100%", height="70%", justify_content="center", margin="0 0 5% 40%")

image_path = './gv.png'
image_path = './UI/gv.png'
image_data = plt.imread(image_path)
plt.figure()
plt.imshow(image_data)
plt.axis('off')
plt.show()
# display_app()

def show_ui():

Expand All @@ -49,94 +48,103 @@ def show_ui():
newCube_button.layout.visibility = 'visible'

def display_cube(cube):

visualizer = plotting.Visualizer(cube)
with large_box: # Capture output within large_box
# Clear previous content
large_box.clear_output()
large_box.layout = Layout(width="85%", height="70%")

large_box.layout = Layout(width="85%", height="100%")

if selected_option == 'Static Image':
display_static_image(cube)
elif selected_option == 'Grid Points':
display_cell_data(cube)
elif selected_option == 'Volumetric':
display_ipyvolume_plot(cube)

if selected_option == 'Slice Options':
visualizer.display_cell_slices()
with additional_box:
additional_box.clear_output(wait=True)
visualizer.display_cell_data()


elif selected_option == 'Mesh Options':
visualizer.display_cell()
origin = (50, 50, 50)
radius = 10
meshes.plot_sphere_surface(origin, radius)
additional_box.clear_output(wait=True)
elif selected_option == 'Color Options':
visualizer.display_cell()
with additional_box:
additional_box.clear_output(wait=True)
visualizer.display_cell_data()
else:
print("Invalid option selected")

def display_static_image(cube):
# Extract the cube data
data3D = cube.data3D

# Create a meshgrid for plotting
x, y, z = cube.grid[0], cube.grid[1], cube.grid[2]

# Create a figure and 3D axes
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# Plot cube data
ax.scatter(x, y, z, c=data3D.flatten(), cmap='viridis')

# Set axis labels
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

# Show plot
plt.show()

def display_cell_data(cube):
# Function to display cell data directly in the additional widget box
with additional_box:
additional_box.clear_output(wait=True)
visualizer = GoVizzy.plotting.Visualizer(cube)
visualizer.display_cell_data()

def display_ipyvolume_plot(cube):
#data3D = cube.data3D
#ipv.figure()
#ipv.pylab.volshow(data3D)
with large_box:
#ipv.show()
visualizer = GoVizzy.plotting.Visualizer(cube)
visualizer.display_cell_slices()



def display_app(large_box, additional_box):
def display_app():

# Attach the dropdown change handler

# Create a VBox for dropdown
dropdown_container = VBox([dropdown])
# Combine the Output widgets with their descriptions
slice_box = VBox([slice_picker_descr, slice_picker])
if selected_option == 'Slice Options':
#display slidersss TO DO

# Attach callback function to button click event
slice_box = VBox([slice_picker_descr, slice_x_slider, slice_y_slider, slice_z_slider])

menu_options = VBox([dropdown, slice_box, additional_box, newCube_button], layout=Layout(flex='1'))
display_box = HBox([large_box, menu_options])

slim_box = HBox([ exit_button])
slim_box.layout.width = '100%'
slim_box.layout.height = '20px'

slim_box.layout.justify_content = 'space-between'


app_layout = AppLayout(header=slim_box, left_sidebar=None, center=display_box,
footer=None, pane_heights=['20px', 1, '20px'])

elif selected_option == 'Mesh Options':
#display Mesh TO DO
menu_options = VBox([dropdown, additional_box, newCube_button], layout=Layout(flex='1'))
display_box = HBox([large_box, menu_options])

menu_options = VBox([dropdown, slice_box, additional_box, slice_x_slider, slice_y_slider, slice_z_slider, newCube_button], layout=Layout(flex='1'))
display_box = HBox([large_box, menu_options])
slim_box = HBox([ exit_button])
slim_box.layout.width = '100%'
slim_box.layout.height = '20px'

slim_box.layout.justify_content = 'space-between'


app_layout = AppLayout(header=slim_box, left_sidebar=None, center=display_box,
footer=None, pane_heights=['20px', 1, '20px'])

elif selected_option == 'Color Options':
#ADD color controls here


menu_options = VBox([dropdown, additional_box, newCube_button], layout=Layout(flex='1'))
display_box = HBox([large_box, menu_options])

slim_box = HBox([ exit_button])
slim_box.layout.width = '100%'
slim_box.layout.height = '20px'
slim_box = HBox([ exit_button])
slim_box.layout.width = '100%'
slim_box.layout.height = '20px'

slim_box.layout.justify_content = 'space-between'
slim_box.layout.justify_content = 'space-between'

# Define other buttons
#slim_bar = ColorPicker(concise=True, value='blue', description='Color', disabled=False, layout=Layout(width="50%", height="20px"))
large_box = Output(layout=Layout(width="75%", height="500px"))
# Create AppLayout
app_layout = AppLayout(header=slim_box, left_sidebar=None, center=display_box,

app_layout = AppLayout(header=slim_box, left_sidebar=None, center=display_box,
footer=None, pane_heights=['20px', 1, '20px'])

else:
print("Invalid option selected")

# Display the layout
display(app_layout)

# Call the display_app function
display_app(large_box, additional_box)

display_app()


def clear_all_outputs():
large_box.clear_output()
Expand All @@ -161,9 +169,8 @@ def handle_dropdown_change(change, cube):
large_box.clear_output(wait=True)

# Display the cube based on the selected option

display_cube(cube)
display_app()

# Update the app layout


dropdown.observe(handle_dropdown_change, names='value')

File renamed without changes
Loading

0 comments on commit 3607bed

Please sign in to comment.