[vtkusers] About vtkDotNetcallback
Andrej Gluhov
realandron at gmail.com
Sun Sep 12 03:47:15 EDT 2010
Hi.
http://devsample.org/index.php here is a sample for Dicom for C++. I rewrote
it as follows.
public class VtkObserverMouseMove
{
protected vtkImageViewer2 m_pImageViewer;
protected vtkRenderWindowInteractor m_pIren;
protected vtkPointPicker m_pPicker;
protected vtkDICOMImageReader m_pDICOMImageReader;
protected Form1 m_pForm;
public VtkObserverMouseMove(vtkImageViewer2 pImageViewer,
vtkRenderWindowInteractor pIren, vtkPointPicker pPicker, vtkDICOMImageReader
pDICOMImageReader,Form1 pForm)
{
m_pImageViewer = pImageViewer;
m_pIren = pIren;
m_pPicker = pPicker;
m_pDICOMImageReader = pDICOMImageReader;
m_pForm = pForm;
}
public void MouseClick(vtkObject caller, uint eventId, object
clientData, IntPtr callData)
{
if (m_pPicker.Pick(m_pIren.GetEventPosition()[0],
m_pIren.GetEventPosition()[1],
0, // always zero.
m_pImageViewer.GetRenderer()) == 0)
{
m_pForm.ClickIntensivity = 0;//textbox in winform
m_pForm.ClickXY[0] = 0;//textbox in winform
m_pForm.ClickXY[1] = 0;//textbox in winform
m_pForm.UpdateTXT();
return;
}
// Get the mapped position of the mouse using the picker.
double[] ptMapped = new double [3];
ptMapped = m_pPicker.GetMapperPosition();
// We have to manually set the physical z-coordinate which
requires
// us to get the volume spacing.
double[] dSpacing = new double[3];
dSpacing = m_pImageViewer.GetInput().GetSpacing();
ptMapped[2] = m_pImageViewer.GetSlice() * dSpacing[2];
// get a shortcut to the pixel data.
vtkImageData pImageData = m_pImageViewer.GetInput();
// Get the volume index within the entire volume now.
int nVolIdx = pImageData.FindPoint(ptMapped);
int ScalarSize= pImageData.GetScalarSize();
if(pImageData.GetNumberOfScalarComponents()== 1)
{
// We have to handle different number of scalar
components.
// Get a shortcut to the raw pixel data. This should be
further
// updated to check if your data is signed or not, but
for this
// example we'll just assume it's unsigned. You should
also check
// the type of your data too (unsigned char, unsigned
short, etc).
IntPtr pPix = pImageData.GetScalarPointer();
Int16 PixelValue = (Int16)Marshal.ReadInt32(pPix,
ScalarSize * nVolIdx);
m_pForm.ClickIntensivity = Convert.ToDouble(PixelValue);
m_pForm.ClickXY[0] = ptMapped[0];
m_pForm.ClickXY[1] = ptMapped[1];
m_pForm.UpdateTXT();
}
}
public void MouseMove(vtkObject caller, uint eventId, object
clientData, IntPtr callData)
{
if (m_pPicker.Pick(m_pIren.GetEventPosition()[0],
m_pIren.GetEventPosition()[1],
0, // always zero.
m_pImageViewer.GetRenderer()) == 0)
{
m_pForm.ClickIntensivity = 0;
m_pForm.ClickXY[0] = 0;
m_pForm.ClickXY[1] = 0;
m_pForm.UpdateTXT();
return;
}
// Get the mapped position of the mouse using the picker.
double[] ptMapped = new double [3];
ptMapped = m_pPicker.GetMapperPosition();
// We have to manually set the physical z-coordinate which
requires
// us to get the volume spacing.
double[] dSpacing = new double[3];
dSpacing = m_pImageViewer.GetInput().GetSpacing();
ptMapped[2] = m_pImageViewer.GetSlice() * dSpacing[2];
// get a shortcut to the pixel data.
vtkImageData pImageData = m_pImageViewer.GetInput();
// Get the volume index within the entire volume now.
int nVolIdx = pImageData.FindPoint(ptMapped);
int ScalarSize= pImageData.GetScalarSize();
if(pImageData.GetNumberOfScalarComponents()== 1)
{
// We have to handle different number of scalar
components.
// Get a shortcut to the raw pixel data. This should be
further
// updated to check if your data is signed or not, but
for this
// example we'll just assume it's unsigned. You should
also check
// the type of your data too (unsigned char, unsigned
short, etc).
IntPtr pPix = pImageData.GetScalarPointer();
Int16 PixelValue = (Int16)Marshal.ReadInt32(pPix,
ScalarSize * nVolIdx);
m_pForm.ClickIntensivity = Convert.ToDouble(PixelValue);
m_pForm.ClickXY[0] = ptMapped[0];
m_pForm.ClickXY[1] = ptMapped[1];
m_pForm.UpdateTXT();
}
}
}
public Form1()
{
InitializeComponent();
vtkRenderWindow.GlobalWarningDisplayOff();
m_renWin = reWin.GetRenderWindow();
m_renWin.AddRenderer(m_renderer);
m_iren.SetRenderWindow(m_renWin);
m_imageViewer.SetRenderer(m_renderer);
m_imageViewer.SetRenderWindow(m_renWin);
m_imageViewer.GetImageActor().InterpolateOff();
m_picker.SetTolerance(0.0);
m_iren.SetPicker(m_picker);
Mouse = new VtkObserverMouseMove(m_imageViewer, m_iren,
m_picker, m_DicomReader, this);
* m_iren.AddObserver((uint)EventIds.LeftButtonPressEvent, new
vtkDotNetCallback(Mouse.MouseClick));
m_iren.AddObserver((uint)EventIds.MouseMoveEvent, new
vtkDotNetCallback(Mouse.MouseMove));*
}
2010/9/12 myaqua1982 <myaqua1982 at 163.com>
> Hi all,
> Now I use vtk in the dot net entironment . I want to select the
> coordinate of point. Caculate the distance between two points and the angles
> in the 3D entironment .Some of them suggested me to use the class called
> vtkDotNetcallback. But I do not know how to use it. I have search in the
> internet, but there is little information about the class.
> Is there anyone who have used it before? Or have caculate distance and
> angle, please give me some advice? Thanks!
>
> 2010-09-12
> ------------------------------
> myaqua1982
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
--
С Уважением,
Андрей.
Best regards, Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100912/cd74bb3d/attachment.htm>
More information about the vtkusers
mailing list