Windows下编译和配置Vtk Web Demo

Paraview作为Ktware的产品提供了一个完整的Web客户端的后端渲染框架。具体文档和资料参考。
http://www.paraview.org/ParaView/Doc/Nightly/www/js-doc/index.html

经过调研发现其实Vtk 7.0里面包含了完整相关架构和代码以及示例。只是没有提供任何文档,在发布版本里面也没有任何编译结果和文档。
参考Paraview 5.0的资料对于vtk 7进行编译和测试,发现确实保留了完整的架构。

下面是编译和配置的简单记录,假定本文的读者有编译Vtk的经验,和安装配置paraview web的相关经验。简单起见,我们在windows下进行相应的安装配置,使用bitnami WAMP stack作为apache前端。

1)环境准备

安装Visual Studio 2012,CMake 3.5.2,Python 2.7.11 Amd64, pywin32-220.win-amd64-py2.7.exe, bitnami WAMP stack 5.6.18
其中Python 2.7的安装目录为C:\Python\Python27
bitnami WAMP stack安装目录为E:\Bitnami\wampstack-5.6.18-0

vtkpython本身可以支持python 2.x和3.x,但是vtkweb使用了tiwsted作为web服务,目前必须用python 2.x

所有目录都不是必须的,但是,如果目录不一致,请注意修改后续操作中的具体目录。

2)编译VTK

从vtk.org下载VTK-7.0.0.tar.gz,解压到E:\Vtk7build\VTK-7.0.0
同时下载 VTKData-7.0.0.tar.gz 和VTKLargeData-7.0.0.tar.gz 解压到E:\Vtk7build\VTK-7.0.0

用CMake编译x64(VS 2012 X64 )的vtk,修改和确认以下选项

  • BUILD_EXAMPLES
  • EXECUTEABLE_OUTPUT_PATH E:/Vtk7build/Result/Bin
  • LIBRARY_OUTPUT_PATH E:/Vtk7build/Result/Lib
  • CMAKE_INSTALL_PREFIX E:/Vtk7build/Install
  • VTK_Group_Imaging
  • VTK_Group_Views
  • VTK_Group_Web
  • VTK_PYTHON_VERSION 2
  • VTK_USE_LARGE_DATA
  • VTK_WRAP_PYTHON
  • VTKMY_WRAP_PYTHON
  • Module_vtkPythonInterpreter

编译vtk.sln之后,build名为Install的project,所有结果会输出到E:\Vtk7build\Install目录之下。

3)测试vtkpython

Copy Install目录为WebTest,为了避免影响原始编译结果。
把C:\Python\Python27\python27.dll拷贝到E:\Vtk7build\WebTest\bin目录下,和vtkpython放在一下。

创建一个bat文件为vtkpython设置运行环境,文件命名为windows_path.Release.bat

set PATH=E:\Vtk7build\WebTest\bin;C:\Python\Python27;%PATH%

set PYTHONPATH=E:\Vtk7build\WebTest\lib\python2.7\site-packages;E:\Vtk7build\WebTest\lib\python2.7\site-packages\vtk;E:\Vtk7build\WebTest\bin;C:\Python\Python27\Lib;C:\Python\Python27\DLLs;%PYTHONPATH%

在cmd窗口依次执行windows_path.Release.bat和E:\Vtk7build\WebTest\bin\vtkpython.exe
就可以进入vtkpython解释器,执行各种基于python的vtk example

4) 使用python launcher直接启动vtk web

