Commit 7cdfaba5 authored by Krzysztof Nowinski's avatar Krzysztof Nowinski

connected components process properly all types of data (time data, nonnumeric data etc.)

parent c62f3584
......@@ -41,6 +41,9 @@ import pl.edu.icm.jscic.CellSet;
import pl.edu.icm.jscic.dataarrays.DataArray;
import pl.edu.icm.jscic.IrregularField;
import pl.edu.icm.jlargearrays.FloatLargeArray;
import pl.edu.icm.jlargearrays.LargeArray;
import pl.edu.icm.jlargearrays.LargeArrayUtils;
import pl.edu.icm.jscic.TimeData;
/**
*
......@@ -82,31 +85,16 @@ public class ExtractCellSets
if (nOut == 0)
return null;
IrregularField out = new IrregularField(nOut);
out.setCurrentCoords(new FloatLargeArray(floatArrayCompact(in.getCurrentCoords() == null ? null : in.getCurrentCoords().getData(), 3, nOut, vpts)));
for (DataArray da : in.getComponents())
if (da.isNumeric())
switch (da.getType()) {
case FIELD_DATA_BYTE:
out.addComponent(DataArray.create(byteArrayCompact((byte[])da.getRawArray().getData(), da.getVectorLength(), nOut, vpts),
da.getVectorLength(), da.getName(), da.getUnit(), da.getUserData()));
break;
case FIELD_DATA_SHORT:
out.addComponent(DataArray.create(shortArrayCompact((short[])da.getRawArray().getData(), da.getVectorLength(), nOut, vpts),
da.getVectorLength(), da.getName(), da.getUnit(), da.getUserData()));
break;
case FIELD_DATA_INT:
out.addComponent(DataArray.create(intArrayCompact((int[])da.getRawArray().getData(), da.getVectorLength(), nOut, vpts),
da.getVectorLength(), da.getName(), da.getUnit(), da.getUserData()));
break;
case FIELD_DATA_FLOAT:
out.addComponent(DataArray.create(floatArrayCompact((float[])da.getRawArray().getData(), da.getVectorLength(), nOut, vpts),
da.getVectorLength(), da.getName(), da.getUnit(), da.getUserData()));
break;
case FIELD_DATA_DOUBLE:
out.addComponent(DataArray.create(doubleArrayCompact((double[])da.getRawArray().getData(), da.getVectorLength(), nOut, vpts),
da.getVectorLength(), da.getName(), da.getUnit(), da.getUserData()));
break;
}
out.setCurrentCoords(in.getCurrentCoords() == null ? null : (FloatLargeArray)arrayCompact(in.getCurrentCoords(), 3, nOut, vpts));
for (DataArray da : in.getComponents()) {
TimeData inTD = da.getTimeData();
TimeData outTD = new TimeData(da.getType());
for (int i = 0; i < inTD.getNSteps(); i++)
outTD.setValue(arrayCompact(inTD.getValue(inTD.getTime(i)),
da.getVectorLength(), nOut, vpts), inTD.getTime(i));
out.addComponent(DataArray.create(outTD, da.getVectorLength(), da.getName(), da.getUnit(), da.getUserData()));
}
for (CellSet s : in.getCellSets())
if (s.isSelected()) {
CellSet outS = new CellSet(s.getName());
......@@ -132,72 +120,16 @@ public class ExtractCellSets
}
return out;
}
public static byte[] byteArrayCompact(byte[] data, int vlen, int outLen, boolean[] v)
{
int n = data.length / vlen;
if (n != v.length)
return null;
byte[] out = new byte[outLen * vlen];
for (int i = 0, j = 0; i < n; i++)
if (v[i]) {
System.arraycopy(data, vlen * i, out, j, vlen);
j += vlen;
}
return out;
}
public static short[] shortArrayCompact(short[] data, int vlen, int outLen, boolean[] v)
{
int n = data.length / vlen;
if (n != v.length)
return null;
short[] out = new short[outLen * vlen];
for (int i = 0, j = 0; i < n; i++)
if (v[i]) {
System.arraycopy(data, vlen * i, out, j, vlen);
j += vlen;
}
return out;
}
public static int[] intArrayCompact(int[] data, int vlen, int outLen, boolean[] v)
{
int n = data.length / vlen;
if (n != v.length)
return null;
int[] out = new int[outLen * vlen];
for (int i = 0, j = 0; i < n; i++)
if (v[i]) {
System.arraycopy(data, vlen * i, out, j, vlen);
j += vlen;
}
return out;
}
public static float[] floatArrayCompact(float[] data, int vlen, int outLen, boolean[] v)
{
int n = data.length / vlen;
if (n != v.length)
return null;
float[] out = new float[outLen * vlen];
for (int i = 0, j = 0; i < n; i++)
if (v[i]) {
System.arraycopy(data, vlen * i, out, j, vlen);
j += vlen;
}
return out;
}
public static double[] doubleArrayCompact(double[] data, int vlen, int outLen, boolean[] v)
public static LargeArray arrayCompact(LargeArray data, int vlen, int outLen, boolean[] v)
{
int n = data.length / vlen;
long n = data.length() / vlen;
if (n != v.length)
return null;
double[] out = new double[outLen * vlen];
LargeArray out = LargeArrayUtils.create(data.getType(), outLen * vlen);
for (int i = 0, j = 0; i < n; i++)
if (v[i]) {
System.arraycopy(data, vlen * i, out, j, vlen);
LargeArrayUtils.arraycopy(data, vlen * i, out, j, vlen);
j += vlen;
}
return out;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment