ImFusion SDK 4.3
TypedImage< T > Class Template Reference

#include <ImFusion/Base/TypedImage.h>

Concrete implementation of a MemImage for a given pixel type. More...

+ Inheritance diagram for TypedImage< T >:

Detailed Description

template<typename T>
class ImFusion::TypedImage< T >

Concrete implementation of a MemImage for a given pixel type.

A TypedImage is movable but not copyable. Use clone() in order to perform a deep copy.

See also
Using Image Data, ImageProcessing

Public Types

using value_type = T
 
- Public Types inherited from MemImage
enum class  Ownership { NotOwning = 0 , Owning = 1 }
 Enumeration to describe image data pointer ownership. More...
 
- Public Types inherited from Image
enum  Type {
  BYTE = static_cast<int>(PixelType::Byte) , UBYTE = static_cast<int>(PixelType::UByte) , SHORT = static_cast<int>(PixelType::Short) , USHORT = static_cast<int>(PixelType::UShort) ,
  INT = static_cast<int>(PixelType::Int) , UINT = static_cast<int>(PixelType::UInt) , FLOAT = static_cast<int>(PixelType::Float) , DOUBLE = static_cast<int>(PixelType::Double) ,
  HFLOAT = static_cast<int>(PixelType::HFloat)
}
 Pixel/voxel data type, equivalent to OpenGL defines. More...
 
enum  Location {
  NONE = 0 , MEMORY = 1 , OPENGL = 2 , OPENCL = 3 ,
  CUSTOM = 6
}
 Location where the data resides. More...
 

Public Member Functions

 TypedImage (const ImageDescriptor &descriptor, T *data=nullptr, Ownership own=Ownership::NotOwning)
 Create a new TypedImage from an ImageDescriptor.
 
 TypedImage (const vec3i &dimensions, int numChannels=1, T *data=nullptr, Ownership own=Ownership::NotOwning)
 Create a new TypedImage with given dimensions and channels.
 
 TypedImage (const TypedImage &)=delete
 
TypedImageoperator= (const TypedImage &)=delete
 
 TypedImage (TypedImage &&other) noexcept
 
TypedImageoperator= (TypedImage &&other) noexcept
 
std::unique_ptr< TypedImage< T > > clone () const
 Create a deep copy of the image.
 
bool update (const TypedImage< T > &other)
 Update image data pointed to by this object. If the other image is not compatible with the current one the image is resized.
 
bool update (const MemImage &other) override
 Update image data pointed to by this object.
 
bool update (const std::vector< T > &data)
 Update image data using non-image buffer. Data arrangement in this buffer is assumed to match the target image.
 
bool update (const T *data)
 More generic and somewhat less secure version of the above method.
 
void fill (T value)
 Fill image with the given constant value for all channels and pixels.
 
void fill (const std::vector< T > &channelValues)
 Fill image with the given channel values for all pixels.
 
void fillDouble (double value) override
 Fill image with the given double value for all channels and pixels.
 
void fillDouble (const std::vector< double > &channelValues) override
 Fill image with the given double channel values for all pixels.
 
const T * pointer () const
 Returns a typed pointer to the underlying raw pixel buffer of the image.
 
T * pointer ()
 
const void * data () const override
 Returns a void pointer to the underlying raw pixel buffer of the image.
 
void * data () override
 
value (int x, int y, int z=0, int c=0) const
 Return the pixel intensity at the coordinate without interpolation.
 
value (size_t index) const
 Return the pixel intensity at the index without interpolation.
 
double valueDouble (size_t index) const override
 Return the pixel intensity at the given index without interpolation casted to double.
 
double valueDouble (int x, int y, int z=0, int c=0) const override
 Return the pixel intensity at the coordinate without interpolation casted to double.
 
double valueDouble (double x, double y, double z=0, int c=0, bool clamp=true, bool *valid=nullptr) const override
 Return the pixel intensity at the given coordinate using linear interpolation casted to double.
 
void setValue (T value, int x, int y, int z=0, int c=0)
 Set the pixel intensity at the given coordinate to value.
 
void setValueDouble (double value, size_t index) const override
 Set the pixel intensity at the given index to value casted to the underlying type without any clamping or normalization.
 
void setValueDouble (double value, int x, int y, int z=0, int c=0) const override
 Set the pixel intensity at the given coordinate to value casted to the underlying type without any clamping or normalization.
 
std::pair< T, T > getRange () const
 Computes the minimum and maximum image intensity of the entire image.
 
void getRange (T &minVal, T &maxVal) const
 
void getRangeDouble (double &minVal, double &maxVal) const override
 Computes the minimum and maximum image intensity of the entire image casted to double.
 
std::unique_ptr< TypedImage< T > > getSliceView (int slice) const
 Extract a MemImage representing a view onto the specified slice of this image.
 
std::pair< double, double > getRangeDouble () const
 Computes the minimum and maximum image intensity of the entire image casted to double.
 
- Public Member Functions inherited from MemImage
std::unique_ptr< MemImageclone () const
 Create a deep copy of the image.
 
template<typename T>
TypedImage< T > * typed ()
 Convenience function to perform a dynamic_cast<TypedImage<T>> of this instance.
 
template<typename T>
const TypedImage< T > * typed () const
 
Location location () const override
 Specifies that the image resides in main memory.
 
bool load (const std::string &filename, int64_t offset=0)
 Loads the image content from a file, returns true if successful.
 
bool save (const std::string &filename) const
 Saves the image content to a file, returns true if successful.
 
std::pair< double, double > getRangeDouble () const
 Computes the minimum and maximum image intensity of the entire image casted to double.
 
std::unique_ptr< MemImagegetSliceView (int slice) const
 Extract a MemImage representing a view onto the specified slice of this image.
 
- Public Member Functions inherited from Image
 Image (const ImageDescriptor &desc)
 Create a new Image with the given descriptor.
 
 Image (const Image &other)=default
 
Imageoperator= (const Image &other)=default
 
 Image (Image &&other) noexcept=default
 
Imageoperator= (Image &&other) noexcept=default
 
const ImageDescriptordescriptor () const
 Return the image descriptor.
 
void configure (const Properties *p) override
 Configure the image descriptor from properties.
 
void configuration (Properties *p) const override
 Store image descriptor into properties.
 
void setShift (double val)
 Sets the intensity shift value.
 
void setScale (double val)
 Sets the intensity scale value.
 
void setSpacing (double sx, double sy, double sz=1.0)
 Specify pixel/voxel spacing with two or three scalar values.
 
void setSpacing (double sx, double sy, double sz, bool isMetric)
 Convenience function for specifying spacing and metric flag at the same time.
 
void setSpacing (const vec3 &s)
 Specify pixel/voxel spacing using a 3-vector.
 
void setSpacing (const vec3 &s, bool metric)
 Convenience function for specifying spacing and metric flag at the same time.
 
void setMetric (bool val)
 Set data to be metric.
 
double storageToOriginal (double value) const
 Applies the image's shift and scale in order to convert value from storage pixel value domain to original pixel value domain.
 
double originalToStorage (double value) const
 Applies the image's shift and scale in order to convert value from original pixel value domain to storage pixel value domain.
 
PixelType pixelType () const
 Returns the data type of the image.
 
Type type () const
 Returns the data type of the image.
 
int width () const
 Returns the width of the image.
 
int height () const
 Returns the height of the image.
 
int slices () const
 Returns the number of 3D slices of the image.
 
int channels () const
 Returns the number of channels of the image.
 
double shift () const
 Returns the intensity shift.
 
double scale () const
 Returns the intensity scale.
 
vec3 spacing () const
 Returns pointer to the pixel/voxel spacing values.
 
bool isMetric () const
 Returns true if data is metric.
 
vec3 extent () const
 Returns the physical size of the image as a vector.
 
vec3i dimensions () const
 Returns the dimensions of the image in pixels as a vector.
 
vec3 pixelToImage (const vec3 &pixel) const
 Convert a 3D pixel/voxel position to image coordinates.
 
vec3 imageToPixel (const vec3 &world) const
 Convert 3D image coordinates to pixel/voxel position.
 
mat4 pixelToImageMatrix () const
 Returns a 4x4 matrix to transform from image pixel space to image space.
 
mat4 imageToPixelMatrix () const
 Returns a 4x4 matrix to transform from image space to image pixel space.
 
size_t index (int x, int y, int z=0, int c=0) const
 Returns a linear memory index for a pixel or voxel.
 
bool hasIndex (int x, int y, int z=0, int c=0) const
 Returns true if the pixel at (x,y,z) exists, false otherwise.
 
vec4i coord (size_t index) const
 Returns the pixel/voxel coordinate (x,y,z,c) for a given index.
 
size_t size () const
 Returns the size (number of elements) of the image.
 
int typeSize () const
 Return the nominal size in bytes of standard data types, zero if unknown.
 
bool isInteger () const
 Returns whether the image is of an integer data type.
 
bool isSigned () const
 Returns whether the image type supports negative values.
 
size_t byteSize () const
 Returns the size of the image in bytes.
 
int alignment () const
 Returns the byte alignment of an image line (up to 8)
 
int dimension () const
 Returns the spatial dimension of the image.
 
bool compatible (const Image &other, bool ignoreType=false, bool ignore3D=false, bool ignoreChannels=false) const
 Tells if this image is compatible to another one.
 
- Public Member Functions inherited from Configurable
virtual void configureDefaults ()
 Retrieve the properties of this object, replaces values with their defaults and sets it again.
 
void registerParameter (ParameterBase *param)
 Register the given Parameter or SubProperty, so that it will be configured during configure()/configuration().
 
void unregisterParameter (const ParameterBase *param)
 Remove the given Parameter or SubProperty from the list of registered parameters.
 
 Configurable (const Configurable &rhs)
 
 Configurable (Configurable &&rhs) noexcept
 
Configurableoperator= (const Configurable &)
 
Configurableoperator= (Configurable &&) noexcept
 

Static Public Member Functions

static std::unique_ptr< TypedImage< T > > create (const ImageDescriptor &descriptor, T *data=nullptr, Ownership own=Ownership::NotOwning)
 Factory method to create a new TypedImage from an ImageDescriptor.
 
static std::unique_ptr< TypedImage< T > > create (const vec3i &dimensions, int numChannels=1, T *data=nullptr, Ownership own=Ownership::NotOwning)
 Factory method to create a new TypedImage of given dimensions and number of channels.
 
static std::unique_ptr< TypedImage< T > > zeros (const ImageDescriptor &descriptor)
 Factory method to create a zero-initialized image, pixel type in descriptor is ignored.
 
static std::unique_ptr< TypedImage< T > > zeros (const vec3i &dimensions, int numChannels=1)
 Factory method to create a zero-initialized image of given dimensions and number of channels.
 
- Static Public Member Functions inherited from MemImage
static std::unique_ptr< MemImagecreate (const ImageDescriptor &descriptor)
 Factory method to instantiate a MemImage from an ImageDescriptor.
 
static std::unique_ptr< MemImagecreate (const ImageDescriptor &descriptor, void *data, Ownership own=Ownership::NotOwning)
 Factory method to instantiate a MemImage from an ImageDescriptor and pointer to existing image data.
 
static std::unique_ptr< MemImagezeros (const ImageDescriptor &descriptor)
 Factory method to create a zero-initialized image.
 

Protected Member Functions

TypedImage< T > * cloneImpl () const override
 
std::unique_ptr< MemImagegetSliceViewImpl (int slice) const override
 
- Protected Member Functions inherited from MemImage
 MemImage (MemImage &&other) noexcept
 
MemImageoperator= (MemImage &&other) noexcept
 
 MemImage (const MemImage &other)=delete
 
MemImageoperator= (const MemImage &other)=delete
 
 MemImage (const ImageDescriptor &desc)
 
- Protected Member Functions inherited from Image
template<typename T>
bool typeCompatible () const
 

Protected Attributes

T * m_data
 Pointer to the actual image data.
 
Ownership m_own
 Do we own the data (i.e. container mode if false)
 
- Protected Attributes inherited from Image
ImageDescriptor m_descriptor
 
