|
43 | 43 | import net.imglib2.img.Img;
|
44 | 44 | import net.imglib2.img.ImgFactory;
|
45 | 45 | import net.imglib2.img.ImgView;
|
46 |
| -import net.imglib2.img.array.ArrayImgFactory; |
47 | 46 | import net.imglib2.img.cell.CellImgFactory;
|
48 | 47 | import net.imglib2.img.planar.PlanarImgFactory;
|
49 | 48 | import net.imglib2.type.NativeType;
|
|
59 | 58 | import net.imglib2.type.numeric.integer.UnsignedShortType;
|
60 | 59 | import net.imglib2.type.numeric.real.DoubleType;
|
61 | 60 | import net.imglib2.type.numeric.real.FloatType;
|
62 |
| -import net.imglib2.util.Intervals; |
63 | 61 | import net.imglib2.util.Util;
|
64 | 62 |
|
65 | 63 | import org.scijava.log.LogService;
|
@@ -320,27 +318,13 @@ private <T extends RealType<T>> Img<T> wrapToImg(
|
320 | 318 | final RandomAccessibleInterval<T> rai)
|
321 | 319 | {
|
322 | 320 | if (rai instanceof Img) return (Img<T>) rai;
|
323 |
| - // NB: In order to synthesize an ImgFactory here, the RAI |
324 |
| - // type must extend NativeType. So let's check! |
325 |
| - final T type = Util.getTypeFromInterval(rai); |
326 |
| - if (!(type instanceof NativeType)) { |
327 |
| - throw new IllegalArgumentException( |
328 |
| - "Cannot create factory for non-Img RAI of non-native-type: " + // |
329 |
| - type.getClass()); |
330 |
| - } |
331 |
| - @SuppressWarnings({ "rawtypes", "unchecked" }) |
332 |
| - final ImgFactory<T> imgFactory = imgFactory((RandomAccessibleInterval) rai); |
333 |
| - return ImgView.wrap(rai, imgFactory); |
| 321 | + return ImgView.wrap(rai, imgFactory(rai)); |
334 | 322 | }
|
335 | 323 |
|
336 |
| - private <T extends NativeType<T>> ImgFactory<T> imgFactory( |
| 324 | + private <T> ImgFactory<T> imgFactory( |
337 | 325 | final RandomAccessibleInterval<T> rai)
|
338 | 326 | {
|
339 |
| - // TODO: Call create.imgFactory op instead. As things stand, we cannot, |
340 |
| - // because imagej-common cannot depend on imagej-ops. Perhaps this |
341 |
| - // "wrapToImgPlus" logic should not live here? Consider best approach. |
342 | 327 | final T type = Util.getTypeFromInterval(rai);
|
343 |
| - return rai == null || Intervals.numElements(rai) <= Integer.MAX_VALUE |
344 |
| - ? new ArrayImgFactory<>(type) : new CellImgFactory<>(type); |
| 328 | + return Util.getSuitableImgFactory(rai, type); |
345 | 329 | }
|
346 | 330 | }
|
0 commit comments