Profile Picture

AntiAlias causes lines to appear speckled

Posted By Lance Levendowski 8 Years Ago
Author
Message
Lance Levendowski
Posted 8 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 6 Months Ago
Posts: 60, Visits: 157
Setting NChartControl.Settings.ShapeRenderingMode to AntiAlias or HighQuality causes NLineSeries to have a speckled appearance when NCartesianChart.Enable3D = True.

Can this be prevented without the use of jittering?

Run the following example and toggle the CheckBoxes to observe the issue.  Also notice that the chart changes size when NCartesianChart.Enable3D is toggled which is undesirable.
Public Class AntiAliasForm
  Inherits Windows.Forms.Form

  Private _ChartControl1 As Nevron.Chart.WinForm.NChartControl
  Private WithEvents _CheckBox1 As Windows.Forms.CheckBox
  Private WithEvents _CheckBox2 As Windows.Forms.CheckBox

  Public Sub New()
    Me.Size = New Drawing.Size(800, 624)
    Me.StartPosition = FormStartPosition.CenterScreen

    Dim chart As New Nevron.Chart.NCartesianChart
    chart.Enable3D = True
    chart.Projection.SetPredefinedProjection(Nevron.GraphicsCore.PredefinedProjection.Orthogonal)
    Call AddLineSeries(250, 0.5#, Drawing.Color.Black, chart)

    Dim chartBounds As New Drawing.Rectangle(0, 0, Me.ClientSize.Width, Me.ClientSize.Height - 24)
    Me._ChartControl1 = New Nevron.Chart.WinForm.NChartControl
    Me._ChartControl1.Charts.Clear()
    Me._ChartControl1.Charts.Add(chart)
    Me._ChartControl1.Anchor = AnchorStyles.Left Or AnchorStyles.Top Or AnchorStyles.Right Or AnchorStyles.Bottom
    Me._ChartControl1.Bounds = chartBounds
    Me._ChartControl1.Settings.JitterMode = Nevron.Chart.JitterMode.Disabled
    '
    'ISSUE: Setting NChartControl.Settings.ShapeRenderingMode to AntiAlias or HighQuality causes NLineSeries to have a speckled appearance when NCartesianChart.Enable3D = True.
    Me._ChartControl1.Settings.ShapeRenderingMode = Nevron.GraphicsCore.ShapeRenderingMode.AntiAlias
    'Me._ChartControl1.Settings.ShapeRenderingMode = Nevron.GraphicsCore.ShapeRenderingMode.HighQuality
    'Me._ChartControl1.Settings.ShapeRenderingMode = Nevron.GraphicsCore.ShapeRenderingMode.HighSpeed
    '
    Me.Controls.Add(Me._ChartControl1)

    Me._CheckBox1 = New Windows.Forms.CheckBox
    Me._CheckBox1.Text = "Enable 3D"
    Me._CheckBox1.Location = New Drawing.Point(0, Me._ChartControl1.Bottom)
    Me._CheckBox1.AutoSize = True
    Me._CheckBox1.Anchor = AnchorStyles.Left Or AnchorStyles.Bottom
    Me._CheckBox1.Checked = Me._ChartControl1.Charts(0).Enable3D
    Me.Controls.Add(Me._CheckBox1)

    Me._CheckBox2 = New Windows.Forms.CheckBox
    Me._CheckBox2.Text = "Enable AntiAlias"
    Me._CheckBox2.Location = New Drawing.Point(Me._CheckBox1.Right + 4, Me._ChartControl1.Bottom)
    Me._CheckBox2.AutoSize = True
    Me._CheckBox2.Anchor = AnchorStyles.Left Or AnchorStyles.Bottom
    Me._CheckBox2.Checked = (Me._ChartControl1.Settings.ShapeRenderingMode = Nevron.GraphicsCore.ShapeRenderingMode.AntiAlias)
    Me.Controls.Add(Me._CheckBox2)
  End Sub
  Private Sub AddLineSeries( _
    ByVal count As Integer, _
    ByVal phaseOffset As Double, _
    ByVal color As Drawing.Color, _
    ByVal chart As Nevron.Chart.NCartesianChart)

    Dim series As New Nevron.Chart.NLineSeries
    series.DataLabelStyle.Visible = False
    series.BorderStyle.Color = color
    series.BorderStyle.Width = New Nevron.GraphicsCore.NLength(2.5!)
    '
    Call Me.AddLineData(count, phaseOffset, series)

    chart.Series.Add(series)
  End Sub
  Private Sub AddLineData( _
    ByVal count As Integer, _
    ByVal phaseOffset As Double, _
    ByVal series As Nevron.Chart.NLineSeries)

    Dim prevYVal As Double = 0
    Dim prevXVal As Double = 0

    Dim valueCount As Integer = series.Values.Count

    If valueCount > 0 Then
      prevYVal = CDbl(series.Values(valueCount - 1))
      prevXVal = CDbl(series.XValues(valueCount - 1))
    End If

    Dim xValues As Double() = New Double(count - 1) {}
    Dim yValues As Double() = New Double(count - 1) {}

    Const constValue As Double = 0.5# 'Replaces the random value from the example.
    Dim magnitude As Double = 0.01 + constValue * 5

    ' continuous
    Dim angle As Double = 2 * Math.PI * phaseOffset
    Dim phase As Double = 10 * (Math.PI * 2 * constValue) / count + 0.0001

    Dim i As Integer = 0
    Do While i < count
      Dim yStep As Double = Math.Sin(angle) * magnitude
      Dim xStep As Double = 0.01 + constValue * magnitude

      If xStep < 0 Then
        xStep = 0
      End If

      angle += phase
      prevXVal += xStep

      yValues(i) = prevYVal + yStep
      xValues(i) = prevXVal
      i += 1
    Loop

    series.Values.AddRange(yValues)
    series.XValues.AddRange(xValues)
  End Sub

  Private Sub _CheckBox1_CheckedChanged(sender As Object, e As System.EventArgs) Handles _CheckBox1.CheckedChanged
    Me._ChartControl1.Charts(0).Enable3D = Me._CheckBox1.Checked
    Me._ChartControl1.Refresh()
  End Sub

  Private Sub _CheckBox2_CheckedChanged(sender As Object, e As System.EventArgs) Handles _CheckBox2.CheckedChanged
    If (Me._CheckBox2.Checked) Then
      Me._ChartControl1.Settings.ShapeRenderingMode = Nevron.GraphicsCore.ShapeRenderingMode.AntiAlias
    Else
      Me._ChartControl1.Settings.ShapeRenderingMode = Nevron.GraphicsCore.ShapeRenderingMode.Default
    End If
  End Sub

End Class



Nevron Support
Posted 8 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hi Lance,

This appearance is caused by the OpenGL line rendering itself so there so not much we can do there. Regarding the size change - you can limit this effect by settings bounds mode to Fit:

chartchart.BoundsMode = Nevron.GraphicsCore.BoundsMode.Fit

Let us know if you meet any problems.


Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic