Visualization in C# language using VTK potential can be implemented using Activiz .NET library, which is a package containing .NET wrappers for all VTK objects.
Activiz .NET is Open source and free to download. It's easy to install thanks to intuitive install manager, just follow its instructions.
After the installation process is done, open MS Visual Studio and start existing (or create new) Windows Forms Application project. First we have to provide access to Activiz .NET library by providing library references.
One of the easiest ways how to manage library references is to let NuGet Package Manager to do it for us. (Installing an extension is only possible with the full version of Visual Studio). After installation of this extension, right click on the name of your solution in Solution Explorer and select Manage NuGet Packages for Solution. In opened dialog window you should be now able to see Kitware Activiz.NET library ready to be installed to your project. Click on the Install button, select projects of solution where to add references to and finish the process.
Installation of ActiViz.NET for Visual Studio Express Editions
With Visual Studio Express Editions you can use ActiViz.NET as well.
- Having ActiViz.NET installed, open Visual Studio, goto Toolbox, right click on any tab and invoke "Add tab" to add a new panel and give it a name (e.g. "VTK 5.8 ActiViz.NET").
- Then invoke "Choose Items..." and in the following dialog click on button "Browse...", navigate to your ActiViz.NET installation folder, browse to /bin folder, select "Kitware.VTK.dll".
Click OK. Now you should see in your ToolBox a new control named RenderWindowControl.
Let's start to develop a first "Hello World" application.
Your first ActiViz.NET application
- Create a new "Windows Forms Application" project.
- Add a reference to "Kitware.mummy.Runtime.dll". In your Solution Explorer, right click "References" and choose "Add reference...", click Browse tab, navigate to your ActiViz.NET installation folder, browse to /bin folder, select "Kitware.mummy.Runtime.dll". Click OK
- Open Form1.cs in Designmode and drag the RenderWindowControl onto your form.
- For now we set the property Dock of renderWindowControl1 to Fill.
- Double click on the renderWindowControl1 creates an OnLoad Event Handler named "renderWindowControl1_Load" in file Form1.cs.
Stay in Form1.cs and add the following "using statement" at the top of Form1.cs (comparable with an #include statement for those of you coming from a c/c++ background):
- Go back to the body of method renderWindowControl1_Load and enter the following code snippet:
// source object
vtkSphereSource SphereSource = vtkSphereSource.New();
vtkPolyDataMapper SphereMapper = vtkPolyDataMapper.New();
vtkActor SphereActor = vtkActor.New();
// get a reference to the renderwindow of our renderWindowControl1
vtkRenderWindow RenderWindow = renderWindowControl1.RenderWindow;
vtkRenderer Renderer = vtkRenderer.New();
Renderer = RenderWindow.GetRenderers().GetFirstRenderer();
// set background color
Renderer.SetBackground(0.2, 0.3, 0.4);
// add our actor to the renderer
// make everything nicely visible
That's it. Isn't it really cool and easy to use VTK within managed code?
Press F5 to run the application.