VS2012+VTK6.3.0+Windows10环境配置及案例
1、需要的工具cmake3.13.4(下载地址:https://cmake.org/download/)
1.1 下载cmake
下载后得到三个文件(有源码,绿的,与cmake安装无关可忽略)
1.2 安装,双击cmake-3.13.4-win64-x64.msi文件按照步骤即可安装完成
2、下载VTK6.3.0(下载地址:https://vtk.org/download/)
3、编译VTK
参考如下博客的(2.2 编译VTK的详细步骤):
https://blog.csdn.net/www_doling_net/article/details/8532742
注意:CMake选择编译环境时选择VS2012
用vs2012打开VTK.sln后,如下图所示:
对项目进行重新生成,需要等待一段时间(二十分钟左右)
生成完毕后,发现如下界面即可
为后期使用方便可对INSTALL进行编译
(VTK里所有的头文件以及相关的库文件等,即会被提取到你在CMAKE_INSTALL_PREFIX里指定的路径里,默认的路径是:C:/Program Files/VTK。)
注意:由于管理员权限的问题,如果直接双击VTK.sln,然后编译INSTALL工程的话,会提示不能在C:\Program Files\下创建目录等错误,如下图所示
此时可以先关闭掉VTK工程,右击VS2012程序,选择“管理员权限运行”Visual Studio 2012,接着在Visual Studio 2012下通过菜单打开VTK.sln文件,再重新编译INSTALL工程。
4、测试VTK,此处参考了:
https://www.cnblogs.com/luckystar-67/p/3260028.html
https://blog.csdn.net/weixin_38500110/article/details/78776775
4.1新建->项目->Visual C++ ->Win32控制台应用程序->demo。选择为->空项目。
4.2选择项目->新建->demo.cpp
4.3拷贝以下代码
#include"vtkSmartPointer.h"
#include"vtkAutoInit.h"
#include"vtkRenderer.h"
#include"vtkRenderWindow.h"
#include"vtkRenderWindowInteractor.h"
#include"vtkPolyData.h"
#include"vtkPolyDataReader.h"
#include"vtkSurfaceReconstructionFilter.h"
#include"vtkActor.h"
#include"vtkCamera.h"
#include"vtkContourFilter.h"
#include"vtkPolyDataMapper.h"
#include"vtkVertexGlyphFilter.h"
#include"vtkProperty.h"
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkInteractionStyle);
int main(int argc, char *argv[])
{
std::string str = "fran_cut.vtk";
vtkSmartPointer reader = vtkSmartPointer::New();
reader->SetFileName(str.c_str());
reader->Update();
vtkSmartPointer data = vtkSmartPointer::New();
data->SetPoints(reader->GetOutput()->GetPoints());// 获取网格模型的点集和几何数据。
vtkSmartPointer surf = vtkSmartPointer::New();
surf->SetInputData(data);
surf->SetNeighborhoodSize(20);
surf->SetSampleSpacing(0.005);
surf->Update();
vtkSmartPointer contour = vtkSmartPointer::New();
contour->SetInputConnection(surf->GetOutputPort());
contour->SetValue(0,0.0);
contour->Update();
vtkSmartPointer vertFilter = vtkSmartPointer::New();
vertFilter->AddInputData(data);
vertFilter->Update();
vtkSmartPointer dataMapper = vtkSmartPointer::New();
dataMapper->SetInputData(vertFilter->GetOutput());
dataMapper->ScalarVisibilityOff();
vtkSmartPointer dataActor = vtkSmartPointer::New();
dataActor->SetMapper(dataMapper);
dataActor->GetProperty()->SetColor(1,0,0);//设置点的大小与颜色
dataActor->GetProperty()->SetPointSize(4);
vtkSmartPointer contourMapper = vtkSmartPointer::New();
contourMapper->SetInputData(contour->GetOutput());
vtkSmartPointer contourActor = vtkSmartPointer::New();
contourActor->SetMapper(contourMapper);
double dataViews[4] = { 0.5, 0, 1, 1 };
double contourViews[4] = { 0.5, 0, 1, 1 };
vtkSmartPointer dataRender = vtkSmartPointer::New();
dataRender->AddActor(dataActor);
dataRender->SetViewPoint(dataViews);
dataRender->SetBackground(1,1,1);//设置左边背景色
vtkSmartPointer contourRender =vtkSmartPointer::New();
contourRender->AddActor(contourActor);
contourRender->SetViewport(contourViews);
contourRender->SetBackground(0, 1, 0);//设置右边背景色
dataRender->GetActiveCamera()->SetPosition(0, -1, 0);
dataRender->GetActiveCamera()->SetFocalPoint(0, 0, 0);
dataRender->GetActiveCamera()->SetViewUp(0, 0, 1);
dataRender->GetActiveCamera()->Azimuth(30);
dataRender->GetActiveCamera()->Elevation(30);
dataRender->ResetCamera();
contourRender->SetActiveCamera(dataRender->GetActiveCamera());
vtkSmartPointer rw =vtkSmartPointer::New();
rw->AddRenderer(dataRender);
rw->AddRenderer(contourRender);
rw->SetSize(640, 320);
rw->SetWindowName("Demo_Window");
rw->Render();
vtkSmartPointer rwi =vtkSmartPointer::New();
rwi->SetRenderWindow(rw);
rwi->Initialize();
rwi->Start();
return EXIT_SUCCESS;
}
4.4项目->demo属性->C/C++->常规->附加包含目录->(即VTK的一些头文件,在步骤3中的INSTALL模块编译时产生的C:\Program Files\VTK)
4.5 demo项目属性>链接器->输入->附加依赖项(添加lib链接对应的dll)
此处可复制以下给出的内容
opengl32.lib
kernel32.lib
user32.lib
gdi32.lib
winspool.lib
comdlg32.lib
advapi32.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
odbc32.lib
vtkalglib-6.3.lib
vtkChartsCore-6.3.lib
vtkCommonColor-6.3.lib
vtkCommonComputationalGeometry-6.3.lib
vtkCommonCore-6.3.lib
vtkCommonDataModel-6.3.lib
vtkCommonExecutionModel-6.3.lib
vtkCommonMath-6.3.lib
vtkCommonMisc-6.3.lib
vtkCommonSystem-6.3.lib
vtkCommonTransforms-6.3.lib
vtkDICOMParser-6.3.lib
vtkDomainsChemistry-6.3.lib
vtkexoIIc-6.3.lib
vtkexpat-6.3.lib
vtkFiltersAMR-6.3.lib
vtkFiltersCore-6.3.lib
vtkFiltersExtraction-6.3.lib
vtkFiltersFlowPaths-6.3.lib
vtkFiltersGeneral-6.3.lib
vtkFiltersGeneric-6.3.lib
vtkFiltersGeometry-6.3.lib
vtkFiltersHybrid-6.3.lib
vtkFiltersHyperTree-6.3.lib
vtkFiltersImaging-6.3.lib
vtkFiltersModeling-6.3.lib
vtkFiltersParallel-6.3.lib
vtkFiltersParallelImaging-6.3.lib
vtkFiltersProgrammable-6.3.lib
vtkFiltersSelection-6.3.lib
vtkFiltersSMP-6.3.lib
vtkFiltersSources-6.3.lib
vtkFiltersStatistics-6.3.lib
vtkFiltersTexture-6.3.lib
vtkFiltersVerdict-6.3.lib
vtkfreetype-6.3.lib
vtkftgl-6.3.lib
vtkGeovisCore-6.3.lib
vtkgl2ps-6.3.lib
vtkhdf5-6.3.lib
vtkhdf5_hl-6.3.lib
vtkImagingColor-6.3.lib
vtkImagingCore-6.3.lib
vtkImagingFourier-6.3.lib
vtkImagingGeneral-6.3.lib
vtkImagingHybrid-6.3.lib
vtkImagingMath-6.3.lib
vtkImagingMorphological-6.3.lib
vtkImagingSources-6.3.lib
vtkImagingStatistics-6.3.lib
vtkImagingStencil-6.3.lib
vtkInfovisCore-6.3.lib
vtkInfovisLayout-6.3.lib
vtkInteractionImage-6.3.lib
vtkInteractionStyle-6.3.lib
vtkInteractionWidgets-6.3.lib
vtkIOAMR-6.3.lib
vtkIOCore-6.3.lib
vtkIOEnSight-6.3.lib
vtkIOExodus-6.3.lib
vtkIOExport-6.3.lib
vtkIOGeometry-6.3.lib
vtkIOImage-6.3.lib
vtkIOImport-6.3.lib
vtkIOInfovis-6.3.lib
vtkIOLegacy-6.3.lib
vtkIOLSDyna-6.3.lib
vtkIOMINC-6.3.lib
vtkIOMovie-6.3.lib
vtkIONetCDF-6.3.lib
vtkIOParallel-6.3.lib
vtkIOParallelXML-6.3.lib
vtkIOPLY-6.3.lib
vtkIOSQL-6.3.lib
vtkIOVideo-6.3.lib
vtkIOXML-6.3.lib
vtkIOXMLParser-6.3.lib
vtkjpeg-6.3.lib
vtkjsoncpp-6.3.lib
vtklibxml2-6.3.lib
vtkmetaio-6.3.lib
vtkNetCDF-6.3.lib
vtkNetCDF_cxx-6.3.lib
vtkoggtheora-6.3.lib
vtkParallelCore-6.3.lib
vtkpng-6.3.lib
vtkproj4-6.3.lib
vtkRenderingAnnotation-6.3.lib
vtkRenderingContext2D-6.3.lib
vtkRenderingContextOpenGL-6.3.lib
vtkRenderingCore-6.3.lib
vtkRenderingFreeType-6.3.lib
vtkRenderingGL2PS-6.3.lib
vtkRenderingImage-6.3.lib
vtkRenderingLabel-6.3.lib
vtkRenderingLIC-6.3.lib
vtkRenderingLOD-6.3.lib
vtkRenderingOpenGL-6.3.lib
vtkRenderingVolume-6.3.lib
vtkRenderingVolumeOpenGL-6.3.lib
vtksqlite-6.3.lib
vtksys-6.3.lib
vtktiff-6.3.lib
vtkverdict-6.3.lib
vtkViewsContext2D-6.3.lib
vtkViewsCore-6.3.lib
vtkViewsInfovis-6.3.lib
vtkzlib-6.3.lib
小技巧:也可自己通过批处理程序获得某个文件夹下的所有文件名,自己选择需要的.lib文件名称
使用“获得文件名称.bat”生成的文件名文档filename.txt
“获得文件名称.bat”的内容
DIR *.* /B >filename.TXT
4.6 demo项目属性>连4接器->常规->附加库目录。。添加包含.lib文件的那个目录的绝对路径即可
4.7 go一把
需要源码和点云数据的请留言。