EMAN2
Static Public Member Functions | Static Public Attributes | Static Private Member Functions | Static Private Attributes
EMAN::TestUtil Class Reference

#include <testutil.h>

Collaboration diagram for EMAN::TestUtil:
Collaboration graph
[legend]

List of all members.

Static Public Member Functions

static int get_debug_int (int i)
static float get_debug_float (int i)
static string get_debug_string (int i)
static Transform get_debug_transform (int i)
static string get_debug_image (const string &imagename)
static string get_golden_image (const string &imagename)
static void to_emobject (const Dict &d)
static EMObject emobject_to_py (bool b)
static EMObject emobject_to_py (unsigned int n)
static EMObject emobject_to_py (int n)
static EMObject emobject_to_py (float f)
static EMObject emobject_to_py (double f)
static EMObject emobject_to_py (const string &str)
static EMObject emobject_to_py (EMData *emdata)
static EMObject emobject_to_py (XYData *xydata)
static EMObject emobject_farray_to_py ()
static EMObject emobject_strarray_to_py ()
static EMObject emobject_transformarray_to_py ()
static EMObject emobject_to_py (Transform *t)
static EMObject emobject_to_py (Ctf *ctf_)
static IntPoint test_IntPoint (const IntPoint &p)
static FloatPoint test_FloatPoint (const FloatPoint &p)
static IntSize test_IntSize (const IntSize &p)
static FloatSize test_FloatSize (const FloatSize &p)
static Vec3i test_Vec3i (const Vec3i &p)
static Vec3f test_Vec3f (const Vec3f &p)
static vector< int > test_vector_int (const vector< int > &v)
static vector< float > test_vector_float (const vector< float > &v)
static vector< long > test_vector_long (const vector< long > &v)
static vector< string > test_vector_string (const vector< string > &v)
static vector< EMData * > test_vector_emdata (const vector< EMData * > &v)
static vector< Pixeltest_vector_pixel (const vector< Pixel > &v)
static map< string, int > test_map_int (const map< string, int > &d)
static map< string, long > test_map_long (const map< string, long > &d)
static map< string, float > test_map_float (const map< string, float > &d)
static map< string, string > test_map_string (const map< string, string > &d)
static map< string, EMObjecttest_map_emobject (const map< string, EMObject > &d)
static map< string, vector
< string > > 
test_map_vecstring (const map< string, vector< string > > &d)
static Dict test_dict (const Dict &d)
static void dump_image_from_file (const string &filename)
static void dump_emdata (EMData *image, const string &filename)
static int check_image (const string &imagefile, EMData *image=0)
static void set_progname (const string &cur_progname)
static void make_image_file (const string &filename, EMUtil::ImageType image_type, EMUtil::EMDataType datatype=EMUtil::EM_FLOAT, int nx=16, int ny=16, int nz=1)
static int verify_image_file (const string &filename, EMUtil::ImageType image_type, EMUtil::EMDataType datatype=EMUtil::EM_FLOAT, int nx=16, int ny=16, int nz=1)
static void make_image_file2 (const string &filename, EMUtil::ImageType image_type, EMUtil::EMDataType datatype=EMUtil::EM_FLOAT, int nx=16, int ny=16, int nz=1)
static int verify_image_file2 (const string &filename, EMUtil::ImageType image_type, EMUtil::EMDataType datatype=EMUtil::EM_FLOAT, int nx=16, int ny=16, int nz=1)

Static Public Attributes

static const char * EMDATA_HEADER_EXT = ".head"
static const char * EMDATA_DATA_EXT = ".data"

Static Private Member Functions

static void make_image_file_by_mode (const string &filename, EMUtil::ImageType image_type, int mode, EMUtil::EMDataType datatype=EMUtil::EM_FLOAT, int nx=16, int ny=16, int nz=1)
static int verify_image_file_by_mode (const string &filename, EMUtil::ImageType image_type, int mode, EMUtil::EMDataType datatype=EMUtil::EM_FLOAT, int nx=16, int ny=16, int nz=1)
static float get_pixel_value_by_dist1 (int nx, int ny, int nz, int x, int y, int z)
static float get_pixel_value_by_dist2 (int nx, int ny, int nz, int x, int y, int z)

Static Private Attributes

static float tf [10] = {1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5}
static int ti [10] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100}
static string progname = ""

Detailed Description

Definition at line 52 of file testutil.h.


Member Function Documentation

int TestUtil::check_image ( const string &  imagefile,
EMData image = 0 
) [static]

Definition at line 413 of file testutil.cpp.

References dump_emdata(), dump_image_from_file(), EMDATA_DATA_EXT, EMDATA_HEADER_EXT, EMAN::Util::is_file_exist(), LOGERR, progname, and EMAN::Util::sbasename().

{
#if DEBUG
        string headerfile1 = Util::sbasename(imagefile) + EMDATA_HEADER_EXT;
        string datafile1 = Util::sbasename(imagefile) + EMDATA_DATA_EXT;

        char imgpath[MAXPATHLEN];
        char * path_env = getenv("DEBUG_IMAGE_PATH");
        if (path_env) {
                sprintf(imgpath, "%s/testdata/%s/", path_env, progname.c_str());
        }
        else {
                sprintf(imgpath, "%s/images/testdata/%s/", getenv("HOME"), progname.c_str());
        }

        string headerfile2 = string(imgpath) + headerfile1;
        string datafile2 = string(imgpath) + datafile1;


        if (image) {
                dump_emdata(image, imagefile);
        }
        else {
                dump_image_from_file(imagefile);
        }

    if (!Util::is_file_exist(headerfile2) ||
        !Util::is_file_exist(datafile2)) {
        return 0;
    }

        string diffcmd1 = "diff " + headerfile1 + " " + headerfile2;

        int err = system(diffcmd1.c_str());
        if (!err) {
                string diffcmd2 = "diff " + datafile1 + " " + datafile2;
                err = system(diffcmd2.c_str());
        }
        if (err) {
                LOGERR("check_image on %s FAILED\n", imagefile.c_str());
        }

        return err;
#endif
    return 0;
}
void TestUtil::dump_emdata ( EMData image,
const string &  filename 
) [static]

Definition at line 472 of file testutil.cpp.

