EMAN2
testutil.h
Go to the documentation of this file.
1/*
2 * Author: Liwei Peng, 12/16/2004 (sludtke@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
32#ifndef eman__testutil_h__
33#define eman__testutil_h__
34
35#include "emdata.h"
36
37using std::map;
38using std::vector;
39using std::string;
40
41namespace EMAN
42{
46 class Dict;
47
49 {
50 public:
51 static const char * EMDATA_HEADER_EXT;
52 static const char * EMDATA_DATA_EXT;
53
54 static int get_debug_int(int i);
55 static float get_debug_float(int i);
56 static string get_debug_string(int i);
57 static Transform get_debug_transform(int i);
58
59 static string get_debug_image(const string & imagename);
60 static string get_golden_image(const string & imagename);
61
62 static void to_emobject(const Dict & d);
63
64 static EMObject emobject_to_py(bool b);
65 static EMObject emobject_to_py(unsigned int n);
66 static EMObject emobject_to_py(int n);
67 static EMObject emobject_to_py(float f);
68 static EMObject emobject_to_py(double f);
69 static EMObject emobject_to_py(const string& str);
70 static EMObject emobject_to_py(EMData * emdata);
71 static EMObject emobject_to_py(XYData * xydata);
76 static EMObject emobject_to_py(Ctf * ctf_);
77
78 static IntPoint test_IntPoint(const IntPoint & p);
79 static FloatPoint test_FloatPoint(const FloatPoint & p);
80 static IntSize test_IntSize(const IntSize & p);
81 static FloatSize test_FloatSize(const FloatSize & p);
82 static Vec3i test_Vec3i(const Vec3i & p);
83 static Vec3f test_Vec3f(const Vec3f & p);
84
85 static vector<int> test_vector_int(const vector<int> & v);
86 static vector<float> test_vector_float(const vector<float> & v);
87 static vector<long> test_vector_long(const vector<long> & v);
88 static vector<string> test_vector_string(const vector<string> & v);
89 static vector<EMData*> test_vector_emdata(const vector<EMData*> & v);
90 static vector<Pixel> test_vector_pixel(const vector<Pixel> & v);
91
92 static map<string, int> test_map_int(const map<string, int>& d);
93 static map<string, long> test_map_long(const map<string, long>& d);
94 static map<string, float> test_map_float(const map<string, float>& d);
95 static map<string, string> test_map_string(const map<string, string>& d);
96 static map<string, EMObject> test_map_emobject(const map<string, EMObject>& d);
97 static map<string, vector<string> > test_map_vecstring(const map<string,
98 vector<string> >& d);
99
100 static Dict test_dict(const Dict & d);
101
102 static void dump_image_from_file(const string & filename);
103 static void dump_emdata(EMData * image, const string & filename);
104 static int check_image(const string& imagefile, EMData * image = 0);
105 static void set_progname(const string & cur_progname);
106
107 static void make_image_file(const string & filename,
108 EMUtil::ImageType image_type,
110 int nx = 16, int ny = 16, int nz = 1)
111 {
112 make_image_file_by_mode(filename, image_type, 1, datatype, nx, ny, nz);
113 }
114
115 static int verify_image_file(const string & filename,
116 EMUtil::ImageType image_type,
118 int nx = 16, int ny = 16, int nz = 1)
119 {
120 return verify_image_file_by_mode(filename, image_type, 1, datatype, nx, ny, nz);
121 }
122
123 static void make_image_file2(const string & filename,
124 EMUtil::ImageType image_type,
126 int nx = 16, int ny = 16, int nz = 1)
127 {
128 make_image_file_by_mode(filename, image_type, 2, datatype,nx, ny, nz);
129 }
130
131 static int verify_image_file2(const string & filename,
132 EMUtil::ImageType image_type,
134 int nx = 16, int ny = 16, int nz = 1)
135 {
136 return verify_image_file_by_mode(filename, image_type, 2,
137 datatype, nx, ny, nz);
138 }
139
140
141
142
143 private:
144 static float tf[10];
145 static int ti[10];
146 static string progname;
147
148 static void make_image_file_by_mode(const string & filename,
149 EMUtil::ImageType image_type, int mode,
151 int nx = 16, int ny = 16, int nz = 1);
152
153 static int verify_image_file_by_mode(const string & filename,
154 EMUtil::ImageType image_type, int mode,
156 int nx = 16, int ny = 16, int nz = 1);
157
158
159 static float get_pixel_value_by_dist1(int nx, int ny, int nz, int x, int y, int z)
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 }
186
187 static float get_pixel_value_by_dist2(int nx, int ny, int nz, int x, int y, int z)
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 }
219 };
220
221
222
223
224
225}
226
227#endif //eman__testutil_h__
228
229
Ctf is the base class for all CTF model.
Definition: ctf.h:60
Dict is a dictionary to store <string, EMObject> pair.
Definition: emobject.h:385
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
EMObject is a wrapper class for types including int, float, double, etc as defined in ObjectType.
Definition: emobject.h:123
EMDataType
Image pixel data type used in EMAN.
Definition: emutil.h:92
ImageType
Image format types.
Definition: emutil.h:112
FloatPoint defines a float-coordinate point in a 1D/2D/3D space.
Definition: geometry.h:278
FloatSize is used to describe a 1D, 2D or 3D rectangular size in floating numbers.
Definition: geometry.h:105
IntPoint defines an integer-coordinate point in a 1D/2D/3D space.
Definition: geometry.h:192
IntSize is used to describe a 1D, 2D or 3D rectangular size in integers.
Definition: geometry.h:49
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)
Definition: testutil.h:123
static map< string, string > test_map_string(const map< string, string > &d)
Definition: testutil.cpp:287
static string get_golden_image(const string &imagename)
Definition: testutil.cpp:101
static vector< int > test_vector_int(const vector< int > &v)
Definition: testutil.cpp:319
static string get_debug_image(const string &imagename)
Definition: testutil.cpp:88
static const char * EMDATA_HEADER_EXT
Definition: testutil.h:51
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)
Definition: testutil.h:131
static vector< long > test_vector_long(const vector< long > &v)
Definition: testutil.cpp:343
static void set_progname(const string &cur_progname)
Definition: testutil.cpp:534
static string get_debug_string(int i)
Definition: testutil.cpp:70
static float get_pixel_value_by_dist2(int nx, int ny, int nz, int x, int y, int z)
Definition: testutil.h:187
static vector< EMData * > test_vector_emdata(const vector< EMData * > &v)
Definition: testutil.cpp:366
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)
Definition: testutil.h:107
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)
Definition: testutil.h:115
static int ti[10]
Definition: testutil.h:145
static float get_pixel_value_by_dist1(int nx, int ny, int nz, int x, int y, int z)
Definition: testutil.h:159
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
static EMObject emobject_transformarray_to_py()
Definition: testutil.cpp:725
static int check_image(const string &imagefile, EMData *image=0)
Definition: testutil.cpp:409
static EMObject emobject_farray_to_py()
Definition: testutil.cpp:706
static float get_debug_float(int i)
Definition: testutil.cpp:65
static map< string, long > test_map_long(const map< string, long > &d)
Definition: testutil.cpp:263
static IntSize test_IntSize(const IntSize &p)
Definition: testutil.cpp:212
static void dump_image_from_file(const string &filename)
Definition: testutil.cpp:456
static Dict test_dict(const Dict &d)
Definition: testutil.cpp:391
static Vec3i test_Vec3i(const Vec3i &p)
Definition: testutil.cpp:232
static const char * EMDATA_DATA_EXT
Definition: testutil.h:52
static map< string, vector< string > > test_map_vecstring(const map< string, vector< string > > &d)
Definition: testutil.cpp:311
static vector< Pixel > test_vector_pixel(const vector< Pixel > &v)
Definition: testutil.cpp:378
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
static void to_emobject(const Dict &d)
Definition: testutil.cpp:114
static FloatSize test_FloatSize(const FloatSize &p)
Definition: testutil.cpp:222
static EMObject emobject_strarray_to_py()
Definition: testutil.cpp:716
static IntPoint test_IntPoint(const IntPoint &p)
Definition: testutil.cpp:193
static Transform get_debug_transform(int i)
Definition: testutil.cpp:77
static map< string, int > test_map_int(const map< string, int > &d)
Definition: testutil.cpp:251
static EMObject emobject_to_py(bool b)
Definition: testutil.cpp:663
static FloatPoint test_FloatPoint(const FloatPoint &p)
Definition: testutil.cpp:202
static vector< string > test_vector_string(const vector< string > &v)
Definition: testutil.cpp:355
static Vec3f test_Vec3f(const Vec3f &p)
Definition: testutil.cpp:241
static map< string, EMObject > test_map_emobject(const map< string, EMObject > &d)
Definition: testutil.cpp:299
static vector< float > test_vector_float(const vector< float > &v)
Definition: testutil.cpp:331
static int get_debug_int(int i)
Definition: testutil.cpp:60
static void dump_emdata(EMData *image, const string &filename)
Definition: testutil.cpp:468
static string progname
Definition: testutil.h:146
static map< string, float > test_map_float(const map< string, float > &d)
Definition: testutil.cpp:275
static float tf[10]
Definition: testutil.h:144
A Transform object is a somewhat specialized object designed specifically for EMAN2/Sparx storage of ...
Definition: transform.h:75
XYData defines a 1D (x,y) data set.
Definition: xydata.h:47
E2Exception class.
Definition: aligner.h:40
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517