VTK/Using JRuby

From KitwarePublic
< VTK
Revision as of 17:15, 10 June 2007 by Vm9Iet (talk | contribs)
Jump to navigationJump to search

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