- Protected Attributes inherited from Configurable
std::vector< Paramm_params
 List of all registered Parameter and SubProperty instances.
 

Deprecated Interface

std::unique_ptr< MemImageprepare (bool msb=false, bool shiftOnly=false) override
 Optimal rescaling and conversion to unsigned data type if applicable.
 
std::unique_ptr< MemImageunscaled () const override
 Return copy of this image with intensity scale and shift undone, if necessary.
 

Additional Inherited Members

- Public Attributes inherited from Configurable
Signal signalParametersChanged
 Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted.
 

Constructor & Destructor Documentation

◆ TypedImage() [1/2]

template<typename T>
TypedImage ( const ImageDescriptor & descriptor,
T * data = nullptr,
Ownership own = Ownership::NotOwning )

Create a new TypedImage from an ImageDescriptor.

Parameters
descriptorImageDescriptor of the new image, pixel type is ignored
dataOptional pointer to image data, must match the descriptor layout if not null.
ownFlag whether the newly created image shall take ownership of data.

◆ TypedImage() [2/2]

template<typename T>
TypedImage ( const vec3i & dimensions,
int numChannels = 1,
T * data = nullptr,
Ownership own = Ownership::NotOwning )

Create a new TypedImage with given dimensions and channels.

Parameters
dimensionsImage width, height, and slices
numChannelsNumber of channels
dataOptional pointer to image data, must match the descriptor layout if not null.
ownFlag whether the newly created image shall take ownership of data.

Member Function Documentation

◆ create() [1/2]

template<typename T>
static std::unique_ptr< TypedImage< T > > create ( const ImageDescriptor & descriptor,
T * data = nullptr,
Ownership own = Ownership::NotOwning )
static

Factory method to create a new TypedImage from an ImageDescriptor.

Note
If the data buffer is not passed as argument, the data buffer of TypedImage is uninitialized
Parameters
descriptorImageDescriptor of the new image, pixel type is ignored
dataOptional pointer to image data, must match the descriptor layout if not null.
ownFlag whether the newly created image shall take ownership of data.

◆ create() [2/2]

template<typename T>
static std::unique_ptr< TypedImage< T > > create ( const vec3i & dimensions,
int numChannels = 1,
T * data = nullptr,
Ownership own = Ownership::NotOwning )
static

Factory method to create a new TypedImage of given dimensions and number of channels.

Note
If the data buffer is not passed as argument, the data buffer of TypedImage is uninitialized
Parameters
dimensionsImage width, height, and slices
numChannelsNumber of channels
dataOptional pointer to image data, must match the descriptor layout if not null.
ownFlag whether the newly created image shall take ownership of data.

◆ update()

template<typename T>
bool update ( const MemImage & other)
overridevirtual

Update image data pointed to by this object.

If the other image is not compatible with the current one the image is resized. If the other image has a different type this method does nothing.

Implements MemImage.

◆ fill()

template<typename T>
void fill ( const std::vector< T > & channelValues)

Fill image with the given channel values for all pixels.

The number of elements in channelValues must match the number of channels of this image.

◆ fillDouble() [1/2]

template<typename T>
void fillDouble ( double value)
overridevirtual

Fill image with the given double value for all channels and pixels.

Note
The passed value will be casted to the underlying type of the image.

Implements MemImage.

◆ fillDouble() [2/2]

template<typename T>
void fillDouble ( const std::vector< double > & channelValues)
overridevirtual

Fill image with the given double channel values for all pixels.

Note
The passed value will be casted to the underlying type of the image. The number of elements in channelValues must match the number of channels of this image.

Implements MemImage.

◆ data() [1/2]

template<typename T>
const void * data ( ) const
inlineoverridevirtual

Returns a void pointer to the underlying raw pixel buffer of the image.

Note
The TypedImage<T> specialization provides pointer() as type-safe alternative.

Implements MemImage.

◆ data() [2/2]

template<typename T>
void * data ( )
inlineoverridevirtual

Implements MemImage.

◆ value()

template<typename T>
T value ( int x,
int y,
int z = 0,
int c = 0 ) const

Return the pixel intensity at the coordinate without interpolation.

Note
Try to avoid calling this function repeatedly because the coordinate-to-index computation is slow. When accessing entire regions of the image prefer use the index-based overload incrementing the index by a suitable stride after each function call instead of always fully recomputing the index.

◆ valueDouble() [1/3]

template<typename T>
double valueDouble ( size_t index) const
inlineoverridevirtual

Return the pixel intensity at the given index without interpolation casted to double.

Implements MemImage.

◆ valueDouble() [2/3]

template<typename T>
double valueDouble ( int x,
int y,
int z = 0,
int c = 0 ) const
overridevirtual

Return the pixel intensity at the coordinate without interpolation casted to double.

Note
Try to avoid calling this function repeatedly because the coordinate-to-index computation is slow. When accessing entire regions of the image prefer use the index-based overload incrementing the index by a suitable stride after each function call instead of always fully recomputing the index.

Implements MemImage.

◆ valueDouble() [3/3]

template<typename T>
double valueDouble ( double x,
double y,
double z = 0,
int c = 0,
bool clamp = true,
bool * valid = nullptr ) const
overridevirtual

Return the pixel intensity at the given coordinate using linear interpolation casted to double.

Note
Be aware that this function is rather slow, use it only if you really need interpolation. Consider using the set of free functions in Math::Interpolation as they provide more control on the interpolation behavior.

Implements MemImage.

◆ setValue()

template<typename T>
void setValue ( T value,
int x,
int y,
int z = 0,
int c = 0 )

Set the pixel intensity at the given coordinate to value.

Note
Try to avoid calling this function repeatedly because the coordinate-to-index computation is slow. When accessing entire regions of the image prefer use the index-based overload incrementing the index by a suitable stride after each function call instead of always fully recomputing the index.

◆ setValueDouble() [1/2]

template<typename T>
void setValueDouble ( double value,
size_t index ) const
inlineoverridevirtual

Set the pixel intensity at the given index to value casted to the underlying type without any clamping or normalization.

Implements MemImage.

◆ setValueDouble() [2/2]

template<typename T>
void setValueDouble ( double value,
int x,
int y,
int z = 0,
int c = 0 ) const
overridevirtual

Set the pixel intensity at the given coordinate to value casted to the underlying type without any clamping or normalization.

Note
Try to avoid calling this function repeatedly because the coordinate-to-index computation is slow. When accessing entire regions of the image prefer use the index-based overload incrementing the index by a suitable stride after each function call instead of always fully recomputing the index.

Implements MemImage.

◆ getRangeDouble()

template<typename T>
void getRangeDouble ( double & minVal,
double & maxVal ) const
overridevirtual

Computes the minimum and maximum image intensity of the entire image casted to double.

Implements MemImage.

◆ getSliceView()

template<typename T>
std::unique_ptr< TypedImage< T > > getSliceView ( int slice) const

Extract a MemImage representing a view onto the specified slice of this image.

The returned image only points to the data and does not own it. It is therefore only valid as long this image is valid. Returns nullptr if slice is out of range.

◆ prepare()

template<typename T>
std::unique_ptr< MemImage > prepare ( bool msb = false,
bool shiftOnly = false )
overridevirtual

Optimal rescaling and conversion to unsigned data type if applicable.

Deprecated
"Use ImageProcessing::createConverted() and/or ImageProcessing::swapEndianness() instead."

Implements MemImage.

◆ unscaled()

template<typename T>
std::unique_ptr< MemImage > unscaled ( ) const
overridevirtual

Return copy of this image with intensity scale and shift undone, if necessary.

The method returns a zero pointer if there is no scale and shift and if the image has a floating-point data type.

Deprecated
"Use ImageProcessing::createConverted() instead."

Implements MemImage.

◆ cloneImpl()

template<typename T>
TypedImage< T > * cloneImpl ( ) const
overrideprotectedvirtual

Implements MemImage.

◆ getSliceViewImpl()

template<typename T>
std::unique_ptr< MemImage > getSliceViewImpl ( int slice) const
overrideprotectedvirtual

Implements MemImage.


The documentation for this class was generated from the following files:
Search Tab / S to search, Esc to close