File: TestDiscreteMarchingCubes.tcl

package info (click to toggle)
vtk7 7.1.1%2Bdfsg1-12
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 125,776 kB
  • sloc: cpp: 1,539,582; ansic: 106,521; python: 78,038; tcl: 47,013; xml: 8,142; yacc: 5,040; java: 4,439; perl: 3,132; lex: 1,926; sh: 1,500; makefile: 122; objc: 83
file content (96 lines) | stat: -rw-r--r-- 2,371 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package require vtk
package require vtkinteraction
package require vtktesting

# Create the RenderWindow, Renderer and both Actors
#
vtkRenderer ren1
vtkRenderWindow renWin
    renWin AddRenderer ren1
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin

# Generate some random colors
proc MakeColors {lut n } {
   catch {vtkMath math}
   $lut SetNumberOfColors $n
   $lut SetTableRange 0 [expr $n-1]
   $lut SetScaleToLinear
   $lut Build
   $lut SetTableValue 0 0 0 0 1
   math RandomSeed 5071
   for {set i 1} {$i < $n } {incr i} {
     $lut  SetTableValue $i [math Random .2 1]  [math Random .2 1]  [math Random .2 1]  1
   }
}

vtkLookupTable lut
MakeColors lut 256



set n 20
set radius 10

# This has been moved outside the loop so that the code can be correctly
# translated to python
catch {vtkImageData blobImage}
for {set i 0} {$i < $n} {incr i} {
  catch {vtkSphere sphere}
    sphere SetRadius $radius
    set max [expr 50 - $radius]
    sphere SetCenter [expr int ( [math Random -$max $max] ) ] [expr int ( [math Random -$max $max] ) ] [expr int ( [math Random -$max $max] ) ]

  catch {vtkSampleFunction sampler}
    sampler SetImplicitFunction sphere
    sampler SetOutputScalarTypeToFloat
    sampler SetSampleDimensions 51 51 51
    sampler SetModelBounds -50 50 -50 50 -50 50

  catch {vtkImageThreshold thres}
    thres SetInputConnection [sampler GetOutputPort]
    thres ThresholdByLower [expr $radius * $radius]
    thres ReplaceInOn
    thres ReplaceOutOn
    thres SetInValue [expr $i + 1]
    thres SetOutValue 0
    thres Update

  if {$i == 0} {
      blobImage DeepCopy [thres GetOutput]
  }

  catch {vtkImageMathematics maxValue}
    maxValue SetInputData 0 blobImage
    maxValue SetInputData 1 [thres GetOutput]
    maxValue SetOperationToMax
    maxValue Modified
    maxValue Update

  blobImage DeepCopy [maxValue GetOutput]
}

vtkDiscreteMarchingCubes discrete
  discrete SetInputData blobImage
  discrete GenerateValues $n 1 $n

vtkPolyDataMapper mapper
  mapper SetInputConnection [discrete GetOutputPort]
  mapper SetLookupTable lut
  mapper SetScalarRange 0 [lut GetNumberOfColors]

vtkActor actor
  actor SetMapper mapper

ren1 AddActor actor

renWin Render

# render the image
#
iren AddObserver UserEvent {wm deiconify .vtkInteract}

# prevent the tk window from showing up then start the event loop
wm withdraw .