Friday, October 14, 2005

Hibernate Lecture @ UCSD 10/14

Tomorrow I am giving a lecture on Hibernate 3.0. The number of students has more than tripled since I last gave a Hibernate lecture in spring -- seems that with EJB 3.0 and JBoss Hibernate is finally taking off.

To avoid the writing of nasty XML-Files (the main critique of Spring's class) we will be using annotations. I just started doing them yesterday and it seems they are some XDoclets on steroids. Anyway I have uploaded my presentation at and if there is enough interest I might also upload the Lab utilizing Apache Derby as the demo database.

If you want me to come to you and give the 8 hour workshop drop me a note.

Tuesday, October 11, 2005

How to convert a raw file to VTK

Sometimes you get volume-data aka vtkImageData in raw format like from our website In order o be able to read that with vtk (the vtkStructurePointReader will do) you will have to follow these steps:

1. Add a vtkHeader
Because editing the whole file with vi would take to long we build the header in an extra file. The header should look like:

# vtk DataFile Version 2.0
My great file
DIMENSIONS 222 346 1434
Put here the dimensions x, y, z
ASPECT_RATIO 0.1 0.0625 0.0625
The spacing or voxel size
ORIGIN 0 0 0
POINT_DATA 110148408
SCALARS volume_scalars short 1
short=16 Bit, char=8 Bit

Save the file for instance as vtk_header

2. Swap Bytes
Depending on the Endianess and in case you are using 16 Bit, short, data you might need to swap the byte order. You can easily find out if you need this step by just skipping it and seeing if the stuff looks right in vtk. To do it use the following Linux command (Sorry, Windows-People):

dd if=source.raw of=swapped.raw conv=swab

3. Merge the files
Now merge the header with the rawfile using for instance cat:

cat header source.raw > file.vtk

4. Read into VTK
Juts modify one of the Volume16Reader examples and replace the read part with (Java):

vtkStructuredPointsReader v16 = new vtkStructuredPointsReader();

Thursday, October 06, 2005

VTK Triangle Strips

One of the projects I am currently working on is to provide a better model for Diffusion MRI in fibreous white matter. The idea is to output some geometries and use another tool to do the heavy lifting, e. g. the simulation. After the white matter is modeled by some parametric curves it gets triangulated and displayed in VTK as a trinagle strip. The goal is to output this strip in some meaningful way. The code to do so is:

void PrintStrips ( FILE *f, vtkPolyData *mypoly ) {

vtkPoints *mypoints = mypoly->GetPoints ( ) ;
vtkCellArray *mystrips = mypoly->GetStrips ( ) ;

int *indices=mystrips->GetPointer ( ) ;
int numindices=mystrips->GetNumberOfConnectivityEntries ( ) ; //Whoa!
int idx=0;

while ( idx<numindices ) {
int striplen=indices[idx]; //Get length of next strip

for ( int jj=0; ( jj<striplen ) && ( idx<numindices ) ;jj++ ) {
float A[3], B[3], C[3]; //coordinates of triangle vertices
mypoints->GetPoint ( indices[idx], A ) ;
//mypoints->GetPoint ( indices[idx+1], B ) ;
//mypoints->GetPoint ( indices[idx+2], C ) ;
fprintf ( f, "[%f, %f, %f]\n", A[0], A[1], A[2] ) ;
//fprintf ( f, "[%f, %f, %f]\n", B[0], B[1], B[2] ) ;
//fprintf ( f, "[%f, %f, %f]\n", C[0], C[1], C[2] ) ;

The commented code allows you to output instead of triangle strips the data as each triangle. Some programs like Open Inventor like that better. (Also in the for loop change jj<striplen in jj<striplen-2).

Something about triangle strips:
Given the coordinates A, B, C, D, E,... the strip implicitly described by those coordinates give the following triangles: ABC, BCD, CDE, ...

Some software however can't automatically decode that and just deals with polygons. Then you have to be explicit and output ABC, BCD, CDE instead of the strip.