[vtkusers] transform using vtkboxwidget ,
Ali Habib
ali.mahmoud.habib at gmail.com
Thu Jul 29 17:04:21 EDT 2010
Dear All,
I am using vtkboxwidget,and vtkclippolydata with two vtkactor.
the problem is that the transformation make the selected actor to be far
from the vtk box widget , how to keep it withen the vtkboxwidget boundry
I use the following code . how to fix this problem , attached is the photo
of the output
public Form1()
{
InitializeComponent();
this.AddInputToWindow(this.vtkFormsWindowControl1.GetRenderWindow() );
}
void AddInputToWindow(vtk.vtkRenderWindow renWin )
{
vtk.vtkDICOMImageReader VDR = new vtk.vtkDICOMImageReader();
VDR.SetDirectoryName(@"G:\Master
Degree\DataSet\case2\DICOM\PA1\ST1\SE2");
VDR.SetDataOrigin(0, 0, 0);
VDR.Update();
// decrease the dataset data for large data preprocessing
vtkImageShrink3D VIS = new vtkImageShrink3D();
VIS.SetShrinkFactors(2, 2, 2);
VIS.SetInputConnection(VDR.GetOutputPort());
VIS.Update();
vtkImageThreshold VIT = new vtkImageThreshold();
VIT.ThresholdBetween(200, 2000);
VIT.SetInputConnection(VIS.GetOutputPort());
VIT.Update();
///// Start the creation of volume rendering
//1. Gget the range of data
vtk.vtkImageChangeInformation VIC = new
vtk.vtkImageChangeInformation();
VIC.SetInput(VDR.GetOutput());
VIC.CenterImageOn();
VIC.Update();
vtk.vtkImageData VoxelData = new vtk.vtkImageData();
VoxelData = VIC.GetOutput();
double[] metaScalarRange = VoxelData.GetScalarRange();
// Render the skin - Soft tissue
double isovalue = 500;
vtkContourFilter skinExtractor = new vtkContourFilter();
skinExtractor.SetInputConnection(VIT.GetOutputPort());
skinExtractor.SetValue(0, isovalue);
skinExtractor.ComputeGradientsOn();
skinExtractor.Update();
planes = new vtkPlanes();
clipper = new vtkClipPolyData();
clipper.SetInput(skinExtractor.GetOutput());
//clipper.SetClipFunction(planes);
clipper.InsideOutOn();
// clipper.Update();
// Select only the region of interest
vtk.vtkPolyDataMapper SourceMapper = new
vtk.vtkPolyDataMapper();
SourceMapper.SetInput(skinExtractor.GetOutput());
SourceMapper.ScalarVisibilityOff();
vtk.vtkPolyDataMapper SelectionMapper = new
vtk.vtkPolyDataMapper();
SelectionMapper.SetInput(clipper.GetOutput());
SelectionMapper.ScalarVisibilityOff();
SourceActor = new vtk.vtkLODActor();
SelectActor = new vtkLODActor();
//SourceActor.GetProperty().SetRepresentationToWireframe();
SourceActor.GetProperty().SetColor(1, 0, 0);
SourceActor.SetMapper(SourceMapper);
SelectActor.GetProperty().SetColor(0, 1, 0);
SelectActor.SetMapper(SelectionMapper);
SelectActor.VisibilityOff();
vtk.vtkRenderer ren1 = new vtk.vtkRenderer();
renWin.AddRenderer(ren1);
vtkRenderWindowInteractor iren = new
vtk.vtkRenderWindowInteractor();
iren.SetRenderWindow(renWin);
// The box widget observes the events invoked by the render
window
// interactor. These events come from user interaction in the
render
//window.
vtkBoxWidget boxWidget = new vtk.vtkBoxWidget();
boxWidget.SetInteractor(iren);
boxWidget.SetPlaceFactor(1.25);
// boxWidget.ScalingEnabledOff();
ren1.AddActor(SourceActor);
ren1.AddActor(SelectActor);
ren1.SetBackground(0.0f, 0.0f, 0.0f);
renWin.AddRenderer(ren1);
boxWidget.SetProp3D(SourceActor);
boxWidget.PlaceWidget();
boxWidget.AddObserver((uint)vtk.EventIds.InteractionEvent, new
vtk.vtkDotNetCallback(Cut_Object));
boxWidget.AddObserver((uint)vtk.EventIds.EndInteractionEvent,
new vtk.vtkDotNetCallback(transfer_Object));
boxWidget.On();
GC.Collect();
}
static void Cut_Object(vtk.vtkObject obj, uint eventId, Object data,
IntPtr clientdata)
{
vtkBoxWidget widget = vtkBoxWidget.SafeDownCast(obj);
if(! transfer)
{
widget.GetPlanes(planes);
clipper.SetClipFunction(planes);
clipper.Update();
SelectActor.SetUserTransform(t); SelectActor.VisibilityOn();
}
}
static void transfer_Object(vtk.vtkObject obj, uint eventId, Object
data, IntPtr clientdata)
{
vtkBoxWidget widget = vtkBoxWidget.SafeDownCast(obj);
if (transfer)
{
/* //widget.ScalingEnabledOff();
widget.GetTransform(t);
SelectActor.SetUserTransform(t); SelectActor.VisibilityOn();
widget.ScalingEnabledOn(); */
vtkTransform boxTransform =new vtkTransform();
widget.GetTransform(boxTransform);
// remove the scaling from the transform before passing it
on
double[] scale = boxTransform.GetScale();
boxTransform.Scale(1.0 / scale[0], 1.0 / scale[1], 1.0/
scale[2]);
boxTransform.RotateWXYZ(0, 0, 0, 0);
SelectActor.SetUserTransform((vtkLinearTransform)boxTransform);
SelectActor.SetPosition(boxTransform.GetPosition());
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100730/4d9e91a5/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.jpg
Type: image/jpeg
Size: 12920 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100730/4d9e91a5/attachment.jpg>
More information about the vtkusers
mailing list