Imaging/vtkImageReslice.cxx
vtkMatrix4x4 *vtkImageReslice::GetIndexMatrix(vtkInformation *inInfo,
                                              vtkInformation *outInfo)
{
  // first verify that we have to update the matrix
  if (this->IndexMatrix == NULL)
    {
    this->IndexMatrix = vtkMatrix4x4::New();
    }

  int isIdentity = 0;
  double inOrigin[3];
  double inSpacing[3];
  double outOrigin[3];
  double outSpacing[3];

  inInfo->Get(vtkDataObject::SPACING(), inSpacing);
  inInfo->Get(vtkDataObject::ORIGIN(), inOrigin);
  outInfo->Get(vtkDataObject::SPACING(), outSpacing);
  outInfo->Get(vtkDataObject::ORIGIN(), outOrigin);

  vtkTransform *transform = vtkTransform::New();
  vtkMatrix4x4 *inMatrix = vtkMatrix4x4::New();
  vtkMatrix4x4 *outMatrix = vtkMatrix4x4::New();

  if (this->OptimizedTransform)
    {
    this->OptimizedTransform->Delete();
    }
  this->OptimizedTransform = NULL;

  if (this->ResliceAxes)
    {
    transform->SetMatrix(this->GetResliceAxes());
    }
  if (this->ResliceTransform)
    {
    if (this->ResliceTransform->IsA("vtkHomogeneousTransform"))
      {
      transform->PostMultiply();
      transform->Concatenate(
        static_cast<vtkHomogeneousTransform *>(this->ResliceTransform)->GetMatrix());
      }
    else
      {
      this->ResliceTransform->Register(this);
      this->OptimizedTransform = this->ResliceTransform;
      }
    }
  
  // check to see if we have an identity matrix
  isIdentity = vtkIsIdentityMatrix(transform->GetMatrix());

  // the outMatrix takes OutputData indices to OutputData coordinates,
  // the inMatrix takes InputData coordinates to InputData indices
  for (int i = 0; i < 3; i++) 
    {
    if ((this->OptimizedTransform == NULL && 
         (inSpacing[i] != outSpacing[i] || inOrigin[i] != outOrigin[i])) ||
        (this->OptimizedTransform != NULL &&
         (outSpacing[i] != 1.0 || outOrigin[i] != 0.0)))
      {
      isIdentity = 0;
      }
    inMatrix->Element[i][i] = 1.0/inSpacing[i];
    inMatrix->Element[i][3] = -inOrigin[i]/inSpacing[i];
    outMatrix->Element[i][i] = outSpacing[i];
    outMatrix->Element[i][3] = outOrigin[i];
    }
  outInfo->Get(vtkDataObject::ORIGIN(), outOrigin);

  if (!isIdentity)
    {
    transform->PreMultiply();
    transform->Concatenate(outMatrix);
    if (this->OptimizedTransform == NULL)
      {
      transform->PostMultiply();
      transform->Concatenate(inMatrix);
      }
    }

  transform->GetMatrix(this->IndexMatrix);
  
  transform->Delete();
  inMatrix->Delete();
  outMatrix->Delete();

  return this->IndexMatrix;
}
//----------------------------------------------------------------------------
// The transform matrix supplied by the user converts output coordinates
// to input coordinates.  
// To speed up the pixel lookup, the following function provides a
// matrix which converts output pixel indices to input pixel indices.
//
// This will also concatenate the ResliceAxes and the ResliceTransform
// if possible (if the ResliceTransform is a 4x4 matrix transform).
// If it does, this->OptimizedTransform will be set to NULL, otherwise
// this->OptimizedTransform will be equal to this->ResliceTransform.
The transform matrix supplied by the user converts output coordinates
to input coordinates.
To speed up the pixel lookup, the following function provides a
matrix which converts output pixel indices to input pixel indices.

