//
// ShadowFunctionOrSetType.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
*/
/*
MEM - memory use reduction strategy:
changes marked by MEM_WLH
1. if (isTexture) no assembleSpatial NOT NEEDED
but if (isTexture) then domain_values = null,
so spatial display_values[i] = null so assembleSpatial
does nothing (except construct a SingletonSet spatial_set)
2. byte[][] assembleColor DONE
this has a bad space / time tradeoff in makeIso*,
so create a boolean in GMC to choose between
(Irregular3DSet, Gridded3DSet) and their slower extensions
3. after use, set display_values[i] = null; DONE
done in many ShadowType.assemble* - marked by MEM_WLH
4. don't fill arrays that won't get used
are there any of these ??
5. replace getValues() by getFloats(false)
already done for getSamples
6. assembleColors first DONE
7. boolean[] range_select
8. in-line byteToFloat and floatToByte DONE
VisADCanvasJ2D, Gridded3DSet, Irregular3DSet
N. iso-surface computation uses:
Irregular3DSet.makeIsosurface:
float[len] fieldValues
float[3 or 4][len] auxValues (color_values)
float[3][nvertex] fieldVertices
float[3 or 4][nvertex] auxLevels
int[1][npolygons][3 or 4] polyToVert
int[1][nvertex][nverts[i]] vertToPoly
int[Delan.Tri.length][4] polys
int[Delan.NumEdges] globalToVertex
float[DomainDimension][Delan.NumEdges] edgeInterp
float[3 or 4][Delan.NumEdges] auxInterp
Gridded3DSet.makeIsoSurface:
start with nvertex_estimate = 4 * npolygons + 100
int[num_cubes] ptFLAG
int[xdim_x_ydim_x_zdim] ptAUX
int[num_cubes+1] pcube
float[1][4 * npolygons] VX
float[1][4 * npolygons] VY
float[1][4 * npolygons] VZ
float[3 or 4][nvet] color_temps
float[3 or 4][len] cfloat
int[7 * npolygons] Vert_f_Pol
int[1][36 * npolygons] Pol_f_Vert
number of bytes = 268 (or 284) * npolygons +
24 (or 28) * len
isosurf:
float[3][len] samples
float[3 or 4][nvertex_estimate] tempaux
number of bytes = 48 (or 64) * npolygons +
12 * len
float[npolygons] NxA, NxB, NyA, NyB, NzA, NzB
float[npolygons] Pnx, Pny, Pnz
float[nvertex] NX, NY, NZ
number of bytes = 84 * npolygons
make_normals:
none
total number of bytes = 36 (or 40) * len +
400 (to 432) * npolygons
so if len = 0.5M and npolygons = 0.1M
bytes = 20M + 43.2M = 63.2M
*/
package visad;
import java.awt.color.*;
import java.awt.image.*;
import java.rmi.*;
import java.text.*;
import java.util.*;
/**
The ShadowFunctionOrSetType class is an abstract parent for
classes that implement ShadowFunctionType or ShadowSetType.
*/
public abstract class ShadowFunctionOrSetType extends ShadowType {
ShadowRealTupleType Domain;
ShadowType Range; // null for ShadowSetType
/** RangeComponents is an array of ShadowRealType-s that are
ShadowRealType components of Range or ShadowRealType
components of ShadowRealTupleType components of Range;
a non-ShadowRealType and non-ShadowTupleType Range is marked
by null;
components of a ShadowTupleType Range that are neither
ShadowRealType nor ShadowRealTupleType are ignored */
ShadowRealType[] RangeComponents; // null for ShadowSetType
ShadowRealType[] DomainComponents;
ShadowRealType[] DomainReferenceComponents;
/** true if range is ShadowRealType or Flat ShadowTupleType
not the same as FunctionType.Flat;
also true for ShadowSetType */
boolean Flat;
/** value_indices from parent */
int[] inherited_values;
/** this constructor is a bit of a kludge to get around
single inheritance problems */
public ShadowFunctionOrSetType(MathType t, DataDisplayLink link, ShadowType parent,
ShadowRealTupleType domain, ShadowType range)
throws VisADException, RemoteException {
super(t, link, parent);
Domain = domain;
Range = range;
if (this instanceof ShadowFunctionType) {
Flat = (Range instanceof ShadowRealType) ||
(Range instanceof ShadowTextType) ||
(Range instanceof ShadowTupleType &&
((ShadowTupleType) Range).isFlat());
MultipleSpatialDisplayScalar = Domain.getMultipleSpatialDisplayScalar() ||
Range.getMultipleSpatialDisplayScalar();
MultipleDisplayScalar = Domain.getMultipleDisplayScalar() ||
Range.getMultipleDisplayScalar();
MappedDisplayScalar = Domain.getMappedDisplayScalar() ||
Range.getMappedDisplayScalar();
RangeComponents = getComponents(Range, true);
}
else if (this instanceof ShadowSetType) {
Flat = true;
MultipleDisplayScalar = Domain.getMultipleDisplayScalar();
MappedDisplayScalar = Domain.getMappedDisplayScalar();
RangeComponents = null;
}
else {
throw new DisplayException("ShadowFunctionOrSetType: must be " +
"ShadowFunctionType or ShadowSetType");
}
DomainComponents = getComponents(Domain, false);
DomainReferenceComponents = getComponents(Domain.getReference(), false);
}
public boolean getFlat() {
return Flat;
}
public ShadowRealType[] getRangeComponents() {
return RangeComponents;
}
public ShadowRealType[] getDomainComponents() {
return DomainComponents;
}
public ShadowRealType[] getDomainReferenceComponents() {
return DomainReferenceComponents;
}
/** used by FlatField.computeRanges */
int[] getRangeDisplayIndices() throws VisADException {
if (!(this instanceof ShadowFunctionType)) {
throw new DisplayException("ShadowFunctionOrSetType.getRangeDisplay" +
"Indices: must be ShadowFunctionType");
}
int n = RangeComponents.length;
int[] indices = new int[n];
for (int i=0; i 0) {
throw new BadMappingException("Animation and SelectValue may only occur " +
"in 1-D Function domain: " +
"ShadowFunctionOrSetType.checkIndices");
}
else {
// eventually ShadowType.testTransform is used to mark Animation,
// Value or Range as isTransform when multiple occur in Domain;
// however, temporary hack in Renderer.isTransformControl requires
// multiple occurence of Animation and Value to throw an Exception
if (avCount > 1) {
throw new BadMappingException("only one Animation and SelectValue may " +
"occur Set domain: " +
"ShadowFunctionOrSetType.checkIndices");
}
}
}
if (Flat || this instanceof ShadowSetType) {
if (this instanceof ShadowFunctionType) {
if (Range instanceof ShadowTupleType) {
local_indices =
((ShadowTupleType) Range).sumIndices(local_indices);
local_display_indices =
((ShadowTupleType) Range).sumDisplayIndices(local_display_indices);
local_value_indices =
((ShadowTupleType) Range).sumValueIndices(local_value_indices);
}
else if (Range instanceof ShadowScalarType) {
((ShadowScalarType) Range).incrementIndices(local_indices);
local_display_indices = addIndices(local_display_indices,
((ShadowScalarType) Range).getDisplayIndices());
local_value_indices = addIndices(local_value_indices,
((ShadowScalarType) Range).getValueIndices());
}
// test legality of Animation and SelectValue in Range
if (checkAnimationOrValue(Range.getDisplayIndices()) > 0) {
throw new BadMappingException("Animation and SelectValue may not " +
"occur in Function range: " +
"ShadowFunctionOrSetType.checkIndices");
}
} // end if (this instanceof ShadowFunctionType)
anyContour = checkContour(local_display_indices);
anyFlow = checkFlow(local_display_indices);
anyShape = checkShape(local_display_indices);
anyText = checkText(local_display_indices);
LevelOfDifficulty =
testIndices(local_indices, local_display_indices, levelOfDifficulty);
/*
System.out.println("ShadowFunctionOrSetType.checkIndices 1:" +
" LevelOfDifficulty = " + LevelOfDifficulty +
" isTerminal = " + isTerminal +
" Type = " + Type.prettyString());
*/
// compute Domain type
if (!Domain.getMappedDisplayScalar()) {
Dtype = D0;
}
else if (Domain.getAllSpatial() && checkR4(Domain.getDisplayIndices())) {
Dtype = D1;
}
else if (checkR1D3(Domain.getDisplayIndices())) {
Dtype = D3;
}
else if (checkR2D2(Domain.getDisplayIndices())) {
Dtype = D2;
}
else if (checkAnimationOrValue(Domain.getDisplayIndices()) > 0) {
Dtype = D4;
}
else {
Dtype = Dbad;
}
if (this instanceof ShadowFunctionType) {
// compute Range type
if (!Range.getMappedDisplayScalar()) {
Rtype = R0;
}
else if (checkR1D3(Range.getDisplayIndices())) {
Rtype = R1;
}
else if (checkR2D2(Range.getDisplayIndices())) {
Rtype = R2;
}
else if (checkR3(Range.getDisplayIndices())) {
Rtype = R3;
}
else if (checkR4(Range.getDisplayIndices())) {
Rtype = R4;
}
else {
Rtype = Rbad;
}
}
else { // this instanceof ShadowSetType
Rtype = R0; // implicit - Set has no range
}
if (LevelOfDifficulty == NESTED) {
if (Dtype != Dbad && Rtype != Rbad) {
if (Dtype == D4) {
LevelOfDifficulty = SIMPLE_ANIMATE_FIELD;
}
else {
LevelOfDifficulty = SIMPLE_FIELD;
}
}
else {
LevelOfDifficulty = LEGAL;
}
}
/*
System.out.println("ShadowFunctionOrSetType.checkIndices 2:" +
" LevelOfDifficulty = " + LevelOfDifficulty +
" Dtype = " + Dtype + " Rtype = " + Rtype);
*/
adjustProjectionSeam = checkAdjustProjectionSeam();
if (this instanceof ShadowFunctionType) {
float[] default_values = getLink().getDefaultValues();
boolean textureEnabled =
default_values[display.getDisplayScalarIndex(Display.TextureEnable)] > 0.5f;
boolean pointMode =
default_values[
display.getDisplayScalarIndex(Display.PointMode)] > 0.5f;
// test for texture mapping
// WLH 30 April 99
isTextureMap = !getMultipleDisplayScalar() &&
getLevelOfDifficulty() == ShadowType.SIMPLE_FIELD &&
((FunctionType) getType()).getReal() && // ??
Domain.getDimension() == 2 &&
Domain.getAllSpatial() &&
!Domain.getSpatialReference() &&
Display.DisplaySpatialCartesianTuple.equals(
Domain.getDisplaySpatialTuple() ) &&
checkColorAlphaRange(Range.getDisplayIndices()) &&
checkAny(Range.getDisplayIndices()) &&
textureEnabled &&
//!display.getGraphicsModeControl().getPointMode();
!pointMode;
curvedTexture = getLevelOfDifficulty() == ShadowType.SIMPLE_FIELD &&
Domain.getAllSpatial() &&
checkSpatialOffsetColorAlphaRange(Domain.getDisplayIndices()) &&
checkSpatialOffsetColorAlphaRange(Range.getDisplayIndices()) &&
checkAny(Range.getDisplayIndices()) &&
//!display.getGraphicsModeControl().getPointMode();
!pointMode;
// WLH 15 March 2000
// isTexture3D = !getMultipleDisplayScalar() &&
isTexture3D = getLevelOfDifficulty() == ShadowType.SIMPLE_FIELD &&
((FunctionType) getType()).getReal() && // ??
Domain.getDimension() == 3 &&
Domain.getAllSpatial() &&
// WLH 1 April 2000
// !Domain.getMultipleDisplayScalar() && // WLH 15 March 2000
checkSpatialRange(Domain.getDisplayIndices()) && // WLH 1 April 2000
!Domain.getSpatialReference() &&
Display.DisplaySpatialCartesianTuple.equals(
Domain.getDisplaySpatialTuple() ) &&
checkColorAlphaRange(Range.getDisplayIndices()) &&
checkAny(Range.getDisplayIndices()) &&
textureEnabled &&
//!display.getGraphicsModeControl().getPointMode();
!pointMode;
// note GgraphicsModeControl.setTextureEnable(false) disables this
isLinearContour3D =
getLevelOfDifficulty() == ShadowType.SIMPLE_FIELD &&
((FunctionType) getType()).getReal() && // ??
Domain.getDimension() == 3 &&
Domain.getAllSpatial() &&
!Domain.getMultipleDisplayScalar() &&
!Domain.getSpatialReference() &&
Display.DisplaySpatialCartesianTuple.equals(
Domain.getDisplaySpatialTuple() ) &&
checkContourColorAlphaRange(Range.getDisplayIndices()) &&
checkContour(Range.getDisplayIndices());
/*
System.out.println("checkIndices.isTexture3D = " + isTexture3D + " " +
(getLevelOfDifficulty() == ShadowType.SIMPLE_FIELD) + " " +
((FunctionType) getType()).getReal() + " " +
(Domain.getDimension() == 3) + " " +
Domain.getAllSpatial() + " " +
checkSpatialRange(Domain.getDisplayIndices()) + " " +
!Domain.getSpatialReference() + " " +
Display.DisplaySpatialCartesianTuple.equals(
Domain.getDisplaySpatialTuple() ) + " " +
checkColorAlphaRange(Range.getDisplayIndices()) + " " +
checkAny(Range.getDisplayIndices()) + " " +
textureEnabled &&
//!display.getGraphicsModeControl().getPointMode() );
!pointMode;
*/
/*
System.out.println("checkIndices.isTextureMap = " + isTextureMap + " " +
!getMultipleDisplayScalar() + " " +
(getLevelOfDifficulty() == ShadowType.SIMPLE_FIELD) + " " +
((FunctionType) getType()).getReal() + " " +
(Domain.getDimension() == 2) + " " +
Domain.getAllSpatial() + " " +
!Domain.getSpatialReference() + " " +
Display.DisplaySpatialCartesianTuple.equals(
Domain.getDisplaySpatialTuple() ) + " " +
checkColorAlphaRange(Range.getDisplayIndices()) + " " +
checkAny(Range.getDisplayIndices()) + " " +
textureEnabled &&
//!display.getGraphicsModeControl().getPointMode() );
!pointMode;
System.out.println("checkIndices.curvedTexture = " + curvedTexture + " " +
(getLevelOfDifficulty() == ShadowType.SIMPLE_FIELD) + " " +
(Domain.getDimension() == 2) + " " +
Domain.getAllSpatial() + " " +
checkSpatialOffsetColorAlphaRange(Domain.getDisplayIndices()) + " " +
checkSpatialOffsetColorAlphaRange(Range.getDisplayIndices()) + " " +
checkAny(Range.getDisplayIndices()) + " " +
textureEnabled &&
//!display.getGraphicsModeControl().getPointMode() );
!pointMode;
*/
}
}
else { // !Flat && this instanceof ShadowFunctionType
if (levelOfDifficulty == NESTED) {
if (!checkNested(Domain.getDisplayIndices())) {
levelOfDifficulty = LEGAL;
}
}
LevelOfDifficulty = Range.checkIndices(local_indices, local_display_indices,
local_value_indices, isTransform,
levelOfDifficulty);
/*
System.out.println("ShadowFunctionOrSetType.checkIndices 3:" +
" LevelOfDifficulty = " + LevelOfDifficulty);
*/
}
return LevelOfDifficulty;
}
public ShadowRealTupleType getDomain() {
return Domain;
}
public ShadowType getRange() {
return Range;
}
/** mark Control-s as needing re-Transform */
void markTransform(boolean[] isTransform) {
if (Range != null) Range.markTransform(isTransform);
}
/** transform data into a (Java3D or Java2D) scene graph;
add generated scene graph components as children of group;
group is Group (Java3D) or VisADGroup (Java2D);
value_array are inherited valueArray values;
default_values are defaults for each display.DisplayRealTypeVector;
return true if need post-process */
public boolean doTransform(Object group, Data data, float[] value_array,
float[] default_values, DataRenderer renderer,
ShadowType shadow_api)
throws VisADException, RemoteException {
visad.util.Trace.msg("ShadowFunctionOrSetType:"+data.getType());
// return if data is missing or no ScalarMaps
if (data.isMissing()) return false;
if (LevelOfDifficulty == NOTHING_MAPPED) return false;
// if transform has taken more than 500 milliseconds and there is
// a flag requesting re-transform, throw a DisplayInterruptException
DataDisplayLink link = renderer.getLink();
// if (link != null) System.out.println("\nstart doTransform " + (System.currentTimeMillis() - link.start_time));
if (link != null) {
boolean time_flag = false;
if (link.time_flag) {
time_flag = true;
}
else {
if (500 < System.currentTimeMillis() - link.start_time) {
link.time_flag = true;
time_flag = true;
}
}
if (time_flag) {
if (link.peekTicks()) {
throw new DisplayInterruptException("please wait . . .");
}
Enumeration maps = link.getSelectedMapVector().elements();
while(maps.hasMoreElements()) {
ScalarMap map = (ScalarMap) maps.nextElement();
if (map.peekTicks(renderer, link)) {
throw new DisplayInterruptException("please wait . . .");
}
}
}
} // end if (link != null)
// get 'shape' flags
boolean anyContour = getAnyContour();
boolean anyFlow = getAnyFlow();
boolean anyShape = getAnyShape();
boolean anyText = getAnyText();
boolean indexed = shadow_api.wantIndexed();
// get some precomputed values useful for transform
// length of ValueArray
int valueArrayLength = display.getValueArrayLength();
// mapping from ValueArray to DisplayScalar
int[] valueToScalar = display.getValueToScalar();
// mapping from ValueArray to MapVector
int[] valueToMap = display.getValueToMap();
Vector MapVector = display.getMapVector();
// array to hold values for various mappings
float[][] display_values = new float[valueArrayLength][];
// get values inherited from parent;
// assume these do not include SelectRange, SelectValue
// or Animation values - see temporary hack in
// DataRenderer.isTransformControl
for (int i=0; i 0) {
display_values[i] = new float[1];
display_values[i][0] = value_array[i];
}
}
// check for only contours and only disabled contours
if (getIsTerminal() && anyContour &&
!anyFlow && !anyShape && !anyText) { // WLH 13 March 99
boolean any_enabled = false;
for (int i=0; i 0.99 &&
renderer.isLegalTextureMap() &&
(domain_set instanceof Linear2DSet ||
(domain_set instanceof LinearNDSet &&
domain_set.getDimension() == 2));
// DRM 2003-08-21
//int curved_size = display.getGraphicsModeControl().getCurvedSize();
int curved_size = (int)
default_values[display.getDisplayScalarIndex(Display.CurvedSize)];
/* DRM 2005-08-29 - default value now correct in link.prepareData()
int curved_size =
(cMapCurveSize > 0)
? cMapCurveSize
: display.getGraphicsModeControl().getCurvedSize();
*/
float textureEnable =
default_values[display.getDisplayScalarIndex(Display.TextureEnable)];
boolean texture = textureEnable > 0.5f;
/* DRM 2005-08-29 - default value now correct in link.prepareData()
boolean texture = display.getGraphicsModeControl().getTextureEnable();
if (textureEnable > -0.5f) {
texture = (textureEnable > 0.5f);
}
*/
boolean curvedTexture = getCurvedTexture() &&
!isTextureMap &&
texture &&
curved_size > 0 &&
getIsTerminal() && // implied by getCurvedTexture()?
shadow_api.allowCurvedTexture() &&
//default_values[alpha_index] > 0.99 &&
renderer.isLegalTextureMap() &&
domain_set.getManifoldDimension() == 2 &&
domain_set instanceof GriddedSet;
boolean domainOnlySpatial =
Domain.getAllSpatial() && !Domain.getMultipleDisplayScalar();
boolean isTexture3D = getIsTexture3D() &&
// default_values[alpha_index] > 0.99 &&
renderer.isLegalTextureMap() &&
(domain_set instanceof Linear3DSet ||
(domain_set instanceof LinearNDSet &&
domain_set.getDimension() == 3));
int t3dm = (int)
default_values[display.getDisplayScalarIndex(Display.Texture3DMode)];
// WLH 1 April 2000
boolean range3D = isTexture3D && anyRange(Domain.getDisplayIndices());
boolean isLinearContour3D = getIsLinearContour3D() &&
domain_set instanceof Linear3DSet &&
shadow_api.allowLinearContour();
/*
System.out.println("doTransform.isTextureMap = " + isTextureMap + " " +
getIsTextureMap() + " " +
// (default_values[alpha_index] > 0.99) + " " +
renderer.isLegalTextureMap() + " " +
(domain_set instanceof Linear2DSet) + " " +
(domain_set instanceof LinearNDSet) + " " +
(domain_set.getDimension() == 2));
System.out.println("doTransform.curvedTexture = " + curvedTexture + " " +
getCurvedTexture() + " " +
!isTextureMap + " " +
(curved_size > 0) + " " +
getIsTerminal() + " " +
shadow_api.allowCurvedTexture() + " " +
(default_values[alpha_index] > 0.99) + " " +
renderer.isLegalTextureMap() + " " +
(domain_set instanceof Gridded2DSet) + " " +
(domain_set instanceof GriddedSet) + " " +
(domain_set.getDimension() == 2) );
*/
float[] coordinates = null;
float[] texCoords = null;
float[] normals = null;
byte[] colors = null;
int data_width = 0;
int data_height = 0;
int data_depth = 0;
int texture_width = 1;
int texture_height = 1;
int texture_depth = 1;
float[] coordinatesX = null;
float[] texCoordsX = null;
float[] normalsX = null;
byte[] colorsX = null;
float[] coordinatesY = null;
float[] texCoordsY = null;
float[] normalsY = null;
byte[] colorsY = null;
float[] coordinatesZ = null;
float[] texCoordsZ = null;
float[] normalsZ = null;
byte[] colorsZ = null;
int[] volume_tuple_index = null;
// if (link != null) System.out.println("test isTextureMap " + (System.currentTimeMillis() - link.start_time));
if (isTextureMap) {
/***
Linear1DSet X = null;
Linear1DSet Y = null;
if (domain_set instanceof Linear2DSet) {
X = ((Linear2DSet) domain_set).getX();
Y = ((Linear2DSet) domain_set).getY();
}
else {
X = ((LinearNDSet) domain_set).getLinear1DComponent(0);
Y = ((LinearNDSet) domain_set).getLinear1DComponent(1);
}
float[][] limits = new float[2][2];
limits[0][0] = (float) X.getFirst();
limits[0][1] = (float) X.getLast();
limits[1][0] = (float) Y.getFirst();
limits[1][1] = (float) Y.getLast();
// get domain_set sizes
data_width = X.getLength();
data_height = Y.getLength();
texture_width = shadow_api.textureWidth(data_width);
texture_height = shadow_api.textureHeight(data_height);
// WLH 27 Jan 2003
float half_width = 0.5f / ((float) (data_width - 1));
float half_height = 0.5f / ((float) (data_height - 1));
half_width = (limits[0][1] - limits[0][0]) * half_width;
half_height = (limits[1][1] - limits[1][0]) * half_height;
limits[0][0] -= half_width;
limits[0][1] += half_width;
limits[1][0] -= half_height;
limits[1][1] += half_height;
// convert values to default units (used in display)
limits = Unit.convertTuple(limits, dataUnits, domain_units);
int[] tuple_index = new int[3];
if (DomainComponents.length != 2) {
throw new DisplayException("texture domain dimension != 2:" +
"ShadowFunctionOrSetType.doTransform");
}
for (int i=0; i 0 &&
real.equals(display.getDisplayScalar(valueToScalar[i])) ) {
value2 = value_array[i];
break;
}
}
coordinates = new float[12];
// corner 0
coordinates[tuple_index[0]] = limits[0][0];
coordinates[tuple_index[1]] = limits[1][0];
coordinates[tuple_index[2]] = value2;
// corner 1
coordinates[3 + tuple_index[0]] = limits[0][1];
coordinates[3 + tuple_index[1]] = limits[1][0];
coordinates[3 + tuple_index[2]] = value2;
// corner 2
coordinates[6 + tuple_index[0]] = limits[0][1];
coordinates[6 + tuple_index[1]] = limits[1][1];
coordinates[6 + tuple_index[2]] = value2;
// corner 3
coordinates[9 + tuple_index[0]] = limits[0][0];
coordinates[9 + tuple_index[1]] = limits[1][1];
coordinates[9 + tuple_index[2]] = value2;
// move image back in Java3D 2-D mode
shadow_api.adjustZ(coordinates);
texCoords = new float[8];
float ratiow = ((float) data_width) / ((float) texture_width);
float ratioh = ((float) data_height) / ((float) texture_height);
shadow_api.setTexCoords(texCoords, ratiow, ratioh);
normals = new float[12];
float n0 = ((coordinates[3+2]-coordinates[0+2]) *
(coordinates[6+1]-coordinates[0+1])) -
((coordinates[3+1]-coordinates[0+1]) *
(coordinates[6+2]-coordinates[0+2]));
float n1 = ((coordinates[3+0]-coordinates[0+0]) *
(coordinates[6+2]-coordinates[0+2])) -
((coordinates[3+2]-coordinates[0+2]) *
(coordinates[6+0]-coordinates[0+0]));
float n2 = ((coordinates[3+1]-coordinates[0+1]) *
(coordinates[6+0]-coordinates[0+0])) -
((coordinates[3+0]-coordinates[0+0]) *
(coordinates[6+1]-coordinates[0+1]));
float nlen = (float) Math.sqrt(n0 * n0 + n1 * n1 + n2 * n2);
n0 = n0 / nlen;
n1 = n1 / nlen;
n2 = n2 / nlen;
// corner 0
normals[0] = n0;
normals[1] = n1;
normals[2] = n2;
// corner 1
normals[3] = n0;
normals[4] = n1;
normals[5] = n2;
// corner 2
normals[6] = n0;
normals[7] = n1;
normals[8] = n2;
// corner 3
normals[9] = n0;
normals[10] = n1;
normals[11] = n2;
colors = new byte[12];
for (int i=0; i<12; i++) colors[i] = (byte) 127;
//for (int i=0; i < 4; i++) {
// System.out.println("i = " + i + " texCoords = " + texCoords[2 * i] + " " +
// texCoords[2 * i + 1]);
// System.out.println(" coordinates = " + coordinates[3 * i] + " " +
// coordinates[3 * i + 1] + " " + coordinates[3 * i + 2]);
// System.out.println(" normals = " + normals[3 * i] + " " + normals[3 * i + 1] +
// " " + normals[3 * i + 2]);
//}
***/
}
else if (isTexture3D) {
visad.util.Trace.call1("ShadowFunctionOrSetType:isTexture3D");
Linear1DSet X = null;
Linear1DSet Y = null;
Linear1DSet Z = null;
if (domain_set instanceof Linear3DSet) {
X = ((Linear3DSet) domain_set).getX();
Y = ((Linear3DSet) domain_set).getY();
Z = ((Linear3DSet) domain_set).getZ();
}
else {
X = ((LinearNDSet) domain_set).getLinear1DComponent(0);
Y = ((LinearNDSet) domain_set).getLinear1DComponent(1);
Z = ((LinearNDSet) domain_set).getLinear1DComponent(2);
}
float[][] limits = new float[3][2];
limits[0][0] = (float) X.getFirst();
limits[0][1] = (float) X.getLast();
limits[1][0] = (float) Y.getFirst();
limits[1][1] = (float) Y.getLast();
limits[2][0] = (float) Z.getFirst();
limits[2][1] = (float) Z.getLast();
// convert values to default units (used in display)
limits = Unit.convertTuple(limits, dataUnits, domain_units, false);
// get domain_set sizes
data_width = X.getLength();
data_height = Y.getLength();
data_depth = Z.getLength();
texture_width = shadow_api.textureWidth(data_width);
texture_height = shadow_api.textureHeight(data_height);
texture_depth = shadow_api.textureDepth(data_depth);
int[] tuple_index = new int[3];
if (DomainComponents.length != 3) {
throw new DisplayException("texture3D domain dimension != 3:" +
"ShadowFunctionOrSetType.doTransform");
}
for (int i=0; i 0.5f);
float mergeArrays =
default_values[
display.getDisplayScalarIndex(Display.MergeGeometries)];
mode.setMergeGeometries(mergeArrays > 0.5f);
//boolean pointMode = mode.getPointMode();
boolean pointMode =
default_values[
display.getDisplayScalarIndex(Display.PointMode)] > 0.5f;
float missingTransparent =
default_values[display.getDisplayScalarIndex(Display.MissingTransparent)];
boolean isMissingTransparent = missingTransparent > 0.5f;
/* DRM: 2005-08-29 - default value now correct
boolean isMissingTransparent = mode.getMissingTransparent();
if (missingTransparent > -0.5f) {
isMissingTransparent = (missingTransparent > 0.5f);
}
*/
if (data instanceof FlatField) {
int mDim = ((FlatField)data).getDomainSet().getManifoldDimension();
if (mDim == 2) {
display.setDepthBufferOffset(renderer, mode);
}
}
// if (link != null) System.out.println("start assembleColor " + (System.currentTimeMillis() - link.start_time));
visad.util.Trace.call1("ShadowFunctionOrSetType:assembleColor ");
// MEM_WLH - this moved
boolean[] single_missing = {false, false, false, false};
// assemble an array of RGBA values
// MEM
byte[][] color_values =
shadow_api.assembleColor(display_values, valueArrayLength, valueToScalar,
display, default_values, range_select,
single_missing, shadow_api);
/*
if (range_select[0] != null) {
int numforced = 0;
for (int k=0; k 3)? " " + color_values[3][0]:""));
}
*/
if (range_select[0] != null && range_select[0].length == 1 &&
!range_select[0][0]) {
// single missing value in range_select[0], so render nothing
return false;
}
visad.util.Trace.call2("ShadowFunctionOrSetType:assembleColor ");
// if (link != null) System.out.println("end assembleColor " + (System.currentTimeMillis() - link.start_time));
float[][] flow1_values = new float[3][];
float[][] flow2_values = new float[3][];
float[] flowScale = new float[2];
float[] arrowScale = new float[2];
// MEM
shadow_api.assembleFlow(flow1_values, flow2_values, flowScale, arrowScale,
display_values, valueArrayLength, valueToScalar,
display, default_values, range_select, renderer,
shadow_api);
/*
if (range_select[0] != null) {
int numforced = 0;
for (int k=0; k 0.999999f) {
*/
if (color_values[3][0] == -1) { // = 255 unsigned
constant_alpha = 0.0f;
// constant_alpha = 1.0f; WLH 26 May 99
// remove alpha from color_values
byte[][] c = new byte[3][];
c[0] = color_values[0];
c[1] = color_values[1];
c[2] = color_values[2];
color_values = c;
}
else { // not opaque
/* TransparencyAttributes with constant alpha seems to have broken
from The Java 3D API Specification: p. 118 transparency = 1 - alpha,
p. 116 transparency 0.0 = opaque, 1.0 = clear */
/*
broken alpha - put it back when alpha fixed
constant_alpha =
new TransparencyAttributes(TransparencyAttributes.NICEST,
1.0f - byteToFloat(color_values[3][0]));
so expand constant alpha to variable alpha
and note no alpha in Java2D:
*/
byte v = color_values[3][0];
color_values[3] = new byte[color_values[0].length];
for (int i=0; i 1) {
int len = range_select[0].length;
/* can be misleading because of the way transparency composites
float alpha =
default_values[display.getDisplayScalarIndex(Display.Alpha)];
// System.out.println("alpha = " + alpha);
if (constant_alpha == constant_alpha) {
alpha = 1.0f - constant_alpha;
// System.out.println("constant_alpha = " + alpha);
}
if (color_values.length < 4) {
byte[][] c = new byte[4][];
c[0] = color_values[0];
c[1] = color_values[1];
c[2] = color_values[2];
c[3] = new byte[len];
for (int i=0; i= limit ) {
y_sub_len /= 2;
n_y_sub *= 2;
}
int[][] y_start_stop = new int[n_y_sub][2];
for (int k = 0; k < n_y_sub-1; k++) {
y_start_stop[k][0] = k*y_sub_len;
y_start_stop[k][1] = (k+1)*y_sub_len - 1;
}
int k = n_y_sub-1;
y_start_stop[k][0] = k*y_sub_len;
y_start_stop[k][1] = lens[1] - 1;
int x_sub_len = lens[0];
int n_x_sub = 1;
while( x_sub_len >= limit ) {
x_sub_len /= 2;
n_x_sub *= 2;
}
int[][] x_start_stop = new int[n_x_sub][2];
for (k = 0; k < n_x_sub-1; k++) {
x_start_stop[k][0] = k*x_sub_len;
x_start_stop[k][1] = (k+1)*x_sub_len - 1;
}
k = n_x_sub-1;
x_start_stop[k][0] = k*x_sub_len;
x_start_stop[k][1] = lens[0] - 1;
if (n_y_sub == 1 && n_x_sub == 1) { //- don't split texture
buildLinearTexture(group, domain_set, dataUnits, domain_units, default_values, shadow_api,
valueArrayLength, valueToScalar, value_array, color_values,
mode, constant_color, constant_alpha);
}
else {
Object branch = shadow_api.makeBranch();
int start = 0;
int i_total = 0;
for (int i=0; i 1) {
int len = range_select[0].length;
float alpha =
default_values[display.getDisplayScalarIndex(Display.Alpha)];
if (constant_alpha == constant_alpha) {
alpha = 1.0f - constant_alpha;
}
if (color_values.length < 4) {
byte[][] c = new byte[4][];
c[0] = color_values[0];
c[1] = color_values[1];
c[2] = color_values[2];
c[3] = new byte[len];
for (int i=0; i 3) {
if (isMissingTransparent) {
for (int i=0; i= limit ) {
y_sub_len /= 2;
n_y_sub *= 2;
}
int[][] y_start_stop = new int[n_y_sub][2];
for (int k = 0; k < n_y_sub-1; k++) {
y_start_stop[k][0] = k*y_sub_len;
y_start_stop[k][1] = (k+1)*y_sub_len - 1;
}
int k = n_y_sub-1;
y_start_stop[k][0] = k*y_sub_len;
y_start_stop[k][1] = lens[1] - 1;
int x_sub_len = lens[0];
int n_x_sub = 1;
while( x_sub_len >= limit ) {
x_sub_len /= 2;
n_x_sub *= 2;
}
int[][] x_start_stop = new int[n_x_sub][2];
for (k = 0; k < n_x_sub-1; k++) {
x_start_stop[k][0] = k*x_sub_len;
x_start_stop[k][1] = (k+1)*x_sub_len - 1;
}
k = n_x_sub-1;
x_start_stop[k][0] = k*x_sub_len;
x_start_stop[k][1] = lens[0] - 1;
if (n_y_sub == 1 && n_x_sub == 1) { //- don't split texture map
buildCurvedTexture(group, domain_set, dataUnits, domain_units, default_values, shadow_api,
valueArrayLength, valueToScalar, value_array, color_values, mode,
constant_color, constant_alpha, curved_size, spatial_values,
spatial_all_select, renderer, range_select, domainOnlySpatial,
null, lens[0], lens[1], lens[0], lens[1]);
}
else {
Object branch = shadow_api.makeBranch();
float[][] samples = spatial_values;
int start = 0;
int i_total = 0;
for (int i=0; i 0) { // vertical stitch
float[][] samplesC = new float[3][4*leny];
byte[][] color_valuesC = new byte[color_values.length][4*leny];
int cntv = 0;
int startv = x_start_stop[j][0] + i_total*lens[0];
for (int iv=0; iv < leny; iv++) {
samplesC[0][cntv] = samples[0][startv-2];
samplesC[0][cntv+1] = samples[0][startv-1];
samplesC[0][cntv+2] = samples[0][startv];
samplesC[0][cntv+3] = samples[0][startv+1];
samplesC[1][cntv] = samples[1][startv-2];
samplesC[1][cntv+1] = samples[1][startv-1];
samplesC[1][cntv+2] = samples[1][startv];
samplesC[1][cntv+3] = samples[1][startv+1];
samplesC[2][cntv] = samples[2][startv-2];
samplesC[2][cntv+1] = samples[2][startv-1];
samplesC[2][cntv+2] = samples[2][startv];
samplesC[2][cntv+3] = samples[2][startv+1];
color_valuesC[0][cntv] = color_values[0][startv-2];
color_valuesC[0][cntv+1] = color_values[0][startv-1];
color_valuesC[0][cntv+2] = color_values[0][startv];
color_valuesC[0][cntv+3] = color_values[0][startv+1];
color_valuesC[1][cntv] = color_values[1][startv-2];
color_valuesC[1][cntv+1] = color_values[1][startv-1];
color_valuesC[1][cntv+2] = color_values[1][startv];
color_valuesC[1][cntv+3] = color_values[1][startv+1];
color_valuesC[2][cntv] = color_values[2][startv-2];
color_valuesC[2][cntv+1] = color_values[2][startv-1];
color_valuesC[2][cntv+2] = color_values[2][startv];
color_valuesC[2][cntv+3] = color_values[2][startv+1];
if (color_valuesC.length == 4) {
color_valuesC[3][cntv] = color_values[3][startv-2];
color_valuesC[3][cntv+1] = color_values[3][startv-1];
color_valuesC[3][cntv+2] = color_values[3][startv];
color_valuesC[3][cntv+3] = color_values[3][startv+1];
}
cntv += 4;
startv += lens[0];
}
Object branchv = shadow_api.makeBranch();
buildCurvedTexture(branchv, null, dataUnits, domain_units, default_values, shadow_api,
valueArrayLength, valueToScalar, value_array, color_valuesC, mode,
constant_color, constant_alpha, curved_size, samplesC,
spatial_all_select, renderer, range_select, domainOnlySpatial,
null,
4, leny, lens[0], lens[1]);
shadow_api.addToGroup(branch, branchv);
}
if (i > 0) { // horz stitch
float[][] samplesC = new float[3][4*lenx];
byte[][] color_valuesC = new byte[color_values.length][4*lenx];
int starth = x_start_stop[j][0] + i_total*lens[0];
int cnth = 0;
System.arraycopy(samples[0], starth-2*lens[0], samplesC[0], cnth, lenx);
System.arraycopy(samples[1], starth-2*lens[0], samplesC[1], cnth, lenx);
System.arraycopy(samples[2], starth-2*lens[0], samplesC[2], cnth, lenx);
cnth += lenx;
System.arraycopy(samples[0], starth-1*lens[0], samplesC[0], cnth, lenx);
System.arraycopy(samples[1], starth-1*lens[0], samplesC[1], cnth, lenx);
System.arraycopy(samples[2], starth-1*lens[0], samplesC[2], cnth, lenx);
cnth += lenx;
System.arraycopy(samples[0], starth, samplesC[0], cnth, lenx);
System.arraycopy(samples[1], starth, samplesC[1], cnth, lenx);
System.arraycopy(samples[2], starth, samplesC[2], cnth, lenx);
cnth += lenx;
System.arraycopy(samples[0], starth+1*lens[0], samplesC[0], cnth, lenx);
System.arraycopy(samples[1], starth+1*lens[0], samplesC[1], cnth, lenx);
System.arraycopy(samples[2], starth+1*lens[0], samplesC[2], cnth, lenx);
cnth = 0;
System.arraycopy(color_values[0], starth-2*lens[0], color_valuesC[0], cnth, lenx);
System.arraycopy(color_values[1], starth-2*lens[0], color_valuesC[1], cnth, lenx);
System.arraycopy(color_values[2], starth-2*lens[0], color_valuesC[2], cnth, lenx);
if (color_values.length == 4) System.arraycopy(color_values[3], starth-2*lens[0], color_valuesC[3], cnth, lenx);
cnth += lenx;
System.arraycopy(color_values[0], starth-1*lens[0], color_valuesC[0], cnth, lenx);
System.arraycopy(color_values[1], starth-1*lens[0], color_valuesC[1], cnth, lenx);
System.arraycopy(color_values[2], starth-1*lens[0], color_valuesC[2], cnth, lenx);
if (color_values.length == 4) System.arraycopy(color_values[3], starth-1*lens[0], color_valuesC[3], cnth, lenx);
cnth += lenx;
System.arraycopy(color_values[0], starth, color_valuesC[0], cnth, lenx);
System.arraycopy(color_values[1], starth, color_valuesC[1], cnth, lenx);
System.arraycopy(color_values[2], starth, color_valuesC[2], cnth, lenx);
if (color_values.length == 4) System.arraycopy(color_values[3], starth, color_valuesC[3], cnth, lenx);
cnth += lenx;
System.arraycopy(color_values[0], starth+1*lens[0], color_valuesC[0], cnth, lenx);
System.arraycopy(color_values[1], starth+1*lens[0], color_valuesC[1], cnth, lenx);
System.arraycopy(color_values[2], starth+1*lens[0], color_valuesC[2], cnth, lenx);
if (color_values.length == 4) System.arraycopy(color_values[3], starth+1*lens[0], color_valuesC[3], cnth, lenx);
Object branchh = shadow_api.makeBranch();
buildCurvedTexture(branchh, null, dataUnits, domain_units, default_values, shadow_api,
valueArrayLength, valueToScalar, value_array, color_valuesC, mode,
constant_color, constant_alpha, curved_size, samplesC,
spatial_all_select, renderer, range_select, domainOnlySpatial,
null,
lenx, 4, lens[0], lens[1]);
shadow_api.addToGroup(branch, branchh);
}
//- tile piece
byte[][] color_valuesW = null;
if (color_values.length == 3) color_valuesW = new byte[3][lenx*leny];
if (color_values.length == 4) color_valuesW = new byte[4][lenx*leny];
int cnt = 0;
for (k=0; k 1) {
int len = range_select[0].length;
/* can be misleading because of the way transparency composites
WLH 15 March 2000 */
float alpha =
default_values[display.getDisplayScalarIndex(Display.Alpha)];
if (constant_alpha == constant_alpha) {
alpha = 1.0f - constant_alpha;
}
if (color_values.length < 4) {
byte[][] c = new byte[4][];
c[0] = color_values[0];
c[1] = color_values[1];
c[2] = color_values[2];
c[3] = new byte[len];
for (int i=0; i 0) {
shadow_api.addToGroup(group, array, mode,
constant_alpha, constant_color);
// System.out.println("array.makeGeometry");
// FREE
array = null;
/* WLH 25 June 2000
if (renderer.getIsDirectManipulation()) {
renderer.setSpatialValues(spatial_values);
}
*/
}
} // end if (!anyContourCreated && !anyFlowCreated &&
// !anyTextCreated && !anyShapeCreated)
// WLH 25 June 2000
if (renderer.getIsDirectManipulation()) {
renderer.setSpatialValues(spatial_values);
}
// if (link != null) System.out.println("end doTransform " + (System.currentTimeMillis() - link.start_time));
return false;
} // end if (LevelOfDifficulty == SIMPLE_FIELD)
else if (LevelOfDifficulty == SIMPLE_ANIMATE_FIELD) {
Control control = null;
Object swit = null;
int index = -1;
if (DomainComponents.length == 1) {
RealType real = (RealType) DomainComponents[0].getType();
for (int i=0; i 1) {
sp[0][0] = spatial_values[0][i];
sp[1][0] = spatial_values[1][i];
sp[2][0] = spatial_values[2][i];
}
else {
sp[0][0] = spatial_values[0][0];
sp[1][0] = spatial_values[1][0];
sp[2][0] = spatial_values[2][0];
}
byte[][] co = new byte[3][1];
if (color_values == null) {
co[0][0] = floatToByte(constant_color[0]);
co[1][0] = floatToByte(constant_color[1]);
co[2][0] = floatToByte(constant_color[2]);
}
else if (color_values[0].length > 1) {
co[0][0] = color_values[0][i];
co[1][0] = color_values[1][i];
co[2][0] = color_values[2][i];
}
else {
co[0][0] = color_values[0][0];
co[1][0] = color_values[1][0];
co[2][0] = color_values[2][0];
}
boolean[][] ra = {{true}};
boolean anyShapeCreated = false;
VisADGeometryArray[] arrays =
shadow_api.assembleShape(display_values, valueArrayLength,
valueToMap, MapVector, valueToScalar, display,
default_values, inherited_values,
sp, co, ra, i, shadow_api);
if (arrays != null) {
for (int j=0; j 1) {
te[0] = text_values[i];
}
else {
te[0] = text_values[0];
}
array = shadow_api.makeText(te, text_control, sp, co, ra);
if (array != null) {
shadow_api.addTextToGroup(branch, array, mode,
constant_alpha, constant_color);
array = null;
anyTextCreated = true;
}
}
boolean anyFlowCreated = false;
if (anyFlow) {
if (flow1_values != null && flow1_values[0] != null) {
// try Flow1
float[][] f1 = new float[3][1];
if (flow1_values[0].length > 1) {
f1[0][0] = flow1_values[0][i];
f1[1][0] = flow1_values[1][i];
f1[2][0] = flow1_values[2][i];
}
else {
f1[0][0] = flow1_values[0][0];
f1[1][0] = flow1_values[1][0];
f1[2][0] = flow1_values[2][0];
}
arrays = shadow_api.makeFlow(0, f1, flowScale[0], arrowScale[0], sp, co, ra);
if (arrays != null) {
for (int j=0; j 1) {
f2[0][0] = flow2_values[0][i];
f2[1][0] = flow2_values[1][i];
f2[2][0] = flow2_values[2][i];
}
else {
f2[0][0] = flow2_values[0][0];
f2[1][0] = flow2_values[1][0];
f2[2][0] = flow2_values[2][0];
}
arrays = shadow_api.makeFlow(1, f2, flowScale[1], arrowScale[1], sp, co, ra);
if (arrays != null) {
for (int j=0; j texture_width || data_height > texture_height) {
throw new VisADException(
"Data dimensions cannot exceed texture dimensions");
}
int size = texture_width * texture_height;
if (data_width != texture_width || data_height != texture_height) {
// expand color_values array to match texture size
byte[][] new_color_values =
new byte[color_values.length][size];
for (int c=0; c 3, false, ColorModel.TRANSLUCENT,
DataBuffer.TYPE_BYTE);
SampleModel sampleModel = new BandedSampleModel(DataBuffer.TYPE_BYTE,
texture_width, texture_height, color_values.length);
DataBuffer buffer = new DataBufferByte(color_values, size);
WritableRaster raster =
Raster.createWritableRaster(sampleModel, buffer, null);
return new BufferedImage(colorModel, raster, false, null);
}
BufferedImage image = null;
if (color_values.length > 3) {
if (!byReference) {
ColorModel colorModel = ColorModel.getRGBdefault();
WritableRaster raster =
colorModel.createCompatibleWritableRaster(texture_width, texture_height);
DataBuffer db = raster.getDataBuffer();
if (!(db instanceof DataBufferInt)) {
throw new UnimplementedException("getRGBdefault isn't DataBufferInt");
}
image = new BufferedImage(colorModel, raster, false, null);
int[] intData = ((DataBufferInt)db).getData();
int k = 0;
int m = 0;
int r, g, b, a;
for (int j=0; j> 8) & 255);
byteData[k++] = (byte) ((intData[i] >> 16) & 255);
}
*/
/* WLH 4 Nov 2000, from com.sun.j3d.utils.geometry.Text2D
// For now, jdk 1.2 only handles ARGB format, not the RGBA we want
BufferedImage bImage = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);
Graphics offscreenGraphics = bImage.createGraphics();
// First, erase the background to the text panel - set alpha to 0
Color myFill = new Color(0f, 0f, 0f, 0f);
offscreenGraphics.setColor(myFill);
offscreenGraphics.fillRect(0, 0, width, height);
// Next, set desired text properties (font, color) and draw String
offscreenGraphics.setFont(font);
Color myTextColor = new Color(color.x, color.y, color.z, 1f);
offscreenGraphics.setColor(myTextColor);
offscreenGraphics.drawString(text, 0, height - descent);
*/
} // end if (!(db instanceof DataBufferInt))
} // end if (color_values.length == 3)
return image;
}
public BufferedImage[] createImages(int axis, int data_width_in,
int data_height_in, int data_depth_in, int texture_width_in,
int texture_height_in, int texture_depth_in, byte[][] color_values)
throws VisADException {
int data_width, data_height, data_depth;
int texture_width, texture_height, texture_depth;
int kwidth, kheight, kdepth;
if (axis == 2) {
kwidth = 1;
kheight = data_width_in;
kdepth = data_width_in * data_height_in;
data_width = data_width_in;
data_height = data_height_in;
data_depth = data_depth_in;
texture_width = texture_width_in;
texture_height = texture_height_in;
texture_depth = texture_depth_in;
}
else if (axis == 1) {
kwidth = 1;
kdepth = data_width_in;
kheight = data_width_in * data_height_in;
data_width = data_width_in;
data_depth = data_height_in;
data_height = data_depth_in;
texture_width = texture_width_in;
texture_depth = texture_height_in;
texture_height = texture_depth_in;
}
else if (axis == 0) {
kdepth = 1;
kwidth = data_width_in;
kheight = data_width_in * data_height_in;
data_depth = data_width_in;
data_width = data_height_in;
data_height = data_depth_in;
texture_depth = texture_width_in;
texture_width = texture_height_in;
texture_height = texture_depth_in;
}
else {
return null;
}
BufferedImage[] images = new BufferedImage[texture_depth];
for (int d=0; d 3) {
ColorModel colorModel = ColorModel.getRGBdefault();
WritableRaster raster =
colorModel.createCompatibleWritableRaster(texture_width, texture_height);
images[d] = new BufferedImage(colorModel, raster, false, null);
/* WLH 23 Feb 2000
if (axis == 1) {
images[(data_depth-1) - d] =
new BufferedImage(colorModel, raster, false, null);
}
else {
images[d] = new BufferedImage(colorModel, raster, false, null);
}
*/
DataBuffer db = raster.getDataBuffer();
if (!(db instanceof DataBufferInt)) {
throw new UnimplementedException("getRGBdefault isn't DataBufferInt");
}
int[] intData = ((DataBufferInt)db).getData();
// int k = d * data_width * data_height;
int kk = d * kdepth;
int m = 0;
int r, g, b, a;
for (int j=0; j 0 &&
real.equals(display.getDisplayScalar(valueToScalar[i])) ) {
value2 = value_array[i];
break;
}
}
coordinates = new float[12];
// corner 0
coordinates[tuple_index[0]] = limits[0][0];
coordinates[tuple_index[1]] = limits[1][0];
coordinates[tuple_index[2]] = value2;
// corner 1
coordinates[3 + tuple_index[0]] = limits[0][1];
coordinates[3 + tuple_index[1]] = limits[1][0];
coordinates[3 + tuple_index[2]] = value2;
// corner 2
coordinates[6 + tuple_index[0]] = limits[0][1];
coordinates[6 + tuple_index[1]] = limits[1][1];
coordinates[6 + tuple_index[2]] = value2;
// corner 3
coordinates[9 + tuple_index[0]] = limits[0][0];
coordinates[9 + tuple_index[1]] = limits[1][1];
coordinates[9 + tuple_index[2]] = value2;
// move image back in Java3D 2-D mode
shadow_api.adjustZ(coordinates);
texCoords = new float[8];
float ratiow = ((float) data_width) / ((float) texture_width);
float ratioh = ((float) data_height) / ((float) texture_height);
shadow_api.setTexCoords(texCoords, ratiow, ratioh);
normals = new float[12];
float n0 = ((coordinates[3+2]-coordinates[0+2]) *
(coordinates[6+1]-coordinates[0+1])) -
((coordinates[3+1]-coordinates[0+1]) *
(coordinates[6+2]-coordinates[0+2]));
float n1 = ((coordinates[3+0]-coordinates[0+0]) *
(coordinates[6+2]-coordinates[0+2])) -
((coordinates[3+2]-coordinates[0+2]) *
(coordinates[6+0]-coordinates[0+0]));
float n2 = ((coordinates[3+1]-coordinates[0+1]) *
(coordinates[6+0]-coordinates[0+0])) -
((coordinates[3+0]-coordinates[0+0]) *
(coordinates[6+1]-coordinates[0+1]));
float nlen = (float) Math.sqrt(n0 * n0 + n1 * n1 + n2 * n2);
n0 = n0 / nlen;
n1 = n1 / nlen;
n2 = n2 / nlen;
// corner 0
normals[0] = n0;
normals[1] = n1;
normals[2] = n2;
// corner 1
normals[3] = n0;
normals[4] = n1;
normals[5] = n2;
// corner 2
normals[6] = n0;
normals[7] = n1;
normals[8] = n2;
// corner 3
normals[9] = n0;
normals[10] = n1;
normals[11] = n2;
colors = new byte[12];
for (int i=0; i<12; i++) colors[i] = (byte) 127;
VisADQuadArray qarray = new VisADQuadArray();
qarray.vertexCount = 4;
qarray.coordinates = coordinates;
qarray.texCoords = texCoords;
qarray.colors = colors;
qarray.normals = normals;
BufferedImage image =
createImage(data_width, data_height, texture_width,
texture_height, color_values);
shadow_api.textureToGroup(group, qarray, image, mode,
constant_alpha, constant_color,
texture_width, texture_height);
}
private void buildCurvedTexture(Object group, Set domain_set, Unit[] dataUnits, Unit[] domain_units,
float[] default_values, ShadowType shadow_api, int valueArrayLength,
int[] valueToScalar, float[] value_array, byte[][] color_values,
GraphicsModeControl mode, float[] constant_color, float constant_alpha,
int curved_size, float[][] spatial_values, boolean spatial_all_select,
DataRenderer renderer, boolean[][] range_select, boolean domainOnlySpatial,
int[] start, int lenX, int lenY, int bigX, int bigY)
throws VisADException
{
//System.out.println("ShadowFunctionOrSetType, start Curved texture: " + System.currentTimeMillis());
float[] coordinates = null;
float[] texCoords = null;
float[] normals = null;
byte[] colors = null;
int data_width = 0;
int data_height = 0;
int texture_width = 1;
int texture_height = 1;
int[] lengths = null;
// get domain_set sizes
if (domain_set != null) {
lengths = ((GriddedSet) domain_set).getLengths();
}
else {
lengths = new int[] {lenX, lenY};
}
data_width = lengths[0];
data_height = lengths[1];
// texture sizes must be powers of two
texture_width = shadow_api.textureWidth(data_width);
texture_height = shadow_api.textureHeight(data_height);
// compute size of triangle array to mapped texture onto
int size = (data_width + data_height) / 2;
curved_size = Math.max(2, Math.min(curved_size, size / 32));
int nwidth = 2 + (data_width - 1) / curved_size;
int nheight = 2 + (data_height - 1) / curved_size;
// WLH 14 Aug 2001
if (range_select[0] != null && !domainOnlySpatial) {
// System.out.println("force curved_size = 1");
curved_size = 1;
nwidth = data_width;
nheight = data_height;
}
// System.out.println("curved_size = " + curved_size + " nwidth = " + nwidth +
// " nheight = " + nheight);
int nn = nwidth * nheight;
coordinates = new float[3 * nn];
int k = 0;
int[] is = new int[nwidth];
int[] js = new int[nheight];
for (int i=0; i
Ads help maintain this website.