[Paraview] Naming an existing data array.

Burlen Loring bloring at lbl.gov
Sat May 31 13:03:03 EDT 2014


Hi Andrew,

I see a couple of things in your script. First is normals and scalars 
are data set attributes. so you need to access them through one of those 
classes, ex vtkPointData.

Correct me if I'm wrong but, although in VTK 6 you generally don't need 
to shallow copy the input to filters I think it's still probably a bad 
practice to modify the arrays in the input dataset.

I think what you want to do is copy the geometric structure of the input 
and then make a deep copy of normals and scalars arrays, and rename the 
copys. Copy structure rather than shallow copy since with a shallow copy 
you'd still end up modifying the arrays in the input dataset.

Finally scalars and normals may not be present. I know you'd probably 
handle that in your final script, ;-)

given all that, here's what I came up with:

    def copyAndNameArray(da, name):
       if da is not None:
         outda = da.NewInstance()
         outda.DeepCopy(da)
         outda.SetName(name)
         return outda
       else:
         return None

    pdi = self.GetPolyDataInput()
    pdo = self.GetPolyDataOutput()
    pdo.CopyStructure(pdi)

    pdo.GetPointData().SetNormals( \
       copyAndNameArray(pdi.GetPointData().GetNormals(), 'Normals'))

    pdo.GetPointData().SetScalars( \
       copyAndNameArray(pdi.GetPointData().GetScalars(), 'Scalars'))

    print 'Normals=%s'%(str(pdo.GetPointData().GetNormals()))
    print 'Scalars=%s'%(str(pdo.GetPointData().GetScalars()))

Curious to hear from other developers as to if I'm on target about not 
modifying arrays in the input or if this is overkill given the new VTK 6 
pipeline.

Burlen

On 05/30/2014 07:29 PM, Andrew Maclean wrote:
> I have a source object that produces a polydata object. Unfortunately 
> the normals and scalars are unnamed. How do I access these and name 
> them in ParaView.
> I thought something like this may work in a Programmable Filter:
>
> pdi = self.GetPolyDataInput()
>
>
> pdo = self.GetPolyDataOutput()
>
>
> pdi.GetNormals().SetName('Normals')
>
>
> pdi.GetScalars().SetName('Scalars')
>
>
> pdo = pdi
>
>
> However, I can't see the array names.
>
> This sort of thing works Ok in a Python Script:
>     # Name the arrays
> randomHillsSource.GetOutput().GetPointData().GetNormals().SetName('Normals')
> randomHillsSource.GetOutput().GetPointData().GetScalars().SetName('Scalars')
> #     pd = randomHillsSource.GetOutput().GetPointData()
> #     print pd
>
> Is it possible to do this on ParaView?
>
> Thanks in advance for any help.
>
> Andrew
>
> -- 
> ___________________________________________
> Andrew J. P. Maclean
>
> ___________________________________________
>
>
> _______________________________________________
> 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 ParaView Wiki at: http://paraview.org/Wiki/ParaView
>
> Follow this link to subscribe/unsubscribe:
> http://www.paraview.org/mailman/listinfo/paraview

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20140531/b57be049/attachment.html>


More information about the ParaView mailing list