Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pytissueoptics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from importlib.metadata import version
from .scene import * # noqa: F403

from .rayscattering import * # noqa: F403
from .scene import * # noqa: F403

__version__ = version("pytissueoptics")
4 changes: 2 additions & 2 deletions pytissueoptics/examples/scene/example0.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@


def exampleCode():
from pytissueoptics.scene import Cuboid, Ellipsoid, MayaviViewer, Sphere, Vector
from pytissueoptics.scene import Cuboid, Ellipsoid, Sphere, Vector, get3DViewer

cuboid = Cuboid(a=1, b=3, c=1, position=Vector(1, 0, 0))
sphere = Sphere(radius=0.5, position=Vector(0, 0, 0))
ellipsoid = Ellipsoid(a=1.5, b=1, c=1, position=Vector(-2, 0, 0))

viewer = MayaviViewer()
viewer = get3DViewer()
viewer.add(cuboid, sphere, ellipsoid, representation="surface")
viewer.show()

Expand Down
4 changes: 2 additions & 2 deletions pytissueoptics/examples/scene/example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def exampleCode():
from pytissueoptics.scene import Cuboid, MayaviViewer, Vector
from pytissueoptics.scene import Cuboid, Vector, get3DViewer

centerCube = Cuboid(a=1, b=1, c=1, position=Vector(0, 0, 0))
topCube = Cuboid(a=1, b=1, c=1, position=Vector(0, 2, 0))
Expand All @@ -17,7 +17,7 @@ def exampleCode():
bottomCube.translateTo(Vector(0, -2, 0))
centerCube.rotate(0, 30, 30)

viewer = MayaviViewer()
viewer = get3DViewer()
viewer.add(centerCube, topCube, bottomCube, representation="surface")
viewer.show()

Expand Down
6 changes: 3 additions & 3 deletions pytissueoptics/examples/scene/example2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@


def exampleCode():
from pytissueoptics.scene import Cuboid, MayaviViewer, Vector
from pytissueoptics.scene import Cuboid, Vector, get3DViewer

cuboid1 = Cuboid(1, 1, 1, position=Vector(2, 0, 0))
cuboid2 = Cuboid(2, 1, 1, position=Vector(0, 2, 0))
cuboid3 = Cuboid(3, 1, 1, position=Vector(0, 0, 2))

viewer = MayaviViewer()
viewer = get3DViewer()
viewer.add(cuboid1, cuboid2, cuboid3, representation="wireframe", lineWidth=5)
viewer.show()

cuboidStack = cuboid1.stack(cuboid2, onSurface="right")
cuboidStack = cuboidStack.stack(cuboid3, onSurface="top")

viewer.clear()
viewer = get3DViewer()
viewer.add(cuboidStack, representation="wireframe", lineWidth=5)
viewer.show()

Expand Down
4 changes: 2 additions & 2 deletions pytissueoptics/examples/scene/example3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@


def exampleCode():
from pytissueoptics.scene import MayaviViewer, loadSolid
from pytissueoptics.scene import get3DViewer, loadSolid

solid = loadSolid("pytissueoptics/examples/scene/droid.obj")

viewer = MayaviViewer()
viewer = get3DViewer()
viewer.add(solid, representation="surface", showNormals=True, normalLength=0.2)
viewer.show()

Expand Down
4 changes: 2 additions & 2 deletions pytissueoptics/examples/scene/example4.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

def exampleCode():
from pytissueoptics.scene import (
MayaviViewer,
PlanoConcaveLens,
PlanoConvexLens,
RefractiveMaterial,
SymmetricLens,
ThickLens,
Vector,
get3DViewer,
)

material = RefractiveMaterial(refractiveIndex=1.44)
Expand All @@ -22,7 +22,7 @@ def exampleCode():
lens2 = PlanoConvexLens(f=-60, diameter=25.4, thickness=4, material=material, position=Vector(0, 0, 20))
lens4 = PlanoConcaveLens(f=60, diameter=25.4, thickness=4, material=material, position=Vector(0, 0, 30))

viewer = MayaviViewer()
viewer = get3DViewer()
viewer.add(lens1, lens2, lens3, lens4, representation="surface", colormap="viridis", showNormals=False)
viewer.show()

Expand Down
2 changes: 0 additions & 2 deletions pytissueoptics/rayscattering/display/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from .direction import DEFAULT_X_VIEW_DIRECTIONS, DEFAULT_Y_VIEW_DIRECTIONS, DEFAULT_Z_VIEW_DIRECTIONS, Direction
from .volumeSlicer import VolumeSlicer

__all__ = [
"DEFAULT_X_VIEW_DIRECTIONS",
"DEFAULT_Y_VIEW_DIRECTIONS",
"DEFAULT_Z_VIEW_DIRECTIONS",
"Direction",
"VolumeSlicer",
]
18 changes: 4 additions & 14 deletions pytissueoptics/rayscattering/display/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pytissueoptics.rayscattering.scatteringScene import ScatteringScene
from pytissueoptics.rayscattering.source import Source
from pytissueoptics.rayscattering.statistics import Stats
from pytissueoptics.scene import MAYAVI_AVAILABLE, MayaviViewer, ViewPointStyle
from pytissueoptics.scene import ViewPointStyle, get3DViewer


