38#define M_PI 3.14159265358979323846f
53const float EMConsts::I2G = (float) (4.0 / (M_PI*M_PI));
54const float EMConsts::I3G = (float) (6.4 / (M_PI*M_PI));
55const float EMConsts::I4G = (float) (8.8 / (M_PI*M_PI));
56const float EMConsts::I5G = (float) (10.4 / (M_PI*M_PI));
58const double EMConsts::pi = 3.141592653589793238462643383279502884197169399;
59const double EMConsts::deg2rad = pi/180.0;
60const double EMConsts::rad2deg = 180.0/pi;
64using std::stringstream;
70set<EMObject*> allemobjlist;
75map< EMObject::ObjectType, string> EMObject::type_registry = init();;
78map< EMObject::ObjectType, string> EMObject::init()
80 map< EMObject::ObjectType, string> mymap;
81 static bool first_construction =
true;
82 if ( first_construction )
86 mymap[
SHORT] =
"SHORT";
89 mymap[
FLOAT] =
"FLOAT";
104 first_construction =
false;
114 cout <<
"The address of my type is " << &
type << endl;
115 cout <<
" Now printing the enumerated values in type_registry " << endl;
118 cout << it->first <<
" " << it->second << endl;
120 cout <<
"My type is " <<
to_str(
type) <<
" and its enumerated value is " <<
type << endl;
121 cout <<
"The address of the static type registry is " << &
type_registry <<
", it should be same for all EMObjects" << endl;
126 allemobjlist.erase(
this);
127 printf(
" -(%6d) %p\n",(
int)allemobjlist.size(),
this);
135 allemobjlist.insert(
this);
136 printf(
" +(%6d) %p\n",(
int)allemobjlist.size(),
this);
141 b(boolean), type(BOOL)
144 allemobjlist.insert(
this);
145 printf(
" +(%6d) %p\n",(
int)allemobjlist.size(),
this);
150 si(sint), type(SHORT)
153 allemobjlist.insert(
this);
154 printf(
" +(%6d) %p\n",(
int)allemobjlist.size(),
this);
162 allemobjlist.insert(
this);
163 printf(
" +(%6d) %p\n",(
int)allemobjlist.size(),
this);
168 ui(num), type(UNSIGNEDINT)
171 allemobjlist.insert(
this);
172 printf(
" +(%6d) %p\n",(
int)allemobjlist.size(),
this);
181 allemobjlist.insert(
this);
182 printf(
" +(%6d) %p\n",(
int)allemobjlist.size(),
this);
197 allemobjlist.insert(
this);
198 printf(
" +(%6d) %p\n",(
int)allemobjlist.size(),
this);
212 allemobjlist.insert(
this);
213 printf(
" +(%6d) %p c*\n",(
int)allemobjlist.size(),
this);
221 allemobjlist.insert(
this);
222 printf(
" +(%6d) %p s\n",(
int)allemobjlist.size(),
this);
227 fp(f), type(FLOAT_POINTER)
230 allemobjlist.insert(
this);
231 printf(
" +(%6d) %p f*\n",(
int)allemobjlist.size(),
this);
236 ip(i), type(INT_POINTER)
239 allemobjlist.insert(
this);
240 printf(
" +(%6d) %p i*\n",(
int)allemobjlist.size(),
this);
245 vp(v), type(VOID_POINTER)
248 allemobjlist.insert(
this);
249 printf(
" +(%6d) %p v*\n",(
int)allemobjlist.size(),
this);
254 emdata(em), type(EMDATA)
257 allemobjlist.insert(
this);
258 printf(
" +(%6d) %p emd\n",(
int)allemobjlist.size(),
this);
263 xydata(xy), type(XYDATA)
266 allemobjlist.insert(
this);
267 printf(
" +(%6d) %p xyd\n",(
int)allemobjlist.size(),
this);
272 farray(t->get_matrix()), type(TRANSFORM)
275 allemobjlist.insert(
this);
276 printf(
" +(%6d) %p xf\n",(
int)allemobjlist.size(),
this);
281 str(ctf->to_string()), type(CTF)
284 allemobjlist.insert(
this);
285 printf(
" +(%6d) %p ctf\n",(
int)allemobjlist.size(),
this);
290 iarray(v), type(INTARRAY)
293 allemobjlist.insert(
this);
294 printf(
" +(%6d) %p ia\n",(
int)allemobjlist.size(),
this);
299 farray(v), type(FLOATARRAY)
302 allemobjlist.insert(
this);
303 printf(
" +(%6d) %p fa\n",(
int)allemobjlist.size(),
this);
308 strarray(sarray), type(STRINGARRAY)
311 allemobjlist.insert(
this);
312 printf(
" +(%6d) %p sa\n",(
int)allemobjlist.size(),
this);
317 transformarray(tarray), type(TRANSFORMARRAY)
320 allemobjlist.insert(
this);
321 printf(
" +(%6d) %p xfa\n",(
int)allemobjlist.size(),
this);
325EMObject::operator bool ()
const
330 else if (type == SHORT) {
333 else if (type == INT) {
336 else if (type == UNSIGNEDINT) {
339 else if (type == FLOAT) {
342 else if (type == DOUBLE) {
345 else if (type == EMDATA) {
348 else if (type == XYDATA) {
351 else if (type == FLOAT_POINTER) {
354 else if (type == INT_POINTER) {
357 else if (type == VOID_POINTER) {
365 if (type != UNKNOWN) {
366 throw TypeException(
"Cannot convert to bool this data type ",
367 get_object_type_name(type));
373EMObject::operator short ()
const
379 if (type != UNKNOWN) {
381 get_object_type_name(type));
387EMObject::operator int ()
const
392 else if (type == SHORT) {
395 else if (type == UNSIGNEDINT) {
398 else if (type == FLOAT) {
401 else if (type == DOUBLE) {
404 else if (type == BOOL) {
408 if (type != UNKNOWN) {
410 get_object_type_name(type));
416EMObject::operator
unsigned int ()
const
418 if (type == UNSIGNEDINT) {
419 return (
unsigned int) ui;
422 if (type != UNKNOWN) {
424 get_object_type_name(type));
430EMObject::operator float ()
const
435 else if (type == FLOAT) {
438 else if (type == SHORT) {
441 else if (type == INT) {
444 else if (type == UNSIGNEDINT) {
447 else if (type == DOUBLE) {
450 else if (type == STRING) {
451 return (
float)atof(str.c_str());
454 if (type != UNKNOWN) {
455 throw TypeException(
"Cannot convert to float from this data type",
456 get_object_type_name(type));
463EMObject::operator double ()
const
468 else if (type == DOUBLE) {
471 else if (type == SHORT) {
474 else if (type == INT) {
477 else if (type == UNSIGNEDINT) {
480 else if (type == FLOAT) {
484 if (type != UNKNOWN) {
485 throw TypeException(
"Cannot convert to double from this data type",
486 get_object_type_name(type));
492EMObject::operator
int * ()
const
494 if (type != INT_POINTER)
497 throw TypeException(
"Cannot convert to float pointer from this data type",
498 get_object_type_name(type));
507EMObject::operator
float * ()
const
509 if (type != FLOAT_POINTER)
512 throw TypeException(
"Cannot convert to float pointer from this data type",
513 get_object_type_name(type));
522EMObject::operator
void * ()
const
524 if (type == VOID_POINTER)
return vp;
525 else if (type == FLOAT_POINTER)
return (
void *)fp;
526 else if (type == INT_POINTER)
return (
void *)ip;
527 else if (type == EMDATA)
return (
void *) emdata;
528 else if (type == XYDATA)
return (
void *) xydata;
530 else throw TypeException(
"Cannot convert to void pointer from this data type", get_object_type_name(type));
533EMObject::operator
const char * ()
const
535 if (type != STRING && type != CTF) {
537 string return_string;
542 return return_string.c_str();
544 if ( type == UNSIGNEDINT )
548 return return_string.c_str();
555 return return_string.c_str();
558 if ( type == DOUBLE )
562 return return_string.c_str();
564 else if (type != UNKNOWN) {
565 throw TypeException(
"Cannot convert to string from this data type",
566 get_object_type_name(type));
576 if (type != EMDATA) {
577 if (type != UNKNOWN) {
578 throw TypeException(
"Cannot convert to EMData* from this data type",
579 get_object_type_name(type));
588 if (type != XYDATA) {
589 if (type != UNKNOWN) {
590 throw TypeException(
"Cannot convert to XYData* from this data type",
591 get_object_type_name(type));
600 if(type != TRANSFORM) {
601 if(type != UNKNOWN) {
602 throw TypeException(
"Cannot convert to TRANSFORM* from this data type",
603 get_object_type_name(type));
611EMObject::operator
Ctf* ()
const
624 else if(str[0] ==
'E') {
631EMObject::operator vector<int>()
const
633 if( type != INTARRAY )
635 if( type != UNKNOWN ) {
636 throw TypeException(
"Cannot convert to vector<int> from this data type", get_object_type_name(type) );
638 return vector<int>();
643EMObject::operator vector < float > ()
const
645 if (type != FLOATARRAY) {
646 if (type != UNKNOWN) {
647 throw TypeException(
"Cannot convert to vector<float> from this data type",
648 get_object_type_name(type));
650 return vector < float >();
655EMObject::operator vector<string> ()
const
657 if (type != STRINGARRAY) {
658 if (type != UNKNOWN) {
659 throw TypeException(
"Cannot convert to vector<string> from this data type",
660 get_object_type_name(type));
662 return vector<string>();
667EMObject::operator vector<Transform> ()
const
669 if(type != TRANSFORMARRAY) {
670 if (type != UNKNOWN) {
671 throw TypeException(
"Cannot convert to vector<string> from this data type",
672 get_object_type_name(type));
674 return vector<Transform>();
676 return transformarray;
696 if (argtype ==
BOOL) {
698 sprintf(tmp_str,
"true");
700 sprintf(tmp_str,
"false");
702 else if (argtype ==
SHORT) {
703 sprintf(tmp_str,
"%hd",
si);
705 else if (argtype ==
INT) {
706 sprintf(tmp_str,
"%d",
n);
709 sprintf(tmp_str,
"%d",
ui);
711 else if (argtype ==
FLOAT) {
712 sprintf(tmp_str,
"%f",
f);
714 else if (argtype ==
DOUBLE) {
715 sprintf(tmp_str,
"%f",
d);
717 else if (argtype ==
EMDATA) {
718 sprintf(tmp_str,
"EMDATA");
721 sprintf(tmp_str,
"FLOAT_POINTER");
724 sprintf(tmp_str,
"INT_POINTER");
727 sprintf(tmp_str,
"VOID_POINTER");
729 else if (argtype ==
XYDATA) {
730 sprintf(tmp_str,
"XYDATA");
733 sprintf(tmp_str,
"INTARRAY");
736 sprintf(tmp_str,
"FLOATARRAY");
739 sprintf(tmp_str,
"STRINGARRAY");
742 sprintf(tmp_str,
"TRANSFORM");
745 sprintf(tmp_str,
"TRANSFORMARRAY");
747 else if (argtype ==
CTF) {
748 sprintf(tmp_str,
"CTF");
751 sprintf(tmp_str,
"UNKNOWN");
754 LOGERR(
"No such EMObject defined");
757 return string(tmp_str);
766 LOGERR(
"No such EMObject defined");
779 return (e1.
b == e2.
b);
782 return (e1.
si == e2.
si);
785 return (e1.
n == e2.
n);
788 return (e1.
ui == e2.
ui);
791 return (e1.
f == e2.
f);
794 return (e1.
d == e2.
d);
798 return (e1.
str == e2.
str);
801 return (e1.
fp == e2.
fp);
804 return (e1.
ip == e2.
ip);
807 return (e1.
vp == e2.
vp);
818 for (
size_t i = 0; i < e1.
farray.size(); i++) {
831 for (
size_t i = 0; i < e1.
iarray.size(); i++) {
841 for (
size_t i = 0; i < e1.
strarray.size(); i++) {
884 allemobjlist.insert(
this);
885 printf(
" +(%6d) %p\n",(
int)allemobjlist.size(),
this);
972 LOGERR(
"No such EMObject defined");
990 map < string, string >::iterator p;
992 printf(
"\t%s %s %s\n",
993 p->first.c_str(), p->second.c_str(),
desc_dict[p->first].c_str());
1006 if (
this != &that )
1015 cerr <<
"Warning - attempted to assign a Dict object to itself. No action taken" << endl;
1035 dict[p->first]=p->second;
1095 map < string, EMObject >::iterator::operator=( that );
1123 map < string, EMObject >::const_iterator::operator=( that );
1132 for (map < string, EMObject >::const_iterator it =
dict.begin(); it !=
dict.end(); ++it ) {
1134 if (lower == lower_key)
return it->second;
1144 for (map < string, EMObject >::const_iterator it =
dict.begin(); it !=
dict.end(); ++it ) {
1146 if (lower == lower_key)
return true;
Ctf is the base class for all CTF model.
virtual int from_string(const string &ctf)=0
Const iterator support for the Dict object This is just a wrapper, everything is inherited from the m...
const_iterator(const map< string, EMObject >::const_iterator parent_it)
const_iterator & operator=(const const_iterator &that)
Non const iterator support for the Dict object This is just a wrapper, everything is inherited from t...
iterator & operator=(const iterator &that)
iterator(map< string, EMObject >::iterator parent_it)
Dict is a dictionary to store <string, EMObject> pair.
bool has_key_ci(const string &key) const
Ask the Dictionary if it as a particular key in a case insensitive way.
Dict & operator=(const Dict &that)
Assignment operator Copies all elements in dict.
iterator find(const string &key)
map< string, EMObject > dict
EMObject get_ci(const string &key) const
Get the EMObject corresponding to the particular key using case insensitivity.
void update(const Dict &that)
Update replaces values from that into this without otherwise altering this.
EMAN1Ctf is the CTF model used in EMAN1.
EMAN2Ctf is the default CTF model used in EMAN2.
EMData stores an image's data and defines core image processing routines.
EMObject is a wrapper class for types including int, float, double, etc as defined in ObjectType.
vector< Transform > transformarray
EMObject & operator=(const EMObject &that)
Assigment operator copies pointer locations (emdata, xydata, transform) - does not take ownership dee...
string to_str() const
Calls to_str( this->type)
bool is_null() const
Checks to see if the EMObject is interpretable This basically equates to checking to see if the type ...
EMObject()
Constructors for each type More types could be added, but all of the accompanying functions would hav...
~EMObject()
Desctructor Does not free pointers.
void printInfo() const
A debug function that prints as much information as possibe to cout.
static string get_object_type_name(ObjectType t)
Get an ObjectType as a string statically Can be accessed without the instantiation of a class object.
vector< string > strarray
static map< ObjectType, string > type_registry
map< string, string > type_dict
map< string, string > desc_dict
static string str_to_lower(const string &s)
Return a lower case version of the argument string.
static int goodf(const float *p_f)
Check whether a number is a good float.
XYData defines a 1D (x,y) data set.
EMData * copy() const
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
#define NotExistingObjectException(objname, desc)
#define TypeException(desc, type)
bool operator!=(const EMObject &e1, const EMObject &e2)
bool operator==(const EMObject &e1, const EMObject &e2)