Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes

cmtk::TemplateArray< T > Class Template Reference
[cmtkBase Library]

Template for Variable-Typed Data Arrays. More...

#include <cmtkTemplateArray.h>

Inheritance diagram for cmtk::TemplateArray< T >:
Inheritance graph
[legend]
Collaboration diagram for cmtk::TemplateArray< T >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef TemplateArray< T > Self
 This type.
typedef TypedArray Superclass
 Base class.
typedef SmartPointer< SelfSmartPtr
 Smart pointer.
typedef DataTypeTraits< T > TypeTraits
 Data type traits.

Public Member Functions

const T * GetDataPtrConcrete () const
 Return const pointer to actual data.
T * GetDataPtrConcrete ()
 Return pointer to actual data.
void SetPaddingValueTemplate (const T paddingData)
 Set the value to mark non-existent data using template data type.
 TemplateArray (void *const data, const size_t datasize, const bool freeArray, const bool paddingflag, const void *paddingData)
 Constructor.
 TemplateArray (const size_t datasize=0)
 Constructor.
virtual ~TemplateArray ()
 Destructor.
virtual void SetPaddingValue (const Types::DataItem paddingData)
 Set the value to mark non-existent data using interface data type.
virtual void SetPaddingPtr (const void *paddingData)
 Set the value to mark non-existent data using interface data type.
virtual void ReplacePaddingData (const Types::DataItem value=0)
 Replace Padding data (padding) with given value.
virtual bool IsPaddingAt (const size_t index) const
 Check for NULL data at given index.
virtual bool IsPaddingOrZeroAt (const size_t index) const
 Check for PADDING data or zero value at given index.
virtual void SetPaddingAt (const size_t index=0)
 Set the specified array element to no data present.
virtual ScalarDataType GetType () const
 Return id of primitive data type handled by this object.
virtual size_t GetItemSize () const
 Return size in bytes of the primitive data type handled by this object.
virtual void * GetDataPtr (const size_t offset=0)
 Return pointer to an element in this objects data array.
virtual const void * GetDataPtr (const size_t offset=0) const
 Return const pointer to an element in this objects data array.
virtual T * GetDataPtrTemplate (const size_t offset=0)
 Return pointer to an element in this objects data array.
virtual const T * GetDataPtrTemplate (const size_t offset=0) const
 Return const pointer to an element in this objects data array.
virtual Types::DataItemGetSubArray (Types::DataItem *const toPtr, const size_t fromIdx, const size_t len, const Types::DataItem substPadding=0) const
 Convert and copy continuous sub-array to a given destination.
virtual Types::DataItemGetSubArray (const size_t fromIdx, const size_t len, const Types::DataItem substPadding=0) const
 Return a sub array of the current instance.
virtual T ConvertItem (const Types::DataItem value)
 Convert Types::DataItem to template type.
virtual TypedArray::SmartPtr Convert (const ScalarDataType dtype) const
 Convert to typed array of any given template type.
virtual void * ConvertSubArray (const ScalarDataType dtype, const size_t fromIdx, const size_t len) const
 Convert a sub-array to any given primitive data type.
virtual void ConvertSubArray (void *const destination, const ScalarDataType dtype, const size_t fromIdx, const size_t len) const
 Convert a sub-array to given primitive data type into existing array.
virtual void ChangeEndianness ()
 Change endianness of data.
virtual void Rescale (const Types::DataItem scale=1, const Types::DataItem offset=0)
 Scale values in the array.
virtual void RescaleAndShift (const Types::DataItem scale=1, const Types::DataItem offset=0, const size_t shiftBits=0)
 Scale and shift values in the array.
virtual void Rescale (const Types::DataItem scale, const Types::DataItem offset, const Types::DataItem truncLo, const Types::DataItem truncHi=CMTK_ITEM_MAX)
 Scale values in the array with truncation boundaries.
virtual void GammaCorrection (const Types::DataItem gamma)
 Apply gamma correction.
virtual void ApplyFunctionFloat (typename Self::FunctionTypeFloat f)
 Apply real function to data.
virtual void ApplyFunctionDouble (typename Self::FunctionTypeDouble f)
 Apply real function to data.
