The example demonstrates how to create contour lines (isolines) on a mesh surface chart.

| 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 - NMeshSurfaceContourLinesExample";
// 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
chartView.Surface.Titles[0].Text = "Mesh Surface Contour Lines";
// 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.SoftTopLeft);
chart.Interactor = new NInteractor(new NTrackballTool());
NLinearScale scale = (NLinearScale)chart.Axes[ENCartesianAxis.PrimaryY].Scale;
scale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None;
// setup axes
NLinearScale scaleX = new NLinearScale();
chart.Axes[ENCartesianAxis.PrimaryX].Scale = scaleX;
scaleX.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, true);
scaleX.MajorGridLines.SetShowAtWall(ENChartWall.Back, true);
NLinearScale scaleZ = new NLinearScale();
chart.Axes[ENCartesianAxis.Depth].Scale = scaleZ;
scaleZ.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, true);
scaleZ.MajorGridLines.SetShowAtWall(ENChartWall.Left, true);
// add interlace stripe to the Y axis
NLinearScale linearScale = chart.Axes[ENCartesianAxis.PrimaryY].Scale as NLinearScale;
NScaleStrip stripStyle = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
stripStyle.Interlaced = true;
stripStyle.SetShowAtWall(ENChartWall.Back, true);
stripStyle.SetShowAtWall(ENChartWall.Left, true);
linearScale.Strips.Add(stripStyle);
// add the surface series
m_Surface = new NMeshSurfaceSeries();
chart.Series.Add(m_Surface);
m_Surface.Name = "Surface";
m_Surface.LegendView.Mode = ENSeriesLegendMode.SeriesLogic;
m_Surface.FillColorMode = ENColorMode.Zone;
m_Surface.FlatPositionValue = 0.5;
m_Surface.Data.SetGridSize(20, 20);
m_Surface.Fill = new NColorFill(NColor.YellowGreen);
m_RedIsoline = new NContourLine();
m_RedIsoline.Value = 100;
m_RedIsoline.Stroke = new NStroke(2.0f, NColor.Red);
m_Surface.ContourLines.Add(m_RedIsoline);
m_BlueIsoline = new NContourLine();
m_BlueIsoline.Value = 50;
m_BlueIsoline.Stroke = new NStroke(2.0f, NColor.Blue);
m_Surface.ContourLines.Add(m_BlueIsoline);
FillData(m_Surface);
return chartViewWithCommandBars;
}
private void FillData(NMeshSurfaceSeries surface)
{
int nCountX = surface.Data.GridSizeX;
int nCountZ = surface.Data.GridSizeZ;
const double dIntervalX = 20.0;
const double dIntervalZ = 20.0;
double dIncrementX = (dIntervalX / nCountX);
double dIncrementZ = (dIntervalZ / nCountZ);
double pz = -(dIntervalZ / 2);
for (int j = 0; j < nCountZ; j++, pz += dIncrementZ)
{
double px = -(dIntervalX / 2);
for (int i = 0; i < nCountX; i++, px += dIncrementX)
{
double x = px + Math.Sin(pz) * 0.4;
double z = pz + Math.Cos(px) * 0.4;
double y = Math.Sin(px * 0.33) * Math.Sin(pz * 0.33) * 200;
if (y < 0)
{
y = -y * 0.7;
}
double tmp = (1 - x * x - z * z);
y -= tmp * tmp * 0.000001;
surface.Data.SetValue(i, j, y, x, z);
}
}
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup group = new NUniSizeBoxGroup(stack);
NNumericUpDown redIsolineValueUpDown = new NNumericUpDown();
redIsolineValueUpDown.Value = m_RedIsoline.Value;
redIsolineValueUpDown.ValueChanged += OnRedIsolineValueUpDownValueChanged;
redIsolineValueUpDown.HorizontalPlacement = Layout.ENHorizontalPlacement.Left;
stack.Add(NPairBox.Create("Red Isoline Value:", redIsolineValueUpDown));
NNumericUpDown blueIsolineValueUpDown = new NNumericUpDown();
blueIsolineValueUpDown.Value = m_BlueIsoline.Value;
blueIsolineValueUpDown.ValueChanged += OnBlueIsolineValueUpDownValueChanged;
blueIsolineValueUpDown.HorizontalPlacement = Layout.ENHorizontalPlacement.Left;
stack.Add(NPairBox.Create("Blue Isoline Value:", blueIsolineValueUpDown));
return group;
}
private void OnRedIsolineValueUpDownValueChanged(NValueChangeEventArgs arg)
{
m_RedIsoline.Value = (double)arg.NewValue;
}
private void OnBlueIsolineValueUpDownValueChanged(NValueChangeEventArgs arg)
{
m_BlueIsoline.Value = (double)arg.NewValue;
}
public string GetExampleDescription()
{
return @"The example demonstrates how to create contour lines (isolines) on a mesh surface chart.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Mesh Surface Series", "https://www.nevron.com/docs/openvision/mesh-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"),
("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
#endregion
#region Fields
NMeshSurfaceSeries m_Surface;
NContourLine m_RedIsoline;
NContourLine m_BlueIsoline;
#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.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 - NMeshSurfaceContourLinesExample"
' 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)
' configure title
chartView.Surface.Titles(0).Text = "Mesh Surface Contour Lines"
' 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.SoftTopLeft)
chart.Interactor = New NInteractor(New NTrackballTool())
Dim scale As NLinearScale = chart.Axes(ENCartesianAxis.PrimaryY).Scale
scale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None
' setup axes
Dim scaleX As NLinearScale = New NLinearScale()
chart.Axes(ENCartesianAxis.PrimaryX).Scale = scaleX
scaleX.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, True)
scaleX.MajorGridLines.SetShowAtWall(ENChartWall.Back, True)
Dim scaleZ As NLinearScale = New NLinearScale()
chart.Axes(ENCartesianAxis.Depth).Scale = scaleZ
scaleZ.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, True)
scaleZ.MajorGridLines.SetShowAtWall(ENChartWall.Left, True)
' add interlace stripe to the Y axis
Dim linearScale As NLinearScale = TryCast(chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLinearScale)
Dim stripStyle As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
stripStyle.Interlaced = True
stripStyle.SetShowAtWall(ENChartWall.Back, True)
stripStyle.SetShowAtWall(ENChartWall.Left, True)
linearScale.Strips.Add(stripStyle)
' add the surface series
m_Surface = New NMeshSurfaceSeries()
chart.Series.Add(m_Surface)
m_Surface.Name = "Surface"
m_Surface.LegendView.Mode = ENSeriesLegendMode.SeriesLogic
m_Surface.FillColorMode = ENColorMode.Zone
m_Surface.FlatPositionValue = 0.5
m_Surface.Data.SetGridSize(20, 20)
m_Surface.Fill = New NColorFill(NColor.YellowGreen)
m_RedIsoline = New NContourLine()
m_RedIsoline.Value = 100
m_RedIsoline.Stroke = New NStroke(2.0F, NColor.Red)
m_Surface.ContourLines.Add(m_RedIsoline)
m_BlueIsoline = New NContourLine()
m_BlueIsoline.Value = 50
m_BlueIsoline.Stroke = New NStroke(2.0F, NColor.Blue)
m_Surface.ContourLines.Add(m_BlueIsoline)
FillData(m_Surface)
Return chartViewWithCommandBars
End Function
Private Sub FillData(surface As NMeshSurfaceSeries)
Dim nCountX = surface.Data.GridSizeX
Dim nCountZ = surface.Data.GridSizeZ
Const dIntervalX = 20.0
Const dIntervalZ = 20.0
Dim dIncrementX = dIntervalX / nCountX
Dim dIncrementZ = dIntervalZ / nCountZ
Dim pz = -(dIntervalZ / 2)
Dim j = 0
While j < nCountZ
Dim px = -(dIntervalX / 2)
Dim i = 0
While i < nCountX
Dim x = px + Math.Sin(pz) * 0.4
Dim z = pz + Math.Cos(px) * 0.4
Dim y = Math.Sin(px * 0.33) * Math.Sin(pz * 0.33) * 200
If y < 0 Then
y = -y * 0.7
End If
Dim tmp = 1 - x * x - z * z
y -= tmp * tmp * 0.000001
surface.Data.SetValue(i, j, y, x, z)
i += 1
px += dIncrementX
End While
j += 1
pz += dIncrementZ
End While
End Sub
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
Dim group As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)
Dim redIsolineValueUpDown As NNumericUpDown = New NNumericUpDown()
redIsolineValueUpDown.Value = m_RedIsoline.Value
redIsolineValueUpDown.ValueChanged += AddressOf OnRedIsolineValueUpDownValueChanged
redIsolineValueUpDown.HorizontalPlacement = Layout.ENHorizontalPlacement.Left
stack.Add(NPairBox.Create("Red Isoline Value:", redIsolineValueUpDown))
Dim blueIsolineValueUpDown As NNumericUpDown = New NNumericUpDown()
blueIsolineValueUpDown.Value = m_BlueIsoline.Value
blueIsolineValueUpDown.ValueChanged += AddressOf OnBlueIsolineValueUpDownValueChanged
blueIsolineValueUpDown.HorizontalPlacement = Layout.ENHorizontalPlacement.Left
stack.Add(NPairBox.Create("Blue Isoline Value:", blueIsolineValueUpDown))
Return group
End Function
Private Sub OnRedIsolineValueUpDownValueChanged(arg As NValueChangeEventArgs)
m_RedIsoline.Value = CDbl(arg.NewValue)
End Sub
Private Sub OnBlueIsolineValueUpDownValueChanged(arg As NValueChangeEventArgs)
m_BlueIsoline.Value = CDbl(arg.NewValue)
End Sub
Public Function GetExampleDescription() As String
Return "The example demonstrates how to create contour lines (isolines) on a mesh surface chart.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Mesh Surface Series", "https://www.nevron.com/docs/openvision/mesh-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"), ("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
#End Region
#Region "Fields"
Private m_Surface As NMeshSurfaceSeries
Private m_RedIsoline As NContourLine
Private m_BlueIsoline As NContourLine
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class