This file is indexed.

/usr/include/ITK-4.5/itkVelocityFieldTransform.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
/*=========================================================================
 *
 *  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 __itkVelocityFieldTransform_hxx
#define __itkVelocityFieldTransform_hxx

#include "itkVelocityFieldTransform.h"

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

namespace itk
{

/**
 * Constructor
 */
template <typename TScalar, unsigned int NDimensions>
VelocityFieldTransform<TScalar, NDimensions>
::VelocityFieldTransform()
{
  this->m_FixedParameters.SetSize( VelocityFieldDimension * ( VelocityFieldDimension + 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<VelocityFieldType, ScalarType> DefaultInterpolatorType;
  typename DefaultInterpolatorType::Pointer interpolator = DefaultInterpolatorType::New();
  this->m_VelocityFieldInterpolator = 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 );

  this->m_VelocityFieldSetTime = 0;
}

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

template <typename TScalar, unsigned int NDimensions>
void
VelocityFieldTransform<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
VelocityFieldTransform<TScalar, NDimensions>
::GetInverse( Self *inverse ) const
{
  if ( !inverse || !this->m_VelocityField )
    {
    return false;
    }
  else
    {
    inverse->SetUpperTimeBound( this->m_LowerTimeBound );
    inverse->SetLowerTimeBound( this->m_UpperTimeBound );
    inverse->SetDisplacementField( this->m_InverseDisplacementField );
    inverse->SetInverseDisplacementField( this->m_DisplacementField );
    inverse->SetInterpolator( this->m_Interpolator );
    inverse->SetVelocityField( this->m_VelocityField );
    inverse->SetVelocityFieldInterpolator( this->m_VelocityFieldInterpolator );
    return true;
    }
}

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

template <typename TScalar, unsigned int NDimensions>
void VelocityFieldTransform<TScalar, NDimensions>
::SetVelocityField( VelocityFieldType* field )
{
  itkDebugMacro( "setting VelocityField to " << field );
  if( this->m_VelocityField != field )
    {
    this->m_VelocityField = 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_VelocityFieldSetTime = this->GetMTime();
    if( !this->m_VelocityFieldInterpolator.IsNull() )
      {
      this->m_VelocityFieldInterpolator->SetInputImage( this->m_VelocityField );
      }
    // Assign to parameters object
    this->m_Parameters.SetParametersObject( this->m_VelocityField );
    }
  this->SetFixedParametersFromVelocityField();
}

template <typename TScalar, unsigned int NDimensions>
void
VelocityFieldTransform<TScalar, NDimensions>
::SetVelocityFieldInterpolator( VelocityFieldInterpolatorType* interpolator )
{
  itkDebugMacro( "setting VelocityFieldInterpolator to " << interpolator );
  if( this->m_VelocityFieldInterpolator != interpolator )
    {
    this->m_VelocityFieldInterpolator = interpolator;
    this->Modified();
    if( !this->m_VelocityField.IsNull() )
      {
      this->m_VelocityFieldInterpolator->SetInputImage( this->m_VelocityField );
      }
    }
}

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

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

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

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

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

  PixelType zeroDisplacement;
  zeroDisplacement.Fill( 0.0 );

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

  this->SetVelocityField( velocityField );
}

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

  const typename VelocityFieldType::RegionType & fieldRegion =
    this->m_VelocityField->GetLargestPossibleRegion();

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

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

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

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

template <typename TScalar, unsigned int NDimensions>
typename VelocityFieldTransform<TScalar, NDimensions>::DisplacementFieldType::Pointer
VelocityFieldTransform<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
VelocityFieldTransform<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<VelocityFieldType>
    thisIt( this->m_VelocityField, this->m_VelocityField->GetLargestPossibleRegion() );
  ImageRegionIterator<VelocityFieldType> cloneIt( rval->m_VelocityField,
    rval->m_VelocityField->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
  VelocityFieldInterpolatorPointer newInterp = dynamic_cast<VelocityFieldInterpolatorType *>
    ( this->m_VelocityFieldInterpolator->CreateAnother().GetPointer() );
  // interpolator needs to know about the velocity field
  newInterp->SetInputImage( rval->GetVelocityField() );
  rval->SetVelocityFieldInterpolator( newInterp );
  return loPtr;
}

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

  std::cout << indent << "Interpolator: " << std::endl;
  std::cout << indent << indent << this->m_VelocityFieldInterpolator << std::endl;

  if( this->m_VelocityField )
    {
    std::cout << indent << "Velocity Field: " << std::endl;
    std::cout << indent << indent << this->m_VelocityField << 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