Showing 3D surface using ViasAd
Code: "visad6_3D_surface_func.java". Programming language: Java
DMelt Version 1.9. Last modified: 07/03/1971. License: Free
https://datamelt.org/code/cache/visad6_3D_surface_func_1282.java
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
import visad.*;
import visad.java3d.DisplayImplJ3D;
import java.rmi.RemoteException;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class visad6_3D_surface_func{
private RealType longitude, latitude;
private RealType altitude, temperature, precipitation;
private RealTupleType domain_tuple, range_tuple;
private FunctionType func_domain_range;
private Set domain_set;
private FlatField vals_ff;
private DataReferenceImpl data_ref;
private DisplayImpl display;
private ScalarMap latMap, lonMap;
private ScalarMap altZMap, tempRGBMap;
private ScalarMap tempZMap, altRGBMap;
public visad6_3D_surface_func(String []args)
throws RemoteException, VisADException {
latitude = RealType.getRealType("latitude",SI.meter,null);
longitude = RealType.getRealType("longitude",SI.meter,null);
domain_tuple = new RealTupleType(latitude, longitude);
temperature = RealType.getRealType("temperature",SI.kelvin,null);
altitude = RealType.getRealType("altitude",SI.meter,null);
range_tuple = new RealTupleType( altitude, temperature );
func_domain_range = new FunctionType( domain_tuple, range_tuple);
int NCOLS = 100;
int NROWS = NCOLS;
domain_set = new Linear2DSet(domain_tuple, -Math.PI, Math.PI, NROWS,
-Math.PI, Math.PI, NCOLS);
float[][] set_samples = domain_set.getSamples( true );
float[][] flat_samples = new float[2][NCOLS * NROWS];
for(int c = 0; c < NCOLS; c++)
for(int r = 0; r < NROWS; r++){
flat_samples[0][ c * NROWS + r ] = 01.0f / (float)( (set_samples[0][ c * NROWS + r ] *
set_samples[0][ c * NROWS + r ]) +
(set_samples[1][ c * NROWS + r ] *
set_samples[1][ c * NROWS + r ]) + 1.0f );
flat_samples[1][ c * NROWS + r ] = (float)( (Math.sin( 0.50*(double) set_samples[0][ c * NROWS + r ]) ) * Math.cos( (double) set_samples[1][ c * NROWS + r ] ) ) ;
}
vals_ff = new FlatField( func_domain_range, domain_set);
vals_ff.setSamples( flat_samples , false );
display = new DisplayImplJ3D("display1");
GraphicsModeControl dispGMC = (GraphicsModeControl) display.getGraphicsModeControl();
dispGMC.setScaleEnable(true);
latMap = new ScalarMap( latitude, Display.YAxis );
lonMap = new ScalarMap( longitude, Display.XAxis );
display.addMap( latMap );
display.addMap( lonMap );
altZMap = new ScalarMap( altitude, Display.ZAxis );
tempRGBMap = new ScalarMap( temperature, Display.RGB );
display.addMap( altZMap );
display.addMap( tempRGBMap );
data_ref = new DataReferenceImpl("data_ref");
data_ref.setData( vals_ff );
display.addReference( data_ref );
JFrame jframe = new JFrame("VisAD");
jframe.getContentPane().add(display.getComponent());
jframe.setSize(600, 600);
jframe.setVisible(true);
}
public static void main(String[] args)
throws RemoteException, VisADException
{
new visad6_3D_surface_func(args);
}
}