-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNormalizedBinned2DData.java
More file actions
93 lines (84 loc) · 1.88 KB
/
Copy pathNormalizedBinned2DData.java
File metadata and controls
93 lines (84 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//package org.freehep.j3d.plot;
import javax.vecmath.Color3b;
/**
* The Binned2DDataNormalizer class is responsible for taking the user provided Binned2DData
* interface, and mapping it to the data format used internally.
*
* This involves normalizing the x,y,z axis to go from 0 to 1, and ensuring that we
* return 0 if the bin indexes are outside the allowed range. This routine also caches
* a local copy of the data to speed up access in the LegoBuilder class.
* @author Joy Kyriakopulos (joyk@fnal.gov)
* @version $Id: NormalizedBinned2DData.java 8584 2006-08-10 23:06:37Z duns $
*/
class NormalizedBinned2DData
{
private int xBins;
private int yBins;
private float[][] data;
private Color3b[][] color;
NormalizedBinned2DData(Binned2DData in)
{
this.initialize(in);
}
void initialize(Binned2DData in)
{
xBins = in.xBins();
yBins = in.yBins();
// Copy the data to a local array, and calculate the Zmin, Zmax
data = new float[xBins][yBins];
color = new Color3b[xBins][yBins];
float zMin = +Float.MAX_VALUE;
float zMax = -Float.MAX_VALUE;
for (int i=0; i<xBins; i++)
{
for (int j=0; j<yBins; j++)
{
float z = in.zAt(i,j);
if (z < zMin) zMin = z;
if (z > zMax) zMax = z;
data[i][j] = z;
color[i][j] = in.colorAt(i,j);
}
}
//System.out.println("zMin = "+zMin+", zMax = "+zMax);
// Now normalize the Z values
for (int i=0; i<xBins; i++)
{
for (int j=0; j<yBins; j++)
{
float z = data[i][j];
data[i][j] = (z-zMin)/(zMax-zMin);
}
}
}
int xBins()
{
return xBins;
}
int yBins()
{
return yBins;
}
float zAt(int xIndex, int yIndex)
{
try
{
return data[xIndex][yIndex];
}
catch (ArrayIndexOutOfBoundsException x)
{
return 0;
}
}
Color3b colorAt(int xIndex, int yIndex)
{
try
{
return color[xIndex][yIndex];
}
catch (ArrayIndexOutOfBoundsException x)
{
return null;
}
}
}