EMAN2
Classes | Public Member Functions | Protected Member Functions | Protected Attributes
EMAN::UnevenMatrix Class Reference

a general data structure for a matrix with variable x dim size for different y More...

#include <polardata.h>

Inheritance diagram for EMAN::UnevenMatrix:
Inheritance graph
[legend]
Collaboration diagram for EMAN::UnevenMatrix:
Collaboration graph
[legend]

List of all members.

Classes

struct  Xdim
 struct to define x dimension size for each y, x0 is inclusive, x1 is one after the maximum, [x0, x1), so the corresponding x dim size is (x1-x0) More...

Public Member Functions

 UnevenMatrix ()
virtual ~UnevenMatrix ()
int get_xsize (int y)
 get the x dim size for a given y
int get_xmin (int y)
 get the minimal x dim value for a given y
int get_xmax (int y)
 get the maximal x dim value for a given y, note: x1 is one out of the max
int get_size ()
 get the total size of the data block

Protected Member Functions

void alloc_data ()
 allocation memory for data array

Protected Attributes

float * data
 store all data in one dimension float array for cache efficiency, we calculate the offset for x, y dimension
map< int, Xdimdesc_data
 describe for each y, the x dimension's size and range
int tot_size
 the total size of the data

Detailed Description

a general data structure for a matrix with variable x dim size for different y

Definition at line 53 of file polardata.h.


Constructor & Destructor Documentation

EMAN::UnevenMatrix::UnevenMatrix ( ) [inline]

Definition at line 56 of file polardata.h.

                               : data(0) {
                        printf("Welcome to UnevenMatrix\n");
                }
virtual EMAN::UnevenMatrix::~UnevenMatrix ( ) [inline, virtual]

Definition at line 59 of file polardata.h.

References data.

                                        {
                        if(data) {
                                delete data;
                                data = 0;
                        }
                        printf("Destructor of UnevenMatrix...\n");
                }

Member Function Documentation

void UnevenMatrix::alloc_data ( ) [protected]

allocation memory for data array

Returns:
int
Exceptions:
InvalidValueExceptionif the desc_data map size is zero

Definition at line 59 of file polardata.cpp.

References data, desc_data, get_xsize(), InvalidValueException, LOGERR, tot_size, and y.

{
        if( desc_data.size() == 0 ) {
                LOGERR("No data space need to be allocated for UnevenMatrix, check you desc_data...");
                throw InvalidValueException((float)desc_data.size(), "desc_data size == 0");
        }
        
        int size = 0;   //total number of float need to be stored in data block
        map< int, Xdim >::const_iterator iter;
        int y = 0;      
        for( iter = desc_data.begin(); iter != desc_data.end(); ++iter ) {
                y = (*iter).first;
                size += get_xsize(y);
        }
        
        this->tot_size = size;
        try {
                this->data = new float[size];
        }
        catch( bad_alloc exception ) {
                LOGERR("memory allocation for UnevenMatrix failed");
        }
        catch(...) {
                LOGERR("Unknown error in memory allocation for UnevenMatrix");
        }
}
int EMAN::UnevenMatrix::get_size ( ) [inline]

get the total size of the data block

Returns:
int the number of float stored in data

Definition at line 96 of file polardata.h.

References tot_size.

                                      {
                        return tot_size;
                }
int EMAN::UnevenMatrix::get_xmax ( int  y) [inline]

get the maximal x dim value for a given y, note: x1 is one out of the max

Parameters:
yint the y value for which we need the corresponding maximal x dim value
Returns:
int the maximal x dim value for a given y

Definition at line 90 of file polardata.h.

References desc_data, and y.

                                           {
                        return desc_data[y].x1 - 1;
                }
int EMAN::UnevenMatrix::get_xmin ( int  y) [inline]

get the minimal x dim value for a given y

Parameters:
yint the y value for which we need the corresponding minimal x dim value
Returns:
int the minimal x dim value for a given y

Definition at line 83 of file polardata.h.

References desc_data, and y.

                                           {
                        return desc_data[y].x0;
                }
int EMAN::UnevenMatrix::get_xsize ( int  y) [inline]

get the x dim size for a given y

Parameters:
yint the y value for which we need the x dim size
Returns:
in tthe x dim size

Definition at line 70 of file polardata.h.

References desc_data, InvalidValueException, and y.

Referenced by alloc_data().

                                            {
                        int xsize = desc_data[y].x1 - desc_data[y].x0;
                        if( xsize <= 0 ) {
                                throw InvalidValueException(xsize, "xsize <= 0");
                        }
                        else {
                                return xsize;
                        }
                }

Member Data Documentation

float* EMAN::UnevenMatrix::data [protected]

store all data in one dimension float array for cache efficiency, we calculate the offset for x, y dimension

Definition at line 127 of file polardata.h.

Referenced by alloc_data(), and ~UnevenMatrix().

map< int, Xdim > EMAN::UnevenMatrix::desc_data [protected]

describe for each y, the x dimension's size and range

Definition at line 130 of file polardata.h.

Referenced by alloc_data(), get_xmax(), get_xmin(), and get_xsize().

the total size of the data

Definition at line 133 of file polardata.h.

Referenced by alloc_data(), and get_size().


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