use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class TestDisparityToColorPointCloud method doesItCrash.
/**
* Simple test to see if it crashes. Very little validation of results is done
*/
@Test
void doesItCrash() {
double baseline = 1.0;
DMatrixRMaj K = PerspectiveOps.pinholeToMatrix(500.0, 500, 0, 250, 250);
DMatrixRMaj rectifiedR = CommonOps_DDRM.identity(3);
Point2Transform2_F64 rectifiedToColor = new DoNothing2Transform2_F64();
int disparityMin = 2;
int disparityRange = 100;
var alg = new DisparityToColorPointCloud();
alg.configure(baseline, K, rectifiedR, rectifiedToColor, disparityMin, disparityRange);
var disparity = new GrayF32(width, height);
var color = new DisparityToColorPointCloud.ColorImage() {
@Override
public boolean isInBounds(int x, int y) {
return true;
}
@Override
public int getRGB(int x, int y) {
return 0xFF00FF;
}
};
var output = new DogArray<>(Point3dRgbI_F64::new);
alg.process(disparity, color, PointCloudWriter.wrapF64RGB(output));
assertEquals(width * height, output.size);
for (int i = 0; i < output.size; i++) {
assertEquals(0xFF00FF, output.get(i).rgb);
}
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class TestPnPLepetitEPnP method selectControlPoints.
@Test
void selectControlPoints() {
List<Point3D_F64> worldPts = GeoTestingOps.randomPoints_F64(-1, 10, -5, 20, 0.1, 0.5, 30, rand);
DogArray<Point3D_F64> controlPts = new DogArray<>(4, Point3D_F64::new);
PnPLepetitEPnP alg = new PnPLepetitEPnP();
alg.selectWorldControlPoints(worldPts, controlPts);
// check that each row is unique
for (int i = 0; i < 4; i++) {
Point3D_F64 ci = controlPts.get(i);
for (int j = i + 1; j < 4; j++) {
Point3D_F64 cj = controlPts.get(j);
double dx = ci.x - cj.x;
double dy = ci.y - cj.y;
double dz = ci.z - cj.z;
double sum = Math.abs(dx) + Math.abs(dy) + Math.abs(dz);
assertTrue(sum > 0.00001);
}
}
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class TestPnPLepetitEPnP method selectWorldControlPoints_planar.
@Test
void selectWorldControlPoints_planar() {
List<Point3D_F64> worldPts = CommonHomographyChecks.createRandomPlane(rand, 3, 30);
DogArray<Point3D_F64> controlPts = new DogArray<>(4, Point3D_F64::new);
PnPLepetitEPnP alg = new PnPLepetitEPnP();
alg.selectWorldControlPoints(worldPts, controlPts);
assertEquals(3, alg.numControl);
// check that each row is unique
for (int i = 0; i < 3; i++) {
Point3D_F64 ci = controlPts.get(i);
for (int j = i + 1; j < 3; j++) {
Point3D_F64 cj = controlPts.get(j);
double dx = ci.x - cj.x;
double dy = ci.y - cj.y;
double dz = ci.z - cj.z;
double sum = Math.abs(dx) + Math.abs(dy) + Math.abs(dz);
assertTrue(sum > 0.00001);
}
}
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class TestPlyCodec method encode_decode_3DRGB_binary.
@Test
void encode_decode_3DRGB_binary() throws IOException {
List<Point3dRgbI_F64> expected = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int r = (10 * i) & 0xFF;
int g = (28 * i) & 0xFF;
int b = (58 * i) & 0xFF;
int rgb = r << 16 | g << 16 | b;
expected.add(new Point3dRgbI_F64(i * 123.45, i - 1.01, i + 2.34, rgb));
}
for (boolean asFloat : new boolean[] { true, false }) {
DogArray<Point3dRgbI_F64> found = new DogArray<>(Point3dRgbI_F64::new);
ByteArrayOutputStream output = new ByteArrayOutputStream();
PlyCodec.saveBinary(PointCloudReader.wrapF64RGB(expected), ByteOrder.BIG_ENDIAN, false, asFloat, output);
ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
PlyCodec.read(input, PointCloudWriter.wrapF64RGB(found));
assertEquals(expected.size(), found.size);
double tol = asFloat ? UtilEjml.TEST_F32 : UtilEjml.TEST_F64;
for (int i = 0; i < found.size; i++) {
assertEquals(0.0, found.get(i).distance(expected.get(i)), tol);
}
}
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class SerializeFieldsYamlBase method deserializeFastAccess.
private void deserializeFastAccess(Object parent, Map<String, Object> state, String key, Field f) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
// See if the list is empty and there's nothing to do
List listOfStates = (List) state.get(key);
if (listOfStates.isEmpty())
return;
// See if we are dealing with a regular array or DogArray
if (FastArray.class.isAssignableFrom(f.get(parent).getClass())) {
FastArray<Object> plist = (FastArray<Object>) f.get(parent);
Class<?> itemType = plist.type;
boolean basic = itemType.isEnum() || itemType.isPrimitive() || itemType.getName().equals("java.lang.String");
// deserialize each element and add it to the list
plist.reset();
for (int i = 0; i < listOfStates.size(); i++) {
Object value = listOfStates.get(i);
if (basic) {
// since numeric values are stored as objects this should work too. Not tested.
if (itemType.isEnum())
plist.add(Enum.valueOf((Class) itemType, (String) value));
else
plist.add(value);
} else {
Object dst = itemType.getConstructor().newInstance();
deserialize(dst, (Map) value);
plist.add(dst);
}
}
} else {
DogArray<Object> plist = (DogArray<Object>) f.get(parent);
// predeclare all the required elements
plist.resetResize(listOfStates.size());
// deserialize each element and add it to the list
for (int i = 0; i < listOfStates.size(); i++) {
Object value = listOfStates.get(i);
Object dst = plist.get(i);
deserialize(dst, (Map) value);
}
}
}
Aggregations