DeepSDFStruct.sdf_operations#
SDF Operations and Transformations#
This module provides various operations that can be applied to SDFs, including space warping transformations like elongation, twisting, bending, dilation/erosion, and shell creation.
Functions
|
Compute distance from point p to cubic bezier curve using sampling with refinement. |
Classes
|
Bend SDF linearly between two control points. |
|
Bend SDF radially. |
|
Create count copies of an SDF rotated around an arbitrary axis line. |
|
Expand an SDF uniformly by adding material to the surface. |
|
Elongate an SDF by adding material along the coordinate axes. |
|
Contract an SDF uniformly by removing material from the surface. |
|
Reflect an SDF across a plane to create symmetric geometry. |
|
Infinite or finite grid repetition of an SDF. |
|
Revolve a 2D profile around an axis to create a 3D surface of revolution. |
|
Create a hollow shell by keeping only a thin layer around the surface. |
|
Sweep a 2D profile along a cubic bezier curve with flat end caps. |
|
Twist an SDF around the Z-axis by an angle proportional to height. |
- class DeepSDFStruct.sdf_operations.BendLinearSDF(sdf, p0, p1, v)#
Bases:
DeepSDFStruct.SDF.SDFBaseBend SDF linearly between two control points.
- Parameters:
- class DeepSDFStruct.sdf_operations.BendRadialSDF(sdf, r0, r1, dz)#
Bases:
DeepSDFStruct.SDF.SDFBaseBend SDF radially.
- Parameters:
- class DeepSDFStruct.sdf_operations.CircularArraySDF(sdf, count, axis=tensor([0., 0., 1.]), base_point=tensor([0., 0., 0.]), start_angle_deg=0.0, end_angle_deg=360)#
Bases:
DeepSDFStruct.SDF.SDFBaseCreate count copies of an SDF rotated around an arbitrary axis line.
The axis line is defined by an
axisdirection and abase_pointlying on that axis. Copies are sampled at evenly spaced angles in the half-open interval [start_angle, end_angle).- Parameters:
- class DeepSDFStruct.sdf_operations.DilateSDF(sdf, r)#
Bases:
DeepSDFStruct.SDF.SDFBaseExpand an SDF uniformly by adding material to the surface.
Increases the size of the geometry by moving the surface outward by a specified distance. Equivalent to making the object larger while maintaining its shape.
- Parameters:
sdf (SDFBase) – The SDF to expand.
r (float) – Expansion distance. Positive values add material (make larger), negative values remove material (make smaller).
Examples
>>> # Expand a sphere by 0.1 units >>> sphere = SphereSDF(center=[0, 0, 0], radius=0.5) >>> DilateSDF(sphere, r=0.1) # radius effectively becomes 0.6 >>> >>> # Shrink by using negative dilation >>> DilateSDF(sphere, r=-0.1) # radius effectively becomes 0.4
- class DeepSDFStruct.sdf_operations.ElongateSDF(sdf, size)#
Bases:
DeepSDFStruct.SDF.SDFBaseElongate an SDF by adding material along the coordinate axes.
Extends the geometry by adding material in the positive and negative directions along each axis. Useful for creating stretched or extended versions of existing shapes.
- Parameters:
sdf (SDFBase) – The base SDF to elongate.
size (array-like of shape (3,) or float) – Elongation amount along each axis (x, y, z). If a single float, applies uniform elongation in all directions.
Examples
>>> # Elongate a sphere by 0.5 in all directions >>> sphere = SphereSDF(center=[0, 0, 0], radius=0.5) >>> ElongateSDF(sphere, size=0.5) >>> >>> # Elongate more in x-direction than y and z >>> ElongateSDF(sphere, size=[1.0, 0.2, 0.2])
- class DeepSDFStruct.sdf_operations.ErodeSDF(sdf, r)#
Bases:
DeepSDFStruct.SDF.SDFBaseContract an SDF uniformly by removing material from the surface.
Decreases the size of the geometry by moving the surface inward by a specified distance. Equivalent to making the object smaller while maintaining its shape.
- Parameters:
sdf (SDFBase) – The SDF to contract.
r (float) – Contraction distance. Must be positive. For expansion, use DilateSDF instead.
Examples
>>> # Shrink a sphere by 0.1 units >>> sphere = SphereSDF(center=[0, 0, 0], radius=0.5) >>> ErodeSDF(sphere, r=0.1) # radius effectively becomes 0.4 >>> >>> # Create a thin shell by combining with original >>> ErodeSDF(sphere, r=0.05)
- class DeepSDFStruct.sdf_operations.MirrorSDF(sdf, plane_point, plane_normal)#
Bases:
DeepSDFStruct.SDF.SDFBaseReflect an SDF across a plane to create symmetric geometry.
Creates a mirror copy of an SDF across a specified plane, effectively doubling the geometry. The result is the union of the original and reflected SDF, creating a symmetric object.
- Parameters:
sdf (SDFBase) – The SDF to mirror. This will be reflected across the plane.
plane_point (array-like of shape (3,)) – A point that lies on the mirror plane. This point, together with plane_normal, defines the mirror plane.
plane_normal (array-like of shape (3,)) – Normal vector of the mirror plane. The plane is perpendicular to this vector. Will be normalized internally.
Examples
>>> # Mirror a sphere across the YZ plane (x=0) >>> sphere = SphereSDF(center=[0.5, 0, 0], radius=0.3) >>> MirrorSDF(sphere, plane_point=[0, 0, 0], plane_normal=[1, 0, 0]) >>> >>> # Mirror across the XY plane (z=0) >>> MirrorSDF(sphere, plane_point=[0, 0, 0], plane_normal=[0, 0, 1]) >>> >>> # Mirror across a diagonal plane >>> MirrorSDF(sphere, plane_point=[0, 0, 0], plane_normal=[1, 1, 0])
Notes
The result is the union (minimum) of original and mirrored SDF
Use plane_point and plane_normal to define any mirror plane
Common mirror planes: - YZ plane: point=[0,0,0], normal=[1,0,0] - XZ plane: point=[0,0,0], normal=[0,1,0] - XY plane: point=[0,0,0], normal=[0,0,1]
The mirrored geometry is exactly symmetric - no thickness or gap
- class DeepSDFStruct.sdf_operations.RepeatSDF(sdf, spacing, count=None)#
Bases:
DeepSDFStruct.SDF.SDFBaseInfinite or finite grid repetition of an SDF.
- Parameters:
- class DeepSDFStruct.sdf_operations.RevolveSDF(sdf_2d, axis=tensor([0., 0., 1.]), offset=0.0)#
Bases:
DeepSDFStruct.SDF.SDFBaseRevolve a 2D profile around an axis to create a 3D surface of revolution.
Takes a 2D SDF profile and rotates it around a specified axis to generate a 3D axisymmetric object. The 2D profile is defined in a plane containing the rotation axis.
- Parameters:
sdf_2d (SDFBase) – A 2D SDF (geometric_dim=2) representing the profile to revolve. The profile should be in the plane where the first coordinate is the radial distance from the axis, and the second coordinate is the height along the axis.
axis (torch.Tensor, default [0, 0, 1]) – The 3D axis vector to revolve around. Must be one of the principal axes: [1,0,0] (X-axis), [0,1,0] (Y-axis), or [0,0,1] (Z-axis). The 2D profile’s first coordinate becomes the radial distance from this axis.
offset (float, default 0.0) – Radial offset from the axis. Positive values move the profile away from the axis, creating a hole in the center. Use this to create hollow objects or to position the profile at a specific radius.
- Raises:
ValueError – If sdf_2d is not a 2D SDF, or if axis is not a principal axis.
Examples
>>> # Create a sphere by revolving a circle around Z-axis >>> circle = CircleSDF(center=[0.5, 0], radius=0.5) >>> RevolveSDF(circle, axis=[0, 0, 1]) >>> >>> # Create a torus by revolving a circle with offset >>> circle = CircleSDF(center=[1.0, 0], radius=0.2) >>> RevolveSDF(circle, axis=[0, 0, 1]) >>> >>> # Revolve around X-axis instead >>> RevolveSDF(circle, axis=[1, 0, 0])
Notes
The 2D profile’s first coordinate (x) represents radial distance from axis
The 2D profile’s second coordinate (y) represents height along the axis
Only principal axes ([1,0,0], [0,1,0], [0,0,1]) are supported
The profile should be positioned appropriately for the desired shape
Use offset to create holes or position the profile away from the axis
- class DeepSDFStruct.sdf_operations.ShellSDF(sdf, thickness)#
Bases:
DeepSDFStruct.SDF.SDFBaseCreate a hollow shell by keeping only a thin layer around the surface.
Converts a solid object into a hollow shell by taking the absolute value of the SDF and offsetting by half the thickness. The result is a shell centered on the original surface.
- Parameters:
sdf (SDFBase) – The SDF to convert to a shell.
thickness (float) – Total thickness of the shell wall. Must be positive.
Examples
>>> # Create a hollow sphere with 0.05 wall thickness >>> sphere = SphereSDF(center=[0, 0, 0], radius=0.5) >>> ShellSDF(sphere, thickness=0.05) >>> >>> # Create a thin-walled box >>> box = BoxSDF(center=[0, 0, 0], extents=[1, 1, 1]) >>> ShellSDF(box, thickness=0.02)
- class DeepSDFStruct.sdf_operations.SweepSDF(profile_sdf, trajectory, bezier_samples=500, cap_ends=True, chunk_size=1000, refine=True)#
Bases:
DeepSDFStruct.SDF.SDFBaseSweep a 2D profile along a cubic bezier curve with flat end caps.
- Parameters:
profile_sdf (DeepSDFStruct.SDF.SDFBase)
- class DeepSDFStruct.sdf_operations.TwistSDF(sdf, k)#
Bases:
DeepSDFStruct.SDF.SDFBaseTwist an SDF around the Z-axis by an angle proportional to height.
Applies a rotational deformation where the rotation angle increases linearly with the z-coordinate. Creates a spiral or twisted effect.
- Parameters:
sdf (SDFBase) – The SDF to twist.
k (float) – Twist rate (radians per unit length). Positive values create counter-clockwise twist when looking down the Z-axis.
Examples
>>> # Twist a box by 0.5 radians per unit height >>> box = BoxSDF(center=[0, 0, 0], extents=[1, 1, 2]) >>> TwistSDF(box, k=0.5) >>> >>> # Stronger twist (full rotation over height 2π) >>> TwistSDF(box, k=1.0)
- DeepSDFStruct.sdf_operations.cubic_bezier_distance(p, control_points, samples=500, chunk_size=1000, refine=True)#
Compute distance from point p to cubic bezier curve using sampling with refinement.
Samples the curve at many points and finds the closest one, then refines locally.
- Parameters:
p – Query point(s), shape (N, 3)
control_points – Control points tensor, shape (4, 3)
samples – Number of samples along the curve
chunk_size – Number of query points to process at a time (for memory efficiency)
refine – Whether to refine the minimum with local optimization
- Returns:
dist: distance to curve, shape (N, 1)
t: parameter value at closest point, shape (N, 1)
closest_point: closest point on curve, shape (N, 3)
- Return type:
Tuple of (dist, t, closest_point) where