Shapeworks Studio  2.1
Shape analysis software suite
itkPSMRegressionShapeMatrixAttribute.h
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 __itkPSMRegressionShapeMatrixAttribute_h
19 #define __itkPSMRegressionShapeMatrixAttribute_h
20 
21 #include "itkPSMShapeMatrixAttribute.h"
22 #include "itkPSMParticleSystem.h"
23 #include "vnl/vnl_vector.h"
24 
25 namespace itk
26 {
32 template <class T, unsigned int VDimension>
34  : public PSMShapeMatrixAttribute<T,VDimension>
35 {
36 public:
38  typedef T DataType;
40  typedef PSMShapeMatrixAttribute<T,VDimension> Superclass;
41  typedef SmartPointer<Self> Pointer;
42  typedef SmartPointer<const Self> ConstPointer;
43  typedef WeakPointer<const Self> ConstWeakPointer;
44 
46  itkNewMacro(Self);
47 
50 
52  virtual void UpdateMeanMatrix();
53 
55  inline vnl_vector<double> ComputeMean(double k) const
56  {
57  return m_Intercept + m_Slope * k;
58  }
59 
61  void ResizeParameters(unsigned int n);
62 
64  virtual void ResizeMeanMatrix(int rs, int cs);
65 
67  void ResizeExplanatory(unsigned int n);
68 
73  virtual void DomainAddEventCallback(Object *, const EventObject &e);
74  virtual void PositionAddEventCallback(Object *o, const EventObject &e);
75  virtual void PositionSetEventCallback(Object *o, const EventObject &e);
76 
78  virtual void PositionRemoveEventCallback(Object *, const EventObject &)
79  {
80  itkExceptionMacro("Method has not been implemented");
81  }
82 
85  void SetDomainsPerShape(int i)
86  { this->m_DomainsPerShape = i; }
87  int GetDomainsPerShape() const
88  { return this->m_DomainsPerShape; }
89 
92  void SetVariables(const std::vector<double> &v)
93  {
94  this->SetExplanatory(v);
95  }
96  void SetExplanatory(const std::vector<double> &v);
97  void SetExplanatory(unsigned int i, double q)
98  { m_Explanatory[i] = q; }
99  const vnl_vector<double> &GetVariables() const
100  { return m_Explanatory; }
101  const vnl_vector<double> &GetExplanatory() const
102  { return m_Explanatory; }
103  vnl_vector<double> &GetExplanatory()
104  { return m_Explanatory; }
105  const double &GetExplanatory(unsigned int i) const
106  { return m_Explanatory[i]; }
107  double &GetExplanatory(unsigned int i)
108  { return m_Explanatory[i]; }
109 
111  const vnl_matrix<double> &GetMeanMatrix() const
112  {
113  return m_MeanMatrix;
114  }
115  vnl_matrix<double> &GetMeanMatrix()
116  {
117  return m_MeanMatrix;
118  }
119 
121  const vnl_vector<double> &GetSlope() const
122  { return m_Slope; }
123  vnl_vector<double> &GetSlope()
124  { return m_Slope; }
125 
127  const vnl_vector<double> &GetIntercept() const
128  { return m_Intercept; }
129  vnl_vector<double> GetIntercept()
130  { return m_Intercept; }
131 
133  void SetSlope(const std::vector<double> &v);
134  void SetSlope(const vnl_vector<double> &v)
135  {
136  m_Slope = v;
137  }
138 
140  void SetIntercept(const std::vector<double> &v);
141  void SetIntercept(const vnl_vector<double> &v)
142  {
143  m_Intercept = v;
144  }
145 
148  virtual void EstimateParameters();
149 
152  virtual void Initialize();
153 
156  virtual void BeforeIteration();
157 
164  { m_RegressionInterval = i; }
165  int GetRegressionInterval() const
166  { return m_RegressionInterval; }
167 
168 protected:
170  {
171  this->m_DefinedCallbacks.DomainAddEvent = true;
172  this->m_DefinedCallbacks.PositionAddEvent = true;
173  this->m_DefinedCallbacks.PositionSetEvent = true;
174  this->m_DefinedCallbacks.PositionRemoveEvent = true;
175  m_UpdateCounter = 0;
176  m_RegressionInterval = 1;
177  }
178  virtual ~PSMRegressionShapeMatrixAttribute() {};
179 
180  void PrintSelf(std::ostream& os, Indent indent) const
181  { Superclass::PrintSelf(os,indent); }
182 
183 private:
184  PSMRegressionShapeMatrixAttribute(const Self&); //purposely not implemented
185  void operator=(const Self&); //purposely not implemented
186 
187  int m_UpdateCounter;
188  int m_RegressionInterval;
189 
190  // Parameters for the linear model
191  vnl_vector<double> m_Intercept;
192  vnl_vector<double> m_Slope;
193 
194  // The explanatory variable value for each sample (matrix column)
195  vnl_vector<double> m_Explanatory;
196 
197  // A matrix to store the mean estimated for each explanatory variable (each sample)
198  vnl_matrix<double> m_MeanMatrix;
199 };
200 
201 } // end namespace
202 
203 #ifndef ITK_MANUAL_INSTANTIATION
204 #include "itkPSMRegressionShapeMatrixAttribute.hxx"
205 #endif
206 
207 #endif
Each column describes a shape. A shape may be composed of m_DomainsPerShape domains (default 1)...
virtual void PositionRemoveEventCallback(Object *, const EventObject &)
Base class for PSMParticleSystem attribute classes.