|
25 | 25 | import java.util.zip.*; |
26 | 26 |
|
27 | 27 | public class ManifoldBindings { |
| 28 | + public enum ManifoldError { |
| 29 | + NO_ERROR, NON_FINITE_VERTEX, NOT_MANIFOLD, VERTEX_INDEX_OUT_OF_BOUNDS, PROPERTIES_WRONG_LENGTH, |
| 30 | + MISSING_POSITION_PROPERTIES, MERGE_VECTORS_DIFFERENT_LENGTHS, MERGE_INDEX_OUT_OF_BOUNDS, TRANSFORM_WRONG_LENGTH, |
| 31 | + RUN_INDEX_WRONG_LENGTH, FACE_ID_WRONG_LENGTH, INVALID_CONSTRUCTION, RESULT_TOO_LARGE; |
| 32 | + |
| 33 | + public static ManifoldError fromInt(int code) { |
| 34 | + ManifoldError[] values = values(); |
| 35 | + if (code < 0 || code >= values.length) |
| 36 | + throw new IllegalArgumentException("Unknown ManifoldError code: " + code); |
| 37 | + return values[code]; |
| 38 | + } |
| 39 | + } |
28 | 40 |
|
29 | 41 | private static boolean loaded = false; |
30 | 42 |
|
@@ -296,9 +308,8 @@ public ManifoldBindings(File cacheDirectory) throws Exception { |
296 | 308 | load("manifold_polygons_simple_length", ValueLayout.JAVA_LONG, ValueLayout.ADDRESS, ValueLayout.JAVA_LONG); |
297 | 309 | // ManifoldVec2 manifold_polygons_get_point(ManifoldPolygons* ps, size_t simple_idx, size_t pt_idx); |
298 | 310 | // ManifoldVec2 = {double x, double y} = 16 bytes, returned by value |
299 | | - load("manifold_polygons_get_point", |
300 | | - MemoryLayout.structLayout(ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE), |
301 | | - ValueLayout.ADDRESS, ValueLayout.JAVA_LONG, ValueLayout.JAVA_LONG); |
| 311 | + load("manifold_polygons_get_point", MemoryLayout.structLayout(ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE), |
| 312 | + ValueLayout.ADDRESS, ValueLayout.JAVA_LONG, ValueLayout.JAVA_LONG); |
302 | 313 | // ManifoldPolygons* manifold_alloc_polygons(); |
303 | 314 | load("manifold_alloc_polygons", ValueLayout.ADDRESS); |
304 | 315 |
|
@@ -493,7 +504,11 @@ public ManifoldBindings(File cacheDirectory) throws Exception { |
493 | 504 |
|
494 | 505 | } |
495 | 506 |
|
496 | | - |
| 507 | + // ManifoldError manifold_status(ManifoldManifold* m); |
| 508 | + public ManifoldError status(MemorySegment m) throws Throwable { |
| 509 | + int code = (int) functions.get("manifold_status").invoke(m); |
| 510 | + return ManifoldError.fromInt(code); |
| 511 | + } |
497 | 512 |
|
498 | 513 | public ArrayList<double[][]> slice(MemorySegment m, double height) throws Throwable { |
499 | 514 | MemorySegment polygons = null; |
@@ -531,7 +546,7 @@ public ArrayList<double[][]> slice(MemorySegment m, double height) throws Throwa |
531 | 546 | } |
532 | 547 | } |
533 | 548 |
|
534 | | - public void deleteMeshGL64(MemorySegment seg) { |
| 549 | + private void deleteMeshGL64(MemorySegment seg) { |
535 | 550 | if (seg == null) |
536 | 551 | return; |
537 | 552 | try { |
@@ -919,6 +934,7 @@ public MemorySegment hull(MemorySegment m) throws Throwable { |
919 | 934 | MemorySegment mem = (MemorySegment) functions.get("manifold_alloc_manifold").invoke(); |
920 | 935 | return (MemorySegment) functions.get("manifold_hull").invoke(mem, m); |
921 | 936 | } |
| 937 | + |
922 | 938 | /** |
923 | 939 | * Computes the convex hull of a set of points. |
924 | 940 | * |
@@ -965,6 +981,7 @@ public MemorySegment hull(ArrayList<double[]> points) throws Throwable { |
965 | 981 | return (MemorySegment) functions.get("manifold_hull_pts").invoke(mem, ptsBuffer, count); |
966 | 982 | } |
967 | 983 | } |
| 984 | + |
968 | 985 | // ManifoldManifold* manifold_batch_hull(void* mem, ManifoldManifoldVec* ms); |
969 | 986 | public MemorySegment batchHull(MemorySegment[] shapes) throws Throwable { |
970 | 987 | MemorySegment vec = (MemorySegment) functions.get("manifold_alloc_manifold_vec").invoke(); |
@@ -1031,13 +1048,6 @@ public MemorySegment[] split(MemorySegment a, MemorySegment b) throws Throwable |
1031 | 1048 | } |
1032 | 1049 | } |
1033 | 1050 |
|
1034 | | - // Placeholder |
1035 | | - // public MemorySegment[] decompose(MemorySegment m) throws Throwable { |
1036 | | - // MemorySegment mem = (MemorySegment) functions.get("manifold_alloc_manifold_vec").invoke(); |
1037 | | - // MemorySegment vec = (MemorySegment) functions.get("manifold_decompose").invoke(mem, m); |
1038 | | - // TODO: Needs vector access functions to implement |
1039 | | - // return new MemorySegment[]{m}; |
1040 | | - // } |
1041 | 1051 |
|
1042 | 1052 | // Creates an independent copy (safe for boolean operations) |
1043 | 1053 | // ManifoldManifold* manifold_copy(void* mem, ManifoldManifold* m); |
@@ -1091,12 +1101,12 @@ public MemorySegment importMeshGL(float[] vertices, int[] triangles, long nVerts |
1091 | 1101 |
|
1092 | 1102 | manMem = (MemorySegment) functions.get("manifold_alloc_manifold").invoke(); |
1093 | 1103 | manifold = (MemorySegment) functions.get("manifold_of_meshgl").invoke(manMem, merged); |
1094 | | -// System.out.println("meshGLMem addr: " + meshGLMem.address()); |
1095 | | -// System.out.println("meshGL addr: " + meshGL.address()); |
1096 | | -// System.out.println("mergedMem addr: " + mergedMem.address()); |
1097 | | -// System.out.println("merged addr: " + merged.address()); |
1098 | | -// System.out.println("manMem addr: " + manMem.address()); |
1099 | | -// System.out.println("manifold addr: " + manifold.address()); |
| 1104 | + // System.out.println("meshGLMem addr: " + meshGLMem.address()); |
| 1105 | + // System.out.println("meshGL addr: " + meshGL.address()); |
| 1106 | + // System.out.println("mergedMem addr: " + mergedMem.address()); |
| 1107 | + // System.out.println("merged addr: " + merged.address()); |
| 1108 | + // System.out.println("manMem addr: " + manMem.address()); |
| 1109 | + // System.out.println("manifold addr: " + manifold.address()); |
1100 | 1110 | return manifold; |
1101 | 1111 |
|
1102 | 1112 | } finally { |
@@ -1295,11 +1305,11 @@ public long estimateMemoryBytes(MemorySegment m) throws Throwable { |
1295 | 1305 | //private HashMap<MemorySegment,Exception> deleted = new HashMap<>(); |
1296 | 1306 |
|
1297 | 1307 | public void delete(MemorySegment manifold) throws Throwable { |
1298 | | -// if (deleted.containsKey(manifold)) { |
1299 | | -// System.err.println("Memory was deleted at "); |
1300 | | -// deleted.get(manifold).printStackTrace(); |
1301 | | -// throw new DoubleFreeException(); |
1302 | | -// } |
| 1308 | + // if (deleted.containsKey(manifold)) { |
| 1309 | + // System.err.println("Memory was deleted at "); |
| 1310 | + // deleted.get(manifold).printStackTrace(); |
| 1311 | + // throw new DoubleFreeException(); |
| 1312 | + // } |
1303 | 1313 | functions.get("manifold_delete_manifold").invoke(manifold); |
1304 | 1314 | //deleted.put(manifold, new Exception()); |
1305 | 1315 | } |
|
0 commit comments