[vtkusers] Traversing (browsing) VTK pipeline
David E DeMarle
dave.demarle at kitware.com
Tue Aug 31 09:16:09 EDT 2010
very nice thanks!
David E DeMarle
Kitware, Inc.
R&D Engineer
28 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-371-3971 x109
2010/8/31 Андрей Траченко <goodrone at gmail.com>:
> Thank you, David,
> your example helped me to find the API I was looking for.
>
> I've written a generic class in Python to browse the pipeline starting
> with vtkRenderer, and also a simple inherited class to show how to use
> it. I hope it could be useful for somebody.
>
> def iterate_collection(coll):
> number = coll.GetNumberOfItems()
> for i in xrange(number):
> yield coll.GetItemAsObject(i)
>
> class PipelineBrowser(object):
> """ Class for browsing a pipeline built using
> x1.SetInputConnection(x2.GetOutputPort()) pattern.
>
> Pass a vtkRenderer instance and call browse().
> Inherit from this class and overwrite on_* methods.
> """
> def __init__(self, ren):
> """ ren is a vtkRenderer """
> self.ren = ren
> def browse(self):
> self.browse_renderer(self.ren)
>
> def on_renderer(self, ren):
> pass
> def browse_renderer(self, ren):
> self.on_renderer(ren)
> for actor in iterate_collection(ren.GetActors()):
> self.browse_actor(actor)
>
> def on_actor(self, actor):
> pass
> def browse_actor(self, actor):
> self.on_actor(actor)
> self.browse_algorithm(actor.GetMapper(), 0, actor)
>
> def on_algorithm(self, alg, level, parent):
> pass
> def browse_algorithm(self, alg, level, parent):
> self.on_algorithm(alg, level, parent)
> for port in range(alg.GetNumberOfInputPorts()):
> for index in range(alg.GetNumberOfInputConnections(port)):
> input_alg = alg.GetInputConnection(port, index).GetProducer()
> self.browse_algorithm(input_alg, level + 1, alg)
>
> class PipelinePrinter(PipelineBrowser):
> """ Simple pipeline browser, printing class names to stdout """
> def on_renderer(self, ren):
> print "Renderer:", ren.GetClassName()
> def on_actor(self, actor):
> print " Actor:", actor.GetClassName()
> def on_algorithm(self, alg, level, parent):
> indent = " " * (level + 2) * 2
> print indent + "Algorithm:", alg.GetClassName()
>
> Andrew
>
> 2010/8/31 David E DeMarle <dave.demarle at kitware.com>:
>> Here is some code I wrote long ago that runs up the pipeline to find
>> out who the progenitor was.
>>
>> void vtkStreamingUpdateSuppressor::PrintPipe(vtkAlgorithm *alg)
>> {
>> //for debugging, this helps me understand which US is which in the messages
>> vtkAlgorithm *algptr = alg;
>> if (!algptr) return;
>> if (algptr->GetNumberOfInputPorts() &&
>> algptr->GetNumberOfInputConnections(0))
>> {
>> vtkAlgorithmOutput *ao = algptr->GetInputConnection(0,0);
>> if (ao)
>> {
>> algptr = ao->GetProducer();
>> this->PrintPipe(algptr);
>> }
>> cerr << "->";
>> }
>> cerr << alg->GetClassName();
>> }
>>
>> Note it only traces up the primary input so it doesn't handle merging,
>> and of course it is traversing only upward, so it doesn't handle
>> branching either.
>>
>> I've always meant to, but have not yet, put together a more complete
>> pipeline examiner. The API you need to do that should be found almost
>> exclusively in vtkExecutive and vtkAlgorithm.
>>
>> David E DeMarle
>> Kitware, Inc.
>> R&D Engineer
>> 28 Corporate Drive
>> Clifton Park, NY 12065-8662
>> Phone: 518-371-3971 x109
>>
>>
>>
>> 2010/8/27 Андрей Траченко <goodrone at gmail.com>:
>>> Another question of the same nature:
>>>
>>> given a vtkAlgorithm, can I tell what other algorithms are connected
>>> to it? I suspect I should use something like vtkExecutive, but I can't
>>> fugure out how.
>>>
>>> 2010/8/27 Андрей Траченко <goodrone at gmail.com>:
>>>> Hello,
>>>>
>>>> I'd like to browse a given VTK pipeline, where filters are connected
>>>> with a->SetInputConnection(b->GetOutputPort()), i.e. get a pointer to
>>>> every filter in the pipeline. Is it possible to do? Where do I start?
>>>> Can I browse it starting with a vtkRenderer?
>>>>
>>>> Thank you!
>>>> Andrew
>>>>
>>> _______________________________________________
>>> 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