A tutorial on how to setup a Windows Forms Application utilizing ActiViz.NET can be found here: Setup a Windows Forms Application to use ActiViz.NET

Other Languages

See (Cxx), (Python)


If you have a simple question about this example contact us at VTKExamplesProject If your question is more complex and may require extended discussion, please use the VTK Discourse Forum



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.Diagnostics;

using Kitware.VTK;

namespace ActiViz.Examples {
   public partial class Form1 : Form {
      public Form1() {

      private void renderWindowControl1_Load(object sender, EventArgs e) {
         try {
         catch(Exception ex) {
            MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK);

      private void Planes() {
         // in this example we need the renderer first to retrieve the active camera
         // in order to get camera's frustum planes and renderer's aspectratio
         vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
         vtkRenderer renderer = vtkRenderer.New();
         renderer = renderWindow.GetRenderers().GetFirstRenderer();
         vtkCamera camera = renderer.GetActiveCamera();
         double[] aspect = renderer.GetAspect();
         double aspectRatio = aspect[0] / aspect[1];

         vtkPlanes planes = vtkPlanes.New();
         // one way
            // allocate memory for 24 unmanaged doubles
            int size = Marshal.SizeOf(typeof(double)) * 24;
            IntPtr ptr = Marshal.AllocHGlobal(size);
            camera.GetFrustumPlanes(aspectRatio, ptr);
            // in case we would need this values diectly we could copy 
            // the unmanaged double array to a managed array like so:

            // double[] planesArray = new double[24];
            // Marshal.Copy(ptr, planesArray, 0, 24);

            // but fortunately we can forward the IntPtr directly to the function 
            // SetFrustumPlanes()
            // free unmanaged memory
         // another way
            vtkSphereSource sphereSource = vtkSphereSource.New();
            double[] bounds = new double[6];
            bounds = sphereSource.GetOutput().GetBounds();
            planes.SetBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]);
         // nothing to visualize