Follow this link to skip to the main content

claraty::N_2D_Array< T > Class Template Reference

#include <2d_array.h>

Inheritance diagram for claraty::N_2D_Array< T >:

Inheritance graph
[legend]
Collaboration diagram for claraty::N_2D_Array< T >:

Collaboration graph
[legend]
List of all members.

Public Types

enum  SIZE_TYPE { SQUARE, EQUALS, NCOLS_EQUALS_NROWS }
typedef T value_type
typedef value_typepointer
typedef const value_typeconst_pointer
typedef N_2D_Array_Iterator<
T > 
iterator
typedef N_2D_Array_const_Iterator<
T > 
const_iterator
typedef value_typereference
typedef const value_typeconst_reference
typedef size_t size_type
typedef ptrdiff_t difference_type

Public Member Functions

 N_2D_Array ()
 N_2D_Array (int n_rows, int n_cols)
template<class In>
 N_2D_Array (int n_rows, int n_cols, In start)
 N_2D_Array (const N_2D_Array &m)
 N_2D_Array (const N_2D_Array &parent, int left, int top, int width, int height)
N_2D_Arrayoperator= (const T &rhs)
N_2D_Arrayoperator= (const N_2D_Array &rhs)
virtual ~N_2D_Array ()
template<class In>
N_2D_Arrayset_diagonal (int size, In start)
N_2D_Arrayset_diagonal (const N_2D_Array< T > &a)
int get_size () const
int ncols () const
int get_num_of_cols () const
int nrows () const
int get_num_of_rows () const
bool is_square () const
void resize (int newNumRows, int newNumCols)
bool is_subarray () const
iterator begin ()
const_iterator begin () const
iterator end ()
const_iterator end () const
N_2D_Arraydisplace_subarray (int delta_x, int delta_y)
N_2D_Arrayresize_subarray (int left, int top, int width, int height)
N_2D_Arrayassociate_subarray (const N_2D_Array &parent, int left, int top, int width, int height)
int get_full_num_cols () const
int get_full_num_rows () const
void dissociate (int new_nrows=-1, int new_ncols=-1)
N_2D_Array< T > get_row (int row) const
N_2D_Array< T > get_col (int col) const
const T * get_row_pointer (int row) const
iterator column_iterator (int col)
const_iterator column_iterator (int col) const
T & operator() (int r, int c)
const T & operator() (int r, int c) const
T & rc (int row, int column)
const T & rc (int row, int column) const
T & xy (int x, int y)
const T & xy (int x, int y) const
T & xy (const N_2D_Point_i &p)
const T & xy (const N_2D_Point_i &p) const
void write (std::ostream &os) const
 operator void * () const
N_2D_Array operator== (const N_2D_Array &rhs) const
N_2D_Array transpose () const
bool io (FDM_Map map)

Protected Member Functions

T & element (int i)
const T & element (int i) const
T * get_data ()
const T * get_data () const
template<class In>
void _copy (In start)
void _copy (T filler)
template<class rhsType>
int _check_size (SIZE_TYPE type, const N_2D_Array< rhsType > &rhs) const
void _init_special (int nr, int nc, T *data, int memwidth)
void _drop_memory ()
void _init (int n_rows, int n_cols)
void _init_index (bool allocate=true)
bool _is_noncontiguous () const

Protected Attributes

int _num_of_rows
int _num_of_cols
int _mem_width
int _mem_height
T * _elements
T ** _index
T * _mem_base
Reference_Count_ref_count
bool _isSubarray

Detailed Description

template<typename T>
class claraty::N_2D_Array< T >

Definition at line 57 of file 2d_array.h.


Member Typedef Documentation

template<typename T>
typedef T claraty::N_2D_Array< T >::value_type

Definition at line 64 of file 2d_array.h.

template<typename T>
typedef value_type* claraty::N_2D_Array< T >::pointer

Definition at line 65 of file 2d_array.h.

template<typename T>
typedef const value_type* claraty::N_2D_Array< T >::const_pointer

Definition at line 66 of file 2d_array.h.

template<typename T>
typedef N_2D_Array_Iterator<T> claraty::N_2D_Array< T >::iterator

Definition at line 67 of file 2d_array.h.

template<typename T>
typedef N_2D_Array_const_Iterator<T> claraty::N_2D_Array< T >::const_iterator

Definition at line 68 of file 2d_array.h.

template<typename T>
typedef value_type& claraty::N_2D_Array< T >::reference

Definition at line 69 of file 2d_array.h.

template<typename T>
typedef const value_type& claraty::N_2D_Array< T >::const_reference

Definition at line 70 of file 2d_array.h.

template<typename T>
typedef size_t claraty::N_2D_Array< T >::size_type

Definition at line 71 of file 2d_array.h.

template<typename T>
typedef ptrdiff_t claraty::N_2D_Array< T >::difference_type

Definition at line 72 of file 2d_array.h.


Member Enumeration Documentation

