1 /*=========================================================================
2  *
3  *  Copyright Insight Software Consortium
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"
22 #include "itkOptimizerParametersHelper.h"
23 
24 namespace itk
25 {
26 /** \class OptimizerParameters
27  *  \brief Class to hold and manage different parameter types used during
28  *  optimization.
29  *
30  * \ingroup ITKCommon
31  */
32 
33 template<typename TParametersValueType>
34 class ITK_TEMPLATE_EXPORT OptimizerParameters : public Array<TParametersValueType>
35 {
36 public:
37 
38   /** The element type stored at each location in the Array. */
39   using ValueType = TParametersValueType;
40   using Self = OptimizerParameters;
41   using Superclass = Array<TParametersValueType>;
42   using ArrayType = Superclass;
43   using VnlVectorType = typename Superclass::VnlVectorType;
44   using SizeValueType = typename Superclass::SizeValueType;
45 
46   /** Helper class for managing different types of parameter
47    * data. */
48   using OptimizerParametersHelperType = OptimizerParametersHelper<TParametersValueType>;
49 
50   /** Default constructor. It is created with an empty array
51    *  it has to be allocated later by assignment              */
52   OptimizerParameters();
53 
54   /** Copy constructor.  Uses VNL copy construtor with correct
55    *  setting for memory management.
56    *  The vnl vector copy constructor creates new memory
57    *  no matter the setting of let array manage memory of rhs.
58    */
59   OptimizerParameters(const OptimizerParameters& rhs);
60 
61   /** Constructor with size. Size can only be changed by assignment */
62   explicit OptimizerParameters(SizeValueType  dimension);
63 
64   /** Constructor with Array assignment */
65   OptimizerParameters( const ArrayType& array );
66 
67   /** Initialize. Initialization called by constructors. */
68   void Initialize();
69 
70   /** Set a new data pointer for the parameter data, pointing it to a different
71    * memory block. The size of the new memory block must equal the current
72    * size, in elements of TParametersValueType.
73    * This call is passed to the assigned OptimizerParametersHelper.
74    * \warning Memory must be managed by caller after this call. */
75   virtual void MoveDataPointer( TParametersValueType * pointer );
76 
77   /** Set an object that holds the parameters. Used by the helper of
78    * derived classes that use an object other than itkArray to hold parameter
79    * data. The helper class must check that the object is the correct type.
80    * The call is passed to the assigned OptimizerParametersHelper. */
81   virtual void SetParametersObject( LightObject * object );
82 
83   /** Assign a helper. OptimizerParameters manages the helper once
84    *  its been assigned. The generic helper, OptimizerParametersHelper,
85    *  is set in constructor.
86    *  Classes that need a specialized helper should allocate
87    *  one themselves and assign it with this method. */
88   virtual void SetHelper( OptimizerParametersHelperType* helper );
89 
90   /** Get the helper in use. */
GetHelper()91   OptimizerParametersHelperType* GetHelper()
92     { return m_Helper; }
93 
94   /** Copy opertors
95    *
96    * TODO Determine behavior when copying from obj pointing to image parameters.
97    *  By default should copy image param data into Array portion of new object,
98    *  i.e. into data_block. Is that what we want? */
99   const Self & operator=(const Self & rhs);
100 
101   const Self & operator=(const ArrayType & rhs);
102 
103   const Self & operator=(const VnlVectorType & rhs);
104 
105   virtual ~OptimizerParameters();
106 
107 private:
108    OptimizerParametersHelperType*           m_Helper;
109 };
110 
111 }//namespace itk
112 
113 #ifndef ITK_MANUAL_INSTANTIATION
114 #include "itkOptimizerParameters.hxx"
115 #endif
116 
117 #endif
118