Difference between revisions of "VTK/CSharp/ActiViz.NET"

From KitwarePublic
< VTK
Jump to navigationJump to search
m (changed some idioms)
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
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.<br />
 
Activiz .NET is Open source and [http://www.kitware.com/products/avdownload.php free to download]. It's easy to install thanks to intuitive install manager, just follow its instructions.
{{Note|This page is old and not up to date. Please refer to https://www.kitware.eu/activiz/ for up to date information.|error}}
 
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.<br /> 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.  
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.  
Line 11: Line 13:


== Installation of ActiViz.NET for Visual Studio Express Editions ==
== Installation of ActiViz.NET for Visual Studio Express Editions ==
With Visual Studio Express Editions you can use ActiViz.NET as well.  
With Visual Studio Express Editions you can use ActiViz.NET as well.
<h3>Setup a Windows Forms Application utilizing ActiViz.NET</h3>
<ul>
<ul>
<li>Having ActiViz.NET installed, open Visual Studio, goto Toolbox,
<li>Having ActiViz.NET installed, open Visual Studio, goto Toolbox,
Line 19: Line 23:
Click OK. Now you should see in your ToolBox a new control named RenderWindowControl.</li>
Click OK. Now you should see in your ToolBox a new control named RenderWindowControl.</li>
</ul>
</ul>
Let's start to develop a first "Hello World" application.
Let's start to develop a first "Hello World" Windows Forms Application.
 
<h4>Your first ActiViz.NET Windows Forms Application</h4>
== Your first ActiViz.NET application ==
<ul>
<ul>
<li>Create a new "Windows Forms Application" project.</li>
<li>Create a new "Windows Forms Application" project.</li>
<li>Add a reference to "Kitware.mummy.Runtime.dll":<br />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</li>
<li>Add a reference to "Kitware.mummy.Runtime.dll":<br />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</li>
<li>Open Form1.cs in Designmode and drag the RenderWindowControl onto your form.</li>
<li>Open Form1.cs in Designmode and drag the RenderWindowControl from the toolbox onto your form.</li>
<li>For now we set the property Dock of renderWindowControl1 to Fill.</li>
<li>For now we set the property Dock of renderWindowControl1 to Fill.</li>
<li>Double click on the renderWindowControl1 creates an OnLoad Event Handler named "renderWindowControl1_Load" in file Form1.cs.<br/>
<li>Double click on the renderWindowControl1 creates an OnLoad Event Handler named "renderWindowControl1_Load" in file Form1.cs.<br/>
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):<br />
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):<br />
<p style="font-family:Consolas; font-size:10pt; margin-left:20px;"><font COLOR="#0000ff">using</font> Kitware.VTK;</p></li>
<source lang="csharp">
<li>Go back to the body of method renderWindowControl1_Load and enter the following code snippet:
  using Kitware.VTK;
<p style="margin-left:20px;"><font FACE="Consolas" size="2" COLOR="#008000">// source object<br>
</source>
</font><font FACE="Consolas" size="2" COLOR="#2b91af">vtkSphereSource</font><font FACE="Consolas" size="2">
</li>
SphereSource = </font><font FACE="Consolas" size="2" COLOR="#2b91af">
<li>Go back to the body of method renderWindowControl1_Load and enter the following code snippet:<br />
vtkSphereSource</font><font FACE="Consolas" size="2">.New();<br />
<source lang="csharp">
SphereSource.SetRadius(0.5);<br>
  // source object
</font><font FACE="Consolas" size="2" COLOR="#008000">// mapper<br />
  vtkSphereSource SphereSource = vtkSphereSource.New();
</font><font FACE="Consolas" size="2" COLOR="#2b91af">vtkPolyDataMapper</font><font FACE="Consolas" size="2">
  SphereSource.SetRadius(0.5);
SphereMapper = </font><font FACE="Consolas" size="2" COLOR="#2b91af">
  // mapper
vtkPolyDataMapper</font><font FACE="Consolas" size="2">.New();<br />
  vtkPolyDataMapper SphereMapper = vtkPolyDataMapper.New();
SphereMapper.SetInputConnection(SphereSource.GetOutputPort());<br />
  SphereMapper.SetInputConnection(SphereSource.GetOutputPort());
</font><font FACE="Consolas" size="2" COLOR="#008000">// actor<br />
  // actor
</font><font FACE="Consolas" size="2" COLOR="#2b91af">vtkActor</font><font FACE="Consolas" size="2">
  vtkActor SphereActor = vtkActor.New();
SphereActor = </font><font FACE="Consolas" size="2" COLOR="#2b91af">vtkActor</font><font FACE="Consolas" size="2">.New();<br />
  SphereActor.SetMapper(SphereMapper);
SphereActor.SetMapper(SphereMapper);<br />
  // get a reference to the renderwindow of our renderWindowControl1
</font><font FACE="Consolas" size="2" COLOR="#008000">// get a reference to the  
  vtkRenderWindow RenderWindow = renderWindowControl1.RenderWindow;
renderwindow of our renderWindowControl1<br />
  // get a reference to the renderer
</font><font FACE="Consolas" size="2" COLOR="#2b91af">vtkRenderWindow</font><font FACE="Consolas" size="2">
  vtkRenderer Renderer = RenderWindow.GetRenderers().GetFirstRenderer();
RenderWindow = renderWindowControl1.RenderWindow;<br />
  // set background color
</font><font FACE="Consolas" size="2" COLOR="#008000">// renderer<br />
  Renderer.SetBackground(0.2, 0.3, 0.4);
</font><font FACE="Consolas" size="2" COLOR="#2b91af">vtkRenderer</font><font FACE="Consolas" size="2">
  // add actor to the renderer
Renderer = </font><font FACE="Consolas" size="2" COLOR="#2b91af">vtkRenderer</font><font FACE="Consolas" size="2">.New();<br />
  Renderer.AddActor(SphereActor);
Renderer = RenderWindow.GetRenderers().GetFirstRenderer();<br />
  // ensure all actors are visible (in this example not necessarely needed,
</font><font FACE="Consolas" size="2" COLOR="#008000">// set background color<br />
  // but in case more than one actor needs to be shown it might be a good idea)
</font><font FACE="Consolas" size="2">Renderer.SetBackground(0.2, 0.3, 0.4);<br />
  Renderer.ResetCamera();
</font><font FACE="Consolas" size="2" COLOR="#008000">// add actor to the  
</source></li></ul>
renderer<br />
 
</font><font FACE="Consolas" size="2">Renderer.AddActor(SphereActor);<br />
</font><font FACE="Consolas" size="2" COLOR="#008000">// ensure all actors are visible<br />
</font><font FACE="Consolas" size="2">Renderer.ResetCamera();</font></p></li></ul>
<br />
That's it.<br />
That's it.<br />
Press F5 to run the application.<br /><br />
Press F5 to run the application.<br /><br />
<h3>Setup a Console Application utilizing ActiViz.NET</h3>
<ul>
<li>There's nothing special to do. :-)</li>
</ul>
Let's start to develop a first "Hello World" console application.
<h4>Your first ActiViz.NET Console Application</h4>
<ul>
<li>Create a new "Console Application" project.</li>
<li>Add a reference to "Kitware.mummy.Runtime.dll" and "Kitware.VTK.dll":<br />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" and "Kitware.VTK.dll". Click OK</li>
<li>Open Program.cs and add the following "using statement" at the top the file (comparable with an #include statement for those of you coming from a c/c++ background):<br />
<source lang="csharp">
  using Kitware.VTK;
</source>
</li>
<li>Goto the main function and enter the following code snippet:<br />
<source lang="csharp">
  // Create a sphere
  vtkSphereSource sphereSource = vtkSphereSource.New();
  sphereSource.Update();
  vtkFeatureEdges featureEdges = vtkFeatureEdges.New();
  featureEdges.FeatureEdgesOff();
  featureEdges.BoundaryEdgesOn();
  featureEdges.NonManifoldEdgesOn();
  featureEdges.SetInputConnection(sphereSource.GetOutputPort());
  featureEdges.Update();
  int numberOfOpenEdges = featureEdges.GetOutput().GetNumberOfCells();
  if(numberOfOpenEdges > 0) {
      Console.WriteLine("Surface is not closed");
  }
  else {
      Console.WriteLine("Surface is closed");
  }
  // nothing to show graphically
  Console.WriteLine("\nPress any key to continue...");
  Console.ReadKey();
</source></li></ul>
That's it.<br />
Press F5 to run the application.
<p></p>
== VTK/Examples/CSharp ==
Here you will find examples: [[http://www.vtk.org/Wiki/VTK/Examples/CSharp ActiViz.NET examples]]
== Build ActiViz.NET with Visual Studio Express C++ 2008 ==
Here you will find a detailed tutorial how to build the ActiViz.NET control with Visual Studio C++ 2008:
[[http://www.vtk.org/Wiki/VTK/CSharp/ActiViz/Build Build ActiViz.NET with Visual Studio Express C++ 2008]]

Latest revision as of 16:52, 1 April 2022

Note: This page is old and not up to date. Please refer to https://www.kitware.eu/activiz/ for up to date information.

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.
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.

Setup a Windows Forms Application utilizing ActiViz.NET

  • 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" Windows Forms Application.

Your first ActiViz.NET Windows Forms 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 from the toolbox 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):
       using Kitware.VTK;
    
  • Go back to the body of method renderWindowControl1_Load and enter the following code snippet:
       // source object
       vtkSphereSource SphereSource = vtkSphereSource.New();
       SphereSource.SetRadius(0.5);
       // mapper
       vtkPolyDataMapper SphereMapper = vtkPolyDataMapper.New();
       SphereMapper.SetInputConnection(SphereSource.GetOutputPort());
       // actor
       vtkActor SphereActor = vtkActor.New();
       SphereActor.SetMapper(SphereMapper);
       // get a reference to the renderwindow of our renderWindowControl1
       vtkRenderWindow RenderWindow = renderWindowControl1.RenderWindow;
       // get a reference to the renderer
       vtkRenderer Renderer = RenderWindow.GetRenderers().GetFirstRenderer();
       // set background color
       Renderer.SetBackground(0.2, 0.3, 0.4);
       // add actor to the renderer
       Renderer.AddActor(SphereActor);
       // ensure all actors are visible (in this example not necessarely needed,
       // but in case more than one actor needs to be shown it might be a good idea)
       Renderer.ResetCamera();
    

That's it.
Press F5 to run the application.

Setup a Console Application utilizing ActiViz.NET

  • There's nothing special to do. :-)

Let's start to develop a first "Hello World" console application.

Your first ActiViz.NET Console Application

  • Create a new "Console Application" project.
  • Add a reference to "Kitware.mummy.Runtime.dll" and "Kitware.VTK.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" and "Kitware.VTK.dll". Click OK
  • Open Program.cs and add the following "using statement" at the top the file (comparable with an #include statement for those of you coming from a c/c++ background):
       using Kitware.VTK;
    
  • Goto the main function and enter the following code snippet:
       // Create a sphere
       vtkSphereSource sphereSource = vtkSphereSource.New();
       sphereSource.Update();
    
       vtkFeatureEdges featureEdges = vtkFeatureEdges.New();
       featureEdges.FeatureEdgesOff();
       featureEdges.BoundaryEdgesOn();
       featureEdges.NonManifoldEdgesOn();
       featureEdges.SetInputConnection(sphereSource.GetOutputPort());
       featureEdges.Update();
    
       int numberOfOpenEdges = featureEdges.GetOutput().GetNumberOfCells();
    
       if(numberOfOpenEdges > 0) {
          Console.WriteLine("Surface is not closed");
       }
       else {
          Console.WriteLine("Surface is closed");
       }
       // nothing to show graphically
       Console.WriteLine("\nPress any key to continue...");
       Console.ReadKey();
    

That's it.
Press F5 to run the application.

VTK/Examples/CSharp

Here you will find examples: [ActiViz.NET examples]


Build ActiViz.NET with Visual Studio Express C++ 2008

Here you will find a detailed tutorial how to build the ActiViz.NET control with Visual Studio C++ 2008: [Build ActiViz.NET with Visual Studio Express C++ 2008]