#include <emutil.h>
Public Types | |
EM_UNKNOWN | |
EM_CHAR | |
EM_UCHAR | |
EM_SHORT | |
EM_USHORT | |
EM_INT | |
EM_UINT | |
EM_FLOAT | |
EM_DOUBLE | |
EM_SHORT_COMPLEX | |
EM_USHORT_COMPLEX | |
EM_FLOAT_COMPLEX | |
IMAGE_UNKNOWN | |
IMAGE_MRC | |
IMAGE_SPIDER | |
IMAGE_SINGLE_SPIDER | |
IMAGE_IMAGIC | |
IMAGE_HDF | |
IMAGE_DM3 | |
IMAGE_TIFF | |
IMAGE_PGM | |
IMAGE_LST | |
IMAGE_PIF | |
IMAGE_VTK | |
IMAGE_PNG | |
IMAGE_SAL | |
IMAGE_ICOS | |
IMAGE_EMIM | |
IMAGE_GATAN2 | |
IMAGE_AMIRA | |
IMAGE_XPLOR | |
IMAGE_EM | |
IMAGE_V4L | |
IMAGE_JPEG | |
IMAGE_FITS | |
IMAGE_LSTFAST | |
IMAGE_DF3 | |
IMAGE_OMAP | |
IMAGE_SITUS | |
enum | EMDataType { EM_UNKNOWN, EM_CHAR, EM_UCHAR, EM_SHORT, EM_USHORT, EM_INT, EM_UINT, EM_FLOAT, EM_DOUBLE, EM_SHORT_COMPLEX, EM_USHORT_COMPLEX, EM_FLOAT_COMPLEX } |
Image pixel data type used in EMAN. More... | |
enum | ImageType { IMAGE_UNKNOWN, IMAGE_MRC, IMAGE_SPIDER, IMAGE_SINGLE_SPIDER, IMAGE_IMAGIC, IMAGE_HDF, IMAGE_DM3, IMAGE_TIFF, IMAGE_PGM, IMAGE_LST, IMAGE_PIF, IMAGE_VTK, IMAGE_PNG, IMAGE_SAL, IMAGE_ICOS, IMAGE_EMIM, IMAGE_GATAN2, IMAGE_AMIRA, IMAGE_XPLOR, IMAGE_EM, IMAGE_V4L, IMAGE_JPEG, IMAGE_FITS, IMAGE_LSTFAST, IMAGE_DF3, IMAGE_OMAP, IMAGE_SITUS } |
Image format types. More... | |
Static Public Member Functions | |
static EMData * | vertical_acf (const EMData *image, int maxdy) |
static EMData * | make_image_median (const vector< EMData * > &image_list) |
static ImageType | get_image_ext_type (const string &file_ext) |
Get an image's format type from its filename extension. | |
static ImageType | get_image_type (const string &filename) |
Get an image's format type by processing the first 1K of the image. | |
static bool | is_valid_filename (const string &filename) |
Ask whether or not the given filename is a valid EM image filename This is the same thing as checking whether or not the return value of EMUtil.get_image_ext_type is IMAGE_UNKNOWN. | |
static int | get_image_count (const string &filename) |
Get the number of images in an image file. | |
static ImageIO * | get_imageio (const string &filename, int rw_mode, ImageType image_type=IMAGE_UNKNOWN) |
Get an ImageIO object. | |
static const char * | get_imagetype_name (EMUtil::ImageType type) |
Give each image type a meaningful name. | |
static const char * | get_datatype_string (EMDataType type) |
Give each data type a meaningful name. | |
static void | get_region_dims (const Region *area, int nx, int *area_x, int ny, int *area_y, int nz=1, int *area_z=0) |
Get a region's dimensions. | |
static void | get_region_origins (const Region *area, int *p_x0, int *p_y0, int *p_z0=0, int nz=1, int image_index=0) |
Get a region's original locations. | |
static void | process_region_io (void *cdata, FILE *file, int rw_mode, int image_index, size_t mode_size, int nx, int ny, int nz=1, const Region *area=0, bool need_flip=false, ImageType imgtype=IMAGE_UNKNOWN, int pre_row=0, int post_row=0) |
Process image region IO. | |
static void | process_ascii_region_io (float *data, FILE *file, int rw_mode, int image_index, size_t mode_size, int nx, int ny, int nz, const Region *area, bool has_index_line, int nitems_per_line, const char *outformat) |
Works for regions that are outside the image data dimension area. | |
static void | dump_dict (const Dict &dict) |
Dump a Dict object. | |
static bool | is_same_size (const EMData *image1, const EMData *image2) |
Check whether two EMData images are of the same size. | |
static bool | is_same_ctf (const EMData *image1, const EMData *image2) |
Check whether two EMData images have the same CTF parameters. | |
static bool | is_complex_type (EMDataType datatype) |
static void | jump_lines (FILE *file, int nlines) |
static vector< string > | get_euler_names (const string &euler_type) |
static vector< EMObject > | get_all_attributes (const string &file_name, const string &attr_name) |
Get an attribute from a stack of image, returned as a vector. | |
static void | getRenderMinMax (float *data, const int nx, const int ny, float &rendermin, float &rendermax, const int nz=1) |
Calculate the min and max pixel value acceptedfor image nomalization, if we did not get them from image attribute dictionary, or they are not valid values rendermin = mean - 3*sigma rendermax = mean + 3*sigma. | |
static bool | cuda_available () |
static void * | em_malloc (const size_t size) |
static void * | em_calloc (const size_t nmemb, const size_t size) |
static void * | em_realloc (void *data, const size_t new_size) |
static void | em_memset (void *data, const int value, const size_t size) |
static void | em_free (void *data) |
static void | em_memcpy (void *dst, const void *const src, const size_t size) |
Static Private Member Functions | |
static ImageType | fast_get_image_type (const string &filename, const void *first_block, off_t file_size) |
static void | jump_lines_by_items (FILE *file, int nitems, int nitems_per_line) |
static void | process_numbers_io (FILE *file, int rw_mode, int nitems_per_line, size_t mode_size, int start, int end, float *data, int *p_i, const char *outformat) |
static void | exclude_numbers_io (FILE *file, int rw_mode, int nitems_per_line, size_t mode_size, int start, int end, float *data, int *p_i, const char *outformat) |
static void | process_lines_io (FILE *file, int rw_mode, int nitems_per_line, size_t mode_size, int nitems, float *data, int *p_i, const char *outformat) |
Definition at line 85 of file emutil.h.
Image pixel data type used in EMAN.
EM_U means "EM unsigned". for example, EM_USHORT means EM unsigned short.
EM_UNKNOWN | |
EM_CHAR | |
EM_UCHAR | |
EM_SHORT | |
EM_USHORT | |
EM_INT | |
EM_UINT | |
EM_FLOAT | |
EM_DOUBLE | |
EM_SHORT_COMPLEX | |
EM_USHORT_COMPLEX | |
EM_FLOAT_COMPLEX |
Definition at line 92 of file emutil.h.
00093 { 00094 EM_UNKNOWN, 00095 EM_CHAR, 00096 EM_UCHAR, 00097 EM_SHORT, 00098 EM_USHORT, 00099 EM_INT, 00100 EM_UINT, 00101 EM_FLOAT, 00102 EM_DOUBLE, 00103 EM_SHORT_COMPLEX, 00104 EM_USHORT_COMPLEX, 00105 EM_FLOAT_COMPLEX 00106 };
Image format types.
Definition at line 110 of file emutil.h.
00111 { 00112 IMAGE_UNKNOWN, 00113 IMAGE_MRC, 00114 IMAGE_SPIDER, 00115 IMAGE_SINGLE_SPIDER, 00116 IMAGE_IMAGIC, 00117 IMAGE_HDF, 00118 IMAGE_DM3, 00119 IMAGE_TIFF, 00120 IMAGE_PGM, 00121 IMAGE_LST, 00122 IMAGE_PIF, 00123 IMAGE_VTK, 00124 IMAGE_PNG, 00125 IMAGE_SAL, 00126 IMAGE_ICOS, 00127 IMAGE_EMIM, 00128 IMAGE_GATAN2, 00129 IMAGE_AMIRA, 00130 IMAGE_XPLOR, 00131 IMAGE_EM, 00132 IMAGE_V4L, 00133 IMAGE_JPEG, 00134 IMAGE_FITS, 00135 IMAGE_LSTFAST, 00136 IMAGE_DF3, 00137 IMAGE_OMAP, 00138 IMAGE_SITUS 00139 };
static bool EMAN::EMUtil::cuda_available | ( | ) | [inline, static] |
void EMUtil::dump_dict | ( | const Dict & | dict | ) | [static] |
Dump a Dict object.
dict | A Dict object. |
Definition at line 983 of file emutil.cpp.
References get_datatype_string(), EMAN::Dict::keys(), and EMAN::Dict::values().
00984 { 00985 vector < string > keys = dict.keys(); 00986 vector < EMObject > values = dict.values(); 00987 00988 for (unsigned int i = 0; i < keys.size(); i++) { 00989 EMObject obj = values[i]; 00990 if( !obj.is_null() ) { 00991 string val = obj.to_str(); 00992 00993 if (keys[i] == "datatype") { 00994 val = get_datatype_string((EMDataType) (int) obj); 00995 } 00996 00997 fprintf(stdout, "%25s\t%s\n", keys[i].c_str(), val.c_str()); 00998 } 00999 } 01000 }
static void* EMAN::EMUtil::em_calloc | ( | const size_t | nmemb, | |
const size_t | size | |||
) | [inline, static] |
static void EMAN::EMUtil::em_free | ( | void * | data | ) | [inline, static] |
Definition at line 356 of file emutil.h.
Referenced by EMAN::EMData::free_memory(), EMAN::EMData::free_rdata(), EMAN::EMData::read_image(), EMAN::EMData::set_size(), and EMAN::EMData::setup4slice().
00356 { 00357 free(data); 00358 }
static void* EMAN::EMUtil::em_malloc | ( | const size_t | size | ) | [inline, static] |
Definition at line 342 of file emutil.h.
Referenced by EMAN::EMData::EMData(), EMAN::EMData::rotate_x(), EMAN::EMData::set_size(), and EMAN::TransformProcessor::transform().
static void EMAN::EMUtil::em_memcpy | ( | void * | dst, | |
const void *const | src, | |||
const size_t | size | |||
) | [inline, static] |
Definition at line 360 of file emutil.h.
Referenced by EMAN::EMData::clip_inplace(), EMAN::EMData::EMData(), EMAN::EMData::get_top_half(), EMAN::EMData::insert_clip(), EMAN::EMData::operator=(), EMAN::EMData::rotate_x(), and EMAN::EMData::set_data_pickle().
static void EMAN::EMUtil::em_memset | ( | void * | data, | |
const int | value, | |||
const size_t | size | |||
) | [inline, static] |
Definition at line 353 of file emutil.h.
Referenced by EMAN::EMData::clip_inplace(), and EMAN::EMData::set_size().
00353 { 00354 memset(data, value, size); 00355 }
static void* EMAN::EMUtil::em_realloc | ( | void * | data, | |
const size_t | new_size | |||
) | [inline, static] |
Definition at line 350 of file emutil.h.
Referenced by EMAN::EMData::set_size().
00350 { 00351 return realloc(data, new_size); 00352 }
void EMUtil::exclude_numbers_io | ( | FILE * | file, | |
int | rw_mode, | |||
int | nitems_per_line, | |||
size_t | mode_size, | |||
int | start, | |||
int | end, | |||
float * | data, | |||
int * | p_i, | |||
const char * | outformat | |||
) | [static, private] |
Definition at line 1405 of file emutil.cpp.
References Assert, portable_fseek(), and EMAN::ImageIO::READ_ONLY.
Referenced by process_ascii_region_io().
01408 { 01409 Assert(file); 01410 Assert(mode_size > 0); 01411 Assert(start >= 0); 01412 Assert(end <= nitems_per_line); 01413 Assert(data); 01414 Assert(p_i); 01415 Assert(outformat); 01416 01417 char line[MAXPATHLEN]; 01418 01419 if (rw_mode == ImageIO::READ_ONLY) { 01420 01421 if (!fgets(line, sizeof(line), file)) { 01422 Assert("read xplor file failed"); 01423 } 01424 01425 int nitems_in_line = (int) (strlen(line) / mode_size); 01426 Assert(end <= nitems_in_line); 01427 01428 vector<float> d(nitems_in_line); 01429 char *pline = line; 01430 01431 for (int i = 0; i < nitems_in_line; i++) { 01432 sscanf(pline, "%f", &d[i]); 01433 pline = pline + (int)mode_size; 01434 } 01435 01436 01437 for (int i = 0; i < start; i++) { 01438 data[*p_i] = d[i]; 01439 (*p_i)++; 01440 } 01441 01442 for (int i = end+1; i < nitems_in_line; i++) { 01443 data[*p_i] = d[i]; 01444 (*p_i)++; 01445 } 01446 } 01447 else { 01448 for (int i = 0; i < start; i++) { 01449 fprintf(file, outformat, data[*p_i]); 01450 (*p_i)++; 01451 } 01452 01453 portable_fseek(file, (end-start+1) * mode_size, SEEK_CUR); 01454 01455 for (int i = end+1; i < nitems_per_line; i++) { 01456 fprintf(file, outformat, data[*p_i]); 01457 (*p_i)++; 01458 } 01459 portable_fseek(file, 1, SEEK_CUR); 01460 } 01461 }
EMUtil::ImageType EMUtil::fast_get_image_type | ( | const string & | filename, | |
const void * | first_block, | |||
off_t | file_size | |||
) | [static, private] |
Definition at line 211 of file emutil.cpp.
References Assert, ENTERFUNC, EXITFUNC, EMAN::Util::get_filename_ext(), get_image_ext_type(), IMAGE_AMIRA, IMAGE_DF3, IMAGE_DM3, IMAGE_EM, IMAGE_GATAN2, IMAGE_HDF, IMAGE_ICOS, IMAGE_IMAGIC, IMAGE_LST, IMAGE_LSTFAST, IMAGE_MRC, IMAGE_OMAP, IMAGE_PGM, IMAGE_PIF, IMAGE_PNG, IMAGE_SAL, IMAGE_SINGLE_SPIDER, IMAGE_SITUS, IMAGE_SPIDER, IMAGE_TIFF, IMAGE_UNKNOWN, IMAGE_V4L, IMAGE_VTK, IMAGE_XPLOR, EMAN::ImagicIO::is_valid(), EMAN::SitusIO::is_valid(), EMAN::OmapIO::is_valid(), EMAN::EmIO::is_valid(), EMAN::Gatan2IO::is_valid(), EMAN::XplorIO::is_valid(), EMAN::AmiraIO::is_valid(), EMAN::SalIO::is_valid(), EMAN::IcosIO::is_valid(), EMAN::PgmIO::is_valid(), EMAN::VtkIO::is_valid(), EMAN::PifIO::is_valid(), EMAN::SingleSpiderIO::is_valid(), EMAN::SpiderIO::is_valid(), EMAN::LstFastIO::is_valid(), EMAN::LstIO::is_valid(), EMAN::DM3IO::is_valid(), and EMAN::MrcIO::is_valid().
Referenced by get_image_type().
00214 { 00215 ENTERFUNC; 00216 Assert(filename != ""); 00217 Assert(first_block != 0); 00218 Assert(file_size > 0); 00219 00220 #ifdef ENABLE_V4L2 00221 if (filename.compare(0,5,"/dev/")==0) return IMAGE_V4L; 00222 #endif 00223 00224 string ext = Util::get_filename_ext(filename); 00225 if (ext == "") { 00226 return IMAGE_UNKNOWN; 00227 } 00228 ImageType image_type = get_image_ext_type(ext); 00229 00230 switch (image_type) { 00231 case IMAGE_MRC: 00232 if (MrcIO::is_valid(first_block, file_size)) { 00233 return IMAGE_MRC; 00234 } 00235 break; 00236 case IMAGE_DM3: 00237 if (DM3IO::is_valid(first_block)) { 00238 return IMAGE_DM3; 00239 } 00240 break; 00241 #ifdef EM_HDF5 00242 case IMAGE_HDF: 00243 if (HdfIO2::is_valid(first_block)) { 00244 return IMAGE_HDF; 00245 } 00246 break; 00247 #endif 00248 case IMAGE_LST: 00249 if (LstIO::is_valid(first_block)) { 00250 return IMAGE_LST; 00251 } 00252 break; 00253 case IMAGE_LSTFAST: 00254 if (LstFastIO::is_valid(first_block)) { 00255 return IMAGE_LSTFAST; 00256 } 00257 break; 00258 #ifdef EM_TIFF 00259 case IMAGE_TIFF: 00260 if (TiffIO::is_valid(first_block)) { 00261 return IMAGE_TIFF; 00262 } 00263 break; 00264 #endif 00265 case IMAGE_SPIDER: 00266 if (SpiderIO::is_valid(first_block)) { 00267 return IMAGE_SPIDER; 00268 } 00269 break; 00270 case IMAGE_SINGLE_SPIDER: 00271 if (SingleSpiderIO::is_valid(first_block)) { 00272 return IMAGE_SINGLE_SPIDER; 00273 } 00274 break; 00275 case IMAGE_PIF: 00276 if (PifIO::is_valid(first_block)) { 00277 return IMAGE_PIF; 00278 } 00279 break; 00280 #ifdef EM_PNG 00281 case IMAGE_PNG: 00282 if (PngIO::is_valid(first_block)) { 00283 return IMAGE_PNG; 00284 } 00285 break; 00286 #endif 00287 case IMAGE_VTK: 00288 if (VtkIO::is_valid(first_block)) { 00289 return IMAGE_VTK; 00290 } 00291 break; 00292 case IMAGE_PGM: 00293 if (PgmIO::is_valid(first_block)) { 00294 return IMAGE_PGM; 00295 } 00296 break; 00297 case IMAGE_ICOS: 00298 if (IcosIO::is_valid(first_block)) { 00299 return IMAGE_ICOS; 00300 } 00301 break; 00302 case IMAGE_SAL: 00303 if (SalIO::is_valid(first_block)) { 00304 return IMAGE_SAL; 00305 } 00306 break; 00307 case IMAGE_AMIRA: 00308 if (AmiraIO::is_valid(first_block)) { 00309 return IMAGE_AMIRA; 00310 } 00311 break; 00312 case IMAGE_XPLOR: 00313 if (XplorIO::is_valid(first_block)) { 00314 return IMAGE_XPLOR; 00315 } 00316 break; 00317 case IMAGE_GATAN2: 00318 if (Gatan2IO::is_valid(first_block)) { 00319 return IMAGE_GATAN2; 00320 } 00321 break; 00322 case IMAGE_EM: 00323 if (EmIO::is_valid(first_block, file_size)) { 00324 return IMAGE_EM; 00325 } 00326 break; 00327 case IMAGE_DF3: 00328 if (EmIO::is_valid(first_block, file_size)) { 00329 return IMAGE_DF3; 00330 } 00331 break; 00332 case IMAGE_OMAP: 00333 if (OmapIO::is_valid(first_block, file_size)) { 00334 return IMAGE_OMAP; 00335 } 00336 break; 00337 case IMAGE_SITUS: 00338 if (SitusIO::is_valid(first_block)) { 00339 return IMAGE_SITUS; 00340 } 00341 break; 00342 case IMAGE_IMAGIC: 00343 if (ImagicIO::is_valid(first_block)) { 00344 return IMAGE_IMAGIC; 00345 } 00346 break; 00347 default: 00348 return IMAGE_UNKNOWN; 00349 } 00350 EXITFUNC; 00351 return IMAGE_UNKNOWN; 00352 }
vector< EMObject > EMUtil::get_all_attributes | ( | const string & | file_name, | |
const string & | attr_name | |||
) | [static] |
Get an attribute from a stack of image, returned as a vector.
file_name | the image file name | |
attr_name | The header attribute name. |
NotExistingObjectException | when access an non-existing attribute | |
InvalidCallException | when call this function for a non-stack image |
Definition at line 1525 of file emutil.cpp.
References Assert, read_images(), and v.
01526 { 01527 vector<EMObject> v; 01528 01529 Assert(file_name != ""); 01530 Assert(attr_name != ""); 01531 01532 vector< shared_ptr<EMData> > vpImg = EMData::read_images(file_name, vector<int>(), true); 01533 vector< shared_ptr<EMData> >::const_iterator iter; 01534 for(iter = vpImg.begin(); iter!=vpImg.end(); ++iter) { 01535 v.push_back((*iter)->get_attr_default(attr_name)); 01536 } 01537 01538 return v; 01539 }
const char * EMUtil::get_datatype_string | ( | EMDataType | type | ) | [static] |
Give each data type a meaningful name.
type | the EMDataType |
Definition at line 722 of file emutil.cpp.
References EM_CHAR, EM_DOUBLE, EM_FLOAT, EM_FLOAT_COMPLEX, EM_INT, EM_SHORT, EM_SHORT_COMPLEX, EM_UCHAR, EM_UINT, EM_UNKNOWN, EM_USHORT, and EM_USHORT_COMPLEX.
Referenced by dump_dict().
00723 { 00724 switch (type) { 00725 case EM_CHAR: 00726 return "CHAR"; 00727 case EM_UCHAR: 00728 return "UNSIGNED CHAR"; 00729 case EM_SHORT: 00730 return "SHORT"; 00731 case EM_USHORT: 00732 return "UNSIGNED SHORT"; 00733 case EM_INT: 00734 return "INT"; 00735 case EM_UINT: 00736 return "UNSIGNED INT"; 00737 case EM_FLOAT: 00738 return "FLOAT"; 00739 case EM_DOUBLE: 00740 return "DOUBLE"; 00741 case EM_SHORT_COMPLEX: 00742 return "SHORT_COMPLEX"; 00743 case EM_USHORT_COMPLEX: 00744 return "USHORT_COMPLEX"; 00745 case EM_FLOAT_COMPLEX: 00746 return "FLOAT_COMPLEX"; 00747 case EM_UNKNOWN: 00748 return "UNKNOWN"; 00749 } 00750 return "UNKNOWN"; 00751 }
vector< string > EMUtil::get_euler_names | ( | const string & | euler_type | ) | [static] |
Definition at line 1481 of file emutil.cpp.
01482 { 01483 vector<string> v; 01484 string b = "euler_"; 01485 01486 if (euler_type == "EMAN") { 01487 v.push_back(b + "alt"); 01488 v.push_back(b + "az"); 01489 v.push_back(b + "phi"); 01490 } 01491 else if (euler_type == "MRC") { 01492 v.push_back(b + "theta"); 01493 v.push_back(b + "phi"); 01494 v.push_back(b + "omega"); 01495 } 01496 else if (euler_type == "IMAGIC") { 01497 v.push_back(b + "alpha"); 01498 v.push_back(b + "beta"); 01499 v.push_back(b + "gamma"); 01500 } 01501 else if (euler_type == "SPIDER") { 01502 v.push_back(b + "phi"); 01503 v.push_back(b + "theta"); 01504 v.push_back(b + "gamma"); 01505 } 01506 else if (euler_type == "SPIN" || 01507 euler_type == "SGIROT") { 01508 v.push_back(b + "q"); 01509 v.push_back(b + "n1"); 01510 v.push_back(b + "n2"); 01511 v.push_back(b + "n3"); 01512 } 01513 01514 else if (euler_type == "QUATERNION") { 01515 v.push_back(b + "e0"); 01516 v.push_back(b + "e1"); 01517 v.push_back(b + "e2"); 01518 v.push_back(b + "e3"); 01519 } 01520 01521 return v; 01522 }
int EMUtil::get_image_count | ( | const string & | filename | ) | [static] |
Get the number of images in an image file.
filename | Image file name. |
Definition at line 479 of file emutil.cpp.
References Assert, ENTERFUNC, EXITFUNC, get_imageio(), EMAN::ImageIO::get_nimg(), and EMAN::ImageIO::READ_ONLY.
Referenced by EMAN::PCA::dopca_ooc(), EMAN::PCA::Lanczos_ooc(), EMAN::EMData::read_images(), EMAN::EMData::read_images_ext(), ReadStackandDist(), and ReadStackandDist_Cart().
00480 { 00481 ENTERFUNC; 00482 Assert(filename != ""); 00483 00484 int nimg = 0; 00485 ImageIO *imageio = get_imageio(filename, ImageIO::READ_ONLY); 00486 00487 if (imageio) { 00488 nimg = imageio->get_nimg(); 00489 } 00490 #ifndef IMAGEIO_CACHE 00491 if( imageio ) 00492 { 00493 delete imageio; 00494 imageio = 0; 00495 } 00496 #endif 00497 EXITFUNC; 00498 return nimg; 00499 }
EMUtil::ImageType EMUtil::get_image_ext_type | ( | const string & | file_ext | ) | [static] |
Get an image's format type from its filename extension.
file_ext | File extension. |
Definition at line 62 of file emutil.cpp.
References ENTERFUNC, EXITFUNC, IMAGE_AMIRA, IMAGE_DF3, IMAGE_DM3, IMAGE_EM, IMAGE_EMIM, IMAGE_FITS, IMAGE_GATAN2, IMAGE_HDF, IMAGE_ICOS, IMAGE_IMAGIC, IMAGE_JPEG, IMAGE_LST, IMAGE_LSTFAST, IMAGE_MRC, IMAGE_OMAP, IMAGE_PGM, IMAGE_PIF, IMAGE_PNG, IMAGE_SAL, IMAGE_SINGLE_SPIDER, IMAGE_SITUS, IMAGE_SPIDER, IMAGE_TIFF, IMAGE_UNKNOWN, IMAGE_V4L, IMAGE_VTK, and IMAGE_XPLOR.
Referenced by fast_get_image_type(), is_valid_filename(), and EMAN::EMData::write_image().
00063 { 00064 ENTERFUNC; 00065 static bool initialized = false; 00066 static map < string, ImageType > imagetypes; 00067 00068 if (!initialized) { 00069 imagetypes["rec"] = IMAGE_MRC; 00070 imagetypes["mrc"] = IMAGE_MRC; 00071 imagetypes["MRC"] = IMAGE_MRC; 00072 imagetypes["ali"] = IMAGE_MRC; 00073 00074 imagetypes["tnf"] = IMAGE_MRC; 00075 imagetypes["TNF"] = IMAGE_MRC; 00076 00077 imagetypes["ccp4"] = IMAGE_MRC; 00078 imagetypes["map"] = IMAGE_MRC; 00079 00080 imagetypes["dm3"] = IMAGE_DM3; 00081 imagetypes["DM3"] = IMAGE_DM3; 00082 00083 imagetypes["spi"] = IMAGE_SPIDER; 00084 imagetypes["SPI"] = IMAGE_SPIDER; 00085 00086 imagetypes["spider"] = IMAGE_SPIDER; 00087 imagetypes["SPIDER"] = IMAGE_SPIDER; 00088 00089 imagetypes["spidersingle"] = IMAGE_SINGLE_SPIDER; 00090 imagetypes["SPIDERSINGLE"] = IMAGE_SINGLE_SPIDER; 00091 00092 imagetypes["singlespider"] = IMAGE_SINGLE_SPIDER; 00093 imagetypes["SINGLESPIDER"] = IMAGE_SINGLE_SPIDER; 00094 00095 imagetypes["img"] = IMAGE_IMAGIC; 00096 imagetypes["IMG"] = IMAGE_IMAGIC; 00097 00098 imagetypes["hed"] = IMAGE_IMAGIC; 00099 imagetypes["HED"] = IMAGE_IMAGIC; 00100 00101 imagetypes["imagic"] = IMAGE_IMAGIC; 00102 imagetypes["IMAGIC"] = IMAGE_IMAGIC; 00103 00104 imagetypes["pgm"] = IMAGE_PGM; 00105 imagetypes["PGM"] = IMAGE_PGM; 00106 00107 imagetypes["lst"] = IMAGE_LST; 00108 imagetypes["LST"] = IMAGE_LST; 00109 00110 imagetypes["lsx"] = IMAGE_LSTFAST; // but .lst or another extension would also be ok 00111 imagetypes["LSX"] = IMAGE_LSTFAST; 00112 00113 imagetypes["pif"] = IMAGE_PIF; 00114 imagetypes["PIF"] = IMAGE_PIF; 00115 00116 imagetypes["png"] = IMAGE_PNG; 00117 imagetypes["PNG"] = IMAGE_PNG; 00118 00119 imagetypes["h5"] = IMAGE_HDF; 00120 imagetypes["H5"] = IMAGE_HDF; 00121 00122 imagetypes["hd5"] = IMAGE_HDF; 00123 imagetypes["HD5"] = IMAGE_HDF; 00124 00125 imagetypes["hdf"] = IMAGE_HDF; 00126 imagetypes["HDF"] = IMAGE_HDF; 00127 00128 imagetypes["tif"] = IMAGE_TIFF; 00129 imagetypes["TIF"] = IMAGE_TIFF; 00130 00131 imagetypes["tiff"] = IMAGE_TIFF; 00132 imagetypes["TIFF"] = IMAGE_TIFF; 00133 00134 imagetypes["fts"] = IMAGE_FITS; 00135 imagetypes["FTS"] = IMAGE_FITS; 00136 00137 imagetypes["vtk"] = IMAGE_VTK; 00138 imagetypes["VTK"] = IMAGE_VTK; 00139 00140 imagetypes["hdr"] = IMAGE_SAL; 00141 imagetypes["HDR"] = IMAGE_SAL; 00142 00143 imagetypes["sal"] = IMAGE_SAL; 00144 imagetypes["SAL"] = IMAGE_SAL; 00145 00146 imagetypes["map"] = IMAGE_ICOS; 00147 imagetypes["MAP"] = IMAGE_ICOS; 00148 00149 imagetypes["icos"] = IMAGE_ICOS; 00150 imagetypes["ICOS"] = IMAGE_ICOS; 00151 00152 imagetypes["am"] = IMAGE_AMIRA; 00153 imagetypes["AM"] = IMAGE_AMIRA; 00154 00155 imagetypes["amira"] = IMAGE_AMIRA; 00156 imagetypes["AMIRA"] = IMAGE_AMIRA; 00157 00158 imagetypes["emim"] = IMAGE_EMIM; 00159 imagetypes["EMIM"] = IMAGE_EMIM; 00160 00161 imagetypes["xplor"] = IMAGE_XPLOR; 00162 imagetypes["XPLOR"] = IMAGE_XPLOR; 00163 00164 imagetypes["em"] = IMAGE_EM; 00165 imagetypes["EM"] = IMAGE_EM; 00166 00167 imagetypes["dm2"] = IMAGE_GATAN2; 00168 imagetypes["DM2"] = IMAGE_GATAN2; 00169 00170 imagetypes["v4l"] = IMAGE_V4L; 00171 imagetypes["V4L"] = IMAGE_V4L; 00172 00173 imagetypes["jpg"] = IMAGE_JPEG; 00174 imagetypes["JPG"] = IMAGE_JPEG; 00175 imagetypes["jpeg"] = IMAGE_JPEG; 00176 imagetypes["JPEG"] = IMAGE_JPEG; 00177 00178 imagetypes["df3"] = IMAGE_DF3; 00179 imagetypes["DF3"] = IMAGE_DF3; 00180 00181 imagetypes["Omap"] = IMAGE_OMAP; 00182 imagetypes["omap"] = IMAGE_OMAP; 00183 imagetypes["OMAP"] = IMAGE_OMAP; 00184 imagetypes["BRIX"] = IMAGE_OMAP; 00185 imagetypes["brix"] = IMAGE_OMAP; 00186 imagetypes["DSN6"] = IMAGE_OMAP; 00187 00188 imagetypes["situs"] = IMAGE_SITUS; 00189 imagetypes["SITUS"] = IMAGE_SITUS; 00190 00191 initialized = true; 00192 } 00193 00194 ImageType result = IMAGE_UNKNOWN; 00195 00196 if (imagetypes.find(file_ext) != imagetypes.end()) { 00197 result = imagetypes[file_ext]; 00198 } 00199 00200 EXITFUNC; 00201 return result; 00202 }
EMUtil::ImageType EMUtil::get_image_type | ( | const string & | filename | ) | [static] |
Get an image's format type by processing the first 1K of the image.
filename | Image file name. |
Definition at line 355 of file emutil.cpp.
References Assert, EMAN::Util::change_filename_ext(), ENTERFUNC, EXITFUNC, fast_get_image_type(), FileAccessException, EMAN::Util::get_filename_ext(), EMAN::ImagicIO::HED_EXT, IMAGE_AMIRA, IMAGE_DF3, IMAGE_DM3, IMAGE_EM, IMAGE_FITS, IMAGE_GATAN2, IMAGE_HDF, IMAGE_ICOS, IMAGE_IMAGIC, IMAGE_LST, IMAGE_LSTFAST, IMAGE_MRC, IMAGE_OMAP, IMAGE_PGM, IMAGE_PIF, IMAGE_PNG, IMAGE_SAL, IMAGE_SINGLE_SPIDER, IMAGE_SITUS, IMAGE_SPIDER, IMAGE_TIFF, IMAGE_UNKNOWN, IMAGE_V4L, IMAGE_VTK, IMAGE_XPLOR, ImageFormatException, EMAN::ImagicIO::IMG_EXT, in, EMAN::Df3IO::is_valid(), EMAN::ImagicIO::is_valid(), EMAN::SitusIO::is_valid(), EMAN::OmapIO::is_valid(), EMAN::EmIO::is_valid(), EMAN::FitsIO::is_valid(), EMAN::Gatan2IO::is_valid(), EMAN::XplorIO::is_valid(), EMAN::AmiraIO::is_valid(), EMAN::SalIO::is_valid(), EMAN::IcosIO::is_valid(), EMAN::PgmIO::is_valid(), EMAN::VtkIO::is_valid(), EMAN::PifIO::is_valid(), EMAN::LstFastIO::is_valid(), EMAN::LstIO::is_valid(), EMAN::DM3IO::is_valid(), EMAN::MrcIO::is_valid(), EMAN::SingleSpiderIO::is_valid(), EMAN::SpiderIO::is_valid(), portable_fseek(), and portable_ftell().
Referenced by get_imageio(), and getRenderMinMax().
00356 { 00357 ENTERFUNC; 00358 Assert(in_filename != ""); 00359 00360 #ifdef ENABLE_V4L2 00361 if (in_filename.compare(0,5,"/dev/")==0) return IMAGE_V4L; 00362 #endif 00363 00364 string filename = in_filename; 00365 00366 string old_ext = Util::get_filename_ext(filename); 00367 if (old_ext == ImagicIO::IMG_EXT) { 00368 filename = Util::change_filename_ext(filename, ImagicIO::HED_EXT); 00369 } 00370 00371 FILE *in = fopen(filename.c_str(), "rb"); 00372 if (!in) { 00373 throw FileAccessException(filename); 00374 } 00375 00376 char first_block[1024]; 00377 size_t n = fread(first_block, sizeof(char), sizeof(first_block), in); 00378 portable_fseek(in, 0, SEEK_END); 00379 off_t file_size = portable_ftell(in); 00380 00381 if (n == 0) { 00382 // This produces annoying console messages 00383 // LOGERR("file '%s' is an empty file", filename.c_str()); 00384 fclose(in); 00385 return IMAGE_UNKNOWN; 00386 } 00387 fclose(in); 00388 00389 ImageType image_type = fast_get_image_type(filename, first_block, file_size); 00390 if (image_type != IMAGE_UNKNOWN) { 00391 return image_type; 00392 } 00393 00394 if (SpiderIO::is_valid(first_block)) { 00395 image_type = IMAGE_SPIDER; 00396 } 00397 else if (SingleSpiderIO::is_valid(first_block)) { 00398 image_type = IMAGE_SINGLE_SPIDER; 00399 } 00400 else if (MrcIO::is_valid(first_block, file_size)) { 00401 image_type = IMAGE_MRC; 00402 } 00403 else if (DM3IO::is_valid(first_block)) { 00404 image_type = IMAGE_DM3; 00405 } 00406 #ifdef EM_HDF5 00407 else if (HdfIO2::is_valid(first_block)) { 00408 image_type = IMAGE_HDF; 00409 } 00410 #endif 00411 else if (LstIO::is_valid(first_block)) { 00412 image_type = IMAGE_LST; 00413 } 00414 else if (LstFastIO::is_valid(first_block)) { 00415 image_type = IMAGE_LSTFAST; 00416 } 00417 #ifdef EM_TIFF 00418 else if (TiffIO::is_valid(first_block)) { 00419 image_type = IMAGE_TIFF; 00420 } 00421 #endif 00422 else if (PifIO::is_valid(first_block)) { 00423 image_type = IMAGE_PIF; 00424 } 00425 #ifdef EM_PNG 00426 else if (PngIO::is_valid(first_block)) { 00427 image_type = IMAGE_PNG; 00428 } 00429 #endif 00430 else if (VtkIO::is_valid(first_block)) { 00431 image_type = IMAGE_VTK; 00432 } 00433 else if (PgmIO::is_valid(first_block)) { 00434 image_type = IMAGE_PGM; 00435 } 00436 else if (IcosIO::is_valid(first_block)) { 00437 image_type = IMAGE_ICOS; 00438 } 00439 else if (SalIO::is_valid(first_block)) { 00440 image_type = IMAGE_SAL; 00441 } 00442 else if (AmiraIO::is_valid(first_block)) { 00443 image_type = IMAGE_AMIRA; 00444 } 00445 else if (XplorIO::is_valid(first_block)) { 00446 image_type = IMAGE_XPLOR; 00447 } 00448 else if (Gatan2IO::is_valid(first_block)) { 00449 image_type = IMAGE_GATAN2; 00450 } 00451 else if (FitsIO::is_valid(first_block)) { 00452 image_type = IMAGE_FITS; 00453 } 00454 else if (EmIO::is_valid(first_block, file_size)) { 00455 image_type = IMAGE_EM; 00456 } 00457 else if(OmapIO::is_valid(first_block, file_size)) { 00458 image_type = IMAGE_OMAP; 00459 } 00460 else if(SitusIO::is_valid(first_block)) { 00461 image_type = IMAGE_SITUS; 00462 } 00463 else if (ImagicIO::is_valid(first_block)) { 00464 image_type = IMAGE_IMAGIC; 00465 } 00466 else if (Df3IO::is_valid(first_block)) { 00467 image_type = IMAGE_DF3; 00468 } 00469 else { 00470 //LOGERR("I don't know this image's type: '%s'", filename.c_str()); 00471 throw ImageFormatException("invalid image type"); 00472 } 00473 00474 EXITFUNC; 00475 return image_type; 00476 }
ImageIO * EMUtil::get_imageio | ( | const string & | filename, | |
int | rw_mode, | |||
ImageType | image_type = IMAGE_UNKNOWN | |||
) | [static] |
Get an ImageIO object.
It may be a newly created object. Or an object stored in the cache.
filename | Image file name. | |
rw_mode | ImageIO read/write mode. | |
image_type | Image format type. |
Definition at line 502 of file emutil.cpp.
References EMAN::GlobalCache::add_imageio(), Assert, ENTERFUNC, EXITFUNC, get_image_type(), EMAN::GlobalCache::get_imageio(), IMAGE_AMIRA, IMAGE_DF3, IMAGE_DM3, IMAGE_EM, IMAGE_FITS, IMAGE_GATAN2, IMAGE_HDF, IMAGE_ICOS, IMAGE_IMAGIC, IMAGE_JPEG, IMAGE_LST, IMAGE_LSTFAST, IMAGE_MRC, IMAGE_OMAP, IMAGE_PGM, IMAGE_PIF, IMAGE_PNG, IMAGE_SAL, IMAGE_SINGLE_SPIDER, IMAGE_SITUS, IMAGE_SPIDER, IMAGE_TIFF, IMAGE_UNKNOWN, IMAGE_V4L, IMAGE_VTK, IMAGE_XPLOR, ImageFormatException, EMAN::GlobalCache::instance(), EMAN::ImageIO::READ_ONLY, EMAN::ImageIO::READ_WRITE, and EMAN::ImageIO::WRITE_ONLY.
Referenced by EMAN::LstIO::calc_ref_image_index(), EMAN::LstFastIO::calc_ref_image_index(), get_image_count(), EMAN::EMData::read_image(), and EMAN::EMData::write_image().
00504 { 00505 ENTERFUNC; 00506 Assert(filename != ""); 00507 Assert(rw == ImageIO::READ_ONLY || 00508 rw == ImageIO::READ_WRITE || 00509 rw == ImageIO::WRITE_ONLY); 00510 00511 ImageIO *imageio = 0; 00512 #ifdef IMAGEIO_CACHE 00513 imageio = GlobalCache::instance()->get_imageio(filename, rw); 00514 if (imageio) { 00515 return imageio; 00516 } 00517 #endif 00518 00519 ImageIO::IOMode rw_mode = static_cast < ImageIO::IOMode > (rw); 00520 00521 if (image_type == IMAGE_UNKNOWN) { 00522 if(rw == ImageIO::WRITE_ONLY || rw == ImageIO::READ_WRITE) { 00523 throw ImageFormatException("writing to this image format not supported."); 00524 } 00525 00526 image_type = get_image_type(filename); 00527 } 00528 00529 switch (image_type) { 00530 #ifdef ENABLE_V4L2 00531 case IMAGE_V4L: 00532 imageio = new V4L2IO(filename, rw_mode); 00533 break; 00534 #endif 00535 case IMAGE_MRC: 00536 imageio = new MrcIO(filename, rw_mode); 00537 break; 00538 case IMAGE_IMAGIC: 00539 imageio = new ImagicIO2(filename, rw_mode); 00540 if (rw_mode==ImageIO::READ_ONLY && ((ImagicIO2 *)imageio)->init_test()==-1 ) { 00541 delete imageio; 00542 imageio = new ImagicIO(filename, rw_mode); 00543 } 00544 break; 00545 case IMAGE_DM3: 00546 imageio = new DM3IO(filename, rw_mode); 00547 break; 00548 #ifdef EM_TIFF 00549 case IMAGE_TIFF: 00550 imageio = new TiffIO(filename, rw_mode); 00551 break; 00552 #endif 00553 #ifdef EM_HDF5 00554 case IMAGE_HDF: 00555 imageio = new HdfIO2(filename, rw_mode); 00556 if (((HdfIO2 *)imageio)->init_test()==-1) { 00557 delete imageio; 00558 imageio = new HdfIO(filename, rw_mode); 00559 } 00560 break; 00561 #endif 00562 case IMAGE_LST: 00563 imageio = new LstIO(filename, rw_mode); 00564 break; 00565 case IMAGE_LSTFAST: 00566 imageio = new LstFastIO(filename, rw_mode); 00567 break; 00568 case IMAGE_PIF: 00569 imageio = new PifIO(filename, rw_mode); 00570 break; 00571 case IMAGE_VTK: 00572 imageio = new VtkIO(filename, rw_mode); 00573 break; 00574 case IMAGE_SPIDER: 00575 imageio = new SpiderIO(filename, rw_mode); 00576 break; 00577 case IMAGE_SINGLE_SPIDER: 00578 imageio = new SingleSpiderIO(filename, rw_mode); 00579 break; 00580 case IMAGE_PGM: 00581 imageio = new PgmIO(filename, rw_mode); 00582 break; 00583 #ifdef EM_JPEG 00584 case IMAGE_JPEG: 00585 imageio = new JpegIO(filename,rw_mode); 00586 break; 00587 #endif 00588 case IMAGE_ICOS: 00589 imageio = new IcosIO(filename, rw_mode); 00590 break; 00591 #ifdef EM_PNG 00592 case IMAGE_PNG: 00593 imageio = new PngIO(filename, rw_mode); 00594 break; 00595 #endif 00596 case IMAGE_SAL: 00597 imageio = new SalIO(filename, rw_mode); 00598 break; 00599 case IMAGE_AMIRA: 00600 imageio = new AmiraIO(filename, rw_mode); 00601 break; 00602 case IMAGE_GATAN2: 00603 imageio = new Gatan2IO(filename, rw_mode); 00604 break; 00605 case IMAGE_EM: 00606 imageio = new EmIO(filename, rw_mode); 00607 break; 00608 case IMAGE_XPLOR: 00609 imageio = new XplorIO(filename, rw_mode); 00610 break; 00611 case IMAGE_FITS: 00612 imageio = new FitsIO(filename, rw_mode); 00613 break; 00614 case IMAGE_DF3: 00615 imageio = new Df3IO(filename, rw_mode); 00616 break; 00617 case IMAGE_OMAP: 00618 imageio = new OmapIO(filename, rw_mode); 00619 break; 00620 case IMAGE_SITUS: 00621 imageio = new SitusIO(filename, rw_mode); 00622 break; 00623 default: 00624 break; 00625 } 00626 #ifdef IMAGEIO_CACHE 00627 GlobalCache::instance()->add_imageio(filename, rw, imageio); 00628 #endif 00629 EXITFUNC; 00630 return imageio; 00631 }
const char * EMUtil::get_imagetype_name | ( | EMUtil::ImageType | type | ) | [static] |
Give each image type a meaningful name.
type | Image format type. |
Definition at line 635 of file emutil.cpp.
References IMAGE_AMIRA, IMAGE_DF3, IMAGE_DM3, IMAGE_EM, IMAGE_EMIM, IMAGE_FITS, IMAGE_GATAN2, IMAGE_HDF, IMAGE_ICOS, IMAGE_IMAGIC, IMAGE_JPEG, IMAGE_LST, IMAGE_LSTFAST, IMAGE_MRC, IMAGE_OMAP, IMAGE_PGM, IMAGE_PIF, IMAGE_PNG, IMAGE_SAL, IMAGE_SINGLE_SPIDER, IMAGE_SITUS, IMAGE_SPIDER, IMAGE_TIFF, IMAGE_UNKNOWN, IMAGE_V4L, IMAGE_VTK, and IMAGE_XPLOR.
00636 { 00637 switch (t) { 00638 case IMAGE_V4L: 00639 return "V4L2"; 00640 break; 00641 case IMAGE_MRC: 00642 return "MRC"; 00643 break; 00644 case IMAGE_SPIDER: 00645 return "SPIDER"; 00646 break; 00647 case IMAGE_SINGLE_SPIDER: 00648 return "Single-SPIDER"; 00649 break; 00650 case IMAGE_IMAGIC: 00651 return "IMAGIC"; 00652 break; 00653 case IMAGE_PGM: 00654 return "PGM"; 00655 break; 00656 case IMAGE_LST: 00657 return "LST"; 00658 break; 00659 case IMAGE_LSTFAST: 00660 return "Fast LST"; 00661 break; 00662 case IMAGE_PIF: 00663 return "PIF"; 00664 break; 00665 case IMAGE_PNG: 00666 return "PNG"; 00667 break; 00668 case IMAGE_HDF: 00669 return "HDF5"; 00670 break; 00671 case IMAGE_DM3: 00672 return "GatanDM3"; 00673 break; 00674 case IMAGE_TIFF: 00675 return "TIFF"; 00676 break; 00677 case IMAGE_VTK: 00678 return "VTK"; 00679 break; 00680 case IMAGE_SAL: 00681 return "HDR"; 00682 break; 00683 case IMAGE_ICOS: 00684 return "ICOS_MAP"; 00685 break; 00686 case IMAGE_EMIM: 00687 return "EMIM"; 00688 break; 00689 case IMAGE_GATAN2: 00690 return "GatanDM2"; 00691 break; 00692 case IMAGE_JPEG: 00693 return "JPEG"; 00694 break; 00695 case IMAGE_AMIRA: 00696 return "AmiraMesh"; 00697 break; 00698 case IMAGE_XPLOR: 00699 return "XPLOR"; 00700 break; 00701 case IMAGE_EM: 00702 return "EM"; 00703 break; 00704 case IMAGE_FITS: 00705 return "FITS"; 00706 break; 00707 case IMAGE_DF3: 00708 return "DF3"; 00709 break; 00710 case IMAGE_OMAP: 00711 return "OMAP"; 00712 break; 00713 case IMAGE_SITUS: 00714 return "SITUS"; 00715 break; 00716 case IMAGE_UNKNOWN: 00717 return "unknown"; 00718 } 00719 return "unknown"; 00720 }
void EMUtil::get_region_dims | ( | const Region * | area, | |
int | nx, | |||
int * | area_x, | |||
int | ny, | |||
int * | area_y, | |||
int | nz = 1 , |
|||
int * | area_z = 0 | |||
) | [static] |
Get a region's dimensions.
area | The region area. | |
nx | Image x size. | |
area_x | The pointer used to return the region x size. | |
ny | Image y size. | |
area_y | The pointer used to return the region y size. | |
nz | Image z size. | |
area_z | The pointer used to return the region z size. |
Definition at line 753 of file emutil.cpp.
References Assert, EMAN::Region::get_ndim(), and EMAN::Region::get_size().
Referenced by process_ascii_region_io(), process_region_io(), EMAN::MrcIO::read_fei_header(), and EMAN::MrcIO::read_mrc_header().
00755 { 00756 Assert(area_x); 00757 Assert(area_y); 00758 00759 if (!area) { 00760 *area_x = nx; 00761 *area_y = ny; 00762 if (area_z) { 00763 *area_z = nz; 00764 } 00765 } 00766 else { 00767 Vec3i size = area->get_size(); 00768 *area_x = size[0]; 00769 *area_y = size[1]; 00770 00771 if (area_z) { 00772 if (area->get_ndim() > 2 && nz > 1) { 00773 *area_z = size[2]; 00774 } 00775 else { 00776 *area_z = 1; 00777 } 00778 } 00779 00780 } 00781 }
void EMUtil::get_region_origins | ( | const Region * | area, | |
int * | p_x0, | |||
int * | p_y0, | |||
int * | p_z0 = 0 , |
|||
int | nz = 1 , |
|||
int | image_index = 0 | |||
) | [static] |
Get a region's original locations.
area | The region area. | |
p_x0 | The pointer used to return the region x origin. | |
p_y0 | The pointer used to return the region y origin. | |
p_z0 | The pointer used to return the region z origin. | |
nz | Image z size. | |
image_index | Image index. |
Definition at line 783 of file emutil.cpp.
References Assert, EMAN::Region::get_ndim(), and EMAN::Region::origin.
00785 { 00786 Assert(p_x0); 00787 Assert(p_y0); 00788 00789 if (area) { 00790 *p_x0 = static_cast < int >(area->origin[0]); 00791 *p_y0 = static_cast < int >(area->origin[1]); 00792 00793 if (p_z0 && nz > 1 && area->get_ndim() > 2) { 00794 *p_z0 = static_cast < int >(area->origin[2]); 00795 } 00796 } 00797 else { 00798 *p_x0 = 0; 00799 *p_y0 = 0; 00800 if (p_z0) { 00801 *p_z0 = nz > 1 ? 0 : image_index; 00802 } 00803 } 00804 }
void EMUtil::getRenderMinMax | ( | float * | data, | |
const int | nx, | |||
const int | ny, | |||
float & | rendermin, | |||
float & | rendermax, | |||
const int | nz = 1 | |||
) | [static] |
Calculate the min and max pixel value acceptedfor image nomalization, if we did not get them from image attribute dictionary, or they are not valid values rendermin = mean - 3*sigma rendermax = mean + 3*sigma.
[in] | data | 2D image's data array |
[in] | nx | x dimension size |
[in] | ny | y dimension size |
[out] | rendermin | the minmal value for normalization |
[out] | rendermax | the maximum value for normalization |
[in] | nz | z dimension size |
Definition at line 1541 of file emutil.cpp.
References get_image_type(), IMAGE_HDF, ImageFormatException, key, max, min, EMAN::ImageIO::READ_ONLY, EMAN::ImageIO::READ_WRITE, sqrt(), and EMAN::ImageIO::WRITE_ONLY.
01542 { 01543 #ifdef _WIN32 01544 if (rendermax<=rendermin || _isnan(rendermin) || _isnan(rendermax)) { 01545 #else 01546 if (rendermax<=rendermin || std::isnan(rendermin) || std::isnan(rendermax)) { 01547 #endif 01548 float m=0.0f,s=0.0f; 01549 01550 size_t size = (size_t)nx*ny*nz; 01551 float min=data[0],max=data[0]; 01552 01553 for (size_t i=0; i<size; ++i) { m+=data[i]; s+=data[i]*data[i]; min=data[i]<min?data[i]:min; max=data[i]>max?data[i]:max; } 01554 m/=(float)(size); 01555 s=sqrt(s/(float)(size)-m*m); 01556 #ifdef _WIN32 01557 if (s<=0 || _isnan(s)) s=1.0; // this means all data values are the same 01558 #else 01559 if (s<=0 || std::isnan(s)) s=1.0; // this means all data values are the same 01560 #endif //_WIN32 01561 rendermin=m-s*5.0f; 01562 rendermax=m+s*5.0f; 01563 if (rendermin<=min) rendermin=min; 01564 if (rendermax>=max) rendermax=max; 01565 } 01566 }
bool EMUtil::is_complex_type | ( | EMDataType | datatype | ) | [static] |
Definition at line 1013 of file emutil.cpp.
References EM_FLOAT_COMPLEX, EM_SHORT_COMPLEX, and EM_USHORT_COMPLEX.
Referenced by EMAN::TestUtil::make_image_file_by_mode(), and EMAN::TestUtil::verify_image_file_by_mode().
01014 { 01015 if (datatype == EM_SHORT_COMPLEX || 01016 datatype == EM_USHORT_COMPLEX || 01017 datatype == EM_FLOAT_COMPLEX) { 01018 return true; 01019 } 01020 return false; 01021 }
Check whether two EMData images have the same CTF parameters.
Definition at line 1125 of file emutil.cpp.
References EMAN::Ctf::equal(), EMAN::EMData::get_ctf(), EMAN::EMData::has_ctff(), and NullPointerException.
01126 { 01127 if (!image1) { 01128 throw NullPointerException("image1 is NULL"); 01129 } 01130 if (!image2) { 01131 throw NullPointerException("image2 is NULL"); 01132 } 01133 01134 Ctf *ctf1 = image1->get_ctf(); 01135 Ctf *ctf2 = image2->get_ctf(); 01136 01137 if ((!ctf1 && !ctf2) && (image1->has_ctff() == false && image2->has_ctff() == false)) { 01138 return true; 01139 } 01140 01141 if (ctf1 && ctf2) { 01142 bool result = ctf1->equal(ctf2); 01143 delete ctf1; 01144 ctf1 = 0; 01145 delete ctf2; 01146 ctf2 = 0; 01147 01148 return result; 01149 } 01150 return false; 01151 }
Check whether two EMData images are of the same size.
Definition at line 1003 of file emutil.cpp.
References EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), and EMAN::EMData::get_zsize().
Referenced by EMAN::CtfAverager::add_image(), EMAN::CtfCAutoAverager::add_image(), EMAN::CtfCWautoAverager::add_image(), EMAN::IterationAverager::add_image(), EMAN::MinMaxAverager::add_image(), EMAN::ImageAverager::add_image(), EMAN::TomoAverager::add_image(), EMAN::EMData::add_incoherent(), EMAN::FRM2DAligner::align(), EMAN::TranslationalAligner::align(), EMAN::EMData::calc_ccfx(), EMAN::NormalizeMaskProcessor::calc_mean(), EMAN::EMData::calc_mutual_correlation(), EMAN::NormalizeMaskProcessor::calc_sigma(), EMAN::EMData::common_lines(), EMAN::EMData::common_lines_real(), EMAN::EMData::convolute(), EMAN::EMData::dot_rotate_translate(), EMAN::EMData::get_circle_mean(), EMAN::Util::im_diff(), EMAN::IndexMaskFileProcessor::process_inplace(), and EMAN::Cmp::validate_input_args().
01004 { 01005 if (em1->get_xsize() == em2->get_xsize() && 01006 em1->get_ysize() == em2->get_ysize() && 01007 em1->get_zsize() == em2->get_zsize()) { 01008 return true; 01009 } 01010 return false; 01011 }
bool EMUtil::is_valid_filename | ( | const string & | filename | ) | [static] |
Ask whether or not the given filename is a valid EM image filename This is the same thing as checking whether or not the return value of EMUtil.get_image_ext_type is IMAGE_UNKNOWN.
filename | Image file name. |
Definition at line 206 of file emutil.cpp.
References EMAN::Util::get_filename_ext(), get_image_ext_type(), and IMAGE_UNKNOWN.
00206 { 00207 ImageType type = get_image_ext_type(Util::get_filename_ext(filename)); 00208 return (type != IMAGE_UNKNOWN); 00209 }
void EMUtil::jump_lines | ( | FILE * | file, | |
int | nlines | |||
) | [static] |
Definition at line 1344 of file emutil.cpp.
References Assert.
Referenced by jump_lines_by_items(), and process_ascii_region_io().
01345 { 01346 Assert(file); 01347 01348 if (nlines > 0) { 01349 char line[MAXPATHLEN]; 01350 for (int l = 0; l < nlines; l++) { 01351 if (!fgets(line, sizeof(line), file)) { 01352 Assert("read xplor file failed"); 01353 } 01354 } 01355 } 01356 }
void EMUtil::jump_lines_by_items | ( | FILE * | file, | |
int | nitems, | |||
int | nitems_per_line | |||
) | [static, private] |
Definition at line 1325 of file emutil.cpp.
References Assert, and jump_lines().
Referenced by process_ascii_region_io().
01326 { 01327 Assert(file); 01328 Assert(nitems_per_line > 0); 01329 01330 if (nitems <= 0) { 01331 return; 01332 } 01333 01334 int nlines = nitems / nitems_per_line; 01335 if ((nitems % nitems_per_line) != 0) { 01336 nlines++; 01337 } 01338 if (nlines > 0) { 01339 jump_lines(file, nlines); 01340 } 01341 }
Definition at line 1060 of file emutil.cpp.
References get_data(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::EMData::set_size(), EMAN::EMData::update(), and v.
01061 { 01062 if (image_list.size() == 0) { 01063 return 0; 01064 } 01065 01066 EMData *image0 = image_list[0]; 01067 int image0_nx = image0->get_xsize(); 01068 int image0_ny = image0->get_ysize(); 01069 int image0_nz = image0->get_zsize(); 01070 size_t size = (size_t)image0_nx * image0_ny * image0_nz; 01071 01072 EMData *result = new EMData(); 01073 01074 result->set_size(image0_nx, image0_ny, image0_nz); 01075 01076 float *dest = result->get_data(); 01077 int nitems = static_cast < int >(image_list.size()); 01078 float *srt = new float[nitems]; 01079 float **src = new float *[nitems]; 01080 01081 for (int i = 0; i < nitems; i++) { 01082 src[i] = image_list[i]->get_data(); 01083 } 01084 01085 for (size_t i = 0; i < size; ++i) { 01086 for (int j = 0; j < nitems; j++) { 01087 srt[j] = src[j][i]; 01088 } 01089 01090 for (int j = 0; j < nitems; j++) { 01091 for (int k = j + 1; k < nitems; k++) { 01092 if (srt[j] < srt[k]) { 01093 float v = srt[j]; 01094 srt[j] = srt[k]; 01095 srt[k] = v; 01096 } 01097 } 01098 } 01099 01100 int l = nitems / 2; 01101 if (nitems < 3) { 01102 dest[i] = srt[l]; 01103 } 01104 else { 01105 dest[i] = (srt[l] + srt[l + 1] + srt[l - 1]) / 3.0f; 01106 } 01107 } 01108 01109 if( srt ) 01110 { 01111 delete[]srt; 01112 srt = 0; 01113 } 01114 if( src ) 01115 { 01116 delete[]src; 01117 src = 0; 01118 } 01119 01120 result->update(); 01121 01122 return result; 01123 }
void EMUtil::process_ascii_region_io | ( | float * | data, | |
FILE * | file, | |||
int | rw_mode, | |||
int | image_index, | |||
size_t | mode_size, | |||
int | nx, | |||
int | ny, | |||
int | nz, | |||
const Region * | area, | |||
bool | has_index_line, | |||
int | nitems_per_line, | |||
const char * | outformat | |||
) | [static] |
Works for regions that are outside the image data dimension area.
The only function that calls this is in xplorio.cpp - that function throws if the region is invalid.
Definition at line 1216 of file emutil.cpp.
References Assert, exclude_numbers_io(), get_region_dims(), jump_lines(), jump_lines_by_items(), EMAN::Region::origin, process_lines_io(), process_numbers_io(), EMAN::ImageIO::READ_ONLY, EMAN::ImageIO::READ_WRITE, and EMAN::ImageIO::WRITE_ONLY.
01220 { 01221 Assert(data != 0); 01222 Assert(file != 0); 01223 Assert(rw_mode == ImageIO::READ_ONLY || 01224 rw_mode == ImageIO::READ_WRITE || 01225 rw_mode == ImageIO::WRITE_ONLY); 01226 01227 int xlen = 0, ylen = 0, zlen = 0; 01228 get_region_dims(area, nx, &xlen, ny, &ylen, nz, &zlen); 01229 01230 int x0 = 0; 01231 int y0 = 0; 01232 int z0 = 0; 01233 01234 if (area) { 01235 x0 = (int)area->origin[0]; 01236 y0 = (int)area->origin[1]; 01237 z0 = (int)area->origin[2]; 01238 } 01239 01240 int nlines_per_sec = (nx *ny) / nitems_per_line; 01241 int nitems_last_line = (nx * ny) % nitems_per_line; 01242 if (nitems_last_line != 0) { 01243 nlines_per_sec++; 01244 } 01245 01246 if (has_index_line) { 01247 nlines_per_sec++; 01248 } 01249 01250 if (z0 > 0) { 01251 jump_lines(file, z0 * nlines_per_sec); 01252 } 01253 01254 01255 int nlines_pre_sec = (y0 * nx + x0) / nitems_per_line; 01256 int gap_nitems = nx - xlen; 01257 int ti = 0; 01258 int rlines = 0; 01259 01260 for (int k = 0; k < zlen; k++) { 01261 EMUtil::jump_lines(file, nlines_pre_sec+1); 01262 01263 int head_nitems = (y0 * nx + x0) % nitems_per_line; 01264 int tail_nitems = 0; 01265 bool is_head_read = false; 01266 01267 for (int j = 0; j < ylen; j++) { 01268 01269 if (head_nitems > 0 && !is_head_read) { 01270 EMUtil::process_numbers_io(file, rw_mode, nitems_per_line, mode_size, 01271 nitems_per_line-head_nitems, 01272 nitems_per_line-1, data, &ti, outformat); 01273 rlines++; 01274 } 01275 01276 EMUtil::process_lines_io(file, rw_mode, nitems_per_line, 01277 mode_size, (xlen - head_nitems), 01278 data, &ti, outformat); 01279 01280 rlines += ((xlen - head_nitems)/nitems_per_line); 01281 01282 tail_nitems = (xlen - head_nitems) % nitems_per_line; 01283 01284 if ((gap_nitems + tail_nitems) > 0) { 01285 head_nitems = nitems_per_line - 01286 (gap_nitems + tail_nitems) % nitems_per_line; 01287 } 01288 else { 01289 head_nitems = 0; 01290 } 01291 01292 is_head_read = false; 01293 01294 if (tail_nitems > 0) { 01295 if ((gap_nitems < (nitems_per_line-tail_nitems)) && 01296 (j != (ylen-1))) { 01297 EMUtil::exclude_numbers_io(file, rw_mode, nitems_per_line, 01298 mode_size, tail_nitems, 01299 tail_nitems+gap_nitems-1, data, &ti, outformat); 01300 is_head_read = true; 01301 rlines++; 01302 } 01303 else { 01304 EMUtil::process_numbers_io(file, rw_mode, nitems_per_line, mode_size, 01305 0, tail_nitems-1, data, &ti, outformat); 01306 rlines++; 01307 } 01308 } 01309 01310 if (gap_nitems > (nitems_per_line-tail_nitems)) { 01311 int gap_nlines = (gap_nitems - (nitems_per_line-tail_nitems)) / 01312 nitems_per_line; 01313 if (gap_nlines > 0 && j != (ylen-1)) { 01314 EMUtil::jump_lines(file, gap_nlines); 01315 } 01316 } 01317 } 01318 01319 int ytail_nitems = (ny-ylen-y0) * nx + (nx-xlen-x0) - (nitems_per_line-tail_nitems); 01320 EMUtil::jump_lines_by_items(file, ytail_nitems, nitems_per_line); 01321 } 01322 }
void EMUtil::process_lines_io | ( | FILE * | file, | |
int | rw_mode, | |||
int | nitems_per_line, | |||
size_t | mode_size, | |||
int | nitems, | |||
float * | data, | |||
int * | p_i, | |||
const char * | outformat | |||
) | [static, private] |
Definition at line 1463 of file emutil.cpp.
References Assert, and process_numbers_io().
Referenced by process_ascii_region_io().
01467 { 01468 Assert(file); 01469 Assert(data); 01470 Assert(p_i); 01471 01472 if (nitems > 0) { 01473 int nlines = nitems / nitems_per_line; 01474 for (int i = 0; i < nlines; i++) { 01475 EMUtil::process_numbers_io(file, rw_mode, nitems_per_line, mode_size, 0, 01476 nitems_per_line-1, data, p_i, outformat); 01477 } 01478 } 01479 }
void EMUtil::process_numbers_io | ( | FILE * | file, | |
int | rw_mode, | |||
int | nitems_per_line, | |||
size_t | mode_size, | |||
int | start, | |||
int | end, | |||
float * | data, | |||
int * | p_i, | |||
const char * | outformat | |||
) | [static, private] |
Definition at line 1358 of file emutil.cpp.
References Assert, portable_fseek(), and EMAN::ImageIO::READ_ONLY.
Referenced by process_ascii_region_io(), and process_lines_io().
01361 { 01362 Assert(file); 01363 Assert(start >= 0); 01364 Assert(start <= end); 01365 Assert(end <= nitems_per_line); 01366 Assert(data); 01367 Assert(p_i); 01368 Assert(outformat); 01369 01370 char line[MAXPATHLEN]; 01371 01372 if (rw_mode == ImageIO::READ_ONLY) { 01373 if (!fgets(line, sizeof(line), file)) { 01374 Assert("read xplor file failed"); 01375 } 01376 01377 int nitems_in_line = (int) (strlen(line) / mode_size); 01378 Assert(end <= nitems_in_line); 01379 vector<float> d(nitems_in_line); 01380 char * pline = line; 01381 01382 for (int i = 0; i < nitems_in_line; i++) { 01383 sscanf(pline, "%f", &d[i]); 01384 pline += (int)mode_size; 01385 } 01386 01387 01388 for (int i = start; i <= end; i++) { 01389 data[*p_i] = d[i]; 01390 (*p_i)++; 01391 } 01392 } 01393 else { 01394 portable_fseek(file, mode_size * start, SEEK_CUR); 01395 for (int i = start; i <= end; i++) { 01396 fprintf(file, outformat, data[*p_i]); 01397 (*p_i)++; 01398 } 01399 01400 portable_fseek(file, mode_size * (nitems_per_line - end-1)+1, SEEK_CUR); 01401 } 01402 }
void EMUtil::process_region_io | ( | void * | cdata, | |
FILE * | file, | |||
int | rw_mode, | |||
int | image_index, | |||
size_t | mode_size, | |||
int | nx, | |||
int | ny, | |||
int | nz = 1 , |
|||
const Region * | area = 0 , |
|||
bool | need_flip = false , |
|||
ImageType | imgtype = IMAGE_UNKNOWN , |
|||
int | pre_row = 0 , |
|||
int | post_row = 0 | |||
) | [static] |
Process image region IO.
It eithers read a region from an image file. Or write a region to an image file. Works for regions that are outside the image data dimension area.(David Woolford, April 23 2009)
cdata | Data array. | |
file | The image file pointer. | |
rw_mode | Read/write mode. It is either READ_ONLY or WRITE_ONLY. | |
image_index | Image index. | |
mode_size | Pixel size. | |
nx | Image x size. | |
ny | Image y size. | |
nz | Image z size. | |
area | The region to read/write. | |
need_flip | Do we need flip the image? | |
imgtype | The Image type of the processed file. | |
pre_row | File size needed to be skipped before each row. | |
post_row | File size needed to be skipped after each row. |
ImageReadException | If the read has some error. | |
ImageWriteException | If the write has some error. |
Definition at line 807 of file emutil.cpp.
References Assert, EMAN::Region::get_ndim(), EMAN::Region::get_origin(), get_region_dims(), EMAN::Region::get_size(), IMAGE_ICOS, ImageReadException, ImageWriteException, portable_fseek(), EMAN::ImageIO::READ_ONLY, EMAN::ImageIO::READ_WRITE, UnexpectedBehaviorException, and EMAN::ImageIO::WRITE_ONLY.
Referenced by EMAN::EMData::read_data(), EMAN::EMData::write_data(), and EMAN::SpiderIO::write_single_data().
00812 { 00813 Assert(vdata != 0); 00814 Assert(file != 0); 00815 Assert(rw_mode == ImageIO::READ_ONLY || 00816 rw_mode == ImageIO::READ_WRITE || 00817 rw_mode == ImageIO::WRITE_ONLY); 00818 00819 if (mode_size == 0) throw UnexpectedBehaviorException("The mode size was 0?"); 00820 00821 unsigned char * cdata = (unsigned char *)vdata; 00822 00823 int dx0 = 0; // data x0 00824 int dy0 = 0; // data y0 00825 int dz0 = 0; // data z0 00826 00827 int fx0 = 0; // file x0 00828 int fy0 = 0; // file y0 00829 int fz0 = nz > 1 ? 0 : image_index; // file z0 00830 00831 00832 int xlen = 0; 00833 int ylen = 0; 00834 int zlen = 0; 00835 get_region_dims(area, nx, &xlen, ny, &ylen, nz, &zlen); 00836 00837 if (area) { // Accommodate for all boundary overlaps of the region 00838 00839 Vec3i origin = area->get_origin(); 00840 00841 00842 fx0 = origin[0]; dx0 = origin[0]; 00843 fy0 = origin[1]; dy0 = origin[1]; 00844 if (nz > 1 && area->get_ndim() > 2) { 00845 fz0 = origin[2]; dz0 = origin[2]; 00846 } 00847 00848 if (need_flip) { 00849 Vec3i size = area->get_size(); 00850 fy0 = ny-(origin[1]+size[1]); 00851 } 00852 00853 if (fx0 < 0) { 00854 dx0 *= -1; 00855 xlen = xlen + fx0; // because there are less reads 00856 fx0 = 0; 00857 }else { 00858 dx0 = 0; 00859 //fx0 *= -1; 00860 } 00861 if (fy0 < 0) { 00862 dy0 *= -1; 00863 ylen = ylen + fy0; // because there are less reads 00864 fy0 = 0; 00865 }else { 00866 if (need_flip){ 00867 dy0*=-1; 00868 } 00869 else dy0 = 0; 00870 //fy0 *= -1; 00871 } 00872 if (fz0 < 0) { 00873 dz0 *= -1; 00874 zlen = zlen + fz0; // because there are less reads 00875 fz0 = 0; 00876 }else { 00877 dz0 = 0; 00878 //fz0 *= -1; 00879 } 00880 00881 if ((fx0 + xlen)> nx) xlen = nx-fx0; 00882 if ((fy0 + ylen)> ny) ylen = ny-fy0; 00883 if ((fz0 + zlen)> nz) zlen = nz-fz0; 00884 if ( xlen <= 0 || ylen <= 0 || zlen <= 0 ) return; // This is fine the region was entirely outside the image 00885 } 00886 00887 if ( xlen <= 0 ) { 00888 cout << "Xlen was too small " << xlen << endl; 00889 return; 00890 } 00891 00892 Vec3i size; 00893 if (area != 0) size = area->get_size(); 00894 else size = Vec3d(nx,ny,nz); 00895 00896 //size_t area_sec_size = xlen * ylen * mode_size; 00897 size_t memory_sec_size = size[0] * size[1] * mode_size; 00898 size_t img_row_size = nx * mode_size + pre_row + post_row; 00899 size_t area_row_size = xlen * mode_size; 00900 size_t memory_row_size = size[0] * mode_size; 00901 00902 if ( area_row_size <= 0 ) { 00903 cout << "Xlen was too small " << xlen << " mode_size " << mode_size << endl; 00904 return; 00905 } 00906 00907 size_t x_pre_gap = fx0 * mode_size; 00908 size_t x_post_gap = (nx - fx0 - xlen) * mode_size; 00909 00910 size_t y_pre_gap = fy0 * img_row_size; 00911 size_t y_post_gap = (ny - fy0 - ylen) * img_row_size; 00912 00913 portable_fseek(file, img_row_size * ny * fz0, SEEK_CUR); 00914 00915 float nxlendata[1]; 00916 int floatsize = (int) sizeof(float); 00917 nxlendata[0] = (float)(nx * floatsize); 00918 00919 for (int k = dz0; k < (dz0+zlen); k++) { 00920 if (y_pre_gap > 0) { 00921 portable_fseek(file, y_pre_gap, SEEK_CUR); 00922 } 00923 //long k2 = k * area_sec_size; 00924 long k2 = k*memory_sec_size; 00925 00926 for (int j = dy0; j < (dy0+ylen); j++) { 00927 if (pre_row > 0) { 00928 if (imgtype == IMAGE_ICOS && rw_mode != ImageIO::READ_ONLY && !area) { 00929 fwrite(nxlendata, floatsize, 1, file); 00930 } 00931 else { 00932 portable_fseek(file, pre_row, SEEK_CUR); 00933 } 00934 } 00935 00936 if (x_pre_gap > 0) { 00937 portable_fseek(file, x_pre_gap, SEEK_CUR); 00938 } 00939 00940 int jj = j; 00941 if (need_flip) { 00942 jj = (dy0+ylen) - 1 - j; 00943 if (dy0 > 0 ) { // region considerations add complications in the flipping scenario (imagic format) 00944 jj += dy0; 00945 } 00946 } 00947 00948 if (rw_mode == ImageIO::READ_ONLY) { 00949 if (fread(&cdata[k2 + jj * memory_row_size+dx0*mode_size], 00950 area_row_size, 1, file) != 1) { 00951 cout << jj << " " << k2 << " " << memory_row_size << " " << dx0 << " " << mode_size << " " << area_row_size << " " << cdata << "done" << endl; 00952 throw ImageReadException("", "incomplete data read"); 00953 } 00954 } 00955 else { 00956 if (fwrite(&cdata[k2 + jj * memory_row_size+dx0*mode_size], 00957 area_row_size, 1, file) != 1) { 00958 throw ImageWriteException("", "incomplete data write"); 00959 } 00960 } 00961 00962 if (x_post_gap > 0) { 00963 portable_fseek(file, x_post_gap, SEEK_CUR); 00964 } 00965 00966 if (post_row > 0) { 00967 if (imgtype == IMAGE_ICOS && rw_mode != ImageIO::READ_ONLY && !area) { 00968 fwrite(nxlendata, floatsize, 1, file); 00969 } 00970 else { 00971 portable_fseek(file, post_row, SEEK_CUR); 00972 } 00973 } 00974 } 00975 00976 if (y_post_gap > 0) { 00977 portable_fseek(file, y_post_gap, SEEK_CUR); 00978 } 00979 } 00980 }
Definition at line 1024 of file emutil.cpp.
References data, EMAN::dot(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), NullPointerException, nx, ny, EMAN::EMData::set_size(), EMAN::EMData::update(), x, and y.
01025 { 01026 if (!image) { 01027 throw NullPointerException("NULL Image"); 01028 } 01029 01030 EMData *ret = new EMData(); 01031 int nx = image->get_xsize(); 01032 int ny = image->get_ysize(); 01033 01034 if (maxdy <= 1) { 01035 maxdy = ny / 8; 01036 } 01037 01038 ret->set_size(nx, maxdy, 1); 01039 01040 float *data = image->get_data(); 01041 float *ret_data = ret->get_data(); 01042 01043 for (int x = 0; x < nx; x++) { 01044 for (int y = 0; y < maxdy; y++) { 01045 float dot = 0; 01046 for (int yy = maxdy; yy < ny - maxdy; yy++) { 01047 dot += data[x + (yy + y) * nx] * data[x + (yy - y) * nx]; 01048 } 01049 ret_data[x + y * nx] = dot; 01050 } 01051 } 01052 01053 ret->update(); 01054 01055 return ret; 01056 }