[vtkusers] update scalars of vtkPoints
Eric E. Monson
emonson at cs.duke.edu
Fri Jul 2 07:35:11 EDT 2010
I hope you realize that my sample code wasn't optimized for speed -- I just wrote the most simple thing that I could get to work, just to show myself that what you were seeing was anomalously slow.
-Eric
On Jul 2, 2010, at 1:41 AM, Hagen Mölle wrote:
> Thanks Eric,
>
> python is not a problem. I will adapt your python script to match my minimal example. My minimal c++ code would contain wxWidgets - so compiling would not be that easy.
>
> Hagen
>> Hey Hagen,
>>
>> Yes, there's definitely something strange going on. As Sebastian suggested, try compiling in release mode to see if that makes a difference.
>>
>> I know you're using C++, but out of curiosity I tried it and this simple Python script creates a 7000 point unstructured grid and modifies the scalars 100 times in about 2 seconds on my machine, re-rendering the scene each time:
>>
>> # -------------
>> import vtk
>>
>> num_pts = 7000
>>
>> # Point source creates polydata
>> pts = vtk.vtkPointSource()
>> pts.SetNumberOfPoints(num_pts)
>> pts.SetRadius(10)
>>
>> # Triangle filter converts it to an unstructured grid
>> tet = vtk.vtkDataSetTriangleFilter()
>> tet.SetInputConnection(pts.GetOutputPort())
>>
>> # Elevation just creates some non-random scalars we can modify
>> elev = vtk.vtkElevationFilter()
>> elev.SetLowPoint(-10,0,0)
>> elev.SetHighPoint(10,0,0)
>> elev.SetInputConnection(tet.GetOutputPort())
>> elev.Update()
>>
>> # Making a deep copy so it's as if we created the
>> # unstructured grid from scratch
>> ug = vtk.vtkUnstructuredGrid()
>> ug.DeepCopy(elev.GetOutputDataObject(0))
>>
>> mapper = vtk.vtkDataSetMapper()
>> mapper.SetInput(ug)
>> mapper.SetScalarModeToUsePointData()
>> mapper.ScalarVisibilityOn()
>> mapper.SetScalarRange(-1,1)
>> actor = vtk.vtkActor()
>> actor.SetMapper(mapper)
>> actor.GetProperty().SetPointSize(4)
>>
>> ren = vtk.vtkRenderer()
>> renWin = vtk.vtkRenderWindow()
>> renWin.AddRenderer(ren)
>> iren = vtk.vtkRenderWindowInteractor()
>> iren.SetRenderWindow(renWin)
>>
>> ren.AddActor(actor)
>> ren.ResetCamera()
>> renWin.Render()
>>
>> # Modify the scalars and render each time
>> sc = ug.GetPointData().GetScalars()
>> for ff in range(100):
>> for ii in range(sc.GetNumberOfTuples()):
>> tmp = sc.GetTuple1(ii)
>> sc.SetTuple1(ii,float(tmp-0.01))
>> ug.Modified()
>> renWin.Render()
>>
>> iren.Start()
>> # -------------
>>
>> Good luck,
>> -Eric
>>
>> ------------------------------------------------------
>> Eric E Monson
>> Duke Visualization Technology Group
>>
>>
>> On Jul 1, 2010, at 9:24 AM, Hagen Mölle wrote:
>>
>>
>>> Hi again,
>>>
>>> using scalars->Modified() works. But now I returned to start. The visualization update of the vtkUnstructuredGrid with for example 7000 points takes about 40 seconds. So there is no difference in time consumption between creating a new dataset or updating the old dataset.
>>>
>>> I do not really understand why it takes vtk over 40 seconds to update the scalars in visualization of only 7000 points (vtkUnstructuredGrid). Is there any else I can do to bring down the update time?
>>>
>>> Hagen
>>>
>>>> Hi Hagen,
>>>>
>>>> did you also try scalars->Modified() instead?
>>>>
>>>> With Modified() you tell the pipeline that the data object has to be updated (also everything coming after this object in pipeline). You might forgot to run Update() on your mapper the vtkUnstructedGrid is attached to (or any other object that has Update() and is connected after the grid in pipeline row). You might also forgot to call the Render() method to update the renderer?
>>>>
>>>> Hope this helps!
>>>>
>>>> Sebastian Barth
>>>>
>>>> -----Ursprüngliche Nachricht-----
>>>> Von: Hagen Mölle [mailto:h.moelle at googlemail.com]
>>>> Gesendet: Donnerstag, 1. Juli 2010 14:16
>>>> An: Barth, Sebastian
>>>> Cc: John Drescher; vtkusers at vtk.org; sebastien.jourdain at kitware.com
>>>> Betreff: Re: AW: [vtkusers] update scalars of vtkPoints
>>>>
>>>> Hi Sebastian,
>>>>
>>>> Thanks for your help. I got it working with vtkPolyData in my 2D
>>>> visualization.
>>>>
>>>> In my 3D visualization of measured points I still have the problem that
>>>> the scalars do not change. There I use vtkUnstructuredGrid instead of
>>>> vtkPolyData. Right now the update routine of the scalars looks like this
>>>> (pseudo code):
>>>>
>>>> scalars = vtkDataSet->GetPointData()->GetScalars()
>>>> for(number of scalars)
>>>> {
>>>> update each scalar
>>>> }
>>>> vtkDataSet->Modified()
>>>>
>>>> The code is compiling for vtkUnstructuredGrid and vtkPolyData. But it
>>>> seems I have to do something additional to update the scalars of the
>>>> vtkUnstructuredGrid.
>>>>
>>>> Any idea?
>>>>
>>>> Hagen
>>>>
>>>>
>>>>
>>>>
>>>>> Hello Hagen,
>>>>>
>>>>> did you forget to call Modified() of the vtkPolyData after altering the points? Otherwise the vtkPolyData does not know that their points, scalars or cells were changed.
>>>>>
>>>>> Sebastian Barth
>>>>>
>>>>> -----Ursprüngliche Nachricht-----
>>>>> Von: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] Im Auftrag von Hagen Mölle
>>>>> Gesendet: Donnerstag, 1. Juli 2010 08:26
>>>>> An: John Drescher; vtkusers at vtk.org; sebastien.jourdain at kitware.com
>>>>> Betreff: Re: [vtkusers] update scalars of vtkPoints
>>>>>
>>>>> On 06/30/2010 06:14 PM, John Drescher wrote:
>>>>>
>>>>>
>>>>>
>>>>>> 2010/6/30 Sebastien Jourdain<sebastien.jourdain at kitware.com>:
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>> Hi Hagen,
>>>>>>>
>>>>>>> As you said, you can start by simply change the data on the fly and
>>>>>>> call Render() once the change has been done. By change I mean point
>>>>>>> location, scalar data and even point number.
>>>>>>> But be aware that only one thread should be used in VTK otherwise they
>>>>>>> have to be synchronized.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> I think vtkPolyData->GetPointData->GetScalars()
>>>>>>
>>>>>> is where to start
>>>>>>
>>>>>> John
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>> Hi Sebastien and John,
>>>>>
>>>>> Thanks for pointing out how to change the scalars of the points on the
>>>>> fly. So I need to alter the vtkDataArray which I get by
>>>>> vtkPolyData->GetPointData->GetScalars(). Hopefully this will work.
>>>>>
>>>>> Yesterday I tried to set new scalars by using the following method:
>>>>> vtkPolyData->GetPointData->SetScalars(vtkDoubleArray). So I did not
>>>>> generate a new dataset. But the visualization did not change during
>>>>> update. It seemed the old scalars where used during update.
>>>>>
>>>>> Hagen
>>>>> _______________________________________________
>>>>> 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 VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>>>>
>>>>> Follow this link to subscribe/unsubscribe:
>>>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>> _______________________________________________
>>> 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 VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>
More information about the vtkusers
mailing list