1

I am currently creating a list of a class item

Public glstBeamsList As New List(Of BEAMLAYOUT)

Public Class BEAMLAYOUT
    Public sourceLocation(2) As Double
    Public pointEastingNorthingDepth As New List(Of Double())
End Class

This class list items can have up to 256 points in it with 3 items in the array.

my issue is that the glstBeamsList is continuously being added to and the routine I have reading thru the list to draw the points to a bitmap and display on screen takes a very long time once the list gets large.

here is the code I am using any help is appreciated.

    Dim Eastlimit, WestLimit, NorthLimit, SouthLimit As Double
    Eastlimit = dblSourceLocationEastings + (gintPlanWidth / 2)
    WestLimit = dblSourceLocationEastings - (gintPlanWidth / 2)
    NorthLimit = dblSourceLocationNorthings + (gintPlanHeight / 2)
    SouthLimit = dblSourceLocationNorthings - (gintPlanHeight / 2)

    For i = 0 To glstBeamsList.Count - 1
        If glstBeamsList(i).sourceLocation(0) = 0 Or
           glstBeamsList(i).sourceLocation(1) = 0 Then GoTo nextPoint

        For ii = 0 To glstBeamsList(i).pointEastingNorthingDepth.Count - 1
            Dim point() = glstBeamsList(i).pointEastingNorthingDepth(ii)
            If point(0) < Eastlimit Then
                If point(0) > WestLimit Then
                    If point(1) < NorthLimit Then
                        If point(1) > SouthLimit Then
                            Dim x, y As Double
                            If point(0) < glstBeamsList(i).sourceLocation(0) Then x = point(0) - glstBeamsList(i).sourceLocation(0)
                            If point(0) > glstBeamsList(i).sourceLocation(0) Then x = glstBeamsList(i).sourceLocation(0) - point(0)
                            If point(1) < glstBeamsList(i).sourceLocation(1) Then y = point(1) - glstBeamsList(i).sourceLocation(1)
                            If point(1) > glstBeamsList(i).sourceLocation(1) Then y = glstBeamsList(i).sourceLocation(1) - point(1)
                            Dim clrPointColor As New Color
                            Select Case point(2)
                                Case -10 To 0
                                    clrPointColor = Color.Red
                                Case -20 To -11
                                    clrPointColor = Color.Orange
                                Case -30 To -21
                                    clrPointColor = Color.Yellow
                                Case -40 To -31
                                    clrPointColor = Color.Green
                                Case -50 To -41
                                    clrPointColor = Color.Blue
                                Case -60 To -51
                                    clrPointColor = Color.Indigo
                                Case -70 To -61
                                    clrPointColor = Color.Purple
                                Case -80 To -71
                                    clrPointColor = Color.Violet
                                Case -90 To -81
                                    clrPointColor = Color.Gray
                                Case -100 To -91
                                    clrPointColor = Color.Black
                                Case -110 To -101
                                    clrPointColor = Color.Red
                            End Select
                            Dim xLoc As Integer = ((gintPlanWidth / 2) + x) * gsngPlanScaleFactor
                            Dim yLoc As Integer = ((gintPlanHeight / 2) + y) * gsngPlanScaleFactor
                            If xLoc > 0 And xLoc < PicBox.Width Then
                                If yLoc > 0 And yLoc < PicBox.Height Then
                                    ggfxPlanViewBitmap.SetPixel(xLoc, yLoc, clrPointColor)

                                End If
                            End If
                        End If
                    End If
                End If
            End If
        Next
Ňɏssa Pøngjǣrdenlarp
  • 37,255
  • 11
  • 50
  • 147
  • I don't see where the goto is going. If the bitmap doesn't change size, most of this code could be done once each time a point is added instead of all the time. When a new point is added, get it's new position and color, add it to the list then just do a loop of all positions/color. If you are drawing on the screen, suspending the UI from drawing until all is done could increase the speed. – the_lotus Nov 14 '17 at 16:24
  • This may not help much, but you could pre-populate an array with possible colors from 0 to 101. Then use the absolute value of point(2) as an index into that array (with appropriate bounds checking of course). Your real bottleneck is probably the SetPixel. – dwilliss Nov 14 '17 at 16:46
  • Try this: https://stackoverflow.com/questions/24701703/c-sharp-faster-alternatives-to-setpixel-and-getpixel-for-bitmaps-for-windows-f – dwilliss Nov 14 '17 at 16:47
  • The Goto is directly at the end of the first For Loop it just would post correctly in my post. – John Sheedy Nov 14 '17 at 16:48
  • You can also populate a byte array with the colors, then construct a bitmap from it. See https://stackoverflow.com/a/21571587/832052 – djv Nov 14 '17 at 17:35

0 Answers0