DeepSDFStruct.flexisquares.flexisquares#

Classes

FlexiSquares([device, qef_reg_scale, ...])

Implements the 2D variant of the DeepSDFStruct.flexicubes method, adapted as DeepSDFStruct.flexisquares, for extracting contour meshes from scalar fields.

class DeepSDFStruct.flexisquares.flexisquares.FlexiSquares(device='cuda', qef_reg_scale=0.001, weight_scale=0.99)#

Bases: object

Implements the 2D variant of the DeepSDFStruct.flexicubes method, adapted as DeepSDFStruct.flexisquares, for extracting contour meshes from scalar fields. This class uses lookup tables and indexed operations to perform differentiable isocontour extraction from signed distance fields defined on 2D grids.

DeepSDFStruct.flexisquares is a differentiable variant of the Dual Marching Squares (DMS) algorithm. It improves geometric fidelity by optimizing surface representations using gradient-based methods.

During initialization, the class loads precomputed lookup tables from DeepSDFStruct.flexisquares and converts them into PyTorch tensors on the specified device.

device#

Computational device, usually “cuda” or “cpu”.

Type:

str

dmc_table#

Dual Marching Squares (DMS) table encoding the edges associated with each dual vertex in 16 possible Marching Squares configurations.

Type:

torch.Tensor

num_vd_table#

Table holding the number of dual vertices for each configuration.

Type:

torch.Tensor

tet_table#

Lookup table used during triangle generation inside the contour.

Type:

torch.Tensor

cube_corners#

Positions of the four corners of a unit square in 2D space

Type:

torch.Tensor

cube_corners_idx#

Corner indices encoded as binary powers to compute case IDs for Marching Squares.

Type:

torch.Tensor

cube_edges#

Edge connections in a square, listed in pairs of corner indices.

Type:

torch.Tensor

construct_voxel_grid(resolution, bounds=None)#

Generates a 2D grid of vertices and their square indices given the specified resolution.

Parameters:
  • resolution (int or list[int]) – Resolution of the 2D grid. If an integer is provided, it is applied to both x and y dimensions. If a tuple/list of two integers is given, they specify (x_res, y_res).

  • bounds (torch.Tensor, optional) – 2×2 tensor defining the [min, max] bounds in x and y. Defaults to [[-0.05, -0.05], [1.05, 1.05]].

Returns:

Tuple containing:
  • Vertices (N×2): Scaled vertex coordinates of the 2D grid.

  • Squares (F×4): Indices into vertices defining each square’s corner connectivity.

Return type:

(torch.Tensor, torch.Tensor)