[vtkusers] Delete an Object created in procedure before returning it

Sanket Jain jainsanket1 at gmail.com
Thu Dec 17 18:58:24 EST 2009


Thank You Bill. It worked!!

Sanket Jain

On Thu, Dec 17, 2009 at 10:17 AM, Bill Lorensen <bill.lorensen at gmail.com>wrote:

> In tcl, if you are reusing an object in a proc, just put a catch
> around the construction:
>
> catch {vtkPolyDataMapper partMapper}
>
> The first time the statement is executed it will create partMapper.
> Subsequent calls, the statement will fail silently.
>
> Be careful when you are first writing the code. The catch can hide errors.
>
> Bill
>
> On Thu, Dec 17, 2009 at 10:26 AM, Sanket Jain <jainsanket1 at gmail.com>
> wrote:
> > Hello Experts,,
> >
> > My question is a TCL question rather than a VTK question. I hope it is
> fine
> > with other members. At the end, is the part of my code required for
> > understanding my question.
> >
> > If you look at my code, I have defined 2 procedures: MakeSTLActor and
> > MakeDataActor. The main function call these procedures whenever required.
> > Now, when these procedures are called for the 1st time, only the
> highlighted
> > portion of the procedure gets the job done.
> >
> > If the procedure is called again for the 2nd time, the interpreter
> > give error saying that objects partMapper and partActoro (in MakeSTLActor
> > procedure; this also implies for the objects in the other procedure) is
> > already created. So, I can delete the partMapper object as soon as its
> job
> > is done (specifically, after creation of partActoro). But I cannot delete
> > partActoro because I have to return this object. So, next time when the
> > procedure is called, I get the error regarding the existence of
> partActoro.
> >
> > At, this point I am using flags in my procedures (closeevent, isotrack),
> to
> > delete the objects before calling the procedure for 2nd time. Although,
> my
> > script runs without any bugs, I think this might not be the most elegant
> way
> > of doing it. So, does any one knows a way by which I can avoid using the
> > flags in my procedure and delete the objects (partActoro and dataActoro
> in
> > the 2 procedures) before/while the return to the main function.
> >
> > Let me know if I need to clarify my question.
> >
> > Thank You,
> >
> > Sanket Jain
> >
> >
> > # CODE STARTS HERE......
> >
> > package require vtk
> >
> > package require
> >
> > vtkinteractionpackage require vtktesting
> >
> > #... Relevant Tk Codes for building the GUI.
> >
> > proc main {} {
> >
> > #......Some Relevant TCL Codes
> >
> > vtkActor partActor
> >
> > set partActor [MakeSTLActor vtkSTLReader part]
> >
> > [$partActor GetProperty] SetOpacity 1
> >
> > vtkActor dataActor
> >
> > set dataActor [MakeDataActor vtkConnectivityFilter connect]
> >
> > #.... Other Relevant TCL Codes
> >
> > }
> >
> > #Make Actor for STL File
> >
> > proc MakeSTLActor {vtkSTLReader part} {
> >
> > global closeevent
> >
> > global isotrack
> >
> > if {$isotrack==1} {
> >
> > partMapper Delete
> >
> > partActoro Delete
> >
> > }
> >
> > if {$closeevent == 0} {
> >
> > partMapper Delete
> >
> > partActoro Delete
> >
> > } else {
> >
> > vtkPolyDataMapper partMapper
> >
> > partMapper SetInputConnection [$part GetOutputPort]
> >
> > vtkActor partActoro
> >
> > partActoro SetMapper partMapper
> >
> > return partActoro
> >
> > }
> >
> > }
> >
> > # Makes Actor for the Original Data
> >
> > proc MakeDataActor {vtkConnectivityFilter connecto} {
> >
> > global closeevent
> >
> > global isotrack
> >
> > if {$isotrack==1} {
> >
> > dataMapper Delete
> >
> > prop Delete
> >
> > dataActoro Delete
> >
> > }
> >
> > if {$closeevent == 0} {
> >
> > dataMapper Delete
> >
> > prop Delete
> >
> > dataActoro Delete
> >
> > } else {
> >
> > vtkDataSetMapper dataMapper
> >
> > dataMapper SetInputConnection [$connecto GetOutputPort]
> >
> > vtkProperty prop
> >
> > prop SetOpacity 0.1
> >
> > vtkActor dataActoro
> >
> > dataActoro SetMapper dataMapper
> >
> > dataActoro SetProperty prop
> >
> > dataActoro SetOrigin 0 0 0
> >
> > return dataActoro
> >
> > }
> >
> > }
> >
> > #.... Similarly Defining other procedures
> >
> > #which creates actors and returns to the main
> >
> > #function which renders them.
> >
> > --
> > Sanket Jain
> >
> > _______________________________________________
> > 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
> >
> >
>



-- 
Sanket Jain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091217/ae79d8a2/attachment.htm>


More information about the vtkusers mailing list