Skip to content
Snippets Groups Projects
Commit ad9da8c5 authored by Julien Michel's avatar Julien Michel
Browse files

ENH: Missing GenerateInputRequestedRegion().

parent 24225ec8
No related branches found
No related tags found
No related merge requests found
......@@ -55,13 +55,15 @@ public:
/** Some convenient typedefs. */
typedef TFunction FunctorType;
typedef TInputImage1 Input1ImageType;
typedef typename Input1ImageType::ConstPointer Input1ImagePointer;
typedef typename Input1ImageType::RegionType Input1ImageRegionType;
typedef typename Input1ImageType::PixelType Input1ImagePixelType;
typedef typename Input1ImageType::ConstPointer Input1ImageConstPointer;
typedef typename Input1ImageType::Pointer Input1ImagePointer;
typedef typename Input1ImageType::RegionType Input1ImageRegionType;
typedef typename Input1ImageType::PixelType Input1ImagePixelType;
typedef TInputImage2 Input2ImageType;
typedef typename Input2ImageType::ConstPointer Input2ImagePointer;
typedef typename Input2ImageType::RegionType Input2ImageRegionType;
typedef typename Input2ImageType::PixelType Input2ImagePixelType;
typedef typename Input2ImageType::ConstPointer Input2ImageConstPointer;
typedef typename Input2ImageType::Pointer Input2ImagePointer;
typedef typename Input2ImageType::RegionType Input2ImageRegionType;
typedef typename Input2ImageType::PixelType Input2ImagePixelType;
typedef TOutputImage OutputImageType;
typedef typename OutputImageType::Pointer OutputImagePointer;
typedef typename OutputImageType::RegionType OutputImageRegionType;
......@@ -76,6 +78,10 @@ public:
/** Connect one of the operands for pixel-wise addition */
void SetInput2( const TInputImage2 * image2);
/** Get the inputs */
const TInputImage1 * GetInput1();
const TInputImage2 * GetInput2();
/** Get the functor object. The functor is returned by reference.
* (Functors do not have to derive from itk::LightObject, so they do
* not necessarily have a reference count. So we cannot return a
......@@ -125,6 +131,11 @@ protected:
virtual void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
int threadId );
/**
* Pad the inputs requested regions by radius
*/
virtual void GenerateInputRequestedRegion(void);
RadiusSizeType m_Radius;
private:
......
......@@ -67,7 +67,109 @@ BinaryFunctorNeighborhoodImageFilter<TInputImage1,TInputImage2,TOutputImage,TFun
SetNthInput(1, const_cast<TInputImage2 *>( image2 ));
}
template <class TInputImage1, class TInputImage2,
class TOutputImage, class TFunction >
const TInputImage1 *
BinaryFunctorNeighborhoodImageFilter<TInputImage1,TInputImage2,TOutputImage,TFunction>
::GetInput1()
{
if(this->GetNumberOfInputs()<1)
{
return 0;
}
return static_cast<const TInputImage1 *>(this->itk::ProcessObject::GetInput(0));
}
template <class TInputImage1, class TInputImage2,
class TOutputImage, class TFunction >
const TInputImage2 *
BinaryFunctorNeighborhoodImageFilter<TInputImage1,TInputImage2,TOutputImage,TFunction>
::GetInput2()
{
if(this->GetNumberOfInputs()<2)
{
return 0;
}
return static_cast<const TInputImage2 *>(this->itk::ProcessObject::GetInput(1));
}
template <class TInputImage1, class TInputImage2,
class TOutputImage, class TFunction >
void
BinaryFunctorNeighborhoodImageFilter<TInputImage1,TInputImage2,TOutputImage,TFunction>
::GenerateInputRequestedRegion()
{
// call the superclass' implementation of this method
Superclass::GenerateInputRequestedRegion();
// get pointers to the input and output
Input1ImagePointer inputPtr1 =
const_cast< TInputImage1 * >( this->GetInput1());
Input2ImagePointer inputPtr2 =
const_cast< TInputImage2 * >( this->GetInput2());
typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
if ( !inputPtr1 || !inputPtr2 || !outputPtr )
{
return;
}
// get a copy of the input requested region (should equal the output
// requested region)
typename TInputImage1::RegionType inputRequestedRegion1, inputRequestedRegion2;
inputRequestedRegion1 = inputPtr1->GetRequestedRegion();
// pad the input requested region by the operator radius
inputRequestedRegion1.PadByRadius( m_Radius );
inputRequestedRegion2 = inputRequestedRegion1;
// crop the input requested region at the input's largest possible region
if ( inputRequestedRegion1.Crop(inputPtr1->GetLargestPossibleRegion()))
{
inputPtr1->SetRequestedRegion( inputRequestedRegion1 );
}
else
{
// Couldn't crop the region (requested region is outside the largest
// possible region). Throw an exception.
// store what we tried to request (prior to trying to crop)
inputPtr1->SetRequestedRegion( inputRequestedRegion1 );
// build an exception
itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
itk::OStringStream msg;
msg << this->GetNameOfClass()
<< "::GenerateInputRequestedRegion()";
e.SetLocation(msg.str().c_str());
e.SetDescription("Requested region is (at least partially) outside the largest possible region of image 1.");
e.SetDataObject(inputPtr1);
throw e;
}
if ( inputRequestedRegion2.Crop(inputPtr2->GetLargestPossibleRegion()))
{
inputPtr2->SetRequestedRegion( inputRequestedRegion2 );
}
else
{
// Couldn't crop the region (requested region is outside the largest
// possible region). Throw an exception.
// store what we tried to request (prior to trying to crop)
inputPtr2->SetRequestedRegion( inputRequestedRegion2 );
// build an exception
itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
itk::OStringStream msg;
msg << this->GetNameOfClass()
<< "::GenerateInputRequestedRegion()";
e.SetLocation(msg.str().c_str());
e.SetDescription("Requested region is (at least partially) outside the largest possible region of image 1.");
e.SetDataObject(inputPtr2);
throw e;
}
return;
}
/**
* ThreadedGenerateData Performs the neighborhood-wise operation
......@@ -86,9 +188,9 @@ BinaryFunctorNeighborhoodImageFilter<TInputImage1, TInputImage2, TOutputImage, T
// We use dynamic_cast since inputs are stored as DataObjects. The
// ImageToImageFilter::GetInput(int) always returns a pointer to a
// TInputImage1 so it cannot be used for the second input.
Input1ImagePointer inputPtr1
Input1ImageConstPointer inputPtr1
= dynamic_cast<const TInputImage1*>(ProcessObjectType::GetInput(0));
Input2ImagePointer inputPtr2
Input2ImageConstPointer inputPtr2
= dynamic_cast<const TInputImage2*>(ProcessObjectType::GetInput(1));
OutputImagePointer outputPtr = this->GetOutput(0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment