pick and update

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

pick and update

Boris Avdeev
Hello,
I am trying to make my pipeline to update as I pick and had no luck so far.
Here is the pipeline:
<pre>
      Modify on a pick event
       |
       V
Reader -> Filter -> Mapper
</pre>
I modify the reader's output. Is it not a good idea? Where have I messed up?
Here is some python code:

    picksR = vtkPolyDataReader()
    picksR.SetFileName(fname)
    proxy = vtkSurfaceReconstructionFilter()
    proxy.SetInput(picksR.GetOutput())
    surf = vtkContourFilter()
    surf.SetValue(0,0.0)
    surf.SetInput(proxy.GetOutput())

    surfMap = vtkPolyDataMapper()
    surfMap.SetInput(surf.GetOutput())
    surfAct = vtkActor()
    surfAct.SetMapper(surfMap)
    ren.AddActor(surfAct)

    def PickingFunction(obj, event):
        global picksR, renWin
        pt = obj.GetPicker().GetPickPosition()
        picksR.GetOutput().GetPoints().InsertNextPoint(pt)
        renWin.Render()

    iact.AddObserver("EndPickEvent", PickingFunction)


Thanks,
Boris
_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: pick and update

Tom Radcliffe

The reader's output will be regenerated during the next Update, so your
changes will be wiped out.  You should pull the data out of the reader
and make a copy.  Then make the copy of the data from the reader the
start of your pipeline.

To do this without copying you can do something like this (in C++,
something similar in Python):

vtkPolyData* pData = pReader->GetOutput();
pData->Register(0);
pReader->Delete();

This should drop the reader but keep the data around.

--Tom

--
Tom Radcliffe, Ph.D., P.Eng.
President, Predictive Patterns Software Inc.
http://www.predictivepatterns.com | 613-483-9803
[hidden email]


Boris Avdeev wrote:

>Hello,
>I am trying to make my pipeline to update as I pick and had no luck so far.
>Here is the pipeline:
><pre>
>      Modify on a pick event
>       |
>       V
>Reader -> Filter -> Mapper
></pre>
>I modify the reader's output. Is it not a good idea? Where have I messed up?
>Here is some python code:
>
>    picksR = vtkPolyDataReader()
>    picksR.SetFileName(fname)
>    proxy = vtkSurfaceReconstructionFilter()
>    proxy.SetInput(picksR.GetOutput())
>    surf = vtkContourFilter()
>    surf.SetValue(0,0.0)
>    surf.SetInput(proxy.GetOutput())
>
>    surfMap = vtkPolyDataMapper()
>    surfMap.SetInput(surf.GetOutput())
>    surfAct = vtkActor()
>    surfAct.SetMapper(surfMap)
>    ren.AddActor(surfAct)
>
>    def PickingFunction(obj, event):
>        global picksR, renWin
>        pt = obj.GetPicker().GetPickPosition()
>        picksR.GetOutput().GetPoints().InsertNextPoint(pt)
>        renWin.Render()
>
>    iact.AddObserver("EndPickEvent", PickingFunction)
>
>
>Thanks,
>Boris
>_______________________________________________
>This is the private VTK discussion list.
>Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>Follow this link to subscribe/unsubscribe:
>http://www.vtk.org/mailman/listinfo/vtkusers
>
>  
>


_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: pick and update

Boris Avdeev
Thanks for your reply. I tried the second alternative. I guess
Delete() method is not exported to Python (because of GC?). I tried to
use the following code instead:

data.Register(None)
data.Update()
read.UnRegister(None)

It did not do any good and now I get seg.fault at the exit.
I did not quite get the copy explanation. What is "make the copy of
the data from the reader the start of your pipeline"?
I tried the following with as much success as earlier:
...
read.Update()
data.DeepCopy(read.GetOutput())
...

Thanks,
Boris


On 1/30/06, Tom Radcliffe <[hidden email]> wrote:

>
> The reader's output will be regenerated during the next Update, so your
> changes will be wiped out.  You should pull the data out of the reader
> and make a copy.  Then make the copy of the data from the reader the
> start of your pipeline.
>
> To do this without copying you can do something like this (in C++,
> something similar in Python):
>
> vtkPolyData* pData = pReader->GetOutput();
> pData->Register(0);
> pReader->Delete();
>
> This should drop the reader but keep the data around.
>
> --Tom
_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: pick and update

Boris Avdeev
Okay, instead of "read.Delete()" I can use "del read". However it
still doesn't help.
What object are you supposed to pass to Register()?



On 1/30/06, Boris Avdeev <[hidden email]> wrote:

> Thanks for your reply. I tried the second alternative. I guess
> Delete() method is not exported to Python (because of GC?). I tried to
> use the following code instead:
>
> data.Register(None)
> data.Update()
> read.UnRegister(None)
>
> It did not do any good and now I get seg.fault at the exit.
> I did not quite get the copy explanation. What is "make the copy of
> the data from the reader the start of your pipeline"?
> I tried the following with as much success as earlier:
> ...
> read.Update()
> data.DeepCopy(read.GetOutput())
> ...
>
> Thanks,
> Boris
>
>
> On 1/30/06, Tom Radcliffe <[hidden email]> wrote:
> >
> > The reader's output will be regenerated during the next Update, so your
> > changes will be wiped out.  You should pull the data out of the reader
> > and make a copy.  Then make the copy of the data from the reader the
> > start of your pipeline.
> >
> > To do this without copying you can do something like this (in C++,
> > something similar in Python):
> >
> > vtkPolyData* pData = pReader->GetOutput();
> > pData->Register(0);
> > pReader->Delete();
> >
> > This should drop the reader but keep the data around.
> >
> > --Tom
>
_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: pick and update

Tom Radcliffe
In reply to this post by Boris Avdeev

I meant using DeepCopy when I said "make a copy of the output data", so
you've tried the right thing.  I had forgotten about GC in Python--I
don't know what effect it might have.  Generally Register and UnRegister
should be called with a null pointer in C++, which I guess is equivalent
to None in Python.  The only reason to use something other than null is
for debugging, so you can see what objects have registered something and
not unregistered it.

--Tom

Boris Avdeev wrote:

>Thanks for your reply. I tried the second alternative. I guess
>Delete() method is not exported to Python (because of GC?). I tried to
>use the following code instead:
>
>data.Register(None)
>data.Update()
>read.UnRegister(None)
>
>It did not do any good and now I get seg.fault at the exit.
>I did not quite get the copy explanation. What is "make the copy of
>the data from the reader the start of your pipeline"?
>I tried the following with as much success as earlier:
>...
>read.Update()
>data.DeepCopy(read.GetOutput())
>...
>
>Thanks,
>Boris
>
>
>On 1/30/06, Tom Radcliffe <[hidden email]> wrote:
>  
>
>>The reader's output will be regenerated during the next Update, so your
>>changes will be wiped out.  You should pull the data out of the reader
>>and make a copy.  Then make the copy of the data from the reader the
>>start of your pipeline.
>>
>>To do this without copying you can do something like this (in C++,
>>something similar in Python):
>>
>>vtkPolyData* pData = pReader->GetOutput();
>>pData->Register(0);
>>pReader->Delete();
>>
>>This should drop the reader but keep the data around.
>>
>>--Tom
>>    
>>
>
>  
>


--
Tom Radcliffe, Ph.D., P.Eng.
President, Predictive Patterns Software Inc.
http://www.predictivepatterns.com | 613-483-9803
[hidden email]

_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: pick and update

David Gobbi-2
In Python you should never use Register() or Delete().  The python
wrappers tie together the Python GC with VTK and call these for you
automatically.

If you want to keep the data around, you just have to keep a python
reference to it around, you don't need to Register it.  Note that the
data keeps a reference to the source, so you need to break the pipeline
after the Update() if you want the source to be deleted.  In VTK 4, you
would do data.SetSource(None).

 - David

Tom Radcliffe wrote:

> I meant using DeepCopy when I said "make a copy of the output data",
> so you've tried the right thing.  I had forgotten about GC in
> Python--I don't know what effect it might have.  Generally Register
> and UnRegister should be called with a null pointer in C++, which I
> guess is equivalent to None in Python.  The only reason to use
> something other than null is for debugging, so you can see what
> objects have registered something and not unregistered it.
>
> --Tom
>
> Boris Avdeev wrote:
>
>> Thanks for your reply. I tried the second alternative. I guess
>> Delete() method is not exported to Python (because of GC?). I tried to
>> use the following code instead:
>>
>> data.Register(None)
>> data.Update()
>> read.UnRegister(None)
>>
>> It did not do any good and now I get seg.fault at the exit.
>> I did not quite get the copy explanation. What is "make the copy of
>> the data from the reader the start of your pipeline"?
>> I tried the following with as much success as earlier:
>> ...
>> read.Update()
>> data.DeepCopy(read.GetOutput())
>> ...
>>
>> Thanks,
>> Boris
>>
>>
>> On 1/30/06, Tom Radcliffe <[hidden email]> wrote:
>>  
>>
>>> The reader's output will be regenerated during the next Update, so your
>>> changes will be wiped out.  You should pull the data out of the reader
>>> and make a copy.  Then make the copy of the data from the reader the
>>> start of your pipeline.
>>>
>>> To do this without copying you can do something like this (in C++,
>>> something similar in Python):
>>>
>>> vtkPolyData* pData = pReader->GetOutput();
>>> pData->Register(0);
>>> pReader->Delete();
>>>
>>> This should drop the reader but keep the data around.
>>>
>>> --Tom
>>>  
>>
>>
>>  
>>
>
>

_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: pick and update

Boris Avdeev
Thanks, that makes sense. However my problem still exists. This is the
code I have now:

    picksR = vtkPolyDataReader()
    picksR.SetFileName(fname)  #points
    picks = picksR.GetOutput()
    picks.Update()
    picks.SetSource(None)
    del picksR

    #reconstruct a surface from the scatteres points
    proxy = vtkSurfaceReconstructionFilter()
    proxy.SetInput(picks)
    surf = vtkContourFilter()
    surf.SetValue(0,0.0)
    surf.SetInput(proxy.GetOutput())

    surfMap = vtkPolyDataMapper()
    surfMap.SetInput(surf.GetOutput())
    surfAct = vtkActor()
    surfAct.SetMapper(surfMap)
    ren.AddActor(surfAct)

    def PickingFunction(obj, event):
        global picks, renWin
        picks.GetPoints().InsertNextPoint(obj.GetPicker().GetPickPosition())
        renWin.Render()      #The surface does not change

        writer = vtkPolyDataWriter()
        writer.SetFileName(fname)
        writer.SetInput(picks)
        writer.Write()            # This works fine

    iact.AddObserver("EndPickEvent", PickingFunction)

Any ideas?

Thanks,
Boris

On 1/30/06, David Gobbi <[hidden email]> wrote:

> In Python you should never use Register() or Delete().  The python
> wrappers tie together the Python GC with VTK and call these for you
> automatically.
>
> If you want to keep the data around, you just have to keep a python
> reference to it around, you don't need to Register it.  Note that the
> data keeps a reference to the source, so you need to break the pipeline
> after the Update() if you want the source to be deleted.  In VTK 4, you
> would do data.SetSource(None).
>
>  - David
>
_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers