EMAN::TestUtil Class Reference

#include <testutil.h>

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().

00414 {
00415 #if DEBUG
00416         string headerfile1 = Util::sbasename(imagefile) + EMDATA_HEADER_EXT;
00417         string datafile1 = Util::sbasename(imagefile) + EMDATA_DATA_EXT;
00418 
00419         char imgpath[MAXPATHLEN];
00420         char * path_env = getenv("DEBUG_IMAGE_PATH");
00421         if (path_env) {
00422                 sprintf(imgpath, "%s/testdata/%s/", path_env, progname.c_str());
00423         }
00424         else {
00425                 sprintf(imgpath, "%s/images/testdata/%s/", getenv("HOME"), progname.c_str());
00426         }
00427 
00428         string headerfile2 = string(imgpath) + headerfile1;
00429         string datafile2 = string(imgpath) + datafile1;
00430 
00431 
00432         if (image) {
00433                 dump_emdata(image, imagefile);
00434         }
00435         else {
00436                 dump_image_from_file(imagefile);
00437         }
00438 
00439     if (!Util::is_file_exist(headerfile2) ||
00440         !Util::is_file_exist(datafile2)) {
00441         return 0;
00442     }
00443 
00444         string diffcmd1 = "diff " + headerfile1 + " " + headerfile2;
00445 
00446         int err = system(diffcmd1.c_str());
00447         if (!err) {
00448                 string diffcmd2 = "diff " + datafile1 + " " + datafile2;
00449                 err = system(diffcmd2.c_str());
00450         }
00451         if (err) {
00452                 LOGERR("check_image on %s FAILED\n", imagefile.c_str());
00453         }
00454 
00455         return err;
00456 #endif
00457     return 0;
00458 }

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().

00473 {
00474         string filebase = Util::sbasename(filename);
00475         string headerfile = filebase + EMDATA_HEADER_EXT;
00476         string datafile = filebase + EMDATA_DATA_EXT;
00477 
00478         FILE *hfile = fopen(headerfile.c_str(), "wb");
00479         if (!hfile) {
00480                 throw FileAccessException(headerfile);
00481         }
00482 #if 0
00483         vector<string> excl_keys;
00484         excl_keys.push_back("MRC.label");
00485         excl_keys.push_back("IMAGIC.minute");
00486         excl_keys.push_back("IMAGIC.sec");
00487 
00488         Dict attr_dict = image->get_attr_dict();
00489         vector < string > keys = attr_dict.keys();
00490 
00491 
00492 
00493         for (size_t i = 0; i < keys.size(); i++) {
00494 
00495                 bool is_exclude = false;
00496                 for (size_t j = 0; j < excl_keys.size(); j++) {
00497                         if (Util::sstrncmp(keys[i].c_str(), excl_keys[j].c_str())) {
00498                                 is_exclude = true;
00499                                 break;
00500                         }
00501                 }
00502                 if (!is_exclude) {
00503                         fprintf(hfile, "%s = %s\n", keys[i].c_str(),
00504                                         attr_dict[keys[i]].to_str().c_str());
00505                 }
00506         }
00507 #endif
00508 
00509         fprintf(hfile, "nx = %d\n", image->get_xsize());
00510         fprintf(hfile, "ny = %d\n", image->get_ysize());
00511         fprintf(hfile, "nz = %d\n", image->get_zsize());
00512 
00513         fclose(hfile);
00514         hfile = 0;
00515 
00516         FILE *dfile = fopen(datafile.c_str(), "wb");
00517         if (!dfile) {
00518                 throw FileAccessException(datafile);
00519         }
00520 
00521         int nx = image->get_xsize();
00522         int ny = image->get_ysize();
00523         int nz = image->get_zsize();
00524 
00525         size_t row_size = nx * sizeof(float);
00526         size_t nxy = nx * ny;
00527         float * rdata = image->get_data();
00528 
00529         for (int i = 0; i < nz; i++) {
00530                 for (int j = 0; j < ny; j++) {
00531                         fwrite(&rdata[i * nxy + j * nx], row_size, 1, dfile);
00532                 }
00533         }
00534         fclose(dfile);
00535         dfile = 0;
00536 }

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().

