From KitwarePublic
< VTK‎ | Examples‎ | CSharp
Revision as of 00:27, 12 June 2012 by Jochen (talk | contribs) (→‎Axes.cs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This example shows how to position an AxesActor in 3D. Notice that position and orientation of the AxesActor is done with a user transform.
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


VTK Examples CSharp GeometricObjects Axes.png
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 Axes() {
         vtkSphereSource sphereSource = vtkSphereSource.New();
         sphereSource.SetCenter(0.0, 0.0, 0.0);

         //create a mapper
         vtkPolyDataMapper sphereMapper = vtkPolyDataMapper.New();

         // create an actor
         vtkActor sphereActor = vtkActor.New();

         // a renderer and render window
         vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
         vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
         renderer.SetBackground(0.2, 0.3, 0.4);

         // add the actors to the scene

         vtkAxesActor axes = vtkAxesActor.New();
         // The axes are positioned with a user transform
         vtkTransform transform = vtkTransform.New();
         transform.Translate(0.75, 0.0, 0.0);
         // properties of the axes labels can be set as follows
         // this sets the x axis label to red
         // axes.GetXAxisCaptionActor2D().GetCaptionTextProperty().SetColor(1,0,0);

         // the actual text of the axis label can be changed:
         // axes.SetXAxisLabelText("test");

         // we need to call Render() for the whole renderWindow, 
         // because vtkAxesActor uses an overlayed renderer for the axes label
         // in total we have now two renderer