From c1281356dfcc865180d971a44fafd9df020656a4 Mon Sep 17 00:00:00 2001 From: Peter Abeles Date: Thu, 25 Apr 2024 09:23:37 -0700 Subject: [PATCH] PackedArray - Added set(index, value) --- .../boofcv/struct/feature/PackedTupleArray_B.java | 4 ++++ .../struct/feature/PackedTupleArray_F64.java | 4 ++++ .../struct/feature/PackedTupleArray_S8.java | 4 ++++ .../struct/feature/PackedTupleArray_U8.java | 4 ++++ .../struct/feature/PackedTupleBigArray_B.java | 4 ++++ .../struct/feature/PackedTupleBigArray_F64.java | 4 ++++ .../struct/feature/PackedTupleBigArray_S8.java | 4 ++++ .../struct/feature/PackedTupleBigArray_U8.java | 4 ++++ .../vocabtree/TestHierarchicalVocabularyTree.java | 3 ++- .../src/main/java/boofcv/struct/PackedArray.java | 7 ++++++- .../struct/packed/PackedArrayPoint2D_F64.java | 8 +++++++- .../struct/packed/PackedArrayPoint2D_I16.java | 8 +++++++- .../struct/packed/PackedArrayPoint2D_I32.java | 8 +++++++- .../struct/packed/PackedArrayPoint3D_F64.java | 9 ++++++++- .../struct/packed/PackedArrayPoint4D_F64.java | 10 +++++++++- .../struct/packed/PackedBigArrayPoint2D_F64.java | 10 +++++++++- .../struct/packed/PackedBigArrayPoint3D_F64.java | 11 ++++++++++- .../struct/packed/PackedBigArrayPoint4D_F64.java | 12 +++++++++++- .../struct/packed/GenericPackedArrayChecks.java | 15 ++++++++++++++- .../struct/packed/TestPackedArrayPoint4D_F64.java | 2 +- 20 files changed, 123 insertions(+), 12 deletions(-) diff --git a/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleArray_B.java b/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleArray_B.java index e7e65e49d1..ea76cce88a 100644 --- a/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleArray_B.java +++ b/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleArray_B.java @@ -64,6 +64,10 @@ public PackedTupleArray_B( int dof ) { numElements++; } + @Override public void set( int index, TupleDesc_B element ) { + System.arraycopy(element.data, 0, array.data, index*numInts, numInts); + } + @Override public TupleDesc_B getTemp( int index ) { System.arraycopy(array.data, index*numInts, temp.data, 0, numInts); return temp; diff --git a/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleArray_F64.java b/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleArray_F64.java index 50802d8df0..c0aa438b0e 100644 --- a/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleArray_F64.java +++ b/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleArray_F64.java @@ -60,6 +60,10 @@ public PackedTupleArray_F64( int dof ) { numElements++; } + @Override public void set( int index, TupleDesc_F64 element ) { + System.arraycopy(element.data, 0, array.data, index*dof, dof); + } + @Override public TupleDesc_F64 getTemp( int index ) { System.arraycopy(array.data, index*dof, temp.data, 0, dof); return temp; diff --git a/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleArray_S8.java b/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleArray_S8.java index 2d47b294a2..1104446b7c 100644 --- a/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleArray_S8.java +++ b/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleArray_S8.java @@ -60,6 +60,10 @@ public PackedTupleArray_S8( int dof ) { numElements++; } + @Override public void set( int index, TupleDesc_S8 element ) { + System.arraycopy(element.data, 0, array.data, index*dof, dof); + } + @Override public TupleDesc_S8 getTemp( int index ) { System.arraycopy(array.data, index*dof, temp.data, 0, dof); return temp; diff --git a/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleArray_U8.java b/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleArray_U8.java index 9357276d7b..1f6a6c82c9 100644 --- a/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleArray_U8.java +++ b/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleArray_U8.java @@ -60,6 +60,10 @@ public PackedTupleArray_U8( int dof ) { numElements++; } + @Override public void set( int index, TupleDesc_U8 element ) { + System.arraycopy(element.data, 0, array.data, index*dof, dof); + } + @Override public TupleDesc_U8 getTemp( int index ) { System.arraycopy(array.data, index*dof, temp.data, 0, dof); return temp; diff --git a/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleBigArray_B.java b/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleBigArray_B.java index 7193ffc44f..d277d61c4f 100644 --- a/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleBigArray_B.java +++ b/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleBigArray_B.java @@ -65,6 +65,10 @@ public PackedTupleBigArray_B( int dof ) { numElements++; } + @Override public void set( int index, TupleDesc_B element ) { + array.setArray((long)index*numInts, element.data, 0, numInts); + } + @Override public TupleDesc_B getTemp( int index ) { array.getArray(index*numInts, temp.data, 0, numInts); return temp; diff --git a/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleBigArray_F64.java b/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleBigArray_F64.java index d904dea62a..be1c3442a5 100644 --- a/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleBigArray_F64.java +++ b/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleBigArray_F64.java @@ -61,6 +61,10 @@ public PackedTupleBigArray_F64( int dof ) { numElements++; } + @Override public void set( int index, TupleDesc_F64 element ) { + array.setArray((long)index*dof, element.data, 0, dof); + } + @Override public TupleDesc_F64 getTemp( int index ) { array.getArray(index*dof, temp.data, 0, dof); return temp; diff --git a/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleBigArray_S8.java b/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleBigArray_S8.java index 71e4740aab..8bd26e69b8 100644 --- a/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleBigArray_S8.java +++ b/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleBigArray_S8.java @@ -61,6 +61,10 @@ public PackedTupleBigArray_S8( int dof ) { numElements++; } + @Override public void set( int index, TupleDesc_S8 element ) { + array.setArray((long)index*dof, element.data, 0, dof); + } + @Override public TupleDesc_S8 getTemp( int index ) { array.getArray(index*dof, temp.data, 0, dof); return temp; diff --git a/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleBigArray_U8.java b/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleBigArray_U8.java index 9c9cb3f4ec..5fa20d5aac 100644 --- a/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleBigArray_U8.java +++ b/main/boofcv-feature/src/main/java/boofcv/struct/feature/PackedTupleBigArray_U8.java @@ -61,6 +61,10 @@ public PackedTupleBigArray_U8( int dof ) { numElements++; } + @Override public void set( int index, TupleDesc_U8 element ) { + array.setArray((long)index*dof, element.data, 0, dof); + } + @Override public TupleDesc_U8 getTemp( int index ) { array.getArray(index*dof, temp.data, 0, dof); return temp; diff --git a/main/boofcv-recognition/src/test/java/boofcv/alg/scene/vocabtree/TestHierarchicalVocabularyTree.java b/main/boofcv-recognition/src/test/java/boofcv/alg/scene/vocabtree/TestHierarchicalVocabularyTree.java index 1bf7b4f893..3bd1f40694 100644 --- a/main/boofcv-recognition/src/test/java/boofcv/alg/scene/vocabtree/TestHierarchicalVocabularyTree.java +++ b/main/boofcv-recognition/src/test/java/boofcv/alg/scene/vocabtree/TestHierarchicalVocabularyTree.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Peter Abeles. All Rights Reserved. + * Copyright (c) 2024, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -143,6 +143,7 @@ public static class Packed2D implements PackedArray { @Override public void reset() {list.clear();} @Override public void reserve( int numElements ) {} @Override public void append( Point2D_F64 element ) {list.add(element.copy());} + @Override public void set(int index, Point2D_F64 element) {} @Override public void forIdx( int idx0, int idx1, BoofLambdas.ProcessIndex op ) {} @Override public Point2D_F64 getTemp( int index ) {return list.get(index);} @Override public void getCopy( int index, Point2D_F64 dst ) {dst.setTo(list.get(index));} diff --git a/main/boofcv-types/src/main/java/boofcv/struct/PackedArray.java b/main/boofcv-types/src/main/java/boofcv/struct/PackedArray.java index c9aa884a87..1e25ae0c2f 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/PackedArray.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/PackedArray.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2024, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -48,6 +48,11 @@ public interface PackedArray extends LArrayAccessor { */ void append( T element ); + /** + * Sets an element's value + */ + void set( int index, T element ); + /** * Passes in each object and index within the specified range. Modifications to the passed in objcet * will be saved in the array. diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_F64.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_F64.java index e68683d2f4..0b5f3ae3ce 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_F64.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2024, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -64,6 +64,12 @@ public final void append( double x, double y ) { append(element.x, element.y); } + @Override public void set( int index, Point2D_F64 element ) { + index *= 2; + array.data[index++] = element.x; + array.data[index] = element.y; + } + @Override public Point2D_F64 getTemp( int index ) { temp.x = array.data[index*2]; temp.y = array.data[index*2 + 1]; diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_I16.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_I16.java index 78b9be9227..4af83fa9d3 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_I16.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_I16.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2024, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -64,6 +64,12 @@ public final void append( int x, int y ) { append(element.x, element.y); } + @Override public void set( int index, Point2D_I16 element ) { + index *= 2; + array.data[index++] = element.x; + array.data[index] = element.y; + } + @Override public Point2D_I16 getTemp( int index ) { temp.x = array.data[index*2]; temp.y = array.data[index*2 + 1]; diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_I32.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_I32.java index d544ac9f84..77c1403ab6 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_I32.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint2D_I32.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2024, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -64,6 +64,12 @@ public final void append( int x, int y ) { append(element.x, element.y); } + @Override public void set( int index, Point2D_I32 element ) { + index *= 2; + array.data[index++] = element.x; + array.data[index] = element.y; + } + @Override public Point2D_I32 getTemp( int index ) { temp.x = array.data[index*2]; temp.y = array.data[index*2 + 1]; diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint3D_F64.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint3D_F64.java index 8cdc0429a4..4bd5b7c7af 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint3D_F64.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint3D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2024, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -61,6 +61,13 @@ public PackedArrayPoint3D_F64() { numElements++; } + @Override public void set( int index, Point3D_F64 element ) { + index *= 3; + array.data[index++] = element.x; + array.data[index++] = element.y; + array.data[index] = element.z; + } + @Override public Point3D_F64 getTemp( int index ) { index *= 3; temp.x = array.data[index]; diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint4D_F64.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint4D_F64.java index 31c351c849..46c8160c2c 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint4D_F64.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArrayPoint4D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2024, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -62,6 +62,14 @@ public PackedArrayPoint4D_F64() { numElements++; } + @Override public void set( int index, Point4D_F64 element ) { + index *= 4; + array.data[index++] = element.x; + array.data[index++] = element.y; + array.data[index++] = element.z; + array.data[index] = element.w; + } + @Override public Point4D_F64 getTemp( int index ) { index *= 4; temp.x = array.data[index]; diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint2D_F64.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint2D_F64.java index ee5901d619..5afbd99066 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint2D_F64.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint2D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2024, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -87,6 +87,14 @@ public void append( double x, double y ) { numPoints++; } + @Override public void set( int index, Point2D_F64 element ) { + index *= DOF; + double[] block = dog.getBlocks().get(index/dog.getBlockSize()); + int where = index%dog.getBlockSize(); + element.x = block[where]; + element.y = block[where + 1]; + } + @Override public Point2D_F64 getTemp( int index ) { index *= DOF; double[] block = dog.getBlocks().get(index/dog.getBlockSize()); diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint3D_F64.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint3D_F64.java index d90a2c5ec6..f17289fbe0 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint3D_F64.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint3D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Peter Abeles. All Rights Reserved. + * Copyright (c) 2024, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -103,6 +103,15 @@ public void append( GeoTuple3D_F64 element ) { append(element.x, element.y, element.z); } + @Override public void set( int index, Point3D_F64 element ) { + index *= DOF; + double[] block = dog.getBlocks().get(index/dog.getBlockSize()); + int where = index%dog.getBlockSize(); + element.x = block[where]; + element.y = block[where + 1]; + element.z = block[where + 2]; + } + /** * Adds all the points in the collection */ diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint4D_F64.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint4D_F64.java index 418a7dab64..7c2d1d907e 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint4D_F64.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArrayPoint4D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2024, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -93,6 +93,16 @@ public void append( double x, double y, double z, double w ) { numPoints++; } + @Override public void set( int index, Point4D_F64 element ) { + index *= DOF; + double[] block = dog.getBlocks().get(index/dog.getBlockSize()); + int where = index%dog.getBlockSize(); + element.x = block[where]; + element.y = block[where + 1]; + element.z = block[where + 2]; + element.w = block[where + 3]; + } + @Override public Point4D_F64 getTemp( int index ) { index *= DOF; double[] block = dog.getBlocks().get(index/dog.getBlockSize()); diff --git a/main/boofcv-types/src/test/java/boofcv/struct/packed/GenericPackedArrayChecks.java b/main/boofcv-types/src/test/java/boofcv/struct/packed/GenericPackedArrayChecks.java index faad898257..78e0ff9dc3 100644 --- a/main/boofcv-types/src/test/java/boofcv/struct/packed/GenericPackedArrayChecks.java +++ b/main/boofcv-types/src/test/java/boofcv/struct/packed/GenericPackedArrayChecks.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Peter Abeles. All Rights Reserved. + * Copyright (c) 2024, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -148,4 +148,17 @@ public abstract class GenericPackedArrayChecks extends BoofStandardJUnit { checkEquals(array.getTemp(i+2), found.get(i)); } } + + @Test void set_index() { + PackedArray alg = createAlg(); + + alg.append(createRandomPoint()); + alg.append(createRandomPoint()); + alg.append(createRandomPoint()); + + var p = createRandomPoint(); + alg.set(1, p); + T found = alg.getTemp(1); + checkEquals(p, found); + } } diff --git a/main/boofcv-types/src/test/java/boofcv/struct/packed/TestPackedArrayPoint4D_F64.java b/main/boofcv-types/src/test/java/boofcv/struct/packed/TestPackedArrayPoint4D_F64.java index c1312cbc9c..770f161960 100644 --- a/main/boofcv-types/src/test/java/boofcv/struct/packed/TestPackedArrayPoint4D_F64.java +++ b/main/boofcv-types/src/test/java/boofcv/struct/packed/TestPackedArrayPoint4D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Peter Abeles. All Rights Reserved. + * Copyright (c) 2024, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). *