Skip to content

Commit

Permalink
PackedArray
Browse files Browse the repository at this point in the history
- Added set(index, value)
  • Loading branch information
lessthanoptimal committed Apr 25, 2024
1 parent d91c6a6 commit c128135
Show file tree
Hide file tree
Showing 20 changed files with 123 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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).
*
Expand Down Expand Up @@ -143,6 +143,7 @@ public static class Packed2D implements PackedArray<Point2D_F64> {
@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<Point2D_F64> 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));}
Expand Down
Original file line number Diff line number Diff line change
@@ -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).
*
Expand Down Expand Up @@ -48,6 +48,11 @@ public interface PackedArray<T> extends LArrayAccessor<T> {
*/
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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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).
*
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
@@ -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).
*
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
@@ -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).
*
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
@@ -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).
*
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
@@ -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).
*
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
@@ -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).
*
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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).
*
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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).
*
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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).
*
Expand Down Expand Up @@ -148,4 +148,17 @@ public abstract class GenericPackedArrayChecks<T> extends BoofStandardJUnit {
checkEquals(array.getTemp(i+2), found.get(i));
}
}

@Test void set_index() {
PackedArray<T> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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).
*
Expand Down

0 comments on commit c128135

Please sign in to comment.