Skip to content

Impl marching cubes - #70

Closed
micampbell wants to merge 3 commits into
masterfrom
implMarchingCubes
Closed

Impl marching cubes#70
micampbell wants to merge 3 commits into
masterfrom
implMarchingCubes

Conversation

@micampbell

Copy link
Copy Markdown
Member

No description provided.

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 * Vector4 and Matrix4x4.Solve(Vector4) extension helpers in Numerics.
  • Update marching-cubes implicit generation to precompute axis intersections and tessellate only candidate cubes; expose cube processing as virtual and add identifier→indices decoding.
  • Refactor/replace the SQP-based quadric distance computation to use Matrix4x4/Vector4 solves.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

FileDescription
TessellationAndVoxelizationGeometryLibrary/Numerics/Extensions.csAdds matrix→vector multiplication and Ax=b solve helpers for 4x4 systems.
TessellationAndVoxelizationGeometryLibrary/MarchingCubes/MarchingCubes.Implicit.csChanges implicit marching-cubes generation to focus cube processing around precomputed intersections and overrides cube face generation.
TessellationAndVoxelizationGeometryLibrary/MarchingCubes/MarchingCubes.Base.csAdds identifier decoding helper, makes cube processing virtual, and alters value caching behavior.
TessellationAndVoxelizationGeometryLibrary/Implicits and Primitives/Primitive Surfaces/GeneralQuadric.csUpdates 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;
@micampbell

Copy link
Copy Markdown
MemberAuthor

code has already been merged

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@micampbell