ITK  5.2.0
Insight Toolkit
itkOptimizerParameters.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  * http://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 itkOptimizerParameters_h
19 #define itkOptimizerParameters_h
20 
21 #include "itkArray.h"
23 
24 #include <memory> // For unique_ptr.
25 
26 namespace itk
27 {
35 template <typename TParametersValueType>
36 class ITK_TEMPLATE_EXPORT OptimizerParameters : public Array<TParametersValueType>
37 {
38 public:
40  using ValueType = TParametersValueType;
46 
50 
53  OptimizerParameters() = default;
54 
61  : Array<TParametersValueType>(rhs)
62  {
63  // Note: don't copy the OptimizerParametersHelper.
64  // The Array copy constructor will allocate new memory
65  // and copy the data to it. So we end up here with a generic
66  // OptimizerParameters data object even if 'rhs' points to
67  // something different.
68  }
69 
73  explicit OptimizerParameters(SizeValueType dimension)
74  : Array<TParametersValueType>(dimension)
75  {}
76 
79  : Array<TParametersValueType>(array)
80  {}
81 
83  explicit OptimizerParameters(const SizeValueType dimension, const ValueType & value)
84  : Array<TParametersValueType>(dimension, value)
85  {}
86 
88  void
90  {
91  // Set the default OptimizerParametersHelper
92  this->m_Helper.reset(new OptimizerParametersHelperType);
93  }
94 
95 
101  virtual void
102  MoveDataPointer(TParametersValueType * pointer)
103  {
104  if (m_Helper == nullptr)
105  {
106  itkGenericExceptionMacro("OptimizerParameters::MoveDataPointer: "
107  "m_Helper must be set.");
108  }
109  this->m_Helper->MoveDataPointer(this, pointer);
110  }
112 
117  virtual void
119  {
120  if (m_Helper == nullptr)
121  {
122  itkGenericExceptionMacro("OptimizerParameters::SetParameterObject: "
123  "m_Helper must be set.");
124  }
125  this->m_Helper->SetParametersObject(this, object);
126  }
128 
134  virtual void
136  {
137  this->m_Helper.reset(helper);
138  }
139 
141  OptimizerParametersHelperType *
143  {
144  return m_Helper.get();
145  }
146 
152  const Self &
153  operator=(const Self & rhs)
154  {
155  // Note: there's no need to copy the OptimizerParametersHelper.
156  // Call the superclass implementation.
157  this->ArrayType::operator=(rhs);
158  return *this;
159  }
161 
162  const Self &
163  operator=(const ArrayType & rhs)
164  {
165  // Call the superclass implementation
166  this->ArrayType::operator=(rhs);
167  return *this;
168  }
169 
170  const Self &
172  {
173  // Call the superclass implementation
174  this->ArrayType::operator=(rhs);
175  return *this;
176  }
177 
178  ~OptimizerParameters() override = default;
179 
180 private:
181  std::unique_ptr<OptimizerParametersHelperType> m_Helper =
182  std::unique_ptr<OptimizerParametersHelperType>{ new OptimizerParametersHelperType };
183 };
184 
185 } // namespace itk
186 
187 #endif
itkOptimizerParametersHelper.h
itk::OptimizerParameters
Class to hold and manage different parameter types used during optimization.
Definition: itkOptimizerParameters.h:36
itk::OptimizerParameters::SetParametersObject
virtual void SetParametersObject(LightObject *object)
Definition: itkOptimizerParameters.h:118
itk::OptimizerParameters::SetHelper
virtual void SetHelper(OptimizerParametersHelperType *helper)
Definition: itkOptimizerParameters.h:135
itk::OptimizerParameters::OptimizerParameters
OptimizerParameters(const SizeValueType dimension, const ValueType &value)
Definition: itkOptimizerParameters.h:83
itk::OptimizerParameters::operator=
const Self & operator=(const ArrayType &rhs)
Definition: itkOptimizerParameters.h:163
itk::OptimizerParameters::MoveDataPointer
virtual void MoveDataPointer(TParametersValueType *pointer)
Definition: itkOptimizerParameters.h:102
itk::OptimizerParameters::operator=
const Self & operator=(const Self &rhs)
Definition: itkOptimizerParameters.h:153
itk::Array< TInternalComputationValueType >::SizeValueType
typename vnl_vector< TInternalComputationValueType >::size_type SizeValueType
Definition: itkArray.h:55
itk::OptimizerParameters::OptimizerParameters
OptimizerParameters(const ArrayType &array)
Definition: itkOptimizerParameters.h:78
itk::Array< TInternalComputationValueType >::VnlVectorType
vnl_vector< TInternalComputationValueType > VnlVectorType
Definition: itkArray.h:54
itk::OptimizerParametersHelper
Basic helper class to manage parameter data as an Array type, the default type.
Definition: itkOptimizerParametersHelper.h:34
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::OptimizerParameters::operator=
const Self & operator=(const VnlVectorType &rhs)
Definition: itkOptimizerParameters.h:171
itk::OptimizerParameters::OptimizerParameters
OptimizerParameters(SizeValueType dimension)
Definition: itkOptimizerParameters.h:73
itkArray.h
itk::Array< TInternalComputationValueType >::ValueType
TInternalComputationValueType ValueType
Definition: itkArray.h:52
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Array
Array class with size defined at construction time.
Definition: itkArray.h:47
itk::OptimizerParameters::OptimizerParameters
OptimizerParameters(const OptimizerParameters &rhs)
Definition: itkOptimizerParameters.h:60
itk::OptimizerParameters::Initialize
void Initialize()
Definition: itkOptimizerParameters.h:89
itk::OptimizerParameters::GetHelper
OptimizerParametersHelperType * GetHelper()
Definition: itkOptimizerParameters.h:142
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83