//
// Histogram.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.math;

import visad.*;
import visad.java3d.*;

import java.rmi.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 Histogram is the VisAD class for creating histograms of Field
 values.

*/ public class Histogram { /** invoke in SpreadSheet by: link(visad.math.Histogram.makeHistogram(A1, A2)) */ public static FlatField makeHistogram(Data[] datums) { FlatField result = null; try { if (datums == null || datums.length != 2) { throw new VisADException("bad arguments"); } if (!(datums[0] instanceof Field)) { throw new VisADException("first argument must be a Field"); } if (!(datums[1] instanceof Set)) { throw new VisADException("second argument must be a Set"); } result = makeHistogram((Field) datums[0], (Set) datums[1]); } catch (VisADException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } if (result == null) { System.out.println("result == null"); } return result; } /** return a histogram of field range values in "bins" defined by the samples of set */ public static FlatField makeHistogram(Field field, Set set) throws VisADException, RemoteException { FunctionType ftype = (FunctionType) field.getType(); RealType[] frealComponents = ftype.getRealComponents(); RealTupleType stype = ((SetType) set.getType()).getDomain(); RealType[] srealComponents = stype.getRealComponents(); RealType count = RealType.getRealType("count"); FunctionType htype = new FunctionType(stype, count); int dim = srealComponents.length; float[][] field_values = field.getFloats(false); float[][] set_values = new float[dim][]; for (int i=0; i= 0) hist_values[0][indices[j]]++; } FlatField result = new FlatField(htype, set); result.setSamples(hist_values, false); return result; } public static void main(String args[]) throws VisADException, RemoteException { int SIZE = 64; RealType X = RealType.getRealType("X"); RealType Y = RealType.getRealType("Y"); RealType A = RealType.getRealType("A"); RealType B = RealType.getRealType("B"); RealType[] domain2d = {X, Y}; RealTupleType Domain2d = new RealTupleType(domain2d); Integer2DSet Domain2dSet = new Integer2DSet(Domain2d, SIZE, SIZE); RealType[] range2d = {A, B}; RealTupleType Range2d = new RealTupleType(range2d); FunctionType Field2d2 = new FunctionType(Domain2d, Range2d); FlatField image = new FlatField(Field2d2, Domain2dSet); int len = Domain2dSet.getLength(); int ADD = len * len / 16; float[][] values = new float[2][len]; for (int i=0; i

Ads help maintain this website.