[vtkusers] Error in writing a subclass of vtkImageAlgorithm

Mengda Wu wumengda at gmail.com
Wed Oct 21 11:52:57 EDT 2015


Hello all,

   I am trying to write a subclass of vtkImageAlgorithm to generate a 2D
image based on a reslice of a 3D image. When I execute it, it was fine with
vtk 6.1 but it has some problems with vtk 6.2. I don't know what has
changed. I think it might be related to RequestInformation.

The errors are:

ERROR: In
D:\Library\VTK\VTK-6.2.0\Common\ExecutionModel\vtkStreamingDemandDrivenPipeline.cxx,
line 857
vtkStreamingDemandDrivenPipeline (0000000010C8E3F0): The update extent
specified in the information for output port 0 on algorithm
vtkTrivialProducer(00000000111F6860) is 0 40 0 201 0 0, which is outside
the whole extent 0 40 0 40 0 0.

ERROR: In
D:\Library\VTK\VTK-6.2.0\Common\ExecutionModel\vtkTrivialProducer.cxx, line
279
vtkTrivialProducer (00000000111F6860): This data object does not contain
the requested extent.

Here is my code:

ImageCurvedReformat::ImageCurvedReformat( )
{
this->SegmentId  = -1;
this->TwistIndex = 0;

this->RadialSpacing  = 0.5;
this->RadialExtent   = 20;

this->UpdateImage = 1;

this->SetNumberOfInputPorts( 2 );
this->SetNumberOfOutputPorts( 6 );

// by default process active point scalars
this->SetInputArrayToProcess(0,0,0,vtkDataObject::FIELD_ASSOCIATION_POINTS,
vtkDataSetAttributes::SCALARS);
}

ImageCurvedReformat::~ImageCurvedReformat( )
{
}

void ImageCurvedReformat::SetUpdateImage(int update)
{
if(this->UpdateImage != update) this->UpdateImage = update;
//Don't set the modiflied flag on purpose
}

vtkImageData* ImageCurvedReformat::GetOutput()
{
return vtkImageData::SafeDownCast(this->GetOutput(0));
}

vtkDataObject* ImageCurvedReformat::GetOutput(int port)
{
return this->GetOutputDataObject(port);
}

int ImageCurvedReformat::ProcessRequest(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA_NOT_GENERATED()))
{
if(!this->UpdateImage)
{
vtkInformation* outImageInfo = outputVector->GetInformationObject(0);
outImageInfo->Set(vtkDemandDrivenPipeline::DATA_NOT_GENERATED(), 1);
vtkInformation* outImagePolyInfo = outputVector->GetInformationObject(5);
outImagePolyInfo->Set(vtkDemandDrivenPipeline::DATA_NOT_GENERATED(), 1);
}
}

// generate the data
if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
{
return this->RequestData(request, inputVector, outputVector);
}

// execute information
if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
{
return this->RequestInformation(request, inputVector, outputVector);
}

// propagate update extent
/*
if(request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT()))
{
return this->RequestUpdateExtent(request, inputVector, outputVector);
}
*/

return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}

//---------------------------------------------------------------------------
int ImageCurvedReformat::FillInputPortInformation(int port, vtkInformation
*info)
{
if( port == 0 )
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkImageData");
else if( port == 1 )
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData");

return 1;
}

//----------------------------------------------------------------------------
int ImageCurvedReformat::FillOutputPortInformation(
int port, vtkInformation* info)
{
if( port == 0 )
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkImageData");
else if ( port < 6 )
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkPolyData");
return 1;
}

int ImageCurvedReformat::RequestInformation (
vtkInformation * request,
vtkInformationVector** inputVector,
vtkInformationVector *outputVector)
{
vtkInformation *inCenterlineInfo = inputVector[1]->GetInformationObject(0);
vtkInformation *outImageInfo = outputVector->GetInformationObject(0);

vtkPolyData   *inputCenterline  =
vtkPolyData::SafeDownCast(inCenterlineInfo->Get(vtkDataObject::DATA_OBJECT()));

if( SegmentId >= 0 && SegmentId < inputCenterline->GetNumberOfCells() )
{
vtkIdType npts=0, *pts=NULL;
int RadialSize = 2*this->RadialExtent+1;
inputCenterline->BuildCells();
inputCenterline->GetCellPoints(SegmentId, npts, pts);
int outWholeExt[6] = {0, RadialSize-1, 0, npts-1, 0, 0};
outImageInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),outWholeExt,6);
}
else
{
int outWholeExt[6] = {0, 0, 0, 0, 0, 0};
outImageInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),outWholeExt,6);
}
double outOrigin[3] = {0.0, 0.0, 0.0};
outImageInfo->Set(vtkDataObject::ORIGIN(), outOrigin, 3);

return Superclass::RequestInformation(request, inputVector, outputVector);
}

int ImageCurvedReformat::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{

//Do some work to do image reformat.
}

   Can you help?

Thanks,
Mengda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151021/69f95bc7/attachment.html>


More information about the vtkusers mailing list