[Insight-users] [vtkusers] Programming challenges with QT, VTK, and ITK
Xiaopeng Yang
yxp233 at postech.ac.kr
Fri Dec 17 20:37:33 EST 2010
Dear Sam,
Thanks a lot for your help. It works now! Still I have another small question. Here is my code. You can find that I define some variables such as picked[3] and pixelIndex. Then I made the transformation from physical point to index in the interaction style class and showed the index in command line. So far everything worked well. And then in the int main code, I would like to use the transformed index to do something, for example using the index as a seed point for segmentation. However, the index always 0, 0, 0. Do you know why?
#include <vtkSmartPointer.h>
. . .
double picked[3];
typedef unsigned short InputPixelType;
. . .
InputImageType::Pointer image = reader->GetOutput();
InputImageType::IndexType pixelIndex;
// Define interaction style
class MouseInteractorStylePP : public vtkInteractorStyleTrackballCamera
{
public:
static MouseInteractorStylePP* New();
vtkTypeMacro(MouseInteractorStylePP, vtkInteractorStyleTrackballCamera);
virtual void OnLeftButtonDown()
{
. . .
point[0]=picked[0];
point[1]=picked[1];
point[2]=picked[2];
bool isInside = image->TransformPhysicalPointToIndex( point, pixelIndex );
if ( isInside )
{
InputImageType::PixelType pixelValue = image->GetPixel( pixelIndex );
pixelValue += 5;
image->SetPixel( pixelIndex, pixelValue );
}
std::cout << "pixelIndex: " << pixelIndex[0] << " " << pixelIndex[1] << " " << pixelIndex[2] << std::endl; //works fine
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}
};
vtkStandardNewMacro(MouseInteractorStylePP);
int main(int, char *[])
{
. . .
std::cout << "pixelIndex: " << pixelIndex[0] << " " << pixelIndex[1] << " " << pixelIndex[2] << std::endl; //Always zero
. . .
}
Merry Christmas and Happy new year!
Best regards,
Xiaopeng
发件人: (Samuel) Byeongjun Park [mailto:byeongjun.park at case.edu]
发送时间: 2010년 12월 18일 토요일 오전 12:50
收件人: 'Xiaopeng Yang'
抄送: insight-users at itk.org; 'vtk'
主题: RE: [vtkusers] Programming challenges with QT, VTK, and ITK
Xiaopeng,
If you use iktImageToVTKImageFilter, it means the image data is in itk::Image object, not in vtkImageData.
So if you got world coordinate, then the first three elements of world coordinate array is the PhysicalPoint of itk::Image.
You can get the index of itkImage using itk::Image::TransformPhysicalPointToIndex(..).
You shouldn’t read the image to both of itk::Image and vtkImageData.
Summarizing..
1. Read the image to itk::Image.
2. Apply itkImageToVTKImageFilter
3. Get a point from vtk
4. Change it to world coordinate point
5. Store the x,y,z coordinate into Itk::Image::PointType object
6. Itk::Image::TransformPhysicalPointToIndex()
Now you get the index of the itk::Image where you picked in vtk window.
Good luck and merry Christmas!
Sam.
-------------- Innovation for the Future Radiation Oncology (http://rophys.meds.case.edu <http://rophys.meds.case.edu/> )
(Samuel) Byeongjun Park, Ph.D. -- Research associate of Sohn Lab.
Case Western Reserve Univerisity, School of Medicine
Visiting: Wood building W517, Phone: 1-216-368-6583
From: Xiaopeng Yang [mailto:yxp233 at postech.ac.kr]
Sent: Friday, December 17, 2010 7:13 AM
To: '(Samuel) Byeongjun Park'
Cc: insight-users at itk.org; 'vtk'
Subject: RE: [vtkusers] Programming challenges with QT, VTK, and ITK
Hello Park,
It has been a very long time since I received your help. These days I am still working on this problem. Now I can get the VTK coordinate (i.e., world coordinate). You mentioned that if I use itk ImageToVTKImageFilter, I can directly use the VTK coordinate as ITK coordinate. However, I could not understand clearly. In my program, I need ITK coordinate for applying ITK region growing algorithm. I do not know how to translate VTK coordinate to ITK coordinate. Could you please explain more in detail?
Thanks very much!
Xiaopeng
发件人: (Samuel) Byeongjun Park [mailto:byeongjun.park at case.edu]
发送时间: 2010년 10월 27일 수요일 오후 10:41
收件人: 'Xiaopeng Yang'
抄送: 'vtk'
主题: RE: [vtkusers] Programming challenges with QT, VTK, and ITK
Hi,
My name is Sam Park. Since you told you are using QT, I think you are using QVTKWidget.
You can make your own QVTK widget class inheriting QVTKWidget.
In there, override
Virtual void mousePressEvent(QMouseEvent *pevent);
You can read the mouse position in QVTKWidget window.
Then,
1. Get the QT coordinate point (x,y)
2. Flip y value by y=height-y;
3. Get the pointer of the Render in your QVTKWidget object.
4. double wpoint[4];
5. Render->SetDisplayPoint(x,y,0);
6. Render->DisplayToWorld();
7. Render->GetWorldPoint(wpoint);
Now You have the VTK coordinate of the point you clicked.
If you imported CT image in ITK and utilized itk::ImageToVTKImageFilter,
you can directly use the VTK coordinate as ITK coordinate.
Good luck.
Sam.
-------------- Innovation for the Future Radiation Oncology
(Samuel) Byeongjun Park, Ph.D. -- Research associate of Sohn Lab.
Case Western Reserve Univerisity, School of Medicine
Visiting: Wood building W517, Phone: 1-216-368-6583
From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf Of Xiaopeng Yang
Sent: Tuesday, October 26, 2010 9:06 PM
To: 'Luis Ibanez'
Cc: 'itk'; 'vtk'
Subject: [vtkusers] Programming challenges with QT, VTK, and ITK
Dear Luis,
How are you doing? Thank you very much for your help so far. Sorry to ask you a question again.
I am now developing a liver segmentation program using QT, VTK, and ITK based on CT images. In my program, fast marching algorithm is used to extract the liver by multiple seed points. To pick the positions of the seed points, vtkImagePlaneWidget is applied. The problem is how to save the multiple seed points I selected by left-clicking of the mouse so that I do not need to type those positions into the code, which is time consuming.
Please provide me with your suggestions. I working on this for almost one week still I cannot figure it out.
Thanks,
Xiaopeng
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20101218/615c5039/attachment.htm>
More information about the Insight-users
mailing list