项中的.h文件中可以找到。另外可以打开D:\\Program Files\\VTK\\,利用文件搜索功能搜寻,找到后用VS2010打开修改(本人用后者,感觉较快)。b.在vtkMFC工程下的< Resource Files>中,找到vtkMFCWindow.cpp打开修改
4个stdafx.h 如下修改
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later.
#define WINVER 0x0601 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later.
#define _WIN32_WINNT 0x0601 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif
#if _MSC_VER >= 1300
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0601 // Change this to the appropriate value to target Windows Me or later.
#endif
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later.
#define _WIN32_IE 0x0800 // Change this to the appropriate value to target IE 5.0 or later.
#endif
红字对应的是win7版本。
vtkMFCWindow.cpp中的部分代码:
// Allow use of features specific to Windows 95 and Windows NT 4 or later.
#ifndef WINVER
#define WINVER 0x0601
#endif
// Define _WIN32_WINNT and _WIN32_IE to avoid the following error with Visual
// Studio 2008 SP1:
// \"C:\\Program Files\\Microsoft
SDKs\\Windows\\v6.0A\\include\\sdkddkver.h(217) :
// fatal error C11: #error : _WIN32_WINNT settings conflicts with _WIN32_IE
// setting\"
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0601 // =_WIN32_WINNT_NT4
#endif
#ifndef _WIN32_IE
#define _WIN32_IE 0x0800 //=_WIN32_IE_IE60SP1
#endif
此时,应该没有问题了。
若出现cannot find vtkMFC.lib则是由于cmake阶段未勾选vtk_use_mfc
7.将D:\\Program Files\\VTK\\VTKbin\\bin \\debug这个文件夹选择此中所有的DLL 后缀的文件全部复制到c:\\windows\\system32 (调试时推荐),或者拷贝到VC项目可执行文件所在位置(安装到其他机器时拷贝)。
8. 用VS2010打开D:\\Program Files\\VTK\\VTKbin
\\Examples\\All\\VTKExamples.sln,选择Cone项目,右键set as active project(VC不熟的人一定要记得这个!),然后
选择调试->启动新实例,这时可以看到正确运行的程序了。
9. 新建项目Test(控制台应用程序空项目),增加Test.cpp文件,用Cone6.cxx的文件内容覆盖Test.cpp的内容。
#include \"vtkConeSource.h\"
#include \"vtkPolyDataMapper.h\"
#include \"vtkRenderWindow.h\"
#include \"vtkCamera.h\"
#include \"vtkActor.h\"
#include \"vtkRenderer.h\"
#include \"vtkProperty.h\"
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)
{
renWin->Render();
ren1->GetActiveCamera()->Azimuth( i );
}
cone->Delete();
coneMapper->Delete();
coneActor->Delete();
ren1->Delete();
renWin->Delete();
return 0;
}
9.1项目属性->配置属性->VC++目录->库目录:
D:\\Program Files\\VTK\\VTKbin\\bin\\debug
若出现无法找到vtkRendering.dll等错误,则是由于该环境变量未配置正确。
9.2项目属性->配置属性->VC++目录->包含目录 ,拷入入下述内容:
D:\\Program Files\\VTK\\VTKbin;
D:\\Program Files\\VTK\\VTKbin\\bin;
D:\\Program Files\\VTK\\VTKsourcecode\\GenericFiltering;
D:\\Program Files\\VTK\\VTKsourcecode\\Common;
D:\\Program Files\\VTK\\VTKsourcecode\\IO;
D:\\Program Files\\VTK\\VTKsourcecode\\Filtering;
D:\\Program Files\\VTK\\VTKsourcecode\\Rendering;
D:\\Program Files\\VTK\\VTKsourcecode\\Graphics;
D:\\Program Files\\VTK\\VTKsourcecode\\VolumeRendering;
D:\\Program Files\\VTK\\VTKsourcecode\\Imaging;
D:\\Program Files\\VTK\\VTKsourcecode\\Hybrid;
D:\\Program Files\\VTK\\VTKsourcecode\\GUISupport;
D:\\Program Files\\VTK\\VTKsourcecode\\ Utilities;
D:\\Program Files\\VTK\\VTKbin\\ Utilities;
D:\\Program Files\\VTK\\VTKsourcecode\\Parallel;
D:\\Program Files\\VTK\\VTKsourcecode\\Widgets
( 注意:网上很多配置方法在Additional include directories(附加包含路径)没有添加D:\\Program Files\\VTK\\VTKbin; D:\\Program Files\\VTK\\VTKbin\\bin; 结果出现错误提示:无法打开包括文件:“vtkConfigure.h”: No such file or directory)
9.3位于项目属性->链接器->输入->附加依赖项 ,拷入下述内容(下面有些lib文件已经被附加进去了,就不需要再添加进去):
opengl32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib vtkCommon.lib vtkDICOMParser.lib vtkexoIIc.lib vtkexpat.lib vtkFiltering.lib vtkfreetype.lib
vtkftgl.lib vtkGenericFiltering.lib vtkGraphics.lib vtkHybrid.lib vtkImaging.lib vtkIO.lib vtkjpeg.lib vtkNetCDF.lib vtkpng.lib vtkRendering.lib vtksys.lib vtktiff.lib vtkVolumeRendering.lib vtkWidgets.lib vtkzlib.lib
(建议把D:\\Program Files\\VTK\\VTKbin\\bin \\debug中所有的lib文件都填进去)
9.4调试,运行,可以看到运行窗口。
像Cannot open include file: 'vtkConeSource.h':这样的错误都是上面三大步没走对或dll没拷到windows/system下造成的。要建立新项目,必须重新配置三大步,因为那三步都是Project setting里的,新项目没有默认这些设置。
如果某个项目再提示缺什么lib或.h的话,再临时加上去就行了。