[vtkusers] Dynamic creation of VTK objects in Tcl

Magnus Gedda vtk at fri.nu
Thu Jul 31 08:36:56 EDT 2003


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