Table of contents
Preface
Tutorial: Advanced VTK graphics and image development (1.3 Create a simple VTK program)
CMake: used for construction and management of project projects.
1. Create folders and write documents
(1) Create a new folder Chap01 to store the project sample program
(2) Create a new text document CMakeLists.txt as a script file to store the project directory
(3) Create a new .cpp file to write project code
(4) Create a new folder bin, used to store the compiled output of CMake
2.CMake compilation
(1) Open CMake and select the file path
(2) Configure->Generate
(3) Ensure that the CMakeLists.txt document is correct
(4) After successful generation, open the folder "F:/VTK/Examples/Chap01/bin" and the following files have been generated
(5) Problems during compilation , please refer to: Problems when Cmake compiles VTK: error configuration process, project files may be invalid solution
3.VS compile and run the project
(1) Open Chap01.sln in the folder "F:/VTK/Examples/Chap01/bin"
(2) Select the cpp file, use the shortcut key F7 to compile and F5 to run
appendix
CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(Chap01)
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})
ADD_EXECUTABLE(1.3_TestVTKInstall 1.3_TestVTKInstall.cpp)
TARGET_LINK_LIBRARIES(1.3_TestVTKInstall ${VTK_LIBRARIES})
※※※ Pay attention to the spaces! ! There can be no mistakes! !
.cpp file source code for testing
#include <vtkRenderWindow.h>
#include <vtkSmartPointer.h>
int main()
{
//用智能指针定义了一个类型为vtkRenderWindow的对象
//VTK类实例化对象也可:vtkRenderWindow* renWin = vtkRenderWindow::New();
vtkSmartPointer<vtkRenderWindow>renWin = vtkSmartPointer<vtkRenderWindow>::New();
//调用vtkRenderWindow里的方法显示并渲染VTK窗口
renWin->Render();
//让程序暂停下来,等待用户输入,显示VTK窗口。若注释掉,将会导致VTK窗口一闪而过
std::cin.get();
return 0;
}
※※※ The output is just a window