[Insight-developers] Re: [Insight-users] One error and one issue with itkImagePCAShapeModelEstimator

Zachary Pincus zpincus at stanford.edu
Sun, 16 May 2004 04:18:19 -0700


Feh, forgot the to do some const-casting! Silly me; here is a new 
version that has no compiler warnings. Sorry about the spam.

itkImagePCAShapeModelEstimator.txx, function 
GenerateInputRequestedRegion:

/**
  * Requires all of the inputs to have a LargestPosibleRegion and 
Spacing the of
  * same size.
  */
template<class TInputImage, class TOutputImage>
void
ImagePCAShapeModelEstimator<TInputImage,TOutputImage>
::GenerateInputRequestedRegion()
{
   Superclass::GenerateInputRequestedRegion();
   // Calling this causes problems because it sets the input requested 
regions
   // to various output requested regions, which might not overlap, 
since the inputs
   // and outputs aren't very closely linked in the PCA case.
   // If we REALLY want to call this, then some heroics are necessary to 
undo
   // the damage it does. Specifically, we will have to set all the 
inputs'
   // requested regions back to *their* LargestPossibleRegion, and not 
that of
   // some random output.
	
   if ( this->GetInput(0) )
     {

     // Get the requested region and spacing of the first input
	InputImagePointer masterInput = const_cast<TInputImage *>( 
this->GetInput(0) );
	masterInput->SetRequestedRegionToLargestPossibleRegion();
	typename TInputImage::RegionType masterRequestedRegion =
	  this->GetInput(0)->GetRequestedRegion();
     typename TInputImage::SpacingType masterSpacing =
       this->GetInput(0)->GetSpacing();

     // Set the requested region of the remaining input to their largest 
possible
     // regions, and make sure the sizes and spacings are proper.
     unsigned int idx;
     for (idx = 1; idx < this->GetNumberOfInputs(); ++idx)
       {
       if ( this->GetInput(idx) )
         {
		InputImagePointer input = const_cast<TInputImage *>( 
this->GetInput(idx) );
	    input->SetRequestedRegionToLargestPossibleRegion();
		
		typename TInputImage::RegionType requestedRegion =
           input->GetRequestedRegion();
         typename TInputImage::SpacingType spacing = input->GetSpacing();
         if( masterRequestedRegion.GetSize() != 
requestedRegion.GetSize() ||
			masterSpacing != spacing)
           {
           itkExceptionMacro("Size and spacing of input " << idx <<
             " is not the same as that of input 0" );
           }

         } // if ( this->GetIntput(idx))
       } // for idx
     } // if( this->GetInput(0) )

}