[vtkusers] Dynamic creation of VTK objects in Tcl
Andy Cedilnik
andy.cedilnik at kitware.com
Thu Jul 31 08:45:25 EDT 2003
Hi Magnus,
Sorry,
proc Create { type } {
if { [ info exists Prototype${type} ] == 0 } {
vtk$type Prototype${type}
}
return [ Prototype${type} New Instance ]
}
Andy
On Thu, 2003-07-31 at 08:36, Magnus Gedda wrote:
> Yay, looks nice. One problem though (if I understood the solution
> properly). Will it not occur an error if i try to create a new actor
> from the same dynamic functions?
>
> Like this:
>
> --------------------------------------------
> proc Create { type } {
> vtk$type t
> return t
> }
>
> set ob1 [ Create "Mapper" ]
>
> set ob2 [ Create "Actor" ]
> $ob2 SetMapper $ob1
>
> set ob3 [ Create "Actor" ] ;# "Object already exist" error?
> $ob3 SetMapper $ob1
> --------------------------------------------
>
>
> But if that is the case, could a solution look like this?:
>
> --------------------------------------------
> proc Create { type name } {
> vtk$type $name
> return $name
> }
>
> set ob1 [ Create "Mapper" "ob1-mapper" ]
>
> set ob2 [ Create "Actor" "ob2-actor" ]
> $ob2 SetMapper $ob1
>
> set ob3 [ Create "Actor" "ob3-actor" ]
> $ob3 SetMapper $ob1
> --------------------------------------------
>
>
>
> Regards
>
> Magnus Gedda,
> Sidec Technologies
>
>
> On Thu, 2003-07-31 at 14:18, Andy Cedilnik wrote:
> > Hi Magnus,
> >
> > What about this:
> >
> > proc CreateMapper { } {
> > vtkMapper m
> > return m
> > }
> > proc CreateActor { } {
> > vtkActor a
> > return a
> > }
> >
> > set actor [ CreateActor ]
> > set mapper [ CreateMapper ]
> >
> > $actor SetMapper $mapper
> >
> > Then you could say something like:
> >
> > proc Create { type } {
> > vtk$type t
> > return t
> > }
> >
> > set ob1 [ Create "Mapper" ]
> > set ob2 [ Create "Actor" ]
> >
> > $ob2 SetMapper $ob1
> >
> > Looks good?
> >
> >
> >
> > On Thu, 2003-07-31 at 03:58, Magnus Gedda wrote:
> > > Is there a way to create VTK objects (sources, filters, etc.)
> > > dynamically in Tcl?
> > >
> > > I don't want to be restrained to using predefined objects since it would
> > > limit my application tremendously. So I need to write a object factory
> > > of some sort, but how do I do it in Tcl?
> >
> >
More information about the vtkusers
mailing list