Skip to content

Commit

Permalink
Use PyVista for displaying VRML files
Browse files Browse the repository at this point in the history
One file at a time until pyvista/pyvista#4475
is fixed
  • Loading branch information
Simon Rit committed May 30, 2023
1 parent 860b1d7 commit 28ce722
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 63 deletions.
10 changes: 0 additions & 10 deletions TP-Rayons-X.ipynb
@@ -1,15 +1,5 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from IPython.core.display import display, HTML\n",
"display(HTML(\"<style>.container { width:100% !important; }</style>\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
64 changes: 11 additions & 53 deletions TPFunctions.py
Expand Up @@ -9,9 +9,7 @@
sys.path.append(new_path)
new_path = r'/usr/local/progs/gate/gate-9.1-install/bin/'
sys.path.append(new_path)
from IPython.display import IFrame
from IPython.core.display import display, HTML
from bs4 import BeautifulSoup

import xraylib as xrl
import matplotlib.pyplot as plt
import matplotlib as mpl
Expand All @@ -21,61 +19,21 @@
import gatetools.phsp as phsp
import gatetools as gt
import logging
import pyvista

def DisplayGate(material1,material2,cwd):
pxheight=800
# Create html file for the simulation
html_file = open("simulation.html", "w")
with open(f'{cwd}/g4_01.wrl', 'r') as file:
wrl_data = file.read()
data = {'input_encoding': 'CLASSIC',
'output_encoding': 'HTML5',
'input_code': wrl_data}
API_ENDPOINT = "https://doc.instantreality.org/tools/x3d_encoding_converter/convert/"
r = requests.post(url=API_ENDPOINT, data=data, verify=False)
soup = BeautifulSoup(r.text, features='html.parser')
soup = BeautifulSoup(soup.find('div', {'class': 'source'}).text, features='html.parser')
soup.link["href"]="https://www.x3dom.org/x3dom/release/x3dom.css"
soup.script["src"]="https://www.x3dom.org/x3dom/release/x3dom.js"
soup.x3d["width"]="100%"
soup.x3d["height"]=f"{pxheight}px"
soup.style="float:left;"
pl = pyvista.Plotter()
pl.import_vrml(f'{cwd}/g4_01.wrl')
pl.add_text(material1, font_size=30)
pl.show()

if os.path.exists(f'{cwd}/g4_03.wrl'):
with open(f'{cwd}/g4_03.wrl', 'r') as file:
wrl_data = file.read()
data = {'input_encoding': 'CLASSIC',
'output_encoding': 'HTML5',
'input_code': wrl_data}
API_ENDPOINT = "https://doc.instantreality.org/tools/x3d_encoding_converter/convert/"
r = requests.post(url=API_ENDPOINT, data=data)
soup2 = BeautifulSoup(r.text, features='html.parser')
soup2 = BeautifulSoup(soup2.find('div', {'class': 'source'}).text, features='html.parser')
soup2.x3d["width"]="100%"
soup2.x3d["height"]=f"{pxheight}px"
pl = pyvista.Plotter()
pl.import_vrml(f'{cwd}/g4_03.wrl')
pl.add_text(material2, font_size=30)
pl.show()

style = soup.new_tag("style")
style.string = ".split { height: 100%; width: 50%; position: fixed; top: 0; } .left { left: 0; } .right { right: 0; border-left: 3px solid black; }"
soup.head.append(style)

left = soup.new_tag("div")
if os.path.exists(f'{cwd}/g4_03.wrl'):
left["class"] = "split left"
left.append(material1)
left.append(soup.x3d)
if os.path.exists(f'{cwd}/g4_03.wrl'):
right = soup.new_tag("div")
right["class"] = "split right"
right.append(material2)
right.append(soup2.x3d)
soup.body.clear()
soup.body.append(left)
if os.path.exists(f'{cwd}/g4_03.wrl'):
soup.body.append(right)

html_file.write(soup.prettify())
html_file.close()
display(HTML("<style>.container { width:100% !important; }</style>"))
display(IFrame(src='./simulation.html', width="100%", align="left", height=pxheight))

def DisplayPhSp(material1,material2,cwd):
logger = logging.getLogger(__name__)
Expand Down

0 comments on commit 28ce722

Please sign in to comment.