(a) E:\Vtk7build 作为根目录,相当于paraview配置的/data
(b) E:\Vtk7build\WebTest 相当于paraview配置的 /data/pv,vtk install的目录结构
(c) E:\Vtk7build\WebProc 相当于paraview配置的 /data/pvw,保存launcher和配置
(d) launcher的配置
E:\Vtk7build\WebProc\conf\launcher.json
-这个配置文件适用于直接启动launcher

    {
        "configuration": {
            "host" : "localhost",
            "port" : 8080,
            "endpoint": "paraview",                   
            "content": "E:/Vtk7build/WebTest/lib/www",           
            "proxy_file" : "E:/Vtk7build/proxy.txt",
            "sessionURL" : "ws://${host}:${port}/ws",
            "timeout" : 25,                           
            "log_dir" : "E:/Vtk7build/WebProc/logs",             
            "upload_dir" : "E:/Vtk7build/WebProc/upload",
            "fields" : ["file", "host", "port", "updir"] 
        },

        "sessionData" : { "updir": "/Home" },     

        "resources" : [ { "host" : "localhost", "port_range" : [9001, 9003] } ],

        "properties" : {
            "vtkpython" : "E:/Vtk7build/WebTest/bin/vtkpython.exe",
            "pvpython" : "/.../ParaView/build/bin/pvpython",
            "vtk_python_path": "E:/Vtk7build/WebTest/lib/python2.7/site-packages/vtk/web",
            "pv_python_path": "/.../ParaView/build/lib/site-packages/paraview/web",
            "plugins_path": "/.../ParaView/build/lib",
            "dataDir": "E:/Vtk7build/build/ExternalData"
        },

        "apps" : {
            "cone" : {
                "cmd" : [
                    "${vtkpython}", "${vtk_python_path}/vtk_web_cone.py", "--port", "$port" ],
                "ready_line" : "Starting factory"
            },
            "graph" : {
                "cmd" : [
                    "${vtkpython}", "${vtk_python_path}/vtk_web_graph.py", "--port", "$port",
                    "--vertices", "${numberOfVertices}", "--edges", "${numberOfEdges}" ],
                "ready_line" : "Starting factory"
            },
            "phylotree" : {
                "cmd" : [
                    "${vtkpython}", "${vtk_python_path}/vtk_web_phylogenetic_tree.py", "--port", "$port",
                    "--tree", "${dataDir}/visomics/${treeFile}", "--table", "${dataDir}/visomics/${tableFile}" ],
                "ready_line" : "Starting factory"
            },
            "filebrowser" : {
                "cmd" : [
                    "${vtkpython}", "${vtk_python_path}/vtk_web_filebrowser.py",
                    "--port", "${port}", "--data-dir", "${dataDir}" ],
                "ready_line" : "Starting factory"
            },
            "data_prober": {
                "cmd": [
                    "${pvpython}", "-dr", "${pv_python_path}/pv_web_data_prober.py",
                    "--port", "${port}", "--data-dir", "${dataDir}", "-f" ],
                "ready_line" : "Starting factory"
            },
            "visualizer": {
                "cmd": [
                    "${pvpython}", "-dr", "${pv_python_path}/pv_web_visualizer.py",
                    "--plugins", "${plugins_path}/libPointSprite_Plugin.so", "--port", "${port}",
                    "--data-dir", "${dataDir}", "--load-file", "${dataDir}/${fileToLoad}",
                    "--authKey", "${secret}", "-f" ],
                "ready_line" : "Starting factory"
            },
            "loader": {
                "cmd": [
                    "${pvpython}", "-dr", "${pv_python_path}/pv_web_file_loader.py",
                    "--port", "${port}", "--data-dir", "${dataDir}",
                    "--load-file", "${dataDir}/${fileToLoad}", "-f" ],
                "ready_line" : "Starting factory"
            },
            "launcher" : {
                "cmd": [
                    "/.../ParaView/Web/Applications/Parallel/server/launcher.sh",
                    "${port}", "${client}", "${resources}", "${file}" ],
                "ready_line" : "Starting factory"
            },
            "your_app": {
                "cmd": [
                    "your_shell_script.sh", "--resource-host", "${host}", "--resource-port", "${port}",
                    "--session-id", "${id}", "--generated-password", "${secret}",
                    "--application-key", "${application}" ],
                "ready_line": "Output line from your shell script indicating process is ready"
            }
        }

(e) 创建proxy.txt文件
E:/Vtk7build/proxy.txt

(f) 启动脚本
E:\Vtk7build\WebProc\bin\start.bat

set PATH=E:\Vtk7build\WebTest\bin;C:\Python\Python27;%PATH%

set PYTHONPATH=E:\Vtk7build\WebTest\lib\python2.7\site-packages;E:\Vtk7build\WebTest\lib\python2.7\site-packages\vtk;E:\Vtk7build\WebTest\bin;C:\Python\Python27\Lib;C:\Python\Python27\DLLs;%PYTHONPATH%

E:\Vtk7build\WebTest\bin\vtkpython.exe E:\Vtk7build\WebTest\lib\python2.7\site-packages\vtk\web\launcher.py E:\Vtk7build\WebProc\conf\launcher.json -d

(g) 到此为止,可以通过start.bat启动服务器,运行演示程序了
访问路径
http://localhost:8080/apps/xxxx
xxx后面对应的路径以这个目录的子目录为准 E:\Vtk7build\WebTest\lib\www\apps
* phylotree 需要额外的文件 可以从
http://visomics.org/visomicsdata.git
- Data/treeData/anolis.phy
- Data/treeData/anolisDataAppended.csv
然后放到${dataDir}/visomics/下面

5)使用apache作为web前端

