[Paraview] Python scripting/Grid geometry transformation

Felipe Bordeu felipe.bordeu at ec-nantes.fr
Wed Apr 3 12:05:38 EDT 2013


you need to copy the point data: add this line to the end of your script:

pdo.GetPointData().AddArray(pdi.GetPointData().GetArray(0))


this will work only for one field, you can put this line inside a loop 
to add all the pointdata.

Felipe

Le 03/04/2013 17:59, Nikolaos Beratlis a écrit :
> I did and it shows me the transformed grid, but the ProgrammableFilter 
> doesn't contain the variable var. I cannot plot contours. Should I 
> change the script?
>
>
> On Wed, Apr 3, 2013 at 11:48 AM, Felipe Bordeu 
> <felipe.bordeu at ec-nantes.fr <mailto:felipe.bordeu at ec-nantes.fr>> wrote:
>
>     You must apply the programmablefilter to the cleantoGrid not to
>     the var3d.xmf.
>
>     look at the screenshot.
>
>     Felipe
>
>
>
>     Le 03/04/2013 17:43, Nikolaos Beratlis a écrit :
>>     Hi Felipe,
>>
>>     I applied the CleanToGrid Filter first and then applied the
>>     following script:
>>
>>
>>     pdi = self.GetInput()
>>
>>     pdo = self.GetOutput()
>>
>>     newPoints = vtk.vtkPoints()
>>
>>     numPoints = pdi.GetNumberOfPoints()
>>
>>     for i in range(0, numPoints):
>>
>>       coord = pdi.GetPoint(i)
>>
>>       x, y, z = coord[:3]
>>
>>       r = x * cos(y)
>>
>>       t = x * sin(y)
>>
>>       newPoints.InsertPoint(i, r, t, z)
>>
>>     pdo.SetPoints(newPoints)
>>
>>
>>     Notice the indentation and also the change of the cos(y) and
>>     sin(y) assignments.
>>
>>     but I got this error:
>>
>>     Traceback (most recent call last):
>>
>>     File "<string>", line 26, in <module>
>>
>>     File "<string>", line 12, in RequestData
>>
>>     AttributeError: SetPoints
>>
>>
>>     What am I doing wrong?
>>
>>
>>     On Wed, Apr 3, 2013 at 11:13 AM, Felipe Bordeu
>>     <felipe.bordeu at ec-nantes.fr <mailto:felipe.bordeu at ec-nantes.fr>>
>>     wrote:
>>
>>         apply a CleanToGrid filter before  the python programmable
>>         filter and this is a corrected version of your script:
>>
>>         pdi = self.GetInput()
>>
>>         pdo = self.GetOutput()
>>
>>         newPoints = vtk.vtkPoints()
>>
>>         numPoints = pdi.GetNumberOfPoints()
>>
>>         for i in range(0, numPoints):
>>
>>         coord = pdi.GetPoint(i)
>>
>>         x, y, z = coord[:3]
>>
>>         r = x * sin(y)
>>
>>         t = x * cos(y)
>>
>>         newPoints.InsertPoint(i, r, t, z)
>>
>>         pdo.SetPoints(newPoints)
>>
>>
>>
>>         Felipe
>>
>>         Le 03/04/2013 04:55, Nikolaos Beratlis a écrit :
>>>         Hi,
>>>
>>>         I am reading the following xmf file (attached as var3d.xmf)
>>>         into Paraview:
>>>
>>>         <?xml version="1.0" ?>
>>>         <!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []>
>>>         <Xdmf Version="2.2">
>>>         <Domain>
>>>         <Grid GridType="Uniform">
>>>         <Topology TopologyType="3DRectMesh" Dimensions="     2     4
>>>         3"/>
>>>         <Geometry GeometryType="VXVYVZ">
>>>         <DataItem Dimensions="  3" NumberType="Float" Precision="4"
>>>         Format="XML">
>>>            0.0000   1.0000   2.0000
>>>         </DataItem>
>>>         <DataItem Dimensions="  4" NumberType="Float" Precision="4"
>>>         Format="XML">
>>>            0.0000   2.0944   4.1888 6.2832
>>>         </DataItem>
>>>         <DataItem Dimensions="  2" NumberType="Float" Precision="4"
>>>         Format="XML">
>>>            1.0000   2.0000
>>>         </DataItem>
>>>         </Geometry>
>>>         <Attribute Name="var" AttributeType="Scalar" Center="Node">
>>>         <DataItem Dimensions="24" NumberType="Float" Precision="4"
>>>         Format="XML">
>>>         0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
>>>         </DataItem>
>>>         </Attribute>
>>>         </Grid>
>>>         </Domain>
>>>         </Xdmf>
>>>
>>>         The grid is a 3D orthogonal grid read in cartesian
>>>         coordinates (see attached image showing grid and contours of
>>>         variable). I then want to transform the grid from cartesian
>>>         to cylindrical coordinates. I tried using the following
>>>         Python script:
>>>
>>>         pdi = self.GetPolyDataInput()
>>>
>>>         pdo = self.GetPolyDataOutput()
>>>
>>>         newPoints = vtk.vtkPoints()
>>>
>>>         numPoints = pdi.GetNumberOfPoints()
>>>
>>>         for i in range(0, numPoints):
>>>
>>>         coord = pdi.GetPoint(i)
>>>
>>>         x, y, z = coord[:3]
>>>
>>>         r = x * sin(y)
>>>
>>>         t = x * cos(y)
>>>
>>>         newPoints.InsertPoint(i, r, t, z)
>>>
>>>         pdo.SetPoints(newPoints)
>>>
>>>
>>>         with Output Data Set Type chosen to be the Same as Input,
>>>         but I get this error:
>>>
>>>
>>>         Traceback (most recent call last):
>>>         File "<string>", line 26, in <module>
>>>         File "<string>", line 12, in RequestData
>>>         AttributeError: 'NoneType' object has no attribute 'SetPoints'
>>>
>>>         I have no experience with Python scripting. What am I doing
>>>         wrong?
>>>
>>>         Thank you,
>>>
>>>         Nikos
>>>
>>>
>>>         _______________________________________________
>>>         Powered bywww.kitware.com  <http://www.kitware.com>
>>>
>>>         Visit other Kitware open-source projects athttp://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
>>
>>
>>         -- 
>>         Felipe Bordeu Weldt
>>         Ingénieur de Recherche
>>         -------------------------------------
>>         Tél. :33 (0)2 40 37 16  <tel:33%20%280%292%2040%2037%2016>  57
>>         Fax. :33 (0)2 40 74 74  <tel:33%20%280%292%2040%2074%2074>  06
>>         Felipe.Bordeu at ec-nantes.fr  <mailto:Felipe.Bordeu at ec-nantes.fr>
>>         Institut GeM - UMR CNRS 6183
>>         École Centrale Nantes
>>         1 Rue de La Noë, 44321 Nantes, FRANCE
>>         -------------------------------------
>>
>>
>>         _______________________________________________
>>         Powered by www.kitware.com <http://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
>>
>>
>
>
>     -- 
>     Felipe Bordeu Weldt
>     Ingénieur de Recherche
>     -------------------------------------
>     Tél. :33 (0)2 40 37 16  <tel:33%20%280%292%2040%2037%2016>  57
>     Fax. :33 (0)2 40 74 74  <tel:33%20%280%292%2040%2074%2074>  06
>     Felipe.Bordeu at ec-nantes.fr  <mailto:Felipe.Bordeu at ec-nantes.fr>
>     Institut GeM - UMR CNRS 6183
>     École Centrale Nantes
>     1 Rue de La Noë, 44321 Nantes, FRANCE
>     -------------------------------------
>
>
>     _______________________________________________
>     Powered by www.kitware.com <http://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
>
>


-- 
Felipe Bordeu Weldt
Ingénieur de Recherche
-------------------------------------
Tél. : 33 (0)2 40 37 16 57
Fax. : 33 (0)2 40 74 74 06
Felipe.Bordeu at ec-nantes.fr
Institut GeM - UMR CNRS 6183
École Centrale Nantes
1 Rue de La Noë, 44321 Nantes, FRANCE
-------------------------------------

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20130403/d06ff132/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 112018 bytes
Desc: not available
URL: <http://www.paraview.org/pipermail/paraview/attachments/20130403/d06ff132/attachment-0001.png>


More information about the ParaView mailing list