1. 程式人生 > >learn vtk by Tcl script on mac

learn vtk by Tcl script on mac

環境:
VTK-8.1.1
Mac OS X 10.13.6
/usr/bin/tclsh

build vtk,cmake一下:

cmake ./ -G "Unix Makefiles" \
-DVTK_USE_QVTK:BOOL=ON \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DVTK_USE_GUISUPPORT:BOOL=ON \
-DVTK_QT_VERSION=5 \
-DModule_vtkGUISupportQt:BOOL=ON \
-DModule_vtkGUISupportQtOpenGL:BOOL=ON \
-DModule_vtkGUISupportQtSQL:BOOL=ON \
-DModule_vtkGUISupportQtWebkit:BOOL=OFF \
-DModule_vtkRenderingQt:BOOL=ON \
-DModule_vtkViewsQt:BOOL=ON \
-DVTK_WRAP_TCL:BOOL=ON \
-DTCL_INTERNAL_PATH=/Users/weiyang/Downloads/VTK-8.1.1/ThirdParty/TclTk/internals/tk8.6

注意:Module_vtkGUISupportQtWebkit 是被關掉的。
然後make, make install。
接著嘗試使用tcl指令碼

tclsh assembly.tcl
can't find package vtk
    while executing
"package require vtk"
    (file "assembly.tcl" line 8)

檢視預設的Tcl變數 auto_path:

 [email protected]  ~/Downloads  tclsh
% puts $auto_path
/System/Library/Frameworks/Tcl.framework/Versions/8.5/Resources/Scripts /System/Library/Frameworks/Tcl.framework/Versions/8.5/Resources /usr/lib ~/Library/Tcl /Library/Tcl /System/Library/Tcl /System/Library/Tcl/8.5 ~/Library/Frameworks /Library/Frameworks /System/Library/Frameworks
%

尋找pkgIndex.tcl 的路徑:

[email protected]  ~  find / -name pkgIndex.tcl 2>/dev/null
/usr/local/lib/tcltk/vtk-8.1/pkgIndex.tcl
/System/Library/Tcl/tklib0.5/crosshair/pkgIndex.tcl
/System/Library/Tcl/tklib0.5/tablelist/pkgIndex.tcl
/System/Library/Tcl/tklib0.5/tooltip/pkgIndex.tcl
...

將包含pkgIndex.tcl的路徑/Users/weiyang/Downloads/VTK-8.1.1/Wrapping/Tcl

放到 auto_path中。可設定環境變數TCLLIBPATH

[email protected]  ~/Downloads/VTK-8.1.1/Examples/Rendering/Tcl  export TCLLIBPATH=/Users/weiyang/Downloads/VTK-8.1.1/Wrapping/Tcl
[email protected]  ~/Downloads/VTK-8.1.1/Examples/Rendering/Tcl  tclsh
% puts $auto_path
/Users/weiyang/Downloads/VTK-8.1.1/Wrapping/Tcl /System/Library/Frameworks/Tcl.framework/Versions/8.5/Resources/Scripts /System/Library/Frameworks/Tcl.framework/Versions/8.5/Resources /usr/lib ~/Library/Tcl /Library/Tcl /System/Library/Tcl /System/Library/Tcl/8.5 ~/Library/Frameworks /Library/Frameworks /System/Library/Frameworks
% exit

然後就能正常解釋,執行tcl指令碼:

 [email protected]  ~/Downloads/VTK-8.1.1/Examples/Rendering/Tcl  vtk assembly.tcl