Xmipp  v3.23.11-Nereus
metadata_generator.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: J.M. de la Rosa Trevin (jmdelarosa@cnb.csic.es)
4  * Jan Horacek (xhorace4@fi.muni.cz)
5  *
6  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21  * 02111-1307 USA
22  *
23  * All comments concerning this program package may be sent to the
24  * e-mail address 'xmipp@cnb.csic.es'
25  ***************************************************************************/
26 
27 #include "metadata_generator.h"
28 #include "xmipp_funcs.h"
29 
31  switch (mode)
32  {
33  case GTOR_UNIFORM:
34  return rnd_unif(op1, op2);
35  case GTOR_GAUSSIAN:
36  return rnd_gaus(op1, op2);
37  case GTOR_STUDENT:
38  return rnd_student_t(op3, op1, op2);
39  default:
40  REPORT_ERROR(ERR_ARG_INCORRECT,"Unknown random type");
41  }
42 }
43 
44 MDRandGenerator::MDRandGenerator(double op1, double op2, const String &mode, double op3) {
45  static bool randomized = false;
46 
47  if (!randomized)//initialize random seed just once
48  {
50  randomized = true;
51  }
52  this->op1 = op1;
53  this->op2 = op2;
54  this->op3 = op3;
55  if (mode == "uniform")
56  this->mode = GTOR_UNIFORM;
57  else if (mode == "gaussian")
58  this->mode = GTOR_GAUSSIAN;
59  else if (mode == "student")
60  this->mode = GTOR_STUDENT;
61  else
62  REPORT_ERROR(ERR_PARAM_INCORRECT, formatString("Unknown random type '%s'", mode.c_str()));
63 
64 }
65 
66 void MDRandGenerator::fillValue(MetaData &md, size_t objId) {
67  double aux = getRandValue();
68  md.setValue(label, aux, objId);
69 }
70 
72  this->value = value;
73 }
74 
75 void MDConstGenerator::fillValue(MetaData &md, size_t objId) {
76  md.setValueFromStr(label, value, objId);
77 }
78 
79 MDLinealGenerator::MDLinealGenerator(double initial, double step) {
80  this->initValue = initial;
81  this->step = step;
82  counter = 0;
83 }
84 
85 void MDLinealGenerator::fillValue(MetaData &md, size_t objId) {
86  double value = initValue + step * counter++;
87  if (MDL::isInt(label))
88  md.setValue(label, (int)value, objId);
89  else if ( MDL::isLong(label))
90  md.setValue(label, (size_t)value, objId);
91  else
92  md.setValue(label, value, objId);
93 }
94 
95 /* Class to generate values for columns of a metadata*/
97  for (size_t id: md.ids())
98  fillValue(md, id);
99 }
100 
101 #ifdef NEVERDEFINED
102 /* Class to fill columns with another metadata in row format */
103 void MDExpandGenerator::fillValue(MetaData &md, size_t objId) {
104  if (md.getValue(label, fn, objId))
105  {
106  expMd.read(fn);
107  if (expMd.isColumnFormat() || expMd.isEmpty())
108  REPORT_ERROR(ERR_VALUE_INCORRECT, "Only can expand non empty and row formatted metadatas");
109  expMd.getRow(row, expMd.firstObject());
110  md.setRow(row, objId);
111  }
112  else
113  REPORT_ERROR(ERR_MD_BADLABEL, formatString("Can't expand missing label '%s'", MDL::label2Str(label).c_str()));
114 }
115 #endif
Parameter incorrect.
Definition: xmipp_error.h:181
double rnd_student_t(double nu)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
static bool isInt(const MDLabel label)
Unexpected label.
Definition: xmipp_error.h:157
MDConstGenerator(const String &value)
virtual IdIteratorProxy< false > ids()
void fillValue(MetaData &md, size_t objId)
virtual bool getValue(MDObject &mdValueOut, size_t id) const =0
double rnd_unif()
void fillValue(MetaData &md, size_t objId)
Incorrect argument received.
Definition: xmipp_error.h:113
MDLinealGenerator(double initial, double step)
static bool isLong(const MDLabel label)
MDRandGenerator(double op1, double op2, const String &mode, double op3=0.)
bool setValue(const MDLabel label, const T &valueIn, size_t id)
std::string String
Definition: xmipp_strings.h:34
double rnd_gaus()
String formatString(const char *format,...)
static String label2Str(const MDLabel &label)
virtual bool setValueFromStr(const MDLabel label, const String &value, size_t id)
unsigned int randomize_random_generator()
void fillValue(MetaData &md, size_t objId)
Incorrect value received.
Definition: xmipp_error.h:195
void fill(MetaData &md)