Skip to content

Commit

Permalink
PackedBigArrayPoint
Browse files Browse the repository at this point in the history
- Provided a way to access the inner array
  • Loading branch information
lessthanoptimal committed Jul 30, 2024
1 parent e4a8d58 commit dd11f93
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import boofcv.misc.BoofLambdas;
import boofcv.struct.PackedArray;
import georegression.struct.point.Point2D_F64;
import lombok.Getter;
import org.ddogleg.struct.BigDogArray_F64;
import org.ddogleg.struct.BigDogGrowth;

Expand All @@ -32,8 +33,8 @@
public class PackedBigArrayPoint2D_F64 implements PackedArray<Point2D_F64> {
private static final int DOF = 2;

// Storage for the raw data in an array
private final BigDogArray_F64 dog;
/** Storage for the raw data in an array */
@Getter private final BigDogArray_F64 array;

// tuple that the result is temporarily written to
private final Point2D_F64 temp = new Point2D_F64();
Expand All @@ -58,7 +59,7 @@ public PackedBigArrayPoint2D_F64( int reservedPoints ) {
* @param growth Growth strategy to use
*/
public PackedBigArrayPoint2D_F64( int reservedPoints, int blockSize, BigDogGrowth growth ) {
dog = new BigDogArray_F64(reservedPoints*DOF, blockSize*DOF, growth);
array = new BigDogArray_F64(reservedPoints*DOF, blockSize*DOF, growth);
}

/**
Expand All @@ -75,35 +76,35 @@ public PackedBigArrayPoint2D_F64 setTo( PackedBigArrayPoint2D_F64 src ) {
}

@Override public void reset() {
dog.reset();
array.reset();
}

@Override public void reserve( int numPoints ) {
dog.reserve(numPoints*DOF);
array.reserve(numPoints*DOF);
}

public void append( double x, double y ) {
dog.add(x);
dog.add(y);
array.add(x);
array.add(y);
}

@Override public void append( Point2D_F64 element ) {
dog.add(element.x);
dog.add(element.y);
array.add(element.x);
array.add(element.y);
}

@Override public void set( int index, Point2D_F64 element ) {
index *= DOF;
double[] block = dog.getBlocks().get(index/dog.getBlockSize());
int where = index%dog.getBlockSize();
double[] block = array.getBlocks().get(index/array.getBlockSize());
int where = index%array.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());
int element = index%dog.getBlockSize();
double[] block = array.getBlocks().get(index/array.getBlockSize());
int element = index%array.getBlockSize();
temp.x = block[element];
temp.y = block[element + 1];

Expand All @@ -112,8 +113,8 @@ public void append( double x, double y ) {

@Override public void getCopy( int index, Point2D_F64 dst ) {
index *= DOF;
double[] block = dog.getBlocks().get(index/dog.getBlockSize());
int element = index%dog.getBlockSize();
double[] block = array.getBlocks().get(index/array.getBlockSize());
int element = index%array.getBlockSize();
dst.x = block[element];
dst.y = block[element + 1];
}
Expand All @@ -123,15 +124,15 @@ public void append( double x, double y ) {
}

@Override public int size() {
return dog.size/2;
return array.size/2;
}

@Override public Class<Point2D_F64> getElementType() {
return Point2D_F64.class;
}

@Override public void forIdx( int idx0, int idx1, BoofLambdas.ProcessIndex<Point2D_F64> op ) {
dog.processByBlock(idx0*DOF, idx1*DOF, ( array, arrayIdx0, arrayIdx1, offset ) -> {
array.processByBlock(idx0*DOF, idx1*DOF, ( array, arrayIdx0, arrayIdx1, offset ) -> {
int pointIndex = idx0 + offset/DOF;
for (int i = arrayIdx0; i < arrayIdx1; i += DOF) {
temp.x = array[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import boofcv.struct.PackedArray;
import georegression.struct.GeoTuple3D_F64;
import georegression.struct.point.Point3D_F64;
import lombok.Getter;
import org.ddogleg.struct.BigDogArray_F64;
import org.ddogleg.struct.BigDogGrowth;

Expand All @@ -38,8 +39,8 @@ public class PackedBigArrayPoint3D_F64 implements PackedArray<Point3D_F64> {
// tuple that the result is temporarily written to
private final Point3D_F64 temp = new Point3D_F64();

// Storage for the raw data in an array
private final BigDogArray_F64 dog;
/** Storage for the raw data in an array */
@Getter private final BigDogArray_F64 array;

/**
* Constructor where the default is used for all parameters.
Expand All @@ -63,7 +64,7 @@ public PackedBigArrayPoint3D_F64( int reservedPoints ) {
* @param growth Growth strategy to use
*/
public PackedBigArrayPoint3D_F64( int reservedPoints, int blockSize, BigDogGrowth growth ) {
dog = new BigDogArray_F64(reservedPoints*DOF, blockSize*DOF, growth);
array = new BigDogArray_F64(reservedPoints*DOF, blockSize*DOF, growth);
}

/**
Expand All @@ -80,17 +81,17 @@ public PackedBigArrayPoint3D_F64 setTo( PackedBigArrayPoint3D_F64 src ) {
}

@Override public void reset() {
dog.reset();
array.reset();
}

@Override public void reserve( int numPoints ) {
dog.reserve(numPoints*DOF);
array.reserve(numPoints*DOF);
}

public void append( double x, double y, double z ) {
dog.add(x);
dog.add(y);
dog.add(z);
array.add(x);
array.add(y);
array.add(z);
}

public void append( GeoTuple3D_F64<?> element ) {
Expand All @@ -99,8 +100,8 @@ public void append( GeoTuple3D_F64<?> element ) {

@Override public void set( int index, Point3D_F64 element ) {
index *= DOF;
double[] block = dog.getBlocks().get(index/dog.getBlockSize());
int where = index%dog.getBlockSize();
double[] block = array.getBlocks().get(index/array.getBlockSize());
int where = index%array.getBlockSize();
element.x = block[where];
element.y = block[where + 1];
element.z = block[where + 2];
Expand All @@ -120,15 +121,15 @@ public <T extends GeoTuple3D_F64<T>> void appendAll( Collection<T> collection )
}

@Override public void append( Point3D_F64 element ) {
dog.add(element.x);
dog.add(element.y);
dog.add(element.z);
array.add(element.x);
array.add(element.y);
array.add(element.z);
}

@Override public Point3D_F64 getTemp( int index ) {
index *= DOF;
double[] block = dog.getBlocks().get(index/dog.getBlockSize());
int element = index%dog.getBlockSize();
double[] block = array.getBlocks().get(index/array.getBlockSize());
int element = index%array.getBlockSize();
temp.x = block[element];
temp.y = block[element + 1];
temp.z = block[element + 2];
Expand All @@ -142,8 +143,8 @@ public <T extends GeoTuple3D_F64<T>> void appendAll( Collection<T> collection )

public void getCopy( int index, GeoTuple3D_F64<?> dst ) {
index *= DOF;
double[] block = dog.getBlocks().get(index/dog.getBlockSize());
int element = index%dog.getBlockSize();
double[] block = array.getBlocks().get(index/array.getBlockSize());
int element = index%array.getBlockSize();
dst.x = block[element];
dst.y = block[element + 1];
dst.z = block[element + 2];
Expand All @@ -154,15 +155,15 @@ public void getCopy( int index, GeoTuple3D_F64<?> dst ) {
}

@Override public int size() {
return dog.size/3;
return array.size/3;
}

@Override public Class<Point3D_F64> getElementType() {
return Point3D_F64.class;
}

@Override public void forIdx( int idx0, int idx1, BoofLambdas.ProcessIndex<Point3D_F64> op ) {
dog.processByBlock(idx0*3, idx1*3, ( array, arrayIdx0, arrayIdx1, offset ) -> {
array.processByBlock(idx0*3, idx1*3, ( array, arrayIdx0, arrayIdx1, offset ) -> {
int pointIndex = idx0 + offset/DOF;
for (int i = arrayIdx0; i < arrayIdx1; i += DOF) {
temp.x = array[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import boofcv.misc.BoofLambdas;
import boofcv.struct.PackedArray;
import georegression.struct.point.Point4D_F64;
import lombok.Getter;
import org.ddogleg.struct.BigDogArray_F64;
import org.ddogleg.struct.BigDogGrowth;

Expand All @@ -33,10 +34,10 @@ public class PackedBigArrayPoint4D_F64 implements PackedArray<Point4D_F64> {
private static final int DOF = 4;

// Storage for the raw data in an array
private final BigDogArray_F64 dog;
private final BigDogArray_F64 array;

// tuple that the result is temporarily written to
private final Point4D_F64 temp = new Point4D_F64();
/** Storage for the raw data in an array */
@Getter private final Point4D_F64 temp = new Point4D_F64();

/**
* Constructor where the default is used for all parameters.
Expand All @@ -60,7 +61,7 @@ public PackedBigArrayPoint4D_F64( int reservedPoints ) {
* @param growth Growth strategy to use
*/
public PackedBigArrayPoint4D_F64( int reservedPoints, int blockSize, BigDogGrowth growth ) {
dog = new BigDogArray_F64(reservedPoints*DOF, blockSize*DOF, growth);
array = new BigDogArray_F64(reservedPoints*DOF, blockSize*DOF, growth);
}

/**
Expand All @@ -77,31 +78,31 @@ public PackedBigArrayPoint4D_F64 setTo( PackedBigArrayPoint4D_F64 src ) {
}

@Override public void reset() {
dog.reset();
array.reset();
}

@Override public void reserve( int numPoints ) {
dog.reserve(numPoints*DOF);
array.reserve(numPoints*DOF);
}

public void append( double x, double y, double z, double w ) {
dog.add(x);
dog.add(y);
dog.add(z);
dog.add(w);
array.add(x);
array.add(y);
array.add(z);
array.add(w);
}

@Override public void append( Point4D_F64 element ) {
dog.add(element.x);
dog.add(element.y);
dog.add(element.z);
dog.add(element.w);
array.add(element.x);
array.add(element.y);
array.add(element.z);
array.add(element.w);
}

@Override public void set( int index, Point4D_F64 element ) {
index *= DOF;
double[] block = dog.getBlocks().get(index/dog.getBlockSize());
int where = index%dog.getBlockSize();
double[] block = array.getBlocks().get(index/array.getBlockSize());
int where = index%array.getBlockSize();
element.x = block[where];
element.y = block[where + 1];
element.z = block[where + 2];
Expand All @@ -110,8 +111,8 @@ public void append( double x, double y, double z, double w ) {

@Override public Point4D_F64 getTemp( int index ) {
index *= DOF;
double[] block = dog.getBlocks().get(index/dog.getBlockSize());
int element = index%dog.getBlockSize();
double[] block = array.getBlocks().get(index/array.getBlockSize());
int element = index%array.getBlockSize();
temp.x = block[element];
temp.y = block[element + 1];
temp.z = block[element + 2];
Expand All @@ -122,8 +123,8 @@ public void append( double x, double y, double z, double w ) {

@Override public void getCopy( int index, Point4D_F64 dst ) {
index *= DOF;
double[] block = dog.getBlocks().get(index/dog.getBlockSize());
int element = index%dog.getBlockSize();
double[] block = array.getBlocks().get(index/array.getBlockSize());
int element = index%array.getBlockSize();
dst.x = block[element];
dst.y = block[element + 1];
dst.z = block[element + 2];
Expand All @@ -135,15 +136,15 @@ public void append( double x, double y, double z, double w ) {
}

@Override public int size() {
return dog.size/4;
return array.size/4;
}

@Override public Class<Point4D_F64> getElementType() {
return Point4D_F64.class;
}

@Override public void forIdx( int idx0, int idx1, BoofLambdas.ProcessIndex<Point4D_F64> op ) {
dog.processByBlock(idx0*DOF, idx1*DOF, ( array, arrayIdx0, arrayIdx1, offset ) -> {
array.processByBlock(idx0*DOF, idx1*DOF, ( array, arrayIdx0, arrayIdx1, offset ) -> {
int pointIndex = idx0 + offset/DOF;
for (int i = arrayIdx0; i < arrayIdx1; i += DOF) {
temp.x = array[i];
Expand Down

0 comments on commit dd11f93

Please sign in to comment.