template<typename T>
enum claraty::N_2D_Array::SIZE_TYPE

Enumerator:
SQUARE 
EQUALS 
NCOLS_EQUALS_NROWS 

Definition at line 60 of file 2d_array.h.

00060                  { SQUARE, 
00061                    EQUALS,
00062                    NCOLS_EQUALS_NROWS };


Constructor & Destructor Documentation

template<typename T>
claraty::N_2D_Array< T >::N_2D_Array (  )  [inline]

Definition at line 91 of file 2d_array.h.

Referenced by claraty::N_2D_Array< T >::operator==().

00092     : _num_of_rows(0), 
00093       _num_of_cols(0), 
00094       _mem_width(0), 
00095       _mem_height(0),
00096       _elements(NULL), 
00097       _index(NULL), 
00098       _mem_base(0) 
00099   {
00100     _ref_count = new Reference_Count(1);
00101     _isSubarray = false;
00102   }

template<class T>
claraty::N_2D_Array< T >::N_2D_Array ( int  n_rows,
int  n_cols 
)

Definition at line 476 of file 2d_array.h.

References claraty::N_2D_Array< T >::_init(), and claraty::N_2D_Array< T >::_ref_count.

00477 {
00478   // elements are created using the default constructor (so may have undefined
00479   // values)
00480   _init(num_of_rows, num_of_cols);
00481   _ref_count = new Reference_Count(1);
00482 }

Here is the call graph for this function:

template<typename T>
template<class In>
claraty::N_2D_Array< T >::N_2D_Array ( int  n_rows,
int  n_cols,
In  start 
) [inline]

Definition at line 114 of file 2d_array.h.

00114                                                {
00115     _init(n_rows, n_cols);
00116     _copy(start);
00117     _ref_count = new Reference_Count(1);
00118   }

template<class T>
claraty::N_2D_Array< T >::N_2D_Array ( const N_2D_Array< T > &  m  ) 

Definition at line 486 of file 2d_array.h.

References claraty::N_2D_Array< T >::_copy(), claraty::N_2D_Array< T >::_elements, claraty::N_2D_Array< T >::_init(), claraty::N_2D_Array< T >::_num_of_cols, claraty::N_2D_Array< T >::_num_of_rows, claraty::N_2D_Array< T >::_ref_count, claraty::N_2D_Array< T >::begin(), and claraty::N_2D_Array< T >::is_subarray().

00487 {
00488   _init(m._num_of_rows, m._num_of_cols);
00489   if (m.is_subarray())
00490     _copy(m.begin());
00491   else
00492     _copy(m._elements);
00493   _ref_count = new Reference_Count(1);
00494 
00495   // cout << "N_2D_Array constructor N_2D_Array(const N_2D_Array&)" << std::endl;
00496 }

Here is the call graph for this function:

template<class T>
claraty::N_2D_Array< T >::N_2D_Array ( const N_2D_Array< T > &  parent,
int  left,
int  top,
int  width,
int  height 
)

Definition at line 500 of file 2d_array.h.

References claraty::N_2D_Array< T >::_elements, claraty::N_2D_Array< T >::_init_index(), claraty::N_2D_Array< T >::_isSubarray, claraty::N_2D_Array< T >::_mem_width, claraty::N_2D_Array< T >::_ref_count, and claraty::Reference_Count::increment().

00502   : _num_of_rows(height), _num_of_cols(width),
00503     _mem_width(parent._mem_width), _mem_height(parent._mem_height),
00504     _mem_base(parent._mem_base), _ref_count(parent._ref_count)
00505 {
00506   _isSubarray = true;
00507   _ref_count->increment();
00508   _elements = parent._elements + top * _mem_width + left;
00509   _init_index();
00510 }

Here is the call graph for this function:

template<typename T>
virtual claraty::N_2D_Array< T >::~N_2D_Array (  )  [inline, virtual]

Definition at line 131 of file 2d_array.h.

00131                         {
00132     _ref_count->decrement();
00133     delete [] _index;
00134     if (_ref_count->get_value() == 0) {
00135       delete [] _mem_base;
00136       delete _ref_count;
00137     }
00138   }


Member Function Documentation

template<class T>
N_2D_Array< T > & claraty::N_2D_Array< T >::operator= ( const T &  rhs  ) 

Reimplemented in claraty::Matrix< T >, claraty::Matrix_NxM< T, Nrows, Ncols >, claraty::Matrix< double >, claraty::Matrix< float >, claraty::Matrix< Pixel_Type >, and claraty::Matrix< uint16_t >.

Definition at line 643 of file 2d_array.h.

References claraty::N_2D_Array< T >::_copy().

00644 {
00645   _copy(filler);
00646   return *this;
00647 }

Here is the call graph for this function:

template<class T>
N_2D_Array< T > & claraty::N_2D_Array< T >::operator= ( const N_2D_Array< T > &  rhs  ) 

Definition at line 651 of file 2d_array.h.

