LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Code Optimisation

Hello,

 

I've managed to compile this code as best I can. The code, looks at a grey scale image, and based on the type of image and information, turns the image into a 3D surface plot based on the pixel value which has a relationship to pressure.

 

I wish to optimize the code as much as possible. 

 

The 3D surface plot relies on information in several case statements. The problem at present, is when I go to load the data, the if the arrays are empty, or if I change the main case statement, the information does not seem to update.

 

At present, all the code is in one while-loop and it runs continuously consuming reasources.

 

Could someone help??? 

0 Kudos
Message 1 of 6
(3,098 Views)

First of all, you have some serious race conditions due to overuse of local variables. You are constnaty reading and writing from/to the same locals in parallel, so the outcome will be random. None of the locals are are needed. Let's have a look at the XY terms subVI.

 

You are writing an empty array (A) to the indicator and new values to a local variable (C) of the indicator. Since there is no data dependency we don't know in what order these two things occur, so your output will be empty with a 50% chance. Same with the local in the loop (B). The value never changes during the loop, so all you need is wire from the outside, from the same wire going to the indicator. No local needed. The parts near D can be deleted, it can never  be true.

 

 

Same in the main VI. All the case statement needs to contain is diagram constants, then wire to the locations where they are needed. You should also use an event structure so things are only recalculated in the inputs change, and not every 100ms. Keep the raw array in a shift register.

 

Many more things can be changed and optimized. This is just a very rough draft to give you some ideas.

 

 

Message Edited by altenbach on 12-06-2009 02:51 PM
Download All
Message 2 of 6
(3,079 Views)

Hello,

 

Thank you. I will take what you said on board. The main problem I had was that the array continued filling up with elements. When that array when to the property node which only accepts an exact number of elements, the program crashed.

 

I thought doing it this way would make it only have x amount of elements that I wanted. I see now, that the way in the example works just the same.

 

Just opened the vi... THANK YOU. Take me a while to figure out what you done and why. BUT thank you!

 

Cheers

 

Message Edited by Kamilan on 12-06-2009 05:31 PM
0 Kudos
Message 3 of 6
(3,071 Views)

Quick Question

 

If I change the film type, the image is not loaded correctly. Only if I chose the film type again (maybe a third time on some attempts) then the picture is scaled and plots on the surface plot.

 

Attached are some sample images that I am using.

Download All
0 Kudos
Message 4 of 6
(3,053 Views)

Sorry, there was a oversing. You should place the entire code below the event structure also inside the main event case.

 

Right now, the film type gets read before the event fires, leading to a race condition. See if this helps...

0 Kudos
Message 5 of 6
(3,035 Views)

Hi Kamilan

 

Find Attached code. I had some spare time and i thought i could utilise it for recoding your app. "Have Fun"

 

dont forget to give kudos if you like it Smiley Very Happy

 

I have not tested it or ensured that all the events are catered properly. but it will definately help you

There  few things which are important

1. The code responds to events and does not keep on prosessing irrespective of any parameter change.

2. Application uses architecture

3. Reuse of Code

4. Error Handling (Though i have not given any thought to make error handling effective.)

 

and many more things which altenbach will tell you (and to me Smiley Wink )

Tushar Jambhekar
tushar@jambhekar.com

Jambhekar Automation Solutions
LabVIEW Consultancy, LabVIEW Training
Rent a LabVIEW Developer, My Blog

0 Kudos
Message 6 of 6
(3,004 Views)