我的开发环境:
系统:win8.1
QT:5.4.2MinGW版
VTK:6.3
按照教程生成一个球体显示在,Qt的QVTKWidget控件中,出现如下ERROR:
ERROR: In D:\VTK6.3\VTK-src\Rendering\Core\vtkTextActor.cxx, line 110vtkTextActor (0509BA90): Failed getting the TextRenderer instance!
解决办法:
在头文件中加入VTK_MODULE_INIT(vtkRenderingFreeType),
我估计可能还需要在VTK源文件cmake编译的时候,将VTK_USE_SYSTEM_FREETYPE设置为ON。
再有,要将类似含有***Actor或含有***Widget类的代码,比如下面
/***************坐标互动窗件儿开始***************************************/ vtkSmartPointeraxes =vtkSmartPointer ::New(); vtkSmartPointer widget =vtkSmartPointer ::New(); widget->SetOutlineColor( 0.9300, 0.5700, 0.1300 ); widget->SetOrientationMarker( axes ); //注意style的设置要在axes设置之前 widget->SetInteractor( iren ); widget->SetViewport( 0.0, 0.0, 0.4, 0.4 ); widget->SetEnabled( 1 ); widget->InteractiveOn();/***************坐标互动窗件儿结束***************************************/
放置在renderWindowInteractor之后设置。比如,在下面的为场景添加坐标窗件儿的程序:
#ifndef INITIAL_OPENGL#define INITIAL_OPENGL#includeVTK_MODULE_INIT(vtkRenderingOpenGL)VTK_MODULE_INIT(vtkInteractionStyle)VTK_MODULE_INIT(vtkRenderingFreeType)#endif#include using namespace std;#include #include #include #include #include #include #include #include #include #include #include #include #include #include void myShow(vtkPolyData* aGrid){ vtkSmartPointer aMapper=vtkSmartPointer ::New(); aMapper->SetInputData(aGrid); aMapper->ScalarVisibilityOn(); vtkSmartPointer anActor=vtkSmartPointer ::New(); anActor->SetMapper(aMapper); // anActor->GetProperty()->SetRepresentationToWireframe(); anActor->GetProperty()->SetDiffuseColor(1,1,1); anActor->GetProperty()->SetLineWidth(10); anActor->GetProperty()->SetPointSize(10); vtkSmartPointer ren1=vtkSmartPointer ::New(); vtkSmartPointer renWin=vtkSmartPointer ::New(); ren1->AddActor(anActor); ren1->ResetCamera(); renWin->AddRenderer(ren1); renWin->SetSize(512,512); vtkSmartPointer iren=vtkSmartPointer ::New(); iren->SetRenderWindow(renWin); vtkSmartPointer style=vtkSmartPointer ::New(); iren->SetInteractorStyle(style);/***************坐标互动窗件儿***************************************/ vtkSmartPointer axes =vtkSmartPointer ::New(); vtkSmartPointer widget =vtkSmartPointer ::New(); widget->SetOutlineColor( 0.9300, 0.5700, 0.1300 ); widget->SetOrientationMarker( axes ); //注意style的设置要在axes设置之前 widget->SetInteractor( iren ); widget->SetViewport( 0.0, 0.0, 0.4, 0.4 ); widget->SetEnabled( 1 ); widget->InteractiveOn();/***************坐标互动窗件儿***************************************/ iren->Start();}int main(){ vtkSmartPointer sphereSource = vtkSmartPointer ::New(); sphereSource->SetCenter(0.0, 0.0, 0.0); sphereSource->SetRadius(1.0); sphereSource->Update(); vtkSmartPointer polydata = vtkSmartPointer ::New(); polydata=sphereSource->GetOutput(); myShow(polydata); return 0;}