Utility class for Mapping arrays of Floats
| 10 | * Utility class for Mapping arrays of Floats |
| 11 | */ |
| 12 | public class MappedFloatArray { |
| 13 | |
| 14 | |
| 15 | private final RandomAccessFile raf; |
| 16 | private final FloatBuffer fbuffer; |
| 17 | private final ByteBuffer buffer; |
| 18 | private final DoubleBuffer dbuffer; |
| 19 | private final IntBuffer ibuffer; |
| 20 | int preferredDimension = 3; |
| 21 | |
| 22 | public MappedFloatArray(String filename) throws IOException { |
| 23 | raf = new RandomAccessFile(filename, "r"); |
| 24 | |
| 25 | buffer = raf.getChannel() |
| 26 | .map(FileChannel.MapMode.READ_ONLY, 0, raf.length()) |
| 27 | .order(ByteOrder.nativeOrder()); |
| 28 | fbuffer = buffer.asFloatBuffer(); |
| 29 | dbuffer = buffer.asDoubleBuffer(); |
| 30 | ibuffer = buffer.asIntBuffer(); |
| 31 | } |
| 32 | |
| 33 | public MappedFloatArray setPreferredDimension(int p) { |
| 34 | preferredDimension = p; |
| 35 | return this; |
| 36 | } |
| 37 | |
| 38 | public Vec3 get3f(int index) { |
| 39 | return new Vec3(fbuffer.get(index), fbuffer.get(index + 1), fbuffer.get(index + 2)); |
| 40 | } |
| 41 | |
| 42 | public int length3f() { |
| 43 | return fbuffer.limit() / 3; |
| 44 | } |
| 45 | |
| 46 | public Vec2 get2f(int index) { |
| 47 | return new Vec2(fbuffer.get(index), fbuffer.get(index + 1)); |
| 48 | } |
| 49 | |
| 50 | public int length2f() { |
| 51 | return fbuffer.limit() / 2; |
| 52 | } |
| 53 | |
| 54 | public float get1f(int index) { |
| 55 | return fbuffer.get(index); |
| 56 | } |
| 57 | |
| 58 | public int length1f() { |
| 59 | return fbuffer.limit(); |
| 60 | } |
| 61 | |
| 62 | public int length() { |
| 63 | switch (preferredDimension) { |
| 64 | case 1: |
| 65 | return length1f(); |
| 66 | case 2: |
| 67 | return length2f(); |
| 68 | case 3: |
| 69 | return length3f(); |
nothing calls this directly
no outgoing calls
no test coverage detected