Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Interface and Graphics > Creating good Perlin Noise with VB.Net code. [resolved].


Reply
 
Thread Tools Display Modes
  #1  
Old 03-31-2012, 07:30 PM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default Creating good Perlin Noise with VB.Net code. [resolved].


I've been trying to get some help for this in another thread,
but it looks like it's a task that is going to need a wider audience
to try and find someone who knows something about
writing/creating procedural textures at the pixel level in VB.Net.

The VB6 example I'm trying to convert to VB.Net is attached to this post.

I've already researched all over the internet and although there are samples in virtually
every other programming language in existence
except there are none for VB.Net.
(If you know of one please reply with a link!!!)


Most of the research links I've already done on are in this post,
which also has a working VB.Net attachment for generating
a set of random greyscale pixels and warping them in various ways.
It's slow because it uses SetPixel but it works.
(see the lock/unlock bits code below for the improved performance way to
manipulate pixels).

mms contributed a little GDI+ VB6 code snippet here, but I couldn't get converted to VB.Net properly.

Toward the bottom is this long post,
there are some additional research links,
as well as links to wood grain images created from perlin noise
(showing what should be possible),
and a simple working C#.Net code version that creates Perlin
Noise is attached at the bottom.


Anyway, it seems the only way to get any speed
when working with individual pixels is to use:
System.Runtime.InteropServices.Marshal.Copy
with
img.LockBits and UnLockBits

Many of the samples I found also used these:
Image.Clone
DrawImageUnscaled (for a little extra speed over DrawImage)

So attached are three sets of code which may work
toward the final solution.

The pixelate test code basically averages out a bunch of pixels
to create that pixelation-as-censorship effect you see on television.
The code works fast and effectively and I've included a screenshot.

The second example ("Pixel_Adjust_using_MarshalCopy_LockBits.zip")
is code that could be the basis for a full image processing app.

It only partially works - I believe it may be an issue with Format24bppRgb
being applied to a colormatrix which treats it as Format32bppArgb image.
The error effect is like scanlines that shouldn't be there.

