This example demonstrates the capabilities of the Vertex Surface Series, which allows you to plot arbitrary OpenGL primitives such as lines, quads, triangles, and more.

| 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 - NVertexSurfaceExample";
// 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);
// configure title
m_Label = chartView.Surface.Titles[0];
chartView.Surface.Titles[0].Text = "Vertex Surface Series";
// setup chart
NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0];
chart.Enable3D = true;
chart.ModelWidth = 60.0f;
chart.ModelDepth = 60.0f;
chart.ModelHeight = 25.0f;
chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted);
chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.ShinyTopLeft);
chart.Interactor = new NInteractor(new NTrackballTool());
NLinearScale scaleY = (NLinearScale)chart.Axes[ENCartesianAxis.PrimaryY].Scale;
scaleY.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None;
// add interlace stripe to the Y axis
NScaleStrip stripStyleY = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
stripStyleY.Interlaced = true;
stripStyleY.SetShowAtWall(ENChartWall.Back, true);
stripStyleY.SetShowAtWall(ENChartWall.Left, true);
scaleY.Strips.Add(stripStyleY);
// setup axes
NOrdinalScale scaleX = (NOrdinalScale)chart.Axes[ENCartesianAxis.PrimaryX].Scale;
scaleX.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, true);
scaleX.MajorGridLines.SetShowAtWall(ENChartWall.Back, true);
scaleX.DisplayDataPointsBetweenTicks = false;
NOrdinalScale scaleZ = (NOrdinalScale)chart.Axes[ENCartesianAxis.Depth].Scale;
scaleZ.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, true);
scaleZ.MajorGridLines.SetShowAtWall(ENChartWall.Left, true);
scaleZ.DisplayDataPointsBetweenTicks = false;
// add the surface series
m_Surface = new NVertexSurfaceSeries();
chart.Series.Add(m_Surface);
m_Surface.Name = "Surface";
m_Surface.LegendView.Mode = ENSeriesLegendMode.SeriesLogic;
m_Surface.FlatPositionValue = 10.0;
m_Surface.Palette.InterpolateColors = false;
m_Surface.ValueFormatter = new NNumericValueFormatter("0.00");
m_Surface.Fill = new NColorFill(NColor.YellowGreen);
m_Surface.FillColorMode = ENColorMode.Zone;
m_Surface.ShowFrame = true;
m_Surface.FrameMode = ENSurfaceFrameMode.Contour;
m_Surface.FrameColorMode = ENColorMode.Uniform;
m_Surface.ShadingMode = ENShadingMode.Smooth;
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup group = new NUniSizeBoxGroup(stack);
NComboBox vertexPrimitiveCombo = new NComboBox();
vertexPrimitiveCombo.Items.FillFromEnum();
vertexPrimitiveCombo.SelectedIndexChanged += OnVertexPrimitiveComboSelectedIndexChanged;
vertexPrimitiveCombo.SelectedIndex = (int)m_Surface.VertexPrimitive;
stack.Add(NPairBox.Create("Vertex Primitive:", vertexPrimitiveCombo));
NCheckBox smoothShadingCheckBox = new NCheckBox();
smoothShadingCheckBox.CheckedChanged += OnSmoothShadingCheckBoxCheckedChanged;
stack.Add(NPairBox.Create("Smooth Shading:", smoothShadingCheckBox));
return group;
}
private void OnSmoothShadingCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
m_Surface.ShadingMode = (bool)arg.NewValue ? ENShadingMode.Smooth : ENShadingMode.Flat;
}
private void OnVertexPrimitiveComboSelectedIndexChanged(NValueChangeEventArgs arg)
{
m_Surface.VertexPrimitive = (ENVertexPrimitive)arg.NewValue;
m_Surface.UseIndices = false;
Random rand = new Random();
string descriptionText = string.Empty;
m_Surface.Data.Clear();
switch (m_Surface.VertexPrimitive)
{
case ENVertexPrimitive.Points:
{
descriptionText = "Each vertex represents a 3d point";
m_Surface.FrameMode = ENSurfaceFrameMode.Dots;
for (int i = 0; i < 10000; i++)
{
m_Surface.Data.AddValue(rand.Next(100),
rand.Next(100),
rand.Next(100));
}
}
break;
case ENVertexPrimitive.Lines:
{
descriptionText = "Each consecutive pair of vertices represents a line segment";
m_Surface.FrameMode = ENSurfaceFrameMode.Dots;
for (int i = 0; i < 200; i++)
{
m_Surface.Data.AddValue(rand.Next(100),
rand.Next(100),
rand.Next(100));
m_Surface.Data.AddValue(rand.Next(100),
rand.Next(100),
rand.Next(100));
}
}
break;
case ENVertexPrimitive.LineLoop:
case ENVertexPrimitive.LineStrip:
{
descriptionText = "Adjacent vertices are connected with a line segment";
for (int i = 0; i < 5; i++)
{
m_Surface.Data.AddValue(rand.Next(100),
rand.Next(100),
rand.Next(100));
}
}
break;
case ENVertexPrimitive.Triangles:
{
descriptionText = "Each three consequtive vertices are considered a triangle";
m_Surface.FrameMode = ENSurfaceFrameMode.Mesh;
NVector3DD top = new NVector3DD(0.5, 1, 0.5);
NVector3DD baseA = new NVector3DD(0, 0, 0);
NVector3DD baseB = new NVector3DD(1, 0, 0);
NVector3DD baseC = new NVector3DD(1, 0, 1);
NVector3DD baseD = new NVector3DD(0, 0, 1);
m_Surface.Data.AddValue(top);
m_Surface.Data.AddValue(baseA);
m_Surface.Data.AddValue(baseB);
m_Surface.Data.AddValue(top);
m_Surface.Data.AddValue(baseB);
m_Surface.Data.AddValue(baseC);
m_Surface.Data.AddValue(top);
m_Surface.Data.AddValue(baseC);
m_Surface.Data.AddValue(baseD);
m_Surface.Data.AddValue(top);
m_Surface.Data.AddValue(baseD);
m_Surface.Data.AddValue(baseA);
}
break;
case ENVertexPrimitive.TriangleStrip:
{
descriptionText = "A series of connected triangles that share common vertices";
m_Surface.FrameMode = ENSurfaceFrameMode.Mesh;
NVector3DD A = new NVector3DD(0, 0, 0);
NVector3DD B = new NVector3DD(1, 0, 0);
NVector3DD C = new NVector3DD(0, 1, 1);
NVector3DD D = new NVector3DD(1, 1, 1);
m_Surface.Data.AddValue(A);
m_Surface.Data.AddValue(B);
m_Surface.Data.AddValue(C);
m_Surface.Data.AddValue(D);
}
break;
case ENVertexPrimitive.TriangleFan:
{
descriptionText = "A series of connected triangles that share a common vertex";
m_Surface.FrameMode = ENSurfaceFrameMode.Mesh;
m_Surface.Data.AddValue(0, 100, 0);
int steps = 10;
for (int i = 0; i < 3000; i++)
{
double angle = i * 2 * Math.PI / steps;
m_Surface.Data.AddValue(Math.Cos(angle) * 100,
0,
Math.Sin(angle) * 100);
}
}
break;
case ENVertexPrimitive.Quads:
{
descriptionText = "Each for consecutive vertices form a quad";
m_Surface.FrameMode = ENSurfaceFrameMode.Mesh;
m_Surface.FillColorMode = ENColorMode.Zone;
NVector3DD A = new NVector3DD(0, 0, 0);
NVector3DD B = new NVector3DD(1, 0, 0);
NVector3DD C = new NVector3DD(0, 1, 1);
NVector3DD D = new NVector3DD(1, 1, 1);
m_Surface.Data.AddValue(A);
m_Surface.Data.AddValue(B);
m_Surface.Data.AddValue(D);
m_Surface.Data.AddValue(C);
}
break;
case ENVertexPrimitive.QuadStrip:
{
descriptionText = "A series of connected quads that share common vertices";
m_Surface.FrameMode = ENSurfaceFrameMode.Mesh;
m_Surface.FillColorMode = ENColorMode.Zone;
NVector3DD A = new NVector3DD(0, 0, 0);
NVector3DD B = new NVector3DD(1, 0, 0);
NVector3DD C = new NVector3DD(0, 1, 1);
NVector3DD D = new NVector3DD(1, 1, 1);
NVector3DD E = new NVector3DD(0, 2, 2);
NVector3DD F = new NVector3DD(1, 2, 2);
m_Surface.Data.AddValue(A);
m_Surface.Data.AddValue(B);
m_Surface.Data.AddValue(C);
m_Surface.Data.AddValue(D);
m_Surface.Data.AddValue(E);
m_Surface.Data.AddValue(F);
}
break;
}
m_Label.Text = "Vertex Surface " + descriptionText;
}
///
///
///
///
public string GetExampleDescription()
{
return @"This example demonstrates the capabilities of the Vertex Surface Series, which allows you to plot arbitrary OpenGL primitives such as lines, quads, triangles, and more.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Vertex Surface Series", "https://www.nevron.com/docs/openvision/vertex-surface-chart-series.html"),
("Surface Series Overview", "https://www.nevron.com/docs/openvision/surface-chart-series-overview.html"),
("3D Charts", "https://www.nevron.com/docs/openvision/3d-charts.html"),
("chart-palettes", "https://www.nevron.com/docs/openvision/chart-palettes.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
#endregion
#region Fields
NLabel m_Label;
NVertexSurfaceSeries m_Surface;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
} | 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.Wpf
Imports System
Class MainWindow
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Title = "NOV WPF - NVertexSurfaceExample"
' 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)
Content = 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)
' configure title
m_Label = chartView.Surface.Titles(0)
chartView.Surface.Titles(0).Text = "Vertex Surface Series"
' setup chart
Dim chart = CType(chartView.Surface.Charts(0), NCartesianChart)
chart.Enable3D = True
chart.ModelWidth = 60.0F
chart.ModelDepth = 60.0F
chart.ModelHeight = 25.0F
chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted)
chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.ShinyTopLeft)
chart.Interactor = New NInteractor(New NTrackballTool())
Dim scaleY As NLinearScale = chart.Axes(ENCartesianAxis.PrimaryY).Scale
scaleY.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None
' add interlace stripe to the Y axis
Dim stripStyleY As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
stripStyleY.Interlaced = True
stripStyleY.SetShowAtWall(ENChartWall.Back, True)
stripStyleY.SetShowAtWall(ENChartWall.Left, True)
scaleY.Strips.Add(stripStyleY)
' setup axes
Dim scaleX As NOrdinalScale = chart.Axes(ENCartesianAxis.PrimaryX).Scale
scaleX.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, True)
scaleX.MajorGridLines.SetShowAtWall(ENChartWall.Back, True)
scaleX.DisplayDataPointsBetweenTicks = False
Dim scaleZ As NOrdinalScale = chart.Axes(ENCartesianAxis.Depth).Scale
scaleZ.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, True)
scaleZ.MajorGridLines.SetShowAtWall(ENChartWall.Left, True)
scaleZ.DisplayDataPointsBetweenTicks = False
' add the surface series
m_Surface = New NVertexSurfaceSeries()
chart.Series.Add(m_Surface)
m_Surface.Name = "Surface"
m_Surface.LegendView.Mode = ENSeriesLegendMode.SeriesLogic
m_Surface.FlatPositionValue = 10.0
m_Surface.Palette.InterpolateColors = False
m_Surface.ValueFormatter = New NNumericValueFormatter("0.00")
m_Surface.Fill = New NColorFill(NColor.YellowGreen)
m_Surface.FillColorMode = ENColorMode.Zone
m_Surface.ShowFrame = True
m_Surface.FrameMode = ENSurfaceFrameMode.Contour
m_Surface.FrameColorMode = ENColorMode.Uniform
m_Surface.ShadingMode = ENShadingMode.Smooth
Return chartViewWithCommandBars
End Function
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
Dim group As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)
Dim vertexPrimitiveCombo As NComboBox = New NComboBox()
vertexPrimitiveCombo.Items.FillFromEnum(Of ENVertexPrimitive)()
vertexPrimitiveCombo.SelectedIndexChanged += AddressOf OnVertexPrimitiveComboSelectedIndexChanged
vertexPrimitiveCombo.SelectedIndex = m_Surface.VertexPrimitive
stack.Add(NPairBox.Create("Vertex Primitive:", vertexPrimitiveCombo))
Dim smoothShadingCheckBox As NCheckBox = New NCheckBox()
smoothShadingCheckBox.CheckedChanged += AddressOf OnSmoothShadingCheckBoxCheckedChanged
stack.Add(NPairBox.Create("Smooth Shading:", smoothShadingCheckBox))
Return group
End Function
Private Sub OnSmoothShadingCheckBoxCheckedChanged(arg As NValueChangeEventArgs)
m_Surface.ShadingMode = If(arg.NewValue, ENShadingMode.Smooth, ENShadingMode.Flat)
End Sub
Private Sub OnVertexPrimitiveComboSelectedIndexChanged(arg As NValueChangeEventArgs)
m_Surface.VertexPrimitive = CType(arg.NewValue, ENVertexPrimitive)
m_Surface.UseIndices = False
Dim rand As Random = New Random()
Dim descriptionText = String.Empty
m_Surface.Data.Clear()
Select Case m_Surface.VertexPrimitive
Case ENVertexPrimitive.Points
descriptionText = "Each vertex represents a 3d point"
m_Surface.FrameMode = ENSurfaceFrameMode.Dots
For i = 0 To 9999
m_Surface.Data.AddValue(rand.Next(100), rand.Next(100), rand.Next(100))
Next
Case ENVertexPrimitive.Lines
descriptionText = "Each consecutive pair of vertices represents a line segment"
m_Surface.FrameMode = ENSurfaceFrameMode.Dots
For i = 0 To 199
m_Surface.Data.AddValue(rand.Next(100), rand.Next(100), rand.Next(100))
m_Surface.Data.AddValue(rand.Next(100), rand.Next(100), rand.Next(100))
Next
Case ENVertexPrimitive.LineLoop, ENVertexPrimitive.LineStrip
descriptionText = "Adjacent vertices are connected with a line segment"
For i = 0 To 4
m_Surface.Data.AddValue(rand.Next(100), rand.Next(100), rand.Next(100))
Next
Case ENVertexPrimitive.Triangles
descriptionText = "Each three consequtive vertices are considered a triangle"
m_Surface.FrameMode = ENSurfaceFrameMode.Mesh
Dim top As NVector3DD = New NVector3DD(0.5, 1, 0.5)
Dim baseA As NVector3DD = New NVector3DD(0, 0, 0)
Dim baseB As NVector3DD = New NVector3DD(1, 0, 0)
Dim baseC As NVector3DD = New NVector3DD(1, 0, 1)
Dim baseD As NVector3DD = New NVector3DD(0, 0, 1)
m_Surface.Data.AddValue(top)
m_Surface.Data.AddValue(baseA)
m_Surface.Data.AddValue(baseB)
m_Surface.Data.AddValue(top)
m_Surface.Data.AddValue(baseB)
m_Surface.Data.AddValue(baseC)
m_Surface.Data.AddValue(top)
m_Surface.Data.AddValue(baseC)
m_Surface.Data.AddValue(baseD)
m_Surface.Data.AddValue(top)
m_Surface.Data.AddValue(baseD)
m_Surface.Data.AddValue(baseA)
Case ENVertexPrimitive.TriangleStrip
descriptionText = "A series of connected triangles that share common vertices"
m_Surface.FrameMode = ENSurfaceFrameMode.Mesh
Dim A As NVector3DD = New NVector3DD(0, 0, 0)
Dim B As NVector3DD = New NVector3DD(1, 0, 0)
Dim C As NVector3DD = New NVector3DD(0, 1, 1)
Dim D As NVector3DD = New NVector3DD(1, 1, 1)
m_Surface.Data.AddValue(A)
m_Surface.Data.AddValue(B)
m_Surface.Data.AddValue(C)
m_Surface.Data.AddValue(D)
Case ENVertexPrimitive.TriangleFan
descriptionText = "A series of connected triangles that share a common vertex"
m_Surface.FrameMode = ENSurfaceFrameMode.Mesh
m_Surface.Data.AddValue(0, 100, 0)
Dim steps = 10
For i = 0 To 2999
Dim angle = i * 2 * Math.PI / steps
m_Surface.Data.AddValue(Math.Cos(angle) * 100, 0, Math.Sin(angle) * 100)
Next
Case ENVertexPrimitive.Quads
descriptionText = "Each for consecutive vertices form a quad"
m_Surface.FrameMode = ENSurfaceFrameMode.Mesh
m_Surface.FillColorMode = ENColorMode.Zone
Dim A As NVector3DD = New NVector3DD(0, 0, 0)
Dim B As NVector3DD = New NVector3DD(1, 0, 0)
Dim C As NVector3DD = New NVector3DD(0, 1, 1)
Dim D As NVector3DD = New NVector3DD(1, 1, 1)
m_Surface.Data.AddValue(A)
m_Surface.Data.AddValue(B)
m_Surface.Data.AddValue(D)
m_Surface.Data.AddValue(C)
Case ENVertexPrimitive.QuadStrip
descriptionText = "A series of connected quads that share common vertices"
m_Surface.FrameMode = ENSurfaceFrameMode.Mesh
m_Surface.FillColorMode = ENColorMode.Zone
Dim A As NVector3DD = New NVector3DD(0, 0, 0)
Dim B As NVector3DD = New NVector3DD(1, 0, 0)
Dim C As NVector3DD = New NVector3DD(0, 1, 1)
Dim D As NVector3DD = New NVector3DD(1, 1, 1)
Dim E As NVector3DD = New NVector3DD(0, 2, 2)
Dim F As NVector3DD = New NVector3DD(1, 2, 2)
m_Surface.Data.AddValue(A)
m_Surface.Data.AddValue(B)
m_Surface.Data.AddValue(C)
m_Surface.Data.AddValue(D)
m_Surface.Data.AddValue(E)
m_Surface.Data.AddValue(F)
End Select
m_Label.Text = "Vertex Surface " & descriptionText
End Sub
'''
'''
'''
'''
Public Function GetExampleDescription() As String
Return "This example demonstrates the capabilities of the Vertex Surface Series, which allows you to plot arbitrary OpenGL primitives such as lines, quads, triangles, and more.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Vertex Surface Series", "https://www.nevron.com/docs/openvision/vertex-surface-chart-series.html"), ("Surface Series Overview", "https://www.nevron.com/docs/openvision/surface-chart-series-overview.html"), ("3D Charts", "https://www.nevron.com/docs/openvision/3d-charts.html"), ("chart-palettes", "https://www.nevron.com/docs/openvision/chart-palettes.html")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
#End Region
#Region "Fields"
Private m_Label As NLabel
Private m_Surface As NVertexSurfaceSeries
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class