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

Michael Jackson mike.jackson at bluequartz.net
Thu Mar 26 09:43:34 EDT 2009


Here are some code snippets from one of my projects, it should get you  
started.

   // Setup and Allocate the Cell Data Arrays
   vtkSmartPointer<vtkDoubleArray> burgerVec =  
vtkSmartPointer<vtkDoubleArray>::New();
   burgerVec->SetName("Direction" );
   burgerVec->SetNumberOfComponents(3);

   // Setup and Allocate the Cell Data Arrays
   vtkSmartPointer<vtkDoubleArray> normalVec =  
vtkSmartPointer<vtkDoubleArray>::New();
   normalVec->SetName( "Normals" );
   normalVec->SetNumberOfComponents(3);

for (....)
{
   burgerVec->InsertNextTuple3(bx, by, bz);
   normalVec->InsertNextTuple3(nx, ny, nz)
}

output->GetPointData()->AddArray(burgerVec);
output->GetPointData()->AddArray(normalVec);
output->GetPointData()->SetActiveVectors( "Direction" );

Hope that helps

_________________________________________________________
Mike Jackson                  mike.jackson at bluequartz.net
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio



On Mar 26, 2009, at 4:21 AM, shenyanwen wrote:

> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list