[vtkusers] Improper translatioon using vtkboxwidget
Ali Habib
ali.mahmoud.habib at gmail.com
Sat Jul 24 17:31:13 EDT 2010
I use the following code to select a part and translate it , but as u can
see in the image the selected red part nt like the green one (which is the
result of transformation)
My question is how to make the translated part be as the selected part
My code is :
static vtkLODActor SourceActor;
//static vtkLODActor SourceActor_2;
static vtkLODActor SelectActor;
static vtkTransform t = new vtkTransform();
static vtkClipPolyData clipper;
static vtkPlanes planes;
static bool transfer = false ;
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();
}
}
Any suggestion please
thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100725/b062d1e7/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Improper_translatioon.jpg
Type: image/jpeg
Size: 44526 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100725/b062d1e7/attachment.jpg>
More information about the vtkusers
mailing list