Xmipp
v3.23.11-Nereus
|
#include <selfile.h>
Public Member Functions | |
Selfile constructors | |
SelFile () | |
SelFile (const FileName &name) | |
void | reserve (int n) |
void | clear () |
Managing files in disk | |
void | read (const FileName &name, int overrinding=1) |
void | append (const FileName &name) |
void | merge (const FileName &name) |
void | merge (SelFile &sel) |
SelFile | operator+ (SelFile &sel) |
void | split_in_two (SelFile &sel1, SelFile &sel2) |
void | split_in_N (int N, std::vector< SelFile > &parts) |
void | mpi_select_part (int rank, int size, int &num_img_tot) |
void | mpi_select_part2 (int rank, int size, int &num_img_tot, int mpi_job_size) |
void | chooseSubset (int firstImage, int lastImage, SelFile &SFsubset) |
void | write (const FileName &sel_name="") |
Moving the current line pointer | |
void | go_beginning () |
void | go_first_ACTIVE () |
const std::string & | operator() (int i) |
const std::string & | NextImg (SelLine::Label label=SelLine::ACTIVE) |
void | next () |
void | jump (int count, SelLine::Label label=SelLine::ACTIVE) |
bool | jump_lines (int count) |
void | search (const std::string &img_name) |
int | eof () |
Getting information | |
FileName | name () const |
int | Is_ACTIVE () const |
int | Is_DISCARDED () const |
int | Is_COMMENT () const |
const SelLine & | current () |
void | get_current (SelLine &_SL) |
int | exists (const std::string &img_name) |
int | ImgNo (SelLine::Label label=SelLine::ACTIVE) const |
int | LineNo () |
void | ImgSize (int &Ydim, int &Xdim) |
FileName | FileExtension () |
int | MaxFileNameLength () |
const std::string | get_current_file () |
SelLine | get_current_line () |
const std::string | get_file_number (int i) |
Modifying the selection file | |
void | remove (const std::string &img_name) |
void | remove_current () |
void | set (const std::string &img_name, SelLine::Label label) |
void | set_current (SelLine::Label label) |
void | set_current_filename (const FileName &fn_new) |
void | insert (const std::string &img_name, SelLine::Label label=SelLine::ACTIVE) |
void | insert (const SelLine &_selline) |
void | insert_comment (const std::string &comment) |
void | clean () |
void | clean_comments () |
Some operators | |
void | assign (const SelFile &sel) |
std::ostream & | operator<< (std::ostream &o, const SelFile &sel) |
Helpful procedures | |
SelFile | sort_by_filenames () |
SelFile | randomize () |
SelFile | randomSubset (int subsetN, bool withReplacement=true) |
SelFile | random_discard (int N) |
SelFile | compare (SelFile &SF1, SelFile &SF2, const int mode) |
Selection File
The SelFile is an object which keeps in memory all the information associated to a .sel file.
SelFile::SelFile | ( | ) |
Empty constructor.
There is no file associated yet.
Definition at line 122 of file selfile.cpp.
|
inline |
|
inline |
void SelFile::assign | ( | const SelFile & | sel | ) |
Another function for assigment.
Definition at line 139 of file selfile.cpp.
void SelFile::chooseSubset | ( | int | firstImage, |
int | lastImage, | ||
SelFile & | SFsubset | ||
) |
Choose a subset of images.
Definition at line 489 of file selfile.cpp.
void SelFile::clean | ( | ) |
Deletes all DISCARDED images from the selection file.
The current line "pointer" is moved to the beginning of the file.
Definition at line 158 of file selfile.cpp.
void SelFile::clean_comments | ( | ) |
Deletes all comments from the selection file.
The current line "pointer" is moved to the beginning of the file.
Definition at line 175 of file selfile.cpp.
void SelFile::clear | ( | ) |
|
inline |
|
inline |
|
inline |
True if the image name is inside the selection file.
The current line "pointer" is not modified. If an image is discarded in the selection file, this function still will say that it exists, although it is discarded.
FileName SelFile::FileExtension | ( | ) |
Returns the extension of the files inside.
This function returns the extension of the first active file.
Definition at line 620 of file selfile.cpp.
const std::string SelFile::get_current_file | ( | ) |
Get the filename of the current line.
If the current line "pointer" is at the end of the file or is pointing to a comment then an empty string is returned.
Definition at line 647 of file selfile.cpp.
|
inline |
const std::string SelFile::get_file_number | ( | int | i | ) |
Get the filename at the ACTIVE line number i.
The first file is number 0. If i is greater than the total number of ACTIVE files, then "" is returned.
Definition at line 657 of file selfile.cpp.
|
inline |
|
inline |
Go to the first ACTIVE image.
Moves the pointer to the first active image in the file.
Definition at line 377 of file selfile.h.
int SelFile::ImgNo | ( | SelLine::Label | label = SelLine::ACTIVE | ) | const |
Number of images inside a selection file with a certain label.
This function returns the number of images inside the selection file with a given label. By default this label is ACTIVE.
Definition at line 589 of file selfile.cpp.
void SelFile::ImgSize | ( | int & | Ydim, |
int & | Xdim | ||
) |
Returns the size of the images inside.
The filenames within a selection file are supposed to be for SPIDER images, this function opens one of the images (an active one) and returns the size of that image, supposed to be the same for the rest of the images in the selection file.
An exception is thrown if the first valid image in the selfile, doesn't exist in the disk or it is not a XMIPP image.
void SelFile::insert | ( | const std::string & | img_name, |
SelLine::Label | label = SelLine::ACTIVE |
||
) |
Insert image before current line.
There is no checking for the previous existence of the img. The current line is still pointing to the same line as it was before entering the function.
Definition at line 759 of file selfile.cpp.
void SelFile::insert | ( | const SelLine & | _selline | ) |
Insert line before current line.
It is checked that the line is either a comment or data line, in this case that the label is right, too. The current line is still pointing to the same line as it was before entering the function.
Definition at line 774 of file selfile.cpp.
void SelFile::insert_comment | ( | const std::string & | comment | ) |
Insert a comment before the current line.
Comments must not start with any special character since a "#" is automatically added at the beginning of the line. The current line is still pointing to the same line as it was before entering the function.
Definition at line 794 of file selfile.cpp.
|
inline |
True if current line is a data line and it is active.
Definition at line 503 of file selfile.h.
|
inline |
|
inline |
True if current line is a data line and it is active.
Definition at line 511 of file selfile.h.
void SelFile::jump | ( | int | count, |
SelLine::Label | label = SelLine::ACTIVE |
||
) |
Jump over a number of lines with a given label.
Starting from the current_line "pointer" this function skips a given number of entries with a certain label. For instance, jump over 1 active image is to jump to the next active image. Jump over 2 active images is to jump to the next of the next active image, and so on. You can give as label DISCARDED, too. The number of images to jump must always be positive, the jump cannot be done backwards.
Definition at line 540 of file selfile.cpp.
bool SelFile::jump_lines | ( | int | count | ) |
Jump over a number of lines disregarding the label.
Returns false if the end of the line is reached before the number of requested line jumps
Definition at line 527 of file selfile.cpp.
int SelFile::LineNo | ( | ) |
Returns the number of lines within a file.
This function gives the total number of lines (including comments) within a file.
Definition at line 605 of file selfile.cpp.
int SelFile::MaxFileNameLength | ( | ) |
Returns the maximum length of an active filename inside the selfile.
The current pointer is not moved.
Definition at line 632 of file selfile.cpp.
void SelFile::merge | ( | const FileName & | name | ) |
Merge a file from disk with an already read one.
All lines (except the comments) in the selection file to be read are either added at the end of the already read one if they are not present at them, either ignored if they are already present, or marked with a comment if the corresponding image name is present in both files but with different labels (active, discarded), in this case the image remains active but a comment in the preceding line informs you of the situation.
Definition at line 254 of file selfile.cpp.
void SelFile::merge | ( | SelFile & | sel | ) |
Merge this file with another selfile.
Definition at line 308 of file selfile.cpp.
void SelFile::mpi_select_part | ( | int | rank, |
int | size, | ||
int & | num_img_tot | ||
) |
For MPI-parallelized runs: select relevant part of selfile for that rank.
Definition at line 425 of file selfile.cpp.
void SelFile::mpi_select_part2 | ( | int | rank, |
int | size, | ||
int & | num_img_tot, | ||
int | mpi_job_size | ||
) |
For MPI-parallelized runs: select relevant part of selfile for that rank. I just do not undertand the previous function
Definition at line 458 of file selfile.cpp.
|
inline |
|
inline |
Move the current pointer to the next image, disregarding its label.
It doesn't matter if next image is ACTIVE or DISCARDED, this function moves the current pointer to it.
const std::string & SelFile::NextImg | ( | SelLine::Label | label = SelLine::ACTIVE | ) |
Returns the name of the next image with a certain label.
The default label is ACTIVE, ie, by default this function returns the name of the next ACTIVE image. But you can give as label DISCARDED and the function will return the name of the next DISCARDED image starting at the current position of the current_line "pointer". If the file is at the end of the selection file, "" is returned. After this function the "pointer" is actually pointing to the next line following the returned image name.
Definition at line 516 of file selfile.cpp.
|
inline |
Get the line i in the file
Get the line i in the file for reading. If it is a comment the comment text is returned. If it is an image, the image filename. The first line in the file is number 0.
Merge two already read files.
Definition at line 355 of file selfile.cpp.
SelFile SelFile::random_discard | ( | int | N | ) |
Discard randomly N images.
A set of N images are discarded from the actual selection file. If N is equal or greater than the actual number of images within the file, all images are discarded. Comments are kept at their original positions. The current line of the resulting selection file is placed at the beginning of the file.
Definition at line 844 of file selfile.cpp.
SelFile SelFile::randomize | ( | ) |
Alter order in sel file.
A new selection file with all the images of the actual object (either they are active or discarded) is created, but this time all images are in a random order. The comments of the original selection file are lost in the new copy. The current line of the resulting selection file is placed at the beginning of the file.
Definition at line 816 of file selfile.cpp.
SelFile SelFile::randomSubset | ( | int | subsetN, |
bool | withReplacement = true |
||
) |
Random subset.
A new selection file is created with the number of images specified in subsetN. The new subset can be created with or without replacement.
void SelFile::read | ( | const FileName & | name, |
int | overrinding = 1 |
||
) |
Read a file from disk.
The old information on the variable is overwritten. An exception is thrown if the file doesn't exist. Lines which do not fit the comment structure or the "image-label" structure are ignored. The image name is limited to MAX_FILENAME_LENGTH characters. After reading the selfile pointer is moved to the first ACTIVE image.
Definition at line 196 of file selfile.cpp.
void SelFile::remove | ( | const std::string & | img_name | ) |
Removes an image from the selection file.
This function searches for an image in the selection file, if it is found then the corresponding line is deleted. If the image is actually being pointed by the current line, then the current line is now the following line.
Definition at line 678 of file selfile.cpp.
void SelFile::remove_current | ( | ) |
Removes actual line.
This function removes the current line, either it is a comment or an image. The current line "pointer" is moved to the following line in the file.
Definition at line 699 of file selfile.cpp.
|
inline |
|
inline |
Move "pointer" to a certain image filename.
This function searches for an image name within the file, and locate the current line "pointer" pointing to that line. If the image name is not present (it is not the same "not present" and "discarded") in the selection file, then the pointer is moved to the end of the selection file. You can check this situation using eof(). It doesn't matter if the current line "pointer" before the function call is after the line where the image name is, this function makes a search all over the file, regardless the previous situation of the current line "pointer".
void SelFile::set | ( | const std::string & | img_name, |
SelLine::Label | label | ||
) |
Set label of an image.
This function searches for an image inside the selection file and sets its label to the given label. If the image is not found in the file, then it is added at the end with the given label. The current line pointer is not modified.
Definition at line 714 of file selfile.cpp.
void SelFile::set_current | ( | SelLine::Label | label | ) |
Set the label of the current file.
The same as the previous function but the label is set to the file currently pointed.
Definition at line 739 of file selfile.cpp.
void SelFile::set_current_filename | ( | const FileName & | fn_new | ) |
Change current filename.
This function changes the current filename to a new one if it is not a comment. If it is a comment line, nothing is done.
Definition at line 750 of file selfile.cpp.
SelFile SelFile::sort_by_filenames | ( | ) |
Sort images in ascending order.
All images are sorted in ascending order either they are active or discarded. All comments are gathered at the end of the resulting selection file. The current line of the resulting selection file is placed at the beginning of the file.
Definition at line 807 of file selfile.cpp.
void SelFile::split_in_N | ( | int | N, |
std::vector< SelFile > & | parts | ||
) |
Split this file into N random parts of approximately the same size.
Definition at line 391 of file selfile.cpp.
Split this file into two random halves.
Definition at line 364 of file selfile.cpp.
void SelFile::write | ( | const FileName & | sel_name = "" | ) |
Write a selection file to disk.
If you give a name then it becomes like a "Save as ..." and from this point on the name of the selection file has changed.
Definition at line 262 of file selfile.cpp.
Compare two selection files.
The result is another selection file. At the beginning of it there is information about the number of active and discarded images on both input selection files, about the number of matching files (a file is said to match if it is active in both selection files), the number of active files which are only in the first selection file, and the number of active files which are only in the second. Then goes the list of matching files, the list of files only in SF1 and the list of files only in SF2. There are comments enough to know where things start and finish, and what the numbers are at the beginning. If a file is active in a file and discarded in the other, then it is said to match and it is kept as active, a preceding comment warns of this situation.
if mode<0, output file will contain all information if mode=0, output will be selfile with overlapping images if mode=1, output will be selfile with images only in file 1 if mode=2, output will be selfile with images only in file 2
Definition at line 872 of file selfile.cpp.
|
friend |
Show a selection file.
Shows all the lines either they are comments, active images or discarded images. A new line is printed at the end.
Definition at line 145 of file selfile.cpp.