diff --git a/CHANGELOG.md b/CHANGELOG.md index 9af7646d..5fde4c32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ New: * Add CylindricalTransform and VectorCylindricalTransform to transform functions from cylindrical to Cartesian coordinates. (#387) * Add the kind attribute to RayTransferPipelineXD that determines whether the ray transfer matrix is multiplied by sensitivity ('power') or not ('radiance'). (#412) +Bug fixes: +* Fix deprecated transforms being cached in LaserMaterial after laser.transform update (#420) Release 1.4.0 (3 Feb 2023) ------------------- diff --git a/cherab/core/laser/material.pxd b/cherab/core/laser/material.pxd index c91fa416..24695146 100644 --- a/cherab/core/laser/material.pxd +++ b/cherab/core/laser/material.pxd @@ -17,7 +17,7 @@ # under the Licence. -from raysect.core.scenegraph._nodebase cimport _NodeBase +from raysect.core cimport Primitive from raysect.core.math cimport AffineMatrix3D from raysect.optical.material.emitter cimport InhomogeneousVolumeEmitter @@ -28,4 +28,8 @@ cdef class LaserMaterial(InhomogeneousVolumeEmitter): cdef: AffineMatrix3D _laser_to_plasma, _laser_segment_to_laser_node + Primitive _primitive + Laser _laser list _models + + cdef void _cache_transforms(self) \ No newline at end of file diff --git a/cherab/core/laser/material.pyx b/cherab/core/laser/material.pyx index 4732e01a..75cc46a6 100644 --- a/cherab/core/laser/material.pyx +++ b/cherab/core/laser/material.pyx @@ -17,7 +17,7 @@ # under the Licence. -from raysect.core.scenegraph._nodebase cimport _NodeBase +from raysect.core cimport Primitive from raysect.optical cimport World, Primitive, Ray, Spectrum, Point3D, Vector3D, AffineMatrix3D from raysect.optical.material.emitter cimport InhomogeneousVolumeEmitter from raysect.optical.material.emitter.inhomogeneous cimport VolumeIntegrator @@ -28,12 +28,12 @@ from cherab.core.laser.model cimport LaserModel cdef class LaserMaterial(InhomogeneousVolumeEmitter): - def __init__(self, Laser laser not None, _NodeBase laser_segment not None, list models, VolumeIntegrator integrator not None): + def __init__(self, Laser laser not None, Primitive laser_segment not None, list models, VolumeIntegrator integrator not None): super().__init__(integrator) - self._laser_segment_to_laser_node = laser_segment.to(laser) - self._laser_to_plasma = laser_segment.to(laser.plasma) + self._laser = laser + self._primitive = laser_segment self.importance = laser.importance #validate and set models @@ -54,6 +54,10 @@ cdef class LaserMaterial(InhomogeneousVolumeEmitter): Point3D point_plasma, point_laser Vector3D direction_plasma, direction_laser LaserModel model + + # cache the important transforms + if self._laser_segment_to_laser_node is None or self._laser_to_plasma is None: + self._cache_transforms() point_laser = point.transform(self._laser_segment_to_laser_node) direction_laser = direction.transform(self._laser_segment_to_laser_node) # observation vector in the laser frame @@ -63,4 +67,16 @@ cdef class LaserMaterial(InhomogeneousVolumeEmitter): for model in self._models: spectrum = model.emission(point_plasma, direction_plasma, point_laser, direction_laser, spectrum) - return spectrum + return spectrum + + cdef void _cache_transforms(self): + """ + cache transforms from laser primitive to laser and plasma + """ + + # if transforms are cached, the material should be used only for one primitive for safety + if not len(self.primitives) == 1: + raise ValueError("LaserMaterial must be attached to exactly one primitive.") + + self._laser_segment_to_laser_node = self._primitive.to(self._laser) + self._laser_to_plasma = self._primitive.to(self._laser.get_plasma()) diff --git a/cherab/core/laser/node.pxd b/cherab/core/laser/node.pxd index 6045fb4a..8fec6821 100644 --- a/cherab/core/laser/node.pxd +++ b/cherab/core/laser/node.pxd @@ -52,4 +52,6 @@ cdef class Laser(Node): list _geometry VolumeIntegrator _integrator - cdef object __weakref__ \ No newline at end of file + cdef object __weakref__ + + cdef Plasma get_plasma(self) \ No newline at end of file diff --git a/cherab/core/laser/node.pyx b/cherab/core/laser/node.pyx index b0b821b5..9475fb69 100644 --- a/cherab/core/laser/node.pyx +++ b/cherab/core/laser/node.pyx @@ -153,6 +153,12 @@ cdef class Laser(Node): self._plasma.notifier.add(self._plasma_changed) self._configure_materials() + + cdef Plasma get_plasma(self): + """ + Fast method to obtain laser's plasma reference. + """ + return self._plasma @property def importance(self):