ITK  5.3.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 
87 
89  explicit OptimizerParameters(const ValueType * const inputData, const SizeValueType dimension)
90  : Array<TParametersValueType>(inputData, dimension)
91  {}
92 
93 
95  void
97  {
98  // Set the default OptimizerParametersHelper
99  this->m_Helper.reset(new OptimizerParametersHelperType);
100  }
101 
102 
108  virtual void
109  MoveDataPointer(TParametersValueType * pointer)
110  {
111  if (m_Helper == nullptr)
112  {
113  itkGenericExceptionMacro("OptimizerParameters::MoveDataPointer: "
114  "m_Helper must be set.");
115  }
116  this->m_Helper->MoveDataPointer(this, pointer);
117  }
119 
124  virtual void
126  {
127  if (m_Helper == nullptr)
128  {
129  itkGenericExceptionMacro("OptimizerParameters::SetParameterObject: "
130  "m_Helper must be set.");
131  }
132  this->m_Helper->SetParametersObject(this, object);
133  }
135 
141  virtual void
143  {
144  this->m_Helper.reset(helper);
145  }
146 
148  OptimizerParametersHelperType *
150  {
151  return m_Helper.get();
152  }
153 
159  const Self &
160  operator=(const Self & rhs)
161  {
162  // Note: there's no need to copy the OptimizerParametersHelper.
163  // Call the superclass implementation.
164  this->ArrayType::operator=(rhs);
165  return *this;
166  }
168 
169  const Self &
170  operator=(const ArrayType & rhs)
171  {
172  // Call the superclass implementation
173  this->ArrayType::operator=(rhs);
174  return *this;
175  }
176 
177  const Self &
179  {
180  // Call the superclass implementation
181  this->ArrayType::operator=(rhs);
182  return *this;
183  }
184 
185  ~OptimizerParameters() override = default;
186 
187 private:
188  std::unique_ptr<OptimizerParametersHelperType> m_Helper =
189  std::unique_ptr<OptimizerParametersHelperType>{ new OptimizerParametersHelperType };
190 };
191 
192 } // namespace itk
193 
194 #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:125
itk::OptimizerParameters::SetHelper
virtual void SetHelper(OptimizerParametersHelperType *helper)
Definition: itkOptimizerParameters.h:142
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:170
itk::OptimizerParameters::MoveDataPointer
virtual void MoveDataPointer(TParametersValueType *pointer)
Definition: itkOptimizerParameters.h:109
itk::OptimizerParameters::operator=
const Self & operator=(const Self &rhs)
Definition: itkOptimizerParameters.h:160
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:178
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:96
itk::OptimizerParameters::GetHelper
OptimizerParametersHelperType * GetHelper()
Definition: itkOptimizerParameters.h:149
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::OptimizerParameters::OptimizerParameters
OptimizerParameters(const ValueType *const inputData, const SizeValueType dimension)
Definition: itkOptimizerParameters.h:89