(a) 做一个launcher的备份,命名为aluncher.json,修改session配置
“sessionURL” : “ws://172.25.73.200/proxy?sessionId=${id}”,
创建一个新的启动用E:\Vtk7build\WebProc\bin\astart.bat

set PATH=E:\Vtk7build\WebTest\bin;C:\Python\Python27;%PATH%

set PYTHONPATH=E:\Vtk7build\WebTest\lib\python2.7\site-packages;E:\Vtk7build\WebTest\lib\python2.7\site-packages\vtk;E:\Vtk7build\WebTest\bin;C:\Python\Python27\Lib;C:\Python\Python27\DLLs;%PYTHONPATH%

E:\Vtk7build\WebTest\bin\vtkpython.exe E:\Vtk7build\WebTest\lib\python2.7\site-packages\vtk\web\launcher.py E:\Vtk7build\WebProc\conf\alauncher.json -d

(b) 修改和配置Modules in E:\Bitnami\wampstack-5.6.18-0\apache2\conf\httpd.conf
Enable
vhost_alias
proxy
proxy_http
proxy_wstunnel
rewrite
(c) 修改配置virtul host配置(E:\Bitnami\wampstack-5.6.18-0\apache2\conf\httpd.conf)
Include conf/extra/httpd-vhosts.conf
注释掉 Include “E:/Bitnami/wampstack-5.6.18-0/apache2/conf/bitnami/bitnami.conf”
禁止bitnami的默认virtual host
(d) 配置virtual host
E:\Bitnami\wampstack-5.6.18-0\apache2\conf\extra\httpd-vhosts.conf中只保留只一个配置

<VirtualHost *:80> 
    ServerName 172.25.73.200 
    ServerAdmin [email protected] 

    DocumentRoot "E:/Vtk7build/WebTest/lib/www" 

    ErrorLog E:/Vtk7build/WebProc/logs/error.log 
    CustomLog E:/Vtk7build/WebProc/logs/access.log combined 

      <Directory E:/Vtk7build/WebTest/lib/www> 
          Options Indexes FollowSymLinks 
          Order allow,deny 
          Allow from all 
          AllowOverride None 
          Require all granted 
      </Directory> 

# Handle launcher forwarding 
      ProxyPass /paraview http://localhost:8080/paraview 

      # Handle WebSocket forwarding 
      RewriteEngine On 
      # The following line is used for debuging rewrite 
      LogLevel debug rewrite:trace6 

      RewriteMap  session-to-port  txt:E:/Vtk7build/proxy.txt 
      RewriteCond %{QUERY_STRING}  ^sessionId=(.*)$ [NC] RewriteRule ^/proxy.*$ ws://${session-to-port:%1}/ws [P] </VirtualHost> 

(e) 启动测试
启动astart.bat,启动apache
通过http://localhost/apps/**来访问,应该就可以正常工作了。

你可能感兴趣的:(windows,Web,VTK)