This will also concatenate the ResliceAxes and the ResliceTransform
if possible (if the ResliceTransform is a 4x4 matrix transform).
If it does, this->OptimizedTransform will be set to NULL, otherwise
this->OptimizedTransform will be equal to this->ResliceTransform.
The transform matrix supplied by the user converts output coordinates to input coordinates . To speed up the pixel lookup the following function provides a matrix which converts output pixel indices to input pixel indices . This will also concatenate the ResliceAxes and the ResliceTransform if possible ( if the ResliceTransform is a 4x4 matrix transform ) . If it does this - > OptimizedTransform will be set to NULL otherwise this - > OptimizedTransform will be equal to this - > ResliceTransform .
vtkMatrix4x4 *vtkImageReslice::GetIndexMatrix(vtkInformation *inInfo,
                                              vtkInformation *outInfo)
{
  if (this->IndexMatrix == NULL)
    {
    this->IndexMatrix = vtkMatrix4x4::New();
    }
  int isIdentity = 0;
  double inOrigin[3];
  double inSpacing[3];
  double outOrigin[3];
  double outSpacing[3];
  inInfo->Get(vtkDataObject::SPACING(), inSpacing);
  inInfo->Get(vtkDataObject::ORIGIN(), inOrigin);
  outInfo->Get(vtkDataObject::SPACING(), outSpacing);
  outInfo->Get(vtkDataObject::ORIGIN(), outOrigin);
  vtkTransform *transform = vtkTransform::New();
  vtkMatrix4x4 *inMatrix = vtkMatrix4x4::New();
  vtkMatrix4x4 *outMatrix = vtkMatrix4x4::New();
  if (this->OptimizedTransform)
    {
    this->OptimizedTransform->Delete();
    }
  this->OptimizedTransform = NULL;
  if (this->ResliceAxes)
    {
    transform->SetMatrix(this->GetResliceAxes());
    }
  if (this->ResliceTransform)
    {
    if (this->ResliceTransform->IsA("vtkHomogeneousTransform"))
      {
      transform->PostMultiply();
      transform->Concatenate(
        static_cast<vtkHomogeneousTransform *>(this->ResliceTransform)->GetMatrix());
      }
    else
      {
      this->ResliceTransform->Register(this);
      this->OptimizedTransform = this->ResliceTransform;
      }
    }
  isIdentity = vtkIsIdentityMatrix(transform->GetMatrix());
  for (int i = 0; i < 3; i++) 
    {
    if ((this->OptimizedTransform == NULL && 
         (inSpacing[i] != outSpacing[i] || inOrigin[i] != outOrigin[i])) ||
        (this->OptimizedTransform != NULL &&
         (outSpacing[i] != 1.0 || outOrigin[i] != 0.0)))
      {
      isIdentity = 0;
      }
    inMatrix->Element[i][i] = 1.0/inSpacing[i];
    inMatrix->Element[i][3] = -inOrigin[i]/inSpacing[i];
    outMatrix->Element[i][i] = outSpacing[i];
    outMatrix->Element[i][3] = outOrigin[i];
    }
  outInfo->Get(vtkDataObject::ORIGIN(), outOrigin);
  if (!isIdentity)
    {
    transform->PreMultiply();
    transform->Concatenate(outMatrix);
    if (this->OptimizedTransform == NULL)
      {
      transform->PostMultiply();
      transform->Concatenate(inMatrix);
      }
    }
  transform->GetMatrix(this->IndexMatrix);
  transform->Delete();
  inMatrix->Delete();
  outMatrix->Delete();
  return this->IndexMatrix;
}
vtkMatrix4x4 * vtkImageReslice :: GetIndexMatrix ( vtkInformation * inInfo , vtkInformation * outInfo ) { if ( this -> IndexMatrix == NULL ) { this -> IndexMatrix = vtkMatrix4x4 :: New ( ) ; } int isIdentity = 0 ; double inOrigin [ 3 ] ; double inSpacing [ 3 ] ; double outOrigin [ 3 ] ; double outSpacing [ 3 ] ; inInfo -> Get ( vtkDataObject :: SPACING ( ) , inSpacing ) ; inInfo -> Get ( vtkDataObject :: ORIGIN ( ) , inOrigin ) ; outInfo -> Get ( vtkDataObject :: SPACING ( ) , outSpacing ) ; outInfo -> Get ( vtkDataObject :: ORIGIN ( ) , outOrigin ) ; vtkTransform * transform = vtkTransform :: New ( ) ; vtkMatrix4x4 * inMatrix = vtkMatrix4x4 :: New ( ) ; vtkMatrix4x4 * outMatrix = vtkMatrix4x4 :: New ( ) ; if ( this -> OptimizedTransform ) { this -> OptimizedTransform -> Delete ( ) ; } this -> OptimizedTransform = NULL ; if ( this -> ResliceAxes ) { transform -> SetMatrix ( this -> GetResliceAxes ( ) ) ; } if ( this -> ResliceTransform ) { if ( this -> ResliceTransform -> IsA ( " " ) ) { transform -> PostMultiply ( ) ; transform -> Concatenate ( static_cast < vtkHomogeneousTransform * > ( this -> ResliceTransform ) -> GetMatrix ( ) ) ; } else { this -> ResliceTransform -> Register ( this ) ; this -> OptimizedTransform = this -> ResliceTransform ; } } isIdentity = vtkIsIdentityMatrix ( transform -> GetMatrix ( ) ) ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( ( this -> OptimizedTransform == NULL && ( inSpacing [ i ] != outSpacing [ i ] || inOrigin [ i ] != outOrigin [ i ] ) ) || ( this -> OptimizedTransform != NULL && ( outSpacing [ i ] != 1.0 || outOrigin [ i ] != 0.0 ) ) ) { isIdentity = 0 ; } inMatrix -> Element [ i ] [ i ] = 1.0 / inSpacing [ i ] ; inMatrix -> Element [ i ] [ 3 ] = - inOrigin [ i ] / inSpacing [ i ] ; outMatrix -> Element [ i ] [ i ] = outSpacing [ i ] ; outMatrix -> Element [ i ] [ 3 ] = outOrigin [ i ] ; } outInfo -> Get ( vtkDataObject :: ORIGIN ( ) , outOrigin ) ; if ( ! isIdentity ) { transform -> PreMultiply ( ) ; transform -> Concatenate ( outMatrix ) ; if ( this -> OptimizedTransform == NULL ) { transform -> PostMultiply ( ) ; transform -> Concatenate ( inMatrix ) ; } } transform -> GetMatrix ( this -> IndexMatrix ) ; transform -> Delete ( ) ; inMatrix -> Delete ( ) ; outMatrix -> Delete ( ) ; return this -> IndexMatrix ; }
The transform matrix supplied by the user converts output coordinates
to input coordinates.
The transform matrix supplied by the user converts output coordinates to input coordinates .
// first verify that we have to update the matrix // check to see if we have an identity matrix // the outMatrix takes OutputData indices to OutputData coordinates, // the inMatrix takes InputData coordinates to InputData indices