virtual void Threshold (const Types::DataItemRange &range)
 Threshold data.
virtual void ThresholdToPadding (const Types::DataItemRange &range)
 Threshold data.
virtual void Binarize (const Types::DataItem threshold=0)
 Binarize array values with given threshold.
virtual void MakeAbsolute ()
 Convert all values to absolute values.
virtual bool Get (Types::DataItem &value, const size_t index) const
 Get an item from the array.
virtual void GetSequence (Types::DataItem *const values, const size_t index, const size_t length) const
 Get a sequence of items from the array.
virtual void Set (const Types::DataItem value, const size_t index)
 Set an item in the array.
virtual void * GetPaddingPtr () const
 Return padding data value as pointer to native representation.
virtual Types::DataItem GetPaddingValue () const
 Return padding data value as pointer to native representation.
virtual bool PaddingDataAt (const size_t index) const
 Test if there is PADDING data at a particular location.
virtual Types::DataItemGetData () const
 Get the whole array data as an exchange type array.
virtual void SetData (Types::DataItem *const data)
 Set all data from an Types::DataItem array.
virtual void ClearArray (const bool usePaddingData=false)
 Clear entire array.
virtual const Types::DataItemRange GetRange () const
 Calculate minimum and maximum data value.
virtual const Types::Range< T > GetRangeTemplate () const
 Calculate minimum and maximum data value.
virtual double GetEntropy (const bool fractional=CMTK_HISTOGRAM_DISCRETE, const int numberOfBins=128) const
 Calculate entropy of distribution of values in this array.
virtual double GetEntropy (Histogram< unsigned int > &histogram) const
 Calculate entropy of values in this array using existing histogram.
virtual double GetEntropy (Histogram< double > &histogram, const bool fractional=CMTK_HISTOGRAM_DISCRETE) const
 Calculate entropy of values in this array using existing histogram.
virtual double GetEntropy (Histogram< double > &histogram, const double *kernel, const size_t kernelRadius) const
 Calculate entropy of values in this array using existing histogram and kernel for Parzen windowing.
virtual size_t GetStatistics (Types::DataItem &mean, Types::DataItem &variance) const
 Calculate statistics.
virtual void BlockSet (const Types::DataItem value, const size_t fromOffset, const size_t toOffset)
 Set data block to constant value.
virtual Histogram< unsigned
int >::SmartPtr 
GetHistogram (const unsigned int numberOfBins, const bool centeredBins=false) const
 Get data histogram.
virtual void ApplyFunctionObject (const TypedArrayFunction &f)
 Apply function class to the values of this array.

Static Public Member Functions

static Self::SmartPtr Create (const size_t size)
 Create array of this type.

Protected Member Functions

virtual SelfCloneVirtual () const
 Clone this object.

Private Member Functions

virtual void Alloc (const size_t datasize)
 Allocate data array.
virtual void FreeData ()
 De-allocate data array.

Private Attributes

T * Data
 The acutal data array.
Padding
 Value used for missing data.

Detailed Description

template<class T>
class cmtk::TemplateArray< T >

Template for Variable-Typed Data Arrays.

From this object, various children are derived for the concrete data types to be handled.

Author:
Torsten Rohlfing

Definition at line 56 of file cmtkTemplateArray.h.


Member Typedef Documentation

template<class T >
typedef TemplateArray<T> cmtk::TemplateArray< T >::Self

This type.

Reimplemented from cmtk::TypedArray.

Definition at line 62 of file cmtkTemplateArray.h.

template<class T >
typedef SmartPointer<Self> cmtk::TemplateArray< T >::SmartPtr

Smart pointer.

Reimplemented from cmtk::TypedArray.

Definition at line 68 of file cmtkTemplateArray.h.

template<class T >
typedef TypedArray cmtk::TemplateArray< T >::Superclass

Base class.

Definition at line 65 of file cmtkTemplateArray.h.

template<class T >
typedef DataTypeTraits<T> cmtk::TemplateArray< T >::TypeTraits

Data type traits.

Definition at line 71 of file cmtkTemplateArray.h.


Constructor & Destructor Documentation

