![]() |
ImFusion SDK 4.3
|
#include <ImFusion/GL/SharedImage.h>
Image shared on multiple devices. More...
Image shared on multiple devices.
This class aids in resource synchronization between CPU and different GPU APIs. It is constructed with a derived image instance either in memory or one of the graphics APIs, an empty base descriptor class is not allowed. In addition to the built-in representations such as MemImage and GlImage it also supports custom representations provided by plugins through the CustomImage interface.
Internally, for each image representation, a shared pointer is held. Synchronization is fully encapsulated and will be performed even on const instances of this class because mere synchronization between devices does not modify the semantic content of an image.
For individual image access, adhere to the following guidelines:
if (img.hasGl()) { auto gl = img.gl(); // wrong, could have been overridden in other thread since hasGl() ... } but instead: if (auto gl = img.hasGl()) { // correct, guaranteed to return either valid image or nullptr ... } Classes | |
| struct | Representation |
Public Types | |
| enum | CloneOptions { Everything = 0 , NoMask = 1 << 0 , NoDeformation = 1 << 1 , ShallowImageCopy = 1 << 2 } |
| Bitset enumeration to configure which aspects of a SharedImageSet to copy. More... | |
Public Member Functions | |
| SharedImage (std::shared_ptr< Image > img) | |
| Creates a new SharedImage wrapping the given image. | |
| template<typename T> | |
| SharedImage (TypedImage< T > &&img) | |
| Creates a new SharedImage by moving the given TypedImage in. | |
| SharedImage (GlImage &&img) | |
| Creates a new SharedImage by moving the given GlImage in. | |
| SharedImage (const ImageDescriptor &descriptor) | |
| Convenience overload to create a new SharedImage holding a MemImage as described by the ImageDescriptor. | |
| SharedImage (const ImageDescriptorWorld &descriptorWorld) | |
| Convenience overload to create a new SharedImage holding a MemImage as described by the ImageDescriptorWorld. | |
| SharedImage (const SharedImage &otherSharedImage) | |
| Copy constructor performs a deep copy of the underlying image data. | |
| SharedImage (const SharedImage &otherSharedImage, Flags< CloneOptions > copyOptions) | |
| Copy constructor variant that also allows for partial copies. | |
| SharedImage (SharedImage &&otherSharedImage) | |
| Move constructor will move all contents from otherSharedImage. | |
| SharedImage & | operator= (const SharedImage &otherSharedImage) |
| Assignment will perform a deep copy of the underlying image data. | |
| SharedImage & | operator= (SharedImage &&otherSharedImage) |
| Move assignment will move all contents from otherSharedImage. | |
| std::unique_ptr< SharedImage > | clone (Flags< CloneOptions > cloneOptions=Everything) const |
| More flexible version of the copy constructor that also allows for partial copies. | |
| Image::Location | location () const |
| Specifies the original location of the image. | |
| const Image * | img () const |
| Return the image descriptor of the currently up-to-date location. | |
| const ImageDescriptor & | descriptor () const |
| Return the image descriptor of the currently up-to-date location. | |
| ImageDescriptorWorld | descriptorWorld () const |
| Return the world image descriptor of the currently up-to-date location. | |
| bool | assign (std::shared_ptr< Image > img) |
| Set img as new main image representation and set the dirty flag accordingly. | |
| bool | update (const MemImage &img) |
| Update the MemImage and set the dirty flag so that the next OpenGL access will upload this image. | |
| bool | update (const GlImage &img) |
| Update the GlImage and set the dirty flag so that the next CPU access will download this image. | |
| void | prepare (bool shiftOnly=false) |
| Prepare the image in memory for most common scenarios Integral types are converted to unsigned representation if applicable, double-precision will be converted to single-precision float. | |
| virtual void | sync () const |
| Synchronize both MemImage and GlImage representations, shorthand for calling both syncMem() and syncGl(). | |
| virtual void | syncMem () const |
| Synchronize MemImage, creating it if it does not exist. | |
| template<typename T> | |
| void | syncCustom () const |
| Synchronize a custom image type where T must inherit the CustomImage interface, creating it if it does not exist. | |
| virtual void | syncGl () const |
| Synchronize OpenGL image, creating it if it does not exist. | |
| void | setDirtyMem () |
| Manually label MemImage as dirty (i.e. | |
| bool | setDirtyGl () |
| Manually label GlImage as dirty (i.e. | |
| template<typename T> | |
| void | setDirtyCustom () |
| Manually label custom image type T as dirty (i.e. | |
| bool | makeExclusive (Image::Location location) const |
| Synchronizes the given location and deletes all other representations stored to free memory. | |
| template<typename T> | |
| bool | makeExclusive () |
| Data::Kind | kind () const |
| Return the data kind of the base interface. | |
| Geometry::AlignedBox | bounds () const |
| Returns the axis-aligned bounding box of the unmasked and undeformed image in world space. | |
Public Attributes | |
| Signal< const SharedImage * > | signalChanged |
| Called when the content of a SharedImage has changed (every time one of the setDirty() methods has been called). | |
| Signal< const SharedImage * > | signalDeformationChanged |
| Called when a Deformation object is assigned or removed from the SharedImage. | |
| Signal< const SharedImage * > | signalMaskChanged |
| Called when a Mask object is assigned or removed from the SharedImage. | |
| Signal< const SharedImage * > | signalDeleted |
| Called when this instance is deleted. | |
Protected Attributes | |
| Image::Location | m_location = Image::NONE |
| The original location of the image. | |
| Data::Modality | m_modality = Data::NA |
| Image modality. | |
| mat4 | m_matrix = mat4::Identity() |
| The optional image matrix. | |
| std::shared_ptr< Deformation > | m_deformation |
| Optional non-linear transformation. | |
| std::shared_ptr< Mask > | m_mask |
| Optional mask. | |
| std::shared_ptr< MemImage > | m_memImg |
| Image in memory. | |
| std::shared_ptr< GlImage > | m_glImg |
| OpenGL texture. | |
| bool | m_memDirty = true |
| Indicates whether m_memImg is obsolete, and needs to be refreshed on access. | |
| bool | m_glDirty = true |
| Indicates whether m_glImg is obsolete, and needs to be refreshed on access. | |
| std::vector< Representation > | m_customImgs |
| List of custom Image representations that are not known to ImFusionLib but can be converted from/to MemImage. | |
| bool | m_glImgHasStrippedChannels = false |
| Indicates that the GL representation was created from an image with > 4 channels. | |
| Geometry::AlignedBox | m_bounds |
| Cached version of the axis-aligned bounding box in world space. | |
| bool | m_boundsDirty = true |
| Flag whether m_bounds needs to be recomputed. | |
Access to direct members of SharedImage | |
| void | setModality (Data::Modality m) |
| Set image modality. | |
| Data::Modality | modality () const |
| Return the modality of this data. | |
| void | setMask (std::shared_ptr< Mask > mask) |
| Sets a mask for this image. | |
| std::shared_ptr< Mask > | mask () const |
| Returns the mask for this image. | |
| void | setDeformation (std::shared_ptr< Deformation > def) |
| Sets a deformation for this image. | |
| std::shared_ptr< Deformation > | deformation () const |
| Returns the deformation for this image or nullptr if no deformation is set. | |
Query an up-to-date representation. | |
| |
| std::shared_ptr< MemImage > | sharedMem () |
| Returns the image in memory. | |
| std::shared_ptr< const MemImage > | sharedMem () const |
| std::shared_ptr< GlImage > | sharedGl () |
| Returns the image as OpenGL texture. | |
| std::shared_ptr< const GlImage > | sharedGl () const |
| template<typename T> | |
| std::shared_ptr< T > | sharedCustom () |
| Returns the image as custom image type, where T must inherit the CustomImage interface. | |
| template<typename T> | |
| std::shared_ptr< const T > | sharedCustom () const |
| MemImage * | mem () |
| Returns the image in memory. | |
| const MemImage * | mem () const |
| GlImage * | gl () |
| Returns the image as OpenGL texture. | |
| const GlImage * | gl () const |
| template<typename T> | |
| T * | custom () |
| Returns the image as custom image type, where T must inherit the CustomImage interface. | |
| template<typename T> | |
| const T * | custom () const |
Query whether an up-to-date representation is present and return it. | |
| |
| std::shared_ptr< const MemImage > | hasMem () const |
| Query whether an up-to-date memory image is present. | |
| std::shared_ptr< MemImage > | hasMem () |
| std::shared_ptr< const GlImage > | hasGl () const |
| Query whether an up-to-date OpenGL image is present. | |
| std::shared_ptr< GlImage > | hasGl () |
| template<typename T> | |
| std::shared_ptr< T > | hasCustom () |
| Query whether an up-to-date image of the requested type is present, where T must inherit the CustomImage interface. | |
| template<typename T> | |
| std::shared_ptr< const T > | hasCustom () const |
Image matrix access | |
By convention this matrix transforms world coordinates to image coordinates.
| |
| void | setMatrix (const mat4 &m) |
| Sets the transformation matrix from world space to image space. | |
| const mat4 & | matrix () const |
| Returns the transformation matrix from world space to image space. | |
| mat4 | matrixToWorld () const |
| Returns the transformation matrix from image space to world space. | |
| void | setMatrixToWorld (const mat4 &value) |
| Sets the transformation matrix from image space to world space. | |
| const mat4 & | matrixFromWorld () const |
| Returns the transformation matrix from world space to image space. | |
| void | setMatrixFromWorld (const mat4 &value) |
| Sets the transformation matrix from world space to image space. | |
Convenience functions to access underlying image descriptor directly | |
| int | width () const |
| Return the width of the base interface. | |
| int | height () const |
| Return the height of the base interface. | |
| int | slices () const |
| Return the number of slices of the base interface. | |
| int | channels () const |
| Return the number of channels of the base interface. | |
| vec3 | spacing () const |
| Return the image spacing. | |
| void | setSpacing (const vec3 &spacing) |
| Set the image spacing on all existing image representations. | |
| void | setSpacing (const vec3 &spacing, bool metric) |
| Set the image spacing on all existing image representations, and whether the spacing is metric. | |
| int | dimension () const |
| Return the image dimensions. | |
| vec3i | dimensions () const |
| Return the image dimensions. | |
| size_t | size () const |
| Return the image size. | |
| vec3 | extent () const |
| Return the image extent. | |
| enum CloneOptions |
Bitset enumeration to configure which aspects of a SharedImageSet to copy.
|
explicit |
Creates a new SharedImage wrapping the given image.
| img | Pointer to the image to initialize the SharedImage with, must not be null. |
| const Image * img | ( | ) | const |
Return the image descriptor of the currently up-to-date location.
| void setMask | ( | std::shared_ptr< Mask > | mask | ) |
Sets a mask for this image.
Only masks that are compatible with the image can be set. Incompatible masks will be ignored. The signalMaskChanged signal is emitted whenever the mask pointer changes.
| std::shared_ptr< Mask > mask | ( | ) | const |
Returns the mask for this image.
Returns nullptr if no mask is set or the current mask is not compatible to the image anymore.
| bool assign | ( | std::shared_ptr< Image > | img | ) |
Set img as new main image representation and set the dirty flag accordingly.
This function will move/sink in the image. Use update() if you want to copy the image data instead.
| bool update | ( | const MemImage & | img | ) |
Update the MemImage and set the dirty flag so that the next OpenGL access will upload this image.
This function will copy the image data into the SharedImage. Use the assign() if you want to move/sink the image in instead.
| bool update | ( | const GlImage & | img | ) |
Update the GlImage and set the dirty flag so that the next CPU access will download this image.
This function will copy the image data into the SharedImage. Use the assign() if you want to move/sink the image in instead.
| void prepare | ( | bool | shiftOnly = false | ) |
Prepare the image in memory for most common scenarios Integral types are converted to unsigned representation if applicable, double-precision will be converted to single-precision float.
Furthermore, if shiftOnly is false it will rescale the present intensity range to [0..1] for floating point types or to the entire available value range for integral types.
|
virtual |
Synchronize OpenGL image, creating it if it does not exist.
| void setDirtyMem | ( | ) |
Manually label MemImage as dirty (i.e.
the other representations must be updated). An implicit synchronization will happen automatically the next time another representation is requested.
| bool setDirtyGl | ( | ) |
Manually label GlImage as dirty (i.e.
the other representations must be updated) An implicit synchronization will happen automatically the next time another representation is requested.
| void setDirtyCustom | ( | ) |
Manually label custom image type T as dirty (i.e.
the other representations must be updated) An implicit synchronization will happen automatically the next time another representation is requested.
| bool makeExclusive | ( | Image::Location | location | ) | const |
Synchronizes the given location and deletes all other representations stored to free memory.
| Signal<const SharedImage*> signalChanged |
Called when the content of a SharedImage has changed (every time one of the setDirty() methods has been called).
| Signal<const SharedImage*> signalMaskChanged |
Called when a Mask object is assigned or removed from the SharedImage.
| Signal<const SharedImage*> signalDeleted |
Called when this instance is deleted.
|
mutableprotected |
Indicates that the GL representation was created from an image with > 4 channels.
Since OpenGL does not support this the GL representation only stores the first 4 channels. A subsequent call to setDirtyGl() has no effect to avoid data loss.