Skip to content
Snippets Groups Projects
Commit 15f05e23 authored by Raphael GIRARDOT's avatar Raphael GIRARDOT
Browse files

Added the possibility, for block data reading, to get extracted block as FlatData array or FlatData

parent aceb571d
Branches
Tags
No related merge requests found
......@@ -67,32 +67,32 @@ public class ImageStack extends StackedData {
}
return image;
}
//
// /**
// * Returns a block of image ROIs, starting at given position.
// *
// * @param x The ROI x coordinate in the image.
// * @param y The ROI y coordinate in the image.
// * @param width The ROI width.
// * @param height The ROI height.
// * @param nbOfImages The number of images in the block.
// * @param position The image position in the stack.
// * @return A {@link FlatData}.
// */
// public FlatData getROIBlockAt(int x, int y, int width, int height, int nbOfImages, int... position) {
// FlatData block = null;
// if ((stackFullShape != null) && (position != null) && (dataShape != null) && (dataShape.length == 2) && (x > -1)
// && (y > -1) && (height > 0) && (width > 0) && (x + width <= dataShape[1])
// && (y + height <= dataShape[0]) && (nbOfImages > 0)) {
// if (position.length != stackFullShape.length) {
// position = Arrays.copyOf(position, stackFullShape.length);
// }
// position[position.length - 1] = x;
// position[position.length - 2] = y;
// block = getData(position, new int[] { nbOfImages, height, width });
// }
// return block;
// }
/**
* Returns a block of image ROIs, starting at given position.
*
* @param x The ROI x coordinate in the image.
* @param y The ROI y coordinate in the image.
* @param width The ROI width.
* @param height The ROI height.
* @param nbOfImages The number of images in the block.
* @param position The image position in the stack.
* @return A {@link FlatData}.
*/
public FlatData getROIFlatBlockAt(int x, int y, int width, int height, int nbOfImages, int... position) {
FlatData block = null;
if ((stackFullShape != null) && (position != null) && (dataShape != null) && (dataShape.length == 2) && (x > -1)
&& (y > -1) && (height > 0) && (width > 0) && (x + width <= dataShape[1])
&& (y + height <= dataShape[0]) && (nbOfImages > 0)) {
if (position.length != stackFullShape.length) {
position = Arrays.copyOf(position, stackFullShape.length);
}
position[position.length - 1] = x;
position[position.length - 2] = y;
block = getData(position, new int[] { nbOfImages, height, width });
}
return block;
}
/**
* Returns a block of image ROIs, starting at given position.
......@@ -125,21 +125,21 @@ public class ImageStack extends StackedData {
return getDataAt(position);
}
// /**
// * Returns a block of images, starting at given position.
// *
// * @param nbOfImages The number of images in the block.
// * @param position The image position in the stack.
// * @return A {@link FlatData}.
// */
// public FlatData getImageBlockAt(int nbOfImages, int... position) {
// FlatData block = null;
// if ((stackFullShape != null) && (position != null) && (dataShape != null) && (dataShape.length == 2)
// && (nbOfImages > 0)) {
// block = getData(position, new int[] { nbOfImages, dataShape[0], dataShape[1] });
// }
// return block;
// }
/**
* Returns a block of images, starting at given position.
*
* @param nbOfImages The number of images in the block.
* @param position The image position in the stack.
* @return A {@link FlatData}.
*/
public FlatData getImageFlatBlockAt(int nbOfImages, int... position) {
FlatData block = null;
if ((stackFullShape != null) && (position != null) && (dataShape != null) && (dataShape.length == 2)
&& (nbOfImages > 0)) {
block = getData(position, new int[] { nbOfImages, dataShape[0], dataShape[1] });
}
return block;
}
/**
* Returns a block of images, starting at given position.
......
......@@ -12,6 +12,7 @@ import fr.soleil.cdma.box.reader.ICDMAReader;
import fr.soleil.cdma.box.util.PositionKey;
import fr.soleil.lib.project.data.FlatData;
import fr.soleil.lib.project.math.ArrayUtils;
import fr.soleil.lib.project.math.MathConst;
import fr.soleil.lib.project.math.NumberArrayUtils;
/**
......@@ -159,43 +160,43 @@ public class SpectrumStack extends StackedData {
return result;
}
// @Override
// public FlatData getBlockAt(int nbOfData, int... position) {
// FlatData result;
// if (useMap) {
// if ((nbOfData > 0) && (spectrumLength > 0) && (position != null) && (stackShape != null)
// && (position.length == stackShape.length)) {
// int count = Math.min(nbOfData, stackShape[stackShape.length - 1] - position[position.length - 1]);
// if (count > 0) {
// double[] array = new double[count * spectrumLength];
// Arrays.fill(array, MathConst.NAN_FOR_NULL);
// int[] index = position.clone();
// int i = 0;
// while (ArrayUtils.isPosition(stackShape, index)) {
// SoftIndexedData<double[]> data = spectra.get(new PositionKey(index));
// if (data != null) {
// double[] spectrum = data.getData();
// if (spectrum != null) {
// System.arraycopy(spectrum, 0, array, i * spectrumLength, spectrumLength);
// }
// }
// ArrayUtils.incrementPosition(stackShape, index);
// if (++i >= count) {
// break;
// }
// }
// result = new FlatData(new int[] { count, spectrumLength }, array);
// } else {
// result = null;
// }
// } else {
// result = null;
// }
// } else {
// result = super.getBlockAt(nbOfData, position);
// }
// return result;
// }
@Override
public FlatData getFlatBlockAt(int nbOfData, int... position) {
FlatData result;
if (useMap) {
if ((nbOfData > 0) && (spectrumLength > 0) && (position != null) && (stackShape != null)
&& (position.length == stackShape.length)) {
int count = Math.min(nbOfData, stackShape[stackShape.length - 1] - position[position.length - 1]);
if (count > 0) {
double[] array = new double[count * spectrumLength];
Arrays.fill(array, MathConst.NAN_FOR_NULL);
int[] index = position.clone();
int i = 0;
while (ArrayUtils.isPosition(stackShape, index)) {
SoftIndexedData<double[]> data = spectra.get(new PositionKey(index));
if (data != null) {
double[] spectrum = data.getData();
if (spectrum != null) {
System.arraycopy(spectrum, 0, array, i * spectrumLength, spectrumLength);
}
}
ArrayUtils.incrementPosition(stackShape, index);
if (++i >= count) {
break;
}
}
result = new FlatData(new int[] { count, spectrumLength }, array);
} else {
result = null;
}
} else {
result = null;
}
} else {
result = super.getFlatBlockAt(nbOfData, position);
}
return result;
}
@Override
public FlatData[] getBlockAt(int nbOfData, int... position) {
......
......@@ -103,27 +103,27 @@ public abstract class StackedData extends ReferencedData {
return getData(position, dataShape);
}
// /**
// * Returns a block of data, starting at given position.
// *
// * @param nbOfData The number of data in a block
// * @param position The data position in the stack.
// * @return A {@link FlatData}.
// */
// public FlatData getBlockAt(int nbOfData, int... position) {
// FlatData block = null;
// int rank = getDataRank();
// if ((stackFullShape != null) && (stackFullShape.length > rank) && (rank > -1) && (position != null)
// && (dataShape != null) && (dataShape.length == rank) && (nbOfData > 0)) {
// int[] shape = new int[rank + 1];
// shape[0] = nbOfData;
// if (rank > 0) {
// System.arraycopy(dataShape, 0, shape, 1, rank);
// }
// block = getData(position, shape);
// }
// return block;
// }
/**
* Returns a block of data, starting at given position.
*
* @param nbOfData The number of data in a block
* @param position The data position in the stack.
* @return A {@link FlatData}.
*/
public FlatData getFlatBlockAt(int nbOfData, int... position) {
FlatData block = null;
int rank = getDataRank();
if ((stackFullShape != null) && (stackFullShape.length > rank) && (rank > -1) && (position != null)
&& (dataShape != null) && (dataShape.length == rank) && (nbOfData > 0)) {
int[] shape = new int[rank + 1];
shape[0] = nbOfData;
if (rank > 0) {
System.arraycopy(dataShape, 0, shape, 1, rank);
}
block = getData(position, shape);
}
return block;
}
/**
* Returns a block of data, starting at given position.
......
......@@ -399,6 +399,36 @@ public class ScanData {
return result;
}
/**
* Returns the image block at a particular coordinate
*
* @param index The coordinate
* @param nbOfImages The number of images inside the block.
* @return A {@link FlatData}. <code>null</code> if no such image.
*/
public FlatData[] getImageBlockAt(int nbOfImages, int... index) {
FlatData[] result = null;
if (images != null) {
result = images.getImageBlockAt(nbOfImages, index);
}
return result;
}
/**
* Returns the image block at a particular coordinate
*
* @param index The coordinate
* @param nbOfImages The number of images inside the block.
* @return A {@link FlatData}. <code>null</code> if no such image.
*/
public FlatData getImageFlatBlockAt(int nbOfImages, int... index) {
FlatData result = null;
if (images != null) {
result = images.getImageFlatBlockAt(nbOfImages, index);
}
return result;
}
// public FlatData getSpectraAt(int... index) {
// FlatData result = null;
//
......@@ -466,6 +496,25 @@ public class ScanData {
return result;
}
/**
* Returns a block of image ROI at a particular coordinate
*
* @param x the desired ROI x
* @param y the desired ROI y
* @param width the desired ROI width
* @param height the desired ROI height
* @param nbOfImages The number of images in the block
* @param index The coordinate
* @return A {@link FlatData} array. <code>null</code> if no such image block.
*/
public FlatData getImageROIFlatBlockAt(int x, int y, int width, int height, int nbOfImages, int... index) {
FlatData result = null;
if (images != null) {
result = images.getROIFlatBlockAt(x, y, width, height, nbOfImages, index);
}
return result;
}
public Object getSpectrumAt(int... position) {
Object spectrum = null;
if (spectrumStack != null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment