//
// Gifts.java
//
/*
VisAD system for interactive analysis and visualization of numerical
data. Copyright (C) 1996 - 2017 Bill Hibbard, Curtis Rueden, Tom
Rink, Dave Glowacki, Steve Emmerson, Tom Whittaker, Don Murray, and
Tommy Jasmin.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA
*/
package visad.gifts;
import visad.*;
import visad.java3d.DisplayImplJ3D;
import visad.java2d.DisplayImplJ2D;
import visad.data.mcidas.BaseMapAdapter;
import visad.data.mcidas.AreaForm;
import visad.bom.WindPolarCoordinateSystem;
import visad.bom.BarbRendererJ2D;
import visad.util.SelectRangeWidget;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.rmi.*;
import java.io.*;
public class Gifts
implements ItemListener, ScalarMapListener
{
// brightness of AREA image
private static final int BRIGHT = 3;
String filename = null;
DataImpl data;
MathType type;
MathType range;
Set domainSet = null;
MathType R_type;
MathType D_type;
RealType xaxis = null;
RealType yaxis = null;
RealType zaxis = null;
RealType flowx;
RealType flowy;
EarthVectorType flowxy = null;
RealType flow_degree;
RealType flow_speed;
RealTupleType domain;
RealTupleType reference;
CoordinateSystem coord_sys;
FunctionType f_type;
DisplayImpl display;
DisplayImpl display2;
float lonmin, lonmax;
float latmin, latmax;
double[] x_range;
double[] y_range;
double[][] dir_spd = new double[2][];
double[][] uv = new double[2][];
boolean slice3d = true;
ConstantMap[] map_constMap, map_constMap2, img_constMap, rect_constMap;
ConstantMap[][] wnd_constMap, clone_wnd_constMap;
DataReference maplines_ref, rect_ref;
DataReference[] winds_ref;
DataReference[] clone_winds_ref;
DataReference image_ref;
ScalarMap xmap1, xmap2, xmap3;
ScalarMap ymap1, ymap2, ymap3;
ScalarMap zmap, zmap2;
ScalarMap flowx_map, flowx_map2;
ScalarMap flowy_map, flowy_map2;
ScalarMap sel_map, rgb_map, slice_map;
boolean xmapEvent = false;
boolean ymapEvent = false;
boolean firstEvent = false;
BaseMapAdapter baseMap;
JCheckBox multi_color;
public static void main(String[] args)
throws VisADException, RemoteException, IOException
{
Gifts gifts = new Gifts(args); // WLH
}
public Gifts(String[] args) // WLH
throws VisADException, RemoteException, IOException
{
if (args.length > 0) slice3d = false; // WLH
flowx = new RealType("flowx", CommonUnit.meterPerSecond, null);
flowy = new RealType("flowy", CommonUnit.meterPerSecond, null);
flow_degree = new RealType("flow_degree", CommonUnit.degree, null);
flow_speed = new RealType("flow_speed", CommonUnit.meterPerSecond, null);
maplines_ref = new DataReferenceImpl("maplines");
image_ref = new DataReferenceImpl("image_ref");
/**------ main gui panel ------*/
Border etchedBorder =
new CompoundBorder(new EtchedBorder(),
new EmptyBorder(5, 5, 5, 5));
JFrame frame = new JFrame("Gifts");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
JPanel big_panel = new JPanel();
big_panel.setLayout(new BoxLayout(big_panel, BoxLayout.X_AXIS));
big_panel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
/**------ File I/O, data initialization -------*/
baseMap = new BaseMapAdapter("./data/OUTLHRES");
if ( baseMap.isEastPositive() )
{
baseMap.setEastPositive(true);
}
/**------ Get wind data ----*/
TextForm form = new TextForm(false, "lon", "lat");
String[][] filenames = { { "./data/REALGI250",
"./data/REALGI300",
"./data/REALGI350",
"./data/REALGI400",
"./data/REALGI430",
"./data/REALGI475",
"./data/REALGI500",
"./data/REALGI570",
"./data/REALGI620",
"./data/REALGI670",
"./data/REALGI700",
"./data/REALGI780",
"./data/REALGI850",
"./data/REALGI920",
"./data/REALGI950",
"./data/REALGI1000" },
{ "./data/REALGR250",
"./data/REALGR300",
"./data/REALGR350",
"./data/REALGR400",
"./data/REALGR430",
"./data/REALGR475",
"./data/REALGR500",
"./data/REALGR570",
"./data/REALGR620",
"./data/REALGR670",
"./data/REALGR700",
"./data/REALGR780",
"./data/REALGR850",
"./data/REALGR920",
"./data/REALGR950",
"./data/REALGR1000" },
{ "./data/TRUTH250",
"./data/TRUTH300",
"./data/TRUTH350",
"./data/TRUTH400",
"./data/TRUTH430",
"./data/TRUTH475",
"./data/TRUTH500",
"./data/TRUTH570",
"./data/TRUTH620",
"./data/TRUTH670",
"./data/TRUTH700",
"./data/TRUTH780",
"./data/TRUTH850",
"./data/TRUTH920",
"./data/TRUTH950",
"./data/TRUTH1000" } };
DataImpl[] winds = getWinds(filenames, form);
int len = winds.length;
winds_ref = new DataReference[len];
for (int i=0; i= 0) {
display.addReference(winds_ref[i], wnd_constMap[i]);
if ( !slice3d ) {
display2.addReferences(new BarbRendererJ2D(), clone_winds_ref[i],
clone_wnd_constMap[i]);
}
else {
display2.addReference(clone_winds_ref[i], clone_wnd_constMap[i]);
display2.addReference(maplines_ref, map_constMap2);
}
}
}
catch (VisADException exc) { /* CTR: TEMP */ exc.printStackTrace(); }
catch (RemoteException exc) { /* CTR: TEMP */ exc.printStackTrace(); }
}
else if (multi_color.isSelected()) {
// turn off multi-color display first
multi_color.setSelected(false);
}
int i = -1;
if (text.equals("GIFTS")) {
i = 0;
gifts_checked = checked;
}
else if (text.equals("GOES")) {
i = 1;
goes_checked = checked;
}
else if (text.equals("TRUTH")) {
i = 2;
truth_checked = checked;
}
if (i >= 0) {
try {
if (checked) {
display.addReference(winds_ref[i], wnd_constMap[i]);
if ( !slice3d ) {
display2.addReferences(new BarbRendererJ2D(), clone_winds_ref[i],
clone_wnd_constMap[i]);
}
else {
display2.addReference(clone_winds_ref[i], clone_wnd_constMap[i]);
}
numSelected++;
}
else {
display.removeReference(winds_ref[i]);
display2.removeReference(clone_winds_ref[i]);
numSelected--;
}
}
catch (VisADException exc) { /* CTR: TEMP */ exc.printStackTrace(); }
catch (RemoteException exc) { /* CTR: TEMP */ exc.printStackTrace(); }
multi_color.setEnabled(numSelected == 1);
}
}
public void mapChanged(ScalarMapEvent e)
throws VisADException, RemoteException
{
if ( xmap1.equals(e.getScalarMap()) ) {
xmapEvent = true;
}
else if ( ymap1.equals(e.getScalarMap()) ) {
ymapEvent = true;
}
if (( xmapEvent && ymapEvent ) && !(firstEvent) ) {
x_range = xmap1.getRange();
y_range = ymap1.getRange();
latmin = (float)y_range[0];
latmax = (float)y_range[1];
lonmin = (float)x_range[0];
lonmax = (float)x_range[1];
baseMap.setLatLonLimits(latmin, latmax, lonmin, lonmax);
DataImpl map = baseMap.getData();
maplines_ref.setData(map);
firstEvent = true;
}
}
public void controlChanged(ScalarMapControlEvent e) { }
DataImpl[] cloneWinds(DataImpl[] winds)
throws VisADException, RemoteException
{
int n_groups = winds.length;
DataImpl[] cloned_winds = new DataImpl[n_groups];
RealType Latitude_winds = new RealType("Latitude_winds",
CommonUnit.degree, null);
RealType Longitude_winds = new RealType("Longitude_winds",
CommonUnit.degree, null);
for (int g=0; g
Ads help maintain this website.