This file is indexed.

/usr/include/ITK-4.5/itkConstantVelocityFieldTransform.hxx is in libinsighttoolkit4-dev 4.5.0-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
/*=========================================================================
 *
 *  Copyright Insight Software Consortium
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/
#ifndef __itkConstantVelocityFieldTransform_hxx
#define __itkConstantVelocityFieldTransform_hxx

#include "itkConstantVelocityFieldTransform.h"

#include "itkExponentialDisplacementFieldImageFilter.h"
#include "itkImageRegionConstIterator.h"
#include "itkImageRegionIterator.h"
#include "itkVectorLinearInterpolateImageFunction.h"

namespace itk
{

/**
 * Constructor
 */
template <typename TScalar, unsigned int NDimensions>
ConstantVelocityFieldTransform<TScalar, NDimensions>
::ConstantVelocityFieldTransform() :
  m_ConstantVelocityField( NULL ),
  m_CalculateNumberOfIntegrationStepsAutomatically( false ),
  m_ConstantVelocityFieldSetTime( 0 )
{
  this->m_FixedParameters.SetSize( ConstantVelocityFieldDimension * ( ConstantVelocityFieldDimension + 3 ) );
  this->m_FixedParameters.Fill( 0.0 );

  this->m_LowerTimeBound = 0.0;
  this->m_UpperTimeBound = 1.0;

  this->m_NumberOfIntegrationSteps = 10;

  // Setup and assign default interpolator
  typedef VectorLinearInterpolateImageFunction<ConstantVelocityFieldType, ScalarType> DefaultInterpolatorType;
  typename DefaultInterpolatorType::Pointer interpolator = DefaultInterpolatorType::New();
  this->m_ConstantVelocityFieldInterpolator = interpolator;

  // Setup and assign parameter helper. This will hold the displacement field
  // for access through the common OptimizerParameters interface.
  OptimizerParametersHelperType* helper = new OptimizerParametersHelperType;
  // After assigning this, this->m_Parameter will manage this,
  // deleting when appropriate.
  this->m_Parameters.SetHelper( helper );
}

/**
 * Destructor
 */
template <typename TScalar, unsigned int NDimensions>
ConstantVelocityFieldTransform<TScalar, NDimensions>::
~ConstantVelocityFieldTransform()
{
}

template <typename TScalar, unsigned int NDimensions>
void
ConstantVelocityFieldTransform<TScalar, NDimensions>
::UpdateTransformParameters( const DerivativeType & update, ScalarType factor)
{
  // This simply adds the values.
  // TODO: This should be multi-threaded probably, via image add filter.
  Superclass::UpdateTransformParameters( update, factor );

  this->IntegrateVelocityField();
}

/**
 * return an inverse transformation
 */
template<typename TScalar, unsigned int NDimensions>
bool
ConstantVelocityFieldTransform<TScalar, NDimensions>
::GetInverse( Self *inverse ) const
{
  if ( !inverse || !this->m_ConstantVelocityField )
    {
    return false;
    }
  else
    {
    inverse->SetUpperTimeBound( this->GetLowerTimeBound() );
    inverse->SetLowerTimeBound( this->GetUpperTimeBound() );
    inverse->SetDisplacementField( this->m_InverseDisplacementField );
    inverse->SetInverseDisplacementField( this->m_DisplacementField );
    inverse->SetInterpolator( this->m_Interpolator );
    inverse->SetConstantVelocityField( this->m_ConstantVelocityField );
    inverse->SetConstantVelocityFieldInterpolator( this->m_ConstantVelocityFieldInterpolator );
    return true;
    }
}

// Return an inverse of this transform
template<typename TScalar, unsigned int NDimensions>
typename ConstantVelocityFieldTransform<TScalar, NDimensions>::InverseTransformBasePointer
ConstantVelocityFieldTransform<TScalar, NDimensions>
::GetInverseTransform() const
{
  Pointer inverseTransform = New();
  if( this->GetInverse( inverseTransform ) )
    {
    return inverseTransform.GetPointer();
    }
  else
    {
    return NULL;
    }
}

