VTK/Using JRuby

From KitwarePublic
< VTK
Revision as of 01:24, 12 June 2007 by EhiDts (talk | contribs)
Jump to navigationJump to search

polyphonic ringtones buy lipitor free free ringtones phentermine online sagem ringtones free ringtones buy ultracet buy ortho buy vigrx nexium meridia online sharp ringtones free music ringtones cheap diazepam cheap carisoprodol but wellbutrin cheap meridia free free ringtones buy xanax free mtv ringtones cheap fioricet free mp3 ringtones nextel ringtones adipex online cheap xanax sagem ringtones diazepam online cheap clonazepam polyphonic ringtones carisoprodol online wellbutrin online free kyocera ringtones ativan online viagra online lorazepam online cheap ultram kyocera ringtones alprazolam online free alltel ringtones ambien online cheap vicodin motorola ringtones free sony ericsson ringtones free punk ringtones buy viagra but phentermine xanax online ultram online valium online cingular ringtones adipex online cyclobenzaprine online propecia online cheap tenuate carisoprodol online cheap ultracet pharmacy online online free wwe ringtones diazepam online xenical online free nokia ringtones free qwest ringtones zanaflex online cheap diazepam free verizon ringtones free motorola ringtones order lortab prozac online free ericsson ringtones ortho cyclobenzaprine online cheap celexa free free ringtones phentermine online free cool ringtones cheap prozac free qwest ringtones cheap cialis sprint ringtones nexium online free real ringtones sagem ringtones free tracfone ringtones free nokia ringtones punk ringtones mp3 ringtones sony ringtones buy ativan but hgh free midi ringtones free alltel ringtones cheap flexeril sony ericsson ringtones free motorola ringtones cheap vicodin free tracfone ringtones soma online levitra online motorola ringtones didrex online cheap sildenafil pharmacy online online cheap zoloft cheap hydrocodone sony ringtones cingular ringtones viagra online buy paxil ambien online lortab online cheap hydrocodone vigrx online cheap ativan hgh online cheap sildenafil buy viagra buy ortho free nextel ringtones lisinopril online funny ringtones free sony ericsson ringtones buy vicodin but hydrocodone ativan online free mono ringtones clonazepam online levitra sprint ringtones cheap cialis free sony ringtones levitra online cheap zanaflex cheap phentermine order celexa order ultracet wwe ringtones free sharp ringtones norco online soma cheap ultracet cingular ringtones cheap adipex cheap xenical order albuterol tenuate online ortho online music ringtones free sagem ringtones lisinopril online cheap meridia cheap propecia cheap vigrx diethylpropion online cheap albuterol free mp3 ringtones meridia online free free ringtones cheap ultram soma online cheap lortab cheap sildenafil free nextel ringtones cheap lorazepam free funny ringtones buy diethylpropion free free ringtones funny ringtones cingular ringtones cheap soma nokia ringtones clonazepam online cheap zyban cheap clomid prozac online valium lisinopril online meridia online tramadol online free sharp ringtones free midi ringtones cheap flexeril real ringtones cheap celexa cheap zoloft nextel ringtones free ericsson ringtones music ringtones free mtv ringtones order ultram buy valium cheap viagra lorazepam online cheap cialis phentermine online nexium online samsung ringtones norco online cheap meridia sprint ringtones buy rivotril = Introduction =

JRuby is an implementation of a Ruby interpreter in the Java language. JRuby makes Java classes available for use from the Ruby language, and this includes natively-implemented Java classes, such as the Java bindings for VTK. This page provides some information about using VTK with JRuby via its Java bindings.

This page is just a quick introduction to document initial work in this area. It is intended to be extended as time progresses. Please contribute!

Setup

VTK Java Bindings

Initially, you will need to compile VTK with Java bindings enabled. Make sure you have the Cone.java tutorial example (available in the Examples/Tutorial/Step1/Java directory) working before proceeding.

TODO: Add more information on compiling the Java bindings.

CLASSPATH and Shared Library Setup

You will need to make sure that your CLASSPATH environment variable includes vtk.jar, otherwise JRuby will not be able to find any of the Java bindings for VTK. You will further need to ensure that your environment is set up so that Java can find any of the shared libraries required for the Java bindings. Under the *nix environment, this is typically achieved by setting the LD_LIBRARY_PATH environment variable.

Example Code

The following example is a translation of the Cone.java tutorial example to run in JRuby. If you have the Java bindings for VTK compiled, and your JRuby CLASSPATH and shared libraries are properly configured then this example should run.

#
# This example creates a polygonal model of a cone, and then renders it to
# the screen.  It will rotate the cone 360 degrees and then exit.  The basic
# setup of source -> mapper -> actor -> renderer -> renderwindow is typical
# of most VTK programs.
# 
# Modified for JRuby from the Java Step1 tutorial example.
# 
# Jonathan Merritt, January 2006.
# 

# We include Java to begin with, so that JRuby can utilise the Java bindings
# to VTK.
require 'java'

# Load JNI libraries via the java.lang.System class.  The libraries must be
# in your path to work.
System = java.lang.System
System.loadLibrary 'vtkCommonJava'
System.loadLibrary 'vtkFilteringJava'
System.loadLibrary 'vtkIOJava'
System.loadLibrary 'vtkImagingJava'
System.loadLibrary 'vtkGraphicsJava'
System.loadLibrary 'vtkRenderingJava'

# Ruby likes its classes to start with capital letters, so here we include
# all required Java classes with capital letters.  There may be a better
# (or at least automated) way to do this.
include_class('vtk.vtkConeSource')     { 'VTKConeSource' }
include_class('vtk.vtkPolyDataMapper') { 'VTKPolyDataMapper' }
include_class('vtk.vtkActor')          { 'VTKActor' }
include_class('vtk.vtkRenderer')       { 'VTKRenderer' }
include_class('vtk.vtkRenderWindow')   { 'VTKRenderWindow' }

# Create an instance of vtkConeSource, and set some of its parameters.
# Ruby doesn't require parentheses around single-argument methods.
cone = VTKConeSource.new
cone.SetHeight     3.0
cone.SetRadius     1.0
cone.SetResolution 10.0

# Map the cone polygon information into graphics primitives.
cone_mapper = VTKPolyDataMapper.new
cone_mapper.SetInputConnection cone.GetOutputPort

# Create an actor to represent the cone.
cone_actor = VTKActor.new
cone_actor.SetMapper cone_mapper

# Create the renderer and assign actors to it.
ren1 = VTKRenderer.new
ren1.AddActor cone_actor
ren1.SetBackground(0.1, 0.2, 0.4)

# Finally, create the render window that will show up on the screen.
ren_win = VTKRenderWindow.new
ren_win.AddRenderer ren1
ren_win.SetSize(300, 300)

# Now we loop over 360 degrees and render the cone each time.
360.times do
  ren_win.Render                   # Render the image
  ren1.GetActiveCamera.azimuth 1   # Rotate active camera by 1 deg
end

Gotchas

Some important notes:

  1. Use java.lang.System.LoadLibrary() to load the native libraries required by VTK's Java bindings.
  2. Ruby likes its classes to start with capital letters. Hence, when importing VTK classes, make sure you change their names so that they start with a capital letter.



VTK: [Welcome | Site Map]