EMAN::EMUtil Class Reference

#include <emutil.h>

List of all members.

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
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 format types. More...

Static Public Member Functions

static EMDatavertical_acf (const EMData *image, int maxdy)
static EMDatamake_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 ImageIOget_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< EMObjectget_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)


Detailed Description

Definition at line 85 of file emutil.h.


Member Enumeration Documentation

enum EMAN::EMUtil::EMDataType

Image pixel data type used in EMAN.

EM_U means "EM unsigned". for example, EM_USHORT means EM unsigned short.

Enumerator:
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                 };

enum EMAN::EMUtil::ImageType

Image format types.

Enumerator:
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 

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                 };


Member Function Documentation

static bool EMAN::EMUtil::cuda_available (  )  [inline, static]

Definition at line 333 of file emutil.h.

00333                                              {
00334 //#ifdef EMAN2_USING_CUDA
00335 //                      return true;
00336 //#else
00337                         return false;
00338 //#endif
00339                 }

void EMUtil::dump_dict ( const Dict dict  )  [static]

Dump a Dict object.

Parameters:
dict A Dict object.

Definition at line 965 of file emutil.cpp.

References get_datatype_string(), EMAN::Dict::keys(), and EMAN::Dict::values().

00966 {
00967         vector < string > keys = dict.keys();
00968         vector < EMObject > values = dict.values();
00969 
00970         for (unsigned int i = 0; i < keys.size(); i++) {
00971                 EMObject obj = values[i];
00972                 if( !obj.is_null() ) {
00973                         string val = obj.to_str();
00974 
00975                         if (keys[i] == "datatype") {
00976                                 val = get_datatype_string((EMDataType) (int) obj);
00977                         }
00978 
00979                         fprintf(stdout, "%25s\t%s\n", keys[i].c_str(), val.c_str());
00980                 }
00981         }
00982 }

static void* EMAN::EMUtil::em_calloc ( const size_t  nmemb,
const size_t  size 
) [inline, static]

Definition at line 345 of file emutil.h.

Referenced by EMAN::EMData::setup4slice().

00345                                                                                     {
00346                         return calloc(nmemb,size);
00347                 }

static void EMAN::EMUtil::em_free ( void *  data  )  [inline, static]

Definition at line 355 of file emutil.h.

Referenced by EMAN::EMData::free_memory(), EMAN::EMData::free_rdata(), EMAN::EMData::set_size(), and EMAN::EMData::setup4slice().

00355                                                       {
00356                         free(data);
00357                 }

static void* EMAN::EMUtil::em_malloc ( const size_t  size  )  [inline, static]

Definition at line 341 of file emutil.h.

Referenced by EMAN::EMData::EMData(), EMAN::EMData::rotate_x(), EMAN::EMData::set_size(), and EMAN::TransformProcessor::transform().

00341                                                                  {
00342                         return malloc(size);
00343                 }

static void EMAN::EMUtil::em_memcpy ( void *  dst,
const void *const   src,
const size_t  size 
) [inline, static]

Definition at line 359 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().

00359                                                                                                 {
00360                         memcpy(dst,src,size);
00361                 }

static void EMAN::EMUtil::em_memset ( void *  data,
const int  value,
const size_t  size 
) [inline, static]

Definition at line 352 of file emutil.h.

Referenced by EMAN::EMData::clip_inplace(), and EMAN::EMData::set_size().

00352                                                                                              {
00353                         memset(data, value, size);
00354                 }

static void* EMAN::EMUtil::em_realloc ( void *  data,
const size_t  new_size 
) [inline, static]

Definition at line 349 of file emutil.h.

Referenced by EMAN::EMData::set_size().

00349                                                                                  {
00350                         return realloc(data, new_size);
00351                 }

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 1387 of file emutil.cpp.

References Assert, portable_fseek(), and EMAN::ImageIO::READ_ONLY.

Referenced by process_ascii_region_io().

01390 {
01391         Assert(file);
01392         Assert(mode_size > 0);
01393         Assert(start >= 0);
01394         Assert(end <= nitems_per_line);
01395         Assert(data);
01396         Assert(p_i);
01397         Assert(outformat);
01398 
01399         char line[MAXPATHLEN];
01400 
01401         if (rw_mode == ImageIO::READ_ONLY) {
01402 
01403                 if (!fgets(line, sizeof(line), file)) {
01404                         Assert("read xplor file failed");
01405                 }
01406 
01407                 int nitems_in_line =  (int) (strlen(line) / mode_size);
01408                 Assert(end <= nitems_in_line);
01409 
01410                 vector<float> d(nitems_in_line);
01411                 char *pline = line;
01412 
01413                 for (int i = 0; i < nitems_in_line; i++) {
01414                         sscanf(pline, "%f", &d[i]);
01415                         pline = pline + (int)mode_size;
01416                 }
01417 
01418 
01419                 for (int i = 0; i < start; i++) {
01420                         data[*p_i] = d[i];
01421                         (*p_i)++;
01422                 }
01423 
01424                 for (int i = end+1; i < nitems_in_line; i++) {
01425                         data[*p_i] = d[i];
01426                         (*p_i)++;
01427                 }
01428         }
01429         else {
01430                 for (int i = 0; i < start; i++) {
01431                         fprintf(file, outformat, data[*p_i]);
01432                         (*p_i)++;
01433                 }
01434 
01435                 portable_fseek(file, (end-start+1) * mode_size, SEEK_CUR);
01436 
01437                 for (int i = end+1; i < nitems_per_line; i++) {
01438                         fprintf(file, outformat, data[*p_i]);
01439                         (*p_i)++;
01440                 }
01441                 portable_fseek(file, 1, SEEK_CUR);
01442         }
01443 }

EMUtil::ImageType EMUtil::fast_get_image_type ( const string &  filename,
const void *  first_block,
off_t  file_size 
) [static, private]

Definition at line 208 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_SPIDER, IMAGE_TIFF, IMAGE_UNKNOWN, IMAGE_V4L, IMAGE_VTK, IMAGE_XPLOR, EMAN::ImagicIO::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().

