[vtkusers] setSlice problem on QVTKWidget
Massi
Massinissa.Bandou at USherbrooke.ca
Wed Sep 5 16:27:23 EDT 2012
Hi,
I'm using the latest version of VTK 5.10 on Win7 and I'm trying to read some
DICOM images and opening them in QVTKWidget on Qt. The problem occurs when I
try to display each slice from the series. It immediately crush when I press
UP or Down on the keyboard (see the picture). After several hours of
debugging, the problem comes from vtkImageViewer2 when I set the number of
slice.
ImageViewer->setSlice(Slice);
Can Anyone help? I really don't know what I'm missing here!
here is my code
************************.h file*****************************
class myVtkInteractorStyleImage : public vtkInteractorStyleImage{
public:
Ui::ImageCoregistration widget;
public:
static myVtkInteractorStyleImage *New();
vtkTypeMacro(myVtkInteractorStyleImage,vtkInteractorStyleImage);
protected:
vtkImageViewer2* ImageViewer;
int Slice;
int MinSlice;
int MaxSlice;
public:
void SetImageViewer(vtkImageViewer2* imageViewer){
ImageViewer = imageViewer;
MinSlice = imageViewer->GetSliceMin();
MaxSlice = imageViewer->GetSliceMax();
Slice = MinSlice;
cout<< "Slicer: Min =" << MinSlice <<", Max =
"<<MaxSlice<<std::endl;
}
protected:
void MoveSliceForward(){
if (Slice < MaxSlice){
Slice += 1;
ImageViewer->SetSlice(Slice);
ImageViewer->Render();
}
}
void MoveSliceBackward(){
if (Slice > MinSlice){
Slice -= 1;
ImageViewer->SetSlice(Slice);
ImageViewer->Render();
}
}
virtual void OnKeyDown(){
std::string key=this->GetInteractor()->GetKeySym();
if (key.compare("Up") == 0){
MoveSliceForward();
}
else if(key.compare("Down") == 0){
MoveSliceBackward();
}
vtkInteractorStyleImage::OnKeyDown();
}
virtual void OnMousewheelForward(){
MoveSliceForward();
}
virtual void OnMouseWheelBackrward(){
if (Slice > MinSlice){
MoveSliceBackward();
}
}
};
************************CPP file****************************
vtkSmartPointer<vtkDICOMImageReader> reader =
vtkSmartPointer<vtkDICOMImageReader>::New();
reader->SetDirectoryName(filename);
reader->Update();
vtkSmartPointer<vtkImageViewer2> imageViewer =
vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetInputConnection(reader->GetOutputPort());
vtkSmartPointer<myVtkInteractorStyleImage> myInteractorStyle =
vtkSmartPointer<myVtkInteractorStyleImage>::New();
myInteractorStyle->SetImageViewer(imageViewer);
widget.qvtkWidget->SetRenderWindow(imageViewer->GetRenderWindow());
imageViewer->SetupInteractor(widget.qvtkWidget->GetRenderWindow()->GetInteractor());
widget.qvtkWidget->GetRenderWindow()->GetInteractor()->SetInteractorStyle(myInteractorStyle);
widget.qvtkWidget->update();
Thanks for your help!
Massi
http://vtk.1045678.n5.nabble.com/file/n5715880/Untitled.png
--
View this message in context: http://vtk.1045678.n5.nabble.com/setSlice-problem-on-QVTKWidget-tp5715880.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list