WPF 3D with Helix Toolkit

Helix Toolkit builds on the 3-D functionality in Windows Presentation Foundation (WPF).  This toolkit provides a higher level API for working with 3D in WPF, via a collection of controls and helper classes.

Using the Package Manager Console To install HelixToolkit.Wpf, run the following command in the Package Manager Console.

PM> Install-Package HelixToolkit.Wpf

Using the Nuget UI

To find HelixToolkit in NuGet, follow these steps:
1. Open your project in Visual Studio.
2. Right click on the References folder and select “Manage Nuget Packages…” from the context menu.
3. In the “Manage Nuget Packages” dialog, select “Online” on the right.
4. In the search field, enter “HelixToolkit”.
5. Select the HelixToolkit.Wpf package and press the Install button.

Creating a 3D view

The HelixViewport3D is the object that will contain our 3D scene. This is a WPF control allowing for imperative or declarative coding. Lets create a HelixViewport3D object using C#.

private void Create3DViewPort() { var hVp3D = new HelixViewport3D(); }

Using XAML object creation would look like this.

<code>&lt;Window x:Class="GettingStartedDemo.MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:h="http://helix-toolkit.org/wpf"
        Title="Getting Started Demo" Height="480" Width="640"&gt;

     &lt;h:HelixViewport3D &gt;
     &lt;/h:HelixViewport3D&gt;

 &lt;/Window&gt;
</code>

This gives us a 3D space in which to setup our scene and work with 3D objects.

Adding lights

Next we need to add lighting to the HelixViewport3D. Without lighting, objects in the view-port scene will not be visible.

In C#:

<code>private void Create3DViewPort()
{
    var hVp3D = new HelixViewport3D();
    var lights = new DefaultLights();
    hVp3D.Children.Add(lights);
} 
</code>

In XAML:

<code>&lt;h:HelixViewport3D &gt;
     &lt;h:DefaultLights/&gt;
 &lt;/h:HelixViewport3D&gt;
</code>

Adding 3D content

Now that we have light and a view-port we can add a 3D object. Helix Toolkit comes with several 3D objects such as a box, tube, helix, pipe, and of course a teapot. Let’s add the teapot to the view-port.

In C#:

<code> private void Create3DViewPort()
 {
     var hVp3D = new HelixViewport3D();
     var lights = new DefaultLights();
     var teaPot = new Teapot();
     hVp3D.Children.Add(lights);
     hVp3D.Children.Add(teaPot);
  } 
</code>

In XAML:

<code> &lt;h:HelixViewport3D &gt;
      &lt;h:DefaultLights/&gt;
      &lt;h:Teapot/&gt;
 &lt;/h:HelixViewport3D&gt;
</code>

Complete Getting Started Example Code

In C#:

<code>public partial class MainWindow
{
    public MainWindow()
    {
        this.InitializeComponent();
        Create3DViewPort();
    }

    private void Create3DViewPort()
    {
        var hVp3D = new HelixViewport3D();
        var lights = new DefaultLights();
        var teaPot = new Teapot();
        hVp3D.Children.Add(lights);
        hVp3D.Children.Add(teaPot);
        this.AddChild(hVp3D);
    }
}
</code>

In XAML:

<code>&lt;Window x:Class="GettingStartedDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:h="http://helix-toolkit.org/wpf"
        Title="Getting Started Demo" Height="480" Width="640"&gt;

    &lt;h:HelixViewport3D &gt;
        &lt;h:DefaultLights/&gt;
        &lt;h:Teapot/&gt;
    &lt;/h:HelixViewport3D&gt;</code>

Graph Plotting in C#

 

 

 

 

 

 

 

Plotting a graph from a set of test-related data is a common software-development task. In my experience, the most common approach is to import data into an Excel spreadsheet, then produce the graph manually using the Excel built-in graphing features. This works well in most situations, but if the underlying data changes frequently, creating graphs by hand can quickly become tedious.
You can automate the process using Windows Presentation Foundation (WPF) technology.

