VTK7.1.1+VS2017的安装配置

  1. 默认前提:已安装好VS2017
  2. Cmake下载安装(版本无所谓):https://blog.csdn.net/u011231598/article/details/80338941
  3. vtk7.1.1官网下载地址(别的版本配置方式一样):https://vtk.org/files/release/7.1/VTK-7.1.1.zip 
  4. VTK解压缩后得到一个VTK-7.1.1的文件夹,我在这个文件夹里面新建了两个文件夹build和VTK-PREFIX。(我的分别是是D:/VTK-7.1.1/build和D:/VTK-7.1.1/VTK-PREFIX)
  5. 用cmake编译VTK:
    打开cmake,在 where is the source code 后面填写VTK解压缩后的文件夹地址,在where to build the binaries 后面填写我们刚刚创建的build文件夹地址。
  6. 然后点击configure,选择Visual Studio 15 2017 Win64,因为我是在64位的vs2017下编译的。等待一段时间,出现红字,在BUILD_EXAMPLES后面打勾,在CMAKE_INSTALL_PREFIX后面填写我们刚刚建立的VTK-PREFIX文件夹地址。

    然后再次点击configure,红色消失。

    点击generate,出现Generate Done。

  7. 打开我们之前创建的build文件夹,用vs2017打开VTK.sln文件。选中ALL_BUILD项目,右键选择生成,静静等待一段时间直到编译完成。

  8. 看看我们的VTK是否安装成功:选择Cube项目,右键选择设为启动项目,然后CTRL+F5运行,一个彩色的多边形就出来啦

以上,VTK就安装成功了,下面我们来看一下新建一个vs工程,VTK该如何配置。

  1. 在VTK.sln的工程中,选中INASTALL项目,右键选择生成,这样在我们前面创建的VTK-PREFIX文件夹中就生成了VTK的头文件、dll文件和lib文件
  2. 在环境变量,系统变量的PATH中,把bin文件夹的地址加进去。我的是D:\VTK-7.1.1\VTK-PREFIX\bin
  3. 在VS2017中创建一个新的工程,选择项目->属性,在VC++目录的包含目录中,把VTK-PREFIX文件夹中的include文件夹的地址加进去,在VC++目录的库目录中,把VTK-PREFIX文件夹中的lib文件夹的地址加进去。
  4. 在VTK-PREFIX的lib文件夹内新建一个txt文件,将   DIR *.lib /B >LIBLIST.TXT 写入txt并保存,改后缀.txt.bat并双击运行,这时在目录生成了一个新的.txt文件,文件存有所有lib文件的名字。编辑项目->属性->配置属性->链接器->输入 附加依赖项,将刚生成的所有lib文件的名字粘贴进去。
  5. .dll 配置:配置完上边,项目应该可以生成了,把 build 文件夹中的 bin 文件夹中的所有 dll 文件放到VS生成出的 exe 所在文件夹下。找不到的可以编译后仔细查看目录,在Debug下。或者在项目->属性->配置属性->调试 环境 写入PATH=VTK-PREFIX的bin的完整目录,也可以将dll文件全部复制在项目中。
  6. 可惜的是每次新建一个项目都要重新配置(貌似可以写配置文件,方便一点,我自己没有试过)

测试:

将以下代码复制到cpp中,配置成功了就能成功显示。

#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCylinderSource.h>
#include <vtkNamedColors.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <array>
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);//和官方的例子有些不同,下面解释
VTK_MODULE_INIT(vtkInteractionStyle);
int main(int, char *[]) {
  vtkSmartPointer<vtkNamedColors> colors =
      vtkSmartPointer<vtkNamedColors>::New();

  // Set the background color.
  std::array<unsigned char, 4> bkg{{26, 51, 102, 255}};
  colors->SetColor("BkgColor", bkg.data());

  // This creates a polygonal cylinder model with eight circumferential facets
  // (i.e, in practice an octagonal prism).
  vtkSmartPointer<vtkCylinderSource> cylinder =
      vtkSmartPointer<vtkCylinderSource>::New();
  cylinder->SetResolution(8);

  // The mapper is responsible for pushing the geometry into the graphics
  // library. It may also do color mapping, if scalars or other attributes are
  // defined.
  vtkSmartPointer<vtkPolyDataMapper> cylinderMapper =
      vtkSmartPointer<vtkPolyDataMapper>::New();
  cylinderMapper->SetInputConnection(cylinder->GetOutputPort());

  // The actor is a grouping mechanism: besides the geometry (mapper), it
  // also has a property, transformation matrix, and/or texture map.
  // Here we set its color and rotate it around the X and Y axes.
  vtkSmartPointer<vtkActor> cylinderActor = vtkSmartPointer<vtkActor>::New();
  cylinderActor->SetMapper(cylinderMapper);
  cylinderActor->GetProperty()->SetColor(
      colors->GetColor4d("Tomato").GetData());
  cylinderActor->RotateX(30.0);
  cylinderActor->RotateY(-45.0);

  // The renderer generates the image
  // which is then displayed on the render window.
  // It can be thought of as a scene to which the actor is added
  vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
  renderer->AddActor(cylinderActor);
  renderer->SetBackground(colors->GetColor3d("BkgColor").GetData());
  // Zoom in a little by accessing the camera and invoking its "Zoom" method.
  renderer->ResetCamera();
  renderer->GetActiveCamera()->Zoom(1.5);

  // The render window is the actual GUI window
  // that appears on the computer screen
  vtkSmartPointer<vtkRenderWindow> renderWindow =
      vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->SetSize(300, 300);
  renderWindow->AddRenderer(renderer);
  renderWindow->SetWindowName("Cylinder");

  // The render window interactor captures mouse events
  // and will perform appropriate camera or actor manipulation
  // depending on the nature of the events.
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
      vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  // This starts the event loop and as a side effect causes an initial render.
  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}

 

报过的错:

模块计算机类型“x64”与目标计算机类型“X86”冲突 注意所有的都改成64和WIN64(WIN32也不行)

其他的错误

参考

                            

 

 

 

 

 

 


 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值