template<class T >
cmtk::TemplateArray< T >::TemplateArray ( void *const   data,
const size_t  datasize,
const bool  freeArray,
const bool  paddingflag,
const void *  paddingData 
) [inline]

Constructor.

A typed array is built from an existing array.

Parameters:
dataPointer to the array of values to be stored.
datasizeNumber of elements in the data array.
freeArrayTag of the memory handler that has to be used for freeing the array after use.
paddingflagFlag that indicates whether there are missing elements in the existing data array.
paddingDataValue that marks missing elements in the data array if "paddingFlag" is true.

Definition at line 102 of file cmtkTemplateArray.h.

template<class T >
cmtk::TemplateArray< T >::TemplateArray ( const size_t  datasize = 0 ) [inline]

Constructor.

Allocate an array of a given size.

Definition at line 118 of file cmtkTemplateArray.h.

References NULL.

template<class T >
virtual cmtk::TemplateArray< T >::~TemplateArray (  ) [inline, virtual]

Destructor.

Free memory by a call to FreeData().

Definition at line 128 of file cmtkTemplateArray.h.


Member Function Documentation

template<class T >
virtual void cmtk::TemplateArray< T >::Alloc ( const size_t  datasize ) [inline, private, virtual]

Allocate data array.

Parameters:
datasizeNumber of data items to allocate memory for.

Implements cmtk::TypedArray.

Definition at line 609 of file cmtkTemplateArray.h.

References cmtk::Memory::DeleteArray(), and NULL.

template<class T >
virtual void cmtk::TemplateArray< T >::Binarize ( const Types::DataItem  threshold = 0 ) [inline, virtual]

Binarize array values with given threshold.

All values greater than threshold (default: zero) are set to one, all values smaller or equal are set to zero.

Implements cmtk::TypedArray.

Definition at line 408 of file cmtkTemplateArray.h.

template<class T >
virtual void cmtk::TemplateArray< T >::ClearArray ( const bool  usePaddingData = false ) [inline, virtual]

Clear entire array.

Parameters:
usePaddingDataIf this flag is set, then the array will be filled with the PaddingData value, if one exists. Otherwise, the array will be filled with the respective data type's zero value.

Implements cmtk::TypedArray.

Definition at line 541 of file cmtkTemplateArray.h.

template<class T >
virtual Self* cmtk::TemplateArray< T >::CloneVirtual (  ) const [inline, protected, virtual]
template<class T >
virtual T cmtk::TemplateArray< T >::ConvertItem ( const Types::DataItem  value ) [inline, virtual]

Convert Types::DataItem to template type.

This function takes an Types::DataItem value and converts it into a value of the type stored in this array.

Parameters:
valueThe item in Types::DataItem representation.
Returns:
The value of type T corresponding to the "value" parameter's value. Conversion is done using the type converter class given as template parameter "C" to this class. Therefore, rounding will occur if necessary.

Definition at line 273 of file cmtkTemplateArray.h.

template<class T >
static Self::SmartPtr cmtk::TemplateArray< T >::Create ( const size_t  size ) [inline, static]

Create array of this type.

Definition at line 74 of file cmtkTemplateArray.h.

Referenced by cmtk::EntropyMinimizationIntensityCorrectionFunctionalBase::SetInputImage().

template<class T >
virtual void cmtk::TemplateArray< T >::FreeData (  ) [inline, private, virtual]

De-allocate data array.

The array is freed using the same memory handler that allocated it. In any case, the current Data pointer is set to NULL.

Implements cmtk::TypedArray.

Definition at line 636 of file cmtkTemplateArray.h.

References cmtk::Memory::DeleteArray(), and NULL.

template<class T >
virtual bool cmtk::TemplateArray< T >::Get ( Types::DataItem value,
const size_t  index 
) const [inline, virtual]

Get an item from the array.

Parameters:
valueThe variable referenced by this parameter is set to the data item stored at the given location in the array. If this item is marked is "padding data", ie. non-existent, "value" is set to zero.
indexThe index of the item to retrieve. Valid values are in the range [0..Datasize()-1].
Returns:
A non-zero value is returned if and only if the value stored in the array at the given location is marked as valid data.

Implements cmtk::TypedArray.

Definition at line 442 of file cmtkTemplateArray.h.

References CheckBounds.

template<class T >
virtual Types::DataItem* cmtk::TemplateArray< T >::GetData (  ) const [inline, virtual]

Get the whole array data as an exchange type array.

Returns:
Pointer to a memory region allocated by Memory::AllocateArray(). This region is filled with all values in the present array as Types::DataItem values. The created array is not maintained by this object. The caller has to make sure free() is called for it.

Implements cmtk::TypedArray.

Definition at line 511 of file cmtkTemplateArray.h.

template<class T >
virtual void* cmtk::TemplateArray< T >::GetDataPtr ( const size_t  offset = 0 ) [inline, virtual]

Return pointer to an element in this objects data array.

Implements cmtk::TypedArray.

Definition at line 191 of file cmtkTemplateArray.h.

template<class T >
virtual const void* cmtk::TemplateArray< T >::GetDataPtr ( const size_t  offset = 0 ) const [inline, virtual]

Return const pointer to an element in this objects data array.

Implements cmtk::TypedArray.

Definition at line 197 of file cmtkTemplateArray.h.

template<class T >
const T* cmtk::TemplateArray< T >::GetDataPtrConcrete (  ) const [inline]

Return const pointer to actual data.

Definition at line 80 of file cmtkTemplateArray.h.

template<class T >
T* cmtk::TemplateArray< T >::GetDataPtrConcrete (  ) [inline]

Return pointer to actual data.

Definition at line 83 of file cmtkTemplateArray.h.

template<class T >
virtual const T* cmtk::TemplateArray< T >::GetDataPtrTemplate ( const size_t  offset = 0 ) const [inline, virtual]

Return const pointer to an element in this objects data array.

Definition at line 209 of file cmtkTemplateArray.h.

template<class T >
virtual T* cmtk::TemplateArray< T >::GetDataPtrTemplate ( const size_t  offset = 0 ) [inline, virtual]

Return pointer to an element in this objects data array.

Definition at line 203 of file cmtkTemplateArray.h.

template<class T >
virtual size_t cmtk::TemplateArray< T >::GetItemSize (  ) const [inline, virtual]

Return size in bytes of the primitive data type handled by this object.

Implements cmtk::TypedArray.

Definition at line 188 of file cmtkTemplateArray.h.

template<class T >
virtual void* cmtk::TemplateArray< T >::GetPaddingPtr (  ) const [inline, virtual]

Return padding data value as pointer to native representation.

This function returns a pointer to the value used by this object for marking non-existent data. As the type of this value depends on the template parameters of this class, only a void pointer can be returned. The caller has to interpret the value stored at that location itself.

If this array does NOT have a padding data value, the data pointed to by the result of this function is undefined.

Returns:
Pointer to the padding value of this object.

Implements cmtk::TypedArray.

Definition at line 493 of file cmtkTemplateArray.h.

template<class T >
virtual Types::DataItem cmtk::TemplateArray< T >::GetPaddingValue (  ) const [inline, virtual]

Return padding data value as pointer to native representation.

Implements cmtk::TypedArray.

Definition at line 497 of file cmtkTemplateArray.h.

template<class T >
virtual void cmtk::TemplateArray< T >::GetSequence ( Types::DataItem *const   values,
const size_t  index,
const size_t  length 
) const [inline, virtual]

Get a sequence of items from the array.

Parameters:
valuesThis must point to an allocated array of at least as many Types::DataItem objects as given in the "length" parameter.
indexThe index of the item to retrieve. Valid values are in the range [0..Datasize()-1].
lengthNumber of consecutive values to get.

Implements cmtk::TypedArray.

Definition at line 461 of file cmtkTemplateArray.h.

References CheckBounds.

template<class T >
virtual Types::DataItem* cmtk::TemplateArray< T >::GetSubArray ( Types::DataItem *const   toPtr,
const size_t  fromIdx,
const size_t  len,
const Types::DataItem  substPadding = 0 
) const [inline, virtual]

Convert and copy continuous sub-array to a given destination.

Parameters:
toPtrA pointer to the location where the data shall be stored.
fromIdxThe index of the first copied data item in the array, beginning with 0.
lenLength, ie. number of values, to copy. The calling function must take care that there is enough memory pointed to by toPtr to store this many values of the transfer data type.
substPaddingWhere there is padding data in the copied range, this value is put to the output.
Returns:
The pointer given to this function to store the desired data to.

Implements cmtk::TypedArray.

Definition at line 225 of file cmtkTemplateArray.h.

template<class T >
virtual Types::DataItem* cmtk::TemplateArray< T >::GetSubArray ( const size_t  fromIdx,
const size_t  len,
const Types::DataItem  substPadding = 0 
) const [inline, virtual]

Return a sub array of the current instance.

The data is returned in a newly allocated primitive array of the Types::DataItem data exchange type.

Parameters:
fromIdxCopying starts at this index in the array. The range for this parameter is [0..Size-1].
lenNumber of data elements to be copied.
substPaddingIf this flag is set (default is NO), then during copying all elements marked as "non-existent" are replaced by zero.
Returns:
Pointer to a newly allocated Types::DataItem array. Allocation is done using the allocator given as template parameter "M" to this class.

Implements cmtk::TypedArray.

Definition at line 259 of file cmtkTemplateArray.h.

template<class T >
virtual ScalarDataType cmtk::TemplateArray< T >::GetType (  ) const [inline, virtual]

Return id of primitive data type handled by this object.

Implements cmtk::TypedArray.

Definition at line 185 of file cmtkTemplateArray.h.

template<class T >
virtual bool cmtk::TemplateArray< T >::IsPaddingAt ( const size_t  index ) const [inline, virtual]

Check for NULL data at given index.

If this array does not have PaddingFlag set, the result is always false.

Implements cmtk::TypedArray.

Definition at line 162 of file cmtkTemplateArray.h.

template<class T >
virtual bool cmtk::TemplateArray< T >::IsPaddingOrZeroAt ( const size_t  index ) const [inline, virtual]

Check for PADDING data or zero value at given index.

Implements cmtk::TypedArray.

Definition at line 169 of file cmtkTemplateArray.h.

template<class T >
virtual void cmtk::TemplateArray< T >::MakeAbsolute (  ) [inline, virtual]

Convert all values to absolute values.

Implements cmtk::TypedArray.

Definition at line 425 of file cmtkTemplateArray.h.

References cmtk::Wrappers::Abs().

template<class T >
virtual bool cmtk::TemplateArray< T >::PaddingDataAt ( const size_t  index ) const [inline, virtual]

Test if there is PADDING data at a particular location.

Implements cmtk::TypedArray.

Definition at line 500 of file cmtkTemplateArray.h.

template<class T >
virtual void cmtk::TemplateArray< T >::ReplacePaddingData ( const Types::DataItem  value = 0 ) [inline, virtual]

Replace Padding data (padding) with given value.

Implements cmtk::TypedArray.

Definition at line 146 of file cmtkTemplateArray.h.

template<class T >
virtual void cmtk::TemplateArray< T >::Rescale ( const Types::DataItem  scale = 1,
const Types::DataItem  offset = 0 
) [inline, virtual]

Scale values in the array.

A call to this member function will perform an in-place rescaling of the values in the array.

Parameters:
scaleThe original data value is multiplied by the parameter first.
offsetThis value is added to the original data value after multiplying it by the scale parameter.

Implements cmtk::TypedArray.

Definition at line 305 of file cmtkTemplateArray.h.

template<class T >
virtual void cmtk::TemplateArray< T >::Rescale ( const Types::DataItem  scale,
const Types::DataItem  offset,
const Types::DataItem  truncLo,
const Types::DataItem  truncHi = CMTK_ITEM_MAX 
) [inline, virtual]

Scale values in the array with truncation boundaries.

A call to this member function will perform an in-place rescaling of the values in the array with value range truncation. Truncation takes place after the scaling itself, i.e., the truncation boundaries refer to the already scaled values.

Parameters:
scaleThe original data value is multiplied by the parameter first.
offsetThis value is added to the original data value after multiplying it by the scale parameter.
truncLoLower truncation boundary. Scaled items below this threshold will be set to equal its value.
truncHiUpper truncation boundary. Scaled items above this threshold will be set to equal its value.

Implements cmtk::TypedArray.

Definition at line 339 of file cmtkTemplateArray.h.

template<class T >
virtual void cmtk::TemplateArray< T >::RescaleAndShift ( const Types::DataItem  scale = 1,
const Types::DataItem  offset = 0,
const size_t  shiftBits = 0 
) [inline, virtual]

Scale and shift values in the array.

Data values are scaled first, then the offsewt is added, and finally the (left) bit shift is applied. In fact, to make sure we're not messing up floats, the bit shift is applied as a multiplication.

Implements cmtk::TypedArray.

Definition at line 317 of file cmtkTemplateArray.h.

template<class T >
virtual void cmtk::TemplateArray< T >::Set ( const Types::DataItem  value,
const size_t  index 
) [inline, virtual]

Set an item in the array.

Parameters:
valueThe new value for the specified item.
indexThe index of the item to set. Valid values are in the range [0..Datasize()-1].
See also:
Convert

Implements cmtk::TypedArray.

Definition at line 477 of file cmtkTemplateArray.h.

References CheckBounds.

template<class T >
virtual void cmtk::TemplateArray< T >::SetData ( Types::DataItem *const   data ) [inline, virtual]

Set all data from an Types::DataItem array.

This function sets all values stored in the present array from a memory region with Types::DataItem values.

Parameters:
dataPointer to an array of Types::DataItem values. Control over the source array is not taken by this object. If it is on the heap, then the calling routine remains responsible for de-allocating the array afterwards.

Implements cmtk::TypedArray.

Definition at line 529 of file cmtkTemplateArray.h.

template<class T >
virtual void cmtk::TemplateArray< T >::SetPaddingAt ( const size_t  size_t = 0 ) [inline, virtual]

Set the specified array element to no data present.

Implements cmtk::TypedArray.

Definition at line 174 of file cmtkTemplateArray.h.

template<class T >
virtual void cmtk::TemplateArray< T >::SetPaddingPtr ( const void *  paddingData ) [inline, virtual]

Set the value to mark non-existent data using interface data type.

Implements cmtk::TypedArray.

Definition at line 140 of file cmtkTemplateArray.h.

template<class T >
virtual void cmtk::TemplateArray< T >::SetPaddingValue ( const Types::DataItem  paddingData ) [inline, virtual]

Set the value to mark non-existent data using interface data type.

Implements cmtk::TypedArray.

Definition at line 134 of file cmtkTemplateArray.h.

template<class T >
void cmtk::TemplateArray< T >::SetPaddingValueTemplate ( const T  paddingData ) [inline]

Set the value to mark non-existent data using template data type.

Definition at line 86 of file cmtkTemplateArray.h.

template<class T >
virtual void cmtk::TemplateArray< T >::Threshold ( const Types::DataItemRange range ) [inline, virtual]

Threshold data.

All values above upper threshold are set to upper thrershold. All values below lower threshold are set to lower threshold.

Implements cmtk::TypedArray.

Definition at line 371 of file cmtkTemplateArray.h.

References cmtk::Types::Range< T >::m_LowerBound, and cmtk::Types::Range< T >::m_UpperBound.

template<class T >
virtual void cmtk::TemplateArray< T >::ThresholdToPadding ( const Types::DataItemRange range ) [inline, virtual]

Threshold data.

All values outside the threshold range are set to the Padding (padding) value.

Implements cmtk::TypedArray.

Definition at line 391 of file cmtkTemplateArray.h.

References cmtk::Types::Range< T >::m_LowerBound, and cmtk::Types::Range< T >::m_UpperBound.


Member Data Documentation

template<class T >
T* cmtk::TemplateArray< T >::Data [private]

The acutal data array.

Definition at line 601 of file cmtkTemplateArray.h.

Referenced by cmtk::TemplateArray< T >::CloneVirtual().

template<class T >
T cmtk::TemplateArray< T >::Padding [private]

Value used for missing data.

Definition at line 604 of file cmtkTemplateArray.h.

Referenced by cmtk::TemplateArray< T >::CloneVirtual().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines