Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mitsuba::BlockedArray< Value, logblockSize > Class Template Reference

Blocked generic 2D array data type. More...

#include <mitsuba/core/barray.h>

Public Member Functions

 BlockedArray ()
 Create an unitialized blocked array. More...
 
 BlockedArray (const Vector2i &size)
 Allocate memory for a new blocked array of the specified width and height. More...
 
void alloc (const Vector2i &size)
 Allocate memory for a blocked array of the specified width and height. More...
 
void map (void *ptr, const Vector2i &size)
 Initialize the blocked array with a given pointer and array size. More...
 
template<typename AltValue >
void init (const AltValue *data)
 Initialize the contents of the blocked array with values from a non-blocked source in row-major order. More...
 
template<typename AltValue >
void init (const AltValue *data, AltValue &min_, AltValue &max_, AltValue &avg_)
 Initialize the contents of the blocked array with values from a non-blocked source in row-major order and collect component-wise minimum, maximum, and average information. More...
 
template<typename AltValue >
void copyTo (AltValue *data) const
 Copy the contents of the blocked array to a non-blocked destination buffer in row-major order. More...
 
void cleanup ()
 Zero out unused memory portions. More...
 
const Vector2igetSize () const
 Return the size of the array. More...
 
size_t getBufferSize () const
 Return the size of the allocated buffer. More...
 
int getWidth () const
 Return the width of the array. More...
 
int getHeight () const
 Return the height of the array. More...
 
 ~BlockedArray ()
 Release all memory. More...
 
Value & operator() (int x, int y)
 Access the specified entry. More...
 
const Value & operator() (int x, int y) const
 Access the specified entry (const version) More...
 
Value * getData ()
 Return a pointer to the internal representation. More...
 
const Value * getData () const
 Return a pointer to the internal representation (const version) More...
 

Static Public Member Functions

static size_t bufferSize (const Vector2i &size)
 Return the hypothetical heap memory requirements of a blocked array for the given size. More...
 

Static Public Attributes

static const size_t blockSize = 1 << logblockSize
 

Protected Member Functions

size_t getBlock (int a) const
 Determine the index of the block which contains the given global index. More...
 
size_t getOffset (int a) const
 Determine the offset within the block that contains the given global index. More...
 

Detailed Description

template<typename Value, size_t logblockSize = 2>
class mitsuba::BlockedArray< Value, logblockSize >

Blocked generic 2D array data type.

This class implements a blocked 2D array for cache-efficient access to two-dimensional data.

Constructor & Destructor Documentation

template<typename Value , size_t logblockSize = 2>
mitsuba::BlockedArray< Value, logblockSize >::BlockedArray ( )
inline

Create an unitialized blocked array.

template<typename Value , size_t logblockSize = 2>
mitsuba::BlockedArray< Value, logblockSize >::BlockedArray ( const Vector2i size)
inline

Allocate memory for a new blocked array of the specified width and height.

template<typename Value , size_t logblockSize = 2>
mitsuba::BlockedArray< Value, logblockSize >::~BlockedArray ( )
inline

Release all memory.

Member Function Documentation

template<typename Value , size_t logblockSize = 2>
void mitsuba::BlockedArray< Value, logblockSize >::alloc ( const Vector2i size)
inline

Allocate memory for a blocked array of the specified width and height.

template<typename Value , size_t logblockSize = 2>
static size_t mitsuba::BlockedArray< Value, logblockSize >::bufferSize ( const Vector2i size)
inlinestatic

Return the hypothetical heap memory requirements of a blocked array for the given size.

template<typename Value , size_t logblockSize = 2>
void mitsuba::BlockedArray< Value, logblockSize >::cleanup ( )
inline

Zero out unused memory portions.

This is useful in case we want to write the internal representation to disk and avoid accessing uninitialized memory (otherwise, valgrind or other similar tools will complain..)

template<typename Value , size_t logblockSize = 2>
template<typename AltValue >
void mitsuba::BlockedArray< Value, logblockSize >::copyTo ( AltValue *  data) const
inline

Copy the contents of the blocked array to a non-blocked destination buffer in row-major order.

This is effectively the opposite of init().

Remarks
This function performs type casts when Value != AltValue
template<typename Value , size_t logblockSize = 2>
size_t mitsuba::BlockedArray< Value, logblockSize >::getBlock ( int  a) const
inlineprotected

Determine the index of the block which contains the given global index.

template<typename Value , size_t logblockSize = 2>
size_t mitsuba::BlockedArray< Value, logblockSize >::getBufferSize ( ) const
inline

Return the size of the allocated buffer.

template<typename Value , size_t logblockSize = 2>
Value* mitsuba::BlockedArray< Value, logblockSize >::getData ( )
inline

Return a pointer to the internal representation.

template<typename Value , size_t logblockSize = 2>
const Value* mitsuba::BlockedArray< Value, logblockSize >::getData ( ) const
inline

Return a pointer to the internal representation (const version)

template<typename Value , size_t logblockSize = 2>
int mitsuba::BlockedArray< Value, logblockSize >::getHeight ( ) const
inline

Return the height of the array.

template<typename Value , size_t logblockSize = 2>
size_t mitsuba::BlockedArray< Value, logblockSize >::getOffset ( int  a) const
inlineprotected

Determine the offset within the block that contains the given global index.

template<typename Value , size_t logblockSize = 2>
const Vector2i& mitsuba::BlockedArray< Value, logblockSize >::getSize ( ) const
inline

Return the size of the array.

template<typename Value , size_t logblockSize = 2>
int mitsuba::BlockedArray< Value, logblockSize >::getWidth ( ) const
inline

Return the width of the array.

template<typename Value , size_t logblockSize = 2>
template<typename AltValue >
void mitsuba::BlockedArray< Value, logblockSize >::init ( const AltValue *  data)
inline

Initialize the contents of the blocked array with values from a non-blocked source in row-major order.

Remarks
This function performs type casts when Value != AltValue
template<typename Value , size_t logblockSize = 2>
template<typename AltValue >
void mitsuba::BlockedArray< Value, logblockSize >::init ( const AltValue *  data,
AltValue &  min_,
AltValue &  max_,
AltValue &  avg_ 
)
inline

Initialize the contents of the blocked array with values from a non-blocked source in row-major order and collect component-wise minimum, maximum, and average information.

Assumes that AltValue is some kind of TVector or TSpectrum instance.

Remarks
This function performs type casts when Value != AltValue
template<typename Value , size_t logblockSize = 2>
void mitsuba::BlockedArray< Value, logblockSize >::map ( void *  ptr,
const Vector2i size 
)
inline

Initialize the blocked array with a given pointer and array size.

This is useful in case memory has already been allocated.

template<typename Value , size_t logblockSize = 2>
Value& mitsuba::BlockedArray< Value, logblockSize >::operator() ( int  x,
int  y 
)
inline

Access the specified entry.

template<typename Value , size_t logblockSize = 2>
const Value& mitsuba::BlockedArray< Value, logblockSize >::operator() ( int  x,
int  y 
) const
inline

Access the specified entry (const version)

Member Data Documentation

template<typename Value , size_t logblockSize = 2>
const size_t mitsuba::BlockedArray< Value, logblockSize >::blockSize = 1 << logblockSize
static

The documentation for this class was generated from the following file: