Simple Cone - Groovy Way

Show a VTK cone using Groovy's SwingBuilder.
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
import groovy.swing.SwingBuilder
import javax.swing.JFrame
import vtk.*
 
/*
 * Create a cone and display it in an application window using Groovy's SwingBuilder
 */
 
// Setup VTK rendering panel, this also loads VTK native libraries
def renWin = new vtkPanel()
 
// Setup cone rendering pipeline
def cone = new vtkConeSource()
cone.SetResolution(8)
 
def coneMapper = new vtkPolyDataMapper()
coneMapper.SetInputConnection(cone.GetOutputPort())
 
def coneActor = new vtkActor()
coneActor.SetMapper(coneMapper)
 
renWin.GetRenderer().AddActor(coneActor)
renWin.GetRenderer().ResetCamera()
 
// Create the main application window
new SwingBuilder().frame(
        title: "GroovyCone",
        defaultCloseOperation: JFrame.DISPOSE_ON_CLOSE,
        show: true,
        pack: true) {
  widget(renWin)
}