template <typename TScalar, unsigned int NDimensions>
void ConstantVelocityFieldTransform<TScalar, NDimensions>
::SetConstantVelocityField( ConstantVelocityFieldType* field )
{
  itkDebugMacro( "setting VelocityField to " << field );
  if( this->m_ConstantVelocityField != field )
    {
    this->m_ConstantVelocityField = field;

    this->Modified();
    /* Store this separately for use in smoothing because we only want
     * to know when the displacement field object has changed, not just
     * its contents. */
    this->m_ConstantVelocityFieldSetTime = this->GetMTime();
    if( !this->m_ConstantVelocityFieldInterpolator.IsNull() )
      {
      this->m_ConstantVelocityFieldInterpolator->SetInputImage( this->m_ConstantVelocityField );
      }
    // Assign to parameters object
    this->m_Parameters.SetParametersObject( this->m_ConstantVelocityField );
    }
  this->SetFixedParametersFromConstantVelocityField();
}

template <typename TScalar, unsigned int NDimensions>
void
ConstantVelocityFieldTransform<TScalar, NDimensions>
::SetConstantVelocityFieldInterpolator( ConstantVelocityFieldInterpolatorType* interpolator )
{
  itkDebugMacro( "setting ConstantVelocityFieldInterpolator to " << interpolator );
  if( this->m_ConstantVelocityFieldInterpolator != interpolator )
    {
    this->m_ConstantVelocityFieldInterpolator = interpolator;
    this->Modified();
    if( !this->m_ConstantVelocityField.IsNull() )
      {
      this->m_ConstantVelocityFieldInterpolator->SetInputImage( this->m_ConstantVelocityField );
      }
    }
}

template <typename TScalar, unsigned int NDimensions>
void
ConstantVelocityFieldTransform<TScalar, NDimensions>
::SetFixedParameters( const ParametersType & fixedParameters )
{
  if( fixedParameters.Size() != ConstantVelocityFieldDimension * ( ConstantVelocityFieldDimension + 3 ) )
    {
    itkExceptionMacro( "The fixed parameters are not the right size." );
    }

  SizeType size;
  for( unsigned int d = 0; d < ConstantVelocityFieldDimension; d++ )
    {
    size[d] = static_cast<SizeValueType>( fixedParameters[d] );
    }

  PointType origin;
  for( unsigned int d = 0; d < ConstantVelocityFieldDimension; d++ )
    {
    origin[d] = fixedParameters[d + ConstantVelocityFieldDimension];
    }

  SpacingType spacing;
  for( unsigned int d = 0; d < ConstantVelocityFieldDimension; d++ )
    {
    spacing[d] = fixedParameters[d + 2 * ConstantVelocityFieldDimension];
    }

  DirectionType direction;
  for( unsigned int di = 0; di < ConstantVelocityFieldDimension; di++ )
    {
    for( unsigned int dj = 0; dj < ConstantVelocityFieldDimension; dj++ )
      {
      direction[di][dj] = fixedParameters[3 * ConstantVelocityFieldDimension + ( di * ConstantVelocityFieldDimension + dj )];
      }
    }

  PixelType zeroDisplacement;
  zeroDisplacement.Fill( 0.0 );

  typename ConstantVelocityFieldType::Pointer velocityField = ConstantVelocityFieldType::New();
  velocityField->SetSpacing( spacing );
  velocityField->SetOrigin( origin );
  velocityField->SetDirection( direction );
  velocityField->SetRegions( size );
  velocityField->Allocate();
  velocityField->FillBuffer( zeroDisplacement );

  this->SetConstantVelocityField( velocityField );
}

template <typename TScalar, unsigned int NDimensions>
void
ConstantVelocityFieldTransform<TScalar, NDimensions>
::SetFixedParametersFromConstantVelocityField() const
  {
  this->m_FixedParameters.SetSize( ConstantVelocityFieldDimension * ( ConstantVelocityFieldDimension + 3 ) );

  const typename ConstantVelocityFieldType::RegionType & fieldRegion =
    this->m_ConstantVelocityField->GetLargestPossibleRegion();

  // Set the field size parameters
  SizeType fieldSize = fieldRegion.GetSize();
  for( unsigned int i = 0; i < ConstantVelocityFieldDimension; i++ )
    {
    this->m_FixedParameters[i] = static_cast<ParametersValueType>( fieldSize[i] );
    }

  // Set the origin parameters
  PointType fieldOrigin = this->m_ConstantVelocityField->GetOrigin();
  for( unsigned int i = 0; i < ConstantVelocityFieldDimension; i++ )
    {
    this->m_FixedParameters[ConstantVelocityFieldDimension + i] = fieldOrigin[i];
    }

  // Set the spacing parameters
  SpacingType fieldSpacing = this->m_ConstantVelocityField->GetSpacing();
  for( unsigned int i = 0; i < ConstantVelocityFieldDimension; i++ )
    {
    this->m_FixedParameters[2 * ConstantVelocityFieldDimension + i] = static_cast<ParametersValueType>( fieldSpacing[i] );
    }

  // Set the direction parameters
  DirectionType fieldDirection = this->m_ConstantVelocityField->GetDirection();
  for( unsigned int di = 0; di < ConstantVelocityFieldDimension; di++ )
    {
    for( unsigned int dj = 0; dj < ConstantVelocityFieldDimension; dj++ )
      {
      this->m_FixedParameters[3 * ConstantVelocityFieldDimension + ( di * ConstantVelocityFieldDimension + dj )] =
        static_cast<ParametersValueType>( fieldDirection[di][dj] );
      }
    }
}

