/** * Inspired from the SL-decomposition in the paper * <a href="https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=0ahUKEwjZlOab96XPAhXBQD4KHcXeB4MQFggsMAE&url=https%3A%2F%2Fparasol.tamu.edu%2Fpublications%2Fdownload.php%3Ffile_id%3D390&usg=AFQjCNF3wXvuCxXNREhu4CW-oNyd1caa0A&sig2=X-zxaHykED7EuqkYhkfUgg"> * Approximate Convex Decomposition of Polygons</a>. * @param concaveHullCollection [input] the collection of concave hulls to be decomposed into convex polygons. * @param depthThreshold [input] the algorithm determines whether the polygon is to split or not by looking at the maximum depth of concave pockets in the concave hull. * When a pocket is deeper than {@code depthThreshold} the concave hull will be split in two. * Otherwise, the pocket vertices will be removed. * @param convexPolygonsToPack [output] the convex polygons approximating the concave hull. */ public static void recursiveApproximateDecomposition(ConcaveHullCollection concaveHullCollection, double depthThreshold, List<ConvexPolygon2D> convexPolygonsToPack) { for (ConcaveHull concaveHull : concaveHullCollection) recursiveApproximateDecomposition(concaveHull.getConcaveHullVertices(), depthThreshold, convexPolygonsToPack); }
/** * Inspired from the SL-decomposition in the paper * <a href="https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=0ahUKEwjZlOab96XPAhXBQD4KHcXeB4MQFggsMAE&url=https%3A%2F%2Fparasol.tamu.edu%2Fpublications%2Fdownload.php%3Ffile_id%3D390&usg=AFQjCNF3wXvuCxXNREhu4CW-oNyd1caa0A&sig2=X-zxaHykED7EuqkYhkfUgg"> * Approximate Convex Decomposition of Polygons</a>. * @param concaveHullVertices [input] the concave hull to be decomposed into convex polygons. * @param depthThreshold [input] the algorithm determines whether the polygon is to split or not by looking at the maximum depth of concave pockets in the concave hull. * When a pocket is deeper than {@code depthThreshold} the concave hull will be split in two. * Otherwise, the pocket vertices will be removed. * @param convexPolygonsToPack [output] the convex polygons approximating the concave hull. */ public static void recursiveApproximateDecomposition(List<? extends Point2DReadOnly> concaveHullVertices, double depthThreshold, List<ConvexPolygon2D> convexPolygonsToPack) { recursiveApproximateDecompositionInternal(new ArrayList<>(concaveHullVertices), depthThreshold, convexPolygonsToPack); }
/** * Inspired from the SL-decomposition in the paper * <a href="https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=0ahUKEwjZlOab96XPAhXBQD4KHcXeB4MQFggsMAE&url=https%3A%2F%2Fparasol.tamu.edu%2Fpublications%2Fdownload.php%3Ffile_id%3D390&usg=AFQjCNF3wXvuCxXNREhu4CW-oNyd1caa0A&sig2=X-zxaHykED7EuqkYhkfUgg"> * Approximate Convex Decomposition of Polygons</a>. * @param concaveHull [input] the concave hull to be decomposed into convex polygons. * @param depthThreshold [input] the algorithm determines whether the polygon is to split or not by looking at the maximum depth of concave pockets in the concave hull. * When a pocket is deeper than {@code depthThreshold} the concave hull will be split in two. * Otherwise, the pocket vertices will be removed. * @param convexPolygonsToPack [output] the convex polygons approximating the concave hull. */ public static void recursiveApproximateDecomposition(ConcaveHull concaveHull, double depthThreshold, List<ConvexPolygon2D> convexPolygonsToPack) { recursiveApproximateDecomposition(concaveHull.getConcaveHullVertices(), depthThreshold, convexPolygonsToPack); }
private Node createConvexDecompositionGraphics(PlanarRegionSegmentationRawData rawData, ConcaveHullFactoryResult concaveHullFactoryResult) { ConcaveHullCollection concaveHullCollection = concaveHullFactoryResult.getConcaveHullCollection(); double depthThreshold = polygonizerParameters.getDepthThreshold(); List<ConvexPolygon2D> convexPolygons = new ArrayList<>(); ConcaveHullDecomposition.recursiveApproximateDecomposition(concaveHullCollection, depthThreshold, convexPolygons); JavaFXMultiColorMeshBuilder meshBuilder = new JavaFXMultiColorMeshBuilder(new TextureColorAdaptivePalette(64)); int regionId = rawData.getRegionId(); RigidBodyTransform rigidBodyTransform = rawData.getTransformFromLocalToWorld(); Color regionColor = OcTreeMeshBuilder.getRegionColor(regionId); for (int i = 0; i < convexPolygons.size(); i++) { ConvexPolygon2D convexPolygon = convexPolygons.get(i); Color color = Color.hsb(regionColor.getHue(), 0.9, 0.5 + 0.5 * ((double) i / (double) convexPolygons.size())); meshBuilder.addPolygon(rigidBodyTransform, convexPolygon, color); } MeshView meshView = new MeshView(meshBuilder.generateMesh()); meshView.setMaterial(meshBuilder.generateMaterial()); return meshView; }
ConcaveHullDecomposition.recursiveApproximateDecomposition(concaveHull, depthThreshold, decomposedPolygons);
.recursiveApproximateDecomposition(new ArrayList<>(truncatedConcaveHullVertices), depthThresholdForConvexDecomposition, truncatedConvexPolygons);
recursiveApproximateDecomposition(p1, depthThreshold, convexPolygonsToPack); recursiveApproximateDecomposition(p2, depthThreshold, convexPolygonsToPack);
double depthThreshold = 0.05; List<ConvexPolygon2D> convexPolygons = new ArrayList<>(); ConcaveHullDecomposition.recursiveApproximateDecomposition(concaveHullVertices, depthThreshold, convexPolygons);