Preparing the Project for Graph Plotting 
Launch Visual Studio and create a new C# project using the WPF Application template. Although you can programmatically generate graphs using WPF primitives, I suggest using the convenient Dynamic Data Display (D3) library developed by a Microsoft Research lab.

You can download the library for free from the CodePlex open source hosting site at codeplex.com/dynamicdatadisplay. You should save a copy of this library in the root directory of your project, then add a reference to the DLL in your project by right-clicking on the project name, select the Add Reference option and point to the DLL file in your root directory.

Next you need to double-click on the file Window1.xaml to load the UI definitions for the project. You should add a reference to the graphic library DLL as follows:

xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"
Title="Window1" Height="500" Width="800" Background="Wheat">


After that, you can add the key plotting object:

<d3:ChartPlotter Name="plotter" Margin="10,10,20,10">
  <d3:ChartPlotter.HorizontalAxis>
    <d3:HorizontalDateTimeAxis Name="dateAxis"/>
  </d3:ChartPlotter.HorizontalAxis>
  <d3:ChartPlotter.VerticalAxis>
    <d3:VerticalIntegerAxis Name="countAxis"/>
  </d3:ChartPlotter.VerticalAxis>
  <d3:Header FontFamily="Arial" Content="Bug Information"/>
  <d3:VerticalAxisTitle FontFamily="Arial" Content="Count"/>
  <d3:HorizontalAxisTitle FontFamily="Arial" Content="Date"/>
</d3:ChartPlotter>

The techniques that I presented here can be used to programmatically generate graphs. The key to the technique is the Dynamic Data Display (D3) library from Microsoft Research. This approach is very useful if the underlying data changes frequently.

WPF Useful Links

The Windows Presentation Foundation (WPF) is a graphical display system for Windows. WPF is designed for .NET, influenced by modern display technologies such as HTML and Flash, and hardware-accelerated. It is also the most radical change to hit Windows user interfaces since Windows 95. It allows you to build advanced user interfaces (UIs) that incorporate documents, media, two-dimensional (2D) and three-dimensional (3D) graphics, animations, and weblike characteristics.

In a pre-WPF world, developing a Windows application would have required the use of several different technologies. For instance, in order to add forms and user controls to your application, you needed to use the Windows Forms included in the .NET Framework. You had to use GDI+ to create images and 2D graphics. To add 3D graphics, you would have needed to use Direct3D or OpenGL.

WPF is designed to be a unified solution for application development, providing a seamless integration of different technologies. With WPF, you can create vector graphics or complex animations and incorporate media into your applications to address all of the areas just listed.

The following links are useful to learn the WPF programing model:

1-    WPF Official Website

http://windowsclient.net/wpf/

2-    Pete Brown’s Blog

http://10rem.net/blog

3-    Welcome to the Windows Presentation Foundation Resource Guide

http://www.wpfpedia.com/

More »

Windows Presentation Foundation

WPF or Windows Presentation Foundation is a new graphical display framework for Windows. This new system is designed to be used by .NET applications and allows the creation of dynamic, interactive graphical user interfaces. One of the most important features of WPF is the integration of DirectX. DirectX provides WPF with the ability to take advantage of the hardware acceleration on today’s graphics cards (GPUs). This allows the graphics load on the CPU to be greatly reduced, while at the same time, expanding the capabilities of the graphical display.

What WPF is and What XAML is

WPF provides a collection of controls such as buttons and grids, which are written in the Extensible Application Markup Language (XAML). XAML is an XML-based markup language created by Microsoft to separate the graphical and interactive elements of application from the main operations in the application, which are written in C# or Visual Basic. The beauty of WPF is how it is able to take advantage of the robustness of C# or Visual Basic, while at the same time using a simple XAML file to create the interface for the application.

The typical way that WPF creates and displays content goes like this:

1. XAML describes how the controls, images, video, and other assets are shown.
2. C# gives these assets their functionality.
3. The compiler then puts the XAML UI and functionality together into an executable (EXE) file for a Windows application or a XAML browser application (XBAP) executable for online applications.
4. The browser or Windows then displays the application.

Copyright © All Rights Reserved - C# Learners