00461 {
00462         EMData * e = new EMData();
00463         e->read_image(filename);
00464         dump_emdata(e, filename);
00465         if( e )
00466         {
00467                 delete e;
00468                 e = 0;
00469         }
00470 }

EMObject TestUtil::emobject_farray_to_py (  )  [static]

Definition at line 710 of file testutil.cpp.

References tf, and v.

00711 {
00712         vector<float> v(3);
00713         for (int i = 0; i < 3; i++) {
00714                 v[i] = tf[i];
00715         }
00716         return EMObject(v);
00717 }

EMObject TestUtil::emobject_strarray_to_py (  )  [static]

Definition at line 720 of file testutil.cpp.

References get_debug_string(), and v.

00721 {
00722         vector<string> v(3);
00723         for (int i = 0; i < 3; i++) {
00724                 v[i] = get_debug_string(i);
00725         }
00726         return EMObject(v);
00727 }

EMObject TestUtil::emobject_to_py ( Ctf ctf_  )  [static]

Definition at line 745 of file testutil.cpp.

00746 {
00747         return EMObject(ctf_);
00748 }

EMObject TestUtil::emobject_to_py ( Transform t  )  [static]

Definition at line 740 of file testutil.cpp.

References t.

00741 {
00742         return EMObject(t);
00743 }

EMObject TestUtil::emobject_to_py ( XYData xydata  )  [static]

Definition at line 704 of file testutil.cpp.

00705 {
00706         return EMObject(xydata);
00707 }

EMObject TestUtil::emobject_to_py ( EMData emdata  )  [static]

Definition at line 698 of file testutil.cpp.

00699 {
00700         return EMObject(emdata);
00701 }

EMObject TestUtil::emobject_to_py ( const string &  str  )  [static]

Definition at line 692 of file testutil.cpp.

00693 {
00694         return EMObject(str);
00695 }

EMObject TestUtil::emobject_to_py ( double  f  )  [static]

Definition at line 687 of file testutil.cpp.

00688 {
00689         return EMObject(f);
00690 }

EMObject TestUtil::emobject_to_py ( float  f  )  [static]

Definition at line 682 of file testutil.cpp.

00683 {
00684         return EMObject(f);
00685 }

EMObject TestUtil::emobject_to_py ( int  n  )  [static]

Definition at line 677 of file testutil.cpp.

00678 {
00679         return EMObject(n);
00680 }

EMObject TestUtil::emobject_to_py ( unsigned int  n  )  [static]

Definition at line 672 of file testutil.cpp.

00673 {
00674         return EMObject(un);
00675 }

EMObject TestUtil::emobject_to_py ( bool  b  )  [static]

Definition at line 667 of file testutil.cpp.

00668 {
00669         return EMObject(b);
00670 }

EMObject TestUtil::emobject_transformarray_to_py (  )  [static]

Definition at line 729 of file testutil.cpp.

References t, and v.

00730 {
00731         vector<Transform> v(3);
00732         for (int i=0; i<3; i++) {
00733                 Transform t;
00734                 t.set_trans(i, i+1, i+2);
00735                 v[i] = t;
00736         }
00737         return EMObject(v);
00738 }

float TestUtil::get_debug_float ( int  i  )  [static]

Definition at line 69 of file testutil.cpp.

References tf.

00070 {
00071         return tf[i];
00072 }

string TestUtil::get_debug_image ( const string &  imagename  )  [static]

Definition at line 92 of file testutil.cpp.

00093 {
00094         char imgpath[MAXPATHLEN];
00095         char * path_env = getenv("DEBUG_IMAGE_PATH");
00096         if (path_env) {
00097                 sprintf(imgpath, "%s/%s", path_env, imagename.c_str());
00098         }
00099         else {
00100                 sprintf(imgpath, "%s/images/%s", getenv("HOME"), imagename.c_str());
00101         }
00102         return string(imgpath);
00103 }

int TestUtil::get_debug_int ( int  i  )  [static]

Definition at line 64 of file testutil.cpp.

References ti.

00065 {
00066         return ti[i];
00067 }

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().

00075 {
00076         char a[32];
00077         sprintf(a, "%d%d", i+1, i+1);
00078         return string(a);
00079 }

Transform TestUtil::get_debug_transform ( int  i  )  [static]

Definition at line 81 of file testutil.cpp.

