Skip to content

Commit

Permalink
add extractInnerVertices()
Browse files Browse the repository at this point in the history
  • Loading branch information
micycle1 committed Aug 10, 2024
1 parent 1935eca commit 157fee6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## **2.0** *(2024-08-xx)*

**Version 2 is built with Java 17**

### Added
* `findShortestTour()` to `PGS_PointSet`. Computes an <i>approximate</i> Traveling Salesman path for a set of points.
* `pruneSparsePoints()` to `PGS_PointSet`. Prunes a list of points by removing points that are considered not sufficiently dense (far away from their nearest neighbours); a counterpart to `prunePointsWithinDistance()`.
Expand All @@ -16,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `fix()` to `PGS_Processing`. Attempts to fix shapes with invalid geometry.
* Additional method signature for `frontChainPack()` that accepts a random seed.
* `isClockwise()` to `PGS_ShapePredicates`. Determines if the vertices of the specified shape form a clockwise loop.
* `extractInnerVertices()` to `PGS_Meshing`. Extracts all inner vertices from a mesh.

### Changes
* Packed circles from `PGS_CirclePacking.stochasticPack()` will now always lie within shape bounds.
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,13 @@ Much of the functionality (but by no means all) is demonstrated below:
<td valign="top" width="25%"><img src="resources/meshing/areaMerge.gif"></td>
<td valign="top" width="25%"><img src="resources/meshing/innerEdges.gif"></td>
</tr>

<tr>
<td align="center" valign="center"><b>Extract Inner Vertices</td>
</tr>
<tr>
<td valign="top" width="25%"><img src="resources/meshing/extractInnerVertices.gif"></td>
</tr>
</table>

## *Geometric Optimisation*
Expand Down
Binary file added resources/meshing/extractInnerVertices.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion src/main/java/micycle/pgs/PGS_Meshing.java
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,25 @@ public static PShape extractInnerEdges(PShape mesh) {
return PGS_SegmentSet.dissolve(innerEdges);
}

/**
* Extracts the inner vertices from a mesh. Inner vertices are defined as
* vertices that are not part of the perimeter (nor holes) of the mesh.
*
* @param mesh The mesh shape to extract inner vertices from.
* @return A PShape object containing only the inner vertices of the original
* mesh.
* @since 2.0
*/
public static List<PVector> extractInnerVertices(PShape mesh) {
var allVertices = PGS_Conversion.toPVector(mesh);
var perimeterVertices = PGS_Conversion.toPVector(PGS_ShapeBoolean.unionMesh(mesh));
var allVerticesSet = new HashSet<>(allVertices);
var perimeterVerticesSet = new HashSet<>(perimeterVertices);

allVerticesSet.removeAll(perimeterVerticesSet);
return new ArrayList<>(allVerticesSet);
}

/**
* Merges the small faces within a mesh into their adjacent faces recursively,
* ensuring that no faces smaller than a specified area remain. This process is
Expand Down Expand Up @@ -867,8 +886,11 @@ public static PShape splitEdges(PShape split, int parts) {
return PGS.polygonizeEdges(splitEdges);
}

/**
* Applies the styling properties of oldMesh to newMesh.
*/
private static PShape applyOriginalStyling(final PShape newMesh, final PShape oldMesh) {
final PShapeData data = new PShapeData(oldMesh.getChild(0)); // use first child; assume global.
final PShapeData data = new PShapeData(oldMesh.getChildCount() > 0 ? oldMesh.getChild(0) : oldMesh); // note use first child
for (int i = 0; i < newMesh.getChildCount(); i++) {
data.applyTo(newMesh.getChild(i));
}
Expand Down

0 comments on commit 157fee6

Please sign in to comment.