ITK  6.0.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 
23 #include "itkOptimizerParameters.h"
26 #include "itkIntTypes.h"
27 
28 namespace itk
29 {
35 {
36 public:
43  {
51  };
52 };
53 // Define how to print enumeration
56 extern ITKOptimizersv4_EXPORT std::ostream &
57  operator<<(std::ostream & out,
59 
112 template <typename TInternalComputationValueType = double>
113 class ITK_TEMPLATE_EXPORT ObjectToObjectOptimizerBaseTemplate : public Object
114 {
115 public:
116  ITK_DISALLOW_COPY_AND_MOVE(ObjectToObjectOptimizerBaseTemplate);
117 
123 
125  itkOverrideGetNameOfClassMacro(ObjectToObjectOptimizerBaseTemplate);
126 
130 
133 
137 
140 
143 
145  using MeasureType = typename MetricType::MeasureType;
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
199  GetScalesInitialized() const;
200 
210  itkSetObjectMacro(ScalesEstimator, ScalesEstimatorType);
211 
217  itkSetMacro(DoEstimateScales, bool);
218  itkGetConstReferenceMacro(DoEstimateScales, bool);
219  itkBooleanMacro(DoEstimateScales);
225  virtual void
226  SetNumberOfWorkUnits(ThreadIdType number);
227 
228 #if !defined(ITK_LEGACY_REMOVE)
229 
232  itkLegacyMacro(virtual void SetNumberOfThreads(ThreadIdType number))
233  {
234  return this->SetNumberOfWorkUnits(number);
235  }
236  itkLegacyMacro(virtual const ThreadIdType & GetNumberOfThreads() const)
237  {
238  return this->m_NumberOfWorkUnits;
239  }
240 #endif // !ITK_LEGACY_REMOVE
241 
244  itkGetConstReferenceMacro(NumberOfWorkUnits, ThreadIdType);
245 
247  itkGetConstMacro(CurrentIteration, SizeValueType);
248 
250  itkSetMacro(NumberOfIterations, SizeValueType);
251 
253  itkGetConstMacro(NumberOfIterations, SizeValueType);
254 
258  virtual const ParametersType &
259  GetCurrentPosition() const;
260 
268  virtual void
269  StartOptimization(bool doOnlyInitialization = false);
270 
272  virtual StopConditionReturnStringType
273  GetStopConditionDescription() const = 0;
274 
278  virtual bool
279  CanUseScales() const
280  {
281  return true;
282  }
283 
284 protected:
290  MetricTypePointer m_Metric{};
291  ThreadIdType m_NumberOfWorkUnits{};
292  SizeValueType m_CurrentIteration{};
293  SizeValueType m_NumberOfIterations{};
294 
296  MeasureType m_CurrentMetricValue{};
297 
300  ScalesType m_Scales{};
301 
306  ScalesType m_Weights{};
307 
309  bool m_ScalesAreIdentity{};
310 
312  typename ScalesEstimatorType::Pointer m_ScalesEstimator{};
313 
315  bool m_WeightsAreIdentity{};
316 
320  bool m_DoEstimateScales{};
321 
322  void
323  PrintSelf(std::ostream & os, Indent indent) const override;
324 };
325 
328 
329 } // end namespace itk
330 
331 #endif
332 
334 #ifndef ITK_TEMPLATE_EXPLICIT_ObjectToObjectOptimizerBaseTemplate
335 // Explicit instantiation is required to ensure correct dynamic_cast
336 // behavior across shared libraries.
337 //
338 // IMPORTANT: Since within the same compilation unit,
339 // ITK_TEMPLATE_EXPLICIT_<classname> defined and undefined states
340 // need to be considered. This code *MUST* be *OUTSIDE* the header
341 // guards.
342 //
343 #if defined(ITKOptimizersv4_EXPORTS)
344 // We are building this library
345 # define ITKOptimizersv4_EXPORT_EXPLICIT ITK_FORWARD_EXPORT
346 #else
347 // We are using this library
348 # define ITKOptimizersv4_EXPORT_EXPLICIT ITKOptimizersv4_EXPORT
349 #endif
350 namespace itk
351 {
352 
353 ITK_GCC_PRAGMA_DIAG_PUSH()
354 ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
355 
356 #if defined(_MSC_VER)
357 # pragma warning(disable : 4661) // no suitable definition provided for explicit template instantiation request
358 #endif
361 
362 ITK_GCC_PRAGMA_DIAG_POP()
363 
364 } // end namespace itk
365 #undef ITKOptimizersv4_EXPORT_EXPLICIT
366 #endif
itk::ObjectToObjectOptimizerBaseTemplateEnums
This class contains all the enum classes used by ObjectToObjectOptimizerBaseTemplate class.
Definition: itkObjectToObjectOptimizerBase.h:34
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::OptimizerParameterScalesEstimatorTemplate
OptimizerParameterScalesEstimatorTemplate is the base class offering a empty method of estimating the...
Definition: itkOptimizerParameterScalesEstimator.h:39
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::MAXIMUM_NUMBER_OF_ITERATIONS
itk::OptimizerParameters< double >
itk::ObjectToObjectOptimizerBaseTemplate::CanUseScales
virtual bool CanUseScales() const
Definition: itkObjectToObjectOptimizerBase.h:279
itk::ObjectToObjectOptimizerBaseTemplate< float >
template class ITKOptimizersv4_EXPORT_EXPLICIT ObjectToObjectOptimizerBaseTemplate< float >
itk::ObjectToObjectMetricBaseTemplate::NumberOfParametersType
unsigned int NumberOfParametersType
Definition: itkObjectToObjectMetricBase.h:176
itk::ObjectToObjectOptimizerBaseTemplate::SetScales
virtual void SetScales(const ScalesType &scales)
Definition: itkObjectToObjectOptimizerBase.h:174
itk::ObjectToObjectOptimizerBaseTemplate< double >::NumberOfParametersType
typename MetricType::NumberOfParametersType NumberOfParametersType
Definition: itkObjectToObjectOptimizerBase.h:142
itk::ObjectToObjectOptimizerBaseTemplate< double >
template class ITKOptimizersv4_EXPORT_EXPLICIT ObjectToObjectOptimizerBaseTemplate< double >
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::CONVERGENCE_CHECKER_PASSED
itk::ObjectToObjectOptimizerBaseTemplate< double >::StopConditionReturnStringType
std::string StopConditionReturnStringType
Definition: itkObjectToObjectOptimizerBase.h:148
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::GRADIENT_MAGNITUDE_TOLEARANCE
itk::operator<<
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
StopConditionObjectToObjectOptimizer
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::COSTFUNCTION_ERROR
itk::ThreadIdType
unsigned int ThreadIdType
Definition: itkIntTypes.h:102
itkOptimizerParameterScalesEstimator.h
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itkOptimizerParameters.h
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer
StopConditionObjectToObjectOptimizer
Definition: itkObjectToObjectOptimizerBase.h:42
itk::ObjectToObjectMetricBaseTemplate
Base class for all object-to-object similarity metrics added in ITKv4.
Definition: itkObjectToObjectMetricBase.h:90
itkIntTypes.h
ITKOptimizersv4_EXPORT_EXPLICIT
#define ITKOptimizersv4_EXPORT_EXPLICIT
Definition: itkObjectToObjectOptimizerBase.h:348
itk::ObjectToObjectOptimizerBaseTemplate< double >::DerivativeType
typename MetricType::DerivativeType DerivativeType
Definition: itkObjectToObjectOptimizerBase.h:139
itkObjectToObjectMetricBase.h
itk::ObjectToObjectOptimizerBaseTemplate< double >::MetricTypePointer
typename MetricType::Pointer MetricTypePointer
Definition: itkObjectToObjectOptimizerBase.h:136
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::UPDATE_PARAMETERS_ERROR
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::OTHER_ERROR
itk::ObjectToObjectOptimizerBaseTemplate
Abstract base for object-to-object optimizers.
Definition: itkObjectToObjectOptimizerBase.h:113
itk::Array< TInternalComputationValueType >
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::ObjectToObjectOptimizerBaseTemplate< double >::StopConditionDescriptionType
std::ostringstream StopConditionDescriptionType
Definition: itkObjectToObjectOptimizerBase.h:151
itk::ObjectToObjectOptimizerBaseTemplate< double >::MeasureType
typename MetricType::MeasureType MeasureType
Definition: itkObjectToObjectOptimizerBase.h:145
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::STEP_TOO_SMALL
itk::StopConditionObjectToObjectOptimizerEnum
ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer StopConditionObjectToObjectOptimizerEnum
Definition: itkObjectToObjectOptimizerBase.h:55
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86