References EMDATA_DATA_EXT, EMDATA_HEADER_EXT, FileAccessException, EMAN::EMData::get_attr_dict(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::keys(), nx, ny, rdata, EMAN::Util::sbasename(), EMAN::Util::sstrncmp(), and EMAN::Gatan::to_str().

Referenced by check_image(), and dump_image_from_file().

{
        string filebase = Util::sbasename(filename);
        string headerfile = filebase + EMDATA_HEADER_EXT;
        string datafile = filebase + EMDATA_DATA_EXT;

        FILE *hfile = fopen(headerfile.c_str(), "wb");
        if (!hfile) {
                throw FileAccessException(headerfile);
        }
#if 0
        vector<string> excl_keys;
        excl_keys.push_back("MRC.label");
        excl_keys.push_back("IMAGIC.minute");
        excl_keys.push_back("IMAGIC.sec");

        Dict attr_dict = image->get_attr_dict();
        vector < string > keys = attr_dict.keys();



        for (size_t i = 0; i < keys.size(); i++) {

                bool is_exclude = false;
                for (size_t j = 0; j < excl_keys.size(); j++) {
                        if (Util::sstrncmp(keys[i].c_str(), excl_keys[j].c_str())) {
                                is_exclude = true;
                                break;
                        }
                }
                if (!is_exclude) {
                        fprintf(hfile, "%s = %s\n", keys[i].c_str(),
                                        attr_dict[keys[i]].to_str().c_str());
                }
        }
#endif

        fprintf(hfile, "nx = %d\n", image->get_xsize());
        fprintf(hfile, "ny = %d\n", image->get_ysize());
        fprintf(hfile, "nz = %d\n", image->get_zsize());

        fclose(hfile);
        hfile = 0;

        FILE *dfile = fopen(datafile.c_str(), "wb");
        if (!dfile) {
                throw FileAccessException(datafile);
        }

        int nx = image->get_xsize();
        int ny = image->get_ysize();
        int nz = image->get_zsize();

        size_t row_size = nx * sizeof(float);
        size_t nxy = nx * ny;
        float * rdata = image->get_data();

        for (int i = 0; i < nz; i++) {
                for (int j = 0; j < ny; j++) {
                        fwrite(&rdata[i * nxy + j * nx], row_size, 1, dfile);
                }
        }
        fclose(dfile);
        dfile = 0;
}
void TestUtil::dump_image_from_file ( const string &  filename) [static]

Definition at line 460 of file testutil.cpp.

References dump_emdata(), and EMAN::EMData::read_image().

Referenced by check_image().

{
        EMData * e = new EMData();
        e->read_image(filename);
        dump_emdata(e, filename);
        if( e )
        {
                delete e;
                e = 0;
        }
}
EMObject TestUtil::emobject_farray_to_py ( ) [static]

Definition at line 710 of file testutil.cpp.

References tf, and v.

{
        vector<float> v(3);
        for (int i = 0; i < 3; i++) {
                v[i] = tf[i];
        }
        return EMObject(v);
}
EMObject TestUtil::emobject_strarray_to_py ( ) [static]

Definition at line 720 of file testutil.cpp.

References get_debug_string(), and v.

{
        vector<string> v(3);
        for (int i = 0; i < 3; i++) {
                v[i] = get_debug_string(i);
        }
        return EMObject(v);
}
EMObject TestUtil::emobject_to_py ( bool  b) [static]

Definition at line 667 of file testutil.cpp.

{
        return EMObject(b);
}
EMObject TestUtil::emobject_to_py ( unsigned int  n) [static]

Definition at line 672 of file testutil.cpp.

{
        return EMObject(un);
}
EMObject TestUtil::emobject_to_py ( Transform t) [static]

Definition at line 740 of file testutil.cpp.

{
        return EMObject(t);
}
EMObject TestUtil::emobject_to_py ( int  n) [static]

Definition at line 677 of file testutil.cpp.

{
        return EMObject(n);
}
EMObject TestUtil::emobject_to_py ( Ctf ctf_) [static]

Definition at line 745 of file testutil.cpp.

{
        return EMObject(ctf_);
}
EMObject TestUtil::emobject_to_py ( float  f) [static]

Definition at line 682 of file testutil.cpp.

{
        return EMObject(f);
}
EMObject TestUtil::emobject_to_py ( double  f) [static]

Definition at line 687 of file testutil.cpp.

{
        return EMObject(f);
}
EMObject TestUtil::emobject_to_py ( const string &  str) [static]

Definition at line 692 of file testutil.cpp.

{
        return EMObject(str);
}
EMObject TestUtil::emobject_to_py ( EMData emdata) [static]

Definition at line 698 of file testutil.cpp.

{
        return EMObject(emdata);
}
EMObject TestUtil::emobject_to_py ( XYData xydata) [static]

Definition at line 704 of file testutil.cpp.

{
        return EMObject(xydata);
}
EMObject TestUtil::emobject_transformarray_to_py ( ) [static]

Definition at line 729 of file testutil.cpp.

References EMAN::Transform::set_trans(), t, and v.

{
        vector<Transform> v(3);
        for (int i=0; i<3; i++) {
                Transform t;
                t.set_trans(i, i+1, i+2);
                v[i] = t;
        }
        return EMObject(v);
}
float TestUtil::get_debug_float ( int  i) [static]

Definition at line 69 of file testutil.cpp.

References tf.

{
        return tf[i];
}
string TestUtil::get_debug_image ( const string &  imagename) [static]

Definition at line 92 of file testutil.cpp.

{
        char imgpath[MAXPATHLEN];
        char * path_env = getenv("DEBUG_IMAGE_PATH");
        if (path_env) {
                sprintf(imgpath, "%s/%s", path_env, imagename.c_str());
        }
        else {
                sprintf(imgpath, "%s/images/%s", getenv("HOME"), imagename.c_str());
        }
        return string(imgpath);
}
int TestUtil::get_debug_int ( int  i) [static]

Definition at line 64 of file testutil.cpp.

References ti.

{
        return ti[i];
}
string TestUtil::get_debug_string ( int  i) [static]

Definition at line 74 of file testutil.cpp.

Referenced by emobject_strarray_to_py(), test_dict(), and to_emobject().

{
        char a[32];
        sprintf(a, "%d%d", i+1, i+1);
        return string(a);
}
Transform TestUtil::get_debug_transform ( int  i) [static]

Definition at line 81 of file testutil.cpp.

References EMAN::Transform::set_trans(), t, and v.

Referenced by to_emobject().

{
        vector<Transform> v(3);
        for (int j=0; j<3; j++) {
                Transform t;
                t.set_trans(j, j+1, j+2);
                v[j] = t;
        }
        return v[i];
}
string TestUtil::get_golden_image ( const string &  imagename) [static]

Definition at line 105 of file testutil.cpp.

{
        char imgpath[MAXPATHLEN];
        char * path_env = getenv("DEBUG_IMAGE_PATH");
        if (path_env) {
                sprintf(imgpath, "%s/testdata/%s", path_env, imagename.c_str());
        }
        else {
                sprintf(imgpath, "%s/images/testdata/%s", getenv("HOME"), imagename.c_str());
        }
        return string(imgpath);
}
static float EMAN::TestUtil::get_pixel_value_by_dist1 ( int  nx,
int  ny,
int  nz,
int  x,
int  y,
int  z 
) [inline, static, private]

Definition at line 163 of file testutil.h.

References abs, x, and y.

Referenced by make_image_file_by_mode(), and verify_image_file_by_mode().

                {
            int x2 = x;
            int y2 = y;
            int z2 = z;

            x2 = abs(nx/2-x);
            y2 = abs(ny/2-y);

            if (z > nz/2) {
                z2 = nz-z;
            }

            if (nz == 1) {
                return (float)(x2*x2 + y2*y2);
            }
            else {
                int areax = (int)((float)nx * z2 / nz);
                int areay = (int)((float)ny * z2 / nz);
                if ((abs(x-nx/2) <= areax) && (abs(y-ny/2) <= areay)) {
                    return (float)(x2*x2 + y2*y2);
                }
                else {
                    return 0;
                }
            }
                }
static float EMAN::TestUtil::get_pixel_value_by_dist2 ( int  nx,
int  ny,
int  nz,
int  x,
int  y,
int  z 
) [inline, static, private]

Definition at line 191 of file testutil.h.

References abs, x, and y.

Referenced by make_image_file_by_mode(), and verify_image_file_by_mode().

                {
            int x2 = x;
            int y2 = y;
            int z2 = z;


            if (x > nx/2) {
                x2 = nx-x;
            }
            if (y > ny/2) {
                y2 = ny-y;
            }

            if (z > nz/2) {
                z2 = nz-z;
            }

            if (nz == 1) {
                return (float)(x2*x2 + y2*y2);
            }
            else {
                int areax = (int)((float)nx * z2 / nz);
                int areay = (int)((float)ny * z2 / nz);
                if ((abs(x-nx/2) <= areax) && (abs(y-ny/2) <= areay)) {
                    return (float)(x2*x2 + y2*y2);
                }
                else {
                    return 0;
                }
            }
        }
static void EMAN::TestUtil::make_image_file ( const string &  filename,
EMUtil::ImageType  image_type,
EMUtil::EMDataType  datatype = EMUtil::EM_FLOAT,
int  nx = 16,
int  ny = 16,
int  nz = 1 
) [inline, static]

Definition at line 111 of file testutil.h.

References make_image_file_by_mode(), nx, and ny.

        {
            make_image_file_by_mode(filename, image_type, 1, datatype, nx, ny, nz);
        }
static void EMAN::TestUtil::make_image_file2 ( const string &  filename,
EMUtil::ImageType  image_type,
EMUtil::EMDataType  datatype = EMUtil::EM_FLOAT,
int  nx = 16,
int  ny = 16,
int  nz = 1 
) [inline, static]

Definition at line 127 of file testutil.h.

References make_image_file_by_mode(), nx, and ny.

        {
            make_image_file_by_mode(filename, image_type, 2, datatype,nx, ny, nz);
        }
void TestUtil::make_image_file_by_mode ( const string &  filename,
EMUtil::ImageType  image_type,
int  mode,
EMUtil::EMDataType  datatype = EMUtil::EM_FLOAT,
int  nx = 16,
int  ny = 16,
int  nz = 1 
) [static, private]

Definition at line 544 of file testutil.cpp.

References data, EMAN::EMData::do_fft(), EMAN::EMData::get_data(), get_pixel_value_by_dist1(), get_pixel_value_by_dist2(), is_complex(), EMAN::EMUtil::is_complex_type(), nx, ny, EMAN::EMData::set_attr(), EMAN::EMData::set_size(), EMAN::EMData::update(), and EMAN::EMData::write_image().

Referenced by make_image_file(), and make_image_file2().

{
    EMData * e = new EMData();
    e->set_size(nx, ny, nz);
        bool is_complex = EMUtil::is_complex_type(datatype);

        e->set_attr("is_complex", (int)is_complex);
    e->set_attr("datatype", (int)datatype);
    float * data = e->get_data();

        size_t l = 0;
    for (int i = 0; i < nz; i++) {
        for (int j = 0; j < ny; j++) {
            for (int k = 0; k < nx; k++) {
                if (mode == 1) {
                    data[l] = get_pixel_value_by_dist1(nx, ny, nz, k, j, i);
                }
                else if (mode == 2) {
                    data[l] = get_pixel_value_by_dist2(nx, ny, nz, k, j, i);
                }
                                l++;
            }
        }
    }

    if (!is_complex) {
        e->write_image(filename, 0, image_type, false, 0, datatype, true);
    }
    else {
        e->update();
        e->set_attr("is_complex", false);
        EMData * fft = e->do_fft();
        fft->write_image(filename, 0, image_type, false, 0, datatype, true);
        if( fft )
        {
                delete fft;
                fft = 0;
        }
    }

        if( e )
        {
        delete e;
        e = 0;
        }
}
void TestUtil::set_progname ( const string &  cur_progname) [static]

Definition at line 538 of file testutil.cpp.

References progname, and EMAN::Util::sbasename().

{
        progname = Util::sbasename(cur_progname);
}
Dict TestUtil::test_dict ( const Dict d) [static]

Definition at line 395 of file testutil.cpp.

References Assert, get_debug_string(), EMAN::Dict::keys(), LOGDEBUG, and tf.

{
        Dict r;

        vector<string> keys = d.keys();
        sort(keys.begin(), keys.end());

        for (size_t i = 0; i < keys.size(); i++) {
                LOGDEBUG("keys[%s] = %f\n", keys[i].c_str(), (float)d[keys[i]]);
                Assert(keys[i] == get_debug_string(i));
                Assert(((float)d[keys[i]]) == tf[i]);
                r[keys[i]] = d[keys[i]];
        }

        return r;
}
FloatPoint TestUtil::test_FloatPoint ( const FloatPoint p) [static]

Definition at line 206 of file testutil.cpp.

References Assert, LOGDEBUG, and tf.

{
        Assert(p[0] == tf[0]);
        Assert(p[1] == tf[1]);
        Assert(p[2] == tf[2]);
        LOGDEBUG("FloatPoint p = (%f, %f, %f)\n", p[0], p[1], p[2]);
        return FloatPoint(tf[0], tf[1], tf[2]);
}
FloatSize TestUtil::test_FloatSize ( const FloatSize p) [static]

Definition at line 226 of file testutil.cpp.

References Assert, LOGDEBUG, and tf.

{
        Assert(p[0] == tf[0]);
        Assert(p[1] == tf[1]);
        Assert(p[2] == tf[2]);
        LOGDEBUG("FloatSize p = (%f, %f, %f)\n", p[0], p[1], p[2]);
        return FloatSize(tf[0], tf[1], tf[2]);
}
IntPoint TestUtil::test_IntPoint ( const IntPoint p) [static]

Definition at line 197 of file testutil.cpp.

References Assert, LOGDEBUG, and ti.

{
        Assert(p[0] == ti[0]);
        Assert(p[1] == ti[1]);
        Assert(p[2] == ti[2]);
        LOGDEBUG("IntPoint p = (%d, %d, %d)\n", p[0], p[1], p[2]);
        return IntPoint(ti[0], ti[1], ti[2]);
}
IntSize TestUtil::test_IntSize ( const IntSize p) [static]

Definition at line 216 of file testutil.cpp.

References Assert, LOGDEBUG, and ti.

{
        Assert(p[0] == ti[0]);
        Assert(p[1] == ti[1]);
        Assert(p[2] == ti[2]);
        LOGDEBUG("IntSize p = (%d, %d, %d)\n", p[0], p[1], p[2]);
        return IntSize(ti[0], ti[1], ti[2]);
}
map< string, EMObject > TestUtil::test_map_emobject ( const map< string, EMObject > &  d) [static]

Definition at line 303 of file testutil.cpp.

References LOGDEBUG.

{
        map<string, EMObject> r;
        map<string, EMObject>::const_iterator p;
        for (p = d.begin(); p != d.end(); p++) {
                LOGDEBUG("map[\"%s\"] = %f; ", p->first.c_str(), (float)(p->second));
                r[p->first] = EMObject(p->second);
        }
        LOGDEBUG("\n");
        return r;
}
map< string, float > TestUtil::test_map_float ( const map< string, float > &  d) [static]

Definition at line 279 of file testutil.cpp.

References LOGDEBUG.

{
        map<string, float> r;
        map<string, float>::const_iterator p;
        for (p = d.begin(); p != d.end(); p++) {
                LOGDEBUG("map[\"%s\"] = %f; ", p->first.c_str(), p->second);
                r[p->first] = p->second;
        }
        LOGDEBUG("\n");
        return r;
}
map< string, int > TestUtil::test_map_int ( const map< string, int > &  d) [static]

Definition at line 255 of file testutil.cpp.

References LOGDEBUG.

{
        map<string, int> r;
        map<string, int>::const_iterator p;
        for (p = d.begin(); p != d.end(); p++) {
                LOGDEBUG("map[\"%s\"] = %d; ", p->first.c_str(), p->second);
                r[p->first] = p->second;
        }
        LOGDEBUG("\n");
        return r;
}
map< string, long > TestUtil::test_map_long ( const map< string, long > &  d) [static]

Definition at line 267 of file testutil.cpp.

References LOGDEBUG.

{
        map<string, long> r;
        map<string, long>::const_iterator p;
        for (p = d.begin(); p != d.end(); p++) {
                LOGDEBUG("map[\"%s\"] = %d; ", p->first.c_str(), p->second);
                r[p->first] = p->second;
        }
        LOGDEBUG("\n");
        return r;
}
map< string, string > TestUtil::test_map_string ( const map< string, string > &  d) [static]

Definition at line 291 of file testutil.cpp.

References LOGDEBUG.

{
        map<string, string> r;
        map<string, string>::const_iterator p;
        for (p = d.begin(); p != d.end(); p++) {
                LOGDEBUG("map[\"%s\"] = %s; ", p->first.c_str(), p->second.c_str());
                r[p->first] = p->second;
        }
        LOGDEBUG("\n");
        return r;
}
map< string, vector< string > > TestUtil::test_map_vecstring ( const map< string, vector< string > > &  d) [static]

Definition at line 315 of file testutil.cpp.

{
        map<string, vector<string> > r;
        return r;
}
Vec3f TestUtil::test_Vec3f ( const Vec3f p) [static]

Definition at line 245 of file testutil.cpp.

References Assert, LOGDEBUG, and tf.

{
        Assert(p[0] == tf[0]);
        Assert(p[1] == tf[1]);
        Assert(p[2] == tf[2]);
        LOGDEBUG("Vec3f p = (%f, %f, %f)\n", p[0], p[1], p[2]);
        return Vec3f(tf[0], tf[1], tf[2]);
}
Vec3i TestUtil::test_Vec3i ( const Vec3i p) [static]

Definition at line 236 of file testutil.cpp.

References Assert, LOGDEBUG, and ti.

{
        Assert(p[0] == ti[0]);
        Assert(p[1] == ti[1]);
        Assert(p[2] == ti[2]);
        LOGDEBUG("Vec3i p = (%d, %d, %d)\n", p[0], p[1], p[2]);
        return Vec3i(ti[0], ti[1], ti[2]);
}
vector< EMData * > TestUtil::test_vector_emdata ( const vector< EMData * > &  v) [static]

Definition at line 370 of file testutil.cpp.

References EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), and LOGDEBUG.

