VTk与MFC混编
前面几个例子是熟悉vtk的,练习时用控制台程序编写,vtk与MFC混编的过程中遇到了很多问题,为了方便大家,我把这一过程中的遇到的错误和解决办法都记录下来了,希望能够对大家有所帮助
VTK入门程序样例分析
一、圆锥圆柱类
1、简单圆锥【圆锥鼠标拖动】
#include \ #include \ #include \ #include \ #include \ #include \
int main() {
vtkConeSource *cone = vtkConeSource::New(); cone->SetHeight( 3.0 ); cone->SetRadius( 1.0 ); cone->SetResolution( 10 );
vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New(); coneMapper->SetInputConnection( cone->GetOutputPort() );
vtkActor *coneActor = vtkActor::New(); coneActor->SetMapper( coneMapper );
vtkRenderer *ren1= vtkRenderer::New(); ren1->AddActor( coneActor );
ren1->SetBackground( 0.1, 0.2, 0.4 );
vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer( ren1 ); renWin->SetSize( 300, 300 );
int i;
for (i = 0; i < 360; ++i) {
// render the image renWin->Render();
// rotate the active camera by one degree ren1->GetActiveCamera()->Azimuth( 1 ); }
cone->Delete(); coneMapper->Delete(); coneActor->Delete(); ren1->Delete(); renWin->Delete(); return 0; }
1、新建工程 2、输入代码 3、添加包含文件 4、编译出错 cone1.obj : error LNK2019: unresolved external symbol \public: void __thiscall vtkCamera::Azimuth(double)\(__imp_?Azimuth@vtkCamera@@QAEXN@Z) referenced in function _wmain
错误解决办法 error LNK2019: 无法解析的外部符号 \称找不到vtkIO.dll 对应解决办法:在每个项目属性的链接器->输入->附加依赖项中添加入vtkIO.lib库,目录为:..\\..\\..\\..\\bin\\Debug\\vtkIO.lib
F:\\VTK58\\bin\\bin\\Debug\\vtkMFC.lib;F:\\VTK58\\bin\\bin\\Debug\\vtkRendering.lib;F:\\VTK58\\bin\\bin\\Debug\\vtkIO.lib;F:\\VTK58\\bin\\bin\\Debug\\vtkFiltering.lib;F:\\VTK58\\bin\\bin\\Debug\\vtkCommon.lib;DelayImp.lib;F:\\VTK58\\bin\\bin\\Debug\\vtkGraphics.lib;F:\\VTK58\\bin\\bin\\Debug\\vtkImaging.lib;F:\\VTK58\\bin\\bin\\Debug\\vtkFiltering.lib;F:\\VTK58\\bin\\bin\\Debug\\vtkCommon.lib;F:\\VTK58\\bin\\bin\\Debug\\vtksys.lib;
错误没了!
2、Callback命令
#include \
#include \ #include \ #include \ #include \ #include \ #include \
// Callback for the interaction
class vtkMyCallback : public vtkCommand { public:
static vtkMyCallback *New() { return new vtkMyCallback; }
virtual void Execute(vtkObject *caller, unsigned long, void*) {
vtkRenderer *renderer = reinterpret_cast
int main() { //
// The pipeline creation is documented in Step1 //
vtkConeSource *cone = vtkConeSource::New(); cone->SetHeight( 3.0 ); cone->SetRadius( 1.0 ); cone->SetResolution( 10 );
vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New(); coneMapper->SetInputConnection( cone->GetOutputPort() ); vtkActor *coneActor = vtkActor::New(); coneActor->SetMapper( coneMapper );
vtkRenderer *ren1= vtkRenderer::New(); ren1->AddActor( coneActor );
ren1->SetBackground( 0.1, 0.2, 0.4 ); ren1->ResetCamera();
vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer( ren1 );