Contents User Forum Source Index APIs by Task APIs by Level Data


G3D::Map2D< Storage, Compute > Class Template Reference

Map of values across a discrete 2D plane. More...

#include <Map2D.h>

Inherits G3D::ReferenceCountedObject.

List of all members.

Public Types

typedef Compute ComputeType
typedef ReferenceCountedPointer<
Map2D
Ref
typedef Storage StorageType
typedef Map2D< Storage, Compute > Type

Public Member Functions

Compute bicubic (const Vector2 &p) const
Compute bicubic (const Vector2 &p, WrapMode wrap) const
Compute bicubic (float x, float y) const
Compute bicubic (float x, float y, WrapMode wrap) const
Compute bilinear (const Vector2 &p, WrapMode wrap) const
Compute bilinear (const Vector2 &p) const
Compute bilinear (float x, float y) const
Compute bilinear (float x, float y, WrapMode wrap) const
bool changed ()
void flipHorizontal ()
void flipVertical ()
Storage & get (const Vector2int16 &p)
Storage & get (int x, int y)
Storage & get (int x, int y, WrapMode wrap)
const Storage & get (const Vector2int16 &p, WrapMode wrap) const
const Storage & get (const Vector2int16 &p) const
const Storage & get (int x, int y) const
const Storage & get (int x, int y, WrapMode wrap) const
const Array< Storage > & getArray () const
Array< Storage > & getArray ()
const Storage * getCArray () const
Storage * getCArray ()
uint32 height () const
bool inBounds (const Vector2int16 &v) const
bool inBounds (int x, int y) const
Compute nearest (const Vector2 &p) const
Compute nearest (float x, float y) const
Compute nearest (float x, float y, WrapMode wrap) const
Rect2D rect2DBounds () const
void ReferenceCountedObject_zeroWeakPointers ()
void resize (uint32 newW, uint32 newH)
void set (int x, int y, const Storage &v)
void set (int x, int y, const Storage &v, WrapMode wrap)
void set (const Vector2int16 &p, const Storage &v)
void setAll (const Storage &v)
void setChanged (bool c)
void setWrapMode (WrapMode m)
Vector2int16 size () const
size_t sizeInMemory () const
uint32 width () const
WrapMode wrapMode () const

Static Public Member Functions

static Ref create (int w=0, int h=0, WrapMode wrap=WrapMode::ERROR)

Public Attributes

GMutex mutex
AtomicInt32 ReferenceCountedObject_refCount
_WeakPtrLinkedListReferenceCountedObject_weakPointer

Protected Member Functions

Compute bicubic (const Compute *ctrl, double s) const
const Storage & fastGet (int x, int y) const
void fastSet (int x, int y, const Storage &v)
 Map2D (int w, int h, WrapMode wrap)
const Storage & slowGet (int x, int y, WrapMode wrap)

Protected Attributes

WrapMode _wrapMode
Array< Storage > data
uint32 h
AtomicInt32 m_changed
uint32 w
Storage ZERO


Detailed Description

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
class G3D::Map2D< Storage, Compute >

Map of values across a discrete 2D plane.

Can be thought of as a generic class for 2D images, allowing flexibility as to pixel format and convenient methods. In fact, the "pixels" can be any values on a grid that can be sensibly interpolated--RGB colors, scalars, 4D vectors, and so on.

Other "image" classes in G3D:

G3D::GImage - Supports file formats, fast, Color3uint8 and Color4uint8 formats. No interpolation.

G3D::Texture::Ref - Represents image on the graphics card (not directly readable on the CPU). Supports 2D, 3D, and a variety of interpolation methods, loads file formats.

G3D::Image3 - A subclass of Map2D<Color3> that supports image loading and saving and conversion to Texture.

G3D::Image4 - A subclass of Map2D<Color4> that supports image loading and saving and conversion to Texture.

G3D::Image3uint8 - A subclass of Map2D<Color3uint8> that supports image loading and saving and conversion to Texture.

G3D::Image4uint8 - A subclass of Map2D<Color4uint8> that supports image loading and saving and conversion to Texture.

There are two type parameters-- the first (@ Storage) is the type used to store the "pixel" values efficiently and the second (Compute) is the type operated on by computation. The Compute::Compute(Storage&) constructor is used to convert between storage and computation types. Storage is often an integer version of Compute, for example Map2D<double, uint8>. By default, the computation type is:

     Storage       Computation

     uint8          float32
     uint16         float32
     uint32         float64
     uint64         float64

     int8           float32
     int16          float32
     int32          float64
     int64          float64

     float32        float64
     float64        float64

     Vector2        Vector2
     Vector2int16   Vector2

     Vector3        Vector3
     Vector3int16   Vector3

     Vector4        Vector4

     Color3         Color3
     Color3uint8    Color3

     Color4         Color4
     Color4uint8    Color4
    
Any other storage type defaults to itself as the computation type.

The computation type can be any that supports lerp, +, -, *, /, and an empty constructor.

Assign value:

im->set(x, y, 7); or im->get(x, y) = 7;

Read value:

int c = im(x, y);

Can also sample with nearest neighbor, bilinear, and bicubic interpolation.

Sampling follows OpenGL conventions, where pixel values represent grid points and (0.5, 0.5) is half-way between two vertical and two horizontal grid points. To draw an image of dimensions w x h with nearest neighbor sampling, render pixels from [0, 0] to [w - 1, h - 1].

Under the WrapMode::CLAMP wrap mode, the value of bilinear interpolation becomes constant outside [1, w - 2] horizontally. Nearest neighbor interpolation is constant outside [0, w - 1] and bicubic outside [3, w - 4]. The class does not offer quadratic interpolation because the interpolation filter could not center over a pixel.

Author:
Morgan McGuire, morgan@cs.williams.edu


Member Typedef Documentation

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
typedef Compute G3D::Map2D< Storage, Compute >::ComputeType

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
typedef ReferenceCountedPointer<Map2D> G3D::Map2D< Storage, Compute >::Ref

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
typedef Storage G3D::Map2D< Storage, Compute >::StorageType

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
typedef Map2D<Storage, Compute> G3D::Map2D< Storage, Compute >::Type


Constructor & Destructor Documentation

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
G3D::Map2D< Storage, Compute >::Map2D ( int  w,
int  h,
WrapMode  wrap 
) [inline, protected]


