use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class ShapeFittingOps method convert_I32_F32.
public static DogArray<Point2D_F32> convert_I32_F32(List<Point2D_I32> input, @Nullable DogArray<Point2D_F32> output) {
if (output == null)
output = new DogArray<>(input.size(), Point2D_F32::new);
else
output.reset();
for (int i = 0; i < input.size(); i++) {
Point2D_I32 p = input.get(i);
output.grow().setTo(p.x, p.y);
}
return output;
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class ShapeFittingOps method fitPolygon.
/**
* <p>Fits a polygon to the provided sequence of connected points. The found polygon is returned as a list of
* vertices. Each point in the original sequence is guaranteed to be within "toleranceDist' of a line segment.</p>
*
* <p>Internally a split-and-merge algorithm is used. See referenced classes for more information. Consider
* using internal algorithms directly if this function is a performance bottleneck.</p>
*
* @param sequence Ordered and connected list of points.
* @param loop If true the sequence is a connected at both ends, otherwise it is assumed to not be.
* @param minimumSideLength The minimum allowed side length in pixels. Try 10
* @param cornerPenalty How much a corner is penalized. Try 0.25
* @return Vertexes in the fit polygon.
* @see PolylineSplitMerge
*/
public static List<PointIndex_I32> fitPolygon(List<Point2D_I32> sequence, boolean loop, int minimumSideLength, double cornerPenalty) {
PolylineSplitMerge alg = new PolylineSplitMerge();
alg.setLoops(loop);
alg.setMinimumSideLength(minimumSideLength);
alg.setCornerScorePenalty(cornerPenalty);
alg.process(sequence);
PolylineSplitMerge.CandidatePolyline best = alg.getBestPolyline();
DogArray<PointIndex_I32> output = new DogArray<>(PointIndex_I32::new);
if (best != null) {
indexToPointIndex(sequence, best.splits, output);
}
return new ArrayList<>(output.toList());
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class PointCloudUtils_F64 method prune.
/**
* Prunes points from the point cloud if they have very few neighbors
*
* @param cloud Point cloud
* @param minNeighbors Minimum number of neighbors for it to not be pruned
* @param radius search distance for neighbors
*/
public static void prune(List<Point3D_F64> cloud, int minNeighbors, double radius) {
if (minNeighbors < 0)
throw new IllegalArgumentException("minNeighbors must be >= 0");
NearestNeighbor<Point3D_F64> nn = FactoryNearestNeighbor.kdtree(new KdTreePoint3D_F64());
NearestNeighbor.Search<Point3D_F64> search = nn.createSearch();
nn.setPoints(cloud, false);
DogArray<NnData<Point3D_F64>> results = new DogArray<>(NnData::new);
// It will always find itself
minNeighbors += 1;
// distance is Euclidean squared
radius *= radius;
for (int i = cloud.size() - 1; i >= 0; i--) {
search.findNearest(cloud.get(i), radius, minNeighbors, results);
if (results.size < minNeighbors) {
cloud.remove(i);
}
}
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class PointCloudUtils_F64 method filter.
/**
* Creates a new list of points while filtering out points
*/
public static DogArray<Point3dRgbI_F64> filter(AccessPointIndex<Point3D_F64> accessPoint, AccessColorIndex accessColor, int size, BoofLambdas.FilterInt filter, @Nullable DogArray<Point3dRgbI_F64> output) {
if (output == null)
output = new DogArray<>(Point3dRgbI_F64::new);
output.reset();
// Guess how much memory is needed
output.reserve(size / 5);
Point3dRgbI_F64 p = output.grow();
for (int pointIdx = 0; pointIdx < size; pointIdx++) {
if (!filter.keep(pointIdx))
continue;
accessPoint.getPoint(pointIdx, p);
p.rgb = accessColor.getRGB(pointIdx);
p = output.grow();
}
output.removeTail();
return output;
}
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);
}
}
}
Aggregations