References claraty::N_2D_Array< T >::_copy(), claraty::N_2D_Array< T >::begin(), claraty::N_2D_Array< T >::get_num_of_cols(), claraty::N_2D_Array< T >::get_num_of_rows(), and claraty::N_2D_Array< T >::resize().

00652 {
00653   if (this == &rhs) return *this;
00654   
00655   resize(rhs.get_num_of_rows(), rhs.get_num_of_cols());
00656 
00657   _copy(rhs.begin());
00658 
00659   return *this;
00660 }

Here is the call graph for this function:

template<class T>
template<class In>
N_2D_Array< T > & claraty::N_2D_Array< T >::set_diagonal ( int  size,
In  start 
)

Definition at line 516 of file 2d_array.h.

References claraty::N_2D_Array< T >::_num_of_cols, and claraty::N_2D_Array< T >::is_square().

Referenced by claraty::Matrix< uint16_t >::Matrix(), and claraty::N_2D_Array< uint16_t >::set_diagonal().

00517 {
00518   if (!is_square()) 
00519     std::cerr << "matrix error: cannot set diagonal on a non-square matrix"
00520               << std::endl;
00521   else if (size!=_num_of_cols) 
00522     std::cerr << "matrix error: number of diagonal elements (" << size << ") "
00523               << "is not the same as matrix dimension of " << _num_of_cols
00524               << std::endl;
00525   else 
00526     for (int i = 0; i < _num_of_cols; ++i, ++start)
00527       operator()(i, i) = *start;
00528   return *this;
00529 }

Here is the call graph for this function:

template<typename T>
N_2D_Array& claraty::N_2D_Array< T >::set_diagonal ( const N_2D_Array< T > &  a  )  [inline]

Definition at line 143 of file 2d_array.h.

00143                                                    {
00144     return set_diagonal(a.get_size(), a.begin());
00145   }

template<typename T>
bool claraty::N_2D_Array< T >::is_square (  )  const [inline]

Definition at line 159 of file 2d_array.h.

Referenced by claraty::det(), claraty::inverse(), and claraty::N_2D_Array< T >::set_diagonal().

00159 { return _num_of_rows == _num_of_cols; }

template<typename T>
void claraty::N_2D_Array< T >::resize ( int  newNumRows,
int  newNumCols 
) [inline]

Reimplemented in claraty::Matrix_NxM< T, Nrows, Ncols >.

Definition at line 168 of file 2d_array.h.

Referenced by claraty::Camera::_verify_resize_image(), claraty::N_2D_Array< uint16_t >::dissociate(), claraty::Transform_Op< T >::filter(), claraty::Rescale_Op< T >::filter(), claraty::Non_Maxima_Sup_Op::filter(), claraty::Convolve_Op< TEMPLATE_REFS >::filter(), claraty::Gamma_Op::gamma_correct(), claraty::Resample_Op::halfsample(), claraty::Image_IO_Pgm_Simple::load(), claraty::Image_IO_Factory::load_image(), claraty::Wheel_Locomotor_Model::map_mechanism_model_to_wheel_locomotor_model(), claraty::Mass_Properties::Mass_Properties(), claraty::Matrix< uint16_t >::operator=(), claraty::N_2D_Array< T >::operator=(), and claraty::Resample_Op::resample().

00168                                                 {
00169     if (_num_of_rows != newNumRows || _num_of_cols != newNumCols) {
00170       if (_isSubarray) {
00171         std::cerr << "N_2D_Array::resize cannot be used on a subarray!"
00172                   << std::endl;
00173         // throw exception
00174       } else if (_ref_count->get_value() != 1) {
00175         std::cerr << "N_2D_Array::resize cannot be used on an array being "
00176           "shared by subarrays" << std::endl;
00177         // throw exception
00178       } else if (get_size() == newNumRows * newNumCols &&
00179                  get_size() != 0) {
00180         delete [] _index;
00181         _num_of_rows = newNumRows;
00182         _num_of_cols = newNumCols;
00183         _mem_width = newNumCols;
00184         _mem_height = newNumRows;
00185         _init_index(true);
00186       } else {
00187         // total array size is different - reallocate everything. technically,
00188         // we could check the number of rows, and save a new/delete cycle on
00189         // the _index, but it's not that big of a deal if we're reallocating
00190         // the underlying data space anyway.
00191         delete [] _mem_base;
00192         delete [] _index;
00193         _init(newNumRows, newNumCols);
00194       }
00195     }
00196   }

template<typename T>
const_iterator claraty::N_2D_Array< T >::begin (  )  const [inline]

Definition at line 204 of file 2d_array.h.

00204                                {
00205     return const_iterator(_elements, _is_noncontiguous(), _num_of_cols,
00206                           _mem_width);
00207   }

template<typename T>
const_iterator claraty::N_2D_Array< T >::end (  )  const [inline]

Definition at line 212 of file 2d_array.h.

00212                              {
00213     return const_iterator(_elements + _num_of_rows * _mem_width,
00214                           _is_noncontiguous(), _num_of_cols, _mem_width);
00215   }

