Sunteți pe pagina 1din 7

Install Guide C# and VTK .

NET Wrapper
Original Author: Marco Aurlio Silva Neto. Translated by: Gerbert ten Brinke Extended by: D. Kroon The following tutorial is written to be used with Visuals Studio C# Express Edition 2005.

Table of Contents
Download and Install .......................................................................................................................... 2 How to create a new project in Visual C# 2005 Express: .................................................................. 3 How to add VTK to C# project: ........................................................................................................... 4

Download and Install

First we must install Visual Studio C# Express Edition 2005. (Or the professional if you have a license). You can download a trial version of Visual Studion C# Express 2005 from the following link http://msdn.microsoft.com/vstudio/express/visualcsharp/download/default.aspx

Install the .NET Wrapper for VTK 5.0 http://sourceforge.net/projects/vtkdotnet/

You need the following files: VTK-5.0.1-control-1.1.zip VTK-5.0.1-wrap-1.1-bin.zip VTK-5.0.1-wrap-1.1-src.zip

Extract the packages in a local directory e.g. C:\VTK Add the "C:\VTK\VTK-5.0.1-control-1.1" and "C:\vtk\VTK-5.0.1-wrap-1.1-bin\VTK\bin" to the Windows System Environment variabele Path

2|Page

How to create a new project in Visual C# 2005 Express:

After executing VC#2005, the following screen is shown

Create a project: From the menu, select: "File - New Project", in the dialog, select Windows Application and type in the field Name, the name of your application.

3|Page

How to add VTK to C# project:

Select from the menu, "Project - Add Reference...". In the dialog that will open select "Browse" and then look for the directory where the file "VTK-5.0.1-wrapbin" is extracted, this folder contains some DLL' s and an executable. In the field "Filename" write "* DotNet.dll" and click "Enter", all DotNet files appear. Select all these files and click OK.

We can add a VTK tool to the toolbox using the menu "View ToolBox". A field with some tools will be shown.

4|Page

Select from the menu, "Tools - Choose Toolbox Items...". In the dialog the will open click "Browse" and locate folder "VTK-5.0.1-control-1". This folder contains a file "vtkFormsWindow.dll". Add this file and click OK. In case of an error (0x8007007E) copy the "vtkFormsWindow.dll" file to the VTK5.0.1-wrap-1.1-bin\VTK\bin folder, and try again. Still receiving an error? than download Dependency Walker and fix missing dll files ...

You can verify in the Toolbox that a control is added called vtkFormsWindowControl. Select this control and place it on the form (Form1.cs [ design ]).

5|Page

Double click on the red cone will show you the source code editor. Below the a few lines starting with using add the line: using vtk; Now you can use vtk from C#. Under of the InitializeComponent() line; Add the line: this.AddConeToWindow(this.vtkFormsWindowControl1.GetRenderWindow()); Below the function: public Form1() add following function: void AddConeToWindow(vtk.vtkRenderWindow renWin) { vtk.vtkConeSource cone = new vtk.vtkConeSource(); cone.SetHeight(3.0f); cone.SetRadius(1.0f); cone.SetResolution(30); vtk.vtkPolyDataMapper coneMapper = new vtk.vtkPolyDataMapper(); coneMapper.SetInput(cone.GetOutput()); vtk.vtkActor coneActor = new vtk.vtkActor(); coneActor.SetMapper(coneMapper); vtk.vtkRenderer ren1 = new vtk.vtkRenderer(); ren1.AddActor(coneActor); ren1.SetBackground(0.0f, 0.0f, 0.0f); renWin.AddRenderer(ren1);

} Click the green play button to execute the program. The final code should be: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using vtk; namespace Projeto_Teste { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.AddConeToWindow(this.vtkFormsWindowControl1.GetRenderWindow());
6|Page

} void AddConeToWindow(vtk.vtkRenderWindow renWin) { vtk.vtkConeSource cone = new vtk.vtkConeSource(); cone.SetHeight(3.0f); cone.SetRadius(1.0f); cone.SetResolution(30); vtk.vtkPolyDataMapper coneMapper = new vtk.vtkPolyDataMapper(); coneMapper.SetInput(cone.GetOutput()); vtk.vtkActor coneActor = new vtk.vtkActor(); coneActor.SetMapper(coneMapper); vtk.vtkRenderer ren1 = new vtk.vtkRenderer(); ren1.AddActor(coneActor); ren1.SetBackground(0.0f, 0.0f, 0.0f); renWin.AddRenderer(ren1); } } }

In case of the error "System.IO.FileNotFoundException was unhandled error", the dll or libraries files could not be found. Add the VTK dll and library folders to the Visual C# and System environment variables (path)

7|Page

S-ar putea să vă placă și