1. first on the VTK site: http://www.vtk.org can be downloaded to the VTK source code (VTK does not provide precompiled binary version, so the installation of VTK must be manually compiled), down after the unlock. VTK data download is also available on the website of VTK. This is the data file required for running VTK example. If we want to do some demonstration and testing after installing VTK, you need to download this package. My opinion is that you don't need to download it. After VTK is installed, We can compile and run the two example codes provided on the VTK website to check whether VTK has been installed successfully.
2. open the package and check that there is a readme.html file under the root directory. This is the installation document. Basically, it is okay to do this. However, this document does not cover the prerequisites such as cmake and OpenGL libraries in Linux, the installation steps are described below.
3. First, we can see that cmake is required for VTK installation. This is a make tool for cross-platform developed by kitware. OK, then download cmake-2.2.3-x86-linux.tar.gz at www.cmake.org. The undo object contains a tar file and a ReadMe file, and the Undo object is OK. The downloaded version is the compiled version, so no compilation is required. Here, I decompress the content in the TAR file to the/usr/local directory. In this way, the/usr/local/bin directory contains the executable files cmake and ccmake.
4. cmake ready. The following describes how to compile VTK based on the document (the source directory of VTK is/home/software/VTK ). First, create a directory dedicated to VTK compilation. If you need to re-compile the source code next time when creating a directory separately, you do not need to change the source code directory, you only need to re-create a build directory. Here, I created a directory:/home/software/VTK-build, enter the directory, and enter ccmake .. /VTK. Now the interactive interface of ccmake is displayed. (If you need to change the C and C ++ compilers, execute ccmake .. /before VTK, the export CC and cxx environment variables can be used), and then press the C key to start Configure. At this time, after configure ends, ccmake reports an error, the OpenGL include file and OpenGL library cannot be automatically found (in Linux, VTK is based on OpenGL, openGL only provides the most basic elements required for 2D and 3D plotting, such as points, lines, and surfaces. On Solaris, it may be Glx. For VTK-based developers, these elements are transparent, because VTK provides a unified interface for upper-layer developers, developers do not need to care about the platform. They only need to call a factory class creation method of VTK to obtain the render CL of the current platform. Ass), you need to manually set opengl_include_dir and opengl_gl_library in the advance mode of ccmake.
5. so, naturally to solve this problem, first of all think of Mesa, this is the current Linux platform OpenGL one of the best implementation, the current use of a lot of people, so, come to the http://www.mesa3d.org, download a mesa 6.4.2 file to prepare for installation. Mesa provides three things: mesademos, mesalib, and mesaglut. Demos, needless to say, mesalib contains libgl. so.1, libglu. so.1 these OpenGL core libraries, as well. H and other OpenGL include header files. Therefore, it is okay to download and install this mesalib. As for mesaglut, we all know that glut is OpenGL utility toolkit, it is a simple encapsulation and Extension Based on OpenGL, And mesa also implements the same thing, so it is called mesaglut. This thing does not need to be installed, because VTK only needs two libraries, GL and Glu, you can also install this mesaglut. I suggest installing it as well. It doesn't take up much space anyway. Besides, mesademos only need mesaglut to run it, maybe other applications will need glut to run in the future? So install them together. After unpacking the mesalib and mesaglut packages, a mesaxxx directory appears and compilation starts.
6. according to the documents on the mesa website, first go to the mesa source code directory, execute make, list a bunch of supported platforms, and finally there is an error message, but the output information clearly tells us that the ignore error can be used, so, continue to execute the command: Make linux-x86 (based on the output information of make to determine the following Platform keyword ), start to compile the source code of Mesa. Note that before installing and compiling Mesa, you must first install the xfree86 develop package, which is available on the RedHat CD, if this part is not installed, install it first and then install Mesa (you can use the Linux Add/delete program tool ). After compilation, execute make install. At this time, the script will ask where the Mesa is installed, such as where the include file is, and where the Lib file is installed, the default values are/usr/local/include and/usr/local/lib, which makes it OK and easy!
7. In fact, the above practice is to compile and install the stand-alone/xlib mode version of Mesa. This means that the compiled Mesa depends on xfree86 and works on xfree86. In contrast, mesa also has a dri/accelerated installation mode called DRI, DRI is also an opensource project. To enable mesa to work in DRI mode, you must first install dri and install dri to change the Linux kernel, there are some troubles, so this time we didn't do this, but there is no doubt that the performance will be much better with DRI, because he directly operates the video card. Currently, many graphics card manufacturers, such as ATI and NVIDIA, support dri. Therefore, if our graphics have high performance requirements, or use dri (if Mesa is compiled in DRI mode, the above make linux-x86 command will be changed to make Linux-dri, but it is far from changing the command to OK, for details, refer to the compilation/installation section on the mesa website ).
8. OK. After Mesa is installed, we can use the program in mesademos to verify it. Use mesademos to install mesaglut! After the mesademos package is unwrapped, A progs directory will be generated under the directory where we just installed Mesa. Make will be OK directly under this progs directory! Run the most famous gears program of Mesa to check whether it can be run!
9. VTK can be installed now. Click it again to create a build directory, and then ccmake .. /VTK. Sure enough, this time, there is no such error message. In the ccmake interface, you can configure whether VTK is compiled into shared libraries, and then press the C key again. Remember, as long as we make some changes to the configuration, we need to press the C key to re-configure until no changes are made, we can press the G key to generate makefile. OK. After ccmake is complete, you can make and directly enter the make command to start VTK compilation. This process is very long and requires patience (because compiling C ++ programs is much slower than C Programs ), enter make install. The installation is complete!
10. After the installation is complete, we can write a program for test and test. We can use the two official examples of VTK to test the program. However, there are three problems to note:
(1) The first one in the official code is to draw a sphere program. You need to change "" In the include statement to <> because we will add-I, in the # include <vtkactor. h> add a sentence # include <vtkproperty. h>, because vtkactor. class vtkproperty is defined in H, which is considered as a forward declaration error in the G ++ compiler. That is, the vtkproperty class is not defined before and cannot be referenced here, therefore, add the # include <vtkproperty. h>. Some compilers do not have this problem, but GCC does.
(2) To compile the source code, you also need to link to many VTK libraries. In the VTK documentation, we recommend that you use cmake to automatically generate makefile, but now I still don't, because I just got started with VTK, therefore, we use a stupid method. I wrote such a compilation command to link all the VTK libraries compiled under/usr/local/lib:
G ++-O quadric-O3-I/usr/local/include/vtk-5.0-L/usr/local/lib-wno-deprecated-lvtkcommon-lvtkdicomparser-lvtkexoiic-lvtkexpat-lvtkfiltering -lvtkfreetype-lvtkftgl-neural-lvtkgraphics-neural-lvtkimaging-lvtkio-lvtkjpeg-neural-lvtkpng-lvtkrendering-lvtksys-lvtktiff-neural-lvtkwidgets-lvtkzquadric. cxx
We can see that the header file of VTK is in the/usr/local/include/vtk-5.0 directory, and the library is in the/usr/local/lib directory.
(3) when compiling the source code, GCC will say that the header file of VTK does not comply with the specifications or anything. If you don't want to see the warning information, you can use the same command as above, add the-wno-deprecated switch to the compile command line.
11. Now, VTK installation and testing are complete. Note that the-I and-l switches must be added during code compilation. Before running the program, the export LD_LIBRARY_PATH =/usr/local/lib is required, in this way, the code can find the library files of VTK and mesa. In particular, the xfree86 package also contains libgl. so.1, In the/usr/x11r6/lib directory (because I installed Kde, Kde used QT, while QT needed OpenGL), but now we use Mesa, so, before executing the program, you need to export LD_LIBRARY_PATH =/usr/local/lib so that the program can use the correct dynamic library! If you are not at ease, you can run the LDD <Executable File> command to check which library files are used in the executable files after the export action is completed, you can clearly check whether the program uses the correct library.
12. as a matter of fact, we should not install Mesa. We can use the xfree86 Library and the header file in the develop package. In this article, Mesa is also based on xfree86. I have read libgl in RedHat. so.1 file source, is also from the XFree86-Mesa-Lib xxxxxx rpm, so, in fact, is mesa. In other words, libgl. so.1, GL. h, Glu. h. All these items are available (all under the/usr/include directory and/usr/lib directory). Therefore, you do not need to install Mesa unless you have installed the DRI mode of Mesa. However, this has not been tested, but it is only possible for the moment. After all, in the release of RedHat, OpenGL has all these items.
Add: "What is dri"-official explanation
The direct rendering infrastructure, also known as the DRI, is a framework for allowing direct access to graphics hardware under the X Window System in a safe and efficient manner. it has des changes to the X server, to several client libraries, and to the kernel. the first major use for the DRI is to create fast OpenGL implementations.
The dri is an integral part of xfree86 4.x, and integrates with mesa, an open source implementation of the OpenGL API. several 3D accelerated drivers have been written to the DRI specification, including drivers for chipsets produced by ATI, matrox, 3dfx, and Intel.
The dri was initially developed by precision insight, Inc. (PI) in cooperation with, and partially funded by Red Hat inc ., and SGI. since Pi's merger with VA Linux, and VA Linux 'Subsequent exit from Linux, the DRI is being maintained by tunsten Graphics Inc ., A new company formed by some of the initial dri developers from Pi. tunsten graphics is the current focal point for all dri development, and has open source developers continue to contribute to the project through the DRI SourceForge project.
It has been tested that you can install VTK without installing Mesa. You only need to install xfree86 develop package. The dynamic library and header file will be installed in/usr/lib, respectively, /usr/x11r6/lib and/usr/include/GL directory
The installation of Windows requires VC, that is, Microsoft's c ++ compiler. Here I use Visual Studio 2003, because this version provides the best support for C ++ standards, then download the VTK source code, vtkdata, and cmake.
The Windows version of cmake has a graphical interface. In fact, the principle and operation are the same as that in Linux, but this is just a graphical interface. Then we compile it step by step, just like in Linux, however, here cmake does not generate makefile, but instead generates. DSW ,. SLN is nothing more than Microsoft's Visual Studio projects and engineering files.
Note: The executable installation files of the Windows version provided by the VTK website are unavailable !!! This executable file does not have any. DLL ,. lib, only a bunch of TCL files and libraries. In short, C ++ and Java are not supported. Therefore, it is unavailable and must be built manually!