ITK  5.4.0
Insight Toolkit
itkObjectToObjectOptimizerBase.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkObjectToObjectOptimizerBase_h
19#define itkObjectToObjectOptimizerBase_h
20
21#include "ITKOptimizersv4Export.h"
22
26#include "itkIntTypes.h"
27
28namespace itk
29{
35{
36public:
43 {
44 MAXIMUM_NUMBER_OF_ITERATIONS,
45 COSTFUNCTION_ERROR,
46 UPDATE_PARAMETERS_ERROR,
47 STEP_TOO_SMALL,
48 CONVERGENCE_CHECKER_PASSED,
49 GRADIENT_MAGNITUDE_TOLEARANCE,
50 OTHER_ERROR
51 };
52};
53// Define how to print enumeration
56extern ITKOptimizersv4_EXPORT std::ostream &
57 operator<<(std::ostream & out,
59
112template <typename TInternalComputationValueType = double>
113class ITK_TEMPLATE_EXPORT ObjectToObjectOptimizerBaseTemplate : public Object
114{
115public:
116 ITK_DISALLOW_COPY_AND_MOVE(ObjectToObjectOptimizerBaseTemplate);
117
123
125 itkOverrideGetNameOfClassMacro(ObjectToObjectOptimizerBaseTemplate);
126
130
133
137
140
143
146
148 using StopConditionReturnStringType = std::string;
149
151 using StopConditionDescriptionType = std::ostringstream;
152
154 itkSetObjectMacro(Metric, MetricType);
155 itkGetModifiableObjectMacro(Metric, MetricType);
161 itkGetConstReferenceMacro(CurrentMetricValue, MeasureType);
162
168 virtual const MeasureType &
169 GetValue() const;
170
172 // itkSetMacro( Scales, ScalesType );
173 virtual void
174 SetScales(const ScalesType & scales)
175 {
176 this->m_Scales = scales;
177 }
181 itkGetConstReferenceMacro(Scales, ScalesType);
182
184 itkGetConstReferenceMacro(ScalesAreIdentity, bool);
185
187 itkSetMacro(Weights, ScalesType);
188
191 itkGetConstReferenceMacro(Weights, ScalesType);
192
194 itkGetConstReferenceMacro(WeightsAreIdentity, bool);
195
198 bool
200
210 itkSetObjectMacro(ScalesEstimator, ScalesEstimatorType);
211
217 itkSetMacro(DoEstimateScales, bool);
218 itkGetConstReferenceMacro(DoEstimateScales, bool);
219 itkBooleanMacro(DoEstimateScales);
225 virtual void
227
228#if !defined(ITK_LEGACY_REMOVE)
232 itkLegacyMacro(virtual void SetNumberOfThreads(ThreadIdType number)) { return this->SetNumberOfWorkUnits(number); }
233 itkLegacyMacro(virtual const ThreadIdType & GetNumberOfThreads() const) { return this->m_NumberOfWorkUnits; }
234#endif // !ITK_LEGACY_REMOVE
238 itkGetConstReferenceMacro(NumberOfWorkUnits, ThreadIdType);
239
241 itkGetConstMacro(CurrentIteration, SizeValueType);
242
244 itkSetMacro(NumberOfIterations, SizeValueType);
245
247 itkGetConstMacro(NumberOfIterations, SizeValueType);
248
252 virtual const ParametersType &
254
262 virtual void
263 StartOptimization(bool doOnlyInitialization = false);
264
268
272 virtual bool
274 {
275 return true;
276 }
277
278protected:
285 ThreadIdType m_NumberOfWorkUnits{};
286 SizeValueType m_CurrentIteration{};
287 SizeValueType m_NumberOfIterations{};
288
290 MeasureType m_CurrentMetricValue{};
291
294 ScalesType m_Scales{};
295
300 ScalesType m_Weights{};
301
303 bool m_ScalesAreIdentity{};
304
306 typename ScalesEstimatorType::Pointer m_ScalesEstimator{};
307
309 bool m_WeightsAreIdentity{};
310
314 bool m_DoEstimateScales{};
315
316 void
317 PrintSelf(std::ostream & os, Indent indent) const override;
318};
319
322
323} // end namespace itk
324
325#endif
326
328#ifndef ITK_TEMPLATE_EXPLICIT_ObjectToObjectOptimizerBaseTemplate
329// Explicit instantiation is required to ensure correct dynamic_cast
330// behavior across shared libraries.
331//
332// IMPORTANT: Since within the same compilation unit,
333// ITK_TEMPLATE_EXPLICIT_<classname> defined and undefined states
334// need to be considered. This code *MUST* be *OUTSIDE* the header
335// guards.
336//
337#if defined(ITKOptimizersv4_EXPORTS)
338// We are building this library
339# define ITKOptimizersv4_EXPORT_EXPLICIT ITK_FORWARD_EXPORT
340#else
341// We are using this library
342# define ITKOptimizersv4_EXPORT_EXPLICIT ITKOptimizersv4_EXPORT
343#endif
344namespace itk
345{
346
347ITK_GCC_PRAGMA_DIAG_PUSH()
348ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
349
350#if defined(_MSC_VER)
351# pragma warning(disable : 4661) // no suitable definition provided for explicit template instantiation request
352#endif
355
356ITK_GCC_PRAGMA_DIAG_POP()
357
358} // end namespace itk
359#undef ITKOptimizersv4_EXPORT_EXPLICIT
360#endif
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Base class for all object-to-object similarity metrics added in ITKv4.
This class contains all the enum classes used by ObjectToObjectOptimizerBaseTemplate class.
Abstract base for object-to-object optimizers.
typename MetricType::DerivativeType DerivativeType
virtual void StartOptimization(bool doOnlyInitialization=false)
typename MetricType::NumberOfParametersType NumberOfParametersType
void PrintSelf(std::ostream &os, Indent indent) const override
virtual const StopConditionReturnStringType GetStopConditionDescription() const =0
virtual const ParametersType & GetCurrentPosition() const
virtual void SetScales(const ScalesType &scales)
virtual const MeasureType & GetValue() const
virtual void SetNumberOfWorkUnits(ThreadIdType number)
Base class for most ITK classes.
Definition: itkObject.h:62
OptimizerParameterScalesEstimatorTemplate is the base class offering a empty method of estimating the...
SmartPointer< Self > Pointer
#define ITKOptimizersv4_EXPORT_EXPLICIT
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
template class ITKOptimizersv4_EXPORT_EXPLICIT ObjectToObjectOptimizerBaseTemplate< double >
template class ITKOptimizersv4_EXPORT_EXPLICIT ObjectToObjectOptimizerBaseTemplate< float >
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:216
unsigned long SizeValueType
Definition: itkIntTypes.h:83