00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef eman__testutil_h__
00037 #define eman__testutil_h__
00038
00039 #include "emdata.h"
00040
00041 using std::map;
00042 using std::vector;
00043 using std::string;
00044
00045 namespace EMAN
00046 {
00050 class Dict;
00051
00052 class TestUtil
00053 {
00054 public:
00055 static const char * EMDATA_HEADER_EXT;
00056 static const char * EMDATA_DATA_EXT;
00057
00058 static int get_debug_int(int i);
00059 static float get_debug_float(int i);
00060 static string get_debug_string(int i);
00061
00062 static string get_debug_image(const string & imagename);
00063 static string get_golden_image(const string & imagename);
00064
00065 static void to_emobject(const Dict & d);
00066
00067 static EMObject emobject_to_py(bool b);
00068 static EMObject emobject_to_py(unsigned int n);
00069 static EMObject emobject_to_py(int n);
00070 static EMObject emobject_to_py(float f);
00071 static EMObject emobject_to_py(double f);
00072 static EMObject emobject_to_py(const string& str);
00073 static EMObject emobject_to_py(EMData * emdata);
00074 static EMObject emobject_to_py(XYData * xydata);
00075 static EMObject emobject_farray_to_py();
00076 static EMObject emobject_strarray_to_py();
00077 static EMObject emobject_to_py(Transform * t);
00078 static EMObject emobject_to_py(Ctf * ctf_);
00079
00080 static IntPoint test_IntPoint(const IntPoint & p);
00081 static FloatPoint test_FloatPoint(const FloatPoint & p);
00082 static IntSize test_IntSize(const IntSize & p);
00083 static FloatSize test_FloatSize(const FloatSize & p);
00084 static Vec3i test_Vec3i(const Vec3i & p);
00085 static Vec3f test_Vec3f(const Vec3f & p);
00086
00087 static vector<int> test_vector_int(const vector<int> & v);
00088 static vector<float> test_vector_float(const vector<float> & v);
00089 static vector<long> test_vector_long(const vector<long> & v);
00090 static vector<string> test_vector_string(const vector<string> & v);
00091 static vector<EMData*> test_vector_emdata(const vector<EMData*> & v);
00092 static vector<Pixel> test_vector_pixel(const vector<Pixel> & v);
00093
00094 static map<string, int> test_map_int(const map<string, int>& d);
00095 static map<string, long> test_map_long(const map<string, long>& d);
00096 static map<string, float> test_map_float(const map<string, float>& d);
00097 static map<string, string> test_map_string(const map<string, string>& d);
00098 static map<string, EMObject> test_map_emobject(const map<string, EMObject>& d);
00099 static map<string, vector<string> > test_map_vecstring(const map<string,
00100 vector<string> >& d);
00101
00102 static Dict test_dict(const Dict & d);
00103
00104 static void dump_image_from_file(const string & filename);
00105 static void dump_emdata(EMData * image, const string & filename);
00106 static int check_image(const string& imagefile, EMData * image = 0);
00107 static void set_progname(const string & cur_progname);
00108
00109 static void make_image_file(const string & filename,
00110 EMUtil::ImageType image_type,
00111 EMUtil::EMDataType datatype = EMUtil::EM_FLOAT,
00112 int nx = 16, int ny = 16, int nz = 1)
00113 {
00114 make_image_file_by_mode(filename, image_type, 1, datatype, nx, ny, nz);
00115 }
00116
00117 static int verify_image_file(const string & filename,
00118 EMUtil::ImageType image_type,
00119 EMUtil::EMDataType datatype = EMUtil::EM_FLOAT,
00120 int nx = 16, int ny = 16, int nz = 1)
00121 {
00122 return verify_image_file_by_mode(filename, image_type, 1, datatype, nx, ny, nz);
00123 }
00124
00125 static void make_image_file2(const string & filename,
00126 EMUtil::ImageType image_type,
00127 EMUtil::EMDataType datatype = EMUtil::EM_FLOAT,
00128 int nx = 16, int ny = 16, int nz = 1)
00129 {
00130 make_image_file_by_mode(filename, image_type, 2, datatype,nx, ny, nz);
00131 }
00132
00133 static int verify_image_file2(const string & filename,
00134 EMUtil::ImageType image_type,
00135 EMUtil::EMDataType datatype = EMUtil::EM_FLOAT,
00136 int nx = 16, int ny = 16, int nz = 1)
00137 {
00138 return verify_image_file_by_mode(filename, image_type, 2,
00139 datatype, nx, ny, nz);
00140 }
00141
00142
00143
00144
00145 private:
00146 static float tf[10];
00147 static int ti[10];
00148 static string progname;
00149
00150 static void make_image_file_by_mode(const string & filename,
00151 EMUtil::ImageType image_type, int mode,
00152 EMUtil::EMDataType datatype = EMUtil::EM_FLOAT,
00153 int nx = 16, int ny = 16, int nz = 1);
00154
00155 static int verify_image_file_by_mode(const string & filename,
00156 EMUtil::ImageType image_type, int mode,
00157 EMUtil::EMDataType datatype = EMUtil::EM_FLOAT,
00158 int nx = 16, int ny = 16, int nz = 1);
00159
00160
00161 static float get_pixel_value_by_dist1(int nx, int ny, int nz, int x, int y, int z)
00162 {
00163 int x2 = x;
00164 int y2 = y;
00165 int z2 = z;
00166
00167 x2 = abs(nx/2-x);
00168 y2 = abs(ny/2-y);
00169
00170 if (z > nz/2) {
00171 z2 = nz-z;
00172 }
00173
00174 if (nz == 1) {
00175 return (float)(x2*x2 + y2*y2);
00176 }
00177 else {
00178 int areax = (int)((float)nx * z2 / nz);
00179 int areay = (int)((float)ny * z2 / nz);
00180 if ((abs(x-nx/2) <= areax) && (abs(y-ny/2) <= areay)) {
00181 return (float)(x2*x2 + y2*y2);
00182 }
00183 else {
00184 return 0;
00185 }
00186 }
00187 }
00188
00189 static float get_pixel_value_by_dist2(int nx, int ny, int nz, int x, int y, int z)
00190 {
00191 int x2 = x;
00192 int y2 = y;
00193 int z2 = z;
00194
00195
00196 if (x > nx/2) {
00197 x2 = nx-x;
00198 }
00199 if (y > ny/2) {
00200 y2 = ny-y;
00201 }
00202
00203 if (z > nz/2) {
00204 z2 = nz-z;
00205 }
00206
00207 if (nz == 1) {
00208 return (float)(x2*x2 + y2*y2);
00209 }
00210 else {
00211 int areax = (int)((float)nx * z2 / nz);
00212 int areay = (int)((float)ny * z2 / nz);
00213 if ((abs(x-nx/2) <= areax) && (abs(y-ny/2) <= areay)) {
00214 return (float)(x2*x2 + y2*y2);
00215 }
00216 else {
00217 return 0;
00218 }
00219 }
00220 }
00221 };
00222
00223
00224
00225
00226
00227 }
00228
00229 #endif //eman__testutil_h__
00230
00231