[vtkusers] problem with vtkPicker(vtkCellPicker, vtkPointPicker)

Sarah Macumber S.Macumber at QuestReliability.com
Thu Sep 25 16:02:36 EDT 2008


Hi Shaadi,

 

vtkPicker will pick 3D world coordinates which may not have a z value of 0.  You will want to use a picker which will return you points confined to your image plane.  You could try using vtkCellPicker <http://www.vtk.org/doc/nightly/html/classvtkCellPicker.html>  or vtkPropPicker <http://www.vtk.org/doc/nightly/html/classvtkPropPicker.html> .

 

All the best,

Sarah Macumber

 

From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf Of Shady Shidfar
Sent: Thursday, September 25, 2008 4:48 AM
To: VTKUsers
Subject: [vtkusers] problem with vtkPicker(vtkCellPicker, vtkPointPicker)

 

Hi Everyone,

I sent this yesterday but I don't know why it didn't apear in the forum. I'm sending it again, please can someone help me with it.

I'm using vtkPicker to pick cells on an image and draw on the image. I've copied a short version of my program. I'm using vtkDotNet and managedItk. I want to draw lines through the picked points on a 2d tif image. Key 'p' is used to pick a point. The lines need to remain in the same place they've been drawn no matter zooming or rotating. The problem is :

1- When I zoom the image and get the picked cell dimension, Z would be a value rather than 0 which I don't understand why.

2- When I rotate the image and pick the points and draw lines. It seems they are in the right place but when I rotate the image the lines would be somewhere outside the image. 

 

I'm using picker.GetPickPosition() to get the dimension of the picked point. I'd probably need to change this. Does anyone know how I can fix the problem? Any suggestions would be a great help

 

Thanks

Shaadi

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Collections;

using vtk;

using itk;

namespace InteractiveHierarchicalSegmentationDotNet.Test

{

public partial class testPicking : Form

{

vtkCellPicker picker;

vtkRenderer renderer = new vtkRenderer();

public testPicking()

{

InitializeComponent();

vtkFormsWindowControl1.GetRenderWindow().AddRenderer(renderer);

viewImage();

picker = new vtkCellPicker();

picker.PickFromListOn(); // to make sure picker won't pick props instead of cells

picker.AddObserver((uint)vtk.EventIds.EndPickEvent, new vtk.vtkDotNetCallback(annotatePick));

vtkFormsWindowControl1.GetInteractor().SetPicker(picker);

}

private void annotatePick(vtk.vtkObject caller, uint eventId,

object clientData, IntPtr callData)

{

vtkActor2D textActor = new vtkActor2D();

{

double[] selPt = picker.GetSelectionPoint();

double x = selPt[0];

double y = selPt[1];

double[] pickPos = picker.GetPickPosition();

double xp = pickPos[0];

double yp = pickPos[1];

double zp = pickPos[2];

pointsDataGridView.Rows.Add();

pointsDataGridView.Rows[pointsDataGridView.RowCount - 1].Cells[0].Value = xp;

pointsDataGridView.Rows[pointsDataGridView.RowCount - 1].Cells[1].Value = yp;

pointsDataGridView.Rows[pointsDataGridView.RowCount - 1].Cells[2].Value = zp;

double[] newPoint = new double[] { xp, yp, zp };

double[] previousPoint = new double[3];

if (pointsDataGridView.Rows.Count == 1)

{

previousPoint = newPoint;

}

else

{

// retrieve the previous row

double pxp = Convert.ToDouble(pointsDataGridView.Rows[pointsDataGridView.Rows.Count - 2].Cells[0].Value);

double pyp = Convert.ToDouble(pointsDataGridView.Rows[pointsDataGridView.Rows.Count - 2].Cells[1].Value);

double pzp = Convert.ToDouble(pointsDataGridView.Rows[pointsDataGridView.Rows.Count - 2].Cells[2].Value);

previousPoint[0] = pxp;

previousPoint[1] = pyp;

previousPoint[2] = pzp;

}

int r = 1, g = 0, b = 0;

createLine(previousPoint, newPoint);

vtkFormsWindowControl1.Refresh();

}

}

private void createLine(double[] startPoint, double[] endPoint)

{

vtkPoints VTKpoints = new vtkPoints();

VTKpoints.SetNumberOfPoints(2);

VTKpoints.InsertPoint(0, startPoint[0], startPoint[1], startPoint[2]);

VTKpoints.InsertPoint(1, endPoint[0], endPoint[1], endPoint[2]);

 

vtkLine line = new vtkLine();

line.GetPointIds().SetId(0, 0);

line.GetPointIds().SetId(1, 1);

vtkUnstructuredGrid grid = new vtkUnstructuredGrid();

grid.Allocate(1, 1);

grid.InsertNextCell(line.GetCellType(), line.GetPointIds());

grid.SetPoints(VTKpoints);

vtkDataSetMapper aLineMapper = new vtkDataSetMapper();

aLineMapper.SetInput(grid);

vtkActor aLineActor = new vtkActor();

aLineActor.SetMapper(aLineMapper);

aLineActor.AddPosition(0, 0, 0);

aLineActor.GetProperty().SetDiffuseColor(1, 0, 0);

renderer.AddActor(aLineActor);

vtkFormsWindowControl1.GetRenderWindow().AddRenderer(renderer);

}

private void viewImage()

{

try

{

itkImage_UC3 input = itkImage_UC3.New();

input.Read("C:/brain.tif");

// Import ITK image to VTK

itkImageToVTKImageFilter_IUC3 itk2vtk =

itkImageToVTKImageFilter_IUC3.New();

itk2vtk.SetInput(input);

itk2vtk.Update();

vtkImageData data = itk2vtk.GetOutput();

vtkImageFlip imageFlip = new vtkImageFlip();

imageFlip.SetFilteredAxis(1);

imageFlip.SetInput(data);

vtk.vtkImageActor imageActor = new vtkImageActor();

imageActor.SetInput(imageFlip.GetOutput());

renderer.AddActor(imageActor);

vtkFormsWindowControl1.Update();

}

catch (Exception ex)

{

Console.WriteLine(ex);

}

}

}

}

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080925/54939185/attachment.htm>


More information about the vtkusers mailing list