VTK入门(配置+常见问题)

环境: win7 64 + visual studio 2012  +  VTK 7.0.0


主要参考网址: 在Windows下用vs构建VTK 项目



步骤:

Step 1 - Download VTK  (zip or tar.gz格式)

Step 2 - Download CMake

Step 3 - Create a build folder  (新建一个bin的文件夹,注意不要有中文)

Step 4 - Run CMake    (注意选择vs的版本,已经generate之前的一些选项是否是你需要的)

Step 5 - Open the Visual Studio project  (在bin文件夹下打开VTK.sln)

Step 6 - Install the project  (将bin\release 目录下的dll文件复制到c:\windows\system32 下)

Be very careful if you have multiple VTK installed on your system that you are using the right one. It is strongly suggested that only one version of the VTK dll be on one system.

Step 7 - Manual building

在vs中新建工程需要设置项目属性中的 Additional Include Directories and Additional Library Directories 为VTK的相关路径

Steps:

  1. Start CMake (CMakeSetup.exe).
  2. Configure VTK (select the correct binary directory in "Where to build the binaries").
  3. Select the proper path for "CMAKE_INSTALL_PREFIX". It should be something like : "C:/MY INSTALLATION/VTK"
  4. Click Configure
  5. Click "OK"
  6. Open Visual Studio, select the VTK.sln project from the binary directoy.
  7. Make sure that ALL_BUILD is the selected target. Build it. It should be a noop.
  8. Once this is done, select the "INSTALL" target. And build this target (eg. Right click on it, then Build this taget only). This will copy and the the correct permission for all the files needed to use VTK in the directory you have specified.


另外新建项目可参考上面网站使用cmake新建项目


BUG  自己配置环境总是出错


VS新建项目之后的配置:

<1>在VC++ Directories中的Library Directories里添加F:\VTK-7.0.0-bin\lib\Debug,即库目录。  【有的Blog里面说是要添加release版本的dll】


<2>在C/C++ -> General中的Additional Include Directories中添加:

F:\VTK-7.0.0-bin\Filters\Sources;F:\VTK-7.0.0\Filters\Sources;F:\VTK-7.0.0-bin\Common\ComputationalGeometry;F:\VTK-7.0.0\Common\ComputationalGeometry;F:\VTK-7.0.0-bin\Common\DataModel;F:\VTK-7.0.0\Common\DataModel;F:\VTK-7.0.0-bin\Common\Math;F:\VTK-7.0.0\Common\Math;F:\VTK-7.0.0-bin\Common\Core;F:\VTK-7.0.0\Common\Core;F:\VTK-7.0.0-bin\Utilities\KWSys;F:\VTK-7.0.0\Utilities\KWSys;F:\VTK-7.0.0-bin\Common\Misc;F:\VTK-7.0.0\Common\Misc;F:\VTK-7.0.0-bin\Common\System;F:\VTK-7.0.0\Common\System;F:\VTK-7.0.0-bin\Common\Transforms;F:\VTK-7.0.0\Common\Transforms;F:\VTK-7.0.0-bin\Filters\General;F:\VTK-7.0.0\Filters\General;F:\VTK-7.0.0-bin\Filters\Core;F:\VTK-7.0.0\Filters\Core;F:\VTK-7.0.0-bin\Common\ExecutionModel;F:\VTK-7.0.0\Common\ExecutionModel;F:\VTK-7.0.0-bin\Interaction\Widgets;F:\VTK-7.0.0\Interaction\Widgets;F:\VTK-7.0.0-bin\Filters\Hybrid;F:\VTK-7.0.0\Filters\Hybrid;F:\VTK-7.0.0-bin\Imaging\Sources;F:\VTK-7.0.0\Imaging\Sources;F:\VTK-7.0.0-bin\Imaging\Core;F:\VTK-7.0.0\Imaging\Core;F:\VTK-7.0.0-bin\Rendering\Core;F:\VTK-7.0.0\Rendering\Core;F:\VTK-7.0.0-bin\Common\Color;F:\VTK-7.0.0\Common\Color;F:\VTK-7.0.0-bin\Filters\Extraction;F:\VTK-7.0.0\Filters\Extraction;F:\VTK-7.0.0-bin\Filters\Statistics;F:\VTK-7.0.0\Filters\Statistics;F:\VTK-7.0.0-bin\Imaging\Fourier;F:\VTK-7.0.0\Imaging\Fourier;F:\VTK-7.0.0-bin\ThirdParty\alglib;F:\VTK-7.0.0\ThirdParty\alglib;F:\VTK-7.0.0-bin\Filters\Geometry;F:\VTK-7.0.0\Filters\Geometry;F:\VTK-7.0.0-bin\Filters\Modeling;F:\VTK-7.0.0\Filters\Modeling;F:\VTK-7.0.0-bin\Imaging\General;F:\VTK-7.0.0\Imaging\General;F:\VTK-7.0.0-bin\Imaging\Hybrid;F:\VTK-7.0.0\Imaging\Hybrid;F:\VTK-7.0.0-bin\IO\Image;F:\VTK-7.0.0\IO\Image;F:\VTK-7.0.0-bin\Utilities\DICOMParser;F:\VTK-7.0.0\Utilities\DICOMParser;F:\VTK-7.0.0-bin\IO\Core;F:\VTK-7.0.0\IO\Core;F:\VTK-7.0.0-bin\ThirdParty\zlib;F:\VTK-7.0.0\ThirdParty\zlib;F:\VTK-7.0.0-bin\Utilities\MetaIO\vtkmetaio;F:\VTK-7.0.0-bin\Utilities\MetaIO;F:\VTK-7.0.0\Utilities\MetaIO;F:\VTK-7.0.0-bin\ThirdParty\jpeg;F:\VTK-7.0.0\ThirdParty\jpeg;F:\VTK-7.0.0-bin\ThirdParty\png;F:\VTK-7.0.0\ThirdParty\png;F:\VTK-7.0.0-bin\ThirdParty\tiff;F:\VTK-7.0.0\ThirdParty\tiff;F:\VTK-7.0.0-bin\Interaction\Style;F:\VTK-7.0.0\Interaction\Style;F:\VTK-7.0.0-bin\Rendering\Annotation;F:\VTK-7.0.0\Rendering\Annotation;F:\VTK-7.0.0-bin\Imaging\Color;F:\VTK-7.0.0\Imaging\Color;F:\VTK-7.0.0-bin\Rendering\FreeType;F:\VTK-7.0.0\Rendering\FreeType;F:\VTK-7.0.0-bin\ThirdParty\freetype;F:\VTK-7.0.0\ThirdParty\freetype;F:\VTK-7.0.0-bin\Rendering\Volume;F:\VTK-7.0.0\Rendering\Volume;F:\VTK-7.0.0-bin\Rendering\OpenGL2;F:\VTK-7.0.0\Rendering\OpenGL2;F:\VTK-7.0.0-bin\Utilities\EncodeString;F:\VTK-7.0.0\Utilities\EncodeString;F:\VTK-7.0.0-bin\ThirdParty\glew;F:\VTK-7.0.0\ThirdParty\glew;F:\VTK-7.0.0-bin\bin\Debug;%(AdditionalIncludeDirectories)

【注意空格木有哦,  本来我以为可以直接在编辑窗口复制黏贴的,后面发现不可以以为要一个个的添加,再后来发现,可以在属性窗口, 附加包含目录 的空格中直接复制   省事好多, 自己也有够笨的】


<3>在Linker -> Input -> Additional Dependencies中添加

kernel32.lib
user32.lib
gdi32.lib
winspool.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
comdlg32.lib
advapi32.lib
comctl32.lib
vfw32.lib
ws2_32.lib
wsock32.lib
opengl32.lib
vtkChartsCore-7.0.lib
vtkCommonColor-7.0.lib
vtkCommonComputationalGeometry-7.0.lib
vtkCommonCore-7.0.lib
vtkCommonDataModel-7.0.lib
vtkCommonExecutionModel-7.0.lib
vtkCommonMath-7.0.lib
vtkCommonMisc-7.0.lib
vtkCommonSystem-7.0.lib
vtkCommonTransforms-7.0.lib
vtkDICOMParser-7.0.lib
vtkDomainsChemistry-7.0.lib
vtkDomainsChemistryOpenGL2-7.0.lib
vtkFiltersAMR-7.0.lib
vtkFiltersCore-7.0.lib
vtkFiltersExtraction-7.0.lib
vtkFiltersFlowPaths-7.0.lib
vtkFiltersGeneral-7.0.lib
vtkFiltersGeneric-7.0.lib
vtkFiltersGeometry-7.0.lib
vtkFiltersHybrid-7.0.lib
vtkFiltersHyperTree-7.0.lib
vtkFiltersImaging-7.0.lib
vtkFiltersModeling-7.0.lib
vtkFiltersParallel-7.0.lib
vtkFiltersParallelImaging-7.0.lib
vtkFiltersProgrammable-7.0.lib
vtkFiltersSMP-7.0.lib
vtkFiltersSelection-7.0.lib
vtkFiltersSources-7.0.lib
vtkFiltersStatistics-7.0.lib
vtkFiltersTexture-7.0.lib
vtkFiltersVerdict-7.0.lib
vtkGeovisCore-7.0.lib
vtkIOAMR-7.0.lib
vtkIOCore-7.0.lib
vtkIOEnSight-7.0.lib
vtkIOExodus-7.0.lib
vtkIOExport-7.0.lib
vtkIOGeometry-7.0.lib
vtkIOImage-7.0.lib
vtkIOImport-7.0.lib
vtkIOInfovis-7.0.lib
vtkIOLSDyna-7.0.lib
vtkIOLegacy-7.0.lib
vtkIOMINC-7.0.lib
vtkIOMovie-7.0.lib
vtkIONetCDF-7.0.lib
vtkIOPLY-7.0.lib
vtkIOParallel-7.0.lib
vtkIOParallelXML-7.0.lib
vtkIOSQL-7.0.lib
vtkIOVideo-7.0.lib
vtkIOXML-7.0.lib
vtkIOXMLParser-7.0.lib
vtkImagingColor-7.0.lib
vtkImagingCore-7.0.lib
vtkImagingFourier-7.0.lib
vtkImagingGeneral-7.0.lib
vtkImagingHybrid-7.0.lib
vtkImagingMath-7.0.lib
vtkImagingMorphological-7.0.lib
vtkImagingSources-7.0.lib
vtkImagingStatistics-7.0.lib
vtkImagingStencil-7.0.lib
vtkInfovisCore-7.0.lib
vtkInfovisLayout-7.0.lib
vtkInteractionImage-7.0.lib
vtkInteractionStyle-7.0.lib
vtkInteractionWidgets-7.0.lib
vtkLocalExample-7.0.lib
vtkNetCDF-7.0.lib
vtkNetCDF_cxx-7.0.lib
vtkParallelCore-7.0.lib
vtkRenderingAnnotation-7.0.lib
vtkRenderingContext2D-7.0.lib
vtkRenderingContextOpenGL2-7.0.lib
vtkRenderingCore-7.0.lib
vtkRenderingFreeType-7.0.lib
vtkRenderingImage-7.0.lib
vtkRenderingLOD-7.0.lib
vtkRenderingLabel-7.0.lib
vtkRenderingOpenGL2-7.0.lib
vtkRenderingVolume-7.0.lib
vtkRenderingVolumeOpenGL2-7.0.lib
vtkViewsContext2D-7.0.lib
vtkViewsCore-7.0.lib
vtkViewsInfovis-7.0.lib
vtkalglib-7.0.lib
vtkexoIIc-7.0.lib
vtkexpat-7.0.lib
vtkfreetype-7.0.lib
vtkglew-7.0.lib
vtkhdf5-7.0.lib
vtkhdf5_hl-7.0.lib
vtkjpeg-7.0.lib
vtkjsoncpp-7.0.lib
vtklibxml2-7.0.lib
vtkmetaio-7.0.lib
vtkmyCommon.lib
vtkmyImaging.lib
vtkmyUnsorted.lib
vtkoggtheora-7.0.lib
vtkpng-7.0.lib
vtkproj4-7.0.lib
vtksqlite-7.0.lib
vtksys-7.0.lib
vtktiff-7.0.lib
vtkverdict-7.0.lib
vtkzlib-7.0.lib

编译报错

1>LINK : fatal error LNK1104: 无法打开文件“vtkChartsCore-7.0.lib”

【分析原因】lib路径输入错误


2>

1>soap.obj : error LNK2019: 无法解析的外部符号 "public: class vtkAlgorithmOutput * __thiscall vtkAlgorithm::GetOutputPort(int)" (?GetOutputPort@vtkAlgorithm@@QAEPAVvtkAlgorithmOutput@@H@Z),该符号在函数 "public: class vtkAlgorithmOutput * __thiscall vtkAlgorithm::GetOutputPort(void)" (?GetOutputPort@vtkAlgorithm@@QAEPAVvtkAlgorithmOutput@@XZ) 中被引用
1>soap.obj : error LNK2019: 无法解析的外部符号 "public: static class vtkConeSource * __cdecl vtkConeSource::New(void)" (?New@vtkConeSource@@SAPAV1@XZ),该符号在函数 _main 中被引用
1>soap.obj : error LNK2019: 无法解析的外部符号 "public: static class vtkPolyDataMapper * __cdecl vtkPolyDataMapper::New(void)" (?New@vtkPolyDataMapper@@SAPAV1@XZ),该符号在函数 _main 中被引用
1>soap.obj : error LNK2019: 无法解析的外部符号 "public: static class vtkRenderWindow * __cdecl vtkRenderWindow::New(void)" (?New@vtkRenderWindow@@SAPAV1@XZ),该符号在函数 _main 中被引用
1>soap.obj : error LNK2019: 无法解析的外部符号 "public: static class vtkActor * __cdecl vtkActor::New(void)" (?New@vtkActor@@SAPAV1@XZ),该符号在函数 _main 中被引用
1>soap.obj : error LNK2019: 无法解析的外部符号 "public: static class vtkRenderer * __cdecl vtkRenderer::New(void)" (?New@vtkRenderer@@SAPAV1@XZ),该符号在函数 _main 中被引用
1>soap.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall vtkRenderer::AddActor(class vtkProp *)" (?AddActor@vtkRenderer@@QAEXPAVvtkProp@@@Z),该符号在函数 _main 中被引用
1>C:\Users\yorktal03\Documents\Visual Studio 2012\Projects\vtkProject001\Debug\vtkProject001.exe : fatal error LNK1120: 7 个无法解析的外部命令

【分析原因】如果之前Cmake勾选了 build_examples,工程中含有VKT的examples,在编译过程中,以下四个项目vtkDLG、vtkMDI、vtkSDI、Win32SampleMFC,可能还会出现类似下面的LINK链接错误:
error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: static class...
称找不到vtkIO.dll    (参考链接

我明白是库不对,但是这个vtkIO.lib找不到啊!搞了两天了还没有搞定

==>突然间意识到,我的系统是64位的,VTK.sln 编译的时候选择的是Debug X64 ,新建项目之后编译是在Debug win32下,  哭瞎


3> F5 运行


昨天用CMakeLists.txt新建的一个项目之前还是可以用的,现在也突然不可以用了。猜测是因为我的操作系统是Windows 7 -64bit,但是我把DLL放入到System32 目录下,System32目录下面还有一个SysWOW64的文件夹,so ...

【但是昨天我也没有将dll文件放入什么里面,所以这个不成立,昨天到今天我的操作就是因为多个版本的VTK所以将5.6.0版本的删除,将VTK7.0.0重新cmake + build,感觉其他我都没有改变呀,不明白哪里有问题了】


【解决问题】 不知道是将dll文件放在SysWOW64下的原因还是将VTK.sln重新build  问题解决


4> 非常恐怖的0xC0000005问题

First-chance exception at 0x000007F7AA106C8F in Test.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

Generic Warning: In F:\VTK-7.0.0\Rendering\Core\vtkPolyDataMapper.cxx, line 28 

Error: no override found for 'vtkPolyDataMapper'.

【分析】If you build your project with CMake, and you use the standard find_package(VTK) and include(${VTK_USE_FILE}) then this problem should not occur. (Because the defines will be automatically added for you by virtue of the include(${VTK_USE_FILE})...) Consider following the guide to using implementation modules, which has fuller details on using implementation modules without using CMake if your project demands it.

The factory methods now require "auto-initialization" depending on what modules are enabled at VTK configure time. If you are enabling all modules, and building your project without using CMake, you will need some defines in your project in order to make the factories work properly.

On September 10, 2013 a new macro was added to make this process a little simpler for projects that just want to initialize modules, where ordering ceases to be important but you must still build a source file into your application that has something along with following (with one entry for each module that should be initialized).

 #include <vtkAutoInit.h>
 VTK_MODULE_INIT(vtkRenderingOpenGL);

This will initialize the vtkRenderingOpenGL object factories, and should be done for each module. If you are using an older version of VTK (6.0 or master from before the date above) than you can try including this snippet in all your code that includes VTK usage, BEFOREincluding ANY VTK header files:

 #define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL)
 #define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL)
如果你是用VTK7.0.0 需要加的是
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
 
PS:  姐姐好有成就感啊
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值