Menu

Tutorial for vtk.net

lotus
2006-09-19
2013-04-25
  • lotus

    lotus - 2006-09-19

    I just finished simple tutorial for vtk.net using c#.

    Andrew, please send message about your e-mail address. (send sf.net message to me)

    lotus.

     
    • awallin55

      awallin55 - 2007-07-19

      Where can this tutorial be found??

       
    • lotus

      lotus - 2007-07-19

      I attached preliminay tutorial of vtk dot net
      I already had sent it to author.
      But there are no response from author.

      Any comment will be okay.

      --lotus--

      --------------------start doc ------------------
      VTK.NET Tutorial
      http://vtkdotnet.sourceforte.net

      Doc. Version. 0.1
      Chapter 1
      Introduction
      1.1 Welcome to VTK.NET

      VTK.NET is a patch to the Visualization Toolkit, version 5.0.1 and 5.x, source to support building .NET wrappers within CMake for the Visual Studio 2005 environment. It uses Managed C++ 2.0 to wrap VTK headers. With these wrappers, you can use VTK from C#, Visual Basic (VB), J#, managed C++, or any other managed language. Included is a managed C++ Windows.Forms.Control to use in C# and VB Windows Forms projects.

      1.2 Quick Installation Guide

      1.2.1 Download

      You can download following files from http://vtkdotnet.sourceforge.net/

          * VTK-5.0.1-wrap-1.1-bin.zip
          * VTK-5.0.1-control-1.1.zip

      1.2.2 Extract VTK-5.0.1-wrap-1.1-bin.zip

          * will make VTK folder with sub-folders named bin, include, lib

      1.2.3 Copy or move extracted folders to someplace

      (ex: C:\Program Files\VTK )

      1.2.4 Add PATH of bin folder

         1. MyComputer (right click) ->Property->Advanced Tab -> Enviroment variable
         2. Add path C:\Program Files\VTK\bin;

      1.2.5 Extract VTK-5.0.1-control-1.1.zip and test vtk-control.

          * My preference is locate vtkFormsWindow.dll in C:\Program Files\VTK\bin folder
          * Make attention refernces when you test ControlSample folder. When distributed sample’s reference is invalid you must add it by manually.

      Chapter 2
      Getting Started with VTK.NET
      2.1 Your first vtk.net application using vtk.net control

      OK. You’re ready to start make vtk.net application. Before you do, though, there are a few things we need to mention, which will hopefully make the tutorial more instructive, useful and fun.

      Because VTK is really large library, there’s lots of information that we won’t be giving you. So if you have more deep question with VTK itself, your first choice is looking vtk examples in vtk original distribution. (you can download here http://www.vtk.org\). There are many bindings with vtk (Python, Tcl/Tk, etc) but basic form is very similar, you can directly translate to any language.

      In this Tutorial, we’re going to assume that you have fully working version of Visual Studio 2005 (Express or standard or any version) and correct installation of vtk.net wapper dlls and vtk.net contol. If any of this is not true, you ( or a frendly system adminstrator) will need to set up you system. you can find information on setup in other manuals( ^^ not yet prepared....)

      In this Tutorial, I assume your vtk installtion folder is C:\Program Files\VTK and vtk.net control is also located in C:\Program Files\VTK\bin.

      First you must check path varialbes.

      Start->Execute->cmd

      c:\> echo %PATH%

      The result string must contains VTK path (e.q. C:\Program Files\VTK\bin)

      2.1.1 Start Visual Studio

      Make new c# windows appliction. At Form1.cs (Design)

         1. Menu -> view -> ToolBox
         2. Right-click in the toolbox area
         3. At general tab, Select Add items on the menu.
         4. You have to browse to the vtkFormsWindow.dll and select it.
         5. You can see vtkFormsWindowContorl in Toolbox

      2.1.2 Add vtkFormWindowControl

      In the form designer, you can drag and drop the vtkFormsWindowControl from toolbox to the canvas to include it in your project. After adding control, reference of vtkFormsWindow is automatically add in solution view of your project.

      2.1.3 Add reference

      you have to add all references named *DotNet.dll (in C:\Program Files\VTK\bin folder) to the project.
      It will be added 10 reference to the project.

      2.1.4 Drop vtk.net control to form

      Drag vtk.net control from Toolbox to your application form. It will show default red cone figure to your form.

      I made dock property of this vtkcontrol to Fill mode. OK, you can run this program and it should be run without errors.

      2.1.5 Add code to plot vtk.net control

      Change Form1.cs code like this.

          namespace WindowsApplication1

          {

              public partial class Form1 : Form

              {

                  public Form1()

                  {

                      InitializeComponent();

                      AddConeToWindow(this.vtkFormsWindowControl1.GetRenderWindow());

                  }

                  void AddConeToWindow(vtk.vtkRenderWindow renWin)

                  {

                      //

                      // Next we create an instance of vtkConeSource and set some of its

                      // properties. The instance of vtkConeSource "cone" is part of a visualization

                      // pipeline (it is a source process object); it produces data (output type is

                      // vtkPolyData) which other filters may process.

                      //

                      vtk.vtkConeSource cone = new vtk.vtkConeSource();

                      cone.SetHeight(3.0f);

                      cone.SetRadius(1.0f);

                      cone.SetResolution(10);

                      //

                      // In this example we terminate the pipeline with a mapper process object.

                      // (Intermediate filters such as vtkShrinkPolyData could be inserted in

                      // between the source and the mapper.)  We create an instance of

                      // vtkPolyDataMapper to map the polygonal data into graphics primitives. We

                      // connect the output of the cone souece to the input of this mapper.

                      //

                      vtk.vtkPolyDataMapper coneMapper = new vtk.vtkPolyDataMapper();

                      coneMapper.SetInput(cone.GetOutput());

                      //

                      // Create an actor to represent the cone. The actor orchestrates rendering of

                      // the mapper’s graphics primitives. An actor also refers to properties via a

                      // vtkProperty instance, and includes an internal transformation matrix. We

                      // set this actor’s mapper to be coneMapper which we created above.

                      //

                      vtk.vtkActor coneActor = new vtk.vtkActor();

                      coneActor.SetMapper(coneMapper);

                      //

                      // Create the Renderer and assign actors to it. A renderer is like a

                      // viewport. It is part or all of a window on the screen and it is

                      // responsible for drawing the actors it has.  We also set the background

                      // color here

                      //

                      vtk.vtkRenderer ren1 = new vtk.vtkRenderer();

                      ren1.AddActor(coneActor);

                      ren1.SetBackground(0.1f, 0.2f, 0.4f);

                      //

                      // Finally we create the render window which will show up on the screen

                      // We put our renderer into the render window using AddRenderer. We also

                      // set the size to be 300 pixels by 300

                      //

                      renWin.AddRenderer(ren1);

                      //vtk.vtkRenderWindowInteractor iren = renWin.GetInteractor();

                  }

              }

          }

      2.1.6 Run IT !!!!

      Run it, you can rotate,zoom, pan cone with your mouse button.

       
    • Andrew Dolgert

      Andrew Dolgert - 2007-07-20

      Sorry. I'm grateful for the help. I had wanted to augment the tutorial. - Drew

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.