From 80f49e3a149ad67a13302b37da83c2d9b63c8011 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Wed, 16 Apr 2025 11:53:41 +1000 Subject: [PATCH 1/2] fix: autoscale should default to 1 if 0 nothing shows when there is no model --- loopstructuralvisualisation/_3d_viewer.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/loopstructuralvisualisation/_3d_viewer.py b/loopstructuralvisualisation/_3d_viewer.py index 2090578..2f2900c 100644 --- a/loopstructuralvisualisation/_3d_viewer.py +++ b/loopstructuralvisualisation/_3d_viewer.py @@ -83,7 +83,7 @@ def _check_model(self, model: GeologicalModel) -> GeologicalModel: return model def _get_vector_scale(self, scale: Optional[Union[float, int]]) -> float: - autoscale = 0.0 + autoscale = 1.0 if self.model is not None: # automatically scale vector data to be 5% of the bounding box length autoscale = self.model.bounding_box.length.max() * 0.05 @@ -207,6 +207,7 @@ def plot_scalar_field( scalar_bar: bool = False, slicer: bool = False, name: Optional[str] = None, + bounding_box: Optional[BoundingBox] = None, ): """Plot a volume with the scalar field as the property calls feature.scalar_field() to get the scalar field and @@ -243,7 +244,7 @@ def plot_scalar_field( name = geological_feature.name + '_scalar_field' name = self.increment_name(name) # , 'scalar_field') - volume = geological_feature.scalar_field().vtk() + volume = geological_feature.scalar_field(bounding_box=bounding_box).vtk() if vmin is not None: pyvista_kwargs["clim"][0] = vmin if vmax is not None: @@ -476,6 +477,7 @@ def plot_vector_field( normalise: bool = False, scale_function: Optional[Callable[[np.ndarray],np.ndarray]] = None, pyvista_kwargs: dict = {}, + bounding_box: Optional[BoundingBox] = None, ) -> pv.Actor: """Plot a vector field @@ -498,8 +500,9 @@ def plot_vector_field( if name is None: name = geological_feature.name + '_vector_field' name = self.increment_name(name) # , 'vector_field') - vectorfield = geological_feature.vector_field() + vectorfield = geological_feature.vector_field(bounding_box=bounding_box) scale = self._get_vector_scale(scale) + print(scale) return self.add_mesh( vectorfield.vtk( scale=scale, @@ -615,6 +618,7 @@ def plot_fault( name: Optional[str] = None, geom: str = "arrow", pyvista_kwargs: dict = {}, + bounding_box: Optional[BoundingBox] = None, ) -> List[pv.Actor]: """Plot a fault including the surface, slip vector and displacement volume @@ -649,7 +653,7 @@ def plot_fault( else: surface_name = f'{fault.name}_surface_{name}' surface_name = self.increment_name(surface_name) - surf = fault.surfaces([0])[0] + surf = fault.surfaces([0],bounding_box=bounding_box)[0] actors.append(self.add_mesh(surf.vtk(), name=surface_name, **pyvista_kwargs)) if slip_vector: if name is None: @@ -658,7 +662,7 @@ def plot_fault( vector_name = f'{fault.name}_vector_{name}' vector_name = self.increment_name(vector_name) - vectorfield = fault.vector_field() + vectorfield = fault.vector_field(bounding_box=bounding_box) vector_scale = self._get_vector_scale(vector_scale) actors.append( self.add_mesh( @@ -676,7 +680,7 @@ def plot_fault( volume_name = fault.name + '_volume' else: volume_name = f'{fault.name}_volume_{name}' - volume = fault.displacementfeature.scalar_field() + volume = fault.displacementfeature.scalar_field(bounding_box=bounding_box) volume = volume.vtk().threshold([-1.0,1.0]) if geom == "arrow": geom = pv.Arrow() @@ -713,7 +717,7 @@ def plot_fault_ellipsoid( name = fault.name + '_ellipsoid' name = self.increment_name(name) ellipsoid = fault.fault_ellipsoid() - return self.add_mesh(ellipsoid.vtk(), name=name, **pyvista_kwargs) + return self.add_mesh(ellipsoid, name=name, **pyvista_kwargs) def rotate(self, angles: np.ndarray): """Rotate the camera by the given angles From 711b044fcd27742fc936f3ee40e5f3c0a8ce34bf Mon Sep 17 00:00:00 2001 From: lachlangrose <7371904+lachlangrose@users.noreply.github.com> Date: Wed, 16 Apr 2025 01:53:59 +0000 Subject: [PATCH 2/2] style: style fixes by ruff and autoformatting by black --- loopstructuralvisualisation/_3d_viewer.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/loopstructuralvisualisation/_3d_viewer.py b/loopstructuralvisualisation/_3d_viewer.py index 2f2900c..b71744d 100644 --- a/loopstructuralvisualisation/_3d_viewer.py +++ b/loopstructuralvisualisation/_3d_viewer.py @@ -475,7 +475,7 @@ def plot_vector_field( geom='arrow', scalars: Optional[np.ndarray] = None, normalise: bool = False, - scale_function: Optional[Callable[[np.ndarray],np.ndarray]] = None, + scale_function: Optional[Callable[[np.ndarray], np.ndarray]] = None, pyvista_kwargs: dict = {}, bounding_box: Optional[BoundingBox] = None, ) -> pv.Actor: @@ -653,7 +653,7 @@ def plot_fault( else: surface_name = f'{fault.name}_surface_{name}' surface_name = self.increment_name(surface_name) - surf = fault.surfaces([0],bounding_box=bounding_box)[0] + surf = fault.surfaces([0], bounding_box=bounding_box)[0] actors.append(self.add_mesh(surf.vtk(), name=surface_name, **pyvista_kwargs)) if slip_vector: if name is None: @@ -666,11 +666,7 @@ def plot_fault( vector_scale = self._get_vector_scale(vector_scale) actors.append( self.add_mesh( - vectorfield.vtk( - scale=vector_scale, - normalise=False - - ), + vectorfield.vtk(scale=vector_scale, normalise=False), name=vector_name, **pyvista_kwargs, ) @@ -681,7 +677,7 @@ def plot_fault( else: volume_name = f'{fault.name}_volume_{name}' volume = fault.displacementfeature.scalar_field(bounding_box=bounding_box) - volume = volume.vtk().threshold([-1.0,1.0]) + volume = volume.vtk().threshold([-1.0, 1.0]) if geom == "arrow": geom = pv.Arrow() elif geom == "disc":