~ubuntu-branches/ubuntu/precise/insighttoolkit/precise

« back to all changes in this revision

Viewing changes to Code/Numerics/itkMultipleValuedVnlCostFunctionAdaptor.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2008-12-19 20:16:49 UTC
  • mfrom: (1.2.1 upstream) (4.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20081219201649-drt97guwl2ryt0cn

* New upstream version.
  - patches/nifti-versioning.patch: Remove.  Applied upstream.
  - control:
  - rules: Update version numbers, package names.

* control: Build-depend on uuid-dev (gdcm uses it).

* copyright: Update download URL.

* rules: Adhere to parallel=N in DEB_BUILD_OPTIONS by setting MAKEFLAGS.

* compat: Set to 7.
* control: Update build-dep on debhelper to version >= 7.

* CMakeCache.txt.debian: Set CMAKE_BUILD_TYPE to "RELEASE" so that we
  build with -O3 (not -O2), necessary to optimize the templated code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
  Program:   Insight Segmentation & Registration Toolkit
4
4
  Module:    $RCSfile: itkMultipleValuedVnlCostFunctionAdaptor.cxx,v $
5
5
  Language:  C++
6
 
  Date:      $Date: 2007-03-22 21:39:37 $
7
 
  Version:   $Revision: 1.13 $
 
6
  Date:      $Date: 2008-05-20 13:50:31 $
 
7
  Version:   $Revision: 1.14 $
8
8
 
9
9
  Copyright (c) Insight Software Consortium. All rights reserved.
10
10
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
28
28
  unsigned int spaceDimension, unsigned int numberOfValues ):
29
29
  vnl_least_squares_function(spaceDimension,numberOfValues) 
30
30
31
 
  m_ScalesInitialized =false;
32
 
  m_Reporter = Object::New();
 
31
  this->m_ScalesInitialized =false;
 
32
  this->m_Reporter = Object::New();
33
33
}
34
34
 
35
35
    
38
38
MultipleValuedVnlCostFunctionAdaptor
39
39
::SetScales(const ScalesType & scales)
40
40
{
41
 
  m_Scales = scales;
42
 
  m_ScalesInitialized = true;
 
41
  this->m_Scales = scales;
 
42
  this->m_ScalesInitialized = true;
43
43
}
44
44
 
45
45
/**  Delegate computation of the value to the CostFunction. */
48
48
::f( const InternalParametersType & inparameters, 
49
49
     InternalMeasureType    & measures        )
50
50
{
51
 
  if( !m_CostFunction )
 
51
  if( ! this->m_CostFunction )
52
52
    {
53
53
    ExceptionObject ex;
54
54
    ex.SetLocation(__FILE__);
58
58
 
59
59
  ParametersType parameters(inparameters.size());
60
60
  // Use scales if they are provided
61
 
  if(m_ScalesInitialized)
 
61
  if( this->m_ScalesInitialized )
62
62
    { 
63
 
    for(unsigned int i=0;i<parameters.size();i++)
 
63
    for( unsigned int i = 0; i < parameters.size(); i++ )
64
64
      {
65
 
      parameters[i] = inparameters[i]/m_Scales[i];
 
65
      parameters[i] = inparameters[i] / this->m_Scales[i];
66
66
      }
67
67
    }
68
68
  else
70
70
    parameters.SetData(const_cast<double*>(inparameters.data_block()));
71
71
    }
72
72
 
73
 
   measures = m_CostFunction->GetValue( parameters );
 
73
   measures = this->m_CostFunction->GetValue( parameters );
74
74
 
75
75
  // Notify observers. This is used for overcoming the limitaion of VNL
76
76
  // optimizers of not providing callbacks per iteration.
88
88
::gradf(  const InternalParametersType   & inparameters,
89
89
          InternalDerivativeType   & gradient       ) 
90
90
{
91
 
  if( !m_CostFunction )
 
91
  if( !this->m_CostFunction )
92
92
    {
93
93
    ExceptionObject ex;
94
94
    ex.SetLocation(__FILE__);
98
98
 
99
99
  DerivativeType externalGradient;
100
100
  ParametersType parameters(inparameters.size());
101
 
  if(m_ScalesInitialized)
 
101
  if( this->m_ScalesInitialized )
102
102
    {  
103
103
    for(unsigned int i=0;i<parameters.size();i++)
104
104
      {
105
 
      parameters[i] = inparameters[i]/m_Scales[i];
 
105
      parameters[i] = inparameters[i] / this->m_Scales[i];
106
106
      }
107
107
    }
108
108
  else
110
110
    parameters.SetData(const_cast<double*>(inparameters.data_block()));
111
111
    }
112
112
 
113
 
  m_CostFunction->GetDerivative( parameters, externalGradient ); 
114
 
  ConvertExternalToInternalGradient( externalGradient, gradient);
 
113
  this->m_CostFunction->GetDerivative( parameters, externalGradient ); 
 
114
  this->ConvertExternalToInternalGradient( externalGradient, gradient);
115
115
}
116
116
  
117
117
 
126
126
  // delegate the computation to the CostFunction
127
127
  DerivativeType externalGradient;
128
128
  ParametersType parameters(x.size());
129
 
  if(m_ScalesInitialized)
 
129
  if( this->m_ScalesInitialized )
130
130
    {
131
131
    for(unsigned int i=0;i<parameters.size();i++)
132
132
      {
133
 
      parameters[i] = x[i]/m_Scales[i];
 
133
      parameters[i] = x[i] / this->m_Scales[i];
134
134
      }
135
135
    }
136
136
  else
138
138
    parameters.SetData(const_cast<double*>(x.data_block()));
139
139
    }
140
140
 
141
 
   *ff = static_cast<InternalMeasureType>(
142
 
        m_CostFunction->GetValue( parameters ) );
143
 
  m_CostFunction->GetDerivative( parameters, externalGradient );
 
141
  *ff = static_cast<InternalMeasureType>(
 
142
        this->m_CostFunction->GetValue( parameters ) );
 
143
  this->m_CostFunction->GetDerivative( parameters, externalGradient );
144
144
 
145
 
  ConvertExternalToInternalGradient( externalGradient, *g );  
 
145
  this->ConvertExternalToInternalGradient( externalGradient, *g );  
146
146
 
147
147
  // Notify observers. This is used for overcoming the limitaion of VNL
148
148
  // optimizers of not providing callbacks per iteration.
161
161
{
162
162
  const unsigned int rows = input.rows();
163
163
  const unsigned int cols = input.cols();
 
164
 
164
165
  for( unsigned int i=0; i<rows; i++ ) 
165
166
    {
166
167
    for( unsigned int j=0; j<cols; j++ ) 
167
168
      {
168
169
      output(j,i) = input(i,j);
 
170
 
 
171
      if( this->m_ScalesInitialized )
 
172
        {
 
173
        output(j,i) /= this->m_Scales[i];
 
174
        }
 
175
 
169
176
      }
170
177
    }
171
178
}
225
232
MultipleValuedVnlCostFunctionAdaptor
226
233
::AddObserver(const EventObject & event, Command * command) const
227
234
{
228
 
  return m_Reporter->AddObserver( event, command );
 
235
  return this->m_Reporter->AddObserver( event, command );
229
236
}
230
237
 
231
238