References t, and v.

Referenced by to_emobject().

00082 {
00083         vector<Transform> v(3);
00084         for (int j=0; j<3; j++) {
00085                 Transform t;
00086                 t.set_trans(j, j+1, j+2);
00087                 v[j] = t;
00088         }
00089         return v[i];
00090 }

string TestUtil::get_golden_image ( const string &  imagename  )  [static]

Definition at line 105 of file testutil.cpp.

00106 {
00107         char imgpath[MAXPATHLEN];
00108         char * path_env = getenv("DEBUG_IMAGE_PATH");
00109         if (path_env) {
00110                 sprintf(imgpath, "%s/testdata/%s", path_env, imagename.c_str());
00111         }
00112         else {
00113                 sprintf(imgpath, "%s/images/testdata/%s", getenv("HOME"), imagename.c_str());
00114         }
00115         return string(imgpath);
00116 }

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.

Referenced by make_image_file_by_mode(), and verify_image_file_by_mode().

00164                 {
00165             int x2 = x;
00166             int y2 = y;
00167             int z2 = z;
00168 
00169             x2 = abs(nx/2-x);
00170             y2 = abs(ny/2-y);
00171 
00172             if (z > nz/2) {
00173                 z2 = nz-z;
00174             }
00175 
00176             if (nz == 1) {
00177                 return (float)(x2*x2 + y2*y2);
00178             }
00179             else {
00180                 int areax = (int)((float)nx * z2 / nz);
00181                 int areay = (int)((float)ny * z2 / nz);
00182                 if ((abs(x-nx/2) <= areax) && (abs(y-ny/2) <= areay)) {
00183                     return (float)(x2*x2 + y2*y2);
00184                 }
00185                 else {
00186                     return 0;
00187                 }
00188             }
00189                 }

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.

Referenced by make_image_file_by_mode(), and verify_image_file_by_mode().

00192                 {
00193             int x2 = x;
00194             int y2 = y;
00195             int z2 = z;
00196 
00197 
00198             if (x > nx/2) {
00199                 x2 = nx-x;
00200             }
00201             if (y > ny/2) {
00202                 y2 = ny-y;
00203             }
00204 
00205             if (z > nz/2) {
00206                 z2 = nz-z;
00207             }
00208 
00209             if (nz == 1) {
00210                 return (float)(x2*x2 + y2*y2);
00211             }
00212             else {
00213                 int areax = (int)((float)nx * z2 / nz);
00214                 int areay = (int)((float)ny * z2 / nz);
00215                 if ((abs(x-nx/2) <= areax) && (abs(y-ny/2) <= areay)) {
00216                     return (float)(x2*x2 + y2*y2);
00217                 }
00218                 else {
00219                     return 0;
00220                 }
00221             }
00222         }

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.

00115         {
00116             make_image_file_by_mode(filename, image_type, 1, datatype, nx, ny, nz);
00117         }

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.

00131         {
00132             make_image_file_by_mode(filename, image_type, 2, datatype,nx, ny, nz);
00133         }

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(), 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().

00548 {
00549     EMData * e = new EMData();
00550     e->set_size(nx, ny, nz);
00551         bool is_complex = EMUtil::is_complex_type(datatype);
00552 
00553         e->set_attr("is_complex", (int)is_complex);
00554     e->set_attr("datatype", (int)datatype);
00555     float * data = e->get_data();
00556 
00557         size_t l = 0;
00558     for (int i = 0; i < nz; i++) {
00559         for (int j = 0; j < ny; j++) {
00560             for (int k = 0; k < nx; k++) {
00561                 if (mode == 1) {
00562                     data[l] = get_pixel_value_by_dist1(nx, ny, nz, k, j, i);
00563                 }
00564                 else if (mode == 2) {
00565                     data[l] = get_pixel_value_by_dist2(nx, ny, nz, k, j, i);
00566                 }
00567                                 l++;
00568             }
00569         }
00570     }
00571 
00572     if (!is_complex) {
00573         e->write_image(filename, 0, image_type, false, 0, datatype, true);
00574     }
00575     else {
00576         e->update();
00577         e->set_attr("is_complex", false);
00578         EMData * fft = e->do_fft();
00579         fft->write_image(filename, 0, image_type, false, 0, datatype, true);
00580         if( fft )
00581         {
00582                 delete fft;
00583                 fft = 0;
00584         }
00585     }
00586 
00587         if( e )
00588         {
00589         delete e;
00590         e = 0;
00591         }
00592 }

void TestUtil::set_progname ( const string &  cur_progname  )  [static]

Definition at line 538 of file testutil.cpp.

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

00539 {
00540         progname = Util::sbasename(cur_progname);
00541 }

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.

00396 {
00397         Dict r;
00398 
00399         vector<string> keys = d.keys();
00400         sort(keys.begin(), keys.end());
00401 
00402         for (size_t i = 0; i < keys.size(); i++) {
00403                 LOGDEBUG("keys[%s] = %f\n", keys[i].c_str(), (float)d[keys[i]]);
00404                 Assert(keys[i] == get_debug_string(i));
00405                 Assert(((float)d[keys[i]]) == tf[i]);
00406                 r[keys[i]] = d[keys[i]];
00407         }
00408 
00409         return r;
00410 }

FloatPoint TestUtil::test_FloatPoint ( const FloatPoint p  )  [static]

Definition at line 206 of file testutil.cpp.

References Assert, LOGDEBUG, and tf.

00207 {
00208         Assert(p[0] == tf[0]);
00209         Assert(p[1] == tf[1]);
00210         Assert(p[2] == tf[2]);
00211         LOGDEBUG("FloatPoint p = (%f, %f, %f)\n", p[0], p[1], p[2]);
00212         return FloatPoint(tf[0], tf[1], tf[2]);
00213 }

FloatSize TestUtil::test_FloatSize ( const FloatSize p  )  [static]

Definition at line 226 of file testutil.cpp.

References Assert, LOGDEBUG, and tf.

00227 {
00228         Assert(p[0] == tf[0]);
00229         Assert(p[1] == tf[1]);
00230         Assert(p[2] == tf[2]);
00231         LOGDEBUG("FloatSize p = (%f, %f, %f)\n", p[0], p[1], p[2]);
00232         return FloatSize(tf[0], tf[1], tf[2]);
00233 }

IntPoint TestUtil::test_IntPoint ( const IntPoint p  )  [static]

Definition at line 197 of file testutil.cpp.

References Assert, LOGDEBUG, and ti.

00198 {
00199         Assert(p[0] == ti[0]);
00200         Assert(p[1] == ti[1]);
00201         Assert(p[2] == ti[2]);
00202         LOGDEBUG("IntPoint p = (%d, %d, %d)\n", p[0], p[1], p[2]);
00203         return IntPoint(ti[0], ti[1], ti[2]);
00204 }

IntSize TestUtil::test_IntSize ( const IntSize p  )  [static]

Definition at line 216 of file testutil.cpp.

References Assert, LOGDEBUG, and ti.

00217 {
00218         Assert(p[0] == ti[0]);
00219         Assert(p[1] == ti[1]);
00220         Assert(p[2] == ti[2]);
00221         LOGDEBUG("IntSize p = (%d, %d, %d)\n", p[0], p[1], p[2]);
00222         return IntSize(ti[0], ti[1], ti[2]);
00223 }

map< string, EMObject > TestUtil::test_map_emobject ( const map< string, EMObject > &  d  )  [static]

Definition at line 303 of file testutil.cpp.

References LOGDEBUG.

00304 {
00305         map<string, EMObject> r;
00306         map<string, EMObject>::const_iterator p;
00307         for (p = d.begin(); p != d.end(); p++) {
00308                 LOGDEBUG("map[\"%s\"] = %f; ", p->first.c_str(), (float)(p->second));
00309                 r[p->first] = EMObject(p->second);
00310         }
00311         LOGDEBUG("\n");
00312         return r;
00313 }

map< string, float > TestUtil::test_map_float ( const map< string, float > &  d  )  [static]

Definition at line 279 of file testutil.cpp.

References LOGDEBUG.

00280 {
00281         map<string, float> r;
00282         map<string, float>::const_iterator p;
00283         for (p = d.begin(); p != d.end(); p++) {
00284                 LOGDEBUG("map[\"%s\"] = %f; ", p->first.c_str(), p->second);
00285                 r[p->first] = p->second;
00286         }
00287         LOGDEBUG("\n");
00288         return r;
00289 }

