Data2D< T > Class Template Reference

Inheritance diagram for Data2D< T >:

RadarImage< T > List of all members.

Detailed Description

template<class T>
class Data2D< T >

A reference-counting method to store 2D data.

This class maintains 2D data and ensures that allocated data is freed. When copying, it increments a pointer so that the data is freed only when the last instance of the same data is being destroyed. This class simplifies memory management and access of two-dimensional arrays. Use this class whenever you need large images created on the heap. It is templatized to create 2D arrays of ints, floats and doubles. You may need to instantiate additional datatypes if needed.

The orientation is such that the origin is at the top-left corner; The vertical direction is x (increasing downwards) and the horizontal direction is y (increasing to the right.) This gives us a right-handed co-oridinate system.

Author:
Lakshman, NSSL


Public Member Functions

 Data2D (T **input_data, int sx, int sy)
 Creates object with sx rows and sy columns and initializes it with the elements of passed in array.
 Data2D (int sx, int sy)
 Uninitialized object with sx rows and sy columns.
 Data2D (int sx, int sy, const T &)
 Object with sx rows and sy columns all initialized to the input value.
 Data2D (const Data2D< T > &)
 The copy constructor simply does reference counting.
Data2Doperator= (const Data2D< T > &)
 Assignment operator, behaves just like the copy constructor.
 ~Data2D ()
 Releases its hold on the data.
int write_pgm (const char *filename, int scaleValues=0) const
 Writes the data out to a pgm (portable gray map) file.
void showImage (const char *filename, bool inBackground) const
 Shows image by using the "xv" command found in your search path.
void set_val (int x, int y, T input_value)
 Set the value at xth row and yth col.
void set_val (T input_value)
 Set all values to be input_value.
get_val (int x, int y) const
 Get the value at xth row and yth col.
int dim_x () const
 Number of rows.
int dim_y () const
 Number of cols.
int num_copies () const
 Number of copies.
void incr (int x, int y, T incr_val=1)
 Increment pixel at x,y by incr_val.
XImage * create_ximage (Display *display, Visual *visual, XColor *colors) const
 Creates an XImage out of the data .
char mapped_color (T data_value, XColor *colors) const
 Overlad this call to get a new color mapping.
Data2D< T > twin () const
 To construct two separate instances of the data.
Data2D< int > roundOff () const
 Will round off all the values in a Data2D<double>, for example.
Data2D< T > crop (size_t x1, size_t y1, size_t x2, size_t y2) const
 Crop the image to the top-left and bottom-right location given.
Data2D< T > zeropad (int newSize) const
 Zeropad and return a square object of size newSize,newSize.
Data2D< T > removezeropad (int newSize) const
 Crop the image around the edges to get a square object of size newSize, newSize.
void convolve (const Data2D< double > &kernel)
 Convolve this data using the kernel provided.
void convolve (const Data2D< T > &kernel)
 Convolve this data using the kernel provided.
void print_out () const
 prints, to standard output, the elements of the array as a table
void print_out (const char *format) const
 prints, to standard output, the elements of the array as a table
void surface_print_out () const
 prints, to standard output, the elements of the array for inpuyt into a surface plot.

Static Public Member Functions

static Data2D< int > read_pgm (const char *filename)
 To read a 2D data from a pgm file.

Protected Member Functions

int allocateData2D (int sx, int sy)
 To allocate data of sx rows and sy columns.
void destruct_self ()
 Release allocated data.

Protected Attributes

T ** data
 2D array of data.
int size_x
 Number of rows.
int size_y
 Number of columns.
int * num_pointers
 The total number of objects pointing to this data.


Constructor & Destructor Documentation

template<class T>
Data2D< T >::Data2D ( T **  input_data,
int  sx,
int  sy 
)

Creates object with sx rows and sy columns and initializes it with the elements of passed in array.

sx or sy if zero will create a "null" object that you can test using if ( obj.dim_x() * obj.dim_y() ) ...

template<class T>
Data2D< T >::Data2D ( int  sx,
int  sy 
)

Uninitialized object with sx rows and sy columns.

template<class T>
Data2D< T >::Data2D ( int  sx,
int  sy,
const T &   
)

Object with sx rows and sy columns all initialized to the input value.

template<class T>
Data2D< T >::Data2D ( const Data2D< T > &   ) 

The copy constructor simply does reference counting.

Note in particular that changing one element of a Data2D changes all its copies. This can be particularly hard to understand especially when you see:

void myfilter( Data2D<int> yourdata ){ your data is changed!! yourdata.set_val( 0, 0, 34 ); }

If you want a completely separate copy, one that can be changed without affecting the original, use the twin() function:

template<class T>
Data2D< T >::~Data2D (  )  [inline]

Releases its hold on the data.

The resources are released only when the last copy is done.


Member Function Documentation

template<class T>
int Data2D< T >::allocateData2D ( int  sx,
int  sy 
) [protected]

To allocate data of sx rows and sy columns.

template<class T>
void Data2D< T >::convolve ( const Data2D< T > &  kernel  ) 

Convolve this data using the kernel provided.

See FFTObj for a more efficient implementation.

template<class T>
void Data2D< T >::convolve ( const Data2D< double > &  kernel  ) 

Convolve this data using the kernel provided.

See FFTObj for a more efficient implementation.

template<class T>
XImage* Data2D< T >::create_ximage ( Display *  display,
Visual *  visual,
XColor *  colors 
) const

Creates an XImage out of the data .

.. This uses Xlib calls. Remember to destroy using XDestroyImage ... Overload the mapped color call to get a new color mapping ...

template<class T>
Data2D<T> Data2D< T >::crop ( size_t  x1,
size_t  y1,
size_t  x2,
size_t  y2 
) const

Crop the image to the top-left and bottom-right location given.

template<class T>
void Data2D< T >::destruct_self (  )  [protected]

Release allocated data.

template<class T>
int Data2D< T >::dim_x (  )  const [inline]

Number of rows.

template<class T>
int Data2D< T >::dim_y (  )  const [inline]

Number of cols.

template<class T>
T Data2D< T >::get_val ( int  x,
int  y 
) const [inline]

Get the value at xth row and yth col.

Does no bound-checking.

template<class T>
void Data2D< T >::incr ( int  x,
int  y,
incr_val = 1 
) [inline]

Increment pixel at x,y by incr_val.

template<class T>
char Data2D< T >::mapped_color ( data_value,
XColor *  colors 
) const

Overlad this call to get a new color mapping.

template<class T>
int Data2D< T >::num_copies (  )  const [inline]

Number of copies.

template<class T>
Data2D& Data2D< T >::operator= ( const Data2D< T > &   ) 

Assignment operator, behaves just like the copy constructor.

template<class T>
void Data2D< T >::print_out ( const char *  format  )  const

prints, to standard output, the elements of the array as a table

template<class T>
void Data2D< T >::print_out (  )  const

prints, to standard output, the elements of the array as a table

template<class T>
static Data2D<int> Data2D< T >::read_pgm ( const char *  filename  )  [static]

To read a 2D data from a pgm file.

template<class T>
Data2D<T> Data2D< T >::removezeropad ( int  newSize  )  const

Crop the image around the edges to get a square object of size newSize, newSize.

template<class T>
Data2D<int> Data2D< T >::roundOff (  )  const

Will round off all the values in a Data2D<double>, for example.

template<class T>
void Data2D< T >::set_val ( input_value  )  [inline]

Set all values to be input_value.

template<class T>
void Data2D< T >::set_val ( int  x,
int  y,
input_value 
) [inline]

Set the value at xth row and yth col.

Does no bound-checking.

template<class T>
void Data2D< T >::showImage ( const char *  filename,
bool  inBackground 
) const

Shows image by using the "xv" command found in your search path.

template<class T>
void Data2D< T >::surface_print_out (  )  const

prints, to standard output, the elements of the array for inpuyt into a surface plot.

template<class T>
Data2D<T> Data2D< T >::twin (  )  const

To construct two separate instances of the data.

template<class T>
int Data2D< T >::write_pgm ( const char *  filename,
int  scaleValues = 0 
) const

Writes the data out to a pgm (portable gray map) file.

The default is to not modify the data in any way. If your data can be > 255, you could scale it for viewing. Negative numbers are always written out as zero.

template<class T>
Data2D<T> Data2D< T >::zeropad ( int  newSize  )  const

Zeropad and return a square object of size newSize,newSize.

A rectangular version is not provided because I've never needed it.


Member Data Documentation

template<class T>
T** Data2D< T >::data [protected]

2D array of data.

template<class T>
int* Data2D< T >::num_pointers [protected]

The total number of objects pointing to this data.

template<class T>
int Data2D< T >::size_x [protected]

Number of rows.

template<class T>
int Data2D< T >::size_y [protected]

Number of columns.


Generated on Fri May 4 13:40:21 2012 for WDSS-IIw2algs by  doxygen 1.4.7