Fast Point 3D Example for WinForms

Nevron NOV Chart for WinForms ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WinForms Chart examples are also available as a stand-alone Visual Studio solution in C# and VB.NET, which you can download from the links below.

Fast Point 3D Example for WinForms Description

This example demonstrates how to create a XYZ scatter point chart rendering millions of data points in real-time using the NFastPointSeries.


Fast Point 3D

C# Fast Point 3D Example Code for Nevron Chart for WinForms
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.Chart.Tools;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;

namespace NovWinFormsProject
{
	public partial class Form1 : Form
	{
		#region Constructors

		public Form1()
		{
			InitializeComponent();

			// Set form title
			Text = "NOV WinForms - NFastPoint3D";

			// Create the NOV example and its controls
			NWidget exampleContent = CreateExampleContent();
			NWidget exampleControls = CreateExampleControls();
			if (exampleControls != null)
			{
				exampleControls.PreferredWidth = 300;
			}

			// Place the example and its controls in a pair box
			NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
			pairBox.FillMode = ENStackFillMode.First;
			pairBox.FitMode = ENStackFitMode.First;
			pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);

			// Host the example in the form
			NNovWidgetHost host = new NNovWidgetHost(pairBox);
			host.Dock = DockStyle.Fill;
			Controls.Add(host);
		}

		#endregion

        #region Example

        /// 
        /// 
        /// 
        /// 
        public NWidget CreateExampleContent()
		{
			NChartViewWithCommandBars chartViewWithCommandBars = new NChartViewWithCommandBars();
			NChartView chartView = chartViewWithCommandBars.View;
            chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian);

            chartView.Registered += OnChartViewRegistered;
            chartView.Unregistered += OnChartViewUnregistered;

            m_Title = chartView.Surface.Titles[0];
            m_Title.Text = "Fast Point 3D";

            NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0];

            chart.Enable3D = true;
            chart.ModelWidth = 50;
            chart.ModelHeight = 50;
            chart.ModelDepth = 50;
            chart.Projection.SetPredefinedProjection(ENPredefinedProjection.Perspective1);
            chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.GlitterLeft);

            ConfigureLinearScale(chart.Axes[ENCartesianAxis.PrimaryX]);
            ConfigureLinearScale(chart.Axes[ENCartesianAxis.PrimaryY]);
            ConfigureLinearScale(chart.Axes[ENCartesianAxis.Depth]);

            // setup the fast point series
            m_FastPointSeries = new NFastPointSeries();
            chart.Series.Add(m_FastPointSeries);
            m_FastPointSeries.Name = "FastPoint Series";
            m_FastPointSeries.FillColorMode = ENColorMode.Custom;

            chart.Interactor = new NInteractor(new NTrackballTool());

            // init the random colors array
            m_RandomColors = new uint[10000];
            Random random = new Random();
            for (int i = 0; i < m_RandomColors.Length; i++)
            {
                uint red = (uint)(255 * random.NextDouble());
                uint green = (uint)(255 * random.NextDouble());
                uint blue = (uint)(255 * random.NextDouble());

                m_RandomColors[i] = (uint)(0xFF000000 | (red << 16) | (green << 8) | blue);
            }

            return chartViewWithCommandBars;
		}
        /// 
        /// 
        /// 
        /// 
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();
			NUniSizeBoxGroup group = new NUniSizeBoxGroup(stack);

            m_PointCountComboBox = new NComboBox();
            m_PointCountComboBox.Items.Fill(new string[] { "100K", "500K", "1M", "2M", "10M"});
            m_PointCountComboBox.SelectedIndexChanged += OnPointCountComboBoxSelectedIndexChanged;
            m_PointCountComboBox.SelectedIndex = 2;

            stack.Add(NPairBox.Create("Point Count:", m_PointCountComboBox));

            m_PointSizeNumericUpDown = new NNumericUpDown();
            m_PointSizeNumericUpDown.Value = 2;
            m_PointSizeNumericUpDown.Minimum = 1;
            m_PointSizeNumericUpDown.Maximum = 20;
            m_PointSizeNumericUpDown.ValueChanged += OnPointSizeNumericUpDownValueChanged;
            stack.Add(NPairBox.Create("Point Size:", m_PointSizeNumericUpDown));

            m_EnableShaderRenderingCheckBox = new NCheckBox();
            m_EnableShaderRenderingCheckBox.CheckedChanged += OnEnableShaderRenderingCheckBoxChanged;
            m_EnableShaderRenderingCheckBox.Checked = m_FastPointSeries.EnableShaderRendering;
            stack.Add(NPairBox.Create("Enable Shader Rendering:", m_EnableShaderRenderingCheckBox));

            m_StartStopTimerButton = new NButton("Stop Timer");
            m_StartStopTimerButton.Click += OnStartStopTimerButtonClick;
            stack.Add(m_StartStopTimerButton);

            AddData();

            return group;
		}
        /// 
        /// 
        /// 
        /// 
        public string GetExampleDescription()
		{
			return @"

This example demonstrates how to create a XYZ scatter point chart rendering millions of data points in real-time using the NFastPointSeries.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Fast Point Series", "https://www.nevron.com/docs/openvision/fast-point-chart-series.html"), ("Fast Series Overview", "https://www.nevron.com/docs/openvision/fast-chart-series-overview.html"), ("3D Charts", "https://www.nevron.com/docs/openvision/3d-charts.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"), ("Chart Data Series", "https://www.nevron.com/docs/openvision/chart-data-series.html"), }; } #endregion #region Implementation /// /// Applies a linear scale and an interlaced stripe at the specified axis /// /// private void ConfigureLinearScale(NCartesianAxis axis) { // add interlaced stripe to the Y axis NLinearScale scale = new NLinearScale(); NScaleStrip stripStyle = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1); stripStyle.SetShowAtWall(ENChartWall.Left, true); stripStyle.SetShowAtWall(ENChartWall.Back, true); stripStyle.SetShowAtWall(ENChartWall.Right, true); stripStyle.SetShowAtWall(ENChartWall.Front, true); stripStyle.SetShowAtWall(ENChartWall.Bottom, true); stripStyle.SetShowAtWall(ENChartWall.Top, true); stripStyle.Interlaced = true; scale.Strips.Add(stripStyle); axis.Scale = scale; axis.Visible = true; } #endregion #region Event Handlers /// /// /// /// private void OnChartViewRegistered(NEventArgs arg) { m_Timer = new NTimer(); m_Timer.Tick += OnTimerTick; m_Timer.Start(); } /// /// /// /// private void OnChartViewUnregistered(NEventArgs arg) { m_Timer.Stop(); m_Timer.Tick -= OnTimerTick; m_Timer = null; } /// /// /// /// void OnStartStopTimerButtonClick(NEventArgs arg) { AddData(); if (m_Timer.IsStarted) { m_Timer.Stop(); m_StartStopTimerButton.Content = new NLabel("Start Timer"); } else { m_Timer.Start(); m_StartStopTimerButton.Content = new NLabel("Stop Timer"); } } /// /// /// private void OnTimerTick() { // spin the points unsafe { fixed (byte* pData = &m_FastPointSeries.Data.Data[0]) { int count = m_FastPointSeries.Data.Count; int dataItemSize = m_FastPointSeries.Data.DataItemSize; float* pXValues = (float*)m_FastPointSeries.Data.GetDataChannelPointer(ENSeriesDataChannelName.XValueF, pData); float* pYValues = (float*)m_FastPointSeries.Data.GetDataChannelPointer(ENSeriesDataChannelName.YValueF, pData); float* pZValues = (float*)m_FastPointSeries.Data.GetDataChannelPointer(ENSeriesDataChannelName.ZValueF, pData); NVector4DF[] spinSpeeds = m_SpinSpeeds; // modify the data for (int i = 0; i < count; i++) { NVector3DF v; v.X = *pXValues; v.Y = *pYValues; v.Z = *pZValues; NVector4DF q = spinSpeeds[i]; float ix = q.W * v.X + q.Y * v.Z - q.Z * v.Y; float iy = q.W * v.Y + q.Z * v.X - q.X * v.Z; float iz = q.W * v.Z + q.X * v.Y - q.Y * v.X; float iw = -q.X * v.X - q.Y * v.Y - q.Z * v.Z; *pXValues = ix * q.W + iw * -q.X + iy * -q.Z - iz * -q.Y; *pYValues = iy * q.W + iw * -q.Y + iz * -q.X - ix * -q.Z; *pZValues = iz * q.W + iw * -q.Z + ix * -q.Y - iy * -q.X; pXValues += dataItemSize; pYValues += dataItemSize; pZValues += dataItemSize; } m_FastPointSeries.Data.OnDataChanged(); } } } /// /// /// /// private void OnPointSizeNumericUpDownValueChanged(NValueChangeEventArgs arg) { m_FastPointSeries.Size = (float)m_PointSizeNumericUpDown.Value; } /// /// /// /// private void OnPointCountComboBoxSelectedIndexChanged(NValueChangeEventArgs arg) { AddData(); } /// /// /// /// private void OnEnableShaderRenderingCheckBoxChanged(NValueChangeEventArgs arg) { m_FastPointSeries.EnableShaderRendering = m_EnableShaderRenderingCheckBox.Checked; } #endregion #region Fields NFastPointSeries m_FastPointSeries; NLabel m_Title; NTimer m_Timer; NComboBox m_PointCountComboBox; NNumericUpDown m_PointSizeNumericUpDown; NCheckBox m_EnableShaderRenderingCheckBox; NButton m_StartStopTimerButton; Random m_Random = new Random(); NVector4DF[] m_SpinSpeeds; uint[] m_RandomColors; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Fast Point 3D Example for WinForms Solution

VB.NET Fast Point 3D Example Code for Nevron Chart for WinForms
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Chart
Imports Nevron.Nov.Chart.Tools
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Forms
Imports System

Public Class Form1

#Region "Constructors"

    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        ' Set form title
        Text = "NOV WinForms - NFastPoint3D"

        ' Create the NOV example and its controls
        Dim exampleContent As NWidget = CreateExampleContent()
        Dim exampleControls As NWidget = CreateExampleControls()
        If Not exampleControls Is Nothing Then
            exampleControls.PreferredWidth = 300
        End If

        ' Place the example and its controls in a pair box
        Dim pairBox As NPairBox = New NPairBox(exampleContent, exampleControls)
        pairBox.FillMode = ENStackFillMode.First
        pairBox.FitMode = ENStackFitMode.First
        pairBox.Margins = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing)

        ' Host the example in the form
        Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
        host.Dock = DockStyle.Fill
        Controls.Add(host)
    End Sub


#End Region

#Region "Example"

        ''' 
        ''' 
        ''' 
        ''' 
        Public Function CreateExampleContent() As NWidget
            Dim chartViewWithCommandBars As NChartViewWithCommandBars = New NChartViewWithCommandBars()
            Dim chartView = chartViewWithCommandBars.View
            chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian)

            chartView.Registered += AddressOf OnChartViewRegistered
            chartView.Unregistered += AddressOf OnChartViewUnregistered

            m_Title = chartView.Surface.Titles(0)
            m_Title.Text = "Fast Point 3D"

            Dim chart = CType(chartView.Surface.Charts(0), NCartesianChart)

            chart.Enable3D = True
            chart.ModelWidth = 50
            chart.ModelHeight = 50
            chart.ModelDepth = 50
            chart.Projection.SetPredefinedProjection(ENPredefinedProjection.Perspective1)
            chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.GlitterLeft)

            Me.ConfigureLinearScale(chart.Axes(ENCartesianAxis.PrimaryX))
            Me.ConfigureLinearScale(chart.Axes(ENCartesianAxis.PrimaryY))
            Me.ConfigureLinearScale(chart.Axes(ENCartesianAxis.Depth))

            ' setup the fast point series
            m_FastPointSeries = New NFastPointSeries()
            chart.Series.Add(m_FastPointSeries)
            m_FastPointSeries.Name = "FastPoint Series"
            m_FastPointSeries.FillColorMode = ENColorMode.Custom

            chart.Interactor = New NInteractor(New NTrackballTool())

            ' init the random colors array
            m_RandomColors = New UInteger(9999) {}
            Dim random As Random = New Random()
            For i = 0 To m_RandomColors.Length - 1
                Dim red As UInteger = CUInt((255 * random.NextDouble()))
                Dim green As UInteger = CUInt((255 * random.NextDouble()))
                Dim blue As UInteger = CUInt((255 * random.NextDouble()))

                m_RandomColors(i) = &HFF000000UI Or red << 16 Or green << 8 Or blue
            Next

            Return chartViewWithCommandBars
        End Function
        ''' 
        ''' 
        ''' 
        ''' 
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()
            Dim group As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)

            m_PointCountComboBox = New NComboBox()
            m_PointCountComboBox.Items.Fill(New String() {"100K", "500K", "1M", "2M", "10M"})
            Me.m_PointCountComboBox.SelectedIndexChanged += AddressOf OnPointCountComboBoxSelectedIndexChanged
            m_PointCountComboBox.SelectedIndex = 2

            stack.Add(NPairBox.Create("Point Count:", m_PointCountComboBox))

            m_PointSizeNumericUpDown = New NNumericUpDown()
            m_PointSizeNumericUpDown.Value = 2
            m_PointSizeNumericUpDown.Minimum = 1
            m_PointSizeNumericUpDown.Maximum = 20
            Me.m_PointSizeNumericUpDown.ValueChanged += AddressOf OnPointSizeNumericUpDownValueChanged
            stack.Add(NPairBox.Create("Point Size:", m_PointSizeNumericUpDown))

            m_EnableShaderRenderingCheckBox = New NCheckBox()
            Me.m_EnableShaderRenderingCheckBox.CheckedChanged += AddressOf OnEnableShaderRenderingCheckBoxChanged
            m_EnableShaderRenderingCheckBox.Checked = m_FastPointSeries.EnableShaderRendering
            stack.Add(NPairBox.Create("Enable Shader Rendering:", m_EnableShaderRenderingCheckBox))

            m_StartStopTimerButton = New NButton("Stop Timer")
            Me.m_StartStopTimerButton.Click += AddressOf OnStartStopTimerButtonClick
            stack.Add(m_StartStopTimerButton)

            AddData()

            Return group
        End Function
        ''' 
        ''' 
        ''' 
        ''' 
        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to create a XYZ scatter point chart rendering millions of data points in real-time using the NFastPointSeries.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Fast Point Series", "https://www.nevron.com/docs/openvision/fast-point-chart-series.html"), ("Fast Series Overview", "https://www.nevron.com/docs/openvision/fast-chart-series-overview.html"), ("3D Charts", "https://www.nevron.com/docs/openvision/3d-charts.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"), ("Chart Data Series", "https://www.nevron.com/docs/openvision/chart-data-series.html")} End Function #End Region #Region "Implementation" ''' ''' Applies a linear scale and an interlaced stripe at the specified axis ''' ''' Private Sub ConfigureLinearScale(axis As NCartesianAxis) ' add interlaced stripe to the Y axis Dim scale As NLinearScale = New NLinearScale() Dim stripStyle As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1) stripStyle.SetShowAtWall(ENChartWall.Left, True) stripStyle.SetShowAtWall(ENChartWall.Back, True) stripStyle.SetShowAtWall(ENChartWall.Right, True) stripStyle.SetShowAtWall(ENChartWall.Front, True) stripStyle.SetShowAtWall(ENChartWall.Bottom, True) stripStyle.SetShowAtWall(ENChartWall.Top, True) stripStyle.Interlaced = True scale.Strips.Add(stripStyle) axis.Scale = scale axis.Visible = True End Sub #End Region #Region "Event Handlers" ''' ''' ''' ''' Private Sub OnChartViewRegistered(arg As NEventArgs) m_Timer = New NTimer() Me.m_Timer.Tick += AddressOf OnTimerTick m_Timer.Start() End Sub ''' ''' ''' ''' Private Sub OnChartViewUnregistered(arg As NEventArgs) m_Timer.Stop() Me.m_Timer.Tick -= AddressOf OnTimerTick m_Timer = Nothing End Sub ''' ''' ''' ''' Private Sub OnStartStopTimerButtonClick(arg As NEventArgs) AddData() If m_Timer.IsStarted Then m_Timer.Stop() m_StartStopTimerButton.Content = New NLabel("Start Timer") Else m_Timer.Start() m_StartStopTimerButton.Content = New NLabel("Stop Timer") End If End Sub ''' ''' ''' ' spin the points ' modify the data Private Sub OnTimerTick() ''' Cannot convert UnsafeStatementSyntax, CONVERSION ERROR: Conversion for UnsafeStatement not implemented, please report this issue in 'unsafe\r\n {\r\n fixed...' at character 9093 ''' ''' ''' Input: ''' // spin the points ''' unsafe ''' { ''' fixed (byte* pData = &this.m_FastPointSeries.Data.Data[0]) ''' { ''' int count = this.m_FastPointSeries.Data.Count; ''' int dataItemSize = this.m_FastPointSeries.Data.DataItemSize; ''' ''' float* pXValues = (float*)this.m_FastPointSeries.Data.GetDataChannelPointer(Nevron.Nov.Chart.ENSeriesDataChannelName.XValueF, pData); ''' float* pYValues = (float*)this.m_FastPointSeries.Data.GetDataChannelPointer(Nevron.Nov.Chart.ENSeriesDataChannelName.YValueF, pData); ''' float* pZValues = (float*)this.m_FastPointSeries.Data.GetDataChannelPointer(Nevron.Nov.Chart.ENSeriesDataChannelName.ZValueF, pData); ''' Nevron.Nov.Graphics.NVector4DF[] spinSpeeds = this.m_SpinSpeeds; ''' ''' // modify the data ''' for (int i = 0; i < count; i++) ''' { ''' Nevron.Nov.Graphics.NVector3DF v; ''' ''' v.X = *pXValues; ''' v.Y = *pYValues; ''' v.Z = *pZValues; ''' ''' Nevron.Nov.Graphics.NVector4DF q = spinSpeeds[i]; ''' ''' float ix = q.W * v.X + q.Y * v.Z - q.Z * v.Y; ''' float iy = q.W * v.Y + q.Z * v.X - q.X * v.Z; ''' float iz = q.W * v.Z + q.X * v.Y - q.Y * v.X; ''' float iw = -q.X * v.X - q.Y * v.Y - q.Z * v.Z; ''' ''' *pXValues = ix * q.W + iw * -q.X + iy * -q.Z - iz * -q.Y; ''' *pYValues = iy * q.W + iw * -q.Y + iz * -q.X - ix * -q.Z; ''' *pZValues = iz * q.W + iw * -q.Z + ix * -q.Y - iy * -q.X; ''' ''' pXValues += dataItemSize; ''' pYValues += dataItemSize; ''' pZValues += dataItemSize; ''' } ''' ''' this.m_FastPointSeries.Data.OnDataChanged(); ''' } ''' } ''' ''' End Sub ''' ''' ''' ''' Private Sub OnPointSizeNumericUpDownValueChanged(arg As NValueChangeEventArgs) m_FastPointSeries.Size = CSng(m_PointSizeNumericUpDown.Value) End Sub ''' ''' ''' ''' Private Sub OnPointCountComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs) AddData() End Sub ''' ''' ''' ''' Private Sub OnEnableShaderRenderingCheckBoxChanged(arg As NValueChangeEventArgs) m_FastPointSeries.EnableShaderRendering = m_EnableShaderRenderingCheckBox.Checked End Sub #End Region #Region "Fields" Private m_FastPointSeries As NFastPointSeries Private m_Title As NLabel Private m_Timer As NTimer Private m_PointCountComboBox As NComboBox Private m_PointSizeNumericUpDown As NNumericUpDown Private m_EnableShaderRenderingCheckBox As NCheckBox Private m_StartStopTimerButton As NButton Private m_Random As Random = New Random() Private m_SpinSpeeds As NVector4DF() Private m_RandomColors As UInteger() #End Region #Region "Static Methods" #End Region #Region "Constants" #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Fast Point 3D Example for WinForms Solution