[vtkusers] How to write a custom reader?

shenyanwen shenyanwen at gmail.com
Tue Apr 7 09:36:59 EDT 2009


Hello, everyone!
I wrote my own reader plugin for my custom data format.
But when I use it, it seems do NOT work!
It seems can NOT execute  the function RequetInformation.
Should I use the method ProcessRequest()?
May some one can help me out?
Thanks so much!

Here are my some parts of codes:

int vtkSgnReader::RequestInformation(vtkInformation *vtkNotUsed(request),
                                     vtkInformationVector
**vtkNotUsed(inputVector),
                                     vtkInformationVector *outputVector)
{
         vtkInformation *outInfo = outputVector->GetInformationObject(0);
          return this->ReadMetaData(outInfo);
}

int vtkSgnReader::ReadMetaData(vtkInformation *outInfo)
{
    if (!sgnfile->Readsgn(FileName))
    {
        return 1;
    }
    int dim[3];
    dim[0]=sgnfile->GetNx();
    dim[1]=sgnfile->GetNy();
    dim[2]=sgnfile->GetNz();
    //Set the extent
    outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),
                     0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1);
    return 1;
}

int vtkSgnReader::RequestData(vtkInformation *vtkNotUsed(request),
                              vtkInformationVector
**vtkNotUsed(inputVector),
                              vtkInformationVector *outputVector)
{
    vtkInformation *outInfo = outputVector->GetInformationObject(0);
    vtkImageData *output = vtkImageData::GetData(outInfo);
   int *extent = output->GetUpdateExtent();
    int numPts=0;
    int L, M, N;
    if (!sgnfile->Readsgn(FileName))
    {
        return 1;
    }
    int dim[3];
    dim[0] = sgnfile->GetNx();
    L = dim[0];
    dim[1] = sgnfile->GetNy();
    M = dim[1];
    dim[2] = sgnfile->GetNz();
    N = dim[2];
    numPts = dim[0]*dim[1]*dim[2];
   output->SetExtent(extent);
    output->SetOrigin(origin);
    output->SetSpacing(ar);

    //set the scalar data
    vtkShortArray *castkey = vtkShortArray::New();
    castkey->SetName("casting_type");
    castkey->SetNumberOfComponents(1);
    castkey->SetNumberOfTuples(numPts);
    for (int i=0; i<L; i++)   for (int j=0;j<M; j++)   for (int k=0; k<N;
k++)
    {
        int idx = i*M*N+j*N+k;
        castkey->SetTupleValue( idx, &(sgnfile->GetSGNData()[idx]) );
    }
    output->GetPointData()->AddArray(castkey);
    castkey->Delete();
    return 1;
}

Do I have something wrong with my code?
Thank you so much for your truly help!

-Seven

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


More information about the vtkusers mailing list