UI Interest Group Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

compass rotation in a picture control - best practice?

Hello All,

I am developing avionics software, 2 picture controls will be fairly densely populated with graphics.I am working on a compass rose (written to picture control, see compass image) which needs to rotate smoothly about its centre based on the bearing it is given.

I have developed a strategy to generate an optimum quality/low cpu load solution but hope someone could describe a better way.

It needs to update smoothly and with minimal impact on the CPU load, the compass needs to have an invisible background. I found that trying to re-draw lines and text at an angle N S E W... dramatically reduced the text quality. I believe the use of sin and cos will load the processor for example when rotating pixels so try to steer clear. I also found an amount of tricky code was needed to descibe the rotating compass in terms of line/text

Next I tried an image but needed an invisible background, a png format image was used, however using a lossless, sharp edged png image again resulted in poor quality text when rotated. I am currently looking at making a lossy (jpg interploated) image as a template before converting to png and expect the image quality to be good enough while being rotated. Ive seen this effect on other software

During no delay image rotation I found a typical 200 x 200 pixel png would load an i5 cpu to 30% with a typical loop time of 200ms. Mathematically rotating a single live image isnt practical. Also, during rotation of a png Labview loses the transparent component, the png image then shows the true file shape (see png totate.png).

My strategy now involves rotating the origonal png image 1 degree each time and saving it unitl 360 images have been created. I can then load all of the images into an FGV shift register when the program starts and simply read a shift register image as required. I noted this takes 1 - 2 ms per loop so a big improvement over sin/cos rotation.

The main issue with the process is the huge number of files involved and tweaks which will mean recreating the 360 images. It would be a great help if someone out there knows how to fix the png invisible layer issue. Then I only need one image and could rotate shift register store the 360 images at program startup.

Advice appreciated

Chris


Download All
0 Kudos
Message 1 of 4
(7,615 Views)

Regarding the poor quality text after rotation: You need to use a high resolution source image, rotate it, then shrink it to size. This will result in a better quality image.

Regarding png transparency: you can create and apply a mask to the image. Check here.

Regarding quick method to change between rotations: you could load all the images into a picture ring and use the rotation value to select which one to display.

Troy - CLD "If a hammer is the only tool you have, everything starts to look like a nail." ~ Maslow/Kaplan - Law of the instrument
0 Kudos
Message 2 of 4
(3,859 Views)

I don't have your source code so I can't comment on your implementation of the rotation algorithm, so I'll just throw these at you in case they help:

http://www.datagenetics.com/blog/august32013/index.html

http://www.datagenetics.com/blog/december32013/index.html

You shouldn't have to create 360 static images for this task.

Message 3 of 4
(3,859 Views)

Hello TroyK & David,

Excellent suggestions in both cases. Both raise interesting point. I managed to find a library with many graphics functions which I have now integrated with my code so have a fairly good fix. Although the code is written using object oriented... however I hadnt spotted the nice code snippet pointed by TroyK, it may be worth replacing the entire library with this snippet.

My lack of graphics knowledge hasnt helped so the link by David are usefull, thanks

A colleague has been working on the graphics images and he found that by exporting to PDF then saving to jpg to get the lossy (smooth) edges then export to png with invisible background I can achieve a far higher quality image. I think the pdf generates the high quality source TroyK was describing. I also think that AutoCAD exports a low quality png

Picture attached and thanksclean compass.png

Regards

Chris

0 Kudos
Message 4 of 4
(3,859 Views)