template<class T>
N_2D_Array< T > & claraty::N_2D_Array< T >::displace_subarray ( int  delta_x,
int  delta_y 
)

Definition at line 534 of file 2d_array.h.

References claraty::N_2D_Array< T >::_elements, claraty::N_2D_Array< T >::_index, claraty::N_2D_Array< T >::_isSubarray, claraty::N_2D_Array< T >::_mem_width, and claraty::N_2D_Array< T >::_num_of_rows.

00535 {
00536   if (!_isSubarray) { // @@ This should throw an exception
00537     std::cerr << "N_2D_Array::displace_subarray requires *this to be a subarray!"
00538          << std::endl;
00539     return *this;
00540   }
00541   size_t offset = delta_y * _mem_width + delta_x;
00542   _elements += offset;
00543   for (int i = 0; i < _num_of_rows; i++)
00544     _index[i] += offset;
00545   return *this;
00546 }

template<class T>
N_2D_Array< T > & claraty::N_2D_Array< T >::resize_subarray ( int  left,
int  top,
int  width,
int  height 
)

Definition at line 550 of file 2d_array.h.

References claraty::N_2D_Array< T >::_elements, claraty::N_2D_Array< T >::_index, claraty::N_2D_Array< T >::_init_index(), claraty::N_2D_Array< T >::_isSubarray, claraty::N_2D_Array< T >::_mem_base, claraty::N_2D_Array< T >::_mem_width, claraty::N_2D_Array< T >::_num_of_cols, and claraty::N_2D_Array< T >::_num_of_rows.

00552 {
00553   if (!_isSubarray) { // @@ This should throw an exception
00554     std::cerr << "N_2D_Array::resize_subarray requires *this to be a subarray!"
00555          << std::endl;
00556     return *this;
00557   }
00558   _num_of_cols = width;
00559   _elements = _mem_base + top * _mem_width + left;
00560   if (height == _num_of_rows) {
00561     // same number of rows - don't reallocate the _index
00562     _init_index(false);
00563   } else {
00564     _num_of_rows = height;
00565     delete [] _index;
00566     _init_index();
00567   }
00568   return *this;
00569 }

Here is the call graph for this function:

template<class T>
N_2D_Array< T > & claraty::N_2D_Array< T >::associate_subarray ( const N_2D_Array< T > &  parent,
int  left,
int  top,
int  width,
int  height 
)

Definition at line 573 of file 2d_array.h.

References claraty::N_2D_Array< T >::_elements, claraty::N_2D_Array< T >::_index, claraty::N_2D_Array< T >::_init_index(), claraty::N_2D_Array< T >::_isSubarray, claraty::N_2D_Array< T >::_mem_base, claraty::N_2D_Array< T >::_mem_height, claraty::N_2D_Array< T >::_mem_width, claraty::N_2D_Array< T >::_num_of_cols, claraty::N_2D_Array< T >::_num_of_rows, claraty::N_2D_Array< T >::_ref_count, and claraty::Reference_Count::increment().

00576 {
00577   if (_isSubarray || _elements != NULL || _index != NULL) {
00578     std::cerr << "N_2D_Array::associate_subarray: this function can only be used "
00579       "on uninitialized arrays" << std::endl;
00580     return *this;
00581   }
00582   delete _ref_count;
00583   _ref_count = parent._ref_count;
00584   _ref_count->increment();
00585   _isSubarray = true;
00586 
00587   _num_of_rows = height;
00588   _num_of_cols = width;
00589   _mem_width = parent._mem_width;
00590   _mem_height = parent._mem_height;
00591   _mem_base = parent._mem_base;
00592   _elements = parent._elements + top * _mem_width + left;
00593   _init_index();
00594   return *this;
00595 }

Here is the call graph for this function:

template<typename T>
int claraty::N_2D_Array< T >::get_full_num_cols (  )  const [inline]

Definition at line 239 of file 2d_array.h.

00239 { return _mem_width; }

template<typename T>
int claraty::N_2D_Array< T >::get_full_num_rows (  )  const [inline]

Definition at line 241 of file 2d_array.h.

00241 { return _mem_height; }

template<typename T>
void claraty::N_2D_Array< T >::dissociate ( int  new_nrows = -1,
int  new_ncols = -1 
) [inline]

Definition at line 251 of file 2d_array.h.

Referenced by claraty::N_2D_Array< T >::io().

00251                                                       {
00252     int nrows = new_nrows, ncols = new_ncols;
00253     if(nrows < 0) {
00254       nrows = _num_of_rows;
00255     }
00256     if(ncols < 0) {
00257       ncols = _num_of_cols;
00258     }
00259     
00260     if (_isSubarray) {
00261       _isSubarray = false;
00262       _num_of_rows = 0;    // force re-allocation / compaction
00263       _num_of_cols = 0;
00264     }
00265     if (_ref_count->get_value() != 1) {
00266       _ref_count->decrement();
00267       _mem_base = 0;    // to prevent destruction of shared space on resize
00268       _num_of_rows = 0; // force re-allocation
00269       _num_of_cols = 0;
00270       _ref_count = new Reference_Count(1);  // get an independent reference count
00271     }
00272     // Resize if necessary
00273     if((nrows != _num_of_rows) || (ncols != _num_of_cols)) {
00274       resize(nrows, ncols);
00275     }
00276   }