Member Function Documentation

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Compute G3D::Map2D< Storage, Compute >::bicubic ( const Vector2 p  )  const [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Compute G3D::Map2D< Storage, Compute >::bicubic ( const Vector2 p,
WrapMode  wrap 
) const [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Compute G3D::Map2D< Storage, Compute >::bicubic ( float  x,
float  y 
) const [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Compute G3D::Map2D< Storage, Compute >::bicubic ( float  x,
float  y,
WrapMode  wrap 
) const [inline]

Uses Catmull-Rom splines to interpolate between grid values.

Guaranteed to match nearest(x, y) at integers.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Compute G3D::Map2D< Storage, Compute >::bicubic ( const Compute *  ctrl,
double  s 
) const [inline, protected]

Given four control points and a value on the range [0, 1) evaluates the Catmull-rom spline between the times of the middle two control points.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Compute G3D::Map2D< Storage, Compute >::bilinear ( const Vector2 p,
WrapMode  wrap 
) const [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Compute G3D::Map2D< Storage, Compute >::bilinear ( const Vector2 p  )  const [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Compute G3D::Map2D< Storage, Compute >::bilinear ( float  x,
float  y 
) const [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Compute G3D::Map2D< Storage, Compute >::bilinear ( float  x,
float  y,
WrapMode  wrap 
) const [inline]

Needs to access elements from (floor(x), floor(y)) to (floor(x) + 1, floor(y) + 1) and will use the wrap mode appropriately (possibly generating out of bounds errors).

Guaranteed to match nearest(x, y) at integers.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
bool G3D::Map2D< Storage, Compute >::changed (  )  [inline]

Returns true if this map has been written to since the last call to setChanged(false).

This is useful if you are caching a texture map other value that must be recomputed whenever this changes.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
static Ref G3D::Map2D< Storage, Compute >::create ( int  w = 0,
int  h = 0,
WrapMode  wrap = WrapMode::ERROR 
) [inline, static]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
const Storage& G3D::Map2D< Storage, Compute >::fastGet ( int  x,
int  y 
) const [inline, protected]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
void G3D::Map2D< Storage, Compute >::fastSet ( int  x,
int  y,
const Storage &  v 
) [inline, protected]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
void G3D::Map2D< Storage, Compute >::flipHorizontal (  )  [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
void G3D::Map2D< Storage, Compute >::flipVertical (  )  [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Storage& G3D::Map2D< Storage, Compute >::get ( const Vector2int16 p  )  [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Storage& G3D::Map2D< Storage, Compute >::get ( int  x,
int  y 
) [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Storage& G3D::Map2D< Storage, Compute >::get ( int  x,
int  y,
WrapMode  wrap 
) [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
const Storage& G3D::Map2D< Storage, Compute >::get ( const Vector2int16 p,
WrapMode  wrap 
) const [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
const Storage& G3D::Map2D< Storage, Compute >::get ( const Vector2int16 p  )  const [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
const Storage& G3D::Map2D< Storage, Compute >::get ( int  x,
int  y 
) const [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
const Storage& G3D::Map2D< Storage, Compute >::get ( int  x,
int  y,
WrapMode  wrap 
) const [inline]

Get the value at (x, y).

Note that the type of image->get(x, y) is the storage type, not the computation type. If the constructor promoting Storage to Compute rescales values (as, for example Color3(Color3uint8&) does), this will not match the value returned by Map2D::nearest.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
const Array<Storage>& G3D::Map2D< Storage, Compute >::getArray (  )  const [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Array<Storage>& G3D::Map2D< Storage, Compute >::getArray (  )  [inline]

Row-major array.

You should call setChanged(true) if you mutate the array.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
const Storage* G3D::Map2D< Storage, Compute >::getCArray (  )  const [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Storage* G3D::Map2D< Storage, Compute >::getCArray (  )  [inline]

Returns a pointer to the underlying row-major data.

There is no padding at the end of the row. Be careful--this will be reallocated during a resize. You should call setChanged(true) if you mutate the array.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
uint32 G3D::Map2D< Storage, Compute >::height (  )  const [inline]

Pixel height.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
bool G3D::Map2D< Storage, Compute >::inBounds ( const Vector2int16 v  )  const [inline]

is (x, y) strictly within the image bounds, or will it trigger some kind of wrap mode

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
bool G3D::Map2D< Storage, Compute >::inBounds ( int  x,
int  y 
) const [inline]

is (x, y) strictly within the image bounds, or will it trigger some kind of wrap mode

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Compute G3D::Map2D< Storage, Compute >::nearest ( const Vector2 p  )  const [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Compute G3D::Map2D< Storage, Compute >::nearest ( float  x,
float  y 
) const [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Compute G3D::Map2D< Storage, Compute >::nearest ( float  x,
float  y,
WrapMode  wrap 
) const [inline]

Returns the nearest neighbor.

Pixel values are considered to be at the upper left corner, so image->nearest(x, y) == image(x, y)

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Rect2D G3D::Map2D< Storage, Compute >::rect2DBounds (  )  const [inline]

Rectangle from (0, 0) to (w, h).

void G3D::ReferenceCountedObject::ReferenceCountedObject_zeroWeakPointers (  )  [inline, inherited]

Automatically called immediately before the object is deleted.

This is not called from the destructor because it needs to be invoked before the subclass destructor.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
void G3D::Map2D< Storage, Compute >::resize ( uint32  newW,
uint32  newH 
) [inline]

Resizes without clearing, leaving garbage.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
void G3D::Map2D< Storage, Compute >::set ( int  x,
int  y,
const Storage &  v 
) [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
void G3D::Map2D< Storage, Compute >::set ( int  x,
int  y,
const Storage &  v,
WrapMode  wrap 
) [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
void G3D::Map2D< Storage, Compute >::set ( const Vector2int16 p,
const Storage &  v 
) [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
void G3D::Map2D< Storage, Compute >::setAll ( const Storage &  v  )  [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
void G3D::Map2D< Storage, Compute >::setChanged ( bool  c  )  [inline]

Set/unset the changed flag.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
void G3D::Map2D< Storage, Compute >::setWrapMode ( WrapMode  m  )  [inline]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Vector2int16 G3D::Map2D< Storage, Compute >::size (  )  const [inline]

Dimensions in pixels.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
size_t G3D::Map2D< Storage, Compute >::sizeInMemory (  )  const [inline]

Number of bytes occupied by the image data and this structure.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
const Storage& G3D::Map2D< Storage, Compute >::slowGet ( int  x,
int  y,
WrapMode  wrap 
) [inline, protected]

Handles the exceptional cases from get.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
uint32 G3D::Map2D< Storage, Compute >::width (  )  const [inline]

Pixel width.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
WrapMode G3D::Map2D< Storage, Compute >::wrapMode (  )  const [inline]


Member Data Documentation

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
WrapMode G3D::Map2D< Storage, Compute >::_wrapMode [protected]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Array<Storage> G3D::Map2D< Storage, Compute >::data [protected]

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
uint32 G3D::Map2D< Storage, Compute >::h [protected]

Height, in pixels.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
AtomicInt32 G3D::Map2D< Storage, Compute >::m_changed [protected]

0 if no mutating method has been invoked since the last call to setChanged();

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
GMutex G3D::Map2D< Storage, Compute >::mutex

Although Map2D is not threadsafe (except for the setChanged() method), you can use this mutex to create your own threadsafe access to a Map2D.

Not used by the default implementation.

The long name is to keep this from accidentally conflicting with a subclass's variable name.

Do not use or explicitly manipulate this value--its type may change in the future and is not part of the supported API.

Linked list of all weak pointers that reference this (some may be on the stack!).

Do not use or explicitly manipulate this value.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
uint32 G3D::Map2D< Storage, Compute >::w [protected]

Width, in pixels.

template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
Storage G3D::Map2D< Storage, Compute >::ZERO [protected]


The documentation for this class was generated from the following file:
Generated on Thu Aug 2 11:40:46 2007 for G3D by doxygen 1.5.2
Hosted by SourceForge.net Logo