Deformetrica

AtlasFunctionalValues.h
1 /***************************************************************************************
2 * *
3 * Deformetrica *
4 * *
5 * Copyright Inria and the University of Utah. All rights reserved. This file is *
6 * distributed under the terms of the Inria Non-Commercial License Agreement. *
7 * *
8 * *
9 ****************************************************************************************/
10 
11 #ifndef _AtlasFunctionalValues_h
12 #define _AtlasFunctionalValues_h
13 
14 #include <vector>
15 #include <vnl/vnl_vector.h>
16 
17 
38 template <class TScalar>
40 {
41 
42 public:
43 
45  // typedef :
47 
49  typedef std::vector<TScalar> VectorType;
50 
51 
52 
54  // Constructor(s) / Destructor :
56 
59  AtlasFunctionalValues(int nobj, int nsubj)
60  {
61  m_NumberOfObjects = nobj;
62  m_NumberOfSubjects = nsubj;
63 
65  for (int s = 0; s < m_NumberOfSubjects; s++)
66  m_DataTerm[s].resize(m_NumberOfObjects,0.0);
67 
68  m_Regularity.resize(m_NumberOfSubjects, 0.0);
69  m_Sparsity.resize(m_NumberOfSubjects, 0.0);
70 
71  m_DataTermPerObject.resize(m_NumberOfObjects, vnl_huge_val(1.0));
72  m_TotalDataTerm = vnl_huge_val(1.0);
73  m_TotalRegularity = vnl_huge_val(1.0);
74  m_TotalSparsity = vnl_huge_val(1.0);
75  m_TotalValue = vnl_huge_val(1.0);
76  m_TotalL2Value = vnl_huge_val(1.0);
77 
78  m_OutOfBox = false;
79  }
80 
83  {
86 
87  m_DataTerm = other.m_DataTerm;
88  m_Regularity = other.m_Regularity;
89  m_Sparsity = other.m_Sparsity;
90 
91  m_OutOfBox = other.m_OutOfBox;
92 
97  m_TotalValue = other.m_TotalValue;
99  }
100 
103 
105 
106 
107 
109  // Encapsulation method(s) :
111 
113  inline std::vector< VectorType > GetDataTerm() { return m_DataTerm; }
115  inline void SetDataTerm(VectorType dt, int s) { m_DataTerm[s] = dt; }
117  inline void SetDataTerm(TScalar r, int s, int i) { m_DataTerm[s][i] = r; }
118 
120  inline void SetRegularity(TScalar r, int s) { m_Regularity[s] = r; }
121 
123  inline void SetSparsity(TScalar r, int s) { m_Sparsity[s] = r; }
124 
126  inline bool IsOutOfBox() { return m_OutOfBox; }
128  inline void SetOutOfBox() { m_OutOfBox = true; }
129 
133  inline TScalar GetTotalDataTerm() { return m_TotalDataTerm; }
134 
136  inline TScalar GetTotalRegularity() { return m_TotalRegularity; }
137 
139  inline TScalar GetTotalSparsity() { return m_TotalSparsity; }
140 
142  inline TScalar GetTotalValue() { return m_TotalValue; }
143 
145  inline TScalar GetTotalL2Value() { return m_TotalL2Value; }
146 
147 
148 
150  // Other method(s) :
152 
154  void Update()
155  {
156  if (m_OutOfBox)
157  return;
158 
159 
161  m_TotalDataTerm = 0.0;
162  for (int i = 0; i < m_NumberOfObjects; i++)
163  {
164  TScalar val = 0.0;
165  for (int s = 0; s < m_NumberOfSubjects; s++)
166  val += m_DataTerm[s][i];
167 
168  val /= m_NumberOfSubjects;
169  m_DataTermPerObject[i] = val;
170  m_TotalDataTerm += val;
171  }
172 
173  m_TotalRegularity = 0.0;
174  m_TotalSparsity = 0.0;
175  for (int s = 0; s < m_NumberOfSubjects; s++)
176  {
179  }
182 
185  }
186 
188  void PrintIter(const int iter)
189  {
190  std::cout << "Iter " << iter << " >> Objective = " << m_TotalValue <<
191  "\t(Data Term = " << m_TotalDataTerm <<
192  "\tRegularity = " << m_TotalRegularity <<
193  "\tSparsityPrior = " << m_TotalSparsity <<
194  ")" << std::endl;
195  }
196 
197 
198 
199 protected:
200 
202  // Attribute(s)
204 
207 
210 
213 
215  std::vector< VectorType > m_DataTerm;
216 
219 
222 
225 
228 
231 
234 
236  TScalar m_TotalValue;
237 
239  TScalar m_TotalL2Value;
240 
241 
242 
243 }; /* class AtlasFunctionalValues */
244 
245 
246 #endif /* _AtlasFunctionalValues_h */
std::vector< TScalar > VectorType
Vector type (std).
Definition: AtlasFunctionalValues.h:49
TScalar GetTotalSparsity()
Returns the total regularity term.
Definition: AtlasFunctionalValues.h:139
VectorType m_Regularity
Vector of regularity terms.
Definition: AtlasFunctionalValues.h:218
AtlasFunctionalValues(int nobj, int nsubj)
Constructor with initialization of the number of deformable objects (resp. the number of subjects) to...
Definition: AtlasFunctionalValues.h:59
TScalar m_TotalL2Value
Total value of the functional ( prior not included).
Definition: AtlasFunctionalValues.h:239
VectorType m_DataTermPerObject
Vector of fidelity-to-data terms.
Definition: AtlasFunctionalValues.h:224
TScalar m_TotalSparsity
Sum on the subjects of the priors.
Definition: AtlasFunctionalValues.h:233
AtlasFunctionalValues(const AtlasFunctionalValues &other)
Copy constructor.
Definition: AtlasFunctionalValues.h:82
std::vector< VectorType > m_DataTerm
Vector of vectors of fidelity-to-data terms.
Definition: AtlasFunctionalValues.h:215
TScalar m_TotalValue
Total value of the functional ( prior included).
Definition: AtlasFunctionalValues.h:236
int m_NumberOfObjects
Number of deformable objects.
Definition: AtlasFunctionalValues.h:206
TScalar m_TotalDataTerm
Double sum on the subjects and the deformable objects of the fidelity-to-data terms.
Definition: AtlasFunctionalValues.h:227
void SetSparsity(TScalar r, int s)
Sets the prior of the s-th subject to r.
Definition: AtlasFunctionalValues.h:123
void Update()
Updates the different total values and the fidelity-to-data term per object.
Definition: AtlasFunctionalValues.h:154
void SetDataTerm(TScalar r, int s, int i)
Sets the fidelity-to-data term of the s-th subject to r.
Definition: AtlasFunctionalValues.h:117
void SetRegularity(TScalar r, int s)
Sets the regularity term of the s-th subject to r.
Definition: AtlasFunctionalValues.h:120
void SetDataTerm(VectorType dt, int s)
Sets the fidelity-to-data terms of the s-th subject to dt.
Definition: AtlasFunctionalValues.h:115
AtlasFunctionalValues * Clone()
Make a copy of the object.
Definition: AtlasFunctionalValues.h:102
std::vector< VectorType > GetDataTerm()
Returns the whole fidelity-to-data terms.
Definition: AtlasFunctionalValues.h:113
int m_NumberOfSubjects
Number of subjects.
Definition: AtlasFunctionalValues.h:209
void PrintIter(const int iter)
Displays the different parts of the functional with an indication of iteration iter.
Definition: AtlasFunctionalValues.h:188
void SetOutOfBox()
Sets the boolean OutOfBox to true.
Definition: AtlasFunctionalValues.h:128
Values of the functional during atlas estimation.
Definition: AtlasFunctionalValues.h:39
TScalar GetTotalL2Value()
Returns the value of the functional without the prior.
Definition: AtlasFunctionalValues.h:145
VectorType m_Sparsity
Vector of prior terms.
Definition: AtlasFunctionalValues.h:221
VectorType GetDataTermPerObject()
Returns a vector of fidelity-to-data terms.
Definition: AtlasFunctionalValues.h:131
TScalar GetTotalDataTerm()
Returns the total fidelity-to-data term.
Definition: AtlasFunctionalValues.h:133
TScalar GetTotalRegularity()
Returns the total regularity term.
Definition: AtlasFunctionalValues.h:136
TScalar GetTotalValue()
Returns the value of the functional with the prior.
Definition: AtlasFunctionalValues.h:142
bool m_OutOfBox
See AbstractDeformations::m_OutOfBox for details.
Definition: AtlasFunctionalValues.h:212
TScalar m_TotalRegularity
Sum on the subjects of the regularity terms.
Definition: AtlasFunctionalValues.h:230
bool IsOutOfBox()
Returns true if any point of the trajectory is out of box, false otherwise.
Definition: AtlasFunctionalValues.h:126