Skip to content

Commit 157fee6

Browse files
committed
add extractInnerVertices()
1 parent 1935eca commit 157fee6

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

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

10+
**Version 2 is built with Java 17**
11+
1012
### Added
1113
* `findShortestTour()` to `PGS_PointSet`. Computes an <i>approximate</i> Traveling Salesman path for a set of points.
1214
* `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()`.
@@ -16,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1618
* `fix()` to `PGS_Processing`. Attempts to fix shapes with invalid geometry.
1719
* Additional method signature for `frontChainPack()` that accepts a random seed.
1820
* `isClockwise()` to `PGS_ShapePredicates`. Determines if the vertices of the specified shape form a clockwise loop.
21+
* `extractInnerVertices()` to `PGS_Meshing`. Extracts all inner vertices from a mesh.
1922

2023
### Changes
2124
* Packed circles from `PGS_CirclePacking.stochasticPack()` will now always lie within shape bounds.

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,13 @@ Much of the functionality (but by no means all) is demonstrated below:
546546
<td valign="top" width="25%"><img src="resources/meshing/areaMerge.gif"></td>
547547
<td valign="top" width="25%"><img src="resources/meshing/innerEdges.gif"></td>
548548
</tr>
549+
550+
<tr>
551+
<td align="center" valign="center"><b>Extract Inner Vertices</td>
552+
</tr>
553+
<tr>
554+
<td valign="top" width="25%"><img src="resources/meshing/extractInnerVertices.gif"></td>
555+
</tr>
549556
</table>
550557

551558
## *Geometric Optimisation*
43.1 KB
Loading

src/main/java/micycle/pgs/PGS_Meshing.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,25 @@ public static PShape extractInnerEdges(PShape mesh) {
812812
return PGS_SegmentSet.dissolve(innerEdges);
813813
}
814814

815+
/**
816+
* Extracts the inner vertices from a mesh. Inner vertices are defined as
817+
* vertices that are not part of the perimeter (nor holes) of the mesh.
818+
*
819+
* @param mesh The mesh shape to extract inner vertices from.
820+
* @return A PShape object containing only the inner vertices of the original
821+
* mesh.
822+
* @since 2.0
823+
*/
824+
public static List<PVector> extractInnerVertices(PShape mesh) {
825+
var allVertices = PGS_Conversion.toPVector(mesh);
826+
var perimeterVertices = PGS_Conversion.toPVector(PGS_ShapeBoolean.unionMesh(mesh));
827+
var allVerticesSet = new HashSet<>(allVertices);
828+
var perimeterVerticesSet = new HashSet<>(perimeterVertices);
829+
830+
allVerticesSet.removeAll(perimeterVerticesSet);
831+
return new ArrayList<>(allVerticesSet);
832+
}
833+
815834
/**
816835
* Merges the small faces within a mesh into their adjacent faces recursively,
817836
* ensuring that no faces smaller than a specified area remain. This process is
@@ -867,8 +886,11 @@ public static PShape splitEdges(PShape split, int parts) {
867886
return PGS.polygonizeEdges(splitEdges);
868887
}
869888

889+
/**
890+
* Applies the styling properties of oldMesh to newMesh.
891+
*/
870892
private static PShape applyOriginalStyling(final PShape newMesh, final PShape oldMesh) {
871-
final PShapeData data = new PShapeData(oldMesh.getChild(0)); // use first child; assume global.
893+
final PShapeData data = new PShapeData(oldMesh.getChildCount() > 0 ? oldMesh.getChild(0) : oldMesh); // note use first child
872894
for (int i = 0; i < newMesh.getChildCount(); i++) {
873895
data.applyTo(newMesh.getChild(i));
874896
}

0 commit comments

Comments
 (0)