Xmipp  v3.23.11-Nereus
ageo_transformer.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 LIBRARIES_RECONSTRUCTION_AGEO_TRANSFORMER_H_
27 #define LIBRARIES_RECONSTRUCTION_AGEO_TRANSFORMER_H_
28 
29 #include "data/dimensions.h"
30 #include "core/xmipp_error.h"
31 #include <memory>
32 #include "data/hw.h"
33 #include <vector>
34 
39 enum class InterpolationType {
40  OneToN, // we have one original item, output are multiple items derived from the original one
41  NToN // we have multiple original items, output are multiple items derived from respective original one
42 };
43 
44 template<typename T>
46 public:
47  virtual ~GeoTransformerSettings() = default;
48  std::vector<HW*> hw;
52  bool doWrap;
54 
55  virtual void check() const {
56  if (0 == hw.size()) {
57  REPORT_ERROR(ERR_VALUE_INCORRECT, "HW contains zero (0) devices");
58  }
59  if ( ! dims.isValid()) {
60  REPORT_ERROR(ERR_LOGIC_ERROR, "Dimensions are invalid");
61  }
62  }
63 };
64 
65 template<typename SettingsType, typename T>
67  static_assert(std::is_base_of<GeoTransformerSettings<T>, SettingsType>::value,
68  "SettingsType must inherit from GeoTransformerSettings");
69 public:
71  m_isInit(false),
72  m_isSrcSet(false) {};
73  virtual ~AGeoTransformer() = default;
74 
75  void init(const SettingsType &s, bool reuse) {
76  s.check();
77  bool skipAllocation = reuse && this->isInitialized() && canBeReused(s);
78  m_settings = s;
79  this->initialize( ! skipAllocation);
80  this->check();
81  m_isInit = true;
82  }
83 
84  virtual void setSrc(const T *data) = 0;
85  virtual const T *getSrc() const = 0;
86 
87  virtual T *getDest() const = 0;
88  virtual void copySrcToDest() = 0;
89 
90  inline const SettingsType &getSettings() const {
91  return m_settings;
92  }
93 
94 protected:
95  virtual void check() = 0;
96  virtual void initialize(bool allocate) = 0;
97  virtual bool canBeReused(const SettingsType &s) const = 0;
98 
99  inline constexpr bool isInitialized() const {
100  return m_isInit;
101  }
102 
103  inline constexpr bool isSrcSet() const {
104  return m_isSrcSet;
105  }
106 
107  void setIsSrcSet(bool status) {
108  m_isSrcSet = status;
109  }
110 
111 private:
112  SettingsType m_settings;
113  bool m_isInit;
114  bool m_isSrcSet;
115 };
117 
118 #endif /* LIBRARIES_RECONSTRUCTION_AGEO_TRANSFORMER_H_ */
const SettingsType & getSettings() const
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void init(const SettingsType &s, bool reuse)
constexpr bool isSrcSet() const
virtual void check() const
InterpolationType
InterpolationDegree degree
constexpr bool isInitialized() const
std::vector< HW * > hw
void setIsSrcSet(bool status)
InterpolationDegree
constexpr bool isValid() const
Definition: dimensions.h:138
InterpolationType type
Incorrect value received.
Definition: xmipp_error.h:195
check(nparam, nf, nfsr, &Linfty, nineq, nineqn, neq, neqn, ncsrl, ncsrn, mode, &modem, eps, bgbnd, param)
Some logical error in the pipeline.
Definition: xmipp_error.h:147