{
        vector<EMData*> r;
        for (size_t i = 0; i < v.size(); i++) {
                EMData * e = v[i];
                LOGDEBUG("Image(%d,%d,%d); ", e->get_xsize(), e->get_ysize(), e->get_zsize());
                r.push_back(v[i]);
        }
        LOGDEBUG("\n");
        return r;
}
vector< float > TestUtil::test_vector_float ( const vector< float > &  v) [static]

Definition at line 335 of file testutil.cpp.

References Assert, LOGDEBUG, and tf.

{
        vector<float> r;
        for (size_t i = 0; i < v.size(); i++) {
                LOGDEBUG("v[%d]=%f; ", i, v[i]);
                Assert(v[i] == tf[i]);
                r.push_back(v[i]);
        }
        LOGDEBUG("\n");
        return r;
}
vector< int > TestUtil::test_vector_int ( const vector< int > &  v) [static]

Definition at line 323 of file testutil.cpp.

References Assert, LOGDEBUG, and ti.

{
        vector<int> r;
        for (size_t i = 0; i < v.size(); i++) {
                LOGDEBUG("v[%d]=%d; ", i, v[i]);
                Assert(v[i] == ti[i]);
                r.push_back(v[i]);
        }
        LOGDEBUG("\n");
        return r;
}
vector< long > TestUtil::test_vector_long ( const vector< long > &  v) [static]

Definition at line 347 of file testutil.cpp.

References Assert, LOGDEBUG, and ti.

{
        vector<long> r;
        for (size_t i = 0; i < v.size(); i++) {
                LOGDEBUG("v[%d]=%d; ", i, (int)v[i]);
                Assert((int)v[i] == ti[i]);
                r.push_back(v[i]);
        }
        LOGDEBUG("\n");
        return r;
}
vector< Pixel > TestUtil::test_vector_pixel ( const vector< Pixel > &  v) [static]

Definition at line 382 of file testutil.cpp.

References LOGDEBUG, EMAN::Pixel::value, EMAN::Pixel::x, EMAN::Pixel::y, and EMAN::Pixel::z.

{
        vector<Pixel> r;
        for (size_t i = 0; i < v.size(); i++) {
                Pixel p = v[i];
                LOGDEBUG("Pixel(%d,%d,%d)=%4.2f; ", p.x, p.y, p.z, p.value);
                Pixel p2(p.x, p.y, p.z, p.value);
                r.push_back(p2);
        }

        return r;
}
vector< string > TestUtil::test_vector_string ( const vector< string > &  v) [static]

Definition at line 359 of file testutil.cpp.

References LOGDEBUG.

{
        vector<string> r;
        for (size_t i = 0; i < v.size(); i++) {
                LOGDEBUG("v[%d]=%s; ", i, v[i].c_str());
                r.push_back(v[i]);
        }
        LOGDEBUG("\n");
        return r;
}
void TestUtil::to_emobject ( const Dict d) [static]