Quote:
edit1: found some VB.Net colormatrix code here.
I will try to compare to what's going on with 2nd example.
Having some clue why this code (that doesn't give any error or warnings),
fails would be helpful in understanding how to do image processing at the
pixel level.

The last example ("PerlinNoiseAttempt1.zip") is a the code from the working C#.Net version cited above where I took all the C# code and converted it to VB.Net using an
online C#-to-VB.Net converter.

I use all the same controls with all the same property values.
The project gives no error or warnings and builds/runs perfectly.

However all I get for the picturebox
(which has a white background color at design time)
is the drawing "effect" of having it turn to a solid grey at runtime.


Attached Images
File Type: jpg Pixelate_Test_Screenshot.JPG (166.5 KB, 27 views)
Attached Files
File Type: zip Pixelate_Test.zip (192.5 KB, 17 views)
File Type: zip Pixel_Adjust_using_MarshalCopy_LockBits.zip (178.1 KB, 7 views)
File Type: zip PerlinNoiseAttempt1.zip (22.0 KB, 16 views)

Last edited by surfR2911; 03-31-2012 at 08:03 PM.
Reply With Quote
  #2  
Old 03-31-2012, 10:19 PM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default A visit to the color matrix

I had a bit of trouble with the colormatrix, but I got a working demo..
This article helped a little (on colormatrix theory if not coding).

There is a nice bit of VB.Net HSL adjustment here.

Although this doesn't get me any perlin noise,
hopefully it will let me tint any perlin noise image
I finally am able to create.

I found forum member "jo0ls" left some image processing
code on psc.

Below is a screenshot of a greyscale image using jo0ls' "random jitter"
filter.

Have to look at his code more..
His color negative inverse works better than the
color matrix code I posted.

Oh I found out colormatrix can be used for Gaussian Blurring by doing multiple
overlays of alpha colormatrix offsets.

I modified this CodePoject on Gaussian Blurring using SetPixel
to also use colormatrix blurring.
Of course this new method is many times faster.

Still looking for a way to Perlin Noise and
color matrix doesn't look like it will do it.
Attached Images
File Type: jpg colormatrix_screenshot.JPG (86.5 KB, 20 views)
File Type: jpg random_jitter.JPG (73.7 KB, 22 views)
File Type: jpg GB-2methods_screenshot.JPG (26.0 KB, 21 views)
Attached Files
File Type: zip ColorMatrixTest.zip (34.5 KB, 11 views)
File Type: zip GausianBlur_TwoMethodsCompared.zip (28.1 KB, 13 views)

Last edited by surfR2911; 03-31-2012 at 11:32 PM.
Reply With Quote
  #3  
Old 04-01-2012, 03:33 AM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default Try try again..

I was playing around with first C# to VB.Net conversion.
It seemed like it was too literal and the events --where being handled right,
so I recreated the whole form and set of controls from scratch and then put back in the math routines.

The picturebox changes from white to all black - so probably somewhere the math is zero-ing out the pixel colors.

But this is encouraging because it shows that everything,
(except the math),
is working right.

It has threading which makes it very difficult to step through.

Here's all the code in case anyone catch catch something stupid/obvious:
Code:
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D
Imports System.Math
Imports System.Runtime.InteropServices

Public Class Form1
  Const ImageSize As Integer = 250
  Private bytes As Byte() = New Byte(ImageSize * ImageSize * 4 - 1) {}
  Private weight1 As Double
  Private weight2 As Double
  Private weight4 As Double
  Private weight8 As Double
  Private weight16 As Double
  Private weight32 As Double
  Private weight64 As Double
  Private Expo As Double, Factor As Double
  Private stat As Integer(,) = New Integer(ImageSize - 1, ImageSize - 1) {}

  Private Sub Recalc()
    Dim sum As Double = 0
    sum += sld1.Value
    sum += sld2.Value
    sum += sld4.Value
    sum += sld8.Value
    sum += sld16.Value
    sum += sld32.Value
    sum += sld64.Value
    If sum = 0 Then
      Return
    End If
    weight1 = sld1.Value / sum
    weight2 = sld2.Value / sum
    weight4 = sld4.Value / sum
    weight8 = sld8.Value / sum
    weight16 = sld16.Value / sum
    weight32 = sld32.Value / sum
    weight64 = sld64.Value / sum
    If Not [Double].TryParse(textBox1.Text, Expo) Then
      Expo = 1
    End If
    If Not [Double].TryParse(txtFaktor.Text, Factor) Then
      Factor = 1
    End If
    Dim bmp As New Bitmap(ImageSize, ImageSize)
    System.Threading.Tasks.Parallel.[For](0, _
       ImageSize - 1, New Action(Of Integer)(AddressOf CalcRow))
    Dim data As BitmapData = bmp.LockBits(New Rectangle(0, _
         0, ImageSize, ImageSize), _
         System.Drawing.Imaging.ImageLockMode.[WriteOnly], _
         System.Drawing.Imaging.PixelFormat.Format32bppArgb)
    System.Runtime.InteropServices.Marshal.Copy(bytes, _
         0, data.Scan0, data.Stride * data.Height)
    bmp.UnlockBits(data)
    PictureBox1.Image = bmp
    End Sub

  Private Sub CalcRow(y As Integer)
    For x As Integer = 0 To ImageSize - 1
      Dim c As Double = 0
      c += GetPixel(x / 64.0, y / 64.0) * weight64
      c += GetPixel(x / 32.0, y / 32.0) * weight32
      c += GetPixel(x / 16.0, y / 16.0) * weight16
      c += GetPixel(x / 8.0, y / 8.0) * weight8
      c += GetPixel(x / 4.0, y / 4.0) * weight4
      c += GetPixel(x / 2.0, y / 2.0) * weight2
      c += GetPixel(x, y) * weight1
      bytes(4 * (x + ImageSize * y) + 3) = 255
      bytes(4 * (x + ImageSize * y) _
         + 0) = CByte(Math.Truncate(Math.Min(255, _
   Math.Max(0, (255 * Factor * Math.Pow(c / 255, Expo))))))
      bytes(4 * (x + ImageSize * y) _
         + 1) = CByte(Math.Truncate(Math.Min(255, _
   Math.Max(0, (255 * Factor * Math.Pow(c / 255, Expo))))))
      bytes(4 * (x + ImageSize * y) _
         + 2) = CByte(Math.Truncate(Math.Min(255, _
   Math.Max(0, (255 * Factor * Math.Pow(c / 255, Expo))))))
    Next
  End Sub

  Private Function GetPixel(x As Double, y As Double) As Double
    Dim ix As Double = Math.Floor(x)
    Dim iy As Double = Math.Floor(y)
    Dim fx As Double = x - ix
    Dim fy As Double = y - iy
    Dim ol As Double = 0, [or] As Double = 0
    Dim ul As Double = 0, ur As Double = 0
    ol = stat(CInt(Math.Truncate(ix)), CInt(Math.Truncate(iy)))
    If fx <> 0 Then
      [or] = stat(CInt(Math.Truncate(ix)) + 1, CInt(Math.Truncate(iy)))
    End If
    If fy <> 0 Then
      ul = stat(CInt(Math.Truncate(ix)), CInt(Math.Truncate(iy)) + 1)
    End If
    If fx <> 0 AndAlso fy <> 0 Then
      ur = stat(CInt(Math.Truncate(ix)) + 1, CInt(Math.Truncate(iy)) + 1)
    End If
    Return (1 - fy) * ((1 - fx) * ol + fx * [or]) _
                     + fy * (((1 - fx) * ul + fx * ur))
  End Function

  Private Sub Button1_Click(sender As System.Object, _
             e As System.EventArgs) Handles Button1.Click
    Recalc()
  End Sub
End Class
I don't exactly understand this line:
Quote:
Private stat As Integer(,) = New Integer(ImageSize - 1, ImageSize - 1) {}
Is stat one value or more than one value?

I have never dealt with "System.Threading.Tasks.Parallel" before - is there a recommended debugging method?

Oh well, I'm too tired to concentrate any more - I'll see about it in the morning..zzzzzzzzzzz
Attached Files
File Type: zip PerlinNoise_Test5.zip (19.4 KB, 8 views)

Last edited by surfR2911; 04-01-2012 at 03:44 AM.
Reply With Quote
  #4  
Old 04-01-2012, 01:11 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,861
Default

Private stat As Integer(,) = New Integer(ImageSize - 1, ImageSize - 1) {}

Stat is two dimensional array of integers. Just another way of declaring it.
I would normally use the older syntax.

Private stat(ImageSize - 1, ImageSize - 1) As Integer
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #5  
Old 04-01-2012, 03:55 PM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default passel stops by for a visit..

Quote:
Stat is two dimensional array of integers. Just another way of declaring it.
I would normally use the older syntax.
Thanks for posting.

I didn't even realize there was some kind of older-versus-newer dichotomy,
but your code looks "normal" whereas the other way of of specifying the array just looks strange.
Guess I'm just not tuned into the ".Net way" enough yet..

In my internet research all all things graphical in VB.Net one site keep turning up in the x-referencing: http://www.bobpowell.net/

There is a section on color lock bits with a nice scan-stride diagram, but it doesn't have a full working code sample, so I was forced to turn to his 1BPP page to find some working code.

The tern "working code" should be used loosely since he doesn't have any direct downloads of projects/solutions.

My first attampt at just copying and pasting the code on the page failed - the splitter control code gave my Express edition of VB.Net a lot of errors.

So I basically reconstructed the project as a VB.Net Express project (took about 15 minutes) and attached it below.

Still don't help me with generating Perlin Noise, but I learned a little bit more about lock bits/unlock bits.If only there was a way to visually see the process taking place on screen with a stop and play VCR controls.

Oh well, we'll see what else I can done on my "day off"..
Attached Files
File Type: zip BP_1BPP_rev1.zip (47.4 KB, 5 views)
Reply With Quote
  #6  
Old 04-02-2012, 04:22 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,861
Default

You said the code was difficult to step through because of the parallel processing, but the capability used was added as part of .Net Framework 4.
In the current majority of cases, it probably doesn't add much, since most people probably still have dual core systems.
The thread switching overhead for code intensive (not event pending) type code is significant on a given core, so I imagine for the most part, the parallel library will either not create more threads than cores, or the threads will essentially be queued up and processed mostly serially since they are processor intensive.
It probably does make a significant difference on quad or more core systems (but I haven't tried to benchmark a case because I don't have two different, but comparable processors to test on).
A fair test would probably be running the same code on an i3 vs an i5 vs an i7 processor, since the base core processing of the ix series is probably comparable, but having more cores would benefit the parallel loop capability of the parallel library.

In any case, you can easily replace the parallel For, with a standard For loop if you want to step through the code in a sequential manner.
For instance, in the C# code:
Code:
// replace this
  System.Threading.Tasks.Parallel.For(0, ImageSize - 1, new Action<int>(CalcRow));

// with this

  for (int i = 0; i < ImageSize; i++)
    CalcRow(i);
Since the machine I'm running on is just a dual core machine, if there is a speed difference, I can't tell just by observation.

{edit}
P.S. Since I already looked at the C# version, I decided to take a couple minutes to look at your VB.net port.
I figured I would just look at the two side by side, step through both at the same time if I had to, to compare the operation.

So, I opened the VB version and in the Form Load, the very first function call,
RedrawStatic wasn't there. The sub wasn't present in the VB version.
RedrawStatic loops through the stat array and creates the random texture (values between 0 and 255 (actually 0 to 254 the way the code uses the Random class, perhaps it should be 0 to 255?))
If your static texture is all 0's, then a solid black result from noisifying "nothing" isn't unexpected.

So, I added the RedrawStatic Sub, called it from the Form_Load event and the Button Click event, as was done in the C# code.
Running the program and, sure enough, it displayed a "noisy" pattern.

Adjusting the sliders (Track bars) didn't change things until you re-clicked the button.
The C# code had an EvtRedraw function, which all the Trackbar's ValueChanged Events were tied to.

The VB code didn't have that sub either, so I added an EvtRedraw Sub, and tied all the trackbar's ValueChanged Events to it.
Now the output updates whenever you changed the value of a trackbar.

I didn't verify anything else, as I'm not really interested in this stuff, but in this case, it didn't take too much time to look at since you did most of the grunt work in converting the code.
I've attached the updated project.
Attached Files
File Type: zip PerlinNoise_Test5p.zip (18.1 KB, 22 views)
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 04-02-2012 at 05:13 PM. Reason: Decided to look at the VB port of the C# code.
Reply With Quote
  #7  
Old 04-03-2012, 05:26 PM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default mucho gracias

Thanks to passel the forum now has it's first working sample of how to do
Perlin Noise (and greyscale difference clouds) with VB.Net.

The thread is marked as resolved
and hopefully others will post further modifications to this code
that will show how such noise can be further shaped
for different types of procedural textures.
Reply With Quote
  #8  
Old 01-05-2013, 07:10 PM
jamesplotts jamesplotts is offline
Newcomer
 
Join Date: Jan 2013
Location: Kansas USA
Posts: 1
Default And here is a useful Perlin Noise Class

I took your working form sample and wrote a class that can be dropped into a project easily. You create an instance of the class specifying the width and height of the field, and it generates a bitmap with the Perlin Noise field.

Code:
Imports System.Data
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D
Imports System.Drawing
Imports System.Threading


    Public Class PerlinNoiseGenerator
        Private bytes As Byte()
        Private dweight1 As Double
        Private dweight2 As Double
        Private dweight4 As Double
        Private dweight8 As Double
        Private dweight16 As Double
        Private dweight32 As Double
        Private dweight64 As Double
        Private pvtExpo As Double = 1, pvtFactor As Double = 1
        Private stat As Integer(,)
        Private pvtWidth As Int32 = 250
        Private pvtHeight As Int32 = 250
        Private pvtFinalImage As Bitmap
        Private RecalcRunning As Boolean
        Private Resetting As Boolean

        Dim pvtWeight1Value As Int32 = 1
        Dim pvtWeight2Value As Int32 = 2
        Dim pvtWeight4Value As Int32 = 10
        Dim pvtWeight8Value As Int32 = 25
        Dim pvtWeight16Value As Int32 = 40
        Dim pvtWeight32Value As Int32 = 48
        Dim pvtWeight64Value As Int32 = 50

        Public Sub New(ByVal Width As Int32, ByVal Height As Int32)
            If Width < 0 OrElse Height < 0 Then Throw New Exception("Parameter out of bounds - cannot be negative value.")
            pvtWidth = Width
            pvtHeight = Height
            RecalcRunning = False
            stat = New Integer(pvtWidth - 1, pvtHeight - 1) {}
            bytes = New Byte(pvtWidth * pvtHeight * 4 - 1) {}
            RedrawStaticMap()
        End Sub

        Public Sub RestoreDefaults()
            Resetting = True
            While RecalcRunning
                Thread.Sleep(0)
            End While
            pvtWeight1Value = 1
            pvtWeight2Value = 2
            pvtWeight4Value = 10
            pvtWeight8Value = 25
            pvtWeight16Value = 40
            pvtWeight32Value = 48
            pvtWeight64Value = 50
            pvtExpo = 1
            pvtFactor = 1
            Resetting = False
            RedrawStaticMap()
        End Sub


        Public Sub RedrawStaticMap()
            Dim rndNum As Random = New Random
            Dim c As Integer

            For y As Integer = 0 To pvtWidth - 1
                For x As Integer = 0 To pvtHeight - 1
                    c = rndNum.Next(255)
                    stat(x, y) = c
                Next
            Next
            Recalc()
        End Sub


        Public Sub Recalc()
            If Resetting Then Exit Sub
            RecalcRunning = True
            Dim sum As Double = 0
            sum += pvtWeight1Value
            sum += pvtWeight2Value
            sum += pvtWeight4Value
            sum += pvtWeight8Value
            sum += pvtWeight16Value
            sum += pvtWeight32Value
            sum += pvtWeight64Value
            If sum = 0 Then
                Return
            End If
            dweight1 = pvtWeight1Value / sum
            dweight2 = pvtWeight2Value / sum
            dweight4 = pvtWeight4Value / sum
            dweight8 = pvtWeight8Value / sum
            dweight16 = pvtWeight16Value / sum
            dweight32 = pvtWeight32Value / sum
            dweight64 = pvtWeight64Value / sum

            Dim bmp As New Bitmap(pvtWidth, pvtHeight)
            '  Execute parallel threads for all the row calculations of the heightfield.
            System.Threading.Tasks.Parallel.[For](0, pvtHeight - 1, New Action(Of Integer)(AddressOf CalcRow))
            Dim data As BitmapData = bmp.LockBits(New Rectangle(0, 0, pvtWidth, pvtHeight), _
                 System.Drawing.Imaging.ImageLockMode.[WriteOnly], System.Drawing.Imaging.PixelFormat.Format32bppArgb)
            System.Runtime.InteropServices.Marshal.Copy(bytes, 0, data.Scan0, data.Stride * data.Height)
            bmp.UnlockBits(data)
            pvtFinalImage = bmp
            RecalcRunning = False
        End Sub

        Private Sub CalcRow(ByVal y As Integer)
            For x As Integer = 0 To pvtWidth - 1
                Dim c As Double = 0
                c += GetPixel(x / 64.0, y / 64.0) * dweight64
                c += GetPixel(x / 32.0, y / 32.0) * dweight32
                c += GetPixel(x / 16.0, y / 16.0) * dweight16
                c += GetPixel(x / 8.0, y / 8.0) * dweight8
                c += GetPixel(x / 4.0, y / 4.0) * dweight4
                c += GetPixel(x / 2.0, y / 2.0) * dweight2
                c += GetPixel(x, y) * dweight1
                bytes(4 * (x + pvtWidth * y) + 3) = 255
                bytes(4 * (x + pvtWidth * y) + 0) = CByte(Math.Truncate(Math.Min(255, Math.Max(0, (255 * pvtFactor * Math.Pow(c / 255, pvtExpo))))))
                bytes(4 * (x + pvtWidth * y) + 1) = CByte(Math.Truncate(Math.Min(255, Math.Max(0, (255 * pvtFactor * Math.Pow(c / 255, pvtExpo))))))
                bytes(4 * (x + pvtWidth * y) + 2) = CByte(Math.Truncate(Math.Min(255, Math.Max(0, (255 * pvtFactor * Math.Pow(c / 255, pvtExpo))))))
            Next
        End Sub

        Private Function GetPixel(ByVal x As Double, ByVal y As Double) As Double
            Dim ix As Double = Math.Floor(x)
            Dim iy As Double = Math.Floor(y)
            Dim fx As Double = x - ix
            Dim fy As Double = y - iy
            Dim ol As Double = 0, [or] As Double = 0, ul As Double = 0, ur As Double = 0
            ol = stat(CInt(Math.Truncate(ix)), CInt(Math.Truncate(iy)))
            If fx <> 0 Then
                [or] = stat(CInt(Math.Truncate(ix)) + 1, CInt(Math.Truncate(iy)))
            End If
            If fy <> 0 Then
                ul = stat(CInt(Math.Truncate(ix)), CInt(Math.Truncate(iy)) + 1)
            End If
            If fx <> 0 AndAlso fy <> 0 Then
                ur = stat(CInt(Math.Truncate(ix)) + 1, CInt(Math.Truncate(iy)) + 1)
            End If
            Return (1 - fy) * ((1 - fx) * ol + fx * [or]) + fy * (((1 - fx) * ul + fx * ur))
        End Function

        Public ReadOnly Property HeightValue(ByVal X As Int32, ByVal Y As Int32) As Int32
            Get
                If X < 0 OrElse X > pvtWidth - 1 OrElse Y < 0 OrElse Y > pvtHeight - 1 Then Throw New IndexOutOfRangeException()
                If pvtFinalImage Is Nothing Then RestoreDefaults()
                Return CInt(pvtFinalImage.GetPixel(X, Y).GetBrightness * 256)
            End Get
        End Property

        Public ReadOnly Property FinalImage() As Image
            Get
                If pvtFinalImage Is Nothing Then RestoreDefaults()
                Return pvtFinalImage
            End Get
        End Property

        Public ReadOnly Property Width() As Int32
            Get
                Return pvtWidth
            End Get
        End Property

        Public ReadOnly Property Height() As Int32
            Get
                Return pvtHeight
            End Get
        End Property

        Public Property Weight1() As Int32
            Get
                Return pvtWeight1Value
            End Get
            Set(ByVal value As Int32)
                If value < 1 OrElse value > 100 Then Throw New Exception("Value not in a range of 1-100.")
                pvtWeight1Value = value
                Recalc()
            End Set
        End Property

        Public Property Weight2() As Int32
            Get
                Return pvtWeight2Value
            End Get
            Set(ByVal value As Int32)
                If value < 1 OrElse value > 100 Then Throw New Exception("Value not in a range of 1-100.")
                pvtWeight2Value = value
                Recalc()
            End Set
        End Property

        Public Property Weight4() As Int32
            Get
                Return pvtWeight4Value
            End Get
            Set(ByVal value As Int32)
                If value < 1 OrElse value > 100 Then Throw New Exception("Value not in a range of 1-100.")
                pvtWeight4Value = value
                Recalc()
            End Set
        End Property

        Public Property Weight8() As Int32
            Get
                Return pvtWeight8Value
            End Get
            Set(ByVal value As Int32)
                If value < 1 OrElse value > 100 Then Throw New Exception("Value not in a range of 1-100.")
                pvtWeight8Value = value
                Recalc()
            End Set
        End Property

        Public Property Weight16() As Int32
            Get
                Return pvtWeight16Value
            End Get
            Set(ByVal value As Int32)
                If value < 1 OrElse value > 100 Then Throw New Exception("Value not in a range of 1-100.")
                pvtWeight16Value = value
                Recalc()
            End Set
        End Property

        Public Property Weight32() As Int32
            Get
                Return pvtWeight32Value
            End Get
            Set(ByVal value As Int32)
                If value < 1 OrElse value > 100 Then Throw New Exception("Value not in a range of 1-100.")
                pvtWeight32Value = value
                Recalc()
            End Set
        End Property

        Public Property Weight64() As Int32
            Get
                Return pvtWeight64Value
            End Get
            Set(ByVal value As Int32)
                If value < 1 OrElse value > 100 Then Throw New Exception("Value not in a range of 1-100.")
                pvtWeight64Value = value
                Recalc()
            End Set
        End Property

    End Class
Enjoy everyone!

Last edited by Cerian Knight; 01-08-2013 at 10:55 AM. Reason: Post okayed, per TS request in post #7 (and edited code correction per poster request)
Reply With Quote
  #9  
Old 06-22-2013, 02:45 PM
Zwockel Zwockel is offline
Newcomer
 
Join Date: Apr 2008
Posts: 1
Default

@jamesplotts very nice !
but you should correct the line:

System.Threading.Tasks.Parallel.[For](0, pvtHeight - 1, New Action(Of Integer)(AddressOf CalcRow))

into

System.Threading.Tasks.Parallel.[For](0, pvtHeight , New Action(Of Integer)(AddressOf CalcRow))

without the -1 or you will get a blank last line.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->