00211 {
00212         ENTERFUNC;
00213         Assert(filename != "");
00214         Assert(first_block != 0);
00215         Assert(file_size > 0);
00216 
00217 #ifdef ENABLE_V4L2
00218         if (filename.compare(0,5,"/dev/")==0) return IMAGE_V4L;
00219 #endif
00220 
00221         string ext = Util::get_filename_ext(filename);
00222         if (ext == "") {
00223                 return IMAGE_UNKNOWN;
00224         }
00225         ImageType image_type = get_image_ext_type(ext);
00226 
00227         switch (image_type) {
00228         case IMAGE_MRC:
00229                 if (MrcIO::is_valid(first_block, file_size)) {
00230                         return IMAGE_MRC;
00231                 }
00232                 break;
00233         case IMAGE_DM3:
00234                 if (DM3IO::is_valid(first_block)) {
00235                         return IMAGE_DM3;
00236                 }
00237                 break;
00238 #ifdef EM_HDF5
00239         case IMAGE_HDF:
00240                 if (HdfIO2::is_valid(first_block)) {
00241                         return IMAGE_HDF;
00242                 }
00243                 break;
00244 #endif
00245         case IMAGE_LST:
00246                 if (LstIO::is_valid(first_block)) {
00247                         return IMAGE_LST;
00248                 }
00249                 break;
00250         case IMAGE_LSTFAST:
00251                 if (LstFastIO::is_valid(first_block)) {
00252                         return IMAGE_LSTFAST;
00253                 }
00254                 break;
00255 #ifdef EM_TIFF
00256         case IMAGE_TIFF:
00257                 if (TiffIO::is_valid(first_block)) {
00258                         return IMAGE_TIFF;
00259                 }
00260                 break;
00261 #endif
00262         case IMAGE_SPIDER:
00263                 if (SpiderIO::is_valid(first_block)) {
00264                         return IMAGE_SPIDER;
00265                 }
00266                 break;
00267         case IMAGE_SINGLE_SPIDER:
00268                 if (SingleSpiderIO::is_valid(first_block)) {
00269                         return IMAGE_SINGLE_SPIDER;
00270                 }
00271                 break;
00272         case IMAGE_PIF:
00273                 if (PifIO::is_valid(first_block)) {
00274                         return IMAGE_PIF;
00275                 }
00276                 break;
00277 #ifdef EM_PNG
00278         case IMAGE_PNG:
00279                 if (PngIO::is_valid(first_block)) {
00280                         return IMAGE_PNG;
00281                 }
00282                 break;
00283 #endif
00284         case IMAGE_VTK:
00285                 if (VtkIO::is_valid(first_block)) {
00286                         return IMAGE_VTK;
00287                 }
00288                 break;
00289         case IMAGE_PGM:
00290                 if (PgmIO::is_valid(first_block)) {
00291                         return IMAGE_PGM;
00292                 }
00293                 break;
00294         case IMAGE_ICOS:
00295                 if (IcosIO::is_valid(first_block)) {
00296                         return IMAGE_ICOS;
00297                 }
00298                 break;
00299         case IMAGE_SAL:
00300                 if (SalIO::is_valid(first_block)) {
00301                         return IMAGE_SAL;
00302                 }
00303                 break;
00304         case IMAGE_AMIRA:
00305                 if (AmiraIO::is_valid(first_block)) {
00306                         return IMAGE_AMIRA;
00307                 }
00308                 break;
00309         case IMAGE_XPLOR:
00310                 if (XplorIO::is_valid(first_block)) {
00311                         return IMAGE_XPLOR;
00312                 }
00313                 break;
00314         case IMAGE_GATAN2:
00315                 if (Gatan2IO::is_valid(first_block)) {
00316                         return IMAGE_GATAN2;
00317                 }
00318                 break;
00319         case IMAGE_EM:
00320                 if (EmIO::is_valid(first_block, file_size)) {
00321                         return IMAGE_EM;
00322                 }
00323                 break;
00324         case IMAGE_DF3:
00325                 if (EmIO::is_valid(first_block, file_size)) {
00326                         return IMAGE_DF3;
00327                 }
00328                 break;
00329         case IMAGE_OMAP:
00330                 if (OmapIO::is_valid(first_block, file_size)) {
00331                         return IMAGE_OMAP;
00332                 }
00333                 break;
00334         case IMAGE_IMAGIC:
00335                 if (ImagicIO::is_valid(first_block)) {
00336                         return IMAGE_IMAGIC;
00337                 }
00338                 break;
00339         default:
00340                 return IMAGE_UNKNOWN;
00341         }
00342         EXITFUNC;
00343         return IMAGE_UNKNOWN;
00344 }

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.

Parameters:
file_name the image file name
attr_name The header attribute name.
Returns:
the vector of attribute value
Exceptions:
NotExistingObjectException when access an non-existing attribute
InvalidCallException when call this function for a non-stack image

Definition at line 1507 of file emutil.cpp.

References Assert, read_images(), and v.

01508 {
01509         vector<EMObject> v;
01510 
01511         Assert(file_name != "");
01512         Assert(attr_name != "");
01513 
01514         vector< shared_ptr<EMData> > vpImg = EMData::read_images(file_name, vector<int>(), true);
01515         vector< shared_ptr<EMData> >::const_iterator iter;
01516         for(iter = vpImg.begin(); iter!=vpImg.end(); ++iter) {
01517                 v.push_back((*iter)->get_attr_default(attr_name));
01518         }
01519 
01520         return v;
01521 }

const char * EMUtil::get_datatype_string ( EMDataType  type  )  [static]

Give each data type a meaningful name.

Parameters:
type the EMDataType
Returns:
a name for that data type

Definition at line 704 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().

00705 {
00706         switch (type) {
00707         case EM_CHAR:
00708                 return "CHAR";
00709         case EM_UCHAR:
00710                 return "UNSIGNED CHAR";
00711         case EM_SHORT:
00712                 return "SHORT";
00713         case EM_USHORT:
00714                 return "UNSIGNED SHORT";
00715         case EM_INT:
00716                 return "INT";
00717         case EM_UINT:
00718                 return "UNSIGNED INT";
00719         case EM_FLOAT:
00720                 return "FLOAT";
00721         case EM_DOUBLE:
00722                 return "DOUBLE";
00723         case EM_SHORT_COMPLEX:
00724                 return "SHORT_COMPLEX";
00725         case EM_USHORT_COMPLEX:
00726                 return "USHORT_COMPLEX";
00727         case EM_FLOAT_COMPLEX:
00728                 return "FLOAT_COMPLEX";
00729         case EM_UNKNOWN:
00730                 return "UNKNOWN";
00731         }
00732         return "UNKNOWN";
00733 }

vector< string > EMUtil::get_euler_names ( const string &  euler_type  )  [static]

Definition at line 1463 of file emutil.cpp.

References b, and v.

01464 {
01465     vector<string> v;
01466     string b = "euler_";
01467 
01468     if (euler_type == "EMAN") {
01469         v.push_back(b + "alt");
01470         v.push_back(b + "az");
01471         v.push_back(b + "phi");
01472     }
01473     else if (euler_type == "MRC") {
01474         v.push_back(b + "theta");
01475         v.push_back(b + "phi");
01476         v.push_back(b + "omega");
01477     }
01478     else if (euler_type == "IMAGIC") {
01479         v.push_back(b + "alpha");
01480         v.push_back(b + "beta");
01481         v.push_back(b + "gamma");
01482     }
01483     else if (euler_type == "SPIDER") {
01484         v.push_back(b + "phi");
01485         v.push_back(b + "theta");
01486         v.push_back(b + "gamma");
01487     }
01488     else if (euler_type == "SPIN" ||
01489              euler_type == "SGIROT") {
01490         v.push_back(b + "q");
01491         v.push_back(b + "n1");
01492         v.push_back(b + "n2");
01493         v.push_back(b + "n3");
01494     }
01495 
01496     else if (euler_type == "QUATERNION") {
01497         v.push_back(b + "e0");
01498         v.push_back(b + "e1");
01499         v.push_back(b + "e2");
01500         v.push_back(b + "e3");
01501     }
01502 
01503     return v;
01504 }

int EMUtil::get_image_count ( const string &  filename  )  [static]

Get the number of images in an image file.

Parameters:
filename Image file name.
Returns:
Number of images in the given file.

Definition at line 467 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().

00468 {
00469         ENTERFUNC;
00470         Assert(filename != "");
00471 
00472         int nimg = 0;
00473         ImageIO *imageio = get_imageio(filename, ImageIO::READ_ONLY);
00474 
00475         if (imageio) {
00476                 nimg = imageio->get_nimg();
00477         }
00478 #ifndef IMAGEIO_CACHE
00479         if( imageio )
00480         {
00481                 delete imageio;
00482                 imageio = 0;
00483         }
00484 #endif
00485         EXITFUNC;
00486         return nimg;
00487 }

EMUtil::ImageType EMUtil::get_image_ext_type ( const string &  file_ext  )  [static]

Get an image's format type from its filename extension.

Parameters:
file_ext File extension.
Returns:
image format type.

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_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                 initialized = true;
00189         }
00190 
00191         ImageType result = IMAGE_UNKNOWN;
00192 
00193         if (imagetypes.find(file_ext) != imagetypes.end()) {
00194                 result = imagetypes[file_ext];
00195         }
00196 
00197         EXITFUNC;
00198         return result;
00199 }

EMUtil::ImageType EMUtil::get_image_type ( const string &  filename  )  [static]

Get an image's format type by processing the first 1K of the image.

Parameters:
filename Image file name.
Returns:
image format type.

Definition at line 347 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_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::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(), LOGERR, portable_fseek(), and portable_ftell().

Referenced by get_imageio(), and getRenderMinMax().

00348 {
00349         ENTERFUNC;
00350         Assert(in_filename != "");
00351 
00352 #ifdef ENABLE_V4L2
00353         if (in_filename.compare(0,5,"/dev/")==0) return IMAGE_V4L;
00354 #endif
00355 
00356         string filename = in_filename;
00357 
00358         string old_ext = Util::get_filename_ext(filename);
00359         if (old_ext == ImagicIO::IMG_EXT) {
00360                 filename = Util::change_filename_ext(filename, ImagicIO::HED_EXT);
00361         }
00362 
00363         FILE *in = fopen(filename.c_str(), "rb");
00364         if (!in) {
00365                 throw FileAccessException(filename);
00366         }
00367 
00368         char first_block[1024];
00369         size_t n = fread(first_block, sizeof(char), sizeof(first_block), in);
00370         portable_fseek(in, 0, SEEK_END);
00371         off_t file_size = portable_ftell(in);
00372 
00373         if (n == 0) {
00374                 LOGERR("file '%s' is an empty file", filename.c_str());
00375                 fclose(in);
00376                 return IMAGE_UNKNOWN;
00377         }
00378         fclose(in);
00379 
00380         ImageType image_type = fast_get_image_type(filename, first_block, file_size);
00381         if (image_type != IMAGE_UNKNOWN) {
00382                 return image_type;
00383         }
00384 
00385         if (SpiderIO::is_valid(first_block)) {
00386                 image_type = IMAGE_SPIDER;
00387         }
00388         else if (SingleSpiderIO::is_valid(first_block)) {
00389                 image_type = IMAGE_SINGLE_SPIDER;
00390         }
00391         else if (MrcIO::is_valid(first_block, file_size)) {
00392                 image_type = IMAGE_MRC;
00393         }
00394         else if (DM3IO::is_valid(first_block)) {
00395                 image_type = IMAGE_DM3;
00396         }
00397 #ifdef EM_HDF5
00398         else if (HdfIO2::is_valid(first_block)) {
00399                 image_type = IMAGE_HDF;
00400         }
00401 #endif
00402         else if (LstIO::is_valid(first_block)) {
00403                 image_type = IMAGE_LST;
00404         }
00405         else if (LstFastIO::is_valid(first_block)) {
00406                 image_type = IMAGE_LSTFAST;
00407         }
00408 #ifdef EM_TIFF
00409         else if (TiffIO::is_valid(first_block)) {
00410                 image_type = IMAGE_TIFF;
00411         }
00412 #endif
00413         else if (PifIO::is_valid(first_block)) {
00414                 image_type = IMAGE_PIF;
00415         }
00416 #ifdef EM_PNG
00417         else if (PngIO::is_valid(first_block)) {
00418                 image_type = IMAGE_PNG;
00419         }
00420 #endif
00421         else if (VtkIO::is_valid(first_block)) {
00422                 image_type = IMAGE_VTK;
00423         }
00424         else if (PgmIO::is_valid(first_block)) {
00425                 image_type = IMAGE_PGM;
00426         }
00427         else if (IcosIO::is_valid(first_block)) {
00428                 image_type = IMAGE_ICOS;
00429         }
00430         else if (SalIO::is_valid(first_block)) {
00431                 image_type = IMAGE_SAL;
00432         }
00433         else if (AmiraIO::is_valid(first_block)) {
00434                 image_type = IMAGE_AMIRA;
00435         }
00436         else if (XplorIO::is_valid(first_block)) {
00437                 image_type = IMAGE_XPLOR;
00438         }
00439         else if (Gatan2IO::is_valid(first_block)) {
00440                 image_type = IMAGE_GATAN2;
00441         }
00442         else if (FitsIO::is_valid(first_block)) {
00443                 image_type = IMAGE_FITS;
00444         }
00445         else if (EmIO::is_valid(first_block, file_size)) {
00446                 image_type = IMAGE_EM;
00447         }
00448         else if(OmapIO::is_valid(first_block, file_size)) {
00449                 image_type = IMAGE_OMAP;
00450         }
00451         else if (ImagicIO::is_valid(first_block)) {
00452                 image_type = IMAGE_IMAGIC;
00453         }
00454         else if (Df3IO::is_valid(first_block)) {
00455                 image_type = IMAGE_DF3;
00456         }
00457         else {
00458                 //LOGERR("I don't know this image's type: '%s'", filename.c_str());
00459                 throw ImageFormatException("invalid image type");
00460         }
00461 
00462         EXITFUNC;
00463         return image_type;
00464 }

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.

Parameters:
filename Image file name.
rw_mode ImageIO read/write mode.
image_type Image format type.
Returns:
An ImageIO object.

Definition at line 490 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_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().

00492 {
00493         ENTERFUNC;
00494         Assert(filename != "");
00495         Assert(rw == ImageIO::READ_ONLY ||
00496                    rw == ImageIO::READ_WRITE ||
00497                    rw == ImageIO::WRITE_ONLY);
00498 
00499         ImageIO *imageio = 0;
00500 #ifdef IMAGEIO_CACHE
00501         imageio = GlobalCache::instance()->get_imageio(filename, rw);
00502         if (imageio) {
00503                 return imageio;
00504         }
00505 #endif
00506 
00507         ImageIO::IOMode rw_mode = static_cast < ImageIO::IOMode > (rw);
00508 
00509         if (image_type == IMAGE_UNKNOWN) {
00510                 if(rw == ImageIO::WRITE_ONLY || rw == ImageIO::READ_WRITE) {
00511                         throw ImageFormatException("writing to this image format not supported.");
00512                 }
00513 
00514                 image_type = get_image_type(filename);
00515         }
00516 
00517         switch (image_type) {
00518 #ifdef ENABLE_V4L2
00519         case IMAGE_V4L:
00520                 imageio = new V4L2IO(filename, rw_mode);
00521                 break;
00522 #endif
00523         case IMAGE_MRC:
00524                 imageio = new MrcIO(filename, rw_mode);
00525                 break;
00526         case IMAGE_IMAGIC:
00527                 imageio = new ImagicIO2(filename, rw_mode);
00528                 if (rw_mode==ImageIO::READ_ONLY && ((ImagicIO2 *)imageio)->init_test()==-1 ) {
00529                         delete imageio;
00530                         imageio = new ImagicIO(filename, rw_mode);
00531                 }
00532                 break;
00533         case IMAGE_DM3:
00534                 imageio = new DM3IO(filename, rw_mode);
00535                 break;
00536 #ifdef EM_TIFF
00537         case IMAGE_TIFF:
00538                 imageio = new TiffIO(filename, rw_mode);
00539                 break;
00540 #endif
00541 #ifdef EM_HDF5
00542         case IMAGE_HDF:
00543                 imageio = new HdfIO2(filename, rw_mode);
00544                 if (((HdfIO2 *)imageio)->init_test()==-1) {
00545                         delete imageio;
00546                         imageio = new HdfIO(filename, rw_mode);
00547                 }
00548                 break;
00549 #endif
00550         case IMAGE_LST:
00551                 imageio = new LstIO(filename, rw_mode);
00552                 break;
00553         case IMAGE_LSTFAST:
00554                 imageio = new LstFastIO(filename, rw_mode);
00555                 break;
00556         case IMAGE_PIF:
00557                 imageio = new PifIO(filename, rw_mode);
00558                 break;
00559         case IMAGE_VTK:
00560                 imageio = new VtkIO(filename, rw_mode);
00561                 break;
00562         case IMAGE_SPIDER:
00563                 imageio = new SpiderIO(filename, rw_mode);
00564                 break;
00565         case IMAGE_SINGLE_SPIDER:
00566                 imageio = new SingleSpiderIO(filename, rw_mode);
00567                 break;
00568         case IMAGE_PGM:
00569                 imageio = new PgmIO(filename, rw_mode);
00570                 break;
00571 #ifdef EM_JPEG
00572         case IMAGE_JPEG:
00573                 imageio = new JpegIO(filename,rw_mode);
00574                 break;
00575 #endif
00576         case IMAGE_ICOS:
00577                 imageio = new IcosIO(filename, rw_mode);
00578                 break;
00579 #ifdef EM_PNG
00580         case IMAGE_PNG:
00581                 imageio = new PngIO(filename, rw_mode);
00582                 break;
00583 #endif
00584         case IMAGE_SAL:
00585                 imageio = new SalIO(filename, rw_mode);
00586                 break;
00587         case IMAGE_AMIRA:
00588                 imageio = new AmiraIO(filename, rw_mode);
00589                 break;
00590         case IMAGE_GATAN2:
00591                 imageio = new Gatan2IO(filename, rw_mode);
00592                 break;
00593         case IMAGE_EM:
00594                 imageio = new EmIO(filename, rw_mode);
00595                 break;
00596         case IMAGE_XPLOR:
00597                 imageio = new XplorIO(filename, rw_mode);
00598                 break;
00599         case IMAGE_FITS:
00600                 imageio = new FitsIO(filename, rw_mode);
00601                 break;
00602         case IMAGE_DF3:
00603                 imageio = new Df3IO(filename, rw_mode);
00604                 break;
00605         case IMAGE_OMAP:
00606                 imageio = new OmapIO(filename, rw_mode);
00607                 break;
00608         default:
00609                 break;
00610         }
00611 #ifdef IMAGEIO_CACHE
00612         GlobalCache::instance()->add_imageio(filename, rw, imageio);
00613 #endif
00614         EXITFUNC;
00615         return imageio;
00616 }

const char * EMUtil::get_imagetype_name ( EMUtil::ImageType  type  )  [static]

Give each image type a meaningful name.

Parameters:
type Image format type.
Returns:
A name for that type.

Definition at line 620 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_SPIDER, IMAGE_TIFF, IMAGE_UNKNOWN, IMAGE_V4L, IMAGE_VTK, and IMAGE_XPLOR.

00621 {
00622         switch (t) {
00623         case IMAGE_V4L:
00624                 return "V4L2";
00625                 break;
00626         case IMAGE_MRC:
00627                 return "MRC";
00628                 break;
00629         case IMAGE_SPIDER:
00630                 return "SPIDER";
00631                 break;
00632         case IMAGE_SINGLE_SPIDER:
00633                 return "Single-SPIDER";
00634                 break;
00635         case IMAGE_IMAGIC:
00636                 return "IMAGIC";
00637                 break;
00638         case IMAGE_PGM:
00639                 return "PGM";
00640                 break;
00641         case IMAGE_LST:
00642                 return "LST";
00643                 break;
00644         case IMAGE_LSTFAST:
00645                 return "Fast LST";
00646                 break;
00647         case IMAGE_PIF:
00648                 return "PIF";
00649                 break;
00650         case IMAGE_PNG:
00651                 return "PNG";
00652                 break;
00653         case IMAGE_HDF:
00654                 return "HDF5";
00655                 break;
00656         case IMAGE_DM3:
00657                 return "GatanDM3";
00658                 break;
00659         case IMAGE_TIFF:
00660                 return "TIFF";
00661                 break;
00662         case IMAGE_VTK:
00663                 return "VTK";
00664                 break;
00665         case IMAGE_SAL:
00666                 return "HDR";
00667                 break;
00668         case IMAGE_ICOS:
00669                 return "ICOS_MAP";
00670                 break;
00671         case IMAGE_EMIM:
00672                 return "EMIM";
00673                 break;
00674         case IMAGE_GATAN2:
00675                 return "GatanDM2";
00676                 break;
00677         case IMAGE_JPEG:
00678                 return "JPEG";
00679                 break;
00680         case IMAGE_AMIRA:
00681                 return "AmiraMesh";
00682                 break;
00683         case IMAGE_XPLOR:
00684                 return "XPLOR";
00685                 break;
00686         case IMAGE_EM:
00687                 return "EM";
00688                 break;
00689         case IMAGE_FITS:
00690                 return "FITS";
00691                 break;
00692         case IMAGE_DF3:
00693                 return "DF3";
00694                 break;
00695         case IMAGE_OMAP:
00696                 return "OMAP";
00697                 break;
00698         case IMAGE_UNKNOWN:
00699                 return "unknown";
00700         }
00701         return "unknown";
00702 }

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.

Parameters:
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 735 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().

00737 {
00738         Assert(area_x);
00739         Assert(area_y);
00740 
00741         if (!area) {
00742                 *area_x = nx;
00743                 *area_y = ny;
00744                 if (area_z) {
00745                         *area_z = nz;
00746                 }
00747         }
00748         else {
00749                 Vec3i size = area->get_size();
00750                 *area_x = size[0];
00751                 *area_y = size[1];
00752 
00753                 if (area_z) {
00754                         if (area->get_ndim() > 2 && nz > 1) {
00755                                 *area_z = size[2];
00756                         }
00757                         else {
00758                                 *area_z = 1;
00759                         }
00760                 }
00761 
00762         }
00763 }

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.

Parameters:
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 765 of file emutil.cpp.

References Assert, EMAN::Region::get_ndim(), and EMAN::Region::origin.

00767 {
00768         Assert(p_x0);
00769         Assert(p_y0);
00770 
00771         if (area) {
00772                 *p_x0 = static_cast < int >(area->origin[0]);
00773                 *p_y0 = static_cast < int >(area->origin[1]);
00774 
00775                 if (p_z0 && nz > 1 && area->get_ndim() > 2) {
00776                         *p_z0 = static_cast < int >(area->origin[2]);
00777                 }
00778         }
00779         else {
00780                 *p_x0 = 0;
00781                 *p_y0 = 0;
00782                 if (p_z0) {
00783                         *p_z0 = nz > 1 ? 0 : image_index;
00784                 }
00785         }
00786 }

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.

Parameters:
[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 1523 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.

01524 {
01525 #ifdef _WIN32
01526         if (rendermax<=rendermin || _isnan(rendermin) || _isnan(rendermax)) {
01527 #else
01528         if (rendermax<=rendermin || std::isnan(rendermin) || std::isnan(rendermax)) {
01529 #endif
01530                 float m=0.0f,s=0.0f;
01531 
01532                 size_t size = (size_t)nx*ny*nz;
01533                 float min=data[0],max=data[0];
01534 
01535                 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; }
01536                 m/=(float)(size);
01537                 s=sqrt(s/(float)(size)-m*m);
01538 #ifdef _WIN32
01539                 if (s<=0 || _isnan(s)) s=1.0;   // this means all data values are the same
01540 #else
01541                 if (s<=0 || std::isnan(s)) s=1.0;       // this means all data values are the same
01542 #endif  //_WIN32
01543                 rendermin=m-s*5.0f;
01544                 rendermax=m+s*5.0f;
01545                 if (rendermin<=min) rendermin=min;
01546                 if (rendermax>=max) rendermax=max;
01547         }
01548 }

bool EMUtil::is_complex_type ( EMDataType  datatype  )  [static]

Definition at line 995 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().

00996 {
00997         if (datatype == EM_SHORT_COMPLEX ||
00998                 datatype == EM_USHORT_COMPLEX ||
00999                 datatype == EM_FLOAT_COMPLEX) {
01000                 return true;
01001         }
01002         return false;
01003 }

bool EMUtil::is_same_ctf ( const EMData image1,
const EMData image2 
) [static]

Check whether two EMData images have the same CTF parameters.

Parameters:
image1 The first EMData image.
image2 The second EMData image.
Returns:
whether two EMData images have the same CTF.

Definition at line 1107 of file emutil.cpp.

References EMAN::Ctf::equal(), EMAN::EMData::get_ctf(), EMAN::EMData::has_ctff(), and NullPointerException.

01108 {
01109         if (!image1) {
01110                 throw NullPointerException("image1 is NULL");
01111         }
01112         if (!image2) {
01113                 throw NullPointerException("image2 is NULL");
01114         }
01115 
01116         Ctf *ctf1 = image1->get_ctf();
01117         Ctf *ctf2 = image2->get_ctf();
01118 
01119         if ((!ctf1 && !ctf2) && (image1->has_ctff() == false && image2->has_ctff() == false)) {
01120                 return true;
01121         }
01122 
01123         if (ctf1 && ctf2) {
01124                 bool result = ctf1->equal(ctf2);
01125                 delete ctf1;
01126                 ctf1 = 0;
01127                 delete ctf2;
01128                 ctf2 = 0;
01129 
01130                 return result;
01131         }
01132         return false;
01133 }

bool EMUtil::is_same_size ( const EMData image1,
const EMData image2 
) [static]

Check whether two EMData images are of the same size.

Parameters:
image1 The first EMData image.
image2 The second EMData image.
Returns:
Whether two EMData images are of the same size.

Definition at line 985 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().

00986 {
00987         if (em1->get_xsize() == em2->get_xsize() &&
00988                 em1->get_ysize() == em2->get_ysize() &&
00989                 em1->get_zsize() == em2->get_zsize()) {
00990                 return true;
00991         }
00992         return false;
00993 }

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.

Parameters:
filename Image file name.
Returns:
whether or not it is a valid filename

Definition at line 203 of file emutil.cpp.

References EMAN::Util::get_filename_ext(), get_image_ext_type(), and IMAGE_UNKNOWN.

00203                                                       {
00204         ImageType type = get_image_ext_type(Util::get_filename_ext(filename));
00205         return (type != IMAGE_UNKNOWN);
00206 }

void EMUtil::jump_lines ( FILE *  file,
int  nlines 
) [static]

Definition at line 1326 of file emutil.cpp.

References Assert.

Referenced by jump_lines_by_items(), and process_ascii_region_io().

01327 {
01328         Assert(file);
01329 
01330         if (nlines > 0) {
01331                 char line[MAXPATHLEN];
01332                 for (int l = 0; l < nlines; l++) {
01333                         if (!fgets(line, sizeof(line), file)) {
01334                                 Assert("read xplor file failed");
01335                         }
01336                 }
01337         }
01338 }

void EMUtil::jump_lines_by_items ( FILE *  file,
int  nitems,
int  nitems_per_line 
) [static, private]

Definition at line 1307 of file emutil.cpp.

References Assert, and jump_lines().

Referenced by process_ascii_region_io().

01308 {
01309         Assert(file);
01310         Assert(nitems_per_line > 0);
01311 
01312         if (nitems <= 0) {
01313                 return;
01314         }
01315 
01316         int nlines = nitems / nitems_per_line;
01317         if ((nitems % nitems_per_line) != 0) {
01318                 nlines++;
01319         }
01320         if (nlines > 0) {
01321                 jump_lines(file, nlines);
01322         }
01323 }

EMData * EMUtil::make_image_median ( const vector< EMData * > &  image_list  )  [static]

Definition at line 1042 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.

01043 {
01044         if (image_list.size() == 0) {
01045                 return 0;
01046         }
01047 
01048         EMData *image0 = image_list[0];
01049         int image0_nx = image0->get_xsize();
01050         int image0_ny = image0->get_ysize();
01051         int image0_nz = image0->get_zsize();
01052         size_t size = (size_t)image0_nx * image0_ny * image0_nz;
01053 
01054         EMData *result = new EMData();
01055 
01056         result->set_size(image0_nx, image0_ny, image0_nz);
01057 
01058         float *dest = result->get_data();
01059         int nitems = static_cast < int >(image_list.size());
01060         float *srt = new float[nitems];
01061         float **src = new float *[nitems];
01062 
01063         for (int i = 0; i < nitems; i++) {
01064                 src[i] = image_list[i]->get_data();
01065         }
01066 
01067         for (size_t i = 0; i < size; ++i) {
01068                 for (int j = 0; j < nitems; j++) {
01069                         srt[j] = src[j][i];
01070                 }
01071 
01072                 for (int j = 0; j < nitems; j++) {
01073                         for (int k = j + 1; k < nitems; k++) {
01074                                 if (srt[j] < srt[k]) {
01075                                         float v = srt[j];
01076                                         srt[j] = srt[k];
01077                                         srt[k] = v;
01078                                 }
01079                         }
01080                 }
01081 
01082                 int l = nitems / 2;
01083                 if (nitems < 3) {
01084                         dest[i] = srt[l];
01085                 }
01086                 else {
01087                         dest[i] = (srt[l] + srt[l + 1] + srt[l - 1]) / 3.0f;
01088                 }
01089         }
01090 
01091         if( srt )
01092         {
01093                 delete[]srt;
01094                 srt = 0;
01095         }
01096         if( src )
01097         {
01098                 delete[]src;
01099                 src = 0;
01100         }
01101 
01102         result->update();
01103 
01104         return result;
01105 }

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 1198 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.

01202 {
01203         Assert(data != 0);
01204         Assert(file != 0);
01205         Assert(rw_mode == ImageIO::READ_ONLY ||
01206                    rw_mode == ImageIO::READ_WRITE ||
01207                    rw_mode == ImageIO::WRITE_ONLY);
01208 
01209         int xlen = 0, ylen = 0, zlen = 0;
01210         get_region_dims(area, nx, &xlen, ny, &ylen, nz, &zlen);
01211 
01212         int x0 = 0;
01213         int y0 = 0;
01214         int z0 = 0;
01215 
01216         if (area) {
01217                 x0 = (int)area->origin[0];
01218                 y0 = (int)area->origin[1];
01219                 z0 = (int)area->origin[2];
01220         }
01221 
01222         int nlines_per_sec = (nx *ny) / nitems_per_line;
01223         int nitems_last_line = (nx * ny) % nitems_per_line;
01224         if (nitems_last_line != 0) {
01225                 nlines_per_sec++;
01226         }
01227 
01228         if (has_index_line) {
01229                 nlines_per_sec++;
01230         }
01231 
01232         if (z0 > 0) {
01233                 jump_lines(file, z0 * nlines_per_sec);
01234         }
01235 
01236 
01237         int nlines_pre_sec = (y0 * nx + x0) / nitems_per_line;
01238         int gap_nitems = nx - xlen;
01239         int ti = 0;
01240         int rlines = 0;
01241 
01242         for (int k = 0; k < zlen; k++) {
01243                 EMUtil::jump_lines(file, nlines_pre_sec+1);
01244 
01245                 int head_nitems = (y0 * nx + x0) % nitems_per_line;
01246                 int tail_nitems = 0;
01247                 bool is_head_read = false;
01248 
01249                 for (int j = 0; j < ylen; j++) {
01250 
01251                         if (head_nitems > 0 && !is_head_read) {
01252                                 EMUtil::process_numbers_io(file, rw_mode, nitems_per_line, mode_size,
01253                                                                                    nitems_per_line-head_nitems,
01254                                                                                    nitems_per_line-1, data, &ti, outformat);
01255                                 rlines++;
01256                         }
01257 
01258                         EMUtil::process_lines_io(file, rw_mode, nitems_per_line,
01259                                                                          mode_size, (xlen - head_nitems),
01260                                                                          data, &ti, outformat);
01261 
01262                         rlines += ((xlen - head_nitems)/nitems_per_line);
01263 
01264                         tail_nitems = (xlen - head_nitems) % nitems_per_line;
01265 
01266                         if ((gap_nitems + tail_nitems) > 0) {
01267                                 head_nitems = nitems_per_line -
01268                                         (gap_nitems + tail_nitems) % nitems_per_line;
01269                         }
01270                         else {
01271                                 head_nitems = 0;
01272                         }
01273 
01274                         is_head_read = false;
01275 
01276                         if (tail_nitems > 0) {
01277                                 if ((gap_nitems < (nitems_per_line-tail_nitems)) &&
01278                                         (j != (ylen-1))) {
01279                                         EMUtil::exclude_numbers_io(file, rw_mode, nitems_per_line,
01280                                                                                            mode_size, tail_nitems,
01281                                                                                            tail_nitems+gap_nitems-1, data, &ti, outformat);
01282                                         is_head_read = true;
01283                                         rlines++;
01284                                 }
01285                                 else {
01286                                         EMUtil::process_numbers_io(file, rw_mode, nitems_per_line, mode_size,
01287                                                                                            0, tail_nitems-1, data, &ti, outformat);
01288                                         rlines++;
01289                                 }
01290                         }
01291 
01292                         if (gap_nitems > (nitems_per_line-tail_nitems)) {
01293                                 int gap_nlines = (gap_nitems - (nitems_per_line-tail_nitems)) /
01294                                         nitems_per_line;
01295                                 if (gap_nlines > 0 && j != (ylen-1)) {
01296                                         EMUtil::jump_lines(file, gap_nlines);
01297                                 }
01298                         }
01299                 }
01300 
01301                 int ytail_nitems = (ny-ylen-y0) * nx + (nx-xlen-x0) - (nitems_per_line-tail_nitems);
01302                 EMUtil::jump_lines_by_items(file, ytail_nitems, nitems_per_line);
01303         }
01304 }

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 1445 of file emutil.cpp.

References Assert, and process_numbers_io().

Referenced by process_ascii_region_io().

01449 {
01450         Assert(file);
01451         Assert(data);
01452         Assert(p_i);
01453 
01454         if (nitems > 0) {
01455                 int nlines = nitems / nitems_per_line;
01456                 for (int i = 0; i < nlines; i++) {
01457                         EMUtil::process_numbers_io(file, rw_mode, nitems_per_line, mode_size, 0,
01458                                                                            nitems_per_line-1, data, p_i, outformat);
01459                 }
01460         }
01461 }

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 1340 of file emutil.cpp.

References Assert, portable_fseek(), and EMAN::ImageIO::READ_ONLY.

Referenced by process_ascii_region_io(), and process_lines_io().

01343 {
01344         Assert(file);
01345         Assert(start >= 0);
01346         Assert(start <= end);
01347         Assert(end <= nitems_per_line);
01348         Assert(data);
01349         Assert(p_i);
01350         Assert(outformat);
01351 
01352         char line[MAXPATHLEN];
01353 
01354         if (rw_mode == ImageIO::READ_ONLY) {
01355                 if (!fgets(line, sizeof(line), file)) {
01356                         Assert("read xplor file failed");
01357                 }
01358 
01359                 int nitems_in_line = (int) (strlen(line) / mode_size);
01360                 Assert(end <= nitems_in_line);
01361                 vector<float> d(nitems_in_line);
01362                 char * pline = line;
01363 
01364                 for (int i = 0; i < nitems_in_line; i++) {
01365                         sscanf(pline, "%f", &d[i]);
01366                         pline += (int)mode_size;
01367                 }
01368 
01369 
01370                 for (int i = start; i <= end; i++) {
01371                         data[*p_i] = d[i];
01372                         (*p_i)++;
01373                 }
01374         }
01375         else {
01376                 portable_fseek(file, mode_size * start, SEEK_CUR);
01377                 for (int i = start; i <= end; i++) {
01378                         fprintf(file, outformat, data[*p_i]);
01379                         (*p_i)++;
01380                 }
01381 
01382                 portable_fseek(file, mode_size * (nitems_per_line - end-1)+1, SEEK_CUR);
01383         }
01384 }

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)

Parameters:
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.
Exceptions:
ImageReadException If the read has some error.
ImageWriteException If the write has some error.

Definition at line 789 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().

00794 {
00795         Assert(vdata != 0);
00796         Assert(file != 0);
00797         Assert(rw_mode == ImageIO::READ_ONLY ||
00798                    rw_mode == ImageIO::READ_WRITE ||
00799                    rw_mode == ImageIO::WRITE_ONLY);
00800 
00801         if (mode_size == 0) throw UnexpectedBehaviorException("The mode size was 0?");
00802 
00803         unsigned char * cdata = (unsigned char *)vdata;
00804 
00805         int dx0 = 0; // data x0
00806         int dy0 = 0; // data y0
00807         int dz0 = 0; // data z0
00808 
00809         int fx0 = 0; // file x0
00810         int fy0 = 0; // file y0
00811         int fz0 = nz > 1 ? 0 : image_index; // file z0
00812 
00813 
00814         int xlen = 0;
00815         int ylen = 0;
00816         int zlen = 0;
00817         get_region_dims(area, nx, &xlen, ny, &ylen, nz, &zlen);
00818 
00819         if (area) { // Accommodate for all boundary overlaps of the region
00820 
00821                 Vec3i origin = area->get_origin();
00822 
00823 
00824                 fx0 = origin[0]; dx0 = origin[0];
00825                 fy0 = origin[1]; dy0 = origin[1];
00826                 if (nz > 1 && area->get_ndim() > 2) {
00827                         fz0 = origin[2]; dz0 = origin[2];
00828                 }
00829 
00830                 if (need_flip) {
00831                         Vec3i size = area->get_size();
00832                         fy0 = ny-(origin[1]+size[1]);
00833                 }
00834 
00835                 if (fx0 < 0) {
00836                         dx0 *= -1;
00837                         xlen = xlen + fx0; // because there are less reads
00838                         fx0 = 0;
00839                 }else {
00840                         dx0 = 0;
00841                         //fx0 *= -1;
00842                 }
00843                 if (fy0 < 0) {
00844                         dy0 *= -1;
00845                         ylen = ylen + fy0; // because there are less reads
00846                         fy0 = 0;
00847                 }else {
00848                         if (need_flip){
00849                                 dy0*=-1;
00850                         }
00851                         else dy0 = 0;
00852                         //fy0 *= -1;
00853                 }
00854                 if (fz0 < 0) {
00855                         dz0 *= -1;
00856                         zlen = zlen + fz0; // because there are less reads
00857                         fz0 = 0;
00858                 }else {
00859                         dz0 = 0;
00860                         //fz0 *= -1;
00861                 }
00862 
00863                 if ((fx0 + xlen)> nx) xlen = nx-fx0;
00864                 if ((fy0 + ylen)> ny) ylen = ny-fy0;
00865                 if ((fz0 + zlen)> nz) zlen = nz-fz0;
00866                 if ( xlen <= 0 || ylen <= 0 || zlen <= 0 ) return; // This is fine the region was entirely outside the image
00867         }
00868 
00869         if ( xlen <= 0 ) {
00870                 cout << "Xlen was too small " << xlen << endl;
00871                 return;
00872         }
00873 
00874         Vec3i size;
00875         if (area != 0) size = area->get_size();
00876         else size = Vec3d(nx,ny,nz);
00877 
00878         //size_t area_sec_size = xlen * ylen * mode_size;
00879         size_t memory_sec_size = size[0] * size[1] * mode_size;
00880         size_t img_row_size = nx * mode_size + pre_row + post_row;
00881         size_t area_row_size = xlen * mode_size;
00882         size_t memory_row_size = size[0] * mode_size;
00883 
00884         if ( area_row_size <= 0 ) {
00885                 cout << "Xlen was too small " << xlen << " mode_size " << mode_size << endl;
00886                 return;
00887         }
00888 
00889         size_t x_pre_gap = fx0 * mode_size;
00890         size_t x_post_gap = (nx - fx0 - xlen) * mode_size;
00891 
00892         size_t y_pre_gap = fy0 * img_row_size;
00893         size_t y_post_gap = (ny - fy0 - ylen) * img_row_size;
00894 
00895         portable_fseek(file, img_row_size * ny * fz0, SEEK_CUR);
00896 
00897         float nxlendata[1];
00898         int floatsize = (int) sizeof(float);
00899         nxlendata[0] = (float)(nx * floatsize);
00900 
00901         for (int k = dz0; k < (dz0+zlen); k++) {
00902                 if (y_pre_gap > 0) {
00903                         portable_fseek(file, y_pre_gap, SEEK_CUR);
00904                 }
00905                 //long k2 = k * area_sec_size;
00906                 long k2 = k*memory_sec_size;
00907 
00908                 for (int j = dy0; j < (dy0+ylen); j++) {
00909                         if (pre_row > 0) {
00910                                 if (imgtype == IMAGE_ICOS && rw_mode != ImageIO::READ_ONLY && !area) {
00911                                         fwrite(nxlendata, floatsize, 1, file);
00912                                 }
00913                                 else {
00914                                         portable_fseek(file, pre_row, SEEK_CUR);
00915                                 }
00916                         }
00917 
00918                         if (x_pre_gap > 0) {
00919                                 portable_fseek(file, x_pre_gap, SEEK_CUR);
00920                         }
00921 
00922                         int jj = j;
00923                         if (need_flip) {
00924                                 jj = (dy0+ylen) - 1 - j;
00925                                 if (dy0 > 0 ) { // region considerations add complications in the flipping scenario (imagic format)
00926                                         jj += dy0;
00927                                 }
00928                         }
00929 
00930                         if (rw_mode == ImageIO::READ_ONLY) {
00931                                 if (fread(&cdata[k2 + jj * memory_row_size+dx0*mode_size],
00932                                                   area_row_size, 1, file) != 1) {
00933                                         cout << jj << " " << k2 << " " << memory_row_size << " " << dx0 << " " << mode_size << " " << area_row_size << " " << cdata << "done" << endl;
00934                                         throw ImageReadException("", "incomplete data read");
00935                                 }
00936                         }
00937                         else {
00938                                 if (fwrite(&cdata[k2 + jj * memory_row_size+dx0*mode_size],
00939                                                    area_row_size, 1, file) != 1) {
00940                                         throw ImageWriteException("", "incomplete data write");
00941                                 }
00942                         }
00943 
00944                         if (x_post_gap > 0) {
00945                                 portable_fseek(file, x_post_gap, SEEK_CUR);
00946                         }
00947 
00948                         if (post_row > 0) {
00949                                 if (imgtype == IMAGE_ICOS && rw_mode != ImageIO::READ_ONLY && !area) {
00950                                         fwrite(nxlendata, floatsize, 1, file);
00951                                 }
00952                                 else {
00953                                         portable_fseek(file, post_row, SEEK_CUR);
00954                                 }
00955                         }
00956                 }
00957 
00958                 if (y_post_gap > 0) {
00959                         portable_fseek(file, y_post_gap, SEEK_CUR);
00960                 }
00961         }
00962 }

EMData * EMUtil::vertical_acf ( const EMData image,
int  maxdy 
) [static]

Definition at line 1006 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.

01007 {
01008         if (!image) {
01009                 throw NullPointerException("NULL Image");
01010         }
01011 
01012         EMData *ret = new EMData();
01013         int nx = image->get_xsize();
01014         int ny = image->get_ysize();
01015 
01016         if (maxdy <= 1) {
01017                 maxdy = ny / 8;
01018         }
01019 
01020         ret->set_size(nx, maxdy, 1);
01021 
01022         float *data = image->get_data();
01023         float *ret_data = ret->get_data();
01024 
01025         for (int x = 0; x < nx; x++) {
01026                 for (int y = 0; y < maxdy; y++) {
01027                         float dot = 0;
01028                         for (int yy = maxdy; yy < ny - maxdy; yy++) {
01029                                 dot += data[x + (yy + y) * nx] * data[x + (yy - y) * nx];
01030                         }
01031                         ret_data[x + y * nx] = dot;
01032                 }
01033         }
01034 
01035         ret->update();
01036 
01037         return ret;
01038 }


The documentation for this class was generated from the following files:
Generated on Tue Jul 12 13:48:15 2011 for EMAN2 by  doxygen 1.4.7