[Paraview] Python scripting/Grid geometry transformation

Nikolaos Beratlis nikos.beratlis at gmail.com
Fri Apr 5 13:36:45 EDT 2013


So I have done the following test. I have created a xmf file of a grid in
cylindrical coordinates "grid3d_cyl.xmf" specified as Topology Type 3DSMesh
and Geometry Type XYZ. That is a full 3D array is written:

<?xml version="1.0" ?>
<!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []>
<Xdmf Version="2.2">
<Domain>
<Grid GridType="Uniform">
<Topology TopologyType="3DSMesh" Dimensions="    30    70    40"/>
<Geometry GeometryType="XYZ">
<DataItem Dimensions="84000 3" NumberType="Float" Precision="4"
Format="XML">
....
....
....
</DataItem>
</Geometry>
</Grid>
</Domain>
</Xdmf>

The grid is 30x70x40 and the file "grid3d_cyl.xmf" is 15.8 MB large. When I
read this into Paraview the information windows shows it uses 0.98MB of
memory.

I then create a grid in cartesian coordinates "grid3d_car" specified as
Topology Type 3DRectMesh and Geometry Type VXVYVZ. Here instead of the full
3D array I write thee 1D arrays, one for each coordinates. The file looks
like:

<?xml version="1.0" ?>
<!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []>
<Xdmf Version="2.2">
<Domain>
<Grid GridType="Uniform">
<Topology TopologyType="3DRectMesh" Dimensions="    30    70    40"/>
<Geometry GeometryType="VXVYVZ">
<DataItem Dimensions="   40" NumberType="Float" Precision="4" Format="XML">
   0.0000   1.0000   2.0000   3.0000   4.0000   5.0000   6.0000   7.0000
8.0000   9.0000  10.0000  11.0000  12.0000  13.0000  14.0000  15.0000
 16.0000  17.0000  18.0000  19.0000  20.0000  21.0000  22.0000  23.0000
 24.0000  25.0000  26.0000  27.0000  28.0000  29.0000  30.0000  31.0000
 32.0000  33.0000  34.0000  35.0000  36.0000  37.0000  38.0000  39.0000
</DataItem>
<DataItem Dimensions="   70" NumberType="Float" Precision="4" Format="XML">
   0.0000   0.0911   0.1821   0.2732   0.3642   0.4553   0.5464   0.6374
0.7285   0.8195   0.9106   1.0017   1.0927   1.1838   1.2748   1.3659
1.4570   1.5480   1.6391   1.7302   1.8212   1.9123   2.0033   2.0944
2.1855   2.2765   2.3676   2.4586   2.5497   2.6408   2.7318   2.8229
2.9139   3.0050   3.0961   3.1871   3.2782   3.3692   3.4603   3.5514
3.6424   3.7335   3.8245   3.9156   4.0067   4.0977   4.1888   4.2799
4.3709   4.4620   4.5530   4.6441   4.7352   4.8262   4.9173   5.0083
5.0994   5.1905   5.2815   5.3726   5.4636   5.5547   5.6458   5.7368
5.8279   5.9189   6.0100   6.1011   6.1921   6.2832
</DataItem>
<DataItem Dimensions="   30" NumberType="Float" Precision="4" Format="XML">
   1.0000   2.0000   3.0000   4.0000   5.0000   6.0000   7.0000   8.0000
9.0000  10.0000  11.0000  12.0000  13.0000  14.0000  15.0000  16.0000
 17.0000  18.0000  19.0000  20.0000  21.0000  22.0000  23.0000  24.0000
 25.0000  26.0000  27.0000  28.0000  29.0000  30.0000
</DataItem>
</Geometry>
</Grid>
</Domain>
</Xdmf>

The gris is still 30x70x40 but the file "grid3d_car.xmf" is more compact,
it is only 2.2 KB in size. When I read it into Paraview the information
windows shows it uses only 0.003MB. So far so good, I end up saving space
both on the hard drive and in memory.

I then convert the cartesian grid to cylindrical coordinates using the
CleantoGrid Filter and also a programmable Filter:

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)


The information window in Paraview shows that The CleanToGrid Filter uses
7.2 MB and the ProgrammableFilter another 7.1MB so in total the cartesian
to cylindrical conversion uses 14.3 MB. That's a huge memory penalty.
Here's a summary:


File                     Size       Memory

grid3d_cyl.xmf   15.8MB    0.98MB
grid3d_car.xmf    2.2KB     0.003MB
CleanToGrid          -           7.2MB
Programmable       -           7.1MB

Since both grids contain the exact same coordinate information I would
expect the approach of converting the grid from cartesian to cylindrical to
not take more than 0.98MB of memory, instead it takes 14.3MB. Does it make
any sense? Am I doing sth wrong? Can I avoid the memory penalty?

Thank you,

Nikos


On Fri, Apr 5, 2013 at 3:48 AM, Felipe Bordeu <felipe.bordeu at ec-nantes.fr>wrote:

>  By "pipelines", I think you want to say "filters". I do not know how to
> delete intermediary results.
> One way is to apply a filter and then save the result ("File"-> "Save
> Data"). So you can open it later without the deed to recreate the hole
> pipeline.
>
> Felipe
>
> Le 04/04/2013 19:51, Nikolaos Beratlis a écrit :
>
> Hi Felipe,
>
>  When I try this script to transform from cartesian to cylindrical
> coordinates after I have applied the CleantoGrid Filter:
>
>   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)
>  pdo.GetPointData().AddArray(pdi.GetPointData().GetArray(0))
> pdo.GetPointData().AddArray(pdi.GetPointData().GetArray(1))
> pdo.GetPointData().AddArray(pdi.GetPointData().GetArray(2))
>
>  it creates two more pipelines, one for CleantoGrid and one for
> Programmable Filter. Both pipelines are linked to the original pipeline and
> both pipelines require the same memory as the original pipeline. Is there a
> way to to delete the previous two pipelines (original with cartesian
> coordinates and cleantoGrid) so that I only use one memory amount and not
> three?
>
>  Nikos
>
>
>  On Wed, Apr 3, 2013 at 12:05 PM, Felipe Bordeu <
> felipe.bordeu at ec-nantes.fr> wrote:
>
>>  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> 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> 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 <2.0944%20%C2%A0%204.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 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
>>>>
>>>>
>>>>
>>>> --
>>>> Felipe Bordeu Weldt
>>>> Ingénieur de Recherche
>>>> -------------------------------------
>>>> Tél. : 33 (0)2 40 37 16 57
>>>> Fax. : 33 (0)2 40 74 74 06Felipe.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
>>>>
>>>> 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 06Felipe.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
>>>
>>> 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 06Felipe.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
>>
>> 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 06Felipe.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
>
> 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/20130405/d2cbbc31/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/20130405/d2cbbc31/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: grid3d_car_info.png
Type: image/png
Size: 58429 bytes
Desc: not available
URL: <http://www.paraview.org/pipermail/paraview/attachments/20130405/d2cbbc31/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: grid3d_cyl_info.png
Type: image/png
Size: 60707 bytes
Desc: not available
URL: <http://www.paraview.org/pipermail/paraview/attachments/20130405/d2cbbc31/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cleantogrid_info.png
Type: image/png
Size: 38589 bytes
Desc: not available
URL: <http://www.paraview.org/pipermail/paraview/attachments/20130405/d2cbbc31/attachment-0008.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ProgrammableFilter_info.png
Type: image/png
Size: 38069 bytes
Desc: not available
URL: <http://www.paraview.org/pipermail/paraview/attachments/20130405/d2cbbc31/attachment-0009.png>


More information about the ParaView mailing list