Xmipp  v3.23.11-Nereus
Classes | Public Member Functions | Protected Member Functions | List of all members
Alignment::AProgAlignSignificant< T > Class Template Referenceabstract

#include <aalign_significant.h>

Inheritance diagram for Alignment::AProgAlignSignificant< T >:
Inheritance graph
[legend]
Collaboration diagram for Alignment::AProgAlignSignificant< T >:
Collaboration graph
[legend]

Classes

struct  Assignment
 
struct  Settings
 

Public Member Functions

virtual void readParams () override
 
virtual void defineParams () override
 
virtual void show () const override
 
virtual void run () override
 
- Public Member Functions inherited from XmippProgram
const char * getParam (const char *param, int arg=0)
 
const char * getParam (const char *param, const char *subparam, int arg=0)
 
int getIntParam (const char *param, int arg=0)
 
int getIntParam (const char *param, const char *subparam, int arg=0)
 
double getDoubleParam (const char *param, int arg=0)
 
double getDoubleParam (const char *param, const char *subparam, int arg=0)
 
float getFloatParam (const char *param, int arg=0)
 
float getFloatParam (const char *param, const char *subparam, int arg=0)
 
void getListParam (const char *param, StringVector &list)
 
int getCountParam (const char *param)
 
bool checkParam (const char *param)
 
bool existsParam (const char *param)
 
void addParamsLine (const String &line)
 
void addParamsLine (const char *line)
 
ParamDefgetParamDef (const char *param) const
 
virtual void quit (int exit_code=0) const
 
virtual int tryRun ()
 
void initProgress (size_t total, size_t stepBin=60)
 
void setProgress (size_t value=0)
 
void endProgress ()
 
void processDefaultComment (const char *param, const char *left)
 
void setDefaultComment (const char *param, const char *comment)
 
virtual void initComments ()
 
void setProgramName (const char *name)
 
void addUsageLine (const char *line, bool verbatim=false)
 
void clearUsage ()
 
void addExampleLine (const char *example, bool verbatim=true)
 
void addSeeAlsoLine (const char *seeAlso)
 
void addKeywords (const char *keywords)
 
const char * name () const
 
virtual void usage (int verb=0) const
 
virtual void usage (const String &param, int verb=2)
 
int version () const
 
virtual void read (int argc, const char **argv, bool reportErrors=true)
 
virtual void read (int argc, char **argv, bool reportErrors=true)
 
void read (const String &argumentsLine)
 
 XmippProgram ()
 
 XmippProgram (int argc, const char **argv)
 
virtual ~XmippProgram ()
 

Protected Member Functions

virtual void check () const
 
const SettingsgetSettings ()
 
virtual std::vector< AlignmentEstimationalign (const T *ref, const T *others)=0
 
virtual void updateRefs (T *refs, const T *others, const std::vector< Assignment > &assignments)=0
 
ctpl::thread_poolgetThreadPool ()
 
void updateRefXmd (size_t refIndex, std::vector< Assignment > &images)
 
- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 

Additional Inherited Members

- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 
- Protected Attributes inherited from XmippProgram
int errorCode
 
ProgramDefprogDef
 Program definition and arguments parser. More...
 
std::map< String, CommentListdefaultComments
 
int argc
 Original command line arguments. More...
 
const char ** argv
 

Detailed Description

template<typename T>
class Alignment::AProgAlignSignificant< T >

Definition at line 46 of file aalign_significant.h.

Member Function Documentation

◆ align()

template<typename T >
virtual std::vector<AlignmentEstimation> Alignment::AProgAlignSignificant< T >::align ( const T *  ref,
const T *  others 
)
protectedpure virtual

◆ check()

template<typename T >
void Alignment::AProgAlignSignificant< T >::check ( ) const
protectedvirtual

Definition at line 206 of file aalign_significant.cpp.

206  {
207  if ( ! m_referenceImages.dims.equalExceptNPadded(m_imagesToAlign.dims)) {
208  REPORT_ERROR(ERR_LOGIC_ERROR, "Dimensions of the images to align and reference images do not match");
209  }
210  if (m_noOfBestToKeep > m_referenceImages.dims.n()) {
211  REPORT_ERROR(ERR_LOGIC_ERROR, "--keepBestN is higher than number of references");
212  }
213  if (m_referenceImages.dims.n() <= 1) {
214  REPORT_ERROR(ERR_LOGIC_ERROR, "We need at least two references");
215  }
216 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Some logical error in the pipeline.
Definition: xmipp_error.h:147

◆ defineParams()

template<typename T >
void Alignment::AProgAlignSignificant< T >::defineParams ( )
overridevirtual

Function in which the param of each Program are defined.

Reimplemented from XmippProgram.

Reimplemented in Alignment::ProgAlignSignificantGPU< T >.

Definition at line 32 of file aalign_significant.cpp.

32  {
33  addUsageLine("Find alignment of the experimental images in respect to a set of references");
34 
35  addParamsLine(" -i <md_file> : Metadata file with the experimental images");
36  addParamsLine(" -r <md_file> : Metadata file with the reference images");
37  addParamsLine(" -o <md_file> : Resulting metadata file with the aligned images");
38  addParamsLine(" [--thr <N=-1>] : Maximal number of the processing CPU threads");
39  addParamsLine(" [--angDistance <a=10>] : Angular distance");
40  addParamsLine(" [--odir <outputDir=\".\">] : Output directory");
41  addParamsLine(" [--keepBestN <N=1>] : For each image, store N best alignments to references. N must be smaller than no. of references");
42  addParamsLine(" [--allowInputSwap] : Allow swapping reference and experimental images");
43  addParamsLine(" [--useWeightInsteadOfCC] : Select the best reference using weight, instead of CC");
44  addParamsLine(" [--oUpdatedRefs <baseName=\"\">]: Update references using assigned experimental images. Store result here");
45 }
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ getSettings()

template<typename T >
const Settings& Alignment::AProgAlignSignificant< T >::getSettings ( )
inlineprotected

Definition at line 73 of file aalign_significant.h.

73  {
74  return m_settings;
75  }

◆ getThreadPool()

template<typename T >
ctpl::thread_pool& Alignment::AProgAlignSignificant< T >::getThreadPool ( )
inlineprotected

Definition at line 79 of file aalign_significant.h.

79  {
80  return m_threadPool;
81  }

◆ readParams()

template<typename T >
void Alignment::AProgAlignSignificant< T >::readParams ( )
overridevirtual

Function in which each program will read parameters that it need. If some error occurs the usage will be printed out.

Reimplemented from XmippProgram.

Reimplemented in Alignment::ProgAlignSignificantGPU< T >.

Definition at line 48 of file aalign_significant.cpp.

48  {
49  m_imagesToAlign.fn = getParam("-i");
50  m_referenceImages.fn = getParam("-r");
51  auto outDir = FileName(getParam("--odir"));
52  if ( ! outDir.exists()) {
53  if (outDir.makePath()) {
54  REPORT_ERROR(ERR_IO_NOWRITE, "cannot create " + outDir);
55  }
56  }
57  m_fnOut = outDir + "/" + std::string(getParam("-o"));
58  m_angDistance = getDoubleParam("--angDistance");
59  m_noOfBestToKeep = getIntParam("--keepBestN");
60  m_allowDataSwap = checkParam("--allowInputSwap");
61  m_useWeightInsteadOfCC = checkParam("--useWeightInsteadOfCC");
62  m_updateHelper.doUpdate = checkParam("--oUpdatedRefs");
63  if (m_updateHelper.doUpdate) {
64  FileName base = outDir + "/" + std::string(getParam("--oUpdatedRefs"));
65  m_updateHelper.fnStk = base + ".stk";
66  m_updateHelper.fnXmd = base + ".xmd";
67  }
68 
69  int threads = getIntParam("--thr");
70  if (-1 == threads) {
71  m_settings.cpuThreads = CPU::findCores();
72  } else {
73  m_settings.cpuThreads = threads;
74  }
75 }
double getDoubleParam(const char *param, int arg=0)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Couldn&#39;t write to file.
Definition: xmipp_error.h:140
static unsigned findCores()
Definition: cpu.h:41
const char * getParam(const char *param, int arg=0)
bool checkParam(const char *param)
int getIntParam(const char *param, int arg=0)

◆ run()

template<typename T >
void Alignment::AProgAlignSignificant< T >::run ( )
overridevirtual

This function will be start running the program. it also should be implemented by derived classes.

Reimplemented from XmippProgram.

Definition at line 575 of file aalign_significant.cpp.

575  {
576  show();
577  m_threadPool.resize(getSettings().cpuThreads);
578  // load data
579  load<false>(m_imagesToAlign);
580  load<true>(m_referenceImages);
581 
582  bool hasMoreReferences = m_allowDataSwap
583  && (m_referenceImages.dims.n() > m_imagesToAlign.dims.n());
584  if (hasMoreReferences) {
585  std::cerr << "We are swapping reference images and experimental images. "
586  "This will enhance the performance. This might lead to worse results if the experimental "
587  "images are not well centered. Use it with care!\n";
588  std::swap(m_referenceImages, m_imagesToAlign);
589  }
590 
591  // for each reference, get alignment of all images
592  updateSettings();
593  check();
594  auto alignment = align(m_referenceImages.data.get(), m_imagesToAlign.data.get());
595 
596  // process the alignment and store
597  if (hasMoreReferences) {
598  std::swap(m_referenceImages, m_imagesToAlign);
599  computeWeights<true>(alignment);
600  if (m_useWeightInsteadOfCC) {
601  computeAssignment<true, true>(alignment);
602  } else {
603  computeAssignment<true, false>(alignment);
604  }
605  } else {
606  computeWeights<false>(alignment);
607  if (m_useWeightInsteadOfCC) {
608  computeAssignment<false, true>(alignment);
609  } else {
610  computeAssignment<false, false>(alignment);
611  }
612  }
613  // at this moment, we can release some memory
614  m_weights.clear();
615  alignment.clear();
616 
617  if (m_useWeightInsteadOfCC) {
618  storeAlignedImages<true>();
619  } else {
620  storeAlignedImages<false>();
621  }
622 
623  if (m_updateHelper.doUpdate) {
624  updateRefs();
625  }
626 }
void resize(int nThreads)
Definition: ctpl.h:70
virtual void updateRefs(T *refs, const T *others, const std::vector< Assignment > &assignments)=0
virtual std::vector< AlignmentEstimation > align(const T *ref, const T *others)=0
virtual void show() const override

◆ show()

template<typename T >
void Alignment::AProgAlignSignificant< T >::show ( ) const
overridevirtual

Show parameters

Reimplemented from XmippProgram.

Reimplemented in Alignment::ProgAlignSignificantGPU< T >.

Definition at line 78 of file aalign_significant.cpp.

78  {
79  if (verbose < 1) return;
80 
81  std::cout << "Input metadata : " << m_imagesToAlign.fn << "\n";
82  std::cout << "Reference metadata : " << m_referenceImages.fn << "\n";
83  std::cout << "Output metadata : " << m_fnOut << "\n";
84  std::cout << "Angular distance : " << m_angDistance << "\n";
85  std::cout << "Best references kept : " << m_noOfBestToKeep << "\n";
86  if (m_updateHelper.doUpdate) {
87  std::cout << "Updated references : " << m_updateHelper.fnXmd << "\n";
88  }
89  std::cout.flush();
90 }
int verbose
Verbosity level.

◆ updateRefs()

template<typename T >
virtual void Alignment::AProgAlignSignificant< T >::updateRefs ( T *  refs,
const T *  others,
const std::vector< Assignment > &  assignments 
)
protectedpure virtual

◆ updateRefXmd()

template<typename T >
void Alignment::AProgAlignSignificant< T >::updateRefXmd ( size_t  refIndex,
std::vector< Assignment > &  images 
)
protected

Definition at line 511 of file aalign_significant.cpp.

511  {
512  static std::mutex mutex;
513  std::lock_guard<std::mutex> lk(mutex); // released at the end of scope
514 
515  const size_t indexInStk = refIndex + 1; // within metadata file, index images from one (1)
516  FileName refName;
517  auto &refMeta = m_updateHelper.refBlock;
518  // name of the reference
519  refName.compose(indexInStk, m_updateHelper.fnStk);
520  // some info about it
521  auto refRow = MDRowVec();
522  assert(std::numeric_limits<int>::max() >= refIndex);
523  refRow.setValue(MDL_REF, getRefMetaIndex(refIndex), true);
524  refRow.setValue(MDL_IMAGE, refName, true);
525  refRow.setValue(MDL_CLASS_COUNT, images.size(), true);
526  refMeta.addRows({refRow});
527 
528  // create image description block
529  std::sort(images.begin(), images.end(), [](const Assignment &l, const Assignment &r) {
530  return l.imgIndex < r.imgIndex; // sort by image index
531  });
532 
533  const size_t noOfImages = images.size();
534  if (0 != noOfImages) {
535  std::vector<MDRowVec> rows(noOfImages);
536  for (size_t i = 0; i < noOfImages; ++i) {
537  auto &row = rows.at(i);
538  const auto &a = images.at(i);
539  getImgRow(row, a.imgIndex);
540  fillRow(row, a.pose, refIndex, a.weight, a.imgIndex);
541  }
542  const auto& labels = rows.at(0).labels();
543  if (0 == m_updateHelper.imgBlocks.size()) {
544  m_updateHelper.imgBlocks.resize(m_referenceImages.dims.n(), labels);
545  }
546  auto &md = m_updateHelper.imgBlocks.at(refIndex);
547  md.addRows(rows);
548  }
549 }
Mutex mutex
void compose(const String &str, const size_t no, const String &ext="")
#define i
void max(Image< double > &op1, const Image< double > &op2)
void sort(struct DCEL_T *dcel)
Definition: sorting.cpp:18
Class to which the image belongs (int)
Number of images assigned to the same class as this image.
Name of an image (std::string)
doublereal * a

The documentation for this class was generated from the following files: