EMAN2
Static Public Member Functions | Static Public Attributes | Static Private Member Functions | Static Private Attributes | List of all members
EMAN::TestUtil Class Reference

#include <testutil.h>

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

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 48 of file testutil.h.

Member Function Documentation

◆ check_image()

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

Definition at line 409 of file testutil.cpp.

410{
411#if DEBUG
412 string headerfile1 = Util::sbasename(imagefile) + EMDATA_HEADER_EXT;
413 string datafile1 = Util::sbasename(imagefile) + EMDATA_DATA_EXT;
414
415 char imgpath[MAXPATHLEN];
416 char * path_env = getenv("DEBUG_IMAGE_PATH");
417 if (path_env) {
418 sprintf(imgpath, "%s/testdata/%s/", path_env, progname.c_str());
419 }
420 else {
421 sprintf(imgpath, "%s/images/testdata/%s/", getenv("HOME"), progname.c_str());
422 }
423
424 string headerfile2 = string(imgpath) + headerfile1;
425 string datafile2 = string(imgpath) + datafile1;
426
427
428 if (image) {
429 dump_emdata(image, imagefile);
430 }
431 else {
432 dump_image_from_file(imagefile);
433 }
434
435 if (!Util::is_file_exist(headerfile2) ||
436 !Util::is_file_exist(datafile2)) {
437 return 0;
438 }
439
440 string diffcmd1 = "diff " + headerfile1 + " " + headerfile2;
441
442 int err = system(diffcmd1.c_str());
443 if (!err) {
444 string diffcmd2 = "diff " + datafile1 + " " + datafile2;
445 err = system(diffcmd2.c_str());
446 }
447 if (err) {
448 LOGERR("check_image on %s FAILED\n", imagefile.c_str());
449 }
450
451 return err;
452#endif
453 return 0;
454}
static const char * EMDATA_HEADER_EXT
Definition: testutil.h:51
static void dump_image_from_file(const string &filename)
Definition: testutil.cpp:456
static const char * EMDATA_DATA_EXT
Definition: testutil.h:52
static void dump_emdata(EMData *image, const string &filename)
Definition: testutil.cpp:468
static string progname
Definition: testutil.h:146
static bool is_file_exist(const string &filename)
check whether a file exists or not
Definition: util.cpp:253
static string sbasename(const string &filename)
Get a filename's basename.
Definition: util.cpp:505
#define LOGERR
Definition: log.h:51

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

◆ dump_emdata()

void TestUtil::dump_emdata ( EMData image,
const string &  filename 
)
static

Definition at line 468 of file testutil.cpp.

469{
470 string filebase = Util::sbasename(filename);
471 string headerfile = filebase + EMDATA_HEADER_EXT;
472 string datafile = filebase + EMDATA_DATA_EXT;
473
474 FILE *hfile = fopen(headerfile.c_str(), "wb");
475 if (!hfile) {
476 throw FileAccessException(headerfile);
477 }
478#if 0
479 vector<string> excl_keys;
480 excl_keys.push_back("MRC.label");
481 excl_keys.push_back("IMAGIC.minute");
482 excl_keys.push_back("IMAGIC.sec");
483
484 Dict attr_dict = image->get_attr_dict();
485 vector < string > keys = attr_dict.keys();
486
487
488
489 for (size_t i = 0; i < keys.size(); i++) {
490
491 bool is_exclude = false;
492 for (size_t j = 0; j < excl_keys.size(); j++) {
493 if (Util::sstrncmp(keys[i].c_str(), excl_keys[j].c_str())) {
494 is_exclude = true;
495 break;
496 }
497 }
498 if (!is_exclude) {
499 fprintf(hfile, "%s = %s\n", keys[i].c_str(),
500 attr_dict[keys[i]].to_str().c_str());
501 }
502 }
503#endif
504
505 fprintf(hfile, "nx = %d\n", image->get_xsize());
506 fprintf(hfile, "ny = %d\n", image->get_ysize());
507 fprintf(hfile, "nz = %d\n", image->get_zsize());
508
509 fclose(hfile);
510 hfile = 0;
511
512 FILE *dfile = fopen(datafile.c_str(), "wb");
513 if (!dfile) {
514 throw FileAccessException(datafile);
515 }
516
517 int nx = image->get_xsize();
518 int ny = image->get_ysize();
519 int nz = image->get_zsize();
520
521 size_t row_size = nx * sizeof(float);
522 size_t nxy = nx * ny;
523 float * rdata = image->get_data();
524
525 for (int i = 0; i < nz; i++) {
526 for (int j = 0; j < ny; j++) {
527 fwrite(&rdata[i * nxy + j * nx], row_size, 1, dfile);
528 }
529 }
530 fclose(dfile);
531 dfile = 0;
532}
#define rdata(i)
Definition: analyzer.cpp:592
Dict is a dictionary to store <string, EMObject> pair.
Definition: emobject.h:385
vector< string > keys() const
Get a vector containing all of the (string) keys in this dictionary.
Definition: emobject.h:475
static bool sstrncmp(const char *s1, const char *s2)
Safe string compare.
Definition: util.cpp:306
#define FileAccessException(filename)
Definition: exception.h:187
const char * to_str(Gatan::TagData::Type type)
Definition: dm3io.cpp:925

