From 19cc85ce17f87312b70a37226d5a389a999161cd Mon Sep 17 00:00:00 2001 From: Peter Abeles Date: Mon, 2 Dec 2024 10:28:56 -0800 Subject: [PATCH] PackedArray - isEquals --- build.gradle | 2 +- change.txt | 7 +++ integration/boofcv-kotlin/build.gradle | 6 +-- .../struct/feature/PackedTupleArray_B.java | 5 ++ .../struct/feature/PackedTupleArray_F64.java | 5 ++ .../struct/feature/PackedTupleArray_S8.java | 5 ++ .../struct/feature/PackedTupleArray_U8.java | 5 ++ .../struct/feature/PackedTupleBigArray_B.java | 5 ++ .../feature/PackedTupleBigArray_F64.java | 5 ++ .../feature/PackedTupleBigArray_S8.java | 5 ++ .../feature/PackedTupleBigArray_U8.java | 5 ++ .../TestHierarchicalVocabularyTree.java | 1 + .../main/java/boofcv/struct/PackedArray.java | 3 ++ .../struct/packed/PackedArrayPoint2D_F64.java | 25 +-------- .../struct/packed/PackedArrayPoint2D_I16.java | 4 ++ .../struct/packed/PackedArrayPoint2D_I32.java | 4 ++ .../struct/packed/PackedArrayPoint3D_F64.java | 25 +-------- .../struct/packed/PackedArrayPoint4D_F64.java | 17 +----- .../boofcv/struct/packed/PackedArray_F64.java | 53 ++++++++++++++++++ .../packed/PackedBigArrayPoint2D_F64.java | 32 +++-------- .../packed/PackedBigArrayPoint3D_F64.java | 20 +------ .../packed/PackedBigArrayPoint4D_F64.java | 19 +------ .../struct/packed/PackedBigArray_F64.java | 54 +++++++++++++++++++ .../packed/GenericPackedArrayChecks.java | 24 +++++++-- 24 files changed, 205 insertions(+), 131 deletions(-) create mode 100644 main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArray_F64.java create mode 100644 main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArray_F64.java diff --git a/build.gradle b/build.gradle index 2a5bb16f65..80572bff37 100644 --- a/build.gradle +++ b/build.gradle @@ -133,7 +133,7 @@ subprojects { dependencies { api("org.georegression:georegression:0.27.3") { exclude group: 'org.ddogleg' } - api("org.ddogleg:ddogleg:0.23.4") + api("org.ddogleg:ddogleg:0.23.5-SNAPSHOT") api("net.sf.trove4j:trove4j:${project.trove4j_version}") diff --git a/change.txt b/change.txt index ca2254522c..30b2b1d147 100644 --- a/change.txt +++ b/change.txt @@ -6,6 +6,13 @@ Version Meaning: .. - Second digit indicates if a new feature was added and/or if only a minor refactoring has been done - Last digit always indicates a bug fix and other minor changes +--------------------- +Date : 202X/XXX/XX +Version : 1.1.8 + +- PackedArray + * Added isEquals() + --------------------- Date : 2024/Oct/05 Version : 1.1.7 diff --git a/integration/boofcv-kotlin/build.gradle b/integration/boofcv-kotlin/build.gradle index e8fd366ebd..aa8744e62e 100644 --- a/integration/boofcv-kotlin/build.gradle +++ b/integration/boofcv-kotlin/build.gradle @@ -1,12 +1,12 @@ plugins { - id 'org.jetbrains.kotlin.jvm' version '1.6.10' + id 'org.jetbrains.kotlin.jvm' version '1.7.22' } configurations.all { resolutionStrategy { force "org.jetbrains:annotations:$project.jetnull_version" - force "org.jetbrains.kotlin:kotlin-stdlib:1.6.10" - force "org.jetbrains.kotlin:kotlin-stdlib-common:1.6.10" + force "org.jetbrains.kotlin:kotlin-stdlib:1.7.22" + force "org.jetbrains.kotlin:kotlin-stdlib-common:1.7.22" } } 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 ea76cce88a..85c0f33cdf 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 @@ -19,6 +19,7 @@ package boofcv.struct.feature; import boofcv.misc.BoofLambdas; +import boofcv.struct.PackedArray; import org.ddogleg.struct.DogArray_I32; /** @@ -99,6 +100,10 @@ public PackedTupleArray_B( int dof ) { } } + @Override public boolean isEquals( PackedArray other ) { + return array.isEquals(((PackedTupleArray_B)other).array); + } + @Override public int getDOF() { return dof; } 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 c0aa438b0e..7608208b35 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 @@ -19,6 +19,7 @@ package boofcv.struct.feature; import boofcv.misc.BoofLambdas; +import boofcv.struct.PackedArray; import org.ddogleg.struct.DogArray_F64; /** @@ -95,6 +96,10 @@ public PackedTupleArray_F64( int dof ) { } } + @Override public boolean isEquals( PackedArray other ) { + return array.isEquals(((PackedTupleArray_F64)other).array); + } + @Override public int getDOF() { return dof; } 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 1104446b7c..828a438a29 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 @@ -19,6 +19,7 @@ package boofcv.struct.feature; import boofcv.misc.BoofLambdas; +import boofcv.struct.PackedArray; import org.ddogleg.struct.DogArray_I8; /** @@ -95,6 +96,10 @@ public PackedTupleArray_S8( int dof ) { } } + @Override public boolean isEquals( PackedArray other ) { + return array.isEquals(((PackedTupleArray_S8)other).array); + } + @Override public int getDOF() { return dof; } 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 1f6a6c82c9..33432f619c 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 @@ -19,6 +19,7 @@ package boofcv.struct.feature; import boofcv.misc.BoofLambdas; +import boofcv.struct.PackedArray; import org.ddogleg.struct.DogArray_I8; /** @@ -95,6 +96,10 @@ public PackedTupleArray_U8( int dof ) { } } + @Override public boolean isEquals( PackedArray other ) { + return array.isEquals(((PackedTupleArray_U8)other).array); + } + @Override public int getDOF() { return dof; } 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 d277d61c4f..32756a84b1 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 @@ -19,6 +19,7 @@ package boofcv.struct.feature; import boofcv.misc.BoofLambdas; +import boofcv.struct.PackedArray; import org.ddogleg.struct.BigDogArray_I32; import org.ddogleg.struct.BigDogGrowth; @@ -100,6 +101,10 @@ public PackedTupleBigArray_B( int dof ) { }); } + @Override public boolean isEquals( PackedArray other ) { + return array.isEquivalent(((PackedTupleBigArray_B)other).array); + } + @Override public int getDOF() { return dof; } 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 be1c3442a5..bb972b7c51 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 @@ -19,6 +19,7 @@ package boofcv.struct.feature; import boofcv.misc.BoofLambdas; +import boofcv.struct.PackedArray; import org.ddogleg.struct.BigDogArray_F64; import org.ddogleg.struct.BigDogGrowth; @@ -96,6 +97,10 @@ public PackedTupleBigArray_F64( int dof ) { }); } + @Override public boolean isEquals( PackedArray other ) { + return array.isEquivalent(((PackedTupleBigArray_F64)other).array, 0.0); + } + @Override public int getDOF() { return dof; } 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 8bd26e69b8..a158ae4c41 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 @@ -19,6 +19,7 @@ package boofcv.struct.feature; import boofcv.misc.BoofLambdas; +import boofcv.struct.PackedArray; import org.ddogleg.struct.BigDogArray_I8; import org.ddogleg.struct.BigDogGrowth; @@ -96,6 +97,10 @@ public PackedTupleBigArray_S8( int dof ) { }); } + @Override public boolean isEquals( PackedArray other ) { + return array.isEquivalent(((PackedTupleBigArray_S8)other).array); + } + @Override public int getDOF() { return dof; } 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 5fa20d5aac..3f0c625110 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 @@ -19,6 +19,7 @@ package boofcv.struct.feature; import boofcv.misc.BoofLambdas; +import boofcv.struct.PackedArray; import org.ddogleg.struct.BigDogArray_I8; import org.ddogleg.struct.BigDogGrowth; @@ -96,6 +97,10 @@ public PackedTupleBigArray_U8( int dof ) { }); } + @Override public boolean isEquals( PackedArray other ) { + return array.isEquivalent(((PackedTupleBigArray_U8)other).array); + } + @Override public int getDOF() { return dof; } 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 3bd1f40694..931c6f7ade 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 @@ -145,6 +145,7 @@ public static class Packed2D implements PackedArray { @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 boolean isEquals(PackedArray other) {return false;} @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));} @Override public void copy( Point2D_F64 src, Point2D_F64 dst ) {dst.setTo(src);} 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 1e25ae0c2f..1d059d529d 100644 --- a/main/boofcv-types/src/main/java/boofcv/struct/PackedArray.java +++ b/main/boofcv-types/src/main/java/boofcv/struct/PackedArray.java @@ -62,4 +62,7 @@ public interface PackedArray extends LArrayAccessor { * @param op The operation to process each element */ void forIdx( int idx0, int idx1, BoofLambdas.ProcessIndex op ); + + /** Checks to see if the two data structures are equal */ + boolean isEquals( PackedArray other ); } 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 cee34d9fe9..a115853cc1 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 @@ -19,36 +19,19 @@ package boofcv.struct.packed; import boofcv.misc.BoofLambdas; -import boofcv.struct.PackedArray; import georegression.struct.point.Point2D_F64; -import lombok.Getter; -import org.ddogleg.struct.DogArray_F64; /** * Packed array of {@link Point2D_F64}. Internally the point is stored in an interleaved format. * * @author Peter Abeles */ -public class PackedArrayPoint2D_F64 implements PackedArray { - private static final int DOF = 2; - - /** Stores tuple in a single continuous array */ - @Getter private final DogArray_F64 array; - +public class PackedArrayPoint2D_F64 extends PackedArray_F64 { // tuple that the result is temporarily written to private final Point2D_F64 temp = new Point2D_F64(); public PackedArrayPoint2D_F64() { - array = new DogArray_F64(); - array.resize(0); - } - - @Override public void reset() { - array.reset(); - } - - @Override public void reserve( int numTuples ) { - array.reserve(numTuples*2); + super(2, 0); } public final void append( double x, double y ) { @@ -82,10 +65,6 @@ public final void append( double x, double y ) { dst.setTo(src); } - @Override public int size() { - return array.size/2; - } - @Override public Class getElementType() { return Point2D_F64.class; } 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 774d368675..c6e4bee2d2 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 @@ -103,6 +103,10 @@ public final void append( int x, int y ) { } } + @Override public boolean isEquals( PackedArray o ) { + return this.array.isEquals(((PackedArrayPoint2D_I16)o).array); + } + /** * Makes this array have a value identical to 'src' * 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 057e650db9..f4f6deb0e3 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 @@ -103,6 +103,10 @@ public final void append( int x, int y ) { } } + @Override public boolean isEquals( PackedArray o ) { + return this.array.isEquals(((PackedArrayPoint2D_I32)o).array); + } + /** * Makes this array have a value identical to 'src' * 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 f93cb29125..bde56c68a2 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 @@ -19,36 +19,19 @@ package boofcv.struct.packed; import boofcv.misc.BoofLambdas; -import boofcv.struct.PackedArray; import georegression.struct.point.Point3D_F64; -import lombok.Getter; -import org.ddogleg.struct.DogArray_F64; /** * Packed array of {@link Point3D_F64}. Internally the point is stored in an interleaved format. * * @author Peter Abeles */ -public class PackedArrayPoint3D_F64 implements PackedArray { - private static final int DOF = 3; - - /** Stores tuple in a single continuous array */ - @Getter private final DogArray_F64 array; - +public class PackedArrayPoint3D_F64 extends PackedArray_F64 { // tuple that the result is temporarily written to private final Point3D_F64 temp = new Point3D_F64(); public PackedArrayPoint3D_F64() { - array = new DogArray_F64(); - array.resize(0); - } - - @Override public void reset() { - array.reset(); - } - - @Override public void reserve( int numTuples ) { - array.reserve(numTuples*2); + super(3, 0); } @Override public void append( Point3D_F64 element ) { @@ -90,10 +73,6 @@ public void append( double x, double y, double z) { dst.setTo(src); } - @Override public int size() { - return array.size/3; - } - @Override public Class getElementType() { return Point3D_F64.class; } 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 ae2b6ba61c..3bc721e1ad 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 @@ -19,28 +19,19 @@ package boofcv.struct.packed; import boofcv.misc.BoofLambdas; -import boofcv.struct.PackedArray; import georegression.struct.point.Point4D_F64; -import lombok.Getter; -import org.ddogleg.struct.DogArray_F64; /** * Packed array of {@link Point4D_F64}. Internally the point is stored in an interleaved format. * * @author Peter Abeles */ -public class PackedArrayPoint4D_F64 implements PackedArray { - private static final int DOF = 4; - - /** Stores tuple in a single continuous array */ - @Getter private final DogArray_F64 array; - +public class PackedArrayPoint4D_F64 extends PackedArray_F64 { // tuple that the result is temporarily written to private final Point4D_F64 temp = new Point4D_F64(); public PackedArrayPoint4D_F64() { - array = new DogArray_F64(); - array.resize(0); + super(4, 0); } @Override public void reset() { @@ -95,10 +86,6 @@ public void append( double x, double y, double z, double w ) { dst.setTo(src); } - @Override public int size() { - return array.size/4; - } - @Override public Class getElementType() { return Point4D_F64.class; } diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArray_F64.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArray_F64.java new file mode 100644 index 0000000000..9cf2423070 --- /dev/null +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedArray_F64.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024, Peter Abeles. All Rights Reserved. + * + * This file is part of BoofCV (http://boofcv.org). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package boofcv.struct.packed; + +import boofcv.struct.PackedArray; +import lombok.Getter; +import org.ddogleg.struct.DogArray_F64; + +public abstract class PackedArray_F64 implements PackedArray { + /** Degrees of freedom */ + protected final int DOF; + + /** Stores tuple in a single continuous array */ + @Getter protected final DogArray_F64 array; + + public PackedArray_F64( int DOF, int length ) { + this.DOF = DOF; + this.array = new DogArray_F64(length); + } + + @Override public void reset() { + array.reset(); + } + + @Override public void reserve( int numTuples ) { + array.reserve(numTuples*DOF); + } + + @Override public int size() { + return array.size/DOF; + } + + @Override public boolean isEquals( PackedArray b ) {return array.isEquals(((PackedArray_F64)b).array);} + + /** True if the two arrays are equal to within the specified tolerance */ + public boolean isEquals( PackedArray b, double tol ) {return array.isEquals(((PackedArray_F64)b).array, tol);} +} 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 de6cf7f48f..2dc7008fb8 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 @@ -19,10 +19,7 @@ package boofcv.struct.packed; 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; /** @@ -30,12 +27,7 @@ * * @author Peter Abeles */ -public class PackedBigArrayPoint2D_F64 implements PackedArray { - private static final int DOF = 2; - - /** Storage for the raw data in an array */ - @Getter private final BigDogArray_F64 array; - +public class PackedBigArrayPoint2D_F64 extends PackedBigArray_F64 { // tuple that the result is temporarily written to private final Point2D_F64 temp = new Point2D_F64(); @@ -59,7 +51,7 @@ public PackedBigArrayPoint2D_F64( int reservedPoints ) { * @param growth Growth strategy to use */ public PackedBigArrayPoint2D_F64( int reservedPoints, int blockSize, BigDogGrowth growth ) { - array = new BigDogArray_F64(reservedPoints*DOF, blockSize*DOF, growth); + super(2, reservedPoints, blockSize, growth); } /** @@ -75,14 +67,6 @@ public PackedBigArrayPoint2D_F64 setTo( PackedBigArrayPoint2D_F64 src ) { return this; } - @Override public void reset() { - array.reset(); - } - - @Override public void reserve( int numPoints ) { - array.reserve(numPoints*DOF); - } - public void append( double x, double y ) { array.add(x); array.add(y); @@ -123,14 +107,6 @@ public void append( double x, double y ) { dst.setTo(src); } - @Override public int size() { - return array.size/2; - } - - @Override public Class getElementType() { - return Point2D_F64.class; - } - @Override public void forIdx( int idx0, int idx1, BoofLambdas.ProcessIndex op ) { array.processByBlock(idx0*DOF, idx1*DOF, ( array, arrayIdx0, arrayIdx1, offset ) -> { int pointIndex = idx0 + offset/DOF; @@ -143,4 +119,8 @@ public void append( double x, double y ) { } }); } + + @Override public Class getElementType() { + return Point2D_F64.class; + } } 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 b6a2326220..3c1163a798 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 @@ -19,11 +19,8 @@ package boofcv.struct.packed; import boofcv.misc.BoofLambdas; -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; import java.util.Collection; @@ -33,15 +30,10 @@ * * @author Peter Abeles */ -public class PackedBigArrayPoint3D_F64 implements PackedArray { - private static final int DOF = 3; - +public class PackedBigArrayPoint3D_F64 extends PackedBigArray_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 */ - @Getter private final BigDogArray_F64 array; - /** * Constructor where the default is used for all parameters. */ @@ -64,7 +56,7 @@ public PackedBigArrayPoint3D_F64( int reservedPoints ) { * @param growth Growth strategy to use */ public PackedBigArrayPoint3D_F64( int reservedPoints, int blockSize, BigDogGrowth growth ) { - array = new BigDogArray_F64(reservedPoints*DOF, blockSize*DOF, growth); + super(3, reservedPoints, blockSize, growth); } /** @@ -80,14 +72,6 @@ public PackedBigArrayPoint3D_F64 setTo( PackedBigArrayPoint3D_F64 src ) { return this; } - @Override public void reset() { - array.reset(); - } - - @Override public void reserve( int numPoints ) { - array.reserve(numPoints*DOF); - } - public void append( double x, double y, double z ) { array.add(x); array.add(y); 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 cd0f55f79a..62dfab8146 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 @@ -19,10 +19,8 @@ package boofcv.struct.packed; 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; /** @@ -30,12 +28,7 @@ * * @author Peter Abeles */ -public class PackedBigArrayPoint4D_F64 implements PackedArray { - private static final int DOF = 4; - - // Storage for the raw data in an array - private final BigDogArray_F64 array; - +public class PackedBigArrayPoint4D_F64 extends PackedBigArray_F64 { /** Storage for the raw data in an array */ @Getter private final Point4D_F64 temp = new Point4D_F64(); @@ -61,7 +54,7 @@ public PackedBigArrayPoint4D_F64( int reservedPoints ) { * @param growth Growth strategy to use */ public PackedBigArrayPoint4D_F64( int reservedPoints, int blockSize, BigDogGrowth growth ) { - array = new BigDogArray_F64(reservedPoints*DOF, blockSize*DOF, growth); + super(4, reservedPoints, blockSize, growth); } /** @@ -77,14 +70,6 @@ public PackedBigArrayPoint4D_F64 setTo( PackedBigArrayPoint4D_F64 src ) { return this; } - @Override public void reset() { - array.reset(); - } - - @Override public void reserve( int numPoints ) { - array.reserve(numPoints*DOF); - } - public void append( double x, double y, double z, double w ) { array.add(x); array.add(y); diff --git a/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArray_F64.java b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArray_F64.java new file mode 100644 index 0000000000..686abf9609 --- /dev/null +++ b/main/boofcv-types/src/main/java/boofcv/struct/packed/PackedBigArray_F64.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024, Peter Abeles. All Rights Reserved. + * + * This file is part of BoofCV (http://boofcv.org). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package boofcv.struct.packed; + +import boofcv.struct.PackedArray; +import lombok.Getter; +import org.ddogleg.struct.BigDogArray_F64; +import org.ddogleg.struct.BigDogGrowth; + +public abstract class PackedBigArray_F64 implements PackedArray { + /** Degrees of freedom */ + protected final int DOF; + + /** Stores tuple in a single continuous array */ + @Getter protected final BigDogArray_F64 array; + + public PackedBigArray_F64( int DOF, int reservedPoints, int blockSize, BigDogGrowth growth ) { + this.DOF = DOF; + this.array = new BigDogArray_F64(reservedPoints*DOF, blockSize*DOF, growth); + } + + @Override public void reset() { + array.reset(); + } + + @Override public void reserve( int numTuples ) { + array.reserve(numTuples*DOF); + } + + @Override public int size() { + return array.size/DOF; + } + + @Override public boolean isEquals( PackedArray b ) {return array.isEquivalent(((PackedBigArray_F64)b).array, 0.0);} + + /** True if the two arrays are equal to within the specified tolerance */ + public boolean isEquals( PackedArray b, double tol ) {return array.isEquivalent(((PackedBigArray_F64)b).array, tol);} +} 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 f450fdf21f..70e46cf860 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 @@ -26,8 +26,7 @@ import java.util.ArrayList; import java.util.List; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.*; /** * Common tests for implementations of {@link PackedArray}. @@ -135,7 +134,7 @@ public abstract class GenericPackedArrayChecks extends BoofStandardJUnit { List found = new ArrayList<>(); DogArray_I32 indexes = new DogArray_I32(); - array.forIdx(2,array.size()-1, (idx, point)->{ + array.forIdx(2, array.size() - 1, ( idx, point ) -> { T copy = createRandomPoint(); array.copy(point, copy); found.add(copy); @@ -144,8 +143,8 @@ public abstract class GenericPackedArrayChecks extends BoofStandardJUnit { assertEquals(23, indexes.size); for (int i = 0; i < indexes.size; i++) { - assertEquals(i+2, indexes.get(i)); - checkEquals(array.getTemp(i+2), found.get(i)); + assertEquals(i + 2, indexes.get(i)); + checkEquals(array.getTemp(i + 2), found.get(i)); } } @@ -163,4 +162,19 @@ public abstract class GenericPackedArrayChecks extends BoofStandardJUnit { } @Test void setTo_Standard() {checkSetTo(createAlg().getClass(), true);} + + @Test void isEquals() { + PackedArray a = createAlg(); + PackedArray b = createAlg(); + + assertTrue(a.isEquals(b)); + + for (int i = 0; i < 4; i++) { + T p = createRandomPoint(); + a.append(p); + assertFalse(a.isEquals(b)); + b.append(p); + assertTrue(a.isEquals(b)); + } + } }