class Visibility(Flag):
Expand Down Expand Up @@ -112,11 +112,8 @@ def show3D(
viewsLogScale: bool = True,
viewsColormap: str = "viridis",
):
if not MAYAVI_AVAILABLE:
utils.warn("Package 'mayavi' is not available. Please install it to use 3D visualizations.")
return

self._viewer3D = MayaviViewer(viewPointStyle=ViewPointStyle.OPTICS)
self._viewer3D = get3DViewer()
self._viewer3D.setViewPointStyle(ViewPointStyle.OPTICS)

if visibility == Visibility.AUTO:
visibility = Visibility.DEFAULT_3D if self._logger.has3D else Visibility.DEFAULT_2D
Expand Down Expand Up @@ -146,10 +143,6 @@ def show3DVolumeSlicer(
interpolate: bool = False,
limits: Tuple[tuple, tuple, tuple] = None,
):
if not MAYAVI_AVAILABLE:
utils.warn("ERROR: Package 'mayavi' is not available. Please install it to use 3D visualizations.")
return

if not self._logger.has3D:
utils.warn("ERROR: Cannot show 3D volume slicer without 3D data.")
return
Expand Down Expand Up @@ -182,10 +175,7 @@ def show3DVolumeSlicer(
if logScale:
hist = utils.logNorm(hist)

from pytissueoptics.rayscattering.display.utils.volumeSlicer import VolumeSlicer

slicer = VolumeSlicer(hist, interpolate=interpolate)
slicer.show()
get3DViewer().showVolumeSlicer(hist, interpolate=interpolate)

def show2D(self, view: View2D = None, viewIndex: int = None, logScale: bool = True, colormap: str = "viridis"):
self._logger.showView(view=view, viewIndex=viewIndex, logScale=logScale, colormap=colormap)
Expand Down
3 changes: 2 additions & 1 deletion pytissueoptics/rayscattering/opencl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

from pytissueoptics.rayscattering.opencl.config.CLConfig import OPENCL_AVAILABLE, WEIGHT_THRESHOLD, CLConfig, warnings
from pytissueoptics.rayscattering.opencl.config.IPPTable import IPPTable
import os

OPENCL_OK = True
OPENCL_DISABLED = os.environ.get("PTO_DISABLE_OPENCL", "0") == "1"
Expand Down
4 changes: 2 additions & 2 deletions pytissueoptics/rayscattering/scatteringScene.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

from pytissueoptics.rayscattering.materials import ScatteringMaterial
from pytissueoptics.scene import MayaviViewer, Scene, Vector
from pytissueoptics.scene import Scene, Vector, get3DViewer
from pytissueoptics.scene.solids import Solid
from pytissueoptics.scene.viewer.displayable import Displayable

Expand All @@ -22,7 +22,7 @@ def add(self, solid: Solid, position: Vector = None):
super().add(solid, position)

def show(self, source: Displayable = None, opacity=0.8, colormap="cool", **kwargs):
viewer = MayaviViewer()
viewer = get3DViewer()
self.addToViewer(viewer, opacity=opacity, colormap=colormap, **kwargs)
if source:
source.addToViewer(viewer)
Expand Down
6 changes: 3 additions & 3 deletions pytissueoptics/rayscattering/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pytissueoptics.scene.solids.cone import Cone
from pytissueoptics.scene.solids.cylinder import Cylinder
from pytissueoptics.scene.utils import progressBar
from pytissueoptics.scene.viewer import Displayable, MayaviViewer
from pytissueoptics.scene.viewer import Abstract3DViewer, Displayable


class Source(Displayable):
Expand Down Expand Up @@ -184,7 +184,7 @@ def photons(self):
def getPhotonCount(self) -> int:
return self._N

def addToViewer(self, viewer: MayaviViewer, representation="surface", colormap="Wistia", opacity=1.0, **kwargs):
def addToViewer(self, viewer: Abstract3DViewer, representation="surface", colormap="Wistia", opacity=1.0, **kwargs):
sphere = Sphere(radius=self.displaySize / 2, position=self._position)
viewer.add(sphere, representation=representation, colormap=colormap, opacity=opacity, **kwargs)

Expand Down Expand Up @@ -227,7 +227,7 @@ def getInitialPositionsAndDirections(self) -> Tuple[np.ndarray, np.ndarray]:
directions = self._getInitialDirections()
return positions, directions

def addToViewer(self, viewer: MayaviViewer, representation="surface", colormap="Wistia", opacity=1, **kwargs):
def addToViewer(self, viewer: Abstract3DViewer, representation="surface", colormap="Wistia", opacity=1, **kwargs):
baseHeight = 0.5 * self.displaySize
baseCenter = self._position + self._direction * baseHeight / 2
base = Cylinder(radius=self.displaySize / 8, length=baseHeight, position=baseCenter)
Expand Down
Loading