[Paraview] Insert text source into view in a script
pat marion
pat.marion at kitware.com
Thu Jul 16 12:07:32 EDT 2009
I committed a fix to cvs. The problem was that
ScalarBarWidgetRepresentation proxy does not have an Input property,
so a runtime error was thrown when servermanager.GetRepresentation()
tried to read the property value. I added a try/except.
By the way, scalar bars can be created now through the paraview.simple
module if you have the latest paraview:
>>> help(CreateScalarBar)
Help on function CreateScalarBar in module paraview.simple:
CreateScalarBar(**params)
Create and return a scalar bar widget. The returned widget may
be added to a render view by appending it to the view's representations
The widget must have a valid lookup table before it is added to a view.
It is possible to pass the lookup table (and other properties) as arguments
to this method:
lt = MakeBlueToRedLt(3.5, 7.5)
bar = CreateScalarBar(LookupTable=lt, Title="Velocity")
GetRenderView().Representations.append(bar)
By default the returned widget is selectable and resizable.
Committed patch:
RCS file: /cvsroot/ParaView3/ParaView3/Utilities/VTKPythonWrapping/paraview/servermanager.py,v
retrieving revision 1.60
diff -u -3 -r1.60 servermanager.py
--- servermanager.py 30 Jun 2009 15:50:25 -0000 1.60
+++ servermanager.py 16 Jul 2009 15:56:00 -0000
@@ -1986,8 +1986,9 @@
def GetRepresentation(aProxy, view):
for rep in view.Representations:
- if rep.Input == aProxy:
- return rep
+ try: isRep = rep.Input == aProxy
+ except: isRep = False
+ if isRep: return rep
return None
def CreateRepresentation(aProxy, view, **extraArgs):
Pat
On Thu, Jul 16, 2009 at 10:34 AM, Utkarsh Ayachit
<utkarsh.ayachit at kitware.com> wrote:
>
> Marco,
>
> Looks like Pat ran into this issue recently as well. He's investigating it.
>
> Utkarsh
>
> On Thu, Jul 16, 2009 at 5:12 AM, M. Nawijn<nawijn at gmail.com> wrote:
> > I just found out the offending line that gives me the problem.
> > Given the following code:
> >
> > from paraview.simple import *
> >
> > lt = MakeBlueToRedLT(-1.0, 1.0)
> >
> > bar = servermanager.rendering.ScalarBarWidgetRepresentation()
> > bar.LookupTable = lt
> > bar.LabelColor = [0.0, 1.0, 0.0]
> > bar.Title = r'W [mm]'
> > bar.TitleColor = [0.0, 1.0, 0.0]
> > bar.LabelFontSize = 14
> > bar.AspectRatio = 15.0
> > bar.AutomaticLabelFormat = 0
> >
> > reader = XMLUnstructuredGridReader(FileName='disp-stage-%d.vtu' % 17)
> >
> > Show()
> > Render()
> >
> > #UpdatePipeline()
> >
> > view = GetActiveView()
> > view.Background = [0,0,0]
> > ResetCamera(view)
> > view.UseOffscreenRenderingForScreenshots = 0
> >
> > dp = GetDisplayProperties()
> > dp.ColorArrayName = 'W'
> >
> > rep = GetRepresentation()
> > rep.LookupTable = lt
> >
> > view.Representations.append(bar)
> >
> > # Don't know how to get this into the view
> > text = Text()
> > text.Text = "Hello"
> >
> > Show()
> > Render()
> >
> > WriteImage('test.png')
> >
> > The code fails to add the text if I have the following line enabled:
> >
> > view.Representations.append(bar)
> >
> > If I uncomment this line, the text is added to the view as expected.
> > Does anybody have a clue why this is?
> >
> > I added the traceback below:
> >
> > vtkFileSeriesReader : [ ...........]
> > vtkPVGeometryFilter : [ ...........]
> > vtkPVCacheKeeper : [ ...........]
> > vtkPainterPolyDataMapper : [ ...........]
> > vtkPainterPolyDataMapper : [ ...........]
> > vtkPainterPolyDataMapper : [ ...........]
> > Traceback (most recent call last):
> > File "test3.py", line 42, in <module>
> > Show()
> > File "/home/nawijn/scratch/paraview-bin/Utilities/VTKPythonWrapping/paraview/simple.py",
> > line 112, in Show
> > rep = GetDisplayProperties(proxy, view)
> > File "/home/nawijn/scratch/paraview-bin/Utilities/VTKPythonWrapping/paraview/simple.py",
> > line 101, in GetDisplayProperties
> > return GetRepresentation(proxy, view)
> > File "/home/nawijn/scratch/paraview-bin/Utilities/VTKPythonWrapping/paraview/simple.py",
> > line 90, in GetRepresentation
> > rep = servermanager.GetRepresentation(proxy, view)
> > File "/home/nawijn/scratch/paraview-bin/Utilities/VTKPythonWrapping/paraview/servermanager.py",
> > line 1989, in GetRepresentation
> > if rep.Input == aProxy:
> > File "/home/nawijn/scratch/paraview-bin/Utilities/VTKPythonWrapping/paraview/servermanager.py",
> > line 357, in __getattr__
> > return getattr(self.SMProxy, name)
> > AttributeError: Input
> >
> > Kind regards,
> >
> > Marco
> >
> >
> >
> > On Wed, Jul 15, 2009 at 10:33 PM, M. Nawijn<nawijn at gmail.com> wrote:
> >> The script works. Somehow it seems like it does not work in
> >> combination with my reader.
> >>
> >> Many thanks for your help. I have to go now, but I hope you have another idea.
> >>
> >> Kind regards,
> >>
> >> Marco
> >>
> >> On Wed, Jul 15, 2009 at 10:27 PM, Utkarsh
> >> Ayachit<utkarsh.ayachit at kitware.com> wrote:
> >>> Oops correction, I had a typo in the script:
> >>> #=======================
> >>> from paraview.simple import *
> >>> Sphere()
> >>> Show()
> >>> Render()
> >>>
> >>> t = Text()
> >>> t.Text = "Hello World"
> >>> Show()
> >>> Render()
> >>> #=======================
> >>>
> >>>
> >>>
> >>> On Wed, Jul 15, 2009 at 4:25 PM, Utkarsh
> >>> Ayachit<utkarsh.ayachit at kitware.com> wrote:
> >>>> Does the following script work:
> >>>> #=======================
> >>>> from paraview.simple import *
> >>>> Sphere()
> >>>> Show()
> >>>> Render()
> >>>>
> >>>> t = Text()
> >>>> t.Text = "Hello World"
> >>>> t.Show()
> >>>> Render()
> >>>> #=======================
> >>>>
> >>>> Utkarsh
> >>>>
> >>>>
> >>>> On Wed, Jul 15, 2009 at 4:23 PM, M. Nawijn<nawijn at gmail.com> wrote:
> >>>>> Hello Utkarsh,
> >>>>>
> >>>>> Thank you for the fast response. I tried this already before posting
> >>>>> my question to the mailing list, however, when I inserted the Show(),
> >>>>> I get the following error:
> >>>>>
> >>>>> vtkFileSeriesReader : [ ...........]
> >>>>> vtkPainterPolyDataMapper : [ ...........]
> >>>>> vtkPainterPolyDataMapper : [ ...........]
> >>>>> Traceback (most recent call last):
> >>>>> File "test3.py", line 39, in <module>
> >>>>> Show()
> >>>>> File "/home/nawijn/scratch/paraview-bin/Utilities/VTKPythonWrapping/paraview/simple.py",
> >>>>> line 112, in Show
> >>>>> rep = GetDisplayProperties(proxy, view)
> >>>>> File "/home/nawijn/scratch/paraview-bin/Utilities/VTKPythonWrapping/paraview/simple.py",
> >>>>> line 101, in GetDisplayProperties
> >>>>> return GetRepresentation(proxy, view)
> >>>>> File "/home/nawijn/scratch/paraview-bin/Utilities/VTKPythonWrapping/paraview/simple.py",
> >>>>> line 90, in GetRepresentation
> >>>>> rep = servermanager.GetRepresentation(proxy, view)
> >>>>> File "/home/nawijn/scratch/paraview-bin/Utilities/VTKPythonWrapping/paraview/servermanager.py",
> >>>>> line 1989, in GetRepresentation
> >>>>> if rep.Input == aProxy:
> >>>>> File "/home/nawijn/scratch/paraview-bin/Utilities/VTKPythonWrapping/paraview/servermanager.py",
> >>>>> line 357, in __getattr__
> >>>>> return getattr(self.SMProxy, name)
> >>>>> AttributeError: Input
> >>>>>
> >>>>>
> >>>>> Any suggestions?
> >>>>>
> >>>>> On Wed, Jul 15, 2009 at 10:17 PM, Utkarsh
> >>>>> Ayachit<utkarsh.ayachit at kitware.com> wrote:
> >>>>>> "Text" is a data source similar to the reader. You need to "Show" it
> >>>>>> to add it to the active view.
> >>>>>>
> >>>>>> Just do:
> >>>>>> load = 100.0
> >>>>>> # Don't know how to get this into the view
> >>>>>> text = Text()
> >>>>>> text.Text = "Load %6.3f" % load
> >>>>>> Show()
> >>>>>>
> >>>>>> Utkarsh
> >>>>>>
> >>>>>> On Wed, Jul 15, 2009 at 4:01 PM, M. Nawijn<nawijn at gmail.com> wrote:
> >>>>>>> Hello,
> >>>>>>>
> >>>>>>> I am a newbie in Paraview Python scripting, so I apologize upfront if
> >>>>>>> this is a trivial question.
> >>>>>>>
> >>>>>>> I am processing a set of datafiles obtained from an optical
> >>>>>>> measurement system. I so far succeeded in loading the data file,
> >>>>>>> adding a color legend and storing the resulting view in a image file.
> >>>>>>> Sample code is posted below.
> >>>>>>>
> >>>>>>> What I would like to do next is add a text source to the view to
> >>>>>>> provide some contextual information about the data (in particular the
> >>>>>>> external load level at which the data was captured). I managed to add
> >>>>>>> a text source to an "empty" view (so without first reading the data),
> >>>>>>> but I cannot find a way to have the data and text source together.
> >>>>>>>
> >>>>>>> Can someone explain how I can add this to the view?
> >>>>>>>
> >>>>>>> Kind regards,
> >>>>>>>
> >>>>>>> Marco
> >>>>>>>
> >>>>>>> #==== What I have so far ===================================================
> >>>>>>>
> >>>>>>> from paraview.simple import *
> >>>>>>>
> >>>>>>> lt = MakeBlueToRedLT(-1.0, 1.0)
> >>>>>>>
> >>>>>>> bar = servermanager.rendering.ScalarBarWidgetRepresentation()
> >>>>>>> bar.LookupTable = lt
> >>>>>>> bar.LabelColor = [0.0, 1.0, 0.0]
> >>>>>>> bar.Title = r'W [mm]'
> >>>>>>> bar.TitleColor = [0.0, 1.0, 0.0]
> >>>>>>> bar.LabelFontSize = 14
> >>>>>>> bar.AspectRatio = 15.0
> >>>>>>> bar.AutomaticLabelFormat = 0
> >>>>>>>
> >>>>>>> reader = XMLUnstructuredGridReader(FileName='disp-stage-%d.vtu' % 17)
> >>>>>>>
> >>>>>>> Show()
> >>>>>>>
> >>>>>>> #UpdatePipeline()
> >>>>>>>
> >>>>>>> view = GetActiveView()
> >>>>>>> view.Background = [0,0,0]
> >>>>>>> ResetCamera(view)
> >>>>>>> view.UseOffscreenRenderingForScreenshots = 0
> >>>>>>>
> >>>>>>> dp = GetDisplayProperties()
> >>>>>>> dp.ColorArrayName = 'W'
> >>>>>>>
> >>>>>>> rep = GetRepresentation()
> >>>>>>> rep.LookupTable = lt
> >>>>>>>
> >>>>>>> view.Representations.append(bar)
> >>>>>>>
> >>>>>>> load = 100.0
> >>>>>>> # Don't know how to get this into the view
> >>>>>>> text = Text()
> >>>>>>> text.Text = "Load %6.3f" % load
> >>>>>>>
> >>>>>>> # Image does not show the text
> >>>>>>> WriteImage('test.png')
> >>>>>>> _______________________________________________
> >>>>>>> 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
> >>>>>>>
> >>>>>>
> >>>>>
> >>>>
> >>>
> >>
> >
More information about the ParaView
mailing list