Xmipp  v3.23.11-Nereus
aextrema_finder.cpp
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 #include "aextrema_finder.h"
27 
28 namespace ExtremaFinder {
29 
30 template<typename T>
31 void AExtremaFinder<T>::init(const ExtremaFinderSettings &settings, bool reuse) {
32  // check that settings is not completely wrong
33  settings.check();
34  bool skipInit = m_isInit && reuse && this->canBeReused(settings);
35  // set it
36  m_settings = ExtremaFinderSettings(settings);
37  if ( ! skipInit) {
38  // initialize
39  switch (m_settings.searchType) {
40  case SearchType::Max:
41  this->initMax();
42  break;
43  case SearchType::Lowest:
44  this->initLowest();
45  break;
47  this->initMaxAroundCenter();
48  break;
50  this->initLowestAroundCenter();
51  break;
52  default: REPORT_ERROR(ERR_NOT_IMPLEMENTED, "Not implemented");
53  }
54  // check that there's no logical problem
55  this->check();
56  // no issue found, we're good to go
57  m_isInit = true;
58  }
59 }
60 
61 template<typename T>
63  switch (s.searchType) {
64  case SearchType::Max: return this->canBeReusedMax(s);
65  case SearchType::Lowest: return this->canBeReusedLowest(s);
66  case SearchType::MaxAroundCenter: return this->canBeReusedMaxAroundCenter(s);
67  case SearchType::LowestAroundCenter: return this->canBeReusedLowestAroundCenter(s);
68  default: REPORT_ERROR(ERR_NOT_IMPLEMENTED, "Not implemented");
69  }
70 }
71 
72 template<typename T>
73 void AExtremaFinder<T>::find(const T *data) {
74  if ((ResultType::Position == m_settings.resultType)
75  || (ResultType::Both == m_settings.resultType)) {
76  m_positions.resize(m_settings.dims.n(), -1.f);
77  }
78  if ((ResultType::Value == m_settings.resultType)
79  || (ResultType::Both == m_settings.resultType)) {
80  m_values.resize(m_settings.dims.n(), std::numeric_limits<T>::lowest());
81  }
82  switch (m_settings.searchType) {
83  case SearchType::Max: return this->findMax(data);
84  case SearchType::Lowest: return this->findLowest(data);
85  case SearchType::MaxAroundCenter: return this->findMaxAroundCenter(data);
86  case SearchType::LowestAroundCenter: return this->findLowestAroundCenter(data);
87  default: REPORT_ERROR(ERR_NOT_IMPLEMENTED, "Not implemented");
88  }
89 }
90 
91 // explicit instantiation
92 template class AExtremaFinder<float>;
93 template class AExtremaFinder<double>;
94 
95 } /* namespace ExtremaFinder */
Case or algorithm not implemented yet.
Definition: xmipp_error.h:177
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void init(const ExtremaFinderSettings &settings, bool reuse)
check(nparam, nf, nfsr, &Linfty, nineq, nineqn, neq, neqn, ncsrl, ncsrn, mode, &modem, eps, bgbnd, param)