//
// TextureFillRendererJ3D.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.bom;
import visad.*;
import visad.java3d.*;
import javax.media.j3d.*;
import java.rmi.*;
import java.io.IOException;
import java.awt.event.*;
import javax.swing.*;
/**
TextureFillRendererJ3D is the VisAD class for rendering Sets (usually
Irregular2DSets) filled with a cross hatch pattern via texture mapping
*/
public class TextureFillRendererJ3D extends DefaultRendererJ3D {
// MathTypes that data must equalsExceptNames()
private static MathType set_type;
// initialize above MathType
static {
try {
set_type = MathType.stringToType("Set(X, Y)");
}
catch (VisADException e) {
throw new VisADError(e.getMessage());
}
}
// texture pattern will repeat 2 * scale times across box
private float scale = 10.0f;
// texture data defining repeating pattern
private int texture_width = 0;
private int texture_height = 0;
private int[] texture = null;
// true for smooth texture
private boolean smooth = false;
/** texture pattern will repreat 2 * s times across box */
public void setScale(float s) {
scale = s;
}
public float getScale() {
return scale;
}
/** define texture pattern as a w * h rectangle of ints (RGB values);
note w and h must be powers of 2, and t.length must be w * h */
public void setTexture(int w, int h, int[] t) throws VisADException {
int ww = 1;
while (ww < w) ww *= 2;
int hh = 1;
while (hh < h) hh *= 2;
if (ww != w || hh != h || t == null || t.length != w * h) {
throw new VisADException("bad params");
}
texture_width = w;
texture_height = h;
texture = t;
}
public int getTextureWidth() {
return texture_width;
}
public int getTextureHeight() {
return texture_height;
}
public int[] getTexture() {
return texture;
}
/** set s = true to smooth texture */
public void setSmooth(boolean s) {
smooth = s;
}
public boolean getSmooth() {
return smooth;
}
/** determine whether the given MathType is usable with TextureFillRendererJ3D */
public static boolean isSetType(MathType type) {
return (set_type.equalsExceptName(type));
}
/** determine whether the given MathType and collection of ScalarMaps
meets the criteria to use TextureFillRendererJ3D. Throw a VisADException
if ImageRenderer cannot be used, otherwise return true. */
public static boolean isRendererUsable(MathType type, ScalarMap[] maps)
throws VisADException
{
RealTupleType domain = null;
RealType x = null, y = null;
RealType rx = null, ry = null;
// must be a function
if (!(type instanceof SetType)) {
throw new VisADException("Not a SetType");
}
SetType set = (SetType) type;
domain = set.getDomain();
// extract x and y from domain
x = (RealType) domain.getComponent(0);
y = (RealType) domain.getComponent(1);
// WLH 19 July 2000
CoordinateSystem cs = domain.getCoordinateSystem();
if (cs != null) {
RealTupleType rxy = cs.getReference();
rx = (RealType) rxy.getComponent(0);
ry = (RealType) rxy.getComponent(1);
}
// verify that collection of ScalarMaps is legal
boolean bx = false, by = false;
boolean brx = false, bry = false; // WLH 19 July 2000
Boolean latlon = null;
DisplayRealType spatial = null;
for (int i=0; i 0) );
display.addReferences(renderer, set_ref);
// create JFrame (i.e., a window) for display and slider
JFrame frame = new JFrame("TextureFillRendererJ3D test");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
// create JPanel in JFrame
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setAlignmentY(JPanel.TOP_ALIGNMENT);
panel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
frame.getContentPane().add(panel);
// add display to JPanel
panel.add(display.getComponent());
// set size of JFrame and make it visible
frame.setSize(500, 500);
frame.setVisible(true);
}
}
Ads help maintain this website.