[Paraview] How to add scalar data in a custom reader?

shenyanwen shenyanwen at gmail.com
Thu Mar 26 10:27:55 EDT 2009


Hi, everyone!
I am writing a custom reader to read my own file which VTK does not support!
The output type of my file is vtkImageData, and each point has 3~5 type of
scalar. Now I have written
the reader like below, I just do not know how to add the scalar value to the
output object! Please check my code and point what's wrong with my code!
1. set the extent using WHOLE_EXTENT in RequestInformation() like below:

       outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),
                 0,dim[0]-1,0,dim[1]-1,0,dim[2]-1);

2.set the origin and the extent and spacing in RequestData() like below:

   vtkInformation *outInfo = outputVector->GetInformationObject(0);
    vtkImageData *output = vtkImageData::GetDateFormat(outInfo);
    int *extent = output->GetUpdateExtent();
     output->SetExtent(extent);
     output->SetOrigin(origin);
      output->SetSpacing(ar);

And now, I want to add some scalar data to the output object.

I wrote my code like this:
vtkIntArray *castkey = vtkIntArray::New();
    castkey->SetName("casting_type");
    for (int i=0; i<dim[0]; i++)
    {
        for (int j=0;j<dim[1]; j++)
        {
            for (int k=0; k<dim[2]; k++)
            {
                int idx = i*dim[2]*dim[1]+j*dim[2]+k;
                castkey->InsertNextValue(sgnfile.GetData()[idx]);
            }
        }
    }

    output->AddArray(castkey);

note:GetData() returns the scalar value of the point idx.
So I was wonder what I did is right or wrong !
Please give me some suggestion!
Thank you so much!






-- 
shenyanwen at gmail.com
Mobile Phone:13476177952
Tel: 027-87558144
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20090326/81399119/attachment.htm>


More information about the ParaView mailing list