template<typename TScalar, unsigned int NDimensions>
void
ConstantVelocityFieldTransform<TScalar, NDimensions>
::IntegrateVelocityField()
{
  typedef ExponentialDisplacementFieldImageFilter<ConstantVelocityFieldType, ConstantVelocityFieldType>
    ExponentiatorType;

  ConstantVelocityFieldPointer constantVelocityField = this->GetModifiableConstantVelocityField();

  typename ExponentiatorType::Pointer exponentiator = ExponentiatorType::New();
  exponentiator->SetInput( constantVelocityField );
  if( this->m_CalculateNumberOfIntegrationStepsAutomatically || this->GetNumberOfIntegrationSteps() == 0 )
    {
    exponentiator->SetAutomaticNumberOfIterations( true );
    if( !this->m_CalculateNumberOfIntegrationStepsAutomatically && this->m_NumberOfIntegrationSteps == 0 )
      {
      itkWarningMacro( "Number of integration steps is 0.  Calculating the number of integration steps automatically." );
      }
    }
  else
    {
    exponentiator->SetAutomaticNumberOfIterations( false );
    exponentiator->SetMaximumNumberOfIterations( this->GetNumberOfIntegrationSteps() );
    }
  exponentiator->SetComputeInverse( false );
  exponentiator->Update();

  // Calculate inverse displacement field

  typename ExponentiatorType::Pointer exponentiatorInv = ExponentiatorType::New();
  exponentiatorInv->SetInput( constantVelocityField );
  if( this->m_CalculateNumberOfIntegrationStepsAutomatically || this->m_NumberOfIntegrationSteps == 0 )
    {
    exponentiatorInv->SetAutomaticNumberOfIterations( true );
    if( !this->m_CalculateNumberOfIntegrationStepsAutomatically && this->m_NumberOfIntegrationSteps == 0 )
      {
      itkWarningMacro( "Number of integration steps is 0.  Calculating the number of integration steps automatically." );
      }
    }
  else
    {
    exponentiatorInv->SetAutomaticNumberOfIterations( false );
    exponentiatorInv->SetMaximumNumberOfIterations( this->GetNumberOfIntegrationSteps() );
    }
  exponentiatorInv->SetComputeInverse( true );
  exponentiatorInv->Update();

  // We use the lower and upper time bounds to keep track of which results should go in
  // the forward and inverse displacement fields.  This is useful when calling and tracking
  // the inverse transform where the velocity field is the same for both the forward and
  // inverse transforms but the upper and lower time bounds are switched as well as the
  // forward and inverse displacement fields.

  if( this->GetLowerTimeBound() <= this->GetUpperTimeBound() )
    {
    this->SetDisplacementField( exponentiator->GetOutput() );
    this->SetInverseDisplacementField( exponentiatorInv->GetOutput() );
    }
  else
    {
    this->SetDisplacementField( exponentiatorInv->GetOutput() );
    this->SetInverseDisplacementField( exponentiator->GetOutput() );
    }
}

template <typename TScalar, unsigned int NDimensions>
typename ConstantVelocityFieldTransform<TScalar, NDimensions>::DisplacementFieldType::Pointer
ConstantVelocityFieldTransform<TScalar, NDimensions>
::CopyDisplacementField( const DisplacementFieldType *toCopy ) const
{
  typename DisplacementFieldType::Pointer rval = DisplacementFieldType::New();
  rval->SetOrigin( toCopy->GetOrigin() );
  rval->SetSpacing( toCopy->GetSpacing() );
  rval->SetDirection( toCopy->GetDirection() );
  rval->SetRegions( toCopy->GetLargestPossibleRegion() );
  rval->Allocate();

  ImageRegionConstIterator<DisplacementFieldType> dispIt( toCopy,toCopy->GetLargestPossibleRegion() );
  ImageRegionIterator<DisplacementFieldType> cloneDispIt( rval,rval->GetLargestPossibleRegion() );
  for( dispIt.GoToBegin(), cloneDispIt.GoToBegin(); !dispIt.IsAtEnd() && !cloneDispIt.IsAtEnd();
      ++dispIt, ++cloneDispIt )
    {
    cloneDispIt.Set( dispIt.Get() );
    }
  return rval;
}

template <typename TScalar, unsigned int NDimensions>
typename LightObject::Pointer
ConstantVelocityFieldTransform<TScalar, NDimensions>
::InternalClone() const
{
  // create a new instance
  LightObject::Pointer loPtr = Superclass::InternalClone();
  typename Self::Pointer rval =
    dynamic_cast<Self *>(loPtr.GetPointer());
  if(rval.IsNull())
    {
    itkExceptionMacro(<< "downcast to type "
                      << this->GetNameOfClass()
                      << " failed.");
    }

  // set the fixed/moving parameters.
  // Not sure these do anything at all useful!
  rval->SetFixedParameters( this->GetFixedParameters() );
  rval->SetParameters( this->GetParameters() );

  // need the displacement field but GetDisplacementField is non-const.
  Self *nonConstThis = const_cast<Self *>(this);
  typename DisplacementFieldType::ConstPointer dispField = nonConstThis->GetDisplacementField();
  typename DisplacementFieldType::Pointer cloneDispField =
    this->CopyDisplacementField(dispField.GetPointer());
  rval->GetModifiableInterpolator()->SetInputImage( cloneDispField );
  rval->SetDisplacementField( cloneDispField );

  // now do the inverse -- it actually gets created as a side effect?
  typename DisplacementFieldType::ConstPointer invDispField = nonConstThis->GetInverseDisplacementField();
  typename DisplacementFieldType::Pointer cloneInvDispField = this->CopyDisplacementField( invDispField.GetPointer() );
  rval->SetInverseDisplacementField( cloneInvDispField );

  // copy the VelocityField
  // SetFixedParameters allocates the VelocityField
  ImageRegionConstIterator<ConstantVelocityFieldType>
    thisIt( this->m_ConstantVelocityField, this->m_ConstantVelocityField->GetLargestPossibleRegion() );
  ImageRegionIterator<ConstantVelocityFieldType> cloneIt( rval->m_ConstantVelocityField,
    rval->m_ConstantVelocityField->GetLargestPossibleRegion() );
  for( thisIt.GoToBegin(),cloneIt.GoToBegin(); !thisIt.IsAtEnd() && !cloneIt.IsAtEnd();
      ++thisIt, ++cloneIt )
    {
    cloneIt.Set( thisIt.Get() );
    }

  // set config parameters
  rval->SetLowerTimeBound( this->GetLowerTimeBound() );
  rval->SetUpperTimeBound( this->GetUpperTimeBound() );
  rval->SetNumberOfIntegrationSteps( this->GetNumberOfIntegrationSteps() );

  // copy the interpolator
  ConstantVelocityFieldInterpolatorPointer newInterp = dynamic_cast<ConstantVelocityFieldInterpolatorType *>
    ( this->m_ConstantVelocityFieldInterpolator->CreateAnother().GetPointer() );
  // interpolator needs to know about the velocity field
  newInterp->SetInputImage( rval->GetConstantVelocityField() );
  rval->SetConstantVelocityFieldInterpolator( newInterp );
  return loPtr;
}

template <typename TScalar, unsigned int NDimensions>
void
ConstantVelocityFieldTransform<TScalar, NDimensions>
::PrintSelf( std::ostream& os, Indent indent ) const
{
  Superclass::PrintSelf( os, indent );

  os << indent << "ConstantVelocityFieldInterpolator: " << std::endl;
  os << indent << indent << this->m_ConstantVelocityFieldInterpolator << std::endl;

  if( this->m_ConstantVelocityField )
    {
    os << indent << "Constant Velocity Field: " << std::endl;
    os << indent << indent << this->m_ConstantVelocityField << std::endl;
    }

  os << indent << "LowerTimeBound: " << this->m_LowerTimeBound << std::endl;
  os << indent << "UpperTimeBound: " << this->m_UpperTimeBound << std::endl;
  os << indent << "NumberOfIntegrationSteps: "
    << this->m_NumberOfIntegrationSteps << std::endl;
}

} // namespace itk

#endif