News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Drawing Graphs query

Started by Raistlin, July 22, 2015, 03:41:10 PM

Previous topic - Next topic

Raistlin

Hi again hard working ppl,

Anyone have expierence drawing graphs inside normal resource (win API) environment?
(Thought I remember seeing jj2007 do something like what I'am looking for in a project of his)

I'am looking to draw sinoide graphs for my Fourier series / Fourier transform app.  A sample
with recommendations would be appreciated. Possibly listing pitfalls to look out for? Oh yes
and quick redraw is essential as live streaming data needs to be visualized.

Thanks in advance
Raistlin
Are you pondering what I'm pondering? It's time to take over the world ! - let's use ASSEMBLY...

dedndave

the attachment to the linked post is a Bezier Spline example program
it uses data from a file to draw the splines

http://masm32.com/board/index.php?topic=1969.msg20895#msg20895

of course, you don't have to use PolyBezier to draw sine waves
you can also plot points and use MoveToEx and LineTo to draw lines
or - you could create a DIB section and "draw" directly to the bitmap

jj2007

#2
Hi Raistlin,

Attached three samples. PlotSinus2 is the simplest:
  CASE WM_PAINT            ; in the PAINT handler, we plot it onto the client area
      ArrayPlot hWnd, RgbCol(200, 255, 240) ; init with window handle and background colour
      ArrayPlot Sinus()
      ArrayPlot exit, "Sinus"      ; finish with a title


You need one or more arrays. Preferably, they can be loaded in the WM_CREATE handler with ArrayRead:

      Dim rc4() As REAL4
      ArrayRead rc4(), "MyReal4.dat"   


Format can be REAL4, REAL8, DWORD, ...

How do you store your values? Can you post sample data?

If your data is in text format, Recall and MovVal can help (see attached Dax.zip):

include \masm32\MasmBasic\Res\MbGui.asm
Event Create
  MakeFont hLegendFont, Height:20, Weight:FW_SEMIBOLD, "Times New Roman"
  Dim bmw() As REAL4      ; single precision is good enough
  Dim daimler() As REAL4
  Dim vw() As REAL4
  Recall "Dax.tab", dax$(), tab      ; get the database
  For_ ecx=0 To eax-2      ; convert tabbed text to REAL4
      MovVal bmw(ecx), dax$(ecx+1, 2)
      MovVal daimler(ecx), dax$(ecx+1, 3)
      MovVal vw(ecx), dax$(ecx+1, 4)
  Next
Event Paint
      ArrayPlot hWnd, RgbCol(144, 240, 255)            ; init with window handle and background colour
      ArrayPlot bmw(), RgbCol(255, 0, 0), lines=2, 7      ; plot the arrays
      ArrayPlot daimler(), RgbCol(0, 0, 255), lines=2, 7
      ArrayPlot vw(), 0, lines=2, 7
      ArrayPlot exit, "Car manufacturers in the DAX"      ; finish with a title
      GuiText 3, 20, "VW", fcol 0, font hLegendFont      ; set a bold font
      GuiText 3, 50, "Daimer", fcol RgbCol(0, 0, 255)
      GuiText 3, 80, "BMW", fcol RgbCol(255, 0, 0)
GuiEnd

dedndave


Raistlin

Hi & thanks guys - exactly what I was looking for

Looks easier than anticipated.

PS: JJ2007 - the Dax example has a corrupt zip - but the plots example is ultra cool for a tut.


again I would like to extend my appreciation dedndave and jj.
Are you pondering what I'm pondering? It's time to take over the world ! - let's use ASSEMBLY...

Gunther

Hi Raistlin,

Quote from: Raistlin on July 22, 2015, 08:34:54 PM
PS: JJ2007 - the Dax example has a corrupt zip - but the plots example is ultra cool for a tut.

no it hasn't. It's not a real zip file, but the image. You can view it with an image tool like Iranview and the like. It has to do with some limitations of the forum. You can't attach images, only zip files.

Gunther
You have to know the facts before you can distort them.

jj2007

Quote from: Raistlin on July 22, 2015, 08:34:54 PMPS: JJ2007 - the Dax example has a corrupt zip - but the plots example is ultra cool for a tut.

As Gunther already wrote, it's a trick to convince the forum software to display attached images.

Again, which format are you using? Binary or text file? Both are possible, see below, but it would be nice to see an example of your data.

      Dim rc4() As REAL4
      if 1      ; either get your data as text from some buffer, e.g. from a text file...
            StringToArray "1.0 1.5 1.8 1.75 1.72 1.75 1.8 1.5 1.0", rc4()
      else      ; ... or get it directly in 4-byte binary format from a file
            ArrayRead rc4(), "MyReal4.dat"   
      endif

Raistlin

Hi jj,

The data will be converted to internal real4 or 8
from dynamic sources and normalized for diffrenciation
and reporting purposes. This at the core of the idea
that the functionality be data independant but not blatently
Object orientated [sorry biteridder]. 

Hope this helps
R
Are you pondering what I'm pondering? It's time to take over the world ! - let's use ASSEMBLY...

jj2007

Quote from: Raistlin on July 23, 2015, 12:24:56 AMThe data will be converted to internal real4 or 8 from dynamic sources and normalized

Check the sox & crime example. If you have a dataset online, we could give it a try. ArrayPlot does normalisation btw, if you throw more than one array into the WM_PAINT handler. There are some undocumented features like the lines=n one, let me know if you want to go that road.

dedndave

when you convert the data - convert to integer as soon as is practical
pixel plots are eventually integer locations, anyways   :P

in the PolyBezier example, i have a couple routines that use the FPU to calculate control points
if you are doing all sine waves, you could probably eliminate that step
the control points for PolyBezier sine waves are very simple to derive