Tuesday, February 21, 2006

VTK: Copy Image Data and run stuff in the background

I spent quite some time to figure out how to copy image data. I am setting up a pipeline in a Java method but want a copy of the image data in one of the fields, hence:


public void runSegmentation() {
//set up progress bar and hourglass cursor
progressBar = new ProgressBar("Segementation");
progressBar.OpenProgressBar();
currentSegmentation.setProgressBar(progressBar);
renWin.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

if (!currentSegmentation.is3D()) {
//set up pipeline

vtkImageReslice reslice2 = new vtkImageReslice();
reslice2.SetOutputExtent(actor.GetDisplayExtent());
reslice2.SetInput(canvas.GetOutput());
reslice2.Update();

currentSegmentation.setModel(reslice2.GetOutput()); //use the canvas as model;-)

undo = true;
slice = actor.GetSliceNumber();
//copy the image
undoImage = new vtkImageData();
undoImage.DeepCopy(canvas.GetOutput());

}

//set up segmentation in the background
SwingWorker worker = new SwingWorker() {
@Override
public Object construct() {
if (!currentSegmentation.is3D()) {
currentSegmentation.Update();
canvas.CopyImage(currentSegmentation.GetOutput());
}
return null;
}

@Override
public void finished() {
currentSegmentation.SetInput(null);
currentSegmentation.setModel(null);
pane.refresh(); //refresh view
progressBar.CloseProgressBar();
renWin.setCursor(transparentCursor);
}

};

//run segmentation in the background
worker.start();

}
}


As you see I have thrown in some multithreading (segmenting data takes awfully long) but the code to copy the image data is essentially:

undoImage = new vtkImageData();
undoImage.DeepCopy(canvas.GetOutput());

I think DeepCopy is the right command but it took me a while. It might also be that the ImageCanvas is a weird construct though.

0 Comments:

Post a Comment

<< Home