//
// UnionSet.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;
//
// TO_DO
// getWedge
//
/**
* UnionSet is the union of an array of SampledSets. They
* must match in domain dimension, manifold dimension,
* CoordinateSystem, and Units. No sets in the array can be null,
* and there must be at least one SampledSet in the array
* (i.e. array.length != 0).
*/
public class UnionSet extends SampledSet {
private static final long serialVersionUID = 1L;
SampledSet[] Sets;
/**
* Construct a UnionSet with an array of SampledSets with null errors.
* CoordinateSystem and Units are defaults from type.
*
* @param type MathType for the sets. Sets the CoordinateSystem and Units.
* @param sets array of SampledSets. All sets must match in domain
* dimension and manifold dimension and no sets in the
* array can be null. There must be at least one SampledSet
* in the array (i.e. sets.length != 0).
*
* @exception VisADException problem creating the UnionSet
*/
public UnionSet(MathType type, SampledSet[] sets) throws VisADException {
this(type, sets, null, null, null, true);
}
/** create the union of the sets array; coordinate_system
and units must be compatible with defaults for type,
or may be null; errors may be null */
private UnionSet(MathType type, SampledSet[] sets,
CoordinateSystem coord_sys, Unit[] units,
ErrorEstimate[] errors) throws VisADException {
this(type, sets, coord_sys, units, errors, true);
}
public UnionSet(MathType type, SampledSet[] sets, CoordinateSystem coord_sys,
Unit[] units, ErrorEstimate[] errors, boolean copy)
throws VisADException {
super(type, find_manifold_dim(sets), sets[0].getCoordinateSystem(),
sets[0].getSetUnits(), null);
DomainDimension = sets[0].DomainDimension;
if (copy) {
Sets = new SampledSet[sets.length];
for (int i=0; i Hi[i]) Hi[i] = sets[j].Hi[i];
}
}
}
private static int find_manifold_dim(SampledSet[] sets)
throws VisADException {
if (sets == null || sets.length == 0 || sets[0] == null) {
throw new SetException("UnionSet: Sets cannot be missing");
}
if (sets.length < 2) {
/* DRM - 03-Jan-2000
throw new SetException("UnionSet: must be at least 2 sets");
*/
return sets[0].ManifoldDimension;
}
int dim = sets[0].DomainDimension;
int mdim = sets[0].ManifoldDimension;
CoordinateSystem cs0 = sets[0].getCoordinateSystem();
Unit[] units0 = sets[0].getSetUnits();
for (int i=1; i rl) return;
boolean[] ri = new boolean[len];
System.arraycopy(range_select, k, ri, 0, len);
Sets[i].cram_missing(ri);
k += len;
}
}
/** create a 2-D GeometryArray from this Set and color_values */
public VisADGeometryArray make2DGeometry(byte[][] color_values,
boolean indexed) throws VisADException {
if (DomainDimension != 3) {
throw new SetException("UnionSet.make2DGeometry: " +
"DomainDimension must be 3, not " +
DomainDimension);
}
if (ManifoldDimension != 2) {
throw new SetException("UnionSet.make2DGeometry: " +
"ManifoldDimension must be 2, not " +
ManifoldDimension);
}
int n = Sets.length;
int dim = (color_values != null) ? color_values.length : 0;
if (indexed) {
VisADIndexedTriangleStripArray[] arrays =
new VisADIndexedTriangleStripArray[n];
int base = 0;
for (int i=0; i= Sets[q].Length) {
curind -= Sets[q++].Length;
/*
System.out.println("curind = " + curind +
" Sets[" + (q-1) + "].Length = " + Sets[q-1].Length);
*/
}
if (q == nsets) curind += Sets[--q].Length;
ind_lens[q]++;
set_num[j] = q;
new_ind[j] = curind;
/*
System.out.println("index[" + j + "] = " + index[j] +
" ind_lens[" + q + "] = " + ind_lens[q] +
" set_num[" + j + "] = " + set_num[j] +
" new_ind[" + j + "] = " + new_ind[j]);
*/
}
// allocate subset space
for (int i=0; i 0) ? new int[ind_lens[i]] : null;
ind_lens[i] = 0;
}
// copy each index point into its proper subset
for (int j=0; j dist_sqr[i]) best_set = i;
}
int ind = subindex[best_set][j];
while (best_set > 0) ind += Sets[--best_set].Length;
index[j] = ind;
}
return index;
}
/** for each of an array of values in R^DomainDimension, compute an array
of 1-D indices and an array of weights, to be used for interpolation;
indices[i] and weights[i] are null if i-th value is outside grid
(i.e., if no interpolation is possible) */
public void valueToInterp(float[][] value, int[][] indices,
float[][] weights) throws VisADException {
int nsets = Sets.length;
int length = indices.length;
int offset = 0;
for (int i=0; i ("+value1[0][i]);
for (int j=1; j index "+index2[i]);
}
System.out.println("-----------------");
System.out.println("valueToInterp test:");
int n = value2[0].length;
int[][] indices = new int[n][];
float[][] weights = new float[n][];
uSet.valueToInterp(value2, indices, weights);
for (int i=0; i");
if (indices[i] == null || indices[i].length == 0) {
System.out.println(" missing");
}
else {
int m = indices[i].length;
for (int j=0; j
Ads help maintain this website.