• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mkofler96 / DeepSDFStruct / 18098653032

29 Sep 2025 01:28PM UTC coverage: 71.001% (+2.6%) from 68.435%
18098653032

push

github

web-flow
Merge pull request #2

Integrated Optimization

236 of 331 branches covered (71.3%)

Branch coverage included in aggregate %.

2041 of 2876 relevant lines covered (70.97%)

0.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

8.33
DeepSDFStruct/plotting.py
1
import matplotlib.pyplot as plt
1✔
2
import numpy as np
1✔
3
import torch
1✔
4

5

6
def plot_slice(
1✔
7
    fun,
8
    origin=(0, 0, 0),
9
    normal=(0, 0, 1),
10
    res=(100, 100),
11
    ax=None,
12
    xlim=(-1, 1),
13
    ylim=(-1, 1),
14
    clim=(-1, 1),
15
    cmap="seismic",
16
    show_zero_level=True,
17
):
18
    plt_show = False
×
19
    if ax is None:
×
20
        fig, ax = plt.subplots()
×
21
        plt_show = True
×
22

23
    points, u, v = generate_plane_points(origin, normal, res, xlim, ylim)
×
24

25
    points = torch.from_numpy(points).to(torch.float32)
×
26
    sdf = fun(points).reshape((res[0], res[1]))
×
27
    X = u.reshape((res[0], res[1]))
×
28
    Y = v.reshape((res[0], res[1]))
×
29
    if isinstance(sdf, torch.Tensor):
×
30
        sdf = sdf.detach().cpu().numpy()
×
31

32
    # cbar = ax[0].scatter(X, Y, c=sdf, cmap="seismic")c
33
    cbar = ax.contourf(X, Y, sdf, cmap=cmap, levels=10)
×
34
    if show_zero_level:
×
35
        ax.contour(X, Y, sdf, levels=[0], colors="black", linewidths=0.5)
×
36
    cbar.set_clim(clim[0], clim[1])
×
37
    ax.set_xticks([])
×
38
    ax.set_yticks([])
×
39
    ax.set_aspect(1)
×
40
    if plt_show:
×
41
        plt.show()
×
42
        return fig, ax
×
43

44

45
def generate_plane_points(origin, normal, res, xlim, ylim):
1✔
46
    """
47
    Generates evenly spaced points on a plane.
48

49
    Parameters:
50
    origin (array-like): A point on the plane (3D vector).
51
    normal (array-like): Normal vector of the plane (3D vector).
52
    num_points_u (int): Number of points along the first direction (u-axis).
53
    num_points_v (int): Number of points along the second direction (v-axis).
54
    spacing (float): Distance between adjacent points.
55

56
    Returns:
57
    points (numpy.ndarray): Array of points on the plane of shape (num_points_u * num_points_v, 3).
58
    """
59
    normal = np.array(normal)
×
60
    normal = normal / np.linalg.norm(normal)
×
61
    origin = np.array(origin)
×
62
    # Find two orthogonal vectors to the normal that lie on the plane (u and v axes)
63
    if np.allclose(normal, [0, 0, 1]):  # Special case when the normal is along z-axis
×
64
        u = np.array([1, 0, 0])
×
65
        v = np.array([0, 1, 0])
×
66
    elif np.allclose(normal, [0, 1, 0]):  # Special case when the normal is along z-axis
×
67
        u = np.array([1, 0, 0])
×
68
        v = np.array([0, 0, 1])
×
69
    elif np.allclose(normal, [1, 0, 0]):  # Special case when the normal is along z-axis
×
70
        u = np.array([0, 1, 0])
×
71
        v = np.array([0, 0, 1])
×
72
    else:
73
        raise NotImplementedError(
×
74
            "Normal vector other than [1,0,0], [0,1,0] and [0,0,1] not supported yet."
75
        )
76

77
    # Create grid points in 2D space (u-v plane)
78
    u_coords = np.linspace(xlim[0], xlim[1], res[0])
×
79
    v_coords = np.linspace(ylim[0], ylim[1], res[1])
×
80

81
    points = []
×
82
    u_exp = []
×
83
    v_exp = []
×
84
    for u_val in u_coords:
×
85
        for v_val in v_coords:
×
86
            point = origin + u_val * u + v_val * v
×
87
            u_exp.append(u_val)
×
88
            v_exp.append(v_val)
×
89
            points.append(point)
×
90

91
    return np.array(points), np.array(u_exp), np.array(v_exp)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc