Xmipp  v3.23.11-Nereus
xmipp_metadata_program.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: David Strelak (davidstrelak@gmail.com)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #ifndef CORE_XMIPP_METADATA_PROGRAM_H_
27 #define CORE_XMIPP_METADATA_PROGRAM_H_
28 
29 #include "xmipp_program.h"
30 #include "xmipp_datatype.h"
31 #include "xmipp_filename.h"
32 #include "metadata_label.h"
33 #include "metadata_row_sql.h"
34 #include "metadata_writemode.h"
35 #include "metadata_base.h"
36 #include "metadata_vec.h"
37 
38 
44 class XmippMetadataProgram: public virtual XmippProgram
45 {
46 private:
48  MetaData * mdIn = nullptr;
49  MetaDataVec mdOut; //TODO: can be treated by reference as mdIn for
50  // uses from another programs...
51  std::unique_ptr<MetaData::id_iterator> iter;
52  size_t iterIndex;
53 
54 public:
58  MetaData * getInputMd() { return mdIn; }
59  MetaDataVec& getOutputMd() { return mdOut; }
60 
61 public:
62  //Image<double> img;
66  bool apply_geo;
71  size_t mdInSize;
72 
73 protected:
76 
81 
82 
83  // BEHAVIOR CONTROL FLAGS //
84 
86  bool produces_an_output; // Default false (only -o param is used)
88  bool produces_a_metadata; // Default false (if true, then produces_an_output is set true)
90  bool each_image_produces_an_output; // Default false (both -o --oroot params are used)
93  bool allow_apply_geo; // Default false
95  bool decompose_stacks; // Default true
97  bool delete_output_stack; // Default true
99  bool get_image_info; // Default true
101  bool save_metadata_stack; // Default false
103  bool track_origin; // Default false
105  bool keep_input_columns; // Default false
107  bool remove_disabled; // Default true
109  bool allow_time_bar; // Default true
110 
111  // DEDUCED FLAGS
120  // Create empty output stack file prior to process images
122  //check whether to delete or not the input metadata
124 
127 
128  virtual void initComments();
129  virtual void defineParams();
130  virtual void readParams();
131  virtual void preProcess();
132  virtual void postProcess();
133  virtual void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut) = 0;
134  virtual bool getImageToProcess(size_t &objId, size_t &objIndex);
135  void show() const override;
140  virtual void startProcessing();
141  virtual void finishProcessing();
142  virtual void writeOutput(); // maybe used by checkpoint
143  virtual void showProgress();
144 
146  virtual void defineLabelParam();
147 
148 public:
150 
156  virtual int tryRead(int argc, const char ** argv, bool reportErrors = true);
157 
160  virtual void init();
161 
165  virtual void setup(MetaData *md, const FileName &o="", const FileName &oroot="",
166  bool applyGeo=false, MDLabel label=MDL_IMAGE);
167 
168 
171  virtual ~XmippMetadataProgram();
172 
174  {
175  mode = _mode;
176  }
177 
179  void setupRowOut(const FileName &fnImgIn, const MDRow &rowIn, const FileName &fnImgOut, MDRow &rowOut) const;
180 
182  virtual void wait();
183 
185  virtual void checkPoint();
186 
188  virtual void run();
189 }
190 ;// end of class XmippMetadataProgram
191 
192 #endif /* CORE_XMIPP_METADATA_PROGRAM_H_ */
bool delete_output_stack
Delete previous output stack file prior to process images.
size_t mdInSize
Number of input elements.
virtual int tryRead(int argc, const char **argv, bool reportErrors=true)
bool single_image
Input is a single image.
bool get_image_info
Get the input image file dimensions to further operations.
bool input_is_stack
Input is a stack.
bool output_is_stack
Output is a stack.
XmippMetadataProgram()
Empty constructor.
int argc
Original command line arguments.
Definition: xmipp_program.h:86
FileName fn_in
Filenames of input and output Metadata.
virtual void wait()
Wait for the distributor to finish.
virtual void setup(MetaData *md, const FileName &o="", const FileName &oroot="", bool applyGeo=false, MDLabel label=MDL_IMAGE)
void setupRowOut(const FileName &fnImgIn, const MDRow &rowIn, const FileName &fnImgOut, MDRow &rowOut) const
Prepare rowout.
const char ** argv
Definition: xmipp_program.h:87
bool produces_an_output
Indicate that a unique final output is produced.
virtual void run()
Run over all images.
DataType
MDLabel image_label
MDLabel to be used to read/write images, usually will be MDL_IMAGE.
bool allow_time_bar
Show process time bar.
virtual void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)=0
bool track_origin
Include the original input image filename in the output stack.
bool remove_disabled
Remove disabled images from the input selfile.
virtual void checkPoint()
For very long programs, it may be needed to write checkpoints.
void show() const override
bool save_metadata_stack
Save the associated output metadata when output file is a stack.
bool decompose_stacks
Input Metadata will treat a stack file as a set of images instead of a unique file.
void setMode(WriteModeMetaData _mode)
bool keep_input_columns
Keep input metadata columns.
bool each_image_produces_an_output
Indicate that an output is produced for each image in the input.
WriteModeMetaData mode
Metadata writing mode: OVERWRITE, APPEND.
size_t ndimOut
Output dimensions.
virtual bool getImageToProcess(size_t &objId, size_t &objIndex)
bool input_is_metadata
Input is a metadata.
WriteModeMetaData
Name of an image (std::string)
MDLabel
bool produces_a_metadata
Indicate that the unique final output file is a Metadata.
size_t time_bar_step
Some time bar related counters.
FileName oext
Output extension and root.