map< string, int > TestUtil::test_map_int ( const map< string, int > &  d  )  [static]

Definition at line 255 of file testutil.cpp.

References LOGDEBUG.

00256 {
00257         map<string, int> r;
00258         map<string, int>::const_iterator p;
00259         for (p = d.begin(); p != d.end(); p++) {
00260                 LOGDEBUG("map[\"%s\"] = %d; ", p->first.c_str(), p->second);
00261                 r[p->first] = p->second;
00262         }
00263         LOGDEBUG("\n");
00264         return r;
00265 }

map< string, long > TestUtil::test_map_long ( const map< string, long > &  d  )  [static]

Definition at line 267 of file testutil.cpp.

References LOGDEBUG.

00268 {
00269         map<string, long> r;
00270         map<string, long>::const_iterator p;
00271         for (p = d.begin(); p != d.end(); p++) {
00272                 LOGDEBUG("map[\"%s\"] = %d; ", p->first.c_str(), p->second);
00273                 r[p->first] = p->second;
00274         }
00275         LOGDEBUG("\n");
00276         return r;
00277 }

map< string, string > TestUtil::test_map_string ( const map< string, string > &  d  )  [static]

Definition at line 291 of file testutil.cpp.

References LOGDEBUG.

00292 {
00293         map<string, string> r;
00294         map<string, string>::const_iterator p;
00295         for (p = d.begin(); p != d.end(); p++) {
00296                 LOGDEBUG("map[\"%s\"] = %s; ", p->first.c_str(), p->second.c_str());
00297                 r[p->first] = p->second;
00298         }
00299         LOGDEBUG("\n");
00300         return r;
00301 }

map< string, vector< string > > TestUtil::test_map_vecstring ( const map< string, vector< string > > &  d  )  [static]

Definition at line 315 of file testutil.cpp.

00317 {
00318         map<string, vector<string> > r;
00319         return r;
00320 }

Vec3f TestUtil::test_Vec3f ( const Vec3f p  )  [static]

Definition at line 245 of file testutil.cpp.

References Assert, LOGDEBUG, and tf.

00246 {
00247         Assert(p[0] == tf[0]);
00248         Assert(p[1] == tf[1]);
00249         Assert(p[2] == tf[2]);
00250         LOGDEBUG("Vec3f p = (%f, %f, %f)\n", p[0], p[1], p[2]);
00251         return Vec3f(tf[0], tf[1], tf[2]);
00252 }

Vec3i TestUtil::test_Vec3i ( const Vec3i p  )  [static]

Definition at line 236 of file testutil.cpp.

References Assert, LOGDEBUG, and ti.

00237 {
00238         Assert(p[0] == ti[0]);
00239         Assert(p[1] == ti[1]);
00240         Assert(p[2] == ti[2]);
00241         LOGDEBUG("Vec3i p = (%d, %d, %d)\n", p[0], p[1], p[2]);
00242         return Vec3i(ti[0], ti[1], ti[2]);
00243 }

vector< EMData * > TestUtil::test_vector_emdata ( const vector< EMData * > &  v  )  [static]

Definition at line 370 of file testutil.cpp.

References LOGDEBUG.

00371 {
00372         vector<EMData*> r;
00373         for (size_t i = 0; i < v.size(); i++) {
00374                 EMData * e = v[i];
00375                 LOGDEBUG("Image(%d,%d,%d); ", e->get_xsize(), e->get_ysize(), e->get_zsize());
00376                 r.push_back(v[i]);
00377         }
00378         LOGDEBUG("\n");
00379         return r;
00380 }

vector< float > TestUtil::test_vector_float ( const vector< float > &  v  )  [static]

Definition at line 335 of file testutil.cpp.

References Assert, LOGDEBUG, and tf.

00336 {
00337         vector<float> r;
00338         for (size_t i = 0; i < v.size(); i++) {
00339                 LOGDEBUG("v[%d]=%f; ", i, v[i]);
00340                 Assert(v[i] == tf[i]);
00341                 r.push_back(v[i]);
00342         }
00343         LOGDEBUG("\n");
00344         return r;
00345 }

vector< int > TestUtil::test_vector_int ( const vector< int > &  v  )  [static]

Definition at line 323 of file testutil.cpp.

References Assert, LOGDEBUG, and ti.

00324 {
00325         vector<int> r;
00326         for (size_t i = 0; i < v.size(); i++) {
00327                 LOGDEBUG("v[%d]=%d; ", i, v[i]);
00328                 Assert(v[i] == ti[i]);
00329                 r.push_back(v[i]);
00330         }
00331         LOGDEBUG("\n");
00332         return r;
00333 }

vector< long > TestUtil::test_vector_long ( const vector< long > &  v  )  [static]

Definition at line 347 of file testutil.cpp.

References Assert, LOGDEBUG, and ti.

00348 {
00349         vector<long> r;
00350         for (size_t i = 0; i < v.size(); i++) {
00351                 LOGDEBUG("v[%d]=%d; ", i, (int)v[i]);
00352                 Assert((int)v[i] == ti[i]);
00353                 r.push_back(v[i]);
00354         }
00355         LOGDEBUG("\n");
00356         return r;
00357 }

vector< Pixel > TestUtil::test_vector_pixel ( const vector< Pixel > &  v  )  [static]

Definition at line 382 of file testutil.cpp.

References LOGDEBUG.

00383 {
00384         vector<Pixel> r;
00385         for (size_t i = 0; i < v.size(); i++) {
00386                 Pixel p = v[i];
00387                 LOGDEBUG("Pixel(%d,%d,%d)=%4.2f; ", p.x, p.y, p.z, p.value);
00388                 Pixel p2(p.x, p.y, p.z, p.value);
00389                 r.push_back(p2);
00390         }
00391 
00392         return r;
00393 }

vector< string > TestUtil::test_vector_string ( const vector< string > &  v  )  [static]

Definition at line 359 of file testutil.cpp.

References LOGDEBUG.

00360 {
00361         vector<string> r;
00362         for (size_t i = 0; i < v.size(); i++) {
00363                 LOGDEBUG("v[%d]=%s; ", i, v[i].c_str());
00364                 r.push_back(v[i]);
00365         }
00366         LOGDEBUG("\n");
00367         return r;
00368 }

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::Dict::has_key(), LOGDEBUG, nx, ny, tf, and ti.

00119 {
00120         if (d.has_key("floatarray")) {
00121                 vector<float> array = d["floatarray"];
00122                 for (size_t i = 0; i < array.size(); i++) {
00123                         Assert(array[i] == tf[i]);
00124                         LOGDEBUG("floatarray[%d] = %f\n", i, array[i]);
00125                 }
00126         }
00127 
00128         if (d.has_key("emdata")) {
00129                 EMData * img = d["emdata"];
00130                 if (img) {
00131                         int nx = img->get_xsize();
00132                         int ny = img->get_ysize();
00133                         int nz = img->get_zsize();
00134                         Assert(nx == ti[0]);
00135                         Assert(ny == ti[1]);
00136                         Assert(nz == ti[2]);
00137                         LOGDEBUG("image size = (%d, %d, %d)\n", nx, ny, nz);
00138                 }
00139         }
00140 
00141         if (d.has_key("int")) {
00142                 int n = d["int"];
00143                 Assert(n == ti[0]);
00144                 LOGDEBUG("int n = %d\n", n);
00145         }
00146 
00147         if (d.has_key("float")) {
00148                 float f = d["float"];
00149                 Assert(f == tf[0]);
00150                 LOGDEBUG("float f = %f\n", f);
00151         }
00152 
00153         if (d.has_key("long")) {
00154                 int l = (int)d["long"];
00155                 Assert(l == ti[0]);
00156                 LOGDEBUG("long l = %d\n", l);
00157         }
00158 
00159     if (d.has_key("string")) {
00160         string s = (const char*)d["string"];
00161         string s2 = get_debug_string(0);
00162         Assert(s == s2);
00163     }
00164 
00165 
00166         if (d.has_key("xydata")) {
00167                 XYData *xyd = d["xydata"];
00168                 size_t nitems = xyd->get_size();
00169                 for (size_t i = 0; i < nitems; i++) {
00170                         float xi = xyd->get_x(i);
00171                         float yi = xyd->get_y(i);
00172                         LOGDEBUG("xydata[%d] = (%f,%f)\n", i, xi, yi);
00173                         Assert(xi == tf[i]);
00174                         Assert(yi == tf[i]);
00175                 }
00176         }
00177 
00178         if (d.has_key("stringarray")) {
00179                 vector<string> array = d["stringarray"];
00180                 for (size_t i = 0; i < array.size(); i++) {
00181                         Assert(array[i] == get_debug_string(i));
00182                         LOGDEBUG("stringarray[%d] = %s\n", i, array[i].c_str());
00183                 }
00184         }
00185 
00186         if (d.has_key("transformarray")) {
00187                 vector<Transform> array = d["transformarray"];
00188                 for (size_t i = 0; i < array.size(); i++) {
00189 //                      array[i].printme();
00190                         Assert(array[i] == get_debug_transform(i));
00191 //                      LOGDEBUG("transformarray[%d] = %s\n", i, array[i].to_str());
00192                 }
00193         }
00194 }

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().

00123         {
00124             return verify_image_file_by_mode(filename, image_type, 1, datatype, nx, ny, nz);
00125         }

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().

00139         {
00140             return verify_image_file_by_mode(filename, image_type, 2,
00141                                                                                          datatype, nx, ny, nz);
00142         }

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, and EMAN::EMData::read_image().

Referenced by verify_image_file(), and verify_image_file2().

00598 {
00599         int err = 0;
00600 
00601         EMData * e = new EMData();
00602         e->read_image(filename);
00603 
00604         Dict attr_dict = e->get_attr_dict();
00605         bool is_complex = EMUtil::is_complex_type(datatype);
00606 
00607         if (is_complex) {
00608                 nx = (nx+2);
00609         }
00610 
00611         if (nx != (int) attr_dict["nx"]) {
00612         LOGERR("nx: %d != %d\n", nx, (int) attr_dict["nx"]);
00613         return 1;
00614     }
00615 
00616     if (ny != (int) attr_dict["ny"]) {
00617         LOGERR("ny: %d != %d\n", ny, (int) attr_dict["ny"]);
00618         return 1;
00619     }
00620 
00621     if (nz != (int) attr_dict["nz"]) {
00622         LOGERR("nz: %d != %d\n", nz, (int) attr_dict["nz"]);
00623         return 1;
00624     }
00625 
00626         if (datatype != (int) attr_dict["datatype"]) {
00627         LOGERR("datatype: %d != %d\n", datatype, (int) attr_dict["datatype"]);
00628         return 1;
00629     }
00630 
00631 
00632         if ((int)is_complex != (int) attr_dict["is_complex"]) {
00633         LOGERR("is_complex: %d != %d\n", is_complex, (int) attr_dict["is_complex"]);
00634         return 1;
00635     }
00636 
00637 
00638         if (!is_complex) {
00639                 float * data = e->get_data();
00640                 size_t l = 0;
00641                 for (int i = 0; i < nz; i++) {
00642                         for (int j = 0; j < ny; j++) {
00643                                 for (int k = 0; k < nx; k++) {
00644 
00645                     int d2 = 0;
00646                     if (mode == 1) {
00647                         d2 = (int)get_pixel_value_by_dist1(nx,ny,nz,k,j,i);
00648                     }
00649                     else if (mode == 2) {
00650                         d2 = (int)get_pixel_value_by_dist2(nx,ny,nz,k,j,i);
00651                     }
00652 
00653                                         if ((int)data[l] != d2) {
00654                         LOGERR("(%d,%d,%d): %d != %d\n", i,j,k,(int)data[l], d2);
00655                                                 break;
00656                                                 err = 1;
00657                                         }
00658                                         l++;
00659                                 }
00660                         }
00661                 }
00662         }
00663 
00664         return err;
00665 }


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]

Definition at line 148 of file testutil.h.

Referenced by emobject_farray_to_py(), get_debug_float(), test_dict(), test_FloatPoint(), test_FloatSize(), test_Vec3f(), test_vector_float(), and to_emobject().

int TestUtil::ti = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100} [static, private]

Definition at line 149 of file testutil.h.

Referenced by get_debug_int(), test_IntPoint(), test_IntSize(), test_Vec3i(), test_vector_int(), test_vector_long(), and to_emobject().


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 12:45:32 2013 for EMAN2 by  doxygen 1.4.7