[vtkusers] Mechanism to instantiate multiple vtkAssembly objects at different position

Avinandan Sengupta avinandan.sengupta at gmail.com
Fri Nov 30 22:22:26 EST 2007


Hi,

I would like to instantiate multiple copies of a vtkAssembly object at 
different positions on the renderer window. To achieve this I'm doing 
the following:

  1. Create an actor
  2. Add it to an assembly
  3. Shallow copy the assembly for each copy I want,
  4. Set the position for each of the assembly copies

This approach does not seem to work - either I'm doing something wrong, 
or this is not supported. I'm reproducing the Tcl code below - I plan to 
migrate the same in C++ once the prototype works.

Thanks,
Avi

########### start of code ##############
package require vtk
package require vtkinteraction
#package require vtktesting

vtkPoints aPoints

#0
aPoints InsertNextPoint 350.00 125.00 0.00
aPoints InsertNextPoint 200.00  75.00 0.00

#2
aPoints InsertNextPoint 100.00 100.00 0.00
aPoints InsertNextPoint 100.00 200.00 0.00

#4
aPoints InsertNextPoint 180.00 270.00 0.00
aPoints InsertNextPoint 250.00 100.00 0.00

#6
aPoints InsertNextPoint 350.00 125.00 30.00
aPoints InsertNextPoint 200.00  75.00 30.00

#8
aPoints InsertNextPoint 100.00 100.00 30.00
aPoints InsertNextPoint 100.00 200.00 30.00

#10
aPoints InsertNextPoint 180.00 270.00 30.00
aPoints InsertNextPoint 250.00 100.00 30.00

vtkPolygon aPoly
 [aPoly GetPointIds] SetNumberOfIds 6
 [aPoly GetPointIds] SetId 0 0
 [aPoly GetPointIds] SetId 1 1
 [aPoly GetPointIds] SetId 2 2
 [aPoly GetPointIds] SetId 3 3
 [aPoly GetPointIds] SetId 4 4
 [aPoly GetPointIds] SetId 5 5

vtkPolygon bPoly
 [bPoly GetPointIds] SetNumberOfIds 6
 [bPoly GetPointIds] SetId 0 6
 [bPoly GetPointIds] SetId 1 7
 [bPoly GetPointIds] SetId 2 8
 [bPoly GetPointIds] SetId 3 9
 [bPoly GetPointIds] SetId 4 10
 [bPoly GetPointIds] SetId 5 11

vtkQuad quad1
   [quad1 GetPointIds] SetId 0 0
   [quad1 GetPointIds] SetId 1 1
   [quad1 GetPointIds] SetId 2 7
   [quad1 GetPointIds] SetId 3 6

vtkQuad quad2
   [quad2 GetPointIds] SetId 0 1
   [quad2 GetPointIds] SetId 1 2
   [quad2 GetPointIds] SetId 2 8
   [quad2 GetPointIds] SetId 3 7

vtkQuad quad3
   [quad3 GetPointIds] SetId 0 2
   [quad3 GetPointIds] SetId 1 3
   [quad3 GetPointIds] SetId 2 9
   [quad3 GetPointIds] SetId 3 8

vtkQuad quad4
   [quad4 GetPointIds] SetId 0 3
   [quad4 GetPointIds] SetId 1 4
   [quad4 GetPointIds] SetId 2 10
   [quad4 GetPointIds] SetId 3 9

vtkQuad quad5
   [quad5 GetPointIds] SetId 0 4
   [quad5 GetPointIds] SetId 1 5
   [quad5 GetPointIds] SetId 2 11
   [quad5 GetPointIds] SetId 3 10

vtkQuad quad6
   [quad6 GetPointIds] SetId 0 5
   [quad6 GetPointIds] SetId 1 0
   [quad6 GetPointIds] SetId 2 6
   [quad6 GetPointIds] SetId 3 11

vtkCellArray aPolyArray
aPolyArray InsertNextCell aPoly
aPolyArray InsertNextCell bPoly
aPolyArray InsertNextCell quad1
aPolyArray InsertNextCell quad2
aPolyArray InsertNextCell quad3
aPolyArray InsertNextCell quad4
aPolyArray InsertNextCell quad5
aPolyArray InsertNextCell quad6

# Assign points and cells
vtkPolyData aPolydata
aPolydata SetPoints aPoints
aPolydata SetPolys aPolyArray

vtkTriangleFilter tf
tf SetInput aPolydata

vtkPolyDataMapper aMapper
aMapper SetInput aPolydata
aMapper SetInputConnection [tf GetOutputPort]

vtkActor aActor
aActor SetMapper aMapper
[aActor GetProperty] SetColor 1.0 0.0 0.0

vtkAssembly aAsm1
aAsm1 AddPart aActor
aAsm1 SetPosition 400.5 400.5 400.5

vtkAssembly aAsm2
aAsm2 ShallowCopy aAsm1
aAsm2 SetPosition 1000 1000 1000

vtkRenderer ren1
vtkRenderWindow renWin
 renWin AddRenderer ren1
 renWin SetSize 300 150

vtkRenderWindowInteractor iren
 iren SetRenderWindow renWin

ren1 SetBackground .1 .2 .4
ren1 AddActor aActor
ren1 AddActor aAsm1
ren1 AddActor aAsm2
ren1 ResetCamera

renWin Render

iren AddObserver UserEvent {wm deiconify .vtkInteract}
iren Initialize
wm withdraw .
########### end of code ##############




More information about the vtkusers mailing list