[vtkusers] How to connect Qobject (QScrollBar or Qspinbox) with vtkobject ImagePlaneWidget

Sun 136208999 at qq.com
Wed Apr 6 09:08:34 EDT 2011


hi,
  I wanna use QScrollBar and QSpinBox to respond with the slice image(axial,coronal,sagittal) of a volume in QVTKWidget.
 So i wrote a ScrollBarCallback class .The code is as follows:
 class ScrollBarCallback: public vtkCommand
{
public:
 static ScrollBarCallback *New()
 {return new ScrollBarCallback();};
   ScrollBarCallback()
  {
    this->ScrollBar=0;
    this->Qinteractor=0;
    this->ImagePlaneWidget=0;
   };
  void SetScrollBar(QScrollBar *scollbar)
  {
   this->ScrollBar=scollbar;
   };
  QScrollBar *GetScrollBar()
  {
  return this->ScrollBar;
  };
  void SetInteractor(QVTKInteractor *interactor)
  {
   
   this->Qinteractor = interactor;
  };
  QVTKInteractor *GetInteractor() 
 {
   return this->Qinteractor;
 };
  void SetImagePlaneWidget(vtkImagePlaneWidget *imageplane)
 {
  this->ImagePlaneWidget=imageplane;
 };
vtkImagePlaneWidget *GetImagePlaneWidget()
{
  return this->ImagePlaneWidget;
};
 virtual void Execute(vtkObject *, unsigned long event , void* )
 {
  QScrollBar * slider=this->GetScrollBar();
  QVTKInteractor *interactor=this->GetInteractor();
  vtkImagePlaneWidget *imageplane= this->GetImagePlaneWidget();
   imageplane->SetInteractor(interactor);
  imageplane->SetSliceIndex(slider->value());
   interactor->Start();
 };
 private:
  QScrollBar *ScrollBar;
 QVTKInteractor *Qinteractor;
 vtkImagePlaneWidget *ImagePlaneWidget;
  
 };
  
 GUI4::GUI4()
{
  this->setupUi(this);
    renwin = vtkRenderWindow::New();
  renwin->StereoCapableWindowOn();
   qVTK2->SetUseTDx(true);
  qVTK2->SetRenderWindow(renwin);
  renwin->Delete();
   QVTKInteractor *iren2=qVTK2->GetInteractor();
   iren2->SetInteractorStyle(iren->GetInteractorStyle());
   Ren2 = vtkRenderer::New();
  qVTK2->GetRenderWindow()->AddRenderer(Ren2);
  ...........
  ...........
  ...........
 vtkProperty* ipwProp = vtkProperty::New();
 vtkImagePlaneWidget* ipw = vtkImagePlaneWidget::New();
  
 ipw->SetKeyPressActivationValue('x');
 ipw->RestrictPlaneToVolumeOn();
 ipw->GetPlaneProperty()->SetColor(1,0,0);
 ipw->SetTexturePlaneProperty(ipwProp);
 ipw->SetResliceInterpolateToNearestNeighbour();
 ipw->SetInput(reader->GetOutput());
 ipw->SetPlaneOrientationToYAxes();
 ipw->SetSliceIndex(30);
 ipw->DisplayTextOn();
  
   vtkLookupTable *table2 =vtkLookupTable::New();
  table2->SetRange(0, 2000);  
   table2->SetValueRange(0.0, 1.0);  
  table2->SetSaturationRange(0.0, 0.0);  
  table2->SetRampToLinear();
  table2->Build();
   vtkImageMapToColors *colorMap = vtkImageMapToColors::New();
  colorMap->SetInput(ipw->GetResliceOutput());
  colorMap->SetLookupTable(table2);
  vtkImageActor  *actor2 =vtkImageActor::New();
  actor2->SetInput(colorMap->GetOutput());
   Ren2->AddActor(actor2); 
   QObject::connect(spinBox_2,SIGNAL(valueChanged(int)),verticalScrollBar_2,SLOT(setValue(int)));
  QObject::connect(verticalScrollBar_2,SIGNAL(valueChanged(int)),spinBox_2,SLOT(setValue(int)));
  verticalScrollBar_2->setValue(ipw->GetSliceIndex());
  
   ScrollBarCallback *callback=ScrollBarCallback::New();
  callback->SetScrollBar(verticalScrollBar_2);
  callback->SetImagePlaneWidget(ipw);
  callback->SetInteractor(iren2);
 
  iren2->GetInteractorStyle()->AddObserver(vtkCommand::InteractionEvent,callback);
  iren2->Start();
...............
 ...............
 ...............
  
    When i used this ScrollBarCallback class, QVTKInteractor showed:
    QVTKInteractor (02A60E78): QVTKInteractor cannot control the event loop.And the scrollbar can not control the the slice(setsliceindex()) . 
    I did not know which code was wrong,or maybe i should use   vtkEventQtSlotConnect. I just did a try,using 
 vtkEventQtSlotConnect::Connect(imageplane->SetSliceIndex(int),vtkCommand::NoEvent,slider,SIGNAL(valueChanged(int)));
 it also didn't work,maybe it was wrong.
  
 I was confused for more than a month.
 Thanks for your advice and help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110406/c721bb89/attachment.htm>


More information about the vtkusers mailing list