Activiz 使用筆記-2

換了個新機器,速度快了好多,因此開開森森的裝了64位的activiz沒想到出了點小問題,下面把遇到的問題和解決方案說一下:php

64位的下載地址也在這裏:web

http://www.kitware.com/opensource/avdownload.php
架構

安裝過程也是傻瓜式的,只要選擇好安裝位置便可,其他直接下一步。app

此次我使用的安裝文件是: ActiViz.NET-5.8.0.607-win64-OpenSource.exe 函數

安裝位置是:工具

D:\Program Files\ActiViz.NET 5.8.0 OpenSource Editionthis

安裝結束後,能夠打開上面的文件夾看一下:spa

其中bin文件夾內存放的就是咱們之後要調用的dll。調試

********************分割線************************************************component

安裝結束後,新建一個vs2010的C#窗體應用項目test1:

和32位activiz同樣,首先在項目中添加引用:

添加這兩個文件到引用。

此時,vs2010會給出兩個警告:


這時由於,此次裝的是64位amd架構的activiz,可是vs2010默認的生成項目的處理器架構是「x86」的,因此會出現衝突,解決辦法就是:點擊 項目-》test1屬性-》生成

將其中的「目標平臺」 從x86改成:x64便可,固然 release也要修改。


這個時候警告就消失了。

******************分割線**********************************************

在後臺代碼中添加命名空間的引用:

using Kitware.VTK;
******************分割線***********************************************

這個時候就有了新的問題:那就是沒法像上一篇筆記中寫的那樣,在工具箱中添加RenderWindowControl這個工具。

這個時候須要本身寫代碼來實如今窗體上添加RenderWindowControl。實現方式以下:


在窗體代碼中添加一個私有成員和私有方法:

 private RenderWindowControl _renwin = null;

///初始化renderwindowcontrol

    private void InitRenderWindowControl()
        {
            _renwin = new RenderWindowControl();
            _renwin.AddTestActors = false;
            _renwin.Location = new System.Drawing.Point(10,10);
            _renwin.Name = "_renwin";
            _renwin.Size = new System.Drawing.Size(100,100);
            _renwin.TabIndex = 0;
            _renwin.TestText = null;

            this.Controls.Add(_renwin);

        }

而後,在窗體的構造函數中添加這個初始化方法。

  public Form1()
        {
            InitializeComponent();
            InitRenderWindowControl();
        }

點擊調試程序,能夠看到窗體上出現了renderwindowcontrol

也能夠在初始函數中爲renderwindowcontrol添加load事件:

  _renwin.Load += new EventHandler(_renwin_Load);

(這一行代碼能夠加在InitRenderWindowControl()方法中,也能夠加在窗體的構造函數中。)

爲load事件添加代碼:

 void _renwin_Load(object sender, EventArgs e)
        {
            vtkSphereSource sphere = vtkSphereSource.New();
            sphere.SetThetaResolution(8);
            sphere.SetPhiResolution(16);

            vtkShrinkPolyData shrink = vtkShrinkPolyData.New();
            shrink.SetInputConnection(sphere.GetOutputPort());
            shrink.SetShrinkFactor(0.9);

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
            mapper.SetInputConnection(shrink.GetOutputPort());

            // The actor links the data pipeline to the rendering subsystem
            vtkActor actor = vtkActor.New();
            actor.SetMapper(mapper);
            actor.GetProperty().SetColor(1, 0, 0);

            // Create components of the rendering subsystem
            //
            vtkRenderer ren1 = _renwin.RenderWindow.GetRenderers().GetFirstRenderer();
            vtkRenderWindow renWin = _renwin.RenderWindow;

            // Add the actors to the renderer, set the window size
            //
            ren1.AddViewProp(actor);
            renWin.SetSize(250, 250);
            renWin.Render();
            vtkCamera camera = ren1.GetActiveCamera();
            camera.Zoom(1.5);
        }

運行效果以下:


***********結束啦,(*^__^*) *****************************

相關文章
相關標籤/搜索