EMAN2
Public Member Functions | Private Member Functions | Private Attributes
EMAN::EMArray< T > Class Template Reference

EMArray -- 1-, 2-, or 3-D array of types T. More...

#include <emarray.h>

List of all members.

Public Member Functions

 EMArray (size_t xsize, size_t ysize=1, size_t zsize=1)
 Constructor.
 ~EMArray ()
 Destructor.
void set_array_offsets (const size_t xoff_=0, const size_t yoff_=0, const size_t zoff_=0)
 Set the array offsets.
void set_array_offsets (const vector< int > offsets)
 Set the array offsets using an offset vector.
vector< int > get_array_offsets ()
 Get an integer array containing the array offsets.
T & operator() (const size_t ix, const size_t iy=0, const size_t iz=0)
 Index into the array using Fortran-style indexing:
int get_xsize () const
int get_ysize () const
int get_zsize () const

Private Member Functions

 EMArray (const EMArray &)
EMArrayoperator= (const EMArray &)

Private Attributes

const size_t nx
const size_t ny
const size_t nz
size_t size
size_t xoff
size_t yoff
size_t zoff
T * array

Detailed Description

template<class T>
class EMAN::EMArray< T >

EMArray -- 1-, 2-, or 3-D array of types T.

Sometimes you need an array of something.

Data is ordered with the first element increasing the fastest.

Definition at line 53 of file emarray.h.


Constructor & Destructor Documentation

template<class T >
EMAN::EMArray< T >::EMArray ( size_t  xsize,
size_t  ysize = 1,
size_t  zsize = 1 
) [inline, explicit]

Constructor.

Definition at line 56 of file emarray.h.

References EMAN::EMArray< T >::array, EMAN::EMArray< T >::nx, EMAN::EMArray< T >::ny, EMAN::EMArray< T >::nz, and EMAN::EMArray< T >::size.

                : nx(xsize),ny(ysize),nz(zsize),
                  xoff(0),yoff(0),zoff(0) {
                size = (size_t)nx*ny*nz;
                array = new T[size];
            }
template<class T >
EMAN::EMArray< T >::~EMArray ( ) [inline]

Destructor.

Definition at line 63 of file emarray.h.

References EMAN::EMArray< T >::array.

{ delete [] array; }
template<class T >
EMAN::EMArray< T >::EMArray ( const EMArray< T > &  ) [private]

Member Function Documentation

template<class T >
vector<int> EMAN::EMArray< T >::get_array_offsets ( ) [inline]

Get an integer array containing the array offsets.

Definition at line 79 of file emarray.h.

References EMAN::EMArray< T >::xoff, EMAN::EMArray< T >::yoff, and EMAN::EMArray< T >::zoff.

                                            {
                vector<int> offsets;
                offsets.push_back(xoff);
                offsets.push_back(yoff);
                offsets.push_back(zoff);
                return offsets;
            }
template<class T >
int EMAN::EMArray< T >::get_xsize ( ) const [inline]

Definition at line 101 of file emarray.h.

References EMAN::EMArray< T >::nx.

{ return nx; }
template<class T >
int EMAN::EMArray< T >::get_ysize ( ) const [inline]

Definition at line 102 of file emarray.h.

References EMAN::EMArray< T >::ny.

{ return ny; }
template<class T >
int EMAN::EMArray< T >::get_zsize ( ) const [inline]

Definition at line 103 of file emarray.h.

References EMAN::EMArray< T >::nz.

{ return nz; }
template<class T >
T& EMAN::EMArray< T >::operator() ( const size_t  ix,
const size_t  iy = 0,
const size_t  iz = 0 
) [inline]

Index into the array using Fortran-style indexing:

EMArray<double> arr(2,2) // 2-D 2x2 array of doubles arr(0,0) = 1.f;

Definition at line 91 of file emarray.h.

References EMAN::EMArray< T >::array, EMAN::EMArray< T >::nx, EMAN::EMArray< T >::ny, OutofRangeException, EMAN::EMArray< T >::size, EMAN::EMArray< T >::xoff, EMAN::EMArray< T >::yoff, and EMAN::EMArray< T >::zoff.

                                             {
                long pos = (ix-xoff) + ((iy-yoff)+(iz-zoff)*ny)*nx;
#ifdef BOUNDS_CHECKING
                if (pos < 0 || pos >= long(size))
                    throw OutofRangeException(0, size-1, pos, "emarray");
#endif // BOUNDS_CHECKING
                return *(array + pos);
            }
template<class T >
EMArray& EMAN::EMArray< T >::operator= ( const EMArray< T > &  ) [private]
template<class T >
void EMAN::EMArray< T >::set_array_offsets ( const size_t  xoff_ = 0,
const size_t  yoff_ = 0,
const size_t  zoff_ = 0 
) [inline]

Set the array offsets.

By default an EMArray ranges from 0..nx-1,0..ny-1,0..nz-1. Setting the offsets to (1,1,1) changes the ranges to 1..nx,1..ny,1..nz, for example.

Definition at line 68 of file emarray.h.

References EMAN::EMArray< T >::xoff, EMAN::EMArray< T >::yoff, and EMAN::EMArray< T >::zoff.

Referenced by EMAN::EMArray< T >::set_array_offsets().

                                                         {
                xoff = xoff_; yoff = yoff_; zoff = zoff_;
            }
template<class T >
void EMAN::EMArray< T >::set_array_offsets ( const vector< int >  offsets) [inline]

Set the array offsets using an offset vector.

This method exists mainly for restoring the original offsets.

Definition at line 75 of file emarray.h.

References EMAN::EMArray< T >::set_array_offsets().

                                                              {
                set_array_offsets(offsets[0],offsets[1],offsets[2]);
            }

Member Data Documentation

template<class T >
T* EMAN::EMArray< T >::array [private]
template<class T >
const size_t EMAN::EMArray< T >::nx [private]
template<class T >
const size_t EMAN::EMArray< T >::ny [private]
template<class T >
const size_t EMAN::EMArray< T >::nz [private]

Definition at line 106 of file emarray.h.

Referenced by EMAN::EMArray< T >::EMArray(), and EMAN::EMArray< T >::get_zsize().

template<class T >
size_t EMAN::EMArray< T >::size [private]

Definition at line 107 of file emarray.h.

Referenced by EMAN::EMArray< T >::EMArray(), and EMAN::EMArray< T >::operator()().

template<class T >
size_t EMAN::EMArray< T >::xoff [private]
template<class T >
size_t EMAN::EMArray< T >::yoff [private]
template<class T >
size_t EMAN::EMArray< T >::zoff [private]

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