template<class T>
N_2D_Array< T > claraty::N_2D_Array< T >::get_row ( int  row  )  const

Definition at line 600 of file 2d_array.h.

References claraty::N_2D_Array< T >::_index, claraty::N_2D_Array< T >::_num_of_cols, and claraty::N_2D_Array< T >::_num_of_rows.

00601 {
00602   if (row < 0 || row > _num_of_rows) {
00603     std::cerr << "array error: row " << row << " exceeds matrix number of rows = " 
00604          <<  _num_of_cols << std::endl;
00605     return N_2D_Array<T>();
00606   }
00607   else 
00608     return N_2D_Array<T>(1, _num_of_cols, _index[row]);
00609 }

template<class T>
N_2D_Array< T > claraty::N_2D_Array< T >::get_col ( int  col  )  const

Definition at line 613 of file 2d_array.h.

References claraty::N_2D_Array< T >::_num_of_cols, and claraty::N_2D_Array< T >::_num_of_rows.

00614 {
00615   if (col < 0 || col > _num_of_cols) {
00616     std::cerr << "array error: col " << col << " exceeds matrix number of columns = " 
00617          <<  _num_of_cols << std::endl;      
00618     return N_2D_Array<T>();
00619   }
00620   else {
00621     N_2D_Array<T> col_array(_num_of_rows, 1);
00622     for (int row = 0; row < _num_of_rows; row++)
00623       col_array(row, 0) = operator()(row, col);
00624     return col_array;
00625   }
00626 }

template<typename T>
const T* claraty::N_2D_Array< T >::get_row_pointer ( int  row  )  const [inline]

Definition at line 283 of file 2d_array.h.

Referenced by claraty::operator *(), and claraty::Matrix< uint16_t >::row().

00283 { return _index[row]; }

template<typename T>
iterator claraty::N_2D_Array< T >::column_iterator ( int  col  )  [inline]

Definition at line 285 of file 2d_array.h.

Referenced by claraty::Matrix< uint16_t >::column(), and claraty::operator *().

00285                                     {
00286     return iterator(_elements + col, true, 1, _mem_width);
00287   }

template<typename T>
const_iterator claraty::N_2D_Array< T >::column_iterator ( int  col  )  const [inline]

Definition at line 288 of file 2d_array.h.

00288                                                 {
00289     return const_iterator(_elements + col, true, 1, _mem_width);
00290   }

template<typename T>
T& claraty::N_2D_Array< T >::operator() ( int  r,
int  c 
) [inline]

Reimplemented in claraty::Matrix_NxM< T, Nrows, Ncols >.

Definition at line 296 of file 2d_array.h.

Referenced by claraty::N_2D_Array< uint16_t >::rc(), and claraty::N_2D_Array< uint16_t >::xy().

00296 { return _index[r][c]; }

template<typename T>
const T& claraty::N_2D_Array< T >::operator() ( int  r,
int  c 
) const [inline]

Reimplemented in claraty::Matrix_NxM< T, Nrows, Ncols >.

Definition at line 297 of file 2d_array.h.

00297 { return _index[r][c]; }

template<typename T>
T& claraty::N_2D_Array< T >::rc ( int  row,
int  column 
) [inline]

Definition at line 301 of file 2d_array.h.

Referenced by claraty::N_2D_Array< T >::write().

00301 { return operator()(row, column); }

template<typename T>
const T& claraty::N_2D_Array< T >::rc ( int  row,
int  column 
) const [inline]

Definition at line 302 of file 2d_array.h.

00302 { return operator()(row, column); }

template<typename T>
T& claraty::N_2D_Array< T >::xy ( int  x,
int  y 
) [inline]

template<typename T>
const T& claraty::N_2D_Array< T >::xy ( int  x,
int  y 
) const [inline]

Definition at line 305 of file 2d_array.h.

00305 { return operator()(y, x); }

template<typename T>
T& claraty::N_2D_Array< T >::xy ( const N_2D_Point_i p  )  [inline]

Definition at line 307 of file 2d_array.h.

00307 { return xy(p.x(), p.y()); }

template<typename T>
const T& claraty::N_2D_Array< T >::xy ( const N_2D_Point_i p  )  const [inline]

Definition at line 308 of file 2d_array.h.

00308 { return xy(p.x(), p.y()); }

template<class T>
void claraty::N_2D_Array< T >::write ( std::ostream &  os  )  const

Definition at line 697 of file 2d_array.h.

