VTK初学一,比较常见的错误2

时间:2023-03-08 15:46:00

我的开发环境:

系统:win8.1

QT:5.4.2MinGW版

VTK:6.3

按照教程生成一个球体显示在,Qt的QVTKWidget控件中,出现如下ERROR:

VTK初学一,比较常见的错误2

ERROR: In D:\VTK6.3\VTK-src\Rendering\Core\vtkTextActor.cxx, line 110
vtkTextActor (0509BA90): Failed getting the TextRenderer instance!

解决办法:

在头文件中加入VTK_MODULE_INIT(vtkRenderingFreeType),

我估计可能还需要在VTK源文件cmake编译的时候,将VTK_USE_SYSTEM_FREETYPE设置为ON。

再有,要将类似含有***Actor或含有***Widget类的代码,比如下面

/***************坐标互动窗件儿开始***************************************/
vtkSmartPointer<vtkAxesActor> axes =vtkSmartPointer<vtkAxesActor>::New();
vtkSmartPointer<vtkOrientationMarkerWidget> widget =vtkSmartPointer<vtkOrientationMarkerWidget>::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( );
widget->InteractiveOn();
/***************坐标互动窗件儿结束***************************************/

放置在renderWindowInteractor之后设置。比如,在下面的为场景添加坐标窗件儿的程序:

#ifndef INITIAL_OPENGL
#define INITIAL_OPENGL
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL)
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingFreeType)
#endif
#include <iostream> using namespace std;
#include <vtkVersion.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyData.h>
#include <vtkSphereSource.h>
#include <vtkOrientationMarkerWidget.h>
#include <vtkAxesActor.h>
#include <vtkPropAssembly.h>
#include <vtkSmartPointer.h>
#include <vtkProperty.h>
#include <vtkInteractorStyleTrackballCamera.h> void myShow(vtkPolyData* aGrid)
{
vtkSmartPointer<vtkPolyDataMapper> aMapper=vtkSmartPointer<vtkPolyDataMapper>::New();
aMapper->SetInputData(aGrid);
aMapper->ScalarVisibilityOn(); vtkSmartPointer<vtkActor> anActor=vtkSmartPointer<vtkActor>::New();
anActor->SetMapper(aMapper);
// anActor->GetProperty()->SetRepresentationToWireframe();
anActor->GetProperty()->SetDiffuseColor(,,);
anActor->GetProperty()->SetLineWidth();
anActor->GetProperty()->SetPointSize(); vtkSmartPointer<vtkRenderer> ren1=vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin=vtkSmartPointer<vtkRenderWindow>::New();
ren1->AddActor(anActor);
ren1->ResetCamera();
renWin->AddRenderer(ren1);
renWin->SetSize(,); vtkSmartPointer<vtkRenderWindowInteractor> iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style=vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
iren->SetInteractorStyle(style);
/***************坐标互动窗件儿***************************************/
vtkSmartPointer<vtkAxesActor> axes =vtkSmartPointer<vtkAxesActor>::New();
vtkSmartPointer<vtkOrientationMarkerWidget> widget =vtkSmartPointer<vtkOrientationMarkerWidget>::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( );
widget->InteractiveOn();
/***************坐标互动窗件儿***************************************/
iren->Start();
}
int main()
{
vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetCenter(0.0, 0.0, 0.0);
sphereSource->SetRadius(1.0);
sphereSource->Update(); vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
polydata=sphereSource->GetOutput();
myShow(polydata);
return ;
}

VTK初学一,比较常见的错误2