Definition at line 118 of file testutil.cpp.

References Assert, get_debug_string(), get_debug_transform(), EMAN::XYData::get_size(), EMAN::XYData::get_x(), EMAN::EMData::get_xsize(), EMAN::XYData::get_y(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), LOGDEBUG, nx, ny, tf, and ti.

{
        if (d.has_key("floatarray")) {
                vector<float> array = d["floatarray"];
                for (size_t i = 0; i < array.size(); i++) {
                        Assert(array[i] == tf[i]);
                        LOGDEBUG("floatarray[%d] = %f\n", i, array[i]);
                }
        }

        if (d.has_key("emdata")) {
                EMData * img = d["emdata"];
                if (img) {
                        int nx = img->get_xsize();
                        int ny = img->get_ysize();
                        int nz = img->get_zsize();
                        Assert(nx == ti[0]);
                        Assert(ny == ti[1]);
                        Assert(nz == ti[2]);
                        LOGDEBUG("image size = (%d, %d, %d)\n", nx, ny, nz);
                }
        }

        if (d.has_key("int")) {
                int n = d["int"];
                Assert(n == ti[0]);
                LOGDEBUG("int n = %d\n", n);
        }

        if (d.has_key("float")) {
                float f = d["float"];
                Assert(f == tf[0]);
                LOGDEBUG("float f = %f\n", f);
        }

        if (d.has_key("long")) {
                int l = (int)d["long"];
                Assert(l == ti[0]);
                LOGDEBUG("long l = %d\n", l);
        }

    if (d.has_key("string")) {
        string s = (const char*)d["string"];
        string s2 = get_debug_string(0);
        Assert(s == s2);
    }


        if (d.has_key("xydata")) {
                XYData *xyd = d["xydata"];
                size_t nitems = xyd->get_size();
                for (size_t i = 0; i < nitems; i++) {
                        float xi = xyd->get_x(i);
                        float yi = xyd->get_y(i);
                        LOGDEBUG("xydata[%d] = (%f,%f)\n", i, xi, yi);
                        Assert(xi == tf[i]);
                        Assert(yi == tf[i]);
                }
        }

        if (d.has_key("stringarray")) {
                vector<string> array = d["stringarray"];
                for (size_t i = 0; i < array.size(); i++) {
                        Assert(array[i] == get_debug_string(i));
                        LOGDEBUG("stringarray[%d] = %s\n", i, array[i].c_str());
                }
        }

        if (d.has_key("transformarray")) {
                vector<Transform> array = d["transformarray"];
                for (size_t i = 0; i < array.size(); i++) {
//                      array[i].printme();
                        Assert(array[i] == get_debug_transform(i));
//                      LOGDEBUG("transformarray[%d] = %s\n", i, array[i].to_str());
                }
        }
}
static int EMAN::TestUtil::verify_image_file ( const string &  filename,
EMUtil::ImageType  image_type,
EMUtil::EMDataType  datatype = EMUtil::EM_FLOAT,
int  nx = 16,
int  ny = 16,
int  nz = 1 
) [inline, static]

Definition at line 119 of file testutil.h.

References nx, ny, and verify_image_file_by_mode().

        {
            return verify_image_file_by_mode(filename, image_type, 1, datatype, nx, ny, nz);
        }
static int EMAN::TestUtil::verify_image_file2 ( const string &  filename,
EMUtil::ImageType  image_type,
EMUtil::EMDataType  datatype = EMUtil::EM_FLOAT,
int  nx = 16,
int  ny = 16,
int  nz = 1 
) [inline, static]

Definition at line 135 of file testutil.h.

References nx, ny, and verify_image_file_by_mode().

        {
            return verify_image_file_by_mode(filename, image_type, 2,
                                                                                         datatype, nx, ny, nz);
        }
int TestUtil::verify_image_file_by_mode ( const string &  filename,
EMUtil::ImageType  image_type,
int  mode,
EMUtil::EMDataType  datatype = EMUtil::EM_FLOAT,
int  nx = 16,
int  ny = 16,
int  nz = 1 
) [static, private]

Definition at line 594 of file testutil.cpp.

References data, EMAN::EMData::get_attr_dict(), EMAN::EMData::get_data(), get_pixel_value_by_dist1(), get_pixel_value_by_dist2(), is_complex(), EMAN::EMUtil::is_complex_type(), LOGERR, nx, ny, and EMAN::EMData::read_image().

