[Paraview-developers] ITK reader in ParaView

Joe Ping-Lin Hsiao phsiao at cs.unc.edu
Mon Mar 12 12:01:49 EDT 2012


I wrapped the ITK reader in vtkImageAlgorithm, and I can read files
without any trouble. However, I got the warning of "Cannot volume
render since no point (or cell) data available. " when I switched the
representation to volume. The information tab (attached) looks fine. I
wonder what I have missed. Here is the code in my reader:

int MyReader::RequestInformation (
    vtkInformation * vtkNotUsed(request),
    vtkInformationVector ** vtkNotUsed( inputVector ),
    vtkInformationVector *outputVector)
{
    this->GetOutput()->SetNumberOfScalarComponents(1);
    this->GetOutput()->SetScalarType(VTK_FLOAT);
    return 1;
}

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

    // get the info object
    vtkInformation *outInfo = outputVector->GetInformationObject(0);
	
    // get the ouptut
    vtkImageData *output = vtkImageData::SafeDownCast(
		outInfo->Get(vtkDataObject::DATA_OBJECT()));
	
    output->SetExtent(outInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()));
    output->AllocateScalars();
	
    if (!this->FileName)
    {
        vtkErrorMacro(<< "A FileName must be specified.");
        return 0;
    }
    if (output->GetScalarType() != VTK_FLOAT)
    {
        vtkErrorMacro("Execute: This source only outputs floats.");
	return 1;
    }

    typedef itk::RGBPixel<unsigned char>     PixelType;
    const   unsigned int        Dimension = 3;

    typedef itk::Image< PixelType, Dimension >   ImageType;
    typedef itk::ImageFileReader< ImageType >    ReaderType;
    typedef itk::ImageToVTKImageFilter< ImageType > ConnectorType;

    ReaderType::Pointer reader = ReaderType::New();
    ConnectorType::Pointer connector = ConnectorType::New();

    reader->SetFileName(FileName);
    connector->SetInput(reader->GetOutput());
    connector->Update();
    output->ShallowCopy(connector->GetOutput());
    output->GetPointData()->GetScalars()->SetName("Elevation");

    return 1;
}

Thanks,
Joe

On Mon, Mar 12, 2012 at 10:38 AM, Sebastien Jourdain
<sebastien.jourdain at kitware.com> wrote:
> I'm pretty sure, you'll need to wrap itk::ImageFileReader into a
> vtkObject class and follow VTK constraints so you can use it inside
> the XML proxy definition.
>
> Seb
>
> On Mon, Mar 12, 2012 at 10:21 AM, Joe Ping-Lin Hsiao <phsiao at cs.unc.edu> wrote:
>> Hi,
>>
>> I'd like to take advantage of itk::ImageFileReader to read Bio-Formats
>> files in ParaView, and I wonder if there is any easy way to do that.
>>
>> I have success reading Bio-Formats files in ITK examples. Then I took
>> MyPNGReader example in ParaView as a template, and replaced the string
>> "vtkPNGReader" with "itk::ImageFileReader" in the server xml. The
>> plugin loaded fine, but I got an error of "Failed to create
>> itk::ImageFileReader" when I tried to load a file.
>>
>> Does anybody know a good place to start?
>>
>> Thanks,
>> Joe
>> _______________________________________________
>> Paraview-developers mailing list
>> Paraview-developers at paraview.org
>> http://public.kitware.com/mailman/listinfo/paraview-developers
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen shot 2012-03-12 at 11.45.41 AM.png
Type: image/png
Size: 51208 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/paraview-developers/attachments/20120312/1b1929eb/attachment-0001.png>


More information about the Paraview-developers mailing list