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 static Transform get_debug_transform(int i);
00062
00063 static string get_debug_image(const string & imagename);
00064 static string get_golden_image(const string & imagename);
00065
00066 static void to_emobject(const Dict & d);
00067
00068 static EMObject emobject_to_py(bool b);
00069 static EMObject emobject_to_py(unsigned int n);
00070 static EMObject emobject_to_py(int n);
00071 static EMObject emobject_to_py(float f);
00072 static EMObject emobject_to_py(double f);
00073 static EMObject emobject_to_py(const string& str);
00074 static EMObject emobject_to_py(EMData * emdata);
00075 static EMObject emobject_to_py(XYData * xydata);
00076 static EMObject emobject_farray_to_py();
00077 static EMObject emobject_strarray_to_py();
00078 static EMObject emobject_transformarray_to_py();
00079 static EMObject emobject_to_py(Transform * t);
00080 static EMObject emobject_to_py(Ctf * ctf_);
00081
00082 static IntPoint test_IntPoint(const IntPoint & p);
00083 static FloatPoint test_FloatPoint(const FloatPoint & p);
00084 static IntSize test_IntSize(const IntSize & p);
00085 static FloatSize test_FloatSize(const FloatSize & p);
00086 static Vec3i test_Vec3i(const Vec3i & p);
00087 static Vec3f test_Vec3f(const Vec3f & p);
00088
00089 static vector<int> test_vector_int(const vector<int> & v);
00090 static vector<float> test_vector_float(const vector<float> & v);
00091 static vector<long> test_vector_long(const vector<long> & v);
00092 static vector<string> test_vector_string(const vector<string> & v);
00093 static vector<EMData*> test_vector_emdata(const vector<EMData*> & v);
00094 static vector<Pixel> test_vector_pixel(const vector<Pixel> & v);
00095
00096 static map<string, int> test_map_int(const map<string, int>& d);
00097 static map<string, long> test_map_long(const map<string, long>& d);
00098 static map<string, float> test_map_float(const map<string, float>& d);
00099 static map<string, string> test_map_string(const map<string, string>& d);
00100 static map<string, EMObject> test_map_emobject(const map<string, EMObject>& d);
00101 static map<string, vector<string> > test_map_vecstring(const map<string,
00102 vector<string> >& d);
00103
00104 static Dict test_dict(const Dict & d);
00105
00106 static void dump_image_from_file(const string & filename);
00107 static void dump_emdata(EMData * image, const string & filename);
00108 static int check_image(const string& imagefile, EMData * image = 0);
00109 static void set_progname(const string & cur_progname);
00110
00111 static void make_image_file(const string & filename,
00112 EMUtil::ImageType image_type,
00113 EMUtil::EMDataType datatype = EMUtil::EM_FLOAT,
00114 int nx = 16, int ny = 16, int nz = 1)
00115 {
00116 make_image_file_by_mode(filename, image_type, 1, datatype, nx, ny, nz);
00117 }
00118
00119 static int verify_image_file(const string & filename,
00120 EMUtil::ImageType image_type,
00121 EMUtil::EMDataType datatype = EMUtil::EM_FLOAT,
00122 int nx = 16, int ny = 16, int nz = 1)
00123 {
00124 return verify_image_file_by_mode(filename, image_type, 1, datatype, nx, ny, nz);
00125 }
00126
00127 static void make_image_file2(const string & filename,
00128 EMUtil::ImageType image_type,
00129 EMUtil::EMDataType datatype = EMUtil::EM_FLOAT,
00130 int nx = 16, int ny = 16, int nz = 1)
00131 {
00132 make_image_file_by_mode(filename, image_type, 2, datatype,nx, ny, nz);
00133 }
00134
00135 static int verify_image_file2(const string & filename,
00136 EMUtil::ImageType image_type,
00137 EMUtil::EMDataType datatype = EMUtil::EM_FLOAT,
00138 int nx = 16, int ny = 16, int nz = 1)
00139 {
00140 return verify_image_file_by_mode(filename, image_type, 2,
00141 datatype, nx, ny, nz);
00142 }
00143
00144
00145
00146
00147 private:
00148 static float tf[10];
00149 static int ti[10];
00150 static string progname;
00151
00152 static void make_image_file_by_mode(const string & filename,
00153 EMUtil::ImageType image_type, int mode,
00154 EMUtil::EMDataType datatype = EMUtil::EM_FLOAT,
00155 int nx = 16, int ny = 16, int nz = 1);
00156
00157 static int verify_image_file_by_mode(const string & filename,
00158 EMUtil::ImageType image_type, int mode,
00159 EMUtil::EMDataType datatype = EMUtil::EM_FLOAT,
00160 int nx = 16, int ny = 16, int nz = 1);
00161
00162
00163 static float get_pixel_value_by_dist1(int nx, int ny, int nz, int x, int y, int z)
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 }
00190
00191 static float get_pixel_value_by_dist2(int nx, int ny, int nz, int x, int y, int z)
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 }
00223 };
00224
00225
00226
00227
00228
00229 }
00230
00231 #endif //eman__testutil_h__
00232
00233