Referenced by verify_image_file(), and verify_image_file2().

{
        int err = 0;

        EMData * e = new EMData();
        e->read_image(filename);

        Dict attr_dict = e->get_attr_dict();
        bool is_complex = EMUtil::is_complex_type(datatype);

        if (is_complex) {
                nx = (nx+2);
        }

        if (nx != (int) attr_dict["nx"]) {
        LOGERR("nx: %d != %d\n", nx, (int) attr_dict["nx"]);
        return 1;
    }

    if (ny != (int) attr_dict["ny"]) {
        LOGERR("ny: %d != %d\n", ny, (int) attr_dict["ny"]);
        return 1;
    }

    if (nz != (int) attr_dict["nz"]) {
        LOGERR("nz: %d != %d\n", nz, (int) attr_dict["nz"]);
        return 1;
    }

        if (datatype != (int) attr_dict["datatype"]) {
        LOGERR("datatype: %d != %d\n", datatype, (int) attr_dict["datatype"]);
        return 1;
    }


        if ((int)is_complex != (int) attr_dict["is_complex"]) {
        LOGERR("is_complex: %d != %d\n", is_complex, (int) attr_dict["is_complex"]);
        return 1;
    }


        if (!is_complex) {
                float * data = e->get_data();
                size_t l = 0;
                for (int i = 0; i < nz; i++) {
                        for (int j = 0; j < ny; j++) {
                                for (int k = 0; k < nx; k++) {

                    int d2 = 0;
                    if (mode == 1) {
                        d2 = (int)get_pixel_value_by_dist1(nx,ny,nz,k,j,i);
                    }
                    else if (mode == 2) {
                        d2 = (int)get_pixel_value_by_dist2(nx,ny,nz,k,j,i);
                    }

                                        if ((int)data[l] != d2) {
                        LOGERR("(%d,%d,%d): %d != %d\n", i,j,k,(int)data[l], d2);
                                                break;
                                                err = 1;
                                        }
                                        l++;
                                }
                        }
                }
        }

        return err;
}

Member Data Documentation

const char * TestUtil::EMDATA_DATA_EXT = ".data" [static]

Definition at line 56 of file testutil.h.

Referenced by check_image(), and dump_emdata().

const char * TestUtil::EMDATA_HEADER_EXT = ".head" [static]

Definition at line 55 of file testutil.h.

Referenced by check_image(), and dump_emdata().

string TestUtil::progname = "" [static, private]

Definition at line 150 of file testutil.h.

Referenced by check_image(), and set_progname().

float TestUtil::tf = {1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5} [static, private]
int TestUtil::ti = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100} [static, private]

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