https://handwiki.org/wiki/index.php?title=DMelt:Plots/VisAd&feed=atom&action=historyDMelt:Plots/VisAd - Revision history2024-03-29T05:29:10ZRevision history for this page on the wikiMediaWiki 1.38.4https://handwiki.org/wiki/index.php?title=DMelt:Plots/VisAd&diff=306&oldid=previmported>Jworkorg at 16:13, 14 February 20212021-02-14T16:13:39Z<p></p>
<p><b>New page</b></p><div><br />
{{sidebar box|[[DMelt:Start|Table of contents]]}}<br />
<br />
<br />
== VisAd ==<br />
<br />
DataMelt includes VisAd, which was destined by programmers at the University of Wisconsin Space Science and Engineering Center (SSEC).<br />
We reproduce its guide in [[DMelt:ExternalGuides/VisAd | VisAd guide section]]<br />
<br />
The Java API is given by <javadoc>visad/package-summary|visad package</javadoc>. <br />
<br />
== VisAd tutorial ==<br />
<br />
Here is a short tutorial how to visualize numerical information using interactive canvas called <javadoc>jhplot.HVisAd</javadoc>.<br />
We will show step-by step example, starting from elementary operation, such as opening the canvas and creating a 3D scene.<br />
<br />
<jcode lang="python"><br />
from jhplot import *<br />
from java.awt import *<br />
c1 = HVisAd("VisAd",600,600) # make 600x600 canvas<br />
display = c1.getDisplay() # get display<br />
ren=c1.getRender() # get display render<br />
ren.setBoxOn(True) # draw a box<br />
ren.setBackgroundColor(Color.white) # make it white<br />
c1.visible() # show it<br />
</jcode><br />
<br />
Next, we will try to manipulate with the box. For example, we can zooming (or zoom out), move it and rotate:<br />
<br />
<jcode lang="python"><br />
from jhplot import *<br />
c1 = HVisAd("VisAd",600,600)<br />
ren=c1.getRender()<br />
ren.setBoxOn(True)<br />
c1.setScaling(0.8)<br />
c1.setRotation(0,20,0) # rotation around Y in 20 deg <br />
c1.setTranslation(0.1,0.0,0.0) # shift in X by 10% <br />
c1.visible() # show it <br />
</jcode><br />
<br />
You can use full Java API of VisAd to archive scaling and rotations using the "ProjectionControl" method:<br />
<br />
<ifauth !@member><br />
<jcode lang="python"><br />
from jhplot import *<br />
from java.awt import *<br />
c1 = HVisAd("test",600,500)<br />
display = c1.getDisplay()<br />
ren=c1.getRender()<br />
proj = ren.getDisplay().getProjectionControl();<br />
mouseBehavior = ren.getMouseBehavior()<br />
tstart = proj.getMatrix()<br />
scale=0.5<br />
t1 = mouseBehavior.make_matrix(0.0, 0.0, 0.0, scale, 0.0, 0.0, 0.0)<br />
t1 = mouseBehavior.multiply_matrix(t1, tstart)<br />
proj.setMatrix(t1)<br />
ren.setBoxOn( True )<br />
c1.visible() # show canvas <br />
</jcode><br />
</ifauth><br />
<br />
So far we had just a box. Now we can draw axises. Here is an example how to set axis, define their ranges <br />
<br />
<jcode lang="python"><br />
from jhplot import *<br />
c1 = HVisAd("VisAd")<br />
display=c1.getDisplay()<br />
cont=display.getGraphicsModeControl()<br />
cont.setSceneAntialiasingEnable(True)<br />
cont.setLineWidth(1)<br />
ren=c1.getRender(); ren.setBoxOn(True) # draw a box <br />
c1.setAxes("X",0,10,"Y",0,10,"Z",0,10)<br />
c1.visible() # show canvas <br />
</jcode><br />
The method setAxes() takes the name of the axis, min and max value for X,Y,Z axis.<br />
Here is a more refined example that shows how to make custom frame with axis:<br />
<br />
<ifauth !@member><br />
<jcode lang="python"><br />
from jhplot import *<br />
from java.awt import Font<br />
from visad import Display,ScalarMap,RealType<br />
<br />
c1 = HVisAd("VisAd",600,600)<br />
display=c1.getDisplay()<br />
cont=display.getGraphicsModeControl()<br />
cont.setSceneAntialiasingEnable(True)<br />
cont.setLineWidth(2)<br />
ren=c1.getRender(); ren.setBoxOn(True) # draw a box <br />
<br />
x=RealType("x"); y=RealType("y"); z=RealType("z") # make X,Y,Z axis<br />
rX = ScalarMap(x,Display.XAxis)<br />
rY = ScalarMap(y,Display.YAxis)<br />
rZ = ScalarMap(z,Display.ZAxis)<br />
<br />
rX.setScalarName("X axis")<br />
rY.setScalarName("Y axis")<br />
rZ.setScalarName("Z axis")<br />
<br />
col=[0.1, 0.1, 0.1] # change color <br />
rX.setScaleColor(col)<br />
rY.setScaleColor(col)<br />
rZ.setScaleColor(col)<br />
<br />
# set min and max ranges<br />
rX.setRange(0,10)<br />
rY.setRange(0,20)<br />
rZ.setRange(0,100)<br />
<br />
axisX=rX.getAxisScale() # this is visad.AxisScale object<br />
axisX.setFont(Font("Arial", Font.BOLD, 16))<br />
axisX.setLabelSize(16)<br />
axisX.setGridLinesVisible(True)<br />
<br />
# attach to the box? <br />
# axisX.setSnapToBox(True) <br />
# axisX.setLabelBothSides(True)<br />
<br />
display.addMap( rX )<br />
display.addMap( rY )<br />
display.addMap( rZ )<br />
<br />
c1.visible() # show canvas <br />
</jcode><br />
</ifauth><br />
<br />
<br />
== VisAd code examples ==<br />
{{ambox | text=[https://datamelt.org/code/index.php?keyword=visad VisAd code examples in Java and Jython]}}<br />
<br />
== Using full VisAd Java api ==<br />
<br />
Here is a Jython macro which shows ho to visualize 2D data calling Java classes directly:<br />
<br />
<ifauth !@member><br />
<jcode lang="python"><br />
dmelt 47000497.py<br />
</jcode><br />
</ifauth></div>imported>Jworkorg