[vtkusers] vtkImageTracerWidget ROI Problem
Sercani
sercanimailgroups at gmail.com
Tue Mar 3 16:02:53 EST 2009
Hi everyone;
I have a problem with vtkImageTracerWidget (i think).I am developing a multi
planar reconstitution project for CT datasets using vtk and java.I want to
draw a closed region on a vtkImageActor and then calculate the voxel count,
min , max scalar values in this region and the density of this region.I' ve
implemented the class below , but something goes wrong here so sometimes the
output of the textactor becomes:
"n:0
min:1.0E299 HU
max:-1.0E299 HU
mean:0.0 HU
den:0.0 mm^3"
Sometimes it shows some other values, but i am not sure the accuracy of
them.I tried every possible combination with vtkExtractVOI,
vtkLinearExtrusionFilter etc. but couldn't manage to fix this.What is wrong
with this code? :
(Panel is an instance of vtkCanvas, and reslice is the active
vtkImageReslice)
import client3d.MPRPanel;
import vtk.vtkExtractVOI;
import vtk.vtkImageAccumulate;
import vtk.vtkImageStencil;
import vtk.vtkImageTracerWidget;
import vtk.vtkLinearExtrusionFilter;
import vtk.vtkPolyData;
import vtk.vtkPolyDataToImageStencil;
import vtk.vtkTextActor;
import vtk.vtkTextProperty;
public class DensityWidget {
private vtkImageTracerWidget itw;
private vtkExtractVOI extract;
private vtkLinearExtrusionFilter extrude;
private MPRPanel panel;
private vtkPolyData poly;
vtkImageStencil stencil;
private double[] range;
private double min;
private double max;
private double diff;
private double avg;
private double[] bounds;
private vtkImageAccumulate accum;
private vtkTextActor textActor;
java.text.DecimalFormat df = new java.text.DecimalFormat("#00.0");
public DensityWidget(MPRPanel panel) {
this.panel = panel;
itw = new vtkImageTracerWidget();
extract = new vtkExtractVOI();
extrude = new vtkLinearExtrusionFilter();
poly = new vtkPolyData();
stencil = new vtkImageStencil();
accum = new vtkImageAccumulate();
textActor = new vtkTextActor();
createVTKPipeline();
}
public void createVTKPipeline() {
extract.SetVOI(panel.getReslice().GetOutputExtent());
extract.SetSampleRate(1, 1, 1);
extract.SetInput(panel.getImagedata());
extract.ReleaseDataFlagOff();
extract.Update();
this.range = extract.GetOutput().GetScalarRange();
this.min = range[0];
this.max = range[1];
this.diff = max - min;
this.avg = (max + min) * 0.5;
this.bounds = extract.GetOutput().GetBounds();
itw.SetCaptureRadius(100000);
itw.GetGlyphSource().SetColor(1, 0, 0);
itw.GetGlyphSource().SetScale(3.0);
itw.GetGlyphSource().SetRotationAngle(45.0);
itw.GetGlyphSource().Modified();
itw.ProjectToPlaneOn();
itw.SetProjectionNormalToZAxes();
itw.SetViewProp(panel.getImageactor());
itw.SetInput(panel.getImagedata());
itw.SetInteractor(panel.getIren());
itw.PlaceWidget();
itw.SnapToImageOn();
itw.AutoCloseOn();
itw.AddObserver("EndInteractionEvent", this, "AdjustROI");
itw.On();
extrude.SetScaleFactor(1);
extrude.SetExtrusionTypeToNormalExtrusion();
extrude.SetVector(0, 0, 1);
stencil.SetInputConnection(extract.GetOutputPort());
stencil.ReverseStencilOff();
stencil.SetBackgroundValue(128);
accum.SetInputConnection(extract.GetOutputPort());
accum.ReverseStencilOff();
accum.SetComponentSpacing(1, 0, 0);
accum.SetComponentExtent(0, (int) diff, 0, 0, 0, 0);
accum.SetComponentOrigin(min, 0, 0);
accum.ReleaseDataFlagOff();
accum.ReverseStencilOff();
accum.IgnoreZeroOff();
vtkTextProperty prop = new vtkTextProperty();
prop.SetFontSize(10);
prop.SetFontFamilyToArial();
prop.BoldOff();
prop.ItalicOff();
prop.ShadowOff();
prop.SetLineSpacing(0.9);
prop.SetJustificationToLeft();
prop.SetVerticalJustificationToTop();
prop.SetColor(1, 1, 0);
textActor.ScaledTextOff();
textActor.SetPosition(100, 40);
textActor.SetTextProperty(prop);
panel.GetRenderer().AddActor(textActor);
panel.resetCameraClippingRange();
panel.Render();
}
public void AdjustROI() {
int closed = itw.IsClosed();
if (closed == 1) {
itw.GetPath(poly);
extrude.SetInput(poly);
extrude.Update();
vtkPolyDataToImageStencil dataToStencil = new
vtkPolyDataToImageStencil();
dataToStencil.SetInputConnection(extrude.GetOutputPort());
dataToStencil.SetOutputSpacing(extract.GetOutput().GetSpacing());
dataToStencil.SetOutputOrigin(extract.GetOutput().GetOrigin());
dataToStencil.SetOutputWholeExtent(extract.GetOutput().GetExtent());
dataToStencil.Update();
stencil.SetStencil(dataToStencil.GetOutput());
stencil.Update();
accum.SetStencil(stencil.GetStencil());
accum.Update();
int aN = accum.GetVoxelCount();
double amin[] = accum.GetMin();
double amax[] = accum.GetMax();
double amean[] = accum.GetMean();
double den = Math.abs(amean[0]) * panel.getSpacing()[0] *
panel.getSpacing()[1] * panel.getSpacing()[2];
String atext = "";
atext += "n:";
atext += aN;
atext += "\n";
atext += "min:" + /*df.format*/ (amin[0]) + " HU";
atext += "\n";
atext += "max:" + /*df.format*/ (amax[0]) + " HU";
atext += "\n";
atext += "mean:" + /*df.format*/ (amean[0]) + " HU";
atext += "\n";
atext += "den:" + /*df.format*/ (den) + " mm^3";
System.out.println(atext);
textActor.SetInput(atext);
textActor.Modified();
textActor.SetPosition(150, 60);
} else {
textActor.SetInput("no ROI");
}
panel.Render();
}
public void destroy() {
itw.Off();
textActor.VisibilityOff();
extract.Delete();
extrude.Delete();
stencil.Delete();
accum.Delete();
textActor.Delete();
itw.Delete();
}
}
Thanks;
Sercan..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090303/5966723a/attachment.htm>
More information about the vtkusers
mailing list