[Paraview] Paraview 4.3.1 Python - Screenshot of specific size and ratio
Ruggiero Guida
ruggiero.guida at gmail.com
Mon Sep 21 00:37:57 EDT 2015
Subject: How to perfectly fit data in a screenshot
Hi,
Just in case someone is interested I report here my solution. The 855 seems
to be a limit for the vertical size. The limit is actually 855 x
magnification. This is good because at least is constant.
To perfectly fit an image with these characteristics:
xc, yc, zc = Focus
width, height = Actual dimensions in meters
You can calculate these parameters
ratio = height / width
magnification = 2 (or whatever value you need)
height_p = 855 * magnification
width_p = int(height_p * 1.0 / ratio / magnification)
Then you can use (apart from all the other settings)
renderView1.ViewSize = [width_p , height_p]
renderView1.InteractionMode = '2D'
renderView1.CameraPosition = [xc, yc, 10000.0 + zc]
renderView1.CameraFocalPoint = [xc, yc, zc]
renderView1.CameraParallelScale = (height / 2.0) (Notice this is the
orginal height in meters)
And finally
SaveScreenshot(output_file, magnification=magnification, quality=100,
view=renderView1)
I don't really understand the value 855, but it doesn't matter anymore.
Cheers
Ruggiero
On 15 September 2015 at 07:59, Ruggiero Guida <ruggiero.guida at gmail.com>
wrote:
> I have noticed that if I run the script in paraview python shell the size
> settings are ignored and the UI settings are used instead - in my case
> 648x639. If I run it from pvpython with paraview closed then the size will
> be 1000x855 or whatever horizontal resolution i specify x 855.
>
> Thanks
> Ruggiero
>
> On 15 Sep 2015, at 05:47, Dan Lipsa <dan.lipsa at kitware.com> wrote:
>
> I was wandering because I thought you used a different script than what I
> sent. If you only changed the palette it should not make a difference. I am
> on Linux. Maybe there is a problem with screenshot saving on MacOS. Maybe
> someone else with a mac could try this. If not, I am in the process of
> getting a mac laptop, I'll try to remember to try this out when I get my
> new laptop.
>
> Dan
>
>
> On Mon, Sep 14, 2015 at 5:43 PM, Ruggiero Guida <ruggiero.guida at gmail.com>
> wrote:
>
>> Not sure I said that I'm on Mac OS X.
>>
>> Re: palette. No reason, I prefer a white background and I was
>> experimenting with the colour mappings from colorbrewer
>>
>>
>> Sent from Outlook <http://aka.ms/Ox5hz3>
>>
>>
>>
>>
>> On Mon, Sep 14, 2015 at 9:51 AM -0700, "Dan Lipsa" <dan.lipsa at kitware.com
>> > wrote:
>>
>> Hmm,
>>> I tried
>>> ~/ParaView-4.3.1-Linux-64bit/bin/pvpython test.py
>>>
>>> and still created the right png - see attached.
>>> I notice you have a different color palette. Why is that?
>>>
>>>
>>> On Mon, Sep 14, 2015 at 8:11 AM, Ruggiero Guida <
>>> ruggiero.guida at gmail.com> wrote:
>>>
>>>> Thanks Dan.
>>>>
>>>> Run you script through pvpython. No modifications apart from the
>>>> filenames. I still have an image with 1000x855 size (see attached).
>>>>
>>>> I will try to build paraview from source to see if this changes.
>>>>
>>>> Thanks
>>>>
>>>> <image.png>
>>>>
>>>> On 12 September 2015 at 02:04, Dan Lipsa <dan.lipsa at kitware.com> wrote:
>>>>
>>>>> Ruggiero,
>>>>> Attached is the script I used on ParaView master. It saves a 1000x1000
>>>>> png. I had to uncomment renderView1.ViewSize and change the magnification
>>>>> for SaveScreenshot to 1.
>>>>>
>>>>> Dan
>>>>>
>>>>>
>>>>>
>>>>> On Thu, Sep 10, 2015 at 9:38 PM, Ruggiero Guida <
>>>>> ruggiero.guida at gmail.com> wrote:
>>>>>
>>>>>> Attached. Thanks for checking.
>>>>>>
>>>>>> On 11 September 2015 at 09:34, Dan Lipsa <dan.lipsa at kitware.com>
>>>>>> wrote:
>>>>>>
>>>>>>> If you send me your test.vtk I can try to generate the script on my
>>>>>>> machine.
>>>>>>>
>>>>>>> Dan
>>>>>>>
>>>>>>>
>>>>>>> On Thu, Sep 10, 2015 at 9:10 PM, Ruggiero Guida <
>>>>>>> ruggiero.guida at gmail.com> wrote:
>>>>>>>
>>>>>>>> I am using the 4.3.1 binary version downloaded from the website. I
>>>>>>>> generated my script starting from the trace as you suggest. Uncommenting
>>>>>>>> the ViewSize on your script works. The fact is that it does not work on
>>>>>>>> mine and i really don't understand why. I guess it is related to the
>>>>>>>> settings of the camera.
>>>>>>>>
>>>>>>>> Have you tried to run my script on your machine? I would expect to
>>>>>>>> have a square image with the data fitted perfectly into it, but as soon as
>>>>>>>> I increase the ViewSize above 855x855, only the horizontal size increases.
>>>>>>>> As you can see from the VTK the source data is 24x24.
>>>>>>>>
>>>>>>>> Thanks
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 11 September 2015 at 08:51, Dan Lipsa <dan.lipsa at kitware.com>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> What version of ParaView do you use? I run the script on a
>>>>>>>>> ParaView source build from git master.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> You should be able to do Tools / Start Trace, open your file and
>>>>>>>>> then save it to the desired resolution. The script generated should tell
>>>>>>>>> you what settings you need. You might need to uncomment the setting of the
>>>>>>>>> ViewSize. This is what I had to do.
>>>>>>>>>
>>>>>>>>> On Thu, Sep 10, 2015 at 6:41 PM, Ruggiero Guida <
>>>>>>>>> ruggiero.guida at gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> Thanks Dan.
>>>>>>>>>>
>>>>>>>>>> The image saved is 648 x 639 (see attached). What I am not
>>>>>>>>>> understanding is the relation between ViewSize, camera settings and actual
>>>>>>>>>> image size in pixels.
>>>>>>>>>>
>>>>>>>>>> I would like to use paraview to render some textures that I will
>>>>>>>>>> be using in my code and I need the image ti fit perfectly the content.
>>>>>>>>>>
>>>>>>>>>> On 10 September 2015 at 23:19, Dan Lipsa <dan.lipsa at kitware.com>
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>>> Ruggiero,
>>>>>>>>>>> The following script saves a 100x100 sphere.
>>>>>>>>>>> I created it using the trace option in ParaView.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Thu, Sep 10, 2015 at 5:07 AM, Ruggiero Guida <
>>>>>>>>>>> ruggiero.guida at gmail.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> I am trying to create a screenshot of a specific size from a
>>>>>>>>>>>> [VTK file][1].
>>>>>>>>>>>> This is the code I am using
>>>>>>>>>>>>
>>>>>>>>>>>> from paraview.simple import *
>>>>>>>>>>>> paraview.simple._DisableFirstRenderCameraReset()
>>>>>>>>>>>> rad_map = LegacyVTKReader(FileNames=['test.vtk'])
>>>>>>>>>>>>
>>>>>>>>>>>> # get active view
>>>>>>>>>>>> renderView1 = GetActiveViewOrCreate('RenderView')
>>>>>>>>>>>> dpi = 70
>>>>>>>>>>>> heigth = 24.39846235421442
>>>>>>>>>>>> width = 24.398462354214413
>>>>>>>>>>>> width_p = int(width * dpi)
>>>>>>>>>>>> heigth_p = int(heigth * dpi)
>>>>>>>>>>>> renderView1.ViewSize = [width_p, heigth_p]
>>>>>>>>>>>>
>>>>>>>>>>>> # reset view to fit data
>>>>>>>>>>>> #renderView1.ResetCamera()
>>>>>>>>>>>>
>>>>>>>>>>>> # current camera placement for renderView1
>>>>>>>>>>>> renderView1.CameraParallelProjection = 1
>>>>>>>>>>>> renderView1.CameraPosition = [5, 5, 1000]
>>>>>>>>>>>> renderView1.CameraFocalPoint = [5, 5, 0.0]
>>>>>>>>>>>> renderView1.CameraViewUp = [0.0, 1.0, 0.0]
>>>>>>>>>>>> scale = (heigth) / 2.0
>>>>>>>>>>>> renderView1.CameraParallelScale = scale
>>>>>>>>>>>>
>>>>>>>>>>>> Render()
>>>>>>>>>>>> SaveScreenshot("/Users/ruggiero/dev/test.png",
>>>>>>>>>>>> magnification=1)
>>>>>>>>>>>>
>>>>>>>>>>>> The problem is that the `ViewSize` seems to be ignored and I
>>>>>>>>>>>> keep having images of fixed size 1707 × 855. The height 855 seems to be a
>>>>>>>>>>>> kind of limit; the only way to get what I want is to limit the `ViewSize`
>>>>>>>>>>>> to 855x855.
>>>>>>>>>>>>
>>>>>>>>>>>> I have checked [this][2] question and [this][3] question, but
>>>>>>>>>>>> with no success.
>>>>>>>>>>>>
>>>>>>>>>>>> Any idea? I am not very confident in the settings for the
>>>>>>>>>>>> camera. Could this be the issue?
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> [1]: https://dl.dropboxusercontent.com/u/1342856/test.vtk
>>>>>>>>>>>> [2]:
>>>>>>>>>>>> http://stackoverflow.com/questions/31930448/in-python-script-for-paraview-can-i-specify-the-resolution-when-i-do-a-savescre
>>>>>>>>>>>> [3]:
>>>>>>>>>>>> http://stackoverflow.com/questions/27430588/paraview-python-command-to-save-picture-of-defined-size
>>>>>>>>>>>>
>>>>>>>>>>>> _______________________________________________
>>>>>>>>>>>> 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
>>>>>>>>>>>>
>>>>>>>>>>>> Search the list archives at:
>>>>>>>>>>>> http://markmail.org/search/?q=ParaView
>>>>>>>>>>>>
>>>>>>>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>>>>>>>> http://public.kitware.com/mailman/listinfo/paraview
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20150921/a3741515/attachment.html>
More information about the ParaView
mailing list