Advertisement
Advertisement
| 04.16.2008 at 05:20PM PDT, ID: 23329379 |
|
[x]
Attachment Details
|
||
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: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: |
public float[][] read2D(byte[] byteArray, float scaling)
throws IOException
{
int structSize = 8; // 2 floats
int pointCount = byteArray.length / structSize;
float[][] floatArray = new float[pointCount][2];
LEDataInputStream dis = new LEDataInputStream(new ByteArrayInputStream(byteArray));
for (int i = 0; i < pointCount; i++)
{
Float xValueReadIn = dis.readFloat();
Float yValueReadIn = dis.readFloat();
//
// Check the x value
//
if (xValueReadIn.isNaN())
{
floatArray[i][0] = 0;
}
else
{
floatArray[i][0] = xValueReadIn.floatValue();
}
//
// Check the y value
//
if (yValueReadIn.isNaN())
{
floatArray[i][1] = 0;
}
else
{
floatArray[i][1] = yValueReadIn.floatValue();
}
}
return floatArray;
}
/**
*
* readDouble2D(byte[] byteArray)
*
* Two 2-dimensional trace point arrays is an array of structures.
* x1,y1a,y1b,
* x2,y2a,y2b,
* ...
* xn,yna,ynb
*
*/
public Vector<Float>[] readDouble2D(byte[] byteArray)
throws IOException
{
return readDouble2D(byteArray, 1);
}
public Vector<Float>[] readDouble2D(byte[] byteArray, float scaling)
throws IOException
{
int structSize = 12; // 3 floats
int pointCount = byteArray.length / structSize;
List<Vector<Float>> vectorArray = new ArrayList<Vector<Float>>(pointCount);
LEDataInputStream dis = new LEDataInputStream(new ByteArrayInputStream(byteArray));
for (int i = 0; i < pointCount; i++)
{
Vector<Float> values = new Vector<Float>(3);
//
// No scaling for x value
//
values.add(new Float(dis.readFloat() * scaling));
for (int j = 0; j < 2; j++)
{
values.add(new Float(dis.readFloat() * scaling));
}
vectorArray.add(values);
}
return (Vector<Float>[])vectorArray.toArray();
}
/*
* ---------------------------
* Here is the misbehaving class
*/
public Map<String, Float>[] read2DMultiPoint(byte[] byteArray, int points, String[] hashNames, float scaling)
throws IOException
{
int structSize = 4 * points;
int pointCount = byteArray.length / structSize;
List<Map<String, Float>> mapArray = new ArrayList<Map<String, Float>>(pointCount);
LEDataInputStream dis = new LEDataInputStream(new ByteArrayInputStream(byteArray));
for (int i = 0; i < pointCount; i++)
{
HashMap<String, Float> pointMap = new HashMap<String, Float>(points);
//
// No scaling for x value
//
pointMap.put(hashNames[0], new Float(dis.readFloat()));
for (int j = 1; j < points; j++)
{
pointMap.put(hashNames[j], new Float(dis.readFloat() * scaling));
}
mapArray.add(pointMap);
}
return (Map<String, Float>[])mapArray.toArray();
}
|