[vtkusers] How to implement algorithm that store intermediate results and have internal variables dependent on the input

David E DeMarle dave.demarle at kitware.com
Mon Jul 23 10:37:54 EDT 2012


On Fri, Jul 20, 2012 at 9:42 AM, Jana Sefcikova <neollie at gmail.com> wrote:
> Hi, I made the segmetation algorithm, that i implemented outside vtk and I
> would like make vtkPolyDataAlgorithm from it.
> My class uses class variables to store intermediate results, such as labels
> for points , also relative depth that depends on input and others.
>
> I want store intermediate results, because I want structure code (as I have
> outside vtk) and I would like give user the possibility continue in
> segmentation.
> But I do not know how to use those variables in vtk way and restore state of
> those variables to constructor state if the input change.
>
> Lot of vtk algorithms that I saw, have all logic inside RequestData and they
> do not store nor pointer to input, nor intermediate results (except for
> example vtkOBBDicer that uses KdTree that is deleted at the end of
> RequestData immediately). Class variables are mostly use as 'algorithm
> characteristic' and they are independent from input.
>
> What is correct implementation of vtk algorithm with internal state
> dependent to input ?
> When I should clear data ? How I can detect that input changed (I store
> pointer to input and compared it, but it is vtk way ?).
> What could be correct way to update input dependent variables when input
> change ?

You can store pointers to various data in internal variables.

VTK's reference counting makes sure that the stored data is not
unexpectedly freed by something outside the algorithm as long as the
container has a reference to it.

To make sure that the object isn't changed unexpectedly by something
outside the algorithm, make a shallow copy of the object that you want
to keep around for later use.

Often they are kept into an internal class instance so that they are
not exposed in the classes header files (PIMPL idiom).

Managing when the cached data needs to be replaced is task specific .
It has to be up the the specific algorithm to decide when it should be
freed up.

>
> Is there any class that could serve as inspiration ?

Examples of internally data caching that comes to mind are
vtkCachedStreamingDemandDrivenPipeline from VTK and
vtkPieceCacheFIlter from ParaView/Plugins/StreamingView/VTK.

> Thanks in advance.
> Jana
>
> _______________________________________________
> 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