51 if (l1.line_type < l2.line_type)
53 else if (l1.line_type > l2.line_type)
56 return l1.text < l2.text;
61 switch (SFL.line_type)
64 o << SFL.text <<
" " << SFL.label << std::endl;
67 o << SFL.text << std::endl;
89 if (line.length() == 0)
93 if (line[0] ==
'#' || line[0] ==
'\0' || line[0] ==
';')
95 line[line.length()-1] =
'\0';
103 no_elements_read = sscanf(line.c_str(),
"%s %d", img_name, &label);
105 if (no_elements_read == 2)
126 current_line = text_line.begin();
133 text_line.erase(text_line.begin(), text_line.end());
135 current_line = text_line.begin();
147 std::vector<SelLine>::const_iterator current = SF.text_line.begin();
148 std::vector<SelLine>::const_iterator last = SF.text_line.end();
149 while (current != last)
160 std::vector<SelLine>::iterator current = text_line.begin();
161 while (current != text_line.end())
166 text_line.erase(current);
171 current_line = text_line.begin();
177 std::vector<SelLine>::iterator current = text_line.begin();
178 std::vector<SelLine>::iterator last = text_line.end();
179 std::vector<SelLine>::iterator temp;
180 while (current != last)
186 text_line.erase(current);
192 current_line = text_line.begin();
199 std::ifstream fh_sel;
216 while (!fh_sel.eof())
224 std::cout <<
"Sel file: Line " << line_no <<
" is skipped due to an error\n";
226 switch (temp.line_type)
232 text_line.push_back(temp);
235 text_line.push_back(temp);
264 std::ofstream fh_sel;
265 std::vector<SelLine>::iterator current = text_line.begin();
266 std::vector<SelLine>::iterator last = text_line.end();
268 if (strcmp(sel_name.c_str(),
"") != 0)
272 if (sel_name.find(IMAGIC_TAG) == 0)
275 const FileName hed_fname = sel_name.substr(IMAGIC_TAG_LEN);
276 std::vector<Image *> imgs;
277 for (; current != last; current++)
281 (img = Image::LoadImage(current->get_text())))
284 if (!ImagicWriteImagicFile(hed_fname, imgs))
285 REPORT_ERROR(1553,
"Error writing selfile to Imagic file " + sel_name);
286 for (std::vector<Image *>::iterator
i = imgs.begin();
i != imgs.end();
i++)
294 fh_sel.open(fn_sel.c_str(), std::ios::out);
299 while (current != last)
300 fh_sel << *(current++);
310 std::vector<SelLine>::iterator current = SF.text_line.begin();
311 std::vector<SelLine>::iterator last = SF.text_line.end();
312 std::vector<SelLine>::iterator found;
316 discrepancy.text =
"# There were discrepancy in the tags for next line, the " 317 "ACTIVE state is kept";
319 while (current != last)
326 if ((found =
find((*current).text)) == text_line.end())
332 text_line.push_back(*current);
340 if ((*found).label != (*current).label)
342 if ((*found).label < (*current).label)
347 text_line.insert(found, 1, discrepancy);
370 int N = SFtmp.
ImgNo();
375 for (
int i = 0;
i < N;
i++)
398 int Nimg = SFtmp.
ImgNo();
402 for (
int n = 0;
n < N;
n++)
405 ptr_SF->reserve(
CEIL(Nimg / N));
406 SF.push_back(*ptr_SF);
411 for (
int i = 0;
i < Nimg;
i++)
420 for (
int n = 0; n < N; n++)
421 SF[n] = SF[n].sort_by_filenames();
428 (*this).clean_comments();
430 num_img_tot = (*this).ImgNo();
431 int remaining = num_img_tot % size;
432 int Npart = (int)(num_img_tot - remaining) / size;
434 if (rank < remaining)
436 myFirst = rank * (Npart + 1);
437 myLast = myFirst + Npart;
441 myFirst = rank * Npart + remaining;
442 myLast = myFirst + Npart - 1;
445 (*this).go_beginning();
448 for (
int nr = myFirst; nr <= myLast; nr++)
450 (*this).go_beginning();
451 (*this).jump_lines(nr);
452 SFpart.
insert((*this).current());
466 (*this).clean_comments();
468 totalNumImg = (*this).ImgNo();
469 int myFirst = jobNumber * mpi_job_size;
470 int myLast = myFirst + mpi_job_size-1;
471 while ((myLast+1) > totalNumImg)
473 myLast = totalNumImg-1;
476 (*this).go_beginning();
479 for (
int nr = myFirst; nr <= myLast; nr++)
481 (*this).go_beginning();
482 (*this).jump_lines(nr);
483 SFpart.
insert((*this).current());
494 for (
int i=firstImage;
i<=lastImage;
i++)
496 if (!eof()) SFsubset.
insert(current());
504 if (current_line == text_line.end())
507 (*current_line).label != label)
510 if (current_line == text_line.end())
518 adjust_to_label(label);
519 static const std::string emptyString;
520 if (current_line != text_line.end())
521 return (*current_line++).text;
529 for (
int i = 0;
i < how_many;
i++)
531 if (current_line != text_line.end())
542 adjust_to_label(label);
543 for (
int i = 0;
i < how_many;
i++)
544 if (current_line != text_line.end())
547 adjust_to_label(label);
553 std::vector<SelLine>::iterator
find(std::vector<SelLine> &text,
554 const std::string &img_name)
556 std::vector<SelLine>::iterator current = text.begin();
557 std::vector<SelLine>::iterator last = text.end();
559 while (current != last)
562 (*current).text == img_name)
572 std::vector<SelLine>::iterator SelFile::find(
const std::string &img_name)
574 std::vector<SelLine>::iterator current = text_line.begin();
575 std::vector<SelLine>::iterator last = text_line.end();
577 while (current != last)
580 (*current).text == img_name)
592 std::vector<SelLine>::const_iterator current = text_line.begin();
593 std::vector<SelLine>::const_iterator last = text_line.end();
594 while (current != last)
597 (*current).label == label)
608 std::vector<SelLine>::iterator current = text_line.begin();
609 std::vector<SelLine>::iterator last = text_line.end();
610 while (current != last)
622 std::vector<SelLine>::iterator aux = current_line;
624 FileName ext = (*current_line).text;
634 std::vector<SelLine>::iterator aux = current_line;
635 size_t max_length = 0;
640 max_length =
XMIPP_MAX(max_length, fn.length());
649 if (current_line == text_line.end())
653 return (*current_line).text;
661 std::vector<SelLine>::iterator current = text_line.begin();
662 std::vector<SelLine>::iterator last = text_line.end();
665 while (current != last)
671 return (*current).text;
680 std::vector<SelLine>::iterator aux =
find(img_name);
681 std::vector<SelLine>::iterator temp;
682 if (aux != text_line.end())
684 if (aux == current_line)
693 text_line.erase(aux);
701 if (current_line != text_line.end())
703 std::vector<SelLine>::iterator temp;
708 text_line.erase(current_line);
717 std::vector<SelLine>::iterator aux =
find(img_name);
718 if (aux == text_line.end())
721 temp.text = img_name;
723 text_line.push_back(temp);
729 if ((*aux).label != label)
731 (*aux).label = label;
741 if ((*current_line).label != label)
743 (*current_line).label = label;
754 (*current_line).text = fn_new;
763 temp.text = img_name;
769 current_line = text_line.insert(current_line, temp);
789 current_line = text_line.insert(current_line, _selline);
798 temp.text =
"# " + comment;
802 current_line = text_line.insert(current_line, temp);
810 sort(result.text_line.begin(), result.text_line.end());
811 result.current_line = result.text_line.begin();
826 for (i = no_imgs; i > 0; i--)
832 result.text_line.push_back(*(aux.current_line));
837 result.no_imgs = no_imgs;
838 result.current_line = result.text_line.begin();
852 for (i = 0; i < N; i++)
855 rnd_indx = (int)
rnd_unif(0, result.no_imgs);
857 result.
jump(rnd_indx, label);
874 std::vector<SelLine> only_in_SF1;
875 std::vector<SelLine> only_in_SF2;
876 std::vector<SelLine> in_both;
879 int SF1_discarded = 0, SF2_discarded = 0;
881 char str[maxLen + 1];
884 std::vector<SelLine>::iterator current = SF1.text_line.begin();
885 std::vector<SelLine>::iterator last = SF1.text_line.end();
886 std::vector<SelLine>::iterator last_SF = SF2.text_line.end();
887 std::vector<SelLine>::iterator found;
889 while (current != last)
905 found = SF2.find((*current).text);
906 if (found == last_SF)
907 only_in_SF1.push_back(*current);
910 only_in_SF1.push_back(*current);
912 in_both.push_back(*current);
917 current = SF2.text_line.begin();
918 last = SF2.text_line.end();
920 while (current != last)
936 found =
find(in_both, (*current).text);
937 if (found != in_both.end())
942 only_in_SF2.push_back(*current);
951 temp.text =
"# Statistics of comparison";
952 result.text_line.push_back(temp);
953 temp.text =
"# -------------------------------------------------------------";
954 result.text_line.push_back(temp);
955 snprintf(str, maxLen,
"%6d", SF1.no_imgs);
956 temp.text =
"# File 1: " + SF1.fn_sel +
"(VALID: " + str;
957 snprintf(str, maxLen,
"%6d", SF1_discarded);
958 temp.text += (std::string)
" DISCARDED: " + str +
")";
959 result.text_line.push_back(temp);
960 snprintf(str, maxLen,
"%6d", SF2.no_imgs);
961 temp.text =
"# File 2: " + SF2.fn_sel +
"(VALID: " + str;
962 snprintf(str, maxLen,
"%6d", SF2_discarded);
963 temp.text += (std::string)
" DISCARDED: " + str +
")";
964 result.text_line.push_back(temp);
966 result.text_line.push_back(temp);
967 snprintf(str, maxLen,
"%6lu", (
unsigned long int)in_both.size());
968 temp.text = (std::string)
"# Matching Files: " + str;
969 result.text_line.push_back(temp);
970 snprintf(str, maxLen,
"%6lu", (
unsigned long int)only_in_SF1.size());
971 temp.text = (std::string)
"# Only in file 1: " + str;
972 result.text_line.push_back(temp);
973 snprintf(str, maxLen,
"%6lu", (
unsigned long int)only_in_SF2.size());
974 temp.text = (std::string)
"# Only in file 2: " + str;
975 result.text_line.push_back(temp);
976 temp.text =
"# -------------------------------------------------------------";
977 result.text_line.push_back(temp);
981 result.text_line.push_back(temp);
982 temp.text =
"# Files in both .sel files";
983 result.text_line.push_back(temp);
985 if (mode<0 || mode==0)
987 current = in_both.begin();
988 last = in_both.end();
989 while (current != last)
990 result.text_line.push_back(*current++);
997 result.text_line.push_back(temp);
998 temp.text =
"# Files only in the first file";
999 result.text_line.push_back(temp);
1001 if (mode<0 || mode==1)
1003 current = only_in_SF1.begin();
1004 last = only_in_SF1.end();
1005 while (current != last)
1006 result.text_line.push_back(*current++);
1013 result.text_line.push_back(temp);
1014 temp.text =
"# Files only in the second file";
1015 result.text_line.push_back(temp);
1017 if (mode<0 || mode==2)
1019 current = only_in_SF2.begin();
1020 last = only_in_SF2.end();
1021 while (current != last)
1022 result.text_line.push_back(*current++);
1026 result.no_imgs = in_both.size() + only_in_SF1.size() + only_in_SF2.size();
1028 result.no_imgs = in_both.size();
1030 result.no_imgs = only_in_SF1.size();
1032 result.no_imgs = only_in_SF2.size();
1033 result.current_line = result.text_line.begin();
friend std::ostream & operator<<(std::ostream &o, const SelLine &line)
void min(Image< double > &op1, const Image< double > &op2)
void split_in_two(SelFile &sel1, SelFile &sel2)
SelFile random_discard(int N)
#define REPORT_ERROR(nerr, ErrormMsg)
int ImgNo(SelLine::Label label=SelLine::ACTIVE) const
void set_current(SelLine::Label label)
const SelLine & current()
Couldn't write to file.
void insert(const std::string &img_name, SelLine::Label label=SelLine::ACTIVE)
void chooseSubset(int firstImage, int lastImage, SelFile &SFsubset)
void merge(const FileName &name)
void set(const std::string &img_name, SelLine::Label label)
void write(const FileName &sel_name="")
void set_current_filename(const FileName &fn_new)
void mpi_select_part2(int rank, int size, int &num_img_tot, int mpi_job_size)
void remove(const std::string &img_name)
bool jump_lines(int count)
void assign(const SelFile &sel)
friend SelFile compare(SelFile &SF1, SelFile &SF2, const int mode)
const std::string & NextImg(SelLine::Label label=SelLine::ACTIVE)
String getExtension() const
SelFile operator+(SelFile &sel)
void read(const FileName &name, int overrinding=1)
SelFile sort_by_filenames()
const std::string get_current_file()
File or directory does not exist.
void mpi_select_part(int rank, int size, int &num_img_tot)
basic_istream< char, std::char_traits< char > > istream
void sort(struct DCEL_T *dcel)
friend std::vector< SelLine >::iterator find(std::vector< SelLine > &text, const std::string &img_name)
void split_in_N(int N, std::vector< SelFile > &parts)
void insert_comment(const std::string &comment)
void assign(const SelLine &line)
const std::string get_file_number(int i)
void jump(int count, SelLine::Label label=SelLine::ACTIVE)
unsigned int randomize_random_generator()
friend std::istream & operator>>(std::istream &i, SelLine &lin)
friend bool operator<(const SelLine &l1, const SelLine &l2)