References EMDATA_DATA_EXT, EMDATA_HEADER_EXT, FileAccessException, EMAN::Dict::keys(), rdata, EMAN::Util::sbasename(), EMAN::Util::sstrncmp(), and EMAN::Gatan::to_str().

Referenced by check_image(), and dump_image_from_file().

◆ dump_image_from_file()

void TestUtil::dump_image_from_file ( const string &  filename)
static

Definition at line 456 of file testutil.cpp.

457{
458 EMData * e = new EMData();
459 e->read_image(filename);
460 dump_emdata(e, filename);
461 if( e )
462 {
463 delete e;
464 e = 0;
465 }
466}
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82

References dump_emdata().

Referenced by check_image().

◆ emobject_farray_to_py()

EMObject TestUtil::emobject_farray_to_py ( )
static

Definition at line 706 of file testutil.cpp.

707{
708 vector<float> v(3);
709 for (int i = 0; i < 3; i++) {
710 v[i] = tf[i];
711 }
712 return EMObject(v);
713}
EMObject is a wrapper class for types including int, float, double, etc as defined in ObjectType.
Definition: emobject.h:123
static float tf[10]
Definition: testutil.h:144

References tf.

◆ emobject_strarray_to_py()

EMObject TestUtil::emobject_strarray_to_py ( )
static

Definition at line 716 of file testutil.cpp.

717{
718 vector<string> v(3);
719 for (int i = 0; i < 3; i++) {
720 v[i] = get_debug_string(i);
721 }
722 return EMObject(v);
723}
static string get_debug_string(int i)
Definition: testutil.cpp:70

References get_debug_string().

◆ emobject_to_py() [1/10]

EMObject TestUtil::emobject_to_py ( bool  b)
static

Definition at line 663 of file testutil.cpp.

664{
665 return EMObject(b);
666}

◆ emobject_to_py() [2/10]

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

Definition at line 688 of file testutil.cpp.

689{
690 return EMObject(str);
691}

◆ emobject_to_py() [3/10]

EMObject TestUtil::emobject_to_py ( Ctf ctf_)
static

Definition at line 741 of file testutil.cpp.

742{
743 return EMObject(ctf_);
744}

◆ emobject_to_py() [4/10]

EMObject TestUtil::emobject_to_py ( double  f)
static

Definition at line 683 of file testutil.cpp.

684{
685 return EMObject(f);
686}

◆ emobject_to_py() [5/10]

EMObject TestUtil::emobject_to_py ( EMData emdata)
static

Definition at line 694 of file testutil.cpp.

695{
696 return EMObject(emdata);
697}

◆ emobject_to_py() [6/10]

EMObject TestUtil::emobject_to_py ( float  f)
static

Definition at line 678 of file testutil.cpp.

679{
680 return EMObject(f);
681}

◆ emobject_to_py() [7/10]

EMObject TestUtil::emobject_to_py ( int  n)
static

Definition at line 673 of file testutil.cpp.

674{
675 return EMObject(n);
676}

◆ emobject_to_py() [8/10]

EMObject TestUtil::emobject_to_py ( Transform t)
static

Definition at line 736 of file testutil.cpp.

737{
738 return EMObject(t);
739}

◆ emobject_to_py() [9/10]

EMObject TestUtil::emobject_to_py ( unsigned int  n)
static

Definition at line 668 of file testutil.cpp.

669{
670 return EMObject(un);
671}

◆ emobject_to_py() [10/10]

EMObject TestUtil::emobject_to_py ( XYData xydata)
static

Definition at line 700 of file testutil.cpp.

701{
702 return EMObject(xydata);
703}

◆ emobject_transformarray_to_py()

EMObject TestUtil::emobject_transformarray_to_py ( )
static

Definition at line 725 of file testutil.cpp.

726{
727 vector<Transform> v(3);
728 for (int i=0; i<3; i++) {
729 Transform t;
730 t.set_trans(i, i+1, i+2);
731 v[i] = t;
732 }
733 return EMObject(v);
734}
A Transform object is a somewhat specialized object designed specifically for EMAN2/Sparx storage of ...
Definition: transform.h:75
void set_trans(const float &x, const float &y, const float &z=0)
Set the post translation component.
Definition: transform.cpp:1036

References EMAN::Transform::set_trans().

◆ get_debug_float()

float TestUtil::get_debug_float ( int  i)
static

Definition at line 65 of file testutil.cpp.

66{
67 return tf[i];
68}

References tf.

◆ get_debug_image()

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

Definition at line 88 of file testutil.cpp.

89{
90 char imgpath[MAXPATHLEN];
91 char * path_env = getenv("DEBUG_IMAGE_PATH");
92 if (path_env) {
93 sprintf(imgpath, "%s/%s", path_env, imagename.c_str());
94 }
95 else {
96 sprintf(imgpath, "%s/images/%s", getenv("HOME"), imagename.c_str());
97 }
98 return string(imgpath);
99}

◆ get_debug_int()

int TestUtil::get_debug_int ( int  i)
static

Definition at line 60 of file testutil.cpp.

61{
62 return ti[i];
63}
static int ti[10]
Definition: testutil.h:145

References ti.

◆ get_debug_string()

string TestUtil::get_debug_string ( int  i)
static

Definition at line 70 of file testutil.cpp.

71{
72 char a[32];
73 sprintf(a, "%d%d", i+1, i+1);
74 return string(a);
75}

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

◆ get_debug_transform()

Transform TestUtil::get_debug_transform ( int  i)
static

Definition at line 77 of file testutil.cpp.

78{
79 vector<Transform> v(3);
80 for (int j=0; j<3; j++) {
81 Transform t;
82 t.set_trans(j, j+1, j+2);
83 v[j] = t;
84 }
85 return v[i];
86}

References EMAN::Transform::set_trans().

Referenced by to_emobject().

◆ get_golden_image()

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

Definition at line 101 of file testutil.cpp.

102{
103 char imgpath[MAXPATHLEN];
104 char * path_env = getenv("DEBUG_IMAGE_PATH");
105 if (path_env) {
106 sprintf(imgpath, "%s/testdata/%s", path_env, imagename.c_str());
107 }
108 else {
109 sprintf(imgpath, "%s/images/testdata/%s", getenv("HOME"), imagename.c_str());
110 }
111 return string(imgpath);
112}

◆ get_pixel_value_by_dist1()

static float EMAN::TestUtil::get_pixel_value_by_dist1 ( int  nx,
int  ny,
int  nz,
int  x,
int  y,
int  z 
)
inlinestaticprivate

Definition at line 159 of file testutil.h.

160 {
161 int x2 = x;
162 int y2 = y;
163 int z2 = z;
164
165 x2 = abs(nx/2-x);
166 y2 = abs(ny/2-y);
167
168 if (z > nz/2) {
169 z2 = nz-z;
170 }
171
172 if (nz == 1) {
173 return (float)(x2*x2 + y2*y2);
174 }
175 else {
176 int areax = (int)((float)nx * z2 / nz);
177 int areay = (int)((float)ny * z2 / nz);
178 if ((abs(x-nx/2) <= areax) && (abs(y-ny/2) <= areay)) {
179 return (float)(x2*x2 + y2*y2);
180 }
181 else {
182 return 0;
183 }
184 }
185 }
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517

References x, and y.

Referenced by make_image_file_by_mode(), and verify_image_file_by_mode().

◆ get_pixel_value_by_dist2()

static float EMAN::TestUtil::get_pixel_value_by_dist2 ( int  nx,
int  ny,
int  nz,
int  x,
int  y,
int  z 
)
inlinestaticprivate

Definition at line 187 of file testutil.h.

188 {
189 int x2 = x;
190 int y2 = y;
191 int z2 = z;
192
193
194 if (x > nx/2) {
195 x2 = nx-x;
196 }
197 if (y > ny/2) {
198 y2 = ny-y;
199 }
200
201 if (z > nz/2) {
202 z2 = nz-z;
203 }
204
205 if (nz == 1) {
206 return (float)(x2*x2 + y2*y2);
207 }
208 else {
209 int areax = (int)((float)nx * z2 / nz);
210 int areay = (int)((float)ny * z2 / nz);
211 if ((abs(x-nx/2) <= areax) && (abs(y-ny/2) <= areay)) {
212 return (float)(x2*x2 + y2*y2);
213 }
214 else {
215 return 0;
216 }
217 }
218 }

References x, and y.

Referenced by make_image_file_by_mode(), and verify_image_file_by_mode().

◆ make_image_file()

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 
)
inlinestatic

Definition at line 107 of file testutil.h.

111 {
112 make_image_file_by_mode(filename, image_type, 1, datatype, nx, ny, nz);
113 }
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)
Definition: testutil.cpp:540

References make_image_file_by_mode().

◆ make_image_file2()

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 
)
inlinestatic

Definition at line 123 of file testutil.h.

127 {
128 make_image_file_by_mode(filename, image_type, 2, datatype,nx, ny, nz);
129 }

References make_image_file_by_mode().

◆ make_image_file_by_mode()

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 
)
staticprivate

Definition at line 540 of file testutil.cpp.

544{
545 EMData * e = new EMData();
546 e->set_size(nx, ny, nz);
547 bool is_complex = EMUtil::is_complex_type(datatype);
548
549 e->set_attr("is_complex", (int)is_complex);
550 e->set_attr("datatype", (int)datatype);
551 float * data = e->get_data();
552
553 size_t l = 0;
554 for (int i = 0; i < nz; i++) {
555 for (int j = 0; j < ny; j++) {
556 for (int k = 0; k < nx; k++) {
557 if (mode == 1) {
558 data[l] = get_pixel_value_by_dist1(nx, ny, nz, k, j, i);
559 }
560 else if (mode == 2) {
561 data[l] = get_pixel_value_by_dist2(nx, ny, nz, k, j, i);
562 }
563 l++;
564 }
565 }
566 }
567
568 if (!is_complex) {
569 e->write_image(filename, 0, image_type, false, 0, datatype, true);
570 }
571 else {
572 e->update();
573 e->set_attr("is_complex", false);
574 EMData * fft = e->do_fft();
575 fft->write_image(filename, 0, image_type, false, 0, datatype, true);
576 if( fft )
577 {
578 delete fft;
579 fft = 0;
580 }
581 }
582
583 if( e )
584 {
585 delete e;
586 e = 0;
587 }
588}
static bool is_complex_type(EMDataType datatype)
Definition: emutil.cpp:1231
static float get_pixel_value_by_dist2(int nx, int ny, int nz, int x, int y, int z)
Definition: testutil.h:187
static float get_pixel_value_by_dist1(int nx, int ny, int nz, int x, int y, int z)
Definition: testutil.h:159
bool is_complex() const
Is this a complex image?

References get_pixel_value_by_dist1(), get_pixel_value_by_dist2(), is_complex(), and EMAN::EMUtil::is_complex_type().

Referenced by make_image_file(), and make_image_file2().

◆ set_progname()

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

Definition at line 534 of file testutil.cpp.

535{
536 progname = Util::sbasename(cur_progname);
537}

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

◆ test_dict()

Dict TestUtil::test_dict ( const Dict d)
static

Definition at line 391 of file testutil.cpp.

392{
393 Dict r;
394
395 vector<string> keys = d.keys();
396 sort(keys.begin(), keys.end());
397
398 for (size_t i = 0; i < keys.size(); i++) {
399 LOGDEBUG("keys[%s] = %f\n", keys[i].c_str(), (float)d[keys[i]]);
400 Assert(keys[i] == get_debug_string(i));
401 Assert(((float)d[keys[i]]) == tf[i]);
402 r[keys[i]] = d[keys[i]];
403 }
404
405 return r;
406}
#define Assert(s)
Define Assert() function that is effective only when -DDEBUG is used.
Definition: emassert.h:42
#define LOGDEBUG
Definition: log.h:55

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

◆ test_FloatPoint()

FloatPoint TestUtil::test_FloatPoint ( const FloatPoint p)
static

Definition at line 202 of file testutil.cpp.

203{
204 Assert(p[0] == tf[0]);
205 Assert(p[1] == tf[1]);
206 Assert(p[2] == tf[2]);
207 LOGDEBUG("FloatPoint p = (%f, %f, %f)\n", p[0], p[1], p[2]);
208 return FloatPoint(tf[0], tf[1], tf[2]);
209}
FloatPoint defines a float-coordinate point in a 1D/2D/3D space.
Definition: geometry.h:278

References Assert, LOGDEBUG, and tf.

◆ test_FloatSize()

FloatSize TestUtil::test_FloatSize ( const FloatSize p)
static

Definition at line 222 of file testutil.cpp.

223{
224 Assert(p[0] == tf[0]);
225 Assert(p[1] == tf[1]);
226 Assert(p[2] == tf[2]);
227 LOGDEBUG("FloatSize p = (%f, %f, %f)\n", p[0], p[1], p[2]);
228 return FloatSize(tf[0], tf[1], tf[2]);
229}
FloatSize is used to describe a 1D, 2D or 3D rectangular size in floating numbers.
Definition: geometry.h:105

References Assert, LOGDEBUG, and tf.

◆ test_IntPoint()

IntPoint TestUtil::test_IntPoint ( const IntPoint p)
static

Definition at line 193 of file testutil.cpp.

194{
195 Assert(p[0] == ti[0]);
196 Assert(p[1] == ti[1]);
197 Assert(p[2] == ti[2]);
198 LOGDEBUG("IntPoint p = (%d, %d, %d)\n", p[0], p[1], p[2]);
199 return IntPoint(ti[0], ti[1], ti[2]);
200}
IntPoint defines an integer-coordinate point in a 1D/2D/3D space.
Definition: geometry.h:192

References Assert, LOGDEBUG, and ti.

◆ test_IntSize()

IntSize TestUtil::test_IntSize ( const IntSize p)
static

Definition at line 212 of file testutil.cpp.

213{
214 Assert(p[0] == ti[0]);
215 Assert(p[1] == ti[1]);
216 Assert(p[2] == ti[2]);
217 LOGDEBUG("IntSize p = (%d, %d, %d)\n", p[0], p[1], p[2]);
218 return IntSize(ti[0], ti[1], ti[2]);
219}
IntSize is used to describe a 1D, 2D or 3D rectangular size in integers.
Definition: geometry.h:49

References Assert, LOGDEBUG, and ti.

◆ test_map_emobject()

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

Definition at line 299 of file testutil.cpp.

300{
301 map<string, EMObject> r;
302 map<string, EMObject>::const_iterator p;
303 for (p = d.begin(); p != d.end(); p++) {
304 LOGDEBUG("map[\"%s\"] = %f; ", p->first.c_str(), (float)(p->second));
305 r[p->first] = EMObject(p->second);
306 }
307 LOGDEBUG("\n");
308 return r;
309}

References LOGDEBUG.

◆ test_map_float()

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

Definition at line 275 of file testutil.cpp.

276{
277 map<string, float> r;
278 map<string, float>::const_iterator p;
279 for (p = d.begin(); p != d.end(); p++) {
280 LOGDEBUG("map[\"%s\"] = %f; ", p->first.c_str(), p->second);
281 r[p->first] = p->second;
282 }
283 LOGDEBUG("\n");
284 return r;
285}

References LOGDEBUG.

◆ test_map_int()

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

Definition at line 251 of file testutil.cpp.

252{
253 map<string, int> r;
254 map<string, int>::const_iterator p;
255 for (p = d.begin(); p != d.end(); p++) {
256 LOGDEBUG("map[\"%s\"] = %d; ", p->first.c_str(), p->second);
257 r[p->first] = p->second;
258 }
259 LOGDEBUG("\n");
260 return r;
261}

References LOGDEBUG.

◆ test_map_long()

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

Definition at line 263 of file testutil.cpp.

264{
265 map<string, long> r;
266 map<string, long>::const_iterator p;
267 for (p = d.begin(); p != d.end(); p++) {
268 LOGDEBUG("map[\"%s\"] = %d; ", p->first.c_str(), p->second);
269 r[p->first] = p->second;
270 }
271 LOGDEBUG("\n");
272 return r;
273}

References LOGDEBUG.

◆ test_map_string()

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

Definition at line 287 of file testutil.cpp.

288{
289 map<string, string> r;
290 map<string, string>::const_iterator p;
291 for (p = d.begin(); p != d.end(); p++) {
292 LOGDEBUG("map[\"%s\"] = %s; ", p->first.c_str(), p->second.c_str());
293 r[p->first] = p->second;
294 }
295 LOGDEBUG("\n");
296 return r;
297}

References LOGDEBUG.

◆ test_map_vecstring()

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

Definition at line 311 of file testutil.cpp.

313{
314 map<string, vector<string> > r;
315 return r;
316}

◆ test_Vec3f()

Vec3f TestUtil::test_Vec3f ( const Vec3f p)
static

Definition at line 241 of file testutil.cpp.

242{
243 Assert(p[0] == tf[0]);
244 Assert(p[1] == tf[1]);
245 Assert(p[2] == tf[2]);
246 LOGDEBUG("Vec3f p = (%f, %f, %f)\n", p[0], p[1], p[2]);
247 return Vec3f(tf[0], tf[1], tf[2]);
248}
Vec3< float > Vec3f
Definition: vec3.h:693

References Assert, LOGDEBUG, and tf.

◆ test_Vec3i()

Vec3i TestUtil::test_Vec3i ( const Vec3i p)
static

Definition at line 232 of file testutil.cpp.

233{
234 Assert(p[0] == ti[0]);
235 Assert(p[1] == ti[1]);
236 Assert(p[2] == ti[2]);
237 LOGDEBUG("Vec3i p = (%d, %d, %d)\n", p[0], p[1], p[2]);
238 return Vec3i(ti[0], ti[1], ti[2]);
239}
Vec3< int > Vec3i
Definition: vec3.h:694

References Assert, LOGDEBUG, and ti.

◆ test_vector_emdata()

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

Definition at line 366 of file testutil.cpp.

367{
368 vector<EMData*> r;
369 for (size_t i = 0; i < v.size(); i++) {
370 EMData * e = v[i];
371 LOGDEBUG("Image(%d,%d,%d); ", e->get_xsize(), e->get_ysize(), e->get_zsize());
372 r.push_back(v[i]);
373 }
374 LOGDEBUG("\n");
375 return r;
376}

References LOGDEBUG.

◆ test_vector_float()

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

Definition at line 331 of file testutil.cpp.

332{
333 vector<float> r;
334 for (size_t i = 0; i < v.size(); i++) {
335 LOGDEBUG("v[%d]=%f; ", i, v[i]);
336 Assert(v[i] == tf[i]);
337 r.push_back(v[i]);
338 }
339 LOGDEBUG("\n");
340 return r;
341}

References Assert, LOGDEBUG, and tf.

◆ test_vector_int()

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

Definition at line 319 of file testutil.cpp.

320{
321 vector<int> r;
322 for (size_t i = 0; i < v.size(); i++) {
323 LOGDEBUG("v[%d]=%d; ", i, v[i]);
324 Assert(v[i] == ti[i]);
325 r.push_back(v[i]);
326 }
327 LOGDEBUG("\n");
328 return r;
329}

References Assert, LOGDEBUG, and ti.

◆ test_vector_long()

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

Definition at line 343 of file testutil.cpp.

344{
345 vector<long> r;
346 for (size_t i = 0; i < v.size(); i++) {
347 LOGDEBUG("v[%d]=%d; ", i, (int)v[i]);
348 Assert((int)v[i] == ti[i]);
349 r.push_back(v[i]);
350 }
351 LOGDEBUG("\n");
352 return r;
353}

References Assert, LOGDEBUG, and ti.

◆ test_vector_pixel()

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

Definition at line 378 of file testutil.cpp.

379{
380 vector<Pixel> r;
381 for (size_t i = 0; i < v.size(); i++) {
382 Pixel p = v[i];
383 LOGDEBUG("Pixel(%d,%d,%d)=%4.2f; ", p.x, p.y, p.z, p.value);
384 Pixel p2(p.x, p.y, p.z, p.value);
385 r.push_back(p2);
386 }
387
388 return r;
389}
Pixel describes a 3D pixel's coordinates and its intensity value.
Definition: geometry.h:452
float value
Definition: geometry.h:483

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

◆ test_vector_string()

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

Definition at line 355 of file testutil.cpp.

356{
357 vector<string> r;
358 for (size_t i = 0; i < v.size(); i++) {
359 LOGDEBUG("v[%d]=%s; ", i, v[i].c_str());
360 r.push_back(v[i]);
361 }
362 LOGDEBUG("\n");
363 return r;
364}

References LOGDEBUG.

◆ to_emobject()

void TestUtil::to_emobject ( const Dict d)
static

Definition at line 114 of file testutil.cpp.

115{
116 if (d.has_key("floatarray")) {
117 vector<float> array = d["floatarray"];
118 for (size_t i = 0; i < array.size(); i++) {
119 Assert(array[i] == tf[i]);
120 LOGDEBUG("floatarray[%d] = %f\n", i, array[i]);
121 }
122 }
123
124 if (d.has_key("emdata")) {
125 EMData * img = d["emdata"];
126 if (img) {
127 int nx = img->get_xsize();
128 int ny = img->get_ysize();
129 int nz = img->get_zsize();
130 Assert(nx == ti[0]);
131 Assert(ny == ti[1]);
132 Assert(nz == ti[2]);
133 LOGDEBUG("image size = (%d, %d, %d)\n", nx, ny, nz);
134 }
135 }
136
137 if (d.has_key("int")) {
138 int n = d["int"];
139 Assert(n == ti[0]);
140 LOGDEBUG("int n = %d\n", n);
141 }
142
143 if (d.has_key("float")) {
144 float f = d["float"];
145 Assert(f == tf[0]);
146 LOGDEBUG("float f = %f\n", f);
147 }
148
149 if (d.has_key("long")) {
150 int l = (int)d["long"];
151 Assert(l == ti[0]);
152 LOGDEBUG("long l = %d\n", l);
153 }
154
155 if (d.has_key("string")) {
156 string s = (const char*)d["string"];
157 string s2 = get_debug_string(0);
158 Assert(s == s2);
159 }
160
161
162 if (d.has_key("xydata")) {
163 XYData *xyd = d["xydata"];
164 size_t nitems = xyd->get_size();
165 for (size_t i = 0; i < nitems; i++) {
166 float xi = xyd->get_x(i);
167 float yi = xyd->get_y(i);
168 LOGDEBUG("xydata[%d] = (%f,%f)\n", i, xi, yi);
169 Assert(xi == tf[i]);
170 Assert(yi == tf[i]);
171 }
172 }
173
174 if (d.has_key("stringarray")) {
175 vector<string> array = d["stringarray"];
176 for (size_t i = 0; i < array.size(); i++) {
177 Assert(array[i] == get_debug_string(i));
178 LOGDEBUG("stringarray[%d] = %s\n", i, array[i].c_str());
179 }
180 }
181
182 if (d.has_key("transformarray")) {
183 vector<Transform> array = d["transformarray"];
184 for (size_t i = 0; i < array.size(); i++) {
185// array[i].printme();
186 Assert(array[i] == get_debug_transform(i));
187// LOGDEBUG("transformarray[%d] = %s\n", i, array[i].to_str());
188 }
189 }
190}
bool has_key(const string &key) const
Ask the Dictionary if it as a particular key.
Definition: emobject.h:511
static Transform get_debug_transform(int i)
Definition: testutil.cpp:77
XYData defines a 1D (x,y) data set.
Definition: xydata.h:47
size_t get_size() const
Definition: xydata.h:127
float get_y(size_t i) const
Definition: xydata.h:95
float get_x(size_t i) const
Definition: xydata.h:84

References Assert, get_debug_string(), get_debug_transform(), EMAN::XYData::get_size(), EMAN::XYData::get_x(), EMAN::XYData::get_y(), EMAN::Dict::has_key(), LOGDEBUG, tf, and ti.

◆ verify_image_file()

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 
)
inlinestatic

Definition at line 115 of file testutil.h.

119 {
120 return verify_image_file_by_mode(filename, image_type, 1, datatype, nx, ny, nz);
121 }
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)
Definition: testutil.cpp:590

References verify_image_file_by_mode().

◆ verify_image_file2()

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 
)
inlinestatic

Definition at line 131 of file testutil.h.

135 {
136 return verify_image_file_by_mode(filename, image_type, 2,
137 datatype, nx, ny, nz);
138 }

References verify_image_file_by_mode().

◆ verify_image_file_by_mode()

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 
)
staticprivate

Definition at line 590 of file testutil.cpp.

594{
595 int err = 0;
596
597 EMData * e = new EMData();
598 e->read_image(filename);
599
600 Dict attr_dict = e->get_attr_dict();
601 bool is_complex = EMUtil::is_complex_type(datatype);
602
603 if (is_complex) {
604 nx = (nx+2);
605 }
606
607 if (nx != (int) attr_dict["nx"]) {
608 LOGERR("nx: %d != %d\n", nx, (int) attr_dict["nx"]);
609 return 1;
610 }
611
612 if (ny != (int) attr_dict["ny"]) {
613 LOGERR("ny: %d != %d\n", ny, (int) attr_dict["ny"]);
614 return 1;
615 }
616
617 if (nz != (int) attr_dict["nz"]) {
618 LOGERR("nz: %d != %d\n", nz, (int) attr_dict["nz"]);
619 return 1;
620 }
621
622 if (datatype != (int) attr_dict["datatype"]) {
623 LOGERR("datatype: %d != %d\n", datatype, (int) attr_dict["datatype"]);
624 return 1;
625 }
626
627
628 if ((int)is_complex != (int) attr_dict["is_complex"]) {
629 LOGERR("is_complex: %d != %d\n", is_complex, (int) attr_dict["is_complex"]);
630 return 1;
631 }
632
633
634 if (!is_complex) {
635 float * data = e->get_data();
636 size_t l = 0;
637 for (int i = 0; i < nz; i++) {
638 for (int j = 0; j < ny; j++) {
639 for (int k = 0; k < nx; k++) {
640
641 int d2 = 0;
642 if (mode == 1) {
643 d2 = (int)get_pixel_value_by_dist1(nx,ny,nz,k,j,i);
644 }
645 else if (mode == 2) {
646 d2 = (int)get_pixel_value_by_dist2(nx,ny,nz,k,j,i);
647 }
648
649 if ((int)data[l] != d2) {
650 LOGERR("(%d,%d,%d): %d != %d\n", i,j,k,(int)data[l], d2);
651 break;
652 err = 1;
653 }
654 l++;
655 }
656 }
657 }
658 }
659
660 return err;
661}

References get_pixel_value_by_dist1(), get_pixel_value_by_dist2(), is_complex(), EMAN::EMUtil::is_complex_type(), and LOGERR.

Referenced by verify_image_file(), and verify_image_file2().

Member Data Documentation

◆ EMDATA_DATA_EXT

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

Definition at line 52 of file testutil.h.

Referenced by check_image(), and dump_emdata().

◆ EMDATA_HEADER_EXT

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

Definition at line 51 of file testutil.h.

Referenced by check_image(), and dump_emdata().

◆ progname

string TestUtil::progname = ""
staticprivate

Definition at line 146 of file testutil.h.

Referenced by check_image(), and set_progname().

◆ tf

float TestUtil::tf = {1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5}
staticprivate

◆ ti

int TestUtil::ti = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100}
staticprivate

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