getVWorldToImagePlate wrong on first canvas display

Hi,

I have a piece of code that puts a Canvas3D in a panel, and this one in a tabbed pane. The Java3D tab is not the one displayed when data is loaded, so to view the scene, tha user has to select the preview tab.

The preview panel as i call it, draws a series of polylines, each one having a text label beside its first point. As I want these texts to be sized so they are allways the same size in screen, I placed a TransformGroup with a scale Transform3D as parent of each text shape, to control its size.

To calculate the scale I use getLocaleToVWorld and getvWorldToImagePlate combined, to get to know the size of the text on screen, and having this, calculate a scale to turn it to be a constant value (say 1cm). When some change is made to the scene contents I recalculate the scale and update all transforms of the text shapes.

This works fine when some update occurs, but when I first select the preview tab and the Canvas3D is thus first displayed, the scale I get makes the texts very little. If right afterwards I make any change that forces to update the scale, I get one that makes the texts the right size.

The following is a secuence of scale calculations of my program, that show how the first scale greatly reduces the size, and the next one, which is forced by me on the setVisible method of the panel and provoked by selecting other tab and then again the preview tab, grows it to be the desired size:

// The calculated scale when data is loaded and the canvas is not visible

Image plate distance = 0.5301327278190269

Text scale = 0.028294800929778853

Previous scale = 1.0

Resulting scale = 0.028294800929778853

// The one calculated the first time it's made visible

Image plate distance = 0.0014393333718180712

Text scale = 10.42149115256946

Previous scale = 0.028294800929778853

Resulting scale = 0.2948740175534045

// The one when hidden and made visible again

Image plate distance = 0.014999999999999942

Text scale = 1.0000000000000038

Previous scale = 0.2948740175534045

Resulting scale = 0.2948740175534056

Regards

[2174 byte] By [Juan_Alvarez_Ferrandoa] at [2007-10-2 6:12:47]
# 1

For the sake of others, this is what Mark Hood kindly answered at the java.net Java Desktop forum:

"There's an interaction with the AWT event listener thread and Java 3D

that introduces a 1-frame latency between the current state of the

Canvas3D and what its getVWorldToImagePlate method returns. The first

value is some bogus thing based on the default screen size. You don't

get the correct value until the second event after whatever AWT event

happened when initially making them visible (and if the next events

are canvas moves or resizes, you don't catch up).

Calling getVworldToImagePlate multiple times doesn't help since it

just returns the internal Java 3D cached value, which won't change

until either the next AWT event involving the canvas is processed or

something which affects the view is performed. Does it help to make a

trivial change to the view, like translating the view platform a small

amount?

com.sun.j3d.utils.universe.ViewInfo.getVworldToImagePlate() computes

the transform independently of the internal Java 3D view state --

directly from the API state instead -- so it avoids that latency. You

might want to give that a try instead of the core Canvas3D version.

You can call the ViewInfo canvas update method directly from an AWT

canvas listener and then get the correct value of vworldToImagePlate

based on the current canvas configuration.

-- Mark"

Juan_Alvarez_Ferrandoa at 2007-7-16 13:14:12 > top of Java-index,Security,Cryptography...
# 2

Hi,

I finally had it solved by the invaluable help of Mark Hood.

With his last tips I could solve the problem by both applying his recommendation of geting the transform from ViewInfo, and also by listening to my panel AWT events by implementing a ControlListener, and having my calculations done at the show or resize events.

Regards

Juan_Alvarez_Ferrandoa at 2007-7-16 13:14:12 > top of Java-index,Security,Cryptography...