LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Draw Multiple Line for Large data

Solved!
Go to solution

Is there a way to improve the speed and performance of drawing a large amount of data in the picture control using the "Draw multiple Line.vi" function? It currently takes a long time for large data, so I'm looking for suggestions on how to optimize it.

 

The attached vi takes more time if the length is more than 10 K points and the vi goes in not responding mode.

Balaji PK (CLA)
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better

Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
0 Kudos
Message 1 of 33
(814 Views)

I have observed that the performance significantly improves when the data is divided into smaller chunks and processed in a for loop. I  updated VI and attached attached.

Balaji PK (CLA)
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better

Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
0 Kudos
Message 2 of 33
(779 Views)

Obviously a picture control is not suitable for that kind of use and I really question the sanity to draw tens of thousands of thick lines in a small canvas. Do you really need lines at all?

 

In any case, the problem seems to be with the linewidth. Set it to=1 and see if things improve.

Message 3 of 33
(752 Views)

I've rarely used the "Picture" indicator and functions.  I've used Graphs and Plots, and have created "images" using LabVIEW Vision functions.  I noticed when I ran your first Demo, plotting the last 10,000 points from your set of 45,000, I got a not-quite-complete oval, generated in less than 1 ms (pretty fast!), but if I increased the plot to 13,000 (to say nothing of plotting all the points), the time to plot went way up, and the time for the code to end (and let me close the VI) also went way up.

 

I have no idea how pictures are implemented.  The problem (to me) seems to be in the rendering of the picture.  If I considered a picture of 2000 x 1000 pixels, I'm pretty sure I could "color" 45,000 points black (or any other color) and have it rendered in under a second (it's just an Image, for goodness sake).

 

There's something "funky" about the Picture, its underlying Data Structure, and its implementation.  My suggestion is to "do what you're trying to do" with something other than the LabVIEW Picture "thing".  It may be another case of prioritizing "What" you want to do, not "How" to do it (though I've not encountered this bizarre a "What" vs "How" situation previously).

 

Bob Schor

Message 4 of 33
(727 Views)

Could someone post an image of the code?

 

Thank you

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 5 of 33
(687 Views)

I have it on a different computer and can show a picture later.

 

The code has several serious flaws, such as using a shift register and "delete from array" inside a tight loop to process successive "subsets" (hint at the correct function 😄 ), but that's not the main problem.

 

My guess is that drawing a multiline with tens of thousands of segments at once overloads the UI threads and starves computer resource (probably more than just CPU and memory, maybe GDI?). I actually had it lock up the computer and crash the mouse driver. No fun!

 

It would be trivial to map the data into a 2D array first then display it in an intensity graph or convert to an image. An example can be found here.

 

memorygraph.png

 

Under the hood, a 2D image in LabVIEW is very ancient technology, probably dating back to windows 3.1 or earlier. We can look inside the image tools and all they do is basically append binary strings with opcodes and data. We can actually use "string length" to measure the data size of an image wire. (see also this old post for an illustrative example how to accidentally consume all memory!)

0 Kudos
Message 6 of 33
(681 Views)

Here is the original code (as a picture).  The trick is the data, shown as a constant array of clusters (x, y) -- there are 45000 entries!  It took my PC about a millisecond to plot the first 10,000 points (which looks like a noisy sampling of an X-Y plot of an oval).  I've exported the array to a Control, so I could size it and get its max and min.  I'll include the Front Panel, so you can get an idea of the data.

Picture, FP.pngPicture, BD.png

  

Note that the code below the Frame Structure is code I added -- "Data to plot" is a copy of the Cluster being plotted that I used to find its size and the ranges of x and y.

 

Bob Schor

Message 7 of 33
(671 Views)

It is a variation on HPGL HP Graphic Language used for pen plotters, Move Pen, Pen Up,...

 

It is a string under the hood.

 

Two things that sped up picture drawing was

 

Erase first

 

FpDefUpdat ( defer first, draw, undefer)

 

Setting the picture hidden may help.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 33
(661 Views)

Thank you for showing an image!

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 33
(659 Views)

@Ben wrote:

It is a variation on HPGL HP Graphic Language used for pen plotters, Move Pen, Pen Up,...

 

It is a string under the hood.

 

Two things that sped up picture drawing was

 

Erase first

 

FpDefUpdat ( defer first, draw, undefer)


Ah, that brings back memories. I actually generated HPGL code in Fortran in ancient history. Had the HP plotter in eavesdrop mode on the 9600 baud serial line between VT 241 terminal the VAX mainframe. 😄

 

The other two points probably make no difference here. It starts with an empty picture and the picture indicator can be placed after the sequence structure and things are still gummed up. The slowdown is deep inside draw multiline but there is really not much code visible Maybe it happens when the string is converted to an image wire? Nothing else updates in the front panel. (And if we do it in chunks (code not shown), we cannot erase until all chunks are written and things are fast in that scenario.).

Once that slow picture is drawn on the FP, the VI becomes basically unusable, even in edit mode.

 

I still suspect that the main problem is GDI exhaustion. My computer went completely haywire and unresponsive. Mouse/keyboard came back after unplugging/plugging to redetect the device. At one point I got a blue screen stating "preparing security options..." or similar. Never seen that before). Make sure to save all work before event attempting to play with any of this! No fun!

 

It is pure insanity to create tens of thousands of double-width lines just to basically turn a few image pixels black.

 

I wonder how much effort it would take to rewrite the picture function using more modern tools.

 

Sorry, just rambling with partial information and guessing. Maybe somebody has more insight!

Message 10 of 33
(647 Views)