|
| 1 | +# Copyright (c) MONAI Consortium |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +# you may not use this file except in compliance with the License. |
| 4 | +# You may obtain a copy of the License at |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# Unless required by applicable law or agreed to in writing, software |
| 7 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 8 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 9 | +# See the License for the specific language governing permissions and |
| 10 | +# limitations under the License. |
| 11 | +""" |
| 12 | +A collection of generic traits for MONAI transforms. |
| 13 | +""" |
| 14 | + |
| 15 | +from __future__ import annotations |
| 16 | + |
| 17 | +__all__ = ["LazyTrait", "RandomizableTrait", "MultiSampleTrait", "ThreadUnsafe"] |
| 18 | + |
| 19 | + |
| 20 | +class LazyTrait: |
| 21 | + """ |
| 22 | + An interface to indicate that the transform has the capability to execute using |
| 23 | + MONAI's lazy resampling feature. In order to do this, the implementing class needs |
| 24 | + to be able to describe its operation as an affine matrix or grid with accompanying metadata. |
| 25 | + This interface can be extended from by people adapting transforms to the MONAI framework as |
| 26 | + well as by implementors of MONAI transforms. |
| 27 | + """ |
| 28 | + |
| 29 | + @property |
| 30 | + def lazy_evaluation(self): |
| 31 | + """ |
| 32 | + Get whether lazy_evaluation is enabled for this transform instance. |
| 33 | + Returns: |
| 34 | + True if the transform is operating in a lazy fashion, False if not. |
| 35 | + """ |
| 36 | + raise NotImplementedError() |
| 37 | + |
| 38 | + @lazy_evaluation.setter |
| 39 | + def lazy_evaluation(self, enabled: bool): |
| 40 | + """ |
| 41 | + Set whether lazy_evaluation is enabled for this transform instance. |
| 42 | + Args: |
| 43 | + enabled: True if the transform should operate in a lazy fashion, False if not. |
| 44 | + """ |
| 45 | + raise NotImplementedError() |
| 46 | + |
| 47 | + |
| 48 | +class RandomizableTrait: |
| 49 | + """ |
| 50 | + An interface to indicate that the transform has the capability to perform |
| 51 | + randomized transforms to the data that it is called upon. This interface |
| 52 | + can be extended from by people adapting transforms to the MONAI framework as well as by |
| 53 | + implementors of MONAI transforms. |
| 54 | + """ |
| 55 | + |
| 56 | + pass |
| 57 | + |
| 58 | + |
| 59 | +class MultiSampleTrait: |
| 60 | + """ |
| 61 | + An interface to indicate that the transform has the capability to return multiple samples |
| 62 | + given an input, such as when performing random crops of a sample. This interface can be |
| 63 | + extended from by people adapting transforms to the MONAI framework as well as by implementors |
| 64 | + of MONAI transforms. |
| 65 | + """ |
| 66 | + |
| 67 | + pass |
| 68 | + |
| 69 | + |
| 70 | +class ThreadUnsafe: |
| 71 | + """ |
| 72 | + A class to denote that the transform will mutate its member variables, |
| 73 | + when being applied. Transforms inheriting this class should be used |
| 74 | + cautiously in a multi-thread context. |
| 75 | +
|
| 76 | + This type is typically used by :py:class:`monai.data.CacheDataset` and |
| 77 | + its extensions, where the transform cache is built with multiple threads. |
| 78 | + """ |
| 79 | + |
| 80 | + pass |
0 commit comments