04.08.2013 Views

pdf for printing - Image Processing and Analysis Group

pdf for printing - Image Processing and Analysis Group

pdf for printing - Image Processing and Analysis Group

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

TCL – part 2<br />

# actor coordinates geometry, properties, trans<strong>for</strong>mation<br />

vtkActor aSphere<br />

aSphere SetMapper map<br />

[aSphere GetProperty] SetColor 0 0 1; # blue<br />

# create a renderer add the sphere<br />

vtkRenderer ren1<br />

ren1 AddActor aSphere<br />

ren1 SetBackground 1 1 1;# Background color white<br />

# create a window to render into<br />

vtkRenderWindow renWin<br />

renWin AddRenderer ren1<br />

# create an interactor<br />

vtkRenderWindowInteractor iren<br />

iren SetRenderWindow renWin<br />

vtkRenderWindowInteractor<br />

# Render an image; since no lights/cameras specified, created automatically<br />

renWin Render<br />

Java – part 1<br />

import vtk.*;<br />

public class test {<br />

// in the static constructor we load in the native code<br />

// The libraries must be in your path to work<br />

static {<br />

System.loadLibrary("vtkCommonJava"); System.loadLibrary("vtkFilteringJava");<br />

System.loadLibrary("vtkIOJava"); System.loadLibrary("vtkImagingJava");<br />

System.loadLibrary("vtkGraphicsJava"); System.loadLibrary("vtkRenderingJava");<br />

}<br />

public static void main (String[] args)<br />

{<br />

// create sphere geometry<br />

vtkSphereSource sphere = new vtkSphereSource();<br />

sphere.SetRadius(1.0);<br />

sphere.SetThetaResolution(18);<br />

sphere.SetPhiResolution(18);<br />

// map to graphics objects<br />

vtkPolyDataMapper map = new vtkPolyDataMapper();<br />

map.SetInput(sphere.GetOutput());<br />

// actor coordinates geometry, properties, trans<strong>for</strong>mation<br />

vtkActor aSphere = new vtkActor();<br />

aSphere.SetMapper(map);<br />

aSphere.GetProperty().SetColor(0,0,1); // color blue<br />

Programming Languages<br />

Mapper<br />

Actor<br />

Renderer<br />

Render<br />

Window<br />

Source<br />

Mapper<br />

Actor<br />

• Interpreted vs Compiled Languages<br />

– Note that classic distinction is blurring thanks to onthe-fly<br />

compilers (e.g. Tcl 8.x)<br />

• Interpreted Languages<br />

– e.g. BASIC, Matlab, Tcl, Python, Perl …<br />

– Fast development, computationally inefficient<br />

• Compiled Languages<br />

– e.g. C/C++, Fortran, Java(?)<br />

– Computationally more efficient but extra step in<br />

development cycle<br />

#include "vtkSphereSource.h"<br />

#include "vtkPolyDataMapper.h"<br />

#include "vtkActor.h"<br />

#include "vtkRenderWindow.h"<br />

#include "vtkRenderer.h"<br />

#include "vtkRenderWindowInteractor.h"<br />

C++ – part 1<br />

void main ()<br />

{<br />

// create sphere geometry<br />

vtkSphereSource *sphere = vtkSphereSource::New();<br />

sphere->SetRadius(1.0);<br />

sphere->SetThetaResolution(18);<br />

sphere->SetPhiResolution(18);<br />

vtkPolyDataMapper *map = vtkPolyDataMapper::New();<br />

map->SetInput(sphere->GetOutput());<br />

// actor coordinates geometry, properties, trans<strong>for</strong>mation<br />

vtkActor *aSphere = vtkActor::New();<br />

aSphere->SetMapper(map);<br />

aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue<br />

…<br />

}<br />

Source<br />

Mapper<br />

Actor<br />

Comment on Language Selection<br />

• VTK can be used from any one of C++/Java/Tcl<br />

<strong>and</strong> Python<br />

• Some features not accessible from the scripting<br />

languages<br />

• In Java/Tcl/Python our own code can:<br />

– Be used to join st<strong>and</strong>ard VTK elements in a pipeline<br />

– Call existing VTK routines<br />

• In C++ we can do all of the above plus<br />

– Write new filters/sources etc as required (which can in<br />

turn be used from the other languages)<br />

Interpreted Languages<br />

• Program execution is per<strong>for</strong>med by the interpreter or<br />

shell e.g.<br />

– TCL (tcsh/wish)<br />

• Allows <strong>for</strong> interactive comm<strong>and</strong> execution<br />

• Faster development cycle because there is no lengthy<br />

compilation step<br />

• Slower per<strong>for</strong>mance as each comm<strong>and</strong> needs to be<br />

parsed be<strong>for</strong>e it is executed<br />

• Simpler to use!

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!