1package require vtk 2package require vtkinteraction 3package require vtktesting 4 5#define a Single Cube 6vtkFloatArray Scalars 7 Scalars InsertNextValue 1.0 8 Scalars InsertNextValue 0.0 9 Scalars InsertNextValue 0.0 10 Scalars InsertNextValue 0.0 11 Scalars InsertNextValue 0.0 12 Scalars InsertNextValue 0.0 13 14vtkPoints Points 15 Points InsertNextPoint 0 0 0 16 Points InsertNextPoint 1 0 0 17 Points InsertNextPoint 1 1 0 18 Points InsertNextPoint 0 1 0 19 Points InsertNextPoint .5 .5 1 20 21vtkIdList Ids 22 Ids InsertNextId 0 23 Ids InsertNextId 1 24 Ids InsertNextId 2 25 Ids InsertNextId 3 26 Ids InsertNextId 4 27 28vtkUnstructuredGrid Grid 29 Grid Allocate 10 10 30 Grid InsertNextCell 14 Ids 31 Grid SetPoints Points 32 [Grid GetPointData] SetScalars Scalars 33 34#Clip the pyramid 35vtkClipDataSet clipper 36 clipper SetInputData Grid 37 clipper SetValue 0.5 38 39# build tubes for the triangle edges 40# 41vtkExtractEdges pyrEdges 42 pyrEdges SetInputConnection [clipper GetOutputPort] 43vtkTubeFilter pyrEdgeTubes 44 pyrEdgeTubes SetInputConnection [pyrEdges GetOutputPort] 45 pyrEdgeTubes SetRadius .005 46 pyrEdgeTubes SetNumberOfSides 6 47vtkPolyDataMapper pyrEdgeMapper 48 pyrEdgeMapper SetInputConnection [pyrEdgeTubes GetOutputPort] 49 pyrEdgeMapper ScalarVisibilityOff 50vtkActor pyrEdgeActor 51 pyrEdgeActor SetMapper pyrEdgeMapper 52 eval [pyrEdgeActor GetProperty] SetDiffuseColor $lamp_black 53 [pyrEdgeActor GetProperty] SetSpecular .4 54 [pyrEdgeActor GetProperty] SetSpecularPower 10 55 56#shrink the triangles so we can see each one 57vtkShrinkFilter aShrinker 58 aShrinker SetShrinkFactor 1 59 aShrinker SetInputConnection [clipper GetOutputPort] 60vtkDataSetMapper aMapper 61 aMapper ScalarVisibilityOff 62 aMapper SetInputConnection [aShrinker GetOutputPort] 63vtkActor Pyrs 64 Pyrs SetMapper aMapper 65 eval [Pyrs GetProperty] SetDiffuseColor $banana 66 67#build a model of the pyramid 68vtkExtractEdges Edges 69 Edges SetInputData Grid 70vtkTubeFilter Tubes 71 Tubes SetInputConnection [Edges GetOutputPort] 72 Tubes SetRadius .01 73 Tubes SetNumberOfSides 6 74vtkPolyDataMapper TubeMapper 75 TubeMapper SetInputConnection [Tubes GetOutputPort] 76 TubeMapper ScalarVisibilityOff 77vtkActor CubeEdges 78 CubeEdges SetMapper TubeMapper 79 eval [CubeEdges GetProperty] SetDiffuseColor $khaki 80 [CubeEdges GetProperty] SetSpecular .4 81 [CubeEdges GetProperty] SetSpecularPower 10 82 83# build the vertices of the pyramid 84# 85vtkSphereSource Sphere 86 Sphere SetRadius 0.04 87 Sphere SetPhiResolution 20 88 Sphere SetThetaResolution 20 89vtkThresholdPoints ThresholdIn 90 ThresholdIn SetInputData Grid 91 ThresholdIn ThresholdByUpper .5 92vtkGlyph3D Vertices 93 Vertices SetInputConnection [ThresholdIn GetOutputPort] 94 Vertices SetSourceConnection [Sphere GetOutputPort] 95vtkPolyDataMapper SphereMapper 96 SphereMapper SetInputConnection [Vertices GetOutputPort] 97 SphereMapper ScalarVisibilityOff 98vtkActor CubeVertices 99 CubeVertices SetMapper SphereMapper 100 eval [CubeVertices GetProperty] SetDiffuseColor $tomato 101 eval [CubeVertices GetProperty] SetDiffuseColor $tomato 102 103#define the text for the labels 104vtkVectorText caseLabel 105 caseLabel SetText "Case 1" 106 107vtkTransform aLabelTransform 108 aLabelTransform Identity 109 aLabelTransform Translate -.2 0 1.25 110 aLabelTransform Scale .05 .05 .05 111 112vtkTransformPolyDataFilter labelTransform 113 labelTransform SetTransform aLabelTransform 114 labelTransform SetInputConnection [caseLabel GetOutputPort] 115 116vtkPolyDataMapper labelMapper 117 labelMapper SetInputConnection [labelTransform GetOutputPort]; 118 119vtkActor labelActor 120 labelActor SetMapper labelMapper 121 122#define the base 123vtkCubeSource baseModel 124 baseModel SetXLength 1.5 125 baseModel SetYLength .01 126 baseModel SetZLength 1.5 127vtkPolyDataMapper baseMapper 128 baseMapper SetInputConnection [baseModel GetOutputPort] 129vtkActor base 130 base SetMapper baseMapper 131 132# Create the RenderWindow, Renderer and both Actors 133# 134vtkRenderer ren1 135vtkRenderWindow renWin 136 renWin AddRenderer ren1 137vtkRenderWindowInteractor iren 138 iren SetRenderWindow renWin 139 140# position the base 141base SetPosition .5 -.09 .5 142 143ren1 AddActor pyrEdgeActor 144ren1 AddActor base 145ren1 AddActor labelActor 146ren1 AddActor CubeEdges 147ren1 AddActor CubeVertices 148ren1 AddActor Pyrs 149eval ren1 SetBackground $slate_grey 150iren AddObserver UserEvent {wm deiconify .vtkInteract} 151 152renWin SetSize 400 400 153 154ren1 ResetCamera 155[ren1 GetActiveCamera] Dolly 1.3 156[ren1 GetActiveCamera] Elevation 15 157ren1 ResetCameraClippingRange 158 159renWin Render 160iren Initialize 161 162set mask "1 2 4 8 16 32" 163proc cases {id} { 164 global mask 165 for {set i 0} {$i < 5} {incr i} { 166 set m [lindex $mask $i] 167 if {[expr $m & $id] == 0} { 168 Scalars SetValue $i 0 169 } else { 170 Scalars SetValue $i 1 171 } 172 caseLabel SetText "Case $id" 173 } 174 Grid Modified 175 renWin Render 176} 177 178cases 20 179 180wm withdraw . 181 182