Skip to content

Commit

Permalink
Merge pull request #9 from mimesis-inria/open3d
Browse files Browse the repository at this point in the history
Update Vedo and SSD versions.
  • Loading branch information
RobinEnjalbert authored Jan 27, 2023
2 parents 910411f + d7a7a0c commit fe20801
Show file tree
Hide file tree
Showing 24 changed files with 211 additions and 364 deletions.
80 changes: 39 additions & 41 deletions examples/demos/Armadillo/FC/Environment/ArmadilloInteractive.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def __init__(self,
self.selected = None
self.interactive_window = True
self.mouse_factor = 10 * p_model.scale
self.key_on = False
self.click_on = False

# Force fields
self.arrows = None
Expand Down Expand Up @@ -89,7 +91,7 @@ def create(self):
self.areas[-1].append(i)
# Create sphere at initial state
self.spheres_init.append(self.mesh_coarse.points(self.areas[-1]).mean(axis=0))
self.spheres.append(self.sphere(self.spheres_init[-1]))
self.spheres.append(self.sphere(self.spheres_init[-1]).alpha(0.5))

# Define fixed plane
mesh_y = self.mesh.points()[:, 1]
Expand All @@ -105,16 +107,13 @@ def create(self):
self.plotter.add(self.mesh)
self.plotter.add(Plane(pos=plane_origin, normal=[0, 1, 0], s=(10 * p_model.scale, 10 * p_model.scale),
c='darkred', alpha=0.2))
self.plotter.add(Text2D("Press 'Alt' to interact with the object.\n"
"Left click to select a sphere.\n"
"Right click to unselect a sphere.", s=0.75))
self.plotter.add(Text2D("Press 'b' to interact with the spheres / with the environment.\n"
"Left click to select / unselect a sphere.", s=0.75))

# Add callbacks
self.plotter.addCallback('KeyPress', self.key_press)
self.plotter.addCallback('KeyRelease', self.key_release)
self.plotter.addCallback('LeftButtonPress', self.left_button_press)
self.plotter.addCallback('RightButtonPress', self.right_button_press)
self.plotter.addCallback('MouseMove', self.mouse_move)
self.plotter.add_callback('KeyPress', self.key_press)
self.plotter.add_callback('LeftButtonPress', self.left_button_press)
self.plotter.add_callback('MouseMove', self.mouse_move)

async def step(self):

Expand All @@ -127,42 +126,39 @@ async def step(self):
def key_press(self, evt):

# Only react to an 'Alt' press
if 'alt' in evt.keyPressed.lower():
# Switch from environment to object interaction
self.plotter.interactor.SetInteractorStyle(vtk.vtkInteractorStyle3D())
self.interactive_window = False

def key_release(self, evt):

# Only react with an 'Alt' release
if 'alt' in evt.keyPressed.lower():
# Switch from object to environment interaction
self.plotter.interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
self.interactive_window = True
self.selected = None
# Reset all
self.update_mesh()
self.update_arrows()
self.update_spheres()
if 'b' in evt.keyPressed.lower():
self.key_on = not self.key_on
if self.key_on:
# Switch from environment to object interaction
self.plotter.interactor.SetInteractorStyle(vtk.vtkInteractorStyle3D())
self.interactive_window = False
self.update_spheres()
else:
# Switch from object to environment interaction
self.plotter.interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
self.interactive_window = True
self.selected = None
# Reset all
self.update_mesh()
self.update_arrows()
self.update_spheres()

def left_button_press(self, evt):

# Select a sphere only in object interaction mode
if not self.interactive_window:
# Pick a unique sphere
if evt.actor in self.spheres:
self.selected = self.spheres.index(evt.actor)
self.update_spheres(center=self.spheres_init[self.selected])

def right_button_press(self, evt):

# Unselect a sphere only in object interaction mode
if not self.interactive_window:
self.selected = None
# Reset all
self.update_mesh()
self.update_arrows()
self.update_spheres()
self.click_on = not self.click_on
if self.click_on:
# Pick a unique sphere
if evt.actor in self.spheres:
self.selected = self.spheres.index(evt.actor)
self.update_spheres(center=self.spheres_init[self.selected])
else:
self.selected = None
# Reset all
self.update_mesh()
self.update_arrows()
self.update_spheres()

def mouse_move(self, evt):

Expand Down Expand Up @@ -215,7 +211,9 @@ def update_spheres(self, center=None):
# Remove actual spheres
self.plotter.remove(*self.spheres)
# If no center provided, reset all the spheres
if center is None:
if self.interactive_window:
self.spheres = [self.sphere(c).alpha(0.5) for c in self.spheres_init]
elif center is None:
self.spheres = [self.sphere(c) for c in self.spheres_init]
# Otherwise, update the selected cell
else:
Expand Down
3 changes: 1 addition & 2 deletions examples/demos/Armadillo/FC/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from DeepPhysX.Core.Pipelines.BasePrediction import BasePrediction
from DeepPhysX.Core.Environment.BaseEnvironmentConfig import BaseEnvironmentConfig
from DeepPhysX.Core.Database.BaseDatabaseConfig import BaseDatabaseConfig
from DeepPhysX.Core.Visualization.VedoVisualizer import VedoVisualizer
from DeepPhysX.Torch.FC.FCConfig import FCConfig

# Session related imports
Expand All @@ -26,7 +25,7 @@ def launch_runner():

# Environment config
environment_config = BaseEnvironmentConfig(environment_class=Armadillo,
visualizer=VedoVisualizer)
visualizer='vedo')