References claraty::N_2D_Array< T >::get_num_of_cols(), claraty::N_2D_Array< T >::get_num_of_rows(), and claraty::N_2D_Array< T >::rc().

00698 {
00699   std::ios::fmtflags oldBase;
00700   int oldPrecision;
00701 
00702   os << "size: (" << get_num_of_rows() << ", " << get_num_of_cols()
00703      << " )" << std::endl;
00704   os.setf(std::ios::showpoint);
00705 
00706   if (sizeof(T)==1) {
00707     oldBase = os.setf(std::ios::hex, std::ios::basefield);
00708   } 
00709   else {
00710     oldPrecision = os.precision();
00711     os.precision(4);
00712   }
00713 
00714   if (get_num_of_cols() != 0)
00715     for (int i = 0; i < get_num_of_rows(); ++i) {
00716       os << "[ ";
00717       for (int j = 0; j < get_num_of_cols(); ++j) {
00718         const T& el = rc(i, j);
00719         os << " " << std::setw(8) << el;
00720       }
00721       os << " ]" << std::endl;
00722     }
00723   if (sizeof(T)==1) 
00724     os.setf(oldBase, std::ios::basefield);
00725   else
00726     os.precision(oldPrecision);
00727 }

Here is the call graph for this function:

template<class T>
claraty::N_2D_Array< T >::operator void * (  )  const

Definition at line 630 of file 2d_array.h.

References claraty::N_2D_Array< T >::begin(), and claraty::N_2D_Array< T >::end().

00631 {
00632   // Bool operator but using void * instead to avoid direct conversion to int
00633   // so when you type 3*array, you do not get 3, rather you get a compile error
00634 
00635   for (const_iterator it = begin(); it != end(); ++it)
00636     if (*it == 0)
00637       return (void *)false;
00638   return (void *)true;
00639 }

Here is the call graph for this function:

template<class T>
N_2D_Array< T > claraty::N_2D_Array< T >::operator== ( const N_2D_Array< T > &  rhs  )  const

Definition at line 678 of file 2d_array.h.

References claraty::N_2D_Array< T >::_check_size(), claraty::N_2D_Array< T >::_num_of_cols, claraty::N_2D_Array< T >::_num_of_rows, claraty::N_2D_Array< T >::begin(), claraty::N_2D_Array< T >::EQUALS, ERROR, claraty::N_2D_Array< T >::get_size(), and claraty::N_2D_Array< T >::N_2D_Array().

00679 { 
00680   if (this == &rhs) return N_2D_Array(_num_of_rows, _num_of_cols, (T)true); 
00681 
00682   if (_check_size(EQUALS, rhs) == ERROR) {
00683     // MUST THROW AN EXCEPTION HERE, BUT FOR NOW
00684     return N_2D_Array(1, 1, (T)false);
00685   }
00686 
00687   N_2D_Array result(_num_of_rows, _num_of_cols);
00688   const_iterator it_lhs = begin(), it_rhs = rhs.begin();
00689   iterator it_res = result.begin();
00690   for (int i = 0; i < get_size(); ++i, ++it_lhs, ++it_rhs, ++it_res) 
00691     *it_res = (*it_lhs == *it_rhs);
00692   return result;
00693 }

Here is the call graph for this function:

template<class T>
N_2D_Array< T > claraty::N_2D_Array< T >::transpose (  )  const

Reimplemented in claraty::Matrix< T >, claraty::Matrix_NxM< T, Nrows, Ncols >, claraty::Matrix< double >, claraty::Matrix< float >, claraty::Matrix< Pixel_Type >, and claraty::Matrix< uint16_t >.

Definition at line 665 of file 2d_array.h.

References claraty::N_2D_Array< T >::_num_of_cols, claraty::N_2D_Array< T >::_num_of_rows, and claraty::N_2D_Array< T >::begin().

00666 { 
00667   N_2D_Array tmp(_num_of_cols, _num_of_rows);
00668   iterator it_tmp = tmp.begin();
00669   for (int i = 0; i < _num_of_cols; ++i) 
00670     for (int j = 0; j < _num_of_rows; ++j, ++it_tmp)
00671       *it_tmp = operator()(j, i);
00672   return tmp;
00673 }

Here is the call graph for this function:

template<typename T>
bool claraty::N_2D_Array< T >::io ( FDM_Map  map  ) 

Reimplemented in claraty::Camera_Image< Pixel_Type >, claraty::Camera_Image< float >, and claraty::Camera_Image< uint16_t >.

Definition at line 806 of file 2d_array.h.

References claraty::N_2D_Array< T >::_index, claraty::N_2D_Array< T >::dissociate(), claraty::FDM_Array::element(), claraty::FDM_Map::field(), claraty::FDM_Map::field_node(), claraty::FDM_Map::is_read(), claraty::N_2D_Array< T >::ncols(), and claraty::N_2D_Array< T >::nrows().

Referenced by claraty::io_object().

00807 {
00808   int nr = nrows(), nc = ncols();
00809 
00810   bool ok = true;
00811 
00812   ok &= map.field("nrows", nr);
00813   ok &= map.field("ncols", nc);
00814 
00815   // If we're reading, dissociate from any sharing and set to the new
00816   // size.  If the memory isn't shared and the size hasn't changed,
00817   // this does nothing.
00818   if (map.is_read()) {
00819     dissociate(nr, nc);
00820   }
00821 
00822   FDM_Array a = map.field_node("elements");
00823 
00824   for (int r = 0; r < nr; r++)
00825     for (int c = 0; c < nc; c++)
00826       ok &= a.element(_index[r][c]);
00827   
00828   return ok;
00829 }

Here is the call graph for this function:

template<typename T>
T& claraty::N_2D_Array< T >::element ( int  i  )  [inline, protected]

Definition at line 331 of file 2d_array.h.

Referenced by claraty::N_1D_Array< T >::operator()(), and claraty::N_1D_Array< T >::operator[]().

00331 { return _elements[i]; }

template<typename T>
const T& claraty::N_2D_Array< T >::element ( int  i  )  const [inline, protected]

Definition at line 332 of file 2d_array.h.

00332 { return _elements[i]; }

template<typename T>
T* claraty::N_2D_Array< T >::get_data (  )  [inline, protected]

template<typename T>
const T* claraty::N_2D_Array< T >::get_data (  )  const [inline, protected]

Definition at line 337 of file 2d_array.h.

00337 { assert(!is_subarray()); return _mem_base; }

template<class T>
template<class In>
void claraty::N_2D_Array< T >::_copy ( In  start  )  [protected]

Definition at line 448 of file 2d_array.h.

References claraty::N_2D_Array< T >::_elements, claraty::N_2D_Array< T >::_num_of_cols, claraty::N_2D_Array< T >::_num_of_rows, claraty::N_2D_Array< T >::begin(), claraty::N_2D_Array< T >::end(), and claraty::N_2D_Array< T >::is_subarray().

Referenced by claraty::Matrix_NxM< T, Nrows, Ncols >::Matrix_NxM(), claraty::N_2D_Array< T >::N_2D_Array(), claraty::N_2D_Array< uint16_t >::N_2D_Array(), claraty::Matrix_NxM< T, Nrows, Ncols >::operator=(), claraty::Matrix< uint16_t >::operator=(), and claraty::N_2D_Array< T >::operator=().

00449 {
00450   if (is_subarray()) {
00451     iterator it = begin(), last = end();
00452     for (; it != last; ++it, ++start)
00453       *it = (int)*start; // compiler warning *it is an int
00454   } else {
00455     T *it = _elements, *last = _elements + _num_of_rows * _num_of_cols;
00456     for (; it != last; ++it, ++start)
00457       *it = (int)*start; // compiler waring *it is an int
00458   }    
00459 }

Here is the call graph for this function:

template<class T>
void claraty::N_2D_Array< T >::_copy ( filler  )  [protected]

Definition at line 463 of file 2d_array.h.

References claraty::N_2D_Array< T >::begin(), and claraty::N_2D_Array< T >::end().

00464 {
00465   iterator it = begin(), last = end();
00466   for (; it != last; ++it)
00467     *it = filler;
00468 }

Here is the call graph for this function:

template<class T>
template<class rhsType>
int claraty::N_2D_Array< T >::_check_size ( SIZE_TYPE  type,
const N_2D_Array< rhsType > &  rhs 
) const [protected]

Definition at line 770 of file 2d_array.h.

References claraty::N_2D_Array< T >::_num_of_cols, claraty::N_2D_Array< T >::_num_of_rows, claraty::N_2D_Array< T >::EQUALS, ERROR, claraty::N_2D_Array< T >::get_num_of_cols(), claraty::N_2D_Array< T >::get_num_of_rows(), claraty::N_2D_Array< T >::NCOLS_EQUALS_NROWS, OK, and claraty::N_2D_Array< T >::SQUARE.

Referenced by claraty::Matrix_NxM< T, Nrows, Ncols >::Matrix_NxM(), claraty::Matrix< uint16_t >::operator+=(), claraty::Matrix< uint16_t >::operator-=(), and claraty::N_2D_Array< T >::operator==().

00772 {
00773   int status = ERROR;
00774 
00775   switch (operation) {
00776   case EQUALS:
00777     status = ((_num_of_rows == rhs.get_num_of_rows()) &&
00778               (_num_of_cols == rhs.get_num_of_cols())) ? OK : ERROR;
00779     break;
00780   case NCOLS_EQUALS_NROWS:
00781     status = (_num_of_cols == rhs.get_num_of_rows()) ? OK : ERROR; 
00782     break;
00783   case SQUARE:
00784     status = (_num_of_rows == _num_of_cols)  ? OK : ERROR;
00785     break;
00786   } // switch
00787 
00788   if (status==ERROR) 
00789     std::cerr << "Array 2D error: array dimensions do not match lhs(" << _num_of_rows 
00790          << "x" << _num_of_cols << "), rhs (" << rhs.get_num_of_rows() << "x" 
00791          << rhs.get_num_of_cols() << ")" << std::endl;
00792 
00793   return status;
00794 }

