|
| 1 | +# Copyright 2016-2021 Euratom |
| 2 | +# Copyright 2016-2021 United Kingdom Atomic Energy Authority |
| 3 | +# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas |
| 4 | +# |
| 5 | +# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the |
| 6 | +# European Commission - subsequent versions of the EUPL (the "Licence"); |
| 7 | +# You may not use this work except in compliance with the Licence. |
| 8 | +# You may obtain a copy of the Licence at: |
| 9 | +# |
| 10 | +# https://joinup.ec.europa.eu/software/page/eupl5 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software distributed |
| 13 | +# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR |
| 14 | +# CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# |
| 16 | +# See the Licence for the specific language governing permissions and limitations |
| 17 | +# under the Licence. |
| 18 | + |
| 19 | +from numpy import ndarray |
| 20 | +from raysect.optical.observer import TargetedPixel |
| 21 | + |
| 22 | +from .base import Observer0DGroup |
| 23 | + |
| 24 | + |
| 25 | +class TargetedPixelGroup(Observer0DGroup): |
| 26 | + """ |
| 27 | + A group of targeted pixels under a single scene-graph node. |
| 28 | +
|
| 29 | + A scene-graph object regrouping a series of 'TargetedPixel' |
| 30 | + observers as a scene-graph parent. Allows combined observation and display |
| 31 | + control simultaneously. |
| 32 | +
|
| 33 | + :ivar list x_width: Width of pixel along local x axis |
| 34 | + :ivar list y_width: Width of pixel along local y axis |
| 35 | + :ivar list targets: Targets for preferential sampling |
| 36 | + :ivar list targeted_path_prob: Probability of ray being casted at the target |
| 37 | + """ |
| 38 | + |
| 39 | + _OBSERVER_TYPE = TargetedPixel |
| 40 | + |
| 41 | + @property |
| 42 | + def x_width(self): |
| 43 | + return [pixel.x_width for pixel in self._observers] |
| 44 | + |
| 45 | + @x_width.setter |
| 46 | + def x_width(self, value): |
| 47 | + if isinstance(value, (list, tuple, ndarray)): |
| 48 | + if len(value) == len(self._observers): |
| 49 | + for pixel, v in zip(self._observers, value): |
| 50 | + pixel.x_width = v |
| 51 | + else: |
| 52 | + raise ValueError( |
| 53 | + "The length of 'x_width' ({}) mismatches the number of pixels ({}).".format(len(value), len(self._observers)) |
| 54 | + ) |
| 55 | + else: |
| 56 | + for pixel in self._observers: |
| 57 | + pixel.x_width = value |
| 58 | + |
| 59 | + @property |
| 60 | + def y_width(self): |
| 61 | + return [pixel.y_width for pixel in self._observers] |
| 62 | + |
| 63 | + @y_width.setter |
| 64 | + def y_width(self, value): |
| 65 | + if isinstance(value, (list, tuple, ndarray)): |
| 66 | + if len(value) == len(self._observers): |
| 67 | + for pixel, v in zip(self._observers, value): |
| 68 | + pixel.y_width = v |
| 69 | + else: |
| 70 | + raise ValueError( |
| 71 | + "The length of 'y_width' ({}) mismatches the number of pixels ({}).".format(len(value), len(self._observers)) |
| 72 | + ) |
| 73 | + else: |
| 74 | + for pixel in self._observers: |
| 75 | + pixel.y_width = value |
| 76 | + |
| 77 | + @property |
| 78 | + def targets(self): |
| 79 | + """ |
| 80 | + List of target lists used by pixels for preferential sampling |
| 81 | +
|
| 82 | + :param list value: List of primitives to be set to each pixel or |
| 83 | + list of lists containing targets specific for each pixel |
| 84 | + in this case the number of lists must match number of pixels |
| 85 | +
|
| 86 | + :rtype: list |
| 87 | + """ |
| 88 | + return [pixel.targets for pixel in self._observers] |
| 89 | + |
| 90 | + @targets.setter |
| 91 | + def targets(self, value): |
| 92 | + if all(isinstance(v, (list, tuple)) for v in value): |
| 93 | + if len(value) == len(self._observers): |
| 94 | + for pixel, v in zip(self._observers, value): |
| 95 | + pixel.targets = v |
| 96 | + else: |
| 97 | + raise ValueError( |
| 98 | + "The number of provided target lists' ({}) mismatches the number of pixels ({}).".format( |
| 99 | + len(value), len(self._observers) |
| 100 | + ) |
| 101 | + ) |
| 102 | + else: |
| 103 | + # assuming a list of primitives, the pixel's setter will throw an error if not |
| 104 | + for pixel in self._observers: |
| 105 | + pixel.targets = value |
| 106 | + |
| 107 | + @property |
| 108 | + def targeted_path_prob(self): |
| 109 | + return [pixel.targeted_path_prob for pixel in self._observers] |
| 110 | + |
| 111 | + @targeted_path_prob.setter |
| 112 | + def targeted_path_prob(self, value): |
| 113 | + if isinstance(value, (list, tuple)): |
| 114 | + if len(value) == len(self._observers): |
| 115 | + for pixel, v in zip(self._observers, value): |
| 116 | + pixel.targeted_path_prob = v |
| 117 | + else: |
| 118 | + raise ValueError( |
| 119 | + "The length of 'value' ({}) mismatches the number of pixels ({}).".format(len(value), len(self._observers)) |
| 120 | + ) |
| 121 | + else: |
| 122 | + for pixel in self._observers: |
| 123 | + pixel.targeted_path_prob = value |
0 commit comments