# FC config
nb_hidden_layers = 3
Expand Down
3 changes: 1 addition & 2 deletions examples/demos/Armadillo/UNet/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from DeepPhysX.Core.Pipelines.BasePrediction import BasePrediction
from DeepPhysX.Core.Environment.BaseEnvironmentConfig import BaseEnvironmentConfig
from DeepPhysX.Core.Database.BaseDatabaseConfig import BaseDatabaseConfig
from DeepPhysX.Core.Visualization.VedoVisualizer import VedoVisualizer
from DeepPhysX.Torch.UNet.UNetConfig import UNetConfig

# Session related imports
Expand All @@ -26,7 +25,7 @@ def launch_runner():

# Environment config
environment_config = BaseEnvironmentConfig(environment_class=Armadillo,
visualizer=VedoVisualizer)
visualizer='vedo')

# UNet config
network_config = UNetConfig(input_size=grid_resolution,
Expand Down
76 changes: 37 additions & 39 deletions examples/demos/Beam/FC/Environment/BeamInteractive.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def __init__(self,
self.selected = None
self.interactive_window = True
self.mouse_factor = 10
self.key_on = False
self.click_on = False

# Force fields
self.arrows = None
Expand Down Expand Up @@ -87,7 +89,7 @@ def create(self):
for z in (np.min(self.mesh_init[:, 2]), np.max(self.mesh_init[:, 2])):
center = [x, y, z]
self.spheres_init.append(self.mesh_init.copy().tolist().index(center))
self.spheres.append(self.sphere(self.mesh.points()[self.spheres_init[-1]]))
self.spheres.append(self.sphere(self.mesh.points()[self.spheres_init[-1]]).alpha(0.5))
x_min, x_max = x - sx / 4, x + sx / 4
y_min, y_max = y - sy / 2, y + sy / 2
z_min, z_max = z - sz / 2, z + sz / 2
Expand All @@ -101,7 +103,7 @@ def create(self):
center = [sx / 2, sy / 2, sz / 2]
center[i] = a
self.spheres_init.append(self.mesh_init.copy().tolist().index(center))
self.spheres.append(self.sphere(self.mesh.points()[self.spheres_init[-1]]))
self.spheres.append(self.sphere(self.mesh.points()[self.spheres_init[-1]]).alpha(0.5))
other = [0, 1, 2]
other.remove(i)
o0_min, o0_max = np.min(self.mesh_init[:, other[0]]), np.max(self.mesh_init[:, other[0]])
Expand All @@ -116,15 +118,12 @@ def create(self):
self.plotter.add(*self.spheres)
self.plotter.add(self.mesh)
self.plotter.add(Plane(pos=[0., 0., 0.], normal=[1, 0, 0], s=(20, 20), c='darkred', alpha=0.2))
self.plotter.add(Text2D("Press 'Alt' to interact with the object.\n"
"Left click to select a sphere.\n"
"Right click to unselect a sphere.", s=0.75))
self.plotter.add(Text2D("Press 'b' to interact with the spheres / with the environment.\n"
"Left click to select / unselect a sphere.", s=0.75))

# Add callbacks
self.plotter.addCallback('KeyPress', self.key_press)
self.plotter.addCallback('KeyRelease', self.key_release)
self.plotter.addCallback('LeftButtonPress', self.left_button_press)
self.plotter.addCallback('RightButtonPress', self.right_button_press)
self.plotter.addCallback('MouseMove', self.mouse_move)

async def step(self):
Expand All @@ -138,42 +137,39 @@ async def step(self):
def key_press(self, evt):

# Only react to an 'Alt' press
if 'alt' in evt.keyPressed.lower():
# Switch from environment to object interaction
self.plotter.interactor.SetInteractorStyle(vtk.vtkInteractorStyle3D())
self.interactive_window = False

def key_release(self, evt):

# Only react with an 'Alt' release
if 'alt' in evt.keyPressed.lower():
# Switch from object to environment interaction
self.plotter.interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
self.interactive_window = True
self.selected = None
# Reset all
self.update_mesh()
self.update_arrows()
self.update_spheres()
if 'b' in evt.keyPressed.lower():
self.key_on = not self.key_on
if self.key_on:
# Switch from environment to object interaction
self.plotter.interactor.SetInteractorStyle(vtk.vtkInteractorStyle3D())
self.interactive_window = False
self.update_spheres()
else:
# Switch from object to environment interaction
self.plotter.interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
self.interactive_window = True
self.selected = None
# Reset all
self.update_mesh()
self.update_arrows()
self.update_spheres()

def left_button_press(self, evt):

# Select a sphere only in object interaction mode
if not self.interactive_window:
# Pick a unique sphere
if evt.actor in self.spheres:
self.selected = self.spheres.index(evt.actor)
self.update_spheres(center=self.spheres_init[self.selected])

def right_button_press(self, evt):

# Unselect a sphere only in object interaction mode
if not self.interactive_window:
self.selected = None
# Reset all
self.update_mesh()
self.update_arrows()
self.update_spheres()
self.click_on = not self.click_on
if self.click_on:
# Pick a unique sphere
if evt.actor in self.spheres:
self.selected = self.spheres.index(evt.actor)
self.update_spheres(center=self.spheres_init[self.selected])
else:
self.selected = None
# Reset all
self.update_mesh()
self.update_arrows()
self.update_spheres()

def mouse_move(self, evt):

Expand Down Expand Up @@ -224,7 +220,9 @@ def update_spheres(self, center=None):
# Remove actual spheres
self.plotter.remove(*self.spheres)
# If no center provided, reset all the spheres
if center is None:
if self.interactive_window:
self.spheres = [self.sphere(self.mesh_init[c]).alpha(0.5) for c in self.spheres_init]
elif center is None:
self.spheres = [self.sphere(self.mesh_init[c]) for c in self.spheres_init]
# Otherwise, update the selected cell
else:
Expand Down
3 changes: 1 addition & 2 deletions examples/demos/Beam/FC/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from DeepPhysX.Core.Pipelines.BasePrediction import BasePrediction
from DeepPhysX.Core.Environment.BaseEnvironmentConfig import BaseEnvironmentConfig
from DeepPhysX.Core.Database.BaseDatabaseConfig import BaseDatabaseConfig
from DeepPhysX.Core.Visualization.VedoVisualizer import VedoVisualizer
from DeepPhysX.Torch.FC.FCConfig import FCConfig

# Session related imports
Expand All @@ -26,7 +25,7 @@ def launch_runner():

# Environment config
environment_config = BaseEnvironmentConfig(environment_class=Beam,
visualizer=VedoVisualizer)
visualizer='vedo')

# FC config
nb_hidden_layers = 3
Expand Down
3 changes: 1 addition & 2 deletions examples/demos/Beam/UNet/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from DeepPhysX.Core.Pipelines.BasePrediction import BasePrediction
from DeepPhysX.Core.Environment.BaseEnvironmentConfig import BaseEnvironmentConfig
from DeepPhysX.Core.Database.BaseDatabaseConfig import BaseDatabaseConfig
from DeepPhysX.Core.Visualization.VedoVisualizer import VedoVisualizer
from DeepPhysX.Torch.UNet.UNetConfig import UNetConfig

# Session related imports
Expand All @@ -26,7 +25,7 @@ def launch_runner():

# Environment config
environment_config = BaseEnvironmentConfig(environment_class=Beam,
visualizer=VedoVisualizer)
visualizer='vedo')

# UNet config
network_config = UNetConfig(input_size=grid_resolution,
Expand Down
Loading

0 comments on commit fe20801

Please sign in to comment.