36 if (i+1 > data.size())
38 std::cout <<
"Docline=" << *
this << std::endl;
48 if (i+1 > data.size())
50 std::cout <<
"Docline=" << *
this << std::endl;
61 if (i + 1 > data.size())
65 int space_needed = i + 1 - data.size();
66 for (
int k = 0;
k < space_needed;
k++)
98 switch (line.line_type)
102 sprintf(aux,
"%5d ", line.key);
104 sprintf(aux,
"%-2lu", (
unsigned long int)(line.data.size()));
108 imax = line.data.size();
109 for (
int i = 0;
i < imax;
i++)
111 sprintf(aux,
" % 10.5f", line.data[
i]);
120 o << line.text << std::endl;
144 int charpos1 = line.find_first_not_of(
" \t");
145 if (line[0] ==
'\0' || line[charpos1] ==
'#' || line[charpos1] ==
';')
161 std::string auxline = line;
172 data.reserve(param_no);
173 for (
int i = 0; i < param_no; i++)
175 data.push_back(
textToFloat(line.substr(8 + i*12, 12)));
187 current_line =
m.begin();
220 std::vector< DocLine >::const_iterator current = doc.m.begin();
221 std::vector< DocLine >::const_iterator last = doc.m.end();
223 while (current != last)
236 if (current_line ==
m.end())
237 o <<
"Current line is at the end of file\n";
243 std::vector< DocLine >::iterator line =
find(key);
245 o <<
"Key " << key <<
" not found\n";
253 std::vector< DocLine >::iterator current =
m.begin();
254 std::vector< DocLine >::iterator last =
m.end();
256 while (current != last)
260 std::cout << *current;
264 std::string str =
"";
266 std::cout <<
"Special line\n";
267 std::cout <<
" Type: " << (*current).line_type << std::endl;
268 std::cout <<
" Key: " << (*current).key << std::endl;
269 std::cout <<
" Text: " << (*current).text << std::endl;
270 std::cout <<
" Data: ";
271 for (
size_t i = 0;
i < (*current).data.size();
i++)
273 sprintf(aux,
" % 11.5f", (*current).data[
i]);
276 std::cout << str << std::endl;
283 std::vector< DocLine >::iterator DocFile::find(
int k)
285 std::vector< DocLine >::iterator current =
m.begin();
286 std::vector< DocLine >::iterator last =
m.end();
288 while (current != last)
301 if (current_line ==
m.end())
308 if (current_line ==
m.end())
315 std::vector< DocLine >::iterator current =
m.begin();
316 std::vector< DocLine >::iterator last =
m.end();
317 int act_key = first_key;
319 while (current != last)
322 (*current).key = act_key++;
353 std::cout <<
"Doc File: Line " << line_no <<
354 " is skipped due to an error\n";
357 switch (temp.line_type)
385 go_first_data_line();
392 std::vector< DocLine >::iterator current =
m.begin();
393 std::vector< DocLine >::iterator last =
m.end();
401 out.open(fn_doc.c_str(), std::ios::out);
404 " cannot be written");
407 while (current != last)
416 adjust_to_data_line();
418 for (
int i = 0;
i < count;
i++)
419 if (current_line !=
m.end())
422 adjust_to_data_line();
429 comment =
" ; " + comment;
433 if ((*current_line).Is_comment())
435 if (strcmp(comment.c_str(), ((*current_line).get_text()).c_str())
438 adjust_to_data_line();
451 bool found_once =
false;
455 if ((*current_line).Is_comment())
457 if (((*current_line).get_text()).
find(pattern) <
458 ((*current_line).get_text()).size() )
479 if ((*current_line).Is_comment())
480 if (strstr(((*current_line).get_text()).c_str(),
"Headerinfo") ==
nullptr)
482 "DocFile::get_selfile: Docfile is of non-NewXmipp type!");
489 if (strstr(((*current_line).get_text()).c_str(),
" ; ") !=
nullptr)
491 img = (*current_line).get_text();
501 std::vector< DocLine >::iterator last =
m.end();
503 current_line =
m.begin();
504 while (current_line != last)
507 (*current_line).key >= k)
518 if ((*current_line).Is_comment())
520 header = (*current_line).get_text();
521 if (strstr(header.c_str(),
"Headerinfo") ==
nullptr)
525 std::vector<std::string> tokens;
527 for (
size_t i = 0;
i < tokens.size();
i++)
529 if (strstr(tokens[
i].c_str(), pattern) !=
nullptr)
543 std::vector< DocLine >::iterator aux = current_line;
544 go_first_data_line();
546 int ret = current_line->data.size();
554 std::vector< DocLine >::iterator last =
m.end();
555 std::vector< DocLine >::iterator
first =
m.begin();
560 return first_key - 1;
572 std::vector< DocLine >::iterator aux =
find(k);
576 +
") is not in the file");
582 const std::string& ang1,
const std::string& ang2,
const std::string& ang3)
584 std::vector< DocLine >::iterator it =
find(k);
589 +
") is not in the file");
638 const std::string& ang1,
const std::string& ang2,
const std::string& ang3)
640 std::vector< DocLine >::iterator it =
find(k);
693 const std::string& ang1,
const std::string& ang2,
const std::string& ang3)
695 std::vector< DocLine >::iterator it =
find(k);
698 +
") is not in the file");
747 const std::string& ang1,
const std::string& ang2,
const std::string& ang3)
749 std::vector< DocLine >::iterator it =
find(k);
802 current_line =
m.begin();
803 current_line += 2*key;
804 DocLine DL = get_current_line();
808 fn_img = ((get_current_line()).
get_text()).erase(0, 3);
814 I().setXmippOrigin();
835 current_line =
m.begin();
836 current_line += 2*key;
837 DocLine DL = get_current_line();
841 fn_img = ((get_current_line()).
get_text()).erase(0, 3);
849 if (current_line !=
m.end())
850 (*current_line).set(i, val);
858 current_line =
m.end();
864 std::vector< DocLine >::iterator it =
find(k);
867 +
") is not in the file");
874 std::vector< DocLine >::iterator last =
m.end();
879 int old = (*current_line).key;
881 current_line =
m.begin();
882 while (current_line != last)
887 if (current_line->key >= key0 && current_line->key <= keyF)
898 if (current_line !=
m.end())
900 std::vector< DocLine >::iterator it = current_line;
906 m.erase(current_line);
916 std::vector< DocLine >::iterator it;
917 for (
int i = 0;
i < count;
i++)
919 current_line =
m.insert(current_line, tmp);
938 current_line =
m.insert(current_line, tmp);
941 int ret = current_line->key;
952 tmp.text =
" ; " + comment;
955 current_line =
m.insert(current_line, tmp);
962 current_line =
m.insert(current_line, line);
967 ret = current_line->key;
980 int ret = get_last_key() + 1;
983 for (
int i = 0;
i < count;
i++, act_key++)
998 tmp.key = get_last_key() + 1;
1010 tmp.text =
" ; " + comment;
1015 const std::string& ang1,
const std::string& ang2,
const std::string& ang3)
1021 else if (ang1[0] ==
't')
1023 else if (ang1[0] ==
'p')
1028 else if (ang2[0] ==
't')
1030 else if (ang2[0] ==
'p')
1035 else if (ang3[0] ==
't')
1037 else if (ang3[0] ==
'p')
1040 return append_data_line(aux);
1044 double rot1,
double tilt1,
double psi1,
1045 const std::string& ang1,
const std::string& ang2,
const std::string& ang3)
1051 else if (ang1[0] ==
't')
1053 else if (ang1[0] ==
'p')
1058 else if (ang2[0] ==
't')
1060 else if (ang2[0] ==
'p')
1065 else if (ang3[0] ==
't')
1067 else if (ang3[0] ==
'p')
1072 else if (ang1[0] ==
't')
1074 else if (ang1[0] ==
'p')
1079 else if (ang2[0] ==
't')
1081 else if (ang2[0] ==
'p')
1086 else if (ang3[0] ==
't')
1088 else if (ang3[0] ==
'p')
1091 return append_data_line(aux);
1095 double rot1,
double tilt1,
double psi1,
1096 double rot2,
double tilt2,
double psi2,
1097 const std::string& ang1,
const std::string& ang2,
const std::string& ang3)
1103 else if (ang1[0] ==
't')
1105 else if (ang1[0] ==
'p')
1110 else if (ang2[0] ==
't')
1112 else if (ang2[0] ==
'p')
1117 else if (ang3[0] ==
't')
1119 else if (ang3[0] ==
'p')
1124 else if (ang1[0] ==
't')
1126 else if (ang1[0] ==
'p')
1131 else if (ang2[0] ==
't')
1133 else if (ang2[0] ==
'p')
1138 else if (ang3[0] ==
't')
1140 else if (ang3[0] ==
'p')
1145 else if (ang1[0] ==
't')
1147 else if (ang1[0] ==
'p')
1152 else if (ang2[0] ==
't')
1154 else if (ang2[0] ==
'p')
1159 else if (ang3[0] ==
't')
1161 else if (ang3[0] ==
'p')
1164 return append_data_line(aux);
1173 ret = line.key = get_last_key() + 1;
1183 std::vector< DocLine >::iterator last =
m.end();
1184 current_line =
m.begin();
1186 while (current_line != last)
1194 current_line =
m.begin();
1209 for (i = no_lines; i > 0; i--)
1216 result.m.push_back(*aux.current_line);
1221 result.no_lines = no_lines;
1222 result.current_line = result.m.begin();
1233 std::vector< DocLine >::iterator current =
m.begin();
1234 std::vector< DocLine >::iterator last =
m.end();
1236 while (current != last)
1249 merge(DFaux, mode, sumcol);
1262 for (
size_t objId : SF.
ids())
1267 if (search_comment(fn_img))
1279 (*current_line) = DL;
1285 w = (*current_line).data[sumcol] + DF(sumcol);
1286 (*current_line).set(sumcol, w);
1290 std::cerr<<
"image name = "<<fn_img;
1297 current_line =
m.end();
1298 append_comment(fn_img);
1313 for (i = 0; i <
n; i++)
1316 rnd_indx = (int)
rnd_unif(0, result.no_lines);
1318 result.
jump(rnd_indx);
1330 std::vector< DocLine >::iterator current =
m.begin();
1331 std::vector< DocLine >::iterator last =
m.end();
1334 while (current != last)
1348 std::vector< DocLine >::iterator it =
find(k);
1352 result.
resize(it->data.size());
1363 go_first_data_line();
1377 std::string ang3,
DocFile& doc)
1388 #define assign_in_correct_place_of_line2(angle_descr,angle_index) \ 1389 switch (angle_descr[0]) \ 1391 case ('r'): line2.set(0, line1[angle_index]); break; \ 1392 case ('t'): line2.set(1, line1[angle_index]); break; \ 1393 case ('p'): line2.set(2, line1[angle_index]); break; \ 1424 double limit0,
bool en_limitF,
double limitF)
1428 for (
size_t objId : sel.
ids())
1433 if ((en_limit0 && doc(col) < limit0) || (en_limitF && doc(col) > limitF))
1451 if (strstr(fn_tmp.c_str(),
"Headerinfo") ==
nullptr)
1457 for (
size_t objId : SF.
ids())
void setRot(double rot, const size_t n=0)
void min(Image< double > &op1, const Image< double > &op2)
void perturb_column(int col, double sigma)
void get_image(int key, Image< double > &I, bool apply_geo=false)
DocLine get_current_line()
#define REPORT_ERROR(nerr, ErrormMsg)
int read_Euler_document_file(FileName name, std::string ang1, std::string ang2, std::string ang3, DocFile &doc)
Matrix1D< double > row(int _key)
void read(const FileName &_name, int overrinding=1)
std::vector< SelLine >::iterator find(std::vector< SelLine > &text, const std::string &img_name)
Couldn't write to file.
int append_angles(double rot, double tilt, double psi, const std::string &ang1, const std::string &ang2, const std::string &ang3)
void readFloatList(const char *str, int N, std::vector< T > &v)
int insert_data_line(int no_lines_to_insert=1)
DocFile random_discard(int N)
void show_line(std::ostream &o, int key=-1)
void get_selfile(MetaData &SF)
String integerToString(int I, int _width, char fill_with)
#define DOCMERGE_SUM_COLUMN
void setPsi(double psi, const size_t n=0)
void get_angles(int _key, double &rot, double &tilt, double &psi, const std::string &ang1, const std::string &ang2, const std::string &ang3)
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
void setCol(int _col, Matrix1D< double > &v)
double operator()(int i) const
#define MAT_ELEM(m, i, j)
int insert_line(const DocLine &DL)
void write(const FileName &_name="")
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
void get_angles2(int _key, double &rot, double &tilt, double &psi, const std::string &ang1, const std::string &ang2, const std::string &ang3)
void set_angles(int _key, double rot, double tilt, double psi, const std::string &ang1, const std::string &ang2, const std::string &ang3)
void setYoff(double yoff, const size_t n=0)
DocFile & operator=(const Matrix2D< double > &A)
void set(int i, double val)
Matrix1D< double > col(int _col)
float textToFloat(const char *str)
void setFlip(bool flip, const size_t n=0)
int append_data_line(int no_lines_to_append=1)
FileName get_imagename(int key)
void resize(size_t Xdim, bool copy=true)
void read(std::istream &i)
void tokenize(const String &str, StringVector &tokens, const String &delimiters)
void go_first_data_line()
#define DOCMERGE_KEEP_OLD
void set_type(Line_Type _line_type)
#define DOCMERGE_KEEP_NEW
int FirstLine_colNumber()
int getColNumberFromHeader(const char *pattern)
basic_istream< char, std::char_traits< char > > istream
void get_subset_docfile(DocFile &DFin, MetaData &SF, DocFile &DFout)
double & operator[](size_t i)
friend std::ostream & operator<<(std::ostream &o, const DocLine &DL)
int append_line(DocLine &DL)
int search_comment(std::string comment)
void insert_comment(std::string comment)
void setXoff(double xoff, const size_t n=0)
void setTilt(double tilt, const size_t n=0)
void merge(const FileName &name, int mode=DOCMERGE_KEEP_OLD, int sumcol=5)
int remove_multiple_strings(std::string pattern)
double psi(const double x)
void append_comment(const std::string &comment)
void adjust_to_data_line()
int textToInteger(const char *str)
void set(size_t i, double val)
void select_images(DocFile &doc, MetaData &sel, int col, bool en_limit0, double limit0, bool en_limitF, double limitF)
void getTransformationMatrix(Matrix2D< double > &A, bool only_apply_shifts=false, const size_t n=0)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
FileName removeSubstring(const String &sub) const
unsigned int randomize_random_generator()
void remove(int _key0, int _keyF=-1)
String nextToken(const String &str, size_t &i)
Incorrect value received.
void get_angles1(int _key, double &rot, double &tilt, double &psi, const std::string &ang1, const std::string &ang2, const std::string &ang3)
#define assign_in_correct_place_of_line2(angle_descr, angle_index)