|
23 | 23 | import java.io.FileNotFoundException;
|
24 | 24 | import java.io.IOException;
|
25 | 25 |
|
| 26 | +import io.bioimage.modelrunner.tensor.Tensor; |
26 | 27 | import io.bioimage.modelrunner.numpy.DecodeNumpy;
|
| 28 | + |
27 | 29 | import net.imglib2.RandomAccessibleInterval;
|
28 | 30 | import net.imglib2.type.NativeType;
|
29 | 31 | import net.imglib2.type.numeric.RealType;
|
30 | 32 |
|
31 | 33 | /**
|
32 |
| - * Class that maps {@link Tensor} objects to the shared memory for interprocessing communication |
| 34 | + * TODO get rid of this class in favour of shared memory IPC |
| 35 | + * Class that maps {@link Tensor} objects to a temporal file for inter-processing communication |
33 | 36 | *
|
34 | 37 | * @author Carlos Garcia Lopez de Haro
|
35 | 38 | */
|
36 | 39 | public final class SharedMemoryFile
|
37 | 40 | {
|
| 41 | + /** |
| 42 | + * Create a .npy Numpy file from a {@link RandomAccessibleInterval} |
| 43 | + * @param <T> |
| 44 | + * the ImgLib2 data type of the {@link RandomAccessibleInterval} |
| 45 | + * @param fileDir |
| 46 | + * file path to the .npy file that is going to be created |
| 47 | + * @param rai |
| 48 | + * the {@link RandomAccessibleInterval} of interest |
| 49 | + * @throws FileNotFoundException if the parent directory where the file wants to be created does not exist |
| 50 | + * @throws IOException if there is any error creating the file |
| 51 | + */ |
38 | 52 | public static <T extends RealType<T> & NativeType<T>>
|
39 | 53 | void buildFileFromRai(String fileDir, RandomAccessibleInterval<T> rai) throws FileNotFoundException, IOException {
|
40 | 54 | DecodeNumpy.writeRaiToNpyFile(fileDir, rai);
|
41 | 55 | }
|
42 | 56 |
|
| 57 | + /** |
| 58 | + * Read a {@link RandomAccessibleInterval} from a .npy Numpy file created to share between processes |
| 59 | + * @param <T> |
| 60 | + * the ImgLib2 data type of the {@link RandomAccessibleInterval} |
| 61 | + * @param fileName |
| 62 | + * name of the .npy file that contains a {@link RandomAccessibleInterval} |
| 63 | + * @return a {@link RandomAccessibleInterval} |
| 64 | + * @throws FileNotFoundException if the file is not found |
| 65 | + * @throws IOException if there is any error reading the file |
| 66 | + */ |
43 | 67 | public static <T extends RealType<T> & NativeType<T>>
|
44 | 68 | RandomAccessibleInterval<T> buildRaiFromFile(String fileName) throws FileNotFoundException, IOException {
|
45 | 69 | return DecodeNumpy.retrieveImgLib2FromNpy(fileName);
|
|
0 commit comments