Xmipp  v3.23.11-Nereus
xmipp_image_base.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Authors: Joaquin Oton (joton@cnb.csic.es)
3  *
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #include "xmipp_image_base.h"
27 #include "xmipp_image.h"
28 #include "xmipp_error.h"
29 
30 #include <stdlib.h>
31 #include "metadata_static.h"
32 #include "metadata_base.h"
33 #include "xmipp_funcs.h"
34 #include <tiffio.h>
35 #include <hdf5.h>
36 
37 //This is needed for static memory allocation
38 
39 void ImageBase::initGeometry(const size_t n)
40 {
42 }
43 
45 {
46  mdaBase->setDimensions(aDim);
47  aDimFile = aDim;
48 }
49 
51 {
52  clearHeader();
53 
55  fimg = fhed = NULL;
56  hFile = NULL;
57  tif = NULL;
58  dataMode = DATA;
60  filename.clear();
61  offset = 0;
62  swap = swapWrite = 0;
63  replaceNsize = 0;
64  _exists = mmapOnRead = mmapOnWrite = false;
65  mFd = 0;
67  m_auxI = nullptr;
68 }
69 
70 void ImageBase::copy(const ImageBase& other) {
71  MDMainHeader = other.MDMainHeader;
72  MD.clear();
73  MD.reserve(other.MD.size());
74  if ((other.MD.size() > 0) && (dynamic_cast<MDRowVec*>(other.MD[0].get()) != nullptr)) {
75  for (const std::unique_ptr<MDRow>& rowPtr : other.MD) {
76  const MDRow& row = *rowPtr;
77  MD.emplace_back(std::unique_ptr<MDRow>(new MDRowVec(dynamic_cast<const MDRowVec&>(row))));
78  }
79  }
80  if ((other.MD.size() > 0) && (dynamic_cast<MDRowSql*>(other.MD[0].get()) != nullptr)) {
81  for (const std::unique_ptr<MDRow>& rowPtr : other.MD) {
82  const MDRow& row = *rowPtr;
83  MD.emplace_back(std::unique_ptr<MDRow>(new MDRowSql(dynamic_cast<const MDRowSql&>(row))));
84  }
85  }
86 
87  filename = other.filename;
88  tempFilename = other.tempFilename;
89  dataFName = other.dataFName;
90  fimg = other.fimg;
91  fhed = other.fhed;
92  tif = other.tif;
93  hFile = other.hFile;
94  aDimFile = other.aDimFile;
95  offset = other.offset;
96  swap = other.swap;
97  swapWrite = other.swapWrite;
98  transform = other.transform;
99  replaceNsize = other.replaceNsize;
100  _exists = other._exists;
101  mmapOnRead = other.mmapOnRead;
102  mmapOnWrite = other.mmapOnWrite;
103  mFd = other.mFd;
104  mappedSize = other.mappedSize;
105  mappedOffset = other.mappedOffset;
107 }
108 
110 {
112  MD.clear();
113  //Just to ensure there is an empty MDRow
114  MD.push_back(std::unique_ptr<MDRow>(new MDRowVec(MDMainHeader)));
115 }
116 
119 int ImageBase::read(const FileName &name, DataMode datamode, size_t select_img,
120  bool mapData, int mode)
121 {
122  if (!mapData)
123  mode = WRITE_READONLY; //TODO: Check if openfile other than readonly is necessary
124 
125  hFile = openFile(name, mode);
126  int err = _read(name, hFile, datamode, select_img, mapData);
127  closeFile(hFile);
128  return err;
129 }
130 
131 int ImageBase::readBatch(const FileName &name, size_t start_img, size_t batch_size,
132  DataMode datamode /*= DATA*/, bool mapData /*= false*/, int mode /*= WRITE_READONLY*/)
133 {
134  if (!mapData) {
135  mode = WRITE_READONLY;
136  }
137 
138  hFile = openFile(name, mode);
139  int err = _readBatch(name, hFile, start_img, batch_size, datamode, mapData);
140  closeFile(hFile);
141  return err;
142 }
143 
144 int ImageBase::readRange(const FileName &name, size_t start_img, size_t end_img,
145  DataMode datamode /*= DATA*/, bool mapData /*= false*/, int mode /*= WRITE_READONLY*/)
146 {
147  if (end_img < start_img) {
148  REPORT_ERROR(ERR_ARG_DEPENDENCE, formatString("readRange: end_img %lu is smaller than start_img %lu\n", end_img, start_img));
149  }
150 
151  readBatch(name, start_img, end_img - start_img + 1, datamode, mapData, mode);
152  return true;
153 }
154 
155 
156 int ImageBase::readMapped(const FileName &name, size_t select_img, int mode)
157 {
158  read(name, HEADER);
159  bool swap = this->swap > 0;
160  return read(name, DATA, select_img, !swap, mode);
161 }
162 
163 int ImageBase::readOrReadMapped(const FileName &name, size_t select_img, int mode)
164 {
165  try
166  {
167  return read(name, DATA, select_img, false, mode);
168  }
169  catch (XmippError &xe)
170  {
171  if (xe.__errno == ERR_MEM_NOTENOUGH)
172  {
173  reportWarning("ImageBase::readOrReadMapped: Not enough memory to allocate. \n"
174  " Proceeding to map image from file.");
175  return readMapped(name, select_img, mode);
176  }
177  else
178  throw xe;
179  }
180 }
181 
182 int ImageBase::readOrReadPreview(const FileName &name, size_t Xdim, size_t Ydim, int select_slice, size_t select_img,
183  bool mapData)
184 {
185  read(name, HEADER);
186  size_t imXdim, imYdim, imZdim, imNdim;
187  getDimensions(imXdim, imYdim, imZdim, imNdim);
188 
189  if (imXdim != Xdim || imYdim != Ydim)
190  return readPreview(name, Xdim, Ydim, select_slice, select_img);
191  else
192  {
193  int ret = read(name, DATA, select_img, mapData);
194  if (select_slice != ALL_SLICES)
195  movePointerTo(select_slice);
196  return ret;
197  }
198 
199 }
200 
202 void ImageBase::mapFile2Write(size_t Xdim, size_t Ydim, size_t Zdim, const FileName &_filename,
203  bool createTempFile, size_t select_img, bool isStack, int mode)
204 {
207 #ifdef XMIPP_MMAP
208  mmapOnWrite = true;
209 #endif
210 
211  setDimensions(Xdim, Ydim, Zdim, 1); // Images with Ndim >1 cannot be mapped to image file
212  MD.resize(1);
213  filename = _filename;
214  FileName fnToOpen;
215  if (createTempFile)
216  {
217  tempFilename.initUniqueName("temp_XXXXXX");
218  fnToOpen = tempFilename + ":" + _filename.getExtension();
219  }
220  else
221  fnToOpen=_filename;
222 
223  /* If the filename is in stack or an image is selected, we will suppose
224  * you want to write this, even if you have not set the flags to.
225  */
226  if ( (filename.isInStack() || select_img > ALL_IMAGES) && mode == WRITE_OVERWRITE)
227  {
228  isStack = true;
229  mode = WRITE_REPLACE;
230  }
231 
232  hFile = openFile(fnToOpen, mode);
233  _write(filename, hFile, select_img, isStack, mode);
234  closeFile(hFile);
235 }
236 
240 #define READ_AND_RETURN() ImageFHandler* hFile = openFile(name); \
241  int err = _read(name, hFile, params.datamode, params.select_img); \
242  applyGeo(*row, params.only_apply_shifts, params.wrap); \
243  closeFile(hFile); \
244  return err
245 
246 void ImageBase::applyGeo(const MetaData &md, size_t objId, const ApplyGeoParams &params)
247 {
248  std::unique_ptr<const MDRow> row(md.getRow(objId));
249  applyGeo(*row, params.only_apply_shifts, params.wrap);
250 }
251 
252 void ImageBase::setGeo(const MDRow &row, size_t n)
253 {
254  if (n < MD.size()) {
255  if (dynamic_cast<const MDRowVec*>(&row) != nullptr)
256  MD[n] = std::unique_ptr<MDRow>(new MDRowVec(dynamic_cast<const MDRowVec&>(row)));
257  if (dynamic_cast<const MDRowSql*>(&row) != nullptr)
258  MD[n] = std::unique_ptr<MDRow>(new MDRowSql(dynamic_cast<const MDRowSql&>(row)));
259  } else {
260  REPORT_ERROR(ERR_MD_OBJECTNUMBER, "Trying to set a value outside the current metadata size");
261  }
262 }
263 
264 int ImageBase::readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams &params)
265 {
266  ImageFHandler* hFile = openFile(name);
267  int err = _read(name, hFile, params.datamode, params.select_img);
268  applyGeo(row, params.only_apply_shifts, params.wrap);
269  closeFile(hFile);
270  return err;
271 }
272 
275 int ImageBase::readApplyGeo(const FileName &name, const MetaData &md, size_t objId, const ApplyGeoParams &params)
276 {
277  std::unique_ptr<const MDRow> row(md.getRow(objId));
278  READ_AND_RETURN();
279 }
280 
283 int ImageBase::readApplyGeo(const MetaData &md, size_t objId, const ApplyGeoParams &params)
284 {
285  std::unique_ptr<const MDRow> row(md.getRow(objId));
286  FileName name;
287  row->getValue(MDL_IMAGE, name);
288  READ_AND_RETURN();
289 }
290 
291 
292 void ImageBase::write(const FileName &name, size_t select_img, bool isStack,
293  int mode, CastWriteMode castMode, int _swapWrite)
294 {
295  const FileName &fname = (name.empty()) ? filename : name;
296 
297  if (mmapOnWrite && mappedSize > 0)
298  {
299  bool hasTempFile = !tempFilename.empty();
300  if (hasTempFile && fname.isInStack())
301  mmapOnWrite = !(mmapOnRead = true); // We change mmap mode from write to read to allow writing the image into a stack.
302  else
303  {
304  if (_swapWrite > 0)
305  REPORT_ERROR(ERR_ARG_INCORRECT, "Cannot swap endianness on writing if file is already mapped.");
306  munmapFile();
307  if (hasTempFile && std::rename(tempFilename.c_str(), fname.c_str()) != 0)
308  REPORT_ERROR(ERR_IO, formatString("Error renaming file '%s' to '%s'.", tempFilename.c_str(), fname.c_str()));
309  return;
310  }
311  }
312  // Swap the endianness of the image file when writing
313  swapWrite = _swapWrite;
314 
315  /* If the filename is in stack we will suppose you want to write this,
316  * even if you have not set the flags to.
317  */
318  if ( fname.isInStack() && mode == WRITE_OVERWRITE)
319  {
320  isStack = true;
321  mode = WRITE_REPLACE;
322  }
323  // else if (!isStack && mode != WRITE_OVERWRITE)
324  // mode = WRITE_OVERWRITE;
325 
326  hFile = openFile(fname, mode);
327  _write(fname, hFile, select_img, isStack, mode, castMode);
328  closeFile(hFile);
329 }
330 
331 void ImageBase::swapPage(char * page, size_t pageNrElements, DataType datatype, int swap)
332 {
333  size_t datatypesize = gettypesize(datatype);
334 #ifdef DEBUG
335 
336  std::cerr<<"DEBUG swapPage: Swapping image data with swap= "
337  << swap<<" datatypesize= "<<datatypesize
338  << " pageNrElements " << pageNrElements
339  << " datatype " << datatype
340  <<std::endl;
341  ;
342 #endif
343 
344  // Swap bytes if required
345  if ( swap == 1 )
346  {
347  if ( datatype >= DT_CShort )
348  datatypesize /= 2;
349  for ( size_t i = 0; i < pageNrElements; i += datatypesize )
350  swapbytes(page+i, datatypesize);
351  }
352  else if ( swap > 1 )
353  {
354  for (size_t i=0; i<pageNrElements; i+=swap )
355  swapbytes(page+i, swap);
356  }
357 }
358 
365 double ImageBase::rot(const size_t n) const
366 {
367  double dummy = 0;
368  MD[n]->getValue(MDL_ANGLE_ROT, dummy);
369  return dummy;
370 }
371 
378 double ImageBase::tilt(const size_t n) const
379 {
380  double dummy = 0;
381  MD[n]->getValue(MDL_ANGLE_TILT, dummy);
382  return dummy;
383 }
384 
391 double ImageBase::psi(const size_t n) const
392 {
393  double dummy = 0;
394  MD[n]->getValue(MDL_ANGLE_PSI, dummy);
395  return dummy;
396 }
397 
404 double ImageBase::Xoff(const size_t n) const
405 {
406  double dummy = 0;
407  MD[n]->getValue(MDL_SHIFT_X, dummy);
408  return dummy;
409 }
410 
417 double ImageBase::Yoff(const size_t n) const
418 {
419  double dummy = 0;
420  MD[n]->getValue(MDL_SHIFT_Y, dummy);
421  return dummy;
422 }
423 
430 double ImageBase::Zoff(const size_t n) const
431 {
432  double dummy = 0;
433  MD[n]->getValue(MDL_SHIFT_Z, dummy);
434  return dummy;
435 }
436 
443 double ImageBase::weight(const size_t n) const
444 {
445  double dummy = 1;
446  MD[n]->getValue(MDL_WEIGHT, dummy);
447  return dummy;
448 }
449 
456 double ImageBase::scale(const size_t n) const
457 {
458  double dummy = 1;
459  MD[n]->getValue(MDL_SCALE, dummy);
460  return dummy;
461 }
462 
463 
470 bool ImageBase::flip(const size_t n) const
471 {
472  bool dummy = false;
473  MD[n]->getValue(MDL_FLIP, dummy);
474  return dummy;
475 }
476 
484 {
485  int dummy;
487  return (DataType)dummy;
488 }
489 
491 {
492  MDMainHeader.setValue(MDL_DATATYPE, (int) datatype);
493 }
501 {
502  double dummy = 1.;
504  return dummy;
505 }
506 
509 void ImageBase::setEulerAngles(double rot, double tilt, double psi,
510  const size_t n)
511 {
512  MD[n]->setValue(MDL_ANGLE_ROT, rot);
513  MD[n]->setValue(MDL_ANGLE_TILT, tilt);
514  MD[n]->setValue(MDL_ANGLE_PSI, psi);
515 }
516 
519 void ImageBase::getEulerAngles(double &rot, double &tilt, double &psi,
520  const size_t n) const
521 {
522  MD[n]->getValue(MDL_ANGLE_ROT, rot);
523  MD[n]->getValue(MDL_ANGLE_TILT, tilt);
524  MD[n]->getValue(MDL_ANGLE_PSI, psi);
525 }
526 
529 void ImageBase::setShifts(double xoff, double yoff, double zoff, const size_t n)
530 {
531  MD[n]->setValue(MDL_SHIFT_X, xoff);
532  MD[n]->setValue(MDL_SHIFT_Y, yoff);
533  MD[n]->setValue(MDL_SHIFT_Z, zoff);
534 }
537 void ImageBase::getShifts(double &xoff, double &yoff, double &zoff, const size_t n) const
538 {
539  MD[n]->getValue(MDL_SHIFT_X, xoff);
540  MD[n]->getValue(MDL_SHIFT_Y, yoff);
541  MD[n]->getValue(MDL_SHIFT_Z, zoff);
542 }
543 
544 void ImageBase::getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const
545 {
546  Xdim = XSIZE(*mdaBase);
547  Ydim = YSIZE(*mdaBase);
548  Zdim = ZSIZE(*mdaBase);
549  Ndim = NSIZE(*mdaBase);
550 }
551 
554 void ImageBase::getInfo(ImageInfo &imgInfo) const
555 {
556  imgInfo.filename = filename;
557  imgInfo.offset = offset;
558  imgInfo.datatype = datatype();
559  imgInfo.swap = getSwap() > 0;
560  imgInfo.adim = aDimFile ;
561 }
562 
564 {
565  read(name, HEADER);
566  getInfo(imgInfo);
567 }
568 
573 {
574  if (name.empty())
575  REPORT_ERROR(ERR_PARAM_INCORRECT, "ImageBase::openFile Cannot open an empty Filename.");
576 
578  FileName fileName, headName = "";
579  FileName ext_name = name.getFileFormat();
580 
581  // Remove image number and block name
582  fileName = name.removeAllPrefixes();
583 
584  fileName = fileName.removeFileFormat();
585 
586  size_t found = fileName.find_first_of("%");
587  if (found!=String::npos)
588  fileName = fileName.substr(0, found) ;
589 
590  bool exist = fileName.exists();
591  bool sizeZero = true;
592 
593  if (exist)
594  sizeZero = fileName.getFileSize() <= 0;
595  hFile->exist = exist && !sizeZero;
596  hFile->mode = mode;
597 
598  String wmChar;
599 
600  switch (mode)
601  {
602  case WRITE_READONLY:
603  if (!exist)
604  REPORT_ERROR(ERR_IO_NOTEXIST, formatString("Cannot access file '%s'. It doesn't exist", name.c_str()));
605  else if (sizeZero)
606  REPORT_ERROR(ERR_IO_SIZE, formatString("Cannot read zero size file '%s'.", name.c_str()));
607 
608  wmChar = "r";
609  break;
610  case WRITE_OVERWRITE:
611  wmChar = "w";
612  break;
613  case WRITE_APPEND:
614  case WRITE_REPLACE:
615  wmChar = (hFile->exist) ? "r+" : "w+";
616  break;
617 
618  }
619 
620  if (ext_name.contains("tif"))
621  {
622  TIFFSetWarningHandler(NULL); // Switch off warning messages
623  if ((hFile->tif = TIFFOpen(fileName.c_str(), wmChar.c_str())) == NULL)
624  REPORT_ERROR(ERR_IO_NOTOPEN,"rwTIFF: There is a problem opening the TIFF file.");
625  hFile->fimg = NULL;
626  hFile->fhed = NULL;
627  }
628  else if (ext_name.contains("hdf") || ext_name.contains("h5"))
629  {
630  if ((hFile->fhdf5 = H5Fopen(fileName.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT)) == -1 )
631  REPORT_ERROR(ERR_IO_NOTOPEN,"ImageBase::openFile: There is a problem opening the HDF5 file.");
632  // hFile->fimg = NULL;
633 
634  if ( (hFile->fimg = fopen(fileName.c_str(), wmChar.c_str())) == NULL )
635  {
636  if (errno == EACCES)
637  REPORT_ERROR(ERR_IO_NOPERM,formatString("Image::openFile: permission denied when opening %s",fileName.c_str()));
638  else
639  REPORT_ERROR(ERR_IO_NOTOPEN,formatString("Image::openFile cannot open: %s", fileName.c_str()));
640  }
641 
642  hFile->fhed = NULL;
643  hFile->tif = NULL;
644  }
645  else
646  {
647  hFile->tif = NULL;
648 
649  if (ext_name.contains("img") || ext_name.contains("hed"))
650  {
651  fileName = fileName.withoutExtension();
652  headName = fileName.addExtension("hed");
653  fileName = fileName.addExtension("img");
654  }
655  else if (ext_name.contains("raw"))
656  {
657  if (mode != WRITE_READONLY || fileName.addExtension("inf").exists() )
658  {
659  headName = fileName.addExtension("inf");
660  ext_name = "inf";
661  }
662  else
663  ext_name = "raw";
664  }
665  else if (ext_name.contains("inf"))
666  {
667  headName = fileName;
668  fileName = fileName.withoutExtension();
669  ext_name = "inf";
670  }
671 
672  // Open image file
673  if ( (hFile->fimg = fopen(fileName.c_str(), wmChar.c_str())) == NULL )
674  {
675  if (errno == EACCES)
676  REPORT_ERROR(ERR_IO_NOPERM,formatString("Image::openFile: permission denied when opening %s",fileName.c_str()));
677  else
678  REPORT_ERROR(ERR_IO_NOTOPEN,formatString("Image::openFile cannot open: %s", fileName.c_str()));
679  }
680 
681 
682  if (headName != "")
683  {
684  if ((hFile->fhed = fopen(headName.c_str(), wmChar.c_str())) == NULL )
685  {
686  if (errno == EACCES)
687  REPORT_ERROR(ERR_IO_NOPERM,formatString("Image::openFile: permission denied when opening %s",headName.c_str()));
688  else
689  REPORT_ERROR(ERR_IO_NOTOPEN,formatString("Image::openFile cannot open: %s",headName.c_str()));
690  }
691 
692  }
693  else
694  hFile->fhed = NULL;
695 
696  }
697  hFile->fileName = fileName;
698  hFile->headName = headName;
699  hFile->ext_name = ext_name;
700 
701  return hFile;
702 }
703 
708 {
709  FileName ext_name, fileName;
710  FILE* fimg, *fhed;
711  TIFF* tif;
712  hid_t fhdf5;
713 
714  if (hFile != NULL)
715  {
716  fileName = hFile->fileName;
717  ext_name = hFile->ext_name;
718  fimg = hFile->fimg;
719  fhed = hFile->fhed;
720  tif = hFile->tif;
721  fhdf5 = hFile->fhdf5;
722  }
723  else
724  {
725  fileName = filename;
726  ext_name = filename.getFileFormat();
727  fimg = this->fimg;
728  fhed = this->fhed;
729  tif = this->tif;
730  fhdf5 = this->fhdf5;
731 
732  }
733 
734  if (ext_name.contains("tif"))
735  {
736  TIFFClose(tif);
737  /* Since when creating a TIFF file without adding an image the file is 8 bytes
738  * and this same file returns an error when trying to open again, we are going
739  * to suppose that under 8 bytes this is empty.
740  */
741  if (fileName.getFileSize() < 9)
743  }
744  else if (ext_name.contains("hdf") || ext_name.contains("h5"))
745  {
746  H5Fclose(fhdf5);
747  if (fclose(fimg) != 0 )
748  REPORT_ERROR(ERR_IO_NOCLOSED,(String)"Can not close image file "+ filename);
749  }
750  else
751  {
752  if (fclose(fimg) != 0 )
753  REPORT_ERROR(ERR_IO_NOCLOSED,(String)"Can not close image file "+ filename);
754 
755  if (fhed != NULL && fclose(fhed) != 0 )
756  REPORT_ERROR(ERR_IO_NOCLOSED,(String)"Can not close header file of "
757  + filename);
758  }
759  delete hFile;
760 }
761 
762 bool isDynamicMRC(const char * envvar, const String &ext)
763 {
764  FileName mrcExtensions;
765  if (getenv(envvar))
766  mrcExtensions=getenv(envvar);
767  String plainExt = ext;
768  size_t found = ext.find_first_of("%");
769  if (found!=String::npos)
770  plainExt = ext.substr(0, found);
771  else
772  return false;
773  return mrcExtensions.contains(plainExt);
774 }
775 
776 bool isMRCStack(const FileName &ext_name)
777 {
778  return ext_name.contains("mrcs") || ext_name.contains("st") ||
779  ext_name.contains("preali") || ext_name.contains("ali") ||
780  ext_name.contains("fixed") ||
781  isDynamicMRC("XMIPP_MRC_STACK_EXTENSIONS",ext_name);
782 }
783 
784 bool isMRCImageOrVolume(const FileName &ext_name)
785 {
786  return ext_name.contains("mrc") || ext_name.contains("map") ||
787  ext_name.contains("rec") || isDynamicMRC("XMIPP_MRC_EXTENSIONS",ext_name);
788 }
789 
790 /* Internal read image file method.
791  */
792 int ImageBase::_read(const FileName &name, ImageFHandler* hFile, DataMode datamode, size_t select_img,
793  bool mapData)
794 {
795  // Temporary Error to find old select_img == -1
796  if (select_img == (size_t) -1)
797  REPORT_ERROR(ERR_DEBUG_TEST, "To select all images use ALL_IMAGES macro, or FIRST_IMAGE macro.");
798 
799  int err = 0;
800  dataMode = datamode;
801 
802  // If MultidimArray pointer has been moved to a slice/image different from zero, then reset it.
803  // This check must be done prior to mappedSize check, since mappedSlice is a trick over data pointer
804  if ( virtualOffset != 0)
806  // If Image has been previously used with mmap, then close the previous file
807  if (mappedSize != 0)
808  munmapFile();
809 
810  // Check whether to map the data or not
811 #ifdef XMIPP_MMAP
812 
813  mmapOnRead = mapData;
814 #endif
815 
816  const auto &ext_name = hFile->ext_name;
817  fimg = hFile->fimg;
818  fhed = hFile->fhed;
819  tif = hFile->tif;
820  fhdf5 = hFile->fhdf5;
821 
822  size_t image_num = name.getPrefixNumber();
823  filename = name;
824  dataFName = hFile->fileName;
825 
826  if (image_num != ALL_IMAGES)
827  select_img = image_num;
828 
829 #undef DEBUG
830  // #define DEBUG
831 #ifdef DEBUG
832 
833  std::cerr << "READ\n" <<
834  "name="<<name <<std::endl;
835  std::cerr << "ext= "<<ext_name <<std::endl;
836  std::cerr << " now reading: "<< filename <<" dataflag= "<<dataMode
837  << " select_img " << select_img << ", image_num = " << image_num << std::endl;
838 #endif
839 #undef DEBUG
840 
841  // Defining default axis order (will be overwritten by data types that need it)
843 
844  //Just clear the header before reading
846  //Set the file pointer at beginning
847  if (fimg != NULL)
848  fseek(fimg, 0, SEEK_SET);
849  if (fhed != NULL)
850  fseek(fhed, 0, SEEK_SET);
851 
852  if (ext_name.contains("spi") || ext_name.contains("xmp") ||
853  ext_name.contains("stk") || ext_name.contains("vol"))
854  err = readSPIDER(select_img);
855  else if (isMRCStack(ext_name)) //mrc stack MUST go BEFORE plain MRC
856  err = readMRC(select_img,true);
857  else if (isMRCImageOrVolume(ext_name)) //mrc
858  err = readMRC(select_img,false);
859  else if (ext_name.contains("eer"))//EER
860  err = readEER(select_img);
861  else if (ext_name.contains("img") || ext_name.contains("hed"))//
862  err = readIMAGIC(select_img);//imagic is always an stack
863  else if (ext_name.contains("ser"))//TIA
864  err = readTIA(select_img,false);
865  else if (ext_name.contains("dm3"))//DM3
866  err = readDM3(select_img,false);
867  else if (ext_name.contains("dm4"))//DM4
868  err = readDM4(select_img,false);
869  else if (ext_name.contains("ems"))//EM stack
870  err = readEM(select_img, true);
871  else if (ext_name.contains("em"))//EM
872  err = readEM(select_img);
873  else if (ext_name.contains("pif"))//PIF
874  err = readPIF(select_img);
875  else if (ext_name.contains("inf"))//RAW with INF file
876  err = readINF(select_img,false);
877  else if (ext_name.contains("raw"))//RAW without INF file
878  err = readRAW(select_img,false);
879  else if (ext_name.contains("tif") || ext_name.contains("gain"))//TIFF
880  err = readTIFF(select_img,false);
881  else if (ext_name.contains("spe"))//SPE
882  err = readSPE(select_img,false);
883  else if (ext_name.contains("jpg"))//SPE
884  err = readJPEG(select_img);
885  else if (ext_name.contains("hdf") || ext_name.contains("h5"))//SPE
886  err = readHDF5(select_img);
887  else
888  err = readSPIDER(select_img);
889 
890  // Negative errors are bad.
891  return err;
892 }
893 
894 int ImageBase::_readBatch(const FileName &name, ImageFHandler* hFile, size_t start_img, size_t batch_size, DataMode datamode,
895  bool mapData)
896 {
897 
898  int err = 0;
899  dataMode = datamode;
900 
901  // If MultidimArray pointer has been moved to a slice/image different from zero, then reset it.
902  // This check must be done prior to mappedSize check, since mappedSlice is a trick over data pointer
903  if ( virtualOffset != 0)
905  // If Image has been previously used with mmap, then close the previous file
906  if (mappedSize != 0)
907  munmapFile();
908 
909  // Check whether to map the data or not
910 #ifdef XMIPP_MMAP
911 
912  mmapOnRead = mapData;
913 #endif
914 
915  const auto &ext_name = hFile->ext_name;
916  fimg = hFile->fimg;
917  fhed = hFile->fhed;
918  tif = hFile->tif;
919  fhdf5 = hFile->fhdf5;
920 
921  filename = name;
922  dataFName = hFile->fileName;
923 
924 
925  //Just clear the header before reading
927  //Set the file pointer at beginning
928  if (fimg != NULL)
929  fseek(fimg, 0, SEEK_SET);
930  if (fhed != NULL)
931  fseek(fhed, 0, SEEK_SET);
932 
933  if (ext_name.contains("spi") || ext_name.contains("xmp") ||
934  ext_name.contains("stk") || ext_name.contains("vol")) {
935  err = readSPIDER(start_img, batch_size);
936  } else if (isMRCStack(ext_name)) { //mrc stack MUST go BEFORE plain MRC
937  err = readMRC(start_img, batch_size, true);
938  } else if (isMRCImageOrVolume(ext_name)) {//mrc
939  err = readMRC(start_img, batch_size, false);
940  } else {
941  REPORT_ERROR(ERR_NOT_IMPLEMENTED, "Reading of a range of files is implemented only for SPIDER and MRC stack.");
942  }
943 
944  // Negative errors are bad.
945  return err;
946 }
947 
948 /* Internal write image file method.
949  */
950 void ImageBase::_write(const FileName &name, ImageFHandler* hFile, size_t select_img,
951  bool isStack, int mode, CastWriteMode castMode)
952 {
953  // Temporary Error to find old select_img == -1
954  if (select_img == (size_t) -1)
955  REPORT_ERROR(ERR_DEBUG_TEST, "To select all images use ALL_IMAGES macro, or FIRST_IMAGE macro.");
956 
957  int err = 0;
958 
959  // if image is mapped to file then close the file and clear
960  if (mmapOnWrite && mappedSize > 0)
961  {
962  munmapFile();
963  return;
964  }
965 
966  filename = name;
967  dataFName = hFile->fileName;
968  _exists = hFile->exist;
969  fimg = hFile->fimg;
970  fhed = hFile->fhed;
971  tif = hFile->tif;
972 
973  FileName ext_name = hFile->ext_name;
974 
975  size_t aux;
976  FileName filNamePlusExt;
977  name.decompose(aux, filNamePlusExt);
978 
979  if (select_img == ALL_IMAGES)
980  select_img = aux;
981 
983  size_t found = filNamePlusExt.find_first_of("%");
984  String imParam = "";
985  if (found!=String::npos)
986  {
987  imParam = filNamePlusExt.substr(found+1).c_str();
988  filNamePlusExt = filNamePlusExt.substr(0, found) ;
989  }
990 
991  // #define DEBUG
992 #ifdef DEBUG
993 
994  std::cerr << "write" <<std::endl;
995  std::cerr<<"extension for write= "<<ext_name<<std::endl;
996  std::cerr<<"filename= "<<filename<<std::endl;
997  std::cerr<<"mode= "<<mode<<std::endl;
998  std::cerr<<"isStack= "<<isStack<<std::endl;
999  std::cerr<<"select_img= "<<select_img<<std::endl;
1000  std::cerr << "exists=" << _exists << std::endl;
1001 #endif
1002 #undef DEBUG
1003  // Check that image is not empty
1004  if (getSize() < 1)
1005  REPORT_ERROR(ERR_MULTIDIM_EMPTY,(String)"write Image ERROR: image "+name+" is empty!");
1006 
1007  replaceNsize = 0;//reset replaceNsize in case image is reused
1008  if(isStack && select_img == ALL_IMAGES && mode == WRITE_REPLACE)
1009  REPORT_ERROR(ERR_VALUE_INCORRECT,"Please specify object to be replaced");
1010  else if (_exists && (mode == WRITE_REPLACE || mode == WRITE_APPEND))
1011  {
1012  // CHECK FOR INCONSISTENCIES BETWEEN data.xdim and x, etc???
1013  size_t Xdim, Ydim, Zdim, _Xdim, _Ydim, _Zdim, Ndim, _Ndim;
1014  Xdim = Ydim = Zdim = _Xdim = _Ydim = _Zdim = Ndim = _Ndim = 0;
1015  if (nullptr == m_auxI) {
1016  m_auxI = new Image<char>();
1017  }
1018  m_auxI->_read(filNamePlusExt, hFile, HEADER, ALL_IMAGES);
1019 
1020  this->getDimensions(Xdim, Ydim, Zdim, Ndim);
1021  m_auxI->getDimensions(_Xdim, _Ydim, _Zdim, _Ndim);
1022 
1023  if(m_auxI->getSize()>1)
1024  {
1025  replaceNsize = _Ndim;
1026 
1029  if (select_img > ALL_IMAGES || Ndim < replaceNsize)
1030  swapWrite = m_auxI->swap;
1031 
1032  if(Xdim != _Xdim ||
1033  Ydim != _Ydim ||
1034  Zdim != _Zdim)
1035  {
1037  "ImageBase::Write: images source and target have different sizes:\n"
1038  "Image source to be written (x,y,z,n) = %d %d %d %lu\n"
1039  "Image file target %s (x,y,z,n) = %d %d %d %lu",
1040  Xdim,Ydim,Zdim,Ndim,dataFName.c_str(),_Xdim,_Ydim,_Zdim,_Ndim));
1041  }
1042  }
1043  }
1044  else if(!_exists && mode == WRITE_APPEND)
1045  {
1046  ;
1047  }
1048  else if (mode == WRITE_READONLY)//If new file we are in the WRITE_OVERWRITE mode
1049  {
1050  REPORT_ERROR(ERR_ARG_INCORRECT, formatString("File %s opened in read-only mode. Cannot write.", name.c_str()));
1051  }
1052 
1053  /*
1054  * SELECT FORMAT
1055  */
1056  //Set the file pointer at beginning
1057  if (fimg != NULL)
1058  fseek(fimg, 0, SEEK_SET);
1059  if (fhed != NULL)
1060  fseek(fhed, 0, SEEK_SET);
1061 
1062  if(ext_name.contains("spi") || ext_name.contains("xmp") ||
1063  ext_name.contains("vol"))
1064  err = writeSPIDER(select_img,isStack,mode);
1065  else if (ext_name.contains("stk"))
1066  err = writeSPIDER(select_img,true,mode);
1067  else if (isMRCStack(ext_name) || isMRCImageOrVolume(ext_name))
1068  writeMRC(select_img,isStack,mode,imParam,castMode);
1069  else if (ext_name.contains("img") || ext_name.contains("hed"))
1070  writeIMAGIC(select_img,mode,imParam,castMode);
1071  else if (ext_name.contains("dm3"))
1072  writeDM3(select_img,false,mode);
1073  else if (ext_name.contains("dm4"))
1074  writeDM4(select_img,false,mode);
1075  else if (ext_name.contains("em"))
1076  writeEM(select_img,false,mode);
1077  else if (ext_name.contains("pif"))
1078  writePIF(select_img,false,mode);
1079  else if (ext_name.contains("ser"))
1080  writeTIA(select_img,false,mode);
1081  else if (ext_name.contains("raw") || ext_name.contains("inf"))
1082  writeINF(select_img,false,mode,imParam,castMode);
1083  else if (ext_name.contains("tif"))
1084  writeTIFF(select_img,isStack,mode,imParam,castMode);
1085  else if (ext_name.contains("spe"))
1086  writeSPE(select_img,isStack,mode);
1087  else if (ext_name.contains("jpg"))
1088  writeJPEG(select_img, false, WRITE_OVERWRITE, "", CW_ADJUST);
1089  else if (ext_name.contains("hdf5") || ext_name.contains("h5"))
1090  writeHDF5(select_img);
1091  else
1092  err = writeSPIDER(select_img,isStack,mode);
1093 
1094  if ( err < 0 )
1095  {
1096  std::cerr << " Filename = " << filename << " Extension= " << ext_name << std::endl;
1097  REPORT_ERROR(ERR_IO_NOWRITE, "Error writing file");
1098  }
1099 
1100  /* If initially the file did not existed, once the first image is written,
1101  * then the file exists
1102  */
1103  if (!_exists)
1104  hFile->exist = _exists = true;
1105 }
1106 
1108 {
1109  try
1110  {
1111  return !read(name, HEADER);
1112  }
1113  catch (XmippError &xe)
1114  {
1115  return false;
1116  }
1117 }
1118 
1121 std::ostream& operator<<(std::ostream& o, const ImageBase& I)
1122 {
1123  o << std::endl;
1124  DataType * fileDT = NULL;
1125  if (!I.filename.empty())
1126  {
1127  o << "--- File information ---" << std::endl;
1128  o << "Filename : " << I.filename << std::endl;
1129  o << "Endianess : ";
1130  if (I.swap^IsLittleEndian())
1131  o << "Little" << std::endl;
1132  else
1133  o << "Big" << std::endl;
1134 
1135  o << "Reversed : ";
1136  if (I.swap)
1137  o << "True" << std::endl;
1138  else
1139  o << "False" << std::endl;
1140  fileDT = new DataType;
1141  *fileDT = I.datatype();
1142  o << "Data type : " << datatype2StrLong(*fileDT) << std::endl;
1143  o << "Data offset : " << I.offset << std::endl;
1144  }
1145 
1146  o << "--- Image information ---" << std::endl;
1147 
1148  DataType myDT = I.myT();
1149  if ((fileDT == NULL || myDT != *fileDT) && I.dataMode >= DATA )
1150  o << "Memory datatype: " << datatype2StrLong(I.myT()) << std::endl;
1151  o << "Image type : ";
1152  if (I.isComplex())
1153  o << "Fourier-space image" << std::endl;
1154  else
1155  o << "Real-space image" << std::endl;
1156 
1157  delete fileDT;
1158 
1159  size_t xdim, ydim, zdim, ndim;
1160  I.getDimensions(xdim, ydim, zdim, ndim);
1161  o << "Dimensions : " << ndim << " x " << zdim << " x " << ydim << " x " << xdim;
1162  o << " ((N)Objects x (Z)Slices x (Y)Rows x (X)Columns)" << std::endl;
1163 
1164  double sampling;
1166  if (sampling > 0)
1167  {
1168  o << "Sampling rate : " << std::endl;
1169  o << " X-rate (Angstrom/pixel) = " << sampling << std::endl;
1171  o << " Y-rate (Angstrom/pixel) = " << sampling << std::endl;
1173  o << " Z-rate (Angstrom/pixel) = " << sampling << std::endl;
1174  }
1175 
1176  std::stringstream oGeo;
1177 
1179  {
1180  oGeo << "Euler angles : " << std::endl;
1181  oGeo << " Phi (rotation around Z axis) = " << I.rot() << std::endl;
1182  oGeo << " Theta (tilt, second rotation around new Y axis) = " << I.tilt() << std::endl;
1183  oGeo << " Psi (third rotation around new Z axis) = " << I.psi() << std::endl;
1184  }
1186  {
1187  oGeo << "Origin Offsets : " << std::endl;
1188  oGeo << " Xoff (origin offset in X-direction) = " << I.Xoff() << std::endl;
1189  oGeo << " Yoff (origin offset in Y-direction) = " << I.Yoff() << std::endl;
1190  oGeo << " Zoff (origin offset in Z-direction) = " << I.Zoff() << std::endl;
1191  }
1193  oGeo << "Scale : " <<I.scale() << std::endl;
1195  oGeo << "Weight : " << I.weight() << std::endl;
1197  oGeo << "Flip : " << I.flip() << std::endl;
1198 
1199  if (!oGeo.str().empty())
1200  o << "--- Geometry ---" << std::endl << oGeo.str();
1201 
1202  return o;
1203 }
1204 
1206 {
1207  delete m_auxI;
1208 }
virtual void munmapFile()=0
ImageFHandler * openFile(const FileName &name, int mode=WRITE_READONLY) const
#define NSIZE(v)
int readBatch(const FileName &name, size_t start_img, size_t batch_size, DataMode datamode=DATA, bool mapData=false, int mode=WRITE_READONLY)
int readOrReadMapped(const FileName &name, size_t select_img=ALL_IMAGES, int mode=WRITE_READONLY)
Rotation angle of an image (double,degrees)
#define YSIZE(v)
int writeTIA(int img_select, bool isStack=false, int mode=WRITE_OVERWRITE)
Definition: rwTIA.cpp:253
Parameter incorrect.
Definition: xmipp_error.h:181
std::array< int, 4 > axisOrder
int readEM(size_t select_img, bool isStack=false)
Definition: rwEM.cpp:33
Case or algorithm not implemented yet.
Definition: xmipp_error.h:177
sampling rate in A/pixel (double)
void reportWarning(const String &what)
int writeDM3(size_t img_select, bool isStack=false, int mode=WRITE_OVERWRITE)
Definition: rwDM3.cpp:437
sampling rate in A/pixel (double)
FileName filename
struct tiff TIFF
MultidimArray is empty.
Definition: xmipp_error.h:175
DataMode dataMode
Just an error for debugging purpose.
Definition: xmipp_error.h:119
sampling rate in A/pixel (double)
bool IsLittleEndian(void)
ArrayDim aDimFile
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Error with some arguments dependencies.
Definition: xmipp_error.h:115
FileName removeFileFormat() const
void swapbytes(char *v, unsigned long n)
double psi(const size_t n=0) const
double Zoff(const size_t n=0) const
int writeSPE(size_t select_img, bool isStack=false, int mode=WRITE_OVERWRITE)
Definition: rwSPE.cpp:84
int readRange(const FileName &name, size_t start_img, size_t end_img, DataMode datamode=DATA, bool mapData=false, int mode=WRITE_READONLY)
size_t mappedOffset
int getSwap() const
FileName tempFilename
FileName dataFName
int readDM3(size_t img_select, bool isStack=false)
Definition: rwDM3.cpp:445
Tilting angle of an image (double,degrees)
Couldn&#39;t write to file.
Definition: xmipp_error.h:140
FileName addExtension(const String &ext) const
void setValue(const MDObject &object) override
int writeHDF5(size_t select_img, bool isStack=false, int mode=WRITE_OVERWRITE, String bitDepth="", CastWriteMode castMode=CW_CAST)
Definition: rwHDF5.cpp:321
Shift for the image in the X axis (double)
int readSPIDER(size_t select_img)
Definition: rwSPIDER.cpp:292
int writeIMAGIC(size_t img_select=ALL_IMAGES, int mode=WRITE_OVERWRITE, const String &bitDepth="", CastWriteMode castMode=CW_CAST)
Definition: rwIMAGIC.cpp:259
There is not enough memory for allocation.
Definition: xmipp_error.h:166
void swapPage(char *page, size_t pageNrElements, DataType datatype, int swap=1)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
std::vector< std::unique_ptr< MDRow > > MD
static void emptifyHeader(MDRow &)
size_t getSize() const
Definition: xmipp_image.h:1091
friend std::ostream & operator<<(std::ostream &o, const ImageBase &I)
ImageFHandler * hFile
const T & getValueOrDefault(MDLabel label, const T &def) const
int readSPE(size_t select_img, bool isStack=false)
Definition: rwSPE.cpp:38
void setDatatype(DataType datatype)
ArrayDim getDimensions()
Special label to be used when gathering MDs in MpiMetadataPrograms.
int readIMAGIC(size_t img_select)
Definition: rwIMAGIC.cpp:127
const FileName & name() const
static constexpr std::array< int, 4 > defaultAxisOrder
if read from file original image datatype, this is an struct defined in image
bool isComplex() const
virtual int readPreview(const FileName &name, size_t Xdim, size_t Ydim=0, int select_slice=CENTRAL_SLICE, size_t select_img=FIRST_IMAGE)=0
Input/Output general error.
Definition: xmipp_error.h:134
void initUniqueName(const char *templateStr="xmippTemp_XXXXXX", const String &fnDir="")
TransformType transform
virtual ~ImageBase()
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
double rot(const size_t n=0) const
void decompose(size_t &no, String &str) const
size_t virtualOffset
double weight(const size_t n=0) const
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams &params=DefaultApplyGeoParams)
DataMode
#define i
Incorrect number of objects in Metadata.
Definition: xmipp_error.h:160
int writeTIFF(size_t select_img, bool isStack=false, int mode=WRITE_OVERWRITE, String bitDepth="", CastWriteMode castMode=CW_CAST)
Definition: rwTIFF.cpp:342
File cannot be closed.
Definition: xmipp_error.h:135
T & getValue(MDLabel label)
int writeMRC(size_t select_img, bool isStack=false, int mode=WRITE_OVERWRITE, const String &bitDepth="", CastWriteMode castMode=CW_CAST)
Definition: rwMRC.cpp:369
void _write(const FileName &name, ImageFHandler *hFile, size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST)
double tilt(const size_t n=0) const
String getExtension() const
FileName removeAllPrefixes() const
int writeEM(size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE)
Definition: rwEM.cpp:148
void closeFile(ImageFHandler *hFile=NULL) const
void setShifts(double xoff, double yoff, double zoff=0., const size_t n=0)
void getInfo(ImageInfo &imgInfo) const
int readTIA(int img_select, bool isStack=false)
Definition: rwTIA.cpp:79
int readMRC(size_t select_img, bool isStack=false)
Definition: rwMRC.cpp:352
int readPIF(size_t select_img)
Definition: rwPIF.cpp:33
int writeINF(size_t img_select, bool isStack=false, int mode=WRITE_OVERWRITE, String bitDepth="", CastWriteMode castMode=CW_CAST)
Definition: rwINF.cpp:132
size_t getPrefixNumber(size_t pos=0) const
Incorrect argument received.
Definition: xmipp_error.h:113
int readOrReadPreview(const FileName &name, size_t Xdim, size_t Ydim, int select_slice=CENTRAL_SLICE, size_t select_img=FIRST_IMAGE, bool mapData=false)
Flip the image? (bool)
int writePIF(size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE)
Definition: rwPIF.cpp:161
virtual void setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)=0
#define sampling
#define XSIZE(v)
double Yoff(const size_t n=0) const
void getEulerAngles(double &rot, double &tilt, double &psi, const size_t n=0) const
double scale(const size_t n=0) const
virtual bool isComplexT() const =0
#define ZSIZE(v)
int readEER(size_t select_img)
Definition: rwEER.cpp:569
virtual std::unique_ptr< MDRow > getRow(size_t id)=0
File or directory does not exist.
Definition: xmipp_error.h:136
void applyGeo(const MetaData &md, size_t objId, const ApplyGeoParams &params=DefaultApplyGeoParams)
DataType
scaling factor for an image or volume (double)
ArrayDim adim
void mode
double dummy
Image base class.
bool contains(const String &str) const
std::string datatype2StrLong(DataType datatype)
int writeSPIDER(size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE)
Definition: rwSPIDER.cpp:320
bool exists() const
int readHDF5(size_t select_img)
Definition: rwHDF5.cpp:136
void setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)
virtual void movePointerTo(int select_slice=ALL_SLICES, size_t select_img=ALL_IMAGES)=0
bool isDynamicMRC(const char *envvar, const String &ext)
void deleteFile() const
int readJPEG(size_t select_img)
Definition: rwJPEG.cpp:34
int readTIFF(size_t select_img, bool isStack=false)
Definition: rwTIFF.cpp:134
void setEulerAngles(double rot, double tilt, double psi, const size_t n=0)
int readINF(size_t img_select, bool isStack=false)
Definition: rwINF.cpp:39
MDRowVec MDMainHeader
bool individualContainsLabel(MDLabel label) const
File cannot be open.
Definition: xmipp_error.h:137
size_t mappedSize
void initGeometry(const size_t n=0)
int _read(const FileName &name, ImageFHandler *hFile, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)
int readDM4(size_t img_select, bool isStack=false)
Definition: rwDM4.cpp:466
double samplingRateX() const
FileName withoutExtension() const
int readRAW(size_t select_img, bool isStack=false)
Definition: rwRAW.cpp:70
DataType datatype() const
std::string String
Definition: xmipp_strings.h:34
double Xoff(const size_t n=0) const
#define ALL_IMAGES
String formatString(const char *format,...)
Shift for the image in the Z axis (double)
String getFileFormat() const
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
ErrorType __errno
Definition: xmipp_error.h:227
DataType datatype
FileName filename
Incorrect file size.
Definition: xmipp_error.h:145
bool flip(const size_t n=0) const
CastWriteMode
Shift for the image in the Y axis (double)
#define READ_AND_RETURN()
virtual DataType myT() const =0
bool isMRCStack(const FileName &ext_name)
Insufficient permissions to perform operation.
Definition: xmipp_error.h:138
void clear() override
bool isImage(const FileName &name)
int readMapped(const FileName &name, size_t select_img=ALL_IMAGES, int mode=WRITE_READONLY)
Incorrect value received.
Definition: xmipp_error.h:195
void copy(const ImageBase &other)
#define ALL_SLICES
void mapFile2Write(size_t Xdim, size_t Ydim, size_t Zdim, const FileName &_filename, bool createTempFile=false, size_t select_img=APPEND_IMAGE, bool isStack=false, int mode=WRITE_OVERWRITE)
size_t replaceNsize
MultidimArrayBase * mdaBase
int * n
Name of an image (std::string)
int writeJPEG(size_t select_img, bool isStack=false, int mode=WRITE_OVERWRITE, String bitDepth="", CastWriteMode castMode=CW_CONVERT)
Definition: rwJPEG.cpp:130
size_t getFileSize() const
int writeDM4(size_t img_select, bool isStack=false, int mode=WRITE_OVERWRITE)
Definition: rwDM4.cpp:676
virtual size_t getSize() const =0
< Score 4 for volumes
bool isInStack() const
void getShifts(double &xoff, double &yoff, double &zoff, const size_t n=0) const
bool isMRCImageOrVolume(const FileName &ext_name)
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const
void setGeo(const MDRow &row, size_t n=0)
int _readBatch(const FileName &name, ImageFHandler *hFile, size_t start_img, size_t batch_size, DataMode datamode=DATA, bool mapData=false)
size_t gettypesize(DataType type)
Returns memory size of datatype.