[vtkusers] Question on designing filters
Lodron, Gerald
Gerald.Lodron at joanneum.at
Thu Aug 12 03:28:05 EDT 2010
Hi
I want to make a vtk filter which hast two input images and one output whereby the input images can have different sizes and the output has the size of the first input.
My filter is working but when the first input is bigger than the second input i get an Update Extent error (Requested region is (at least partially) outside the largest possible region).
Can anyone say me what i making wrong:
here some code snippets, it would be also great if anyone can say me how to make a better type handling than the if(dim ==3), switch(datatype) stuff:
class CFilter : public vtkImageAlgorithm
{
public:
static CFilter *New();
void PrintSelf(ostream& oStream, vtkIndent oIndent);
protected:
CFilter ();
~CFilter ();
int RequestData(vtkInformation *poRequest, vtkInformationVector** ppoInputVector, vtkInformationVector* poOutputVector);
private:
CFilter (CFilter &);
void operator=(const CFilter &);
};
CFilter ::CFilter ()
{
this->SetNumberOfInputPorts(2);
}
int
CFilter ::RequestData(vtkInformation *poRequest, vtkInformationVector** ppoInputVector, vtkInformationVector* poOutputVector)
{
vtkInformation* oInputInfo;
oInputInfo = ppoInputVector[0]->GetInformationObject(0);
vtkImageData *oInput1 = vtkImageData::SafeDownCast(oInputInfo->Get(vtkDataObject::DATA_OBJECT()));
oInputInfo = ppoInputVector[1]->GetInformationObject(0);
vtkImageData *oInput2 = vtkImageData::SafeDownCast(oInputInfo->Get(vtkDataObject::DATA_OBJECT()));
unsigned int iDim;
if((oInput1->GetDataDimension() == 3) && (oInput2->GetDataDimension() == 3))
{
iDim = 3;
}
else if ((oInput1->GetDataDimension() == 2) && (oInput2->GetDataDimension() == 2))
{
iDim = 2;
}
else
{
std::cout << "Error: This filter requires two or three dimensional data!" << std::endl;
return 0;
}
vtkInformation* oInfo = poOutputVector->GetInformationObject(0);
vtkImageData *oOutput = vtkImageData::SafeDownCast(oInfo->Get(vtkDataObject::DATA_OBJECT()));
int iScalarType = oInput1->GetScalarType();
vtkSmartPointer<vtkImageCast> oInputCaster1 = vtkImageCast::New();
oInputCaster1->ReleaseDataFlagOn();
oInputCaster1->SetInput(oInput1);
vtkSmartPointer<vtkImageCast> oInputCaster2 = vtkImageCast::New();
oInputCaster2->ReleaseDataFlagOn();
oInputCaster2->SetInput(oInput2);
vtkSmartPointer<vtkImageCast> oOutputCaster = vtkImageCast::New();
oOutputCaster->SetOutputScalarType(iScalarType);
if(iDim == 2)
{
switch(iScalarType)
{
case VTK_FLOAT:
{
typedef itk::Image<float, 2> TInputImage;
typedef itk::Image<float, 2> TOutputImage;
typedef MyITKFilter<TInputImage,TOutputImage> TFilter;
typedef itk::VTKImageToImageFilter<TInputImage> TInputConverter;
typedef itk::ImageToVTKImageFilter<TOutputImage> TOutputConverter;
oInputCaster1->SetOutputScalarTypeToFloat();
oInputCaster2->SetOutputScalarTypeToFloat();
TInputConverter::Pointer oInputConverter1 = TInputConverter::New();
oInputConverter1->ReleaseDataFlagOn();
oInputConverter1->SetInput(oInputCaster1->GetOutput());
TInputConverter::Pointer oInputConverter2 = TInputConverter::New();
oInputConverter2->ReleaseDataFlagOn();
oInputConverter2->SetInput(oInputCaster2->GetOutput());
TFilter::Pointer oFilter = TFilter::New();
oFilter->SetInput1(oInputConverter1->GetOutput());
oFilter->SetInput2(oInputConverter2->GetOutput());
oFilter->ReleaseDataFlagOn();
TOutputConverter::Pointer oOutputConverter = TOutputConverter::New();
oOutputConverter->ReleaseDataFlagOn();
oOutputConverter->SetInput(oFilter->GetOutput());
oOutputCaster->SetInput(oOutputConverter->GetOutput());
oOutputCaster->Update();
}
break;
case VTK_UNSIGNED_CHAR:
{
typedef itk::Image<unsigned char, 2> TInputImage;
typedef itk::Image<unsigned char, 2> TOutputImage;
typedef CCheckerboard<TInputImage,TOutputImage> TFilter;
typedef itk::VTKImageToImageFilter<TInputImage> TInputConverter;
typedef itk::ImageToVTKImageFilter<TOutputImage> TOutputConverter;
oInputCaster1->SetOutputScalarTypeToUnsignedChar();
oInputCaster2->SetOutputScalarTypeToUnsignedChar();
blablabla
}
//do for all cases
}
}
else if (iDim==3)
{
//do for dim = 3 and all cases
}
}
oOutput->ShallowCopy(oOutputCaster->GetOutput());
oOutputCaster->Delete();
oInputCaster1->Delete();
oInputCaster2->Delete();
return 1;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100812/f362c33f/attachment.htm>
More information about the vtkusers
mailing list