Impl marching cubes#70
Open
micampbell wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements/updates marching-cubes tessellation for implicit solids and adds supporting numeric utilities intended to enable additional geometry operations (e.g., solving small linear systems for optimization steps).
Changes:
- Add
Matrix4x4 * Vector4andMatrix4x4.Solve(Vector4)extension helpers in Numerics. - Update marching-cubes implicit generation to precompute axis intersections and tessellate only candidate cubes; expose cube processing as
virtualand add identifier→indices decoding. - Refactor/replace the SQP-based quadric distance computation to use
Matrix4x4/Vector4solves.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| TessellationAndVoxelizationGeometryLibrary/Numerics/Extensions.cs | Adds matrix→vector multiplication and Ax=b solve helpers for 4x4 systems. |
| TessellationAndVoxelizationGeometryLibrary/MarchingCubes/MarchingCubes.Implicit.cs | Changes implicit marching-cubes generation to focus cube processing around precomputed intersections and overrides cube face generation. |
| TessellationAndVoxelizationGeometryLibrary/MarchingCubes/MarchingCubes.Base.cs | Adds identifier decoding helper, makes cube processing virtual, and alters value caching behavior. |
| TessellationAndVoxelizationGeometryLibrary/Implicits and Primitives/Primitive Surfaces/GeneralQuadric.cs | Updates SQP distance approach to a Matrix4x4/Vector4-based solve loop. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+323
to
+327
| public override double DistanceToPoint(Vector3 point) | ||
| { | ||
| Vector3 startPoint = GetPointNearQuadric(point); | ||
| double[] u = { startPoint.X, startPoint.Y, startPoint.Z, 0 }; | ||
| double[] du = { double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity }; | ||
| int iters = 0; | ||
| while (iters < 1000 && (du[0] * du[0] + du[1] * du[1] + du[2] * du[2] + du[3] * du[3]) < 1E-6) { | ||
| double[,] H = { { 2 + 2 * XSqdCoeff * u[3], XYCoeff * u[3], XZCoeff * u[3], 2 * XSqdCoeff * u[0] + XYCoeff * u[1] + XZCoeff * u[2] + XCoeff }, | ||
| { XYCoeff * u[3], 2 + 2 * YSqdCoeff * u[3], YZCoeff * u[3], 2 * YSqdCoeff * u[1] + XYCoeff * u[0] + YZCoeff * u[2] + YCoeff }, | ||
| { XZCoeff * u[3], YZCoeff * u[3], 2 + 2 * ZSqdCoeff * u[3], 2 * YSqdCoeff * u[2] + XZCoeff * u[0] + YZCoeff * u[1] + ZCoeff }, | ||
| { 2 * XSqdCoeff * u[0] + XYCoeff * u[1] + XZCoeff * u[2] + XCoeff, 2 * YSqdCoeff * u[1] + XYCoeff * u[0] + YZCoeff * u[2] + YCoeff, 2 * YSqdCoeff * u[2] + XZCoeff * u[0] + YZCoeff * u[1] + ZCoeff, 0} }; | ||
| double[] RHS = { 2 * (u[0] - point.X) + u[3] * (2 * XSqdCoeff * u[0] + XYCoeff * u[1] + XZCoeff * u[2] + XCoeff), | ||
| 2 * (u[1] - point.Y) + 2 * YSqdCoeff * u[1] + XYCoeff * u[0] + YZCoeff * u[2] + YCoeff, | ||
| 2 * (u[2] - point.Z) + 2 * YSqdCoeff * u[2] + XZCoeff * u[0] + YZCoeff * u[1] + ZCoeff, | ||
| QuadricValue(new Vector3(u[..3]))}; | ||
| StarMath.solve(H, RHS, out du, true); | ||
| u[0] += du[0]; | ||
| u[1] += du[1]; | ||
| u[2] += du[2]; | ||
| u[3] += du[3]; | ||
| var closestPt = GetPointOnQuadric(point); | ||
| var closestPt4 = new Vector4(closestPt, 0); // the fourth number "w" here represents the Lagrange multiplier | ||
| var delta = Vector4.Zero; |
Comment on lines
+334
to
+335
| XZCoeff * closestPt4.W, YZCoeff * closestPt4.W, 2 + 2 * ZSqdCoeff * closestPt4.W, 2 * YSqdCoeff * closestPt4.Z + XZCoeff * closestPt4.X + YZCoeff * closestPt4.Y + ZCoeff, | ||
| 2 * XSqdCoeff * closestPt4.X + XYCoeff * closestPt4.Y + XZCoeff * closestPt4.Z + XCoeff, 2 * YSqdCoeff * closestPt4.Y + XYCoeff * closestPt4.X + YZCoeff * closestPt4.Z + YCoeff, 2 * YSqdCoeff * closestPt4.Z + XZCoeff * closestPt4.X + YZCoeff * closestPt4.Y + ZCoeff, 0); |
Comment on lines
+336
to
+340
| var rhs = new Vector4( | ||
| 2 * (closestPt4.X - point.X) + closestPt4.W * (2 * XSqdCoeff * closestPt4.X + XYCoeff * closestPt4.Y + XZCoeff * closestPt4.Z + XCoeff), | ||
| 2 * (closestPt4.Y - point.Y) + 2 * YSqdCoeff * closestPt4.Y + XYCoeff * closestPt4.X + YZCoeff * closestPt4.Z + YCoeff, | ||
| 2 * (closestPt4.Z - point.Z) + 2 * YSqdCoeff * closestPt4.Z + XZCoeff * closestPt4.X + YZCoeff * closestPt4.Y + ZCoeff, | ||
| QuadricValue(closestPt)); |
Comment on lines
257
to
262
| if (valueDictionary.TryGetValue(identifier, out var prevValue)) | ||
| { | ||
| if (prevValue.NumTimesCalled < 7) | ||
| prevValue.NumTimesCalled++; | ||
| else valueDictionary.Remove(identifier); | ||
| //if (prevValue.NumTimesCalled < 7) | ||
| // prevValue.NumTimesCalled++; | ||
| //else valueDictionary.Remove(identifier); | ||
| return prevValue; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.