Here is the call graph for this function:

template<class T>
void claraty::N_2D_Array< T >::_init_special ( int  nr,
int  nc,
T *  data,
int  memwidth 
) [protected]

Definition at line 387 of file 2d_array.h.

References claraty::N_2D_Array< T >::_elements, claraty::N_2D_Array< T >::_init_index(), claraty::N_2D_Array< T >::_mem_base, claraty::N_2D_Array< T >::_mem_width, claraty::N_2D_Array< T >::_num_of_cols, and claraty::N_2D_Array< T >::_num_of_rows.

Referenced by claraty::Matrix_NxM< T, Nrows, Ncols >::_init().

00388 {
00389   _num_of_rows = n_rows;
00390   _num_of_cols = n_cols;
00391   _mem_width = memwidth;
00392 
00393   _elements = data;
00394   _mem_base = data;
00395 
00396   _init_index();
00397 }

Here is the call graph for this function:

template<typename T>
void claraty::N_2D_Array< T >::_drop_memory (  )  [inline, protected]

Definition at line 355 of file 2d_array.h.

Referenced by claraty::Matrix_NxM< T, Nrows, Ncols >::~Matrix_NxM().

00355                       {
00356     _elements = NULL;
00357     _mem_base = NULL;
00358   }

template<class T>
void claraty::N_2D_Array< T >::_init ( int  n_rows,
int  n_cols 
) [protected]

Reimplemented in claraty::Matrix< T >, claraty::Matrix< double >, claraty::Matrix< float >, claraty::Matrix< Pixel_Type >, and claraty::Matrix< uint16_t >.

Definition at line 400 of file 2d_array.h.

References claraty::N_2D_Array< T >::_elements, claraty::N_2D_Array< T >::_index, claraty::N_2D_Array< T >::_init_index(), claraty::N_2D_Array< T >::_isSubarray, claraty::N_2D_Array< T >::_mem_base, claraty::N_2D_Array< T >::_mem_height, claraty::N_2D_Array< T >::_mem_width, claraty::N_2D_Array< T >::_num_of_cols, and claraty::N_2D_Array< T >::_num_of_rows.

Referenced by claraty::N_2D_Array< T >::N_2D_Array(), claraty::N_2D_Array< uint16_t >::N_2D_Array(), and claraty::N_2D_Array< uint16_t >::resize().

00401 {
00402   // Allocate contiguous space for all the elements in the array.
00403 
00404   // Init only gets called on non-subarray
00405   _isSubarray = false;
00406 
00407   _num_of_rows = n_rows;
00408   _num_of_cols = n_cols;
00409   _mem_width = _num_of_cols;
00410   _mem_height = _num_of_rows;
00411 
00412   if (n_rows==0 || n_cols==0) {
00413     _elements = NULL;
00414     _mem_base = NULL;
00415     _index = NULL;
00416     return; 
00417   }
00418 
00419   _mem_base = new T[n_rows*n_cols];
00420   _elements = _mem_base;
00421 
00422   // Copy pointer to the beginning of every row into index pointer array
00423   //
00424   _init_index();
00425 }

Here is the call graph for this function:

template<class T>
void claraty::N_2D_Array< T >::_init_index ( bool  allocate = true  )  [protected]

Definition at line 429 of file 2d_array.h.

References claraty::N_2D_Array< T >::_elements, claraty::N_2D_Array< T >::_index, claraty::N_2D_Array< T >::_mem_width, and claraty::N_2D_Array< T >::_num_of_rows.

Referenced by claraty::N_2D_Array< T >::_init(), claraty::N_2D_Array< T >::_init_special(), claraty::N_2D_Array< T >::associate_subarray(), claraty::N_2D_Array< T >::N_2D_Array(), claraty::N_2D_Array< uint16_t >::resize(), and claraty::N_2D_Array< T >::resize_subarray().

00430 {
00431   // Allocate memory for the row pointers. These are needed to address the 
00432   // individual elements of the matrix using the index **
00433   
00434   typedef T* p_T;
00435 
00436   if (allocate)
00437     _index = new p_T[_num_of_rows];
00438 
00439   // Initialize index vector that points to the beginning of every row
00440   int i;
00441   T *p_row;
00442   for (i = 0, p_row = _elements; i < _num_of_rows; i++, p_row += _mem_width)
00443     _index[i]= p_row;
00444 }

template<typename T>
bool claraty::N_2D_Array< T >::_is_noncontiguous (  )  const [inline, protected]

Definition at line 367 of file 2d_array.h.

Referenced by claraty::N_2D_Array< uint16_t >::begin(), and claraty::N_2D_Array< uint16_t >::end().

00367                                  {
00368     return _num_of_cols != _mem_width;
00369   }


Member Data Documentation


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