QT QVTKWidget与 render 和 imageViewer2 结合的显示问题

https://blog.csdn.net/menjiawan/article/details/45192039

下面链接是官网的例子:可以看看

https://vtk.org/Wiki/VTK/Examples/Cxx/Qt

 

1、QVTKWidget 与 imageViewer2 结合

#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include 

int main(int argc, char** argv)
{
    QApplication app(argc, argv);
    
    QVTKWidget widget;
    widget.resize( 256, 256 );
    
    vtkSmartPointer reader =vtkSmartPointer::New();
    reader->SetDirectoryName("/Users/mac/Desktop/CT数据/tsing" );// path.toUtf8().constData()
    reader->Update();
    
    int dims[3];double spacing[3];double origin[3];
    reader->GetOutput()->GetDimensions(dims);
    reader->GetOutput()->GetSpacing(spacing);
    reader->GetOutput()->GetOrigin(origin);
    std::cout << "dims:" << dims[0] << ", " << dims[1] << ", " << dims[2] << std::endl;
    std::cout << "spacing:" << spacing[0] << ", " << spacing[1] << ", " << spacing[2] << std::endl;
    std::cout << "origin:" << origin[0] << ", " << origin[1] << ", " << origin[2] << std::endl;
    NodeContainer::Pointer  seeds = NodeContainer::New();
    seeds->Initialize();

    vtkSmartPointer viewer =vtkSmartPointer::New();
    viewer->SetInputData(reader->GetOutput());
    viewer->SetSliceOrientationToXY();
    viewer->GetRenderer()->SetBackground(1,1,1);
    
    vtkSmartPointer rwi = vtkSmartPointer::New();
    viewer->SetupInteractor(rwi);
    
    vtkSmartPointer style = vtkSmartPointer::New();
    rwi->SetInteractorStyle( style );

  //  viewer->SetupInteractor(widget.GetRenderWindow()->GetInteractor());
  //因为我上面自己定义了交互函数(rwi和style),这里这个默认的交互就不用要了。
  
    
    widget.SetRenderWindow(viewer->GetRenderWindow());
   
    widget.show();
    
    app.exec();
    
    return EXIT_SUCCESS;
}

2、QVTKWidget 与 render 结合

https://vtk.org/Wiki/VTK/Examples/Cxx/Qt/RenderWindowNoUiFile

 

 

备注:主要区别是最后的窗口设置。

 

QT QVTKWidget与 render 和 imageViewer2 结合的显示问题_第1张图片

//第一种:
      /* viewer->GetRenderer()->ResetCamera();//need
     qvtkWidgetLeft->SetRenderWindow(viewer->GetRenderWindow());
     qvtkWidgetLeft->GetRenderWindow()->SetInteractor(rwi);
     qvtkWidgetLeft->GetRenderWindow()->Render();*/


//第二种  
      /*  viewer->SetRenderer(render);
        viewer->SetRenderWindow(qvtkWidgetLeft->GetRenderWindow());
        viewer->Render();
       // viewer->GetRenderer()->ResetCamera();
        viewer->SetupInteractor(qvtkWidgetLeft->GetRenderWindow()->GetInteractor());
        qvtkWidgetLeft->GetInteractor()->SetInteractorStyle(style);
        viewer->GetImageActor()->InterpolateOff();
      //  render->ResetCamera();
        render->DrawOn();
        qvtkWidgetLeft->GetRenderWindow()->Render();*/


//第三种:
    
    /*viewer->SetupInteractor(qvtkWidgetLeft->GetRenderWindow()->GetInteractor());
     qvtkWidgetLeft->SetRenderWindow(viewer->GetRenderWindow());
    qvtkWidgetLeft->GetInteractor()->SetInteractorStyle(style);
    viewer->GetRenderer()->ResetCamera();
    viewer->Render();*/

 

 

 

 

你可能感兴趣的:(QT,QT,VTK,ITK,混合编译)