stochastic_poisson_surface_reconstruction
stochastic_poisson_surface_reconstruction(P, N, gs=None, h=None, corner=None, output_variance=False, sigma_n=0.0, sigma=0.05, solve_subspace_dim=0, verbose=False, prior_fun=None)
Runs Stochastic Poisson Surface Reconstruction from a set of points and normals to output a scalar field that takes negative values inside the surface and positive values outside the surface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
P |
(n,dim) numpy array
|
Coordinates of points in R^dim |
required |
N |
(n,dim) numpy array
|
(Unit) normals at each point |
required |
gs |
(dim,) numpy array
|
Number of grid points in each dimension |
None
|
h |
(dim,) numpy array
|
Grid spacing in each dimension |
None
|
corner |
(dim,) numpy array
|
Coordinates of the lower left corner of the grid |
None
|
output_variance |
bool, optional (default False)
|
Whether to use to output a mean and variance scalar field instead of just the mean scalar field |
False
|
sigma_n |
float, optional (default 0.0)
|
Noise level in the normals |
0.0
|
sigma |
float, optional (default 0.05)
|
Scalar global variance parameter |
0.05
|
solve_subspace_dim |
int, optional (default 0)
|
If > 0, use a subspace solver to solve the linear system. This is useful for large problems and essential in 3D. |
0
|
verbose |
bool, optional (default True)
|
Whether to print progress |
False
|
prior_fun |
function, optional (default None)
|
Function that takes a (m,dim) numpy array and returns a (m,dim) numpy array. This is used to specify a prior on the gradient of the scalar field (see Sec. 5 in "Stochastic Poisson Surface Reconstruction"). |
None
|
Returns:
Name | Type | Description |
---|---|---|
scalar_mean |
(gs[0],gs[1],...,gs[dim-1]) numpy array
|
Mean of the reconstructed scalar field |
scalar_variance |
(gs[0],gs[1],...,gs[dim-1]) numpy array
|
Variance of the reconstructed scalar field. This will only be part of the output if output_variance=True. |
grid_vertices |
list of (gs[0],gs[1],...,gs[dim-1],dim) numpy arrays
|
Grid vertices (each element in the list is one dimension), as in the output of np.meshgrid |
Notes
This algorithm implements "Stochastic Poisson Surface Reconstruction" as introduced by Sellán and Jacobson in 2022. If you are only looking to reconstruct a mesh from a point cloud, use the traditional "(Screened) Poisson Surface Reconstruction" by Kazhdan et al. implemented in point_cloud_to_mesh
.
See this jupyter notebook for a full tutorial on how to use this function.
See also
fd_interpolate, fd_grad, matrix_from_function, compactly_supported_normal, grid_neighbors
Examples:
from scipy.stats import norm
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
from gpytoolbox.poisson_surface_reconstruction import poisson_surface_reconstruction, random_points_on_polyline, png2poly
# Generate random points on a polyline
poly = gpytoolbox.png2poly("test/unit_tests_data/illustrator.png")[0]
poly = poly - np.min(poly)
poly = poly/np.max(poly)
poly = 0.5*poly + 0.25
poly = 3*poly - 1.5
num_samples = 40
np.random.seed(2)
EC = edge_indices(poly.shape[0],closed=False)
P,I,_ = random_points_on_mesh(poly, EC, num_samples, return_indices=True)
vecs = poly[EC[:,0],:] - poly[EC[:,1],:]
vecs /= np.linalg.norm(vecs, axis=1)[:,None]
J = np.array([[0., -1.], [1., 0.]])
N = vecs @ J.T
N = N[I,:]
# Problem parameters
gs = np.array([50,50])
# Call to PSR
scalar_mean, scalar_var, grid_vertices = gpytoolbox.poisson_surface_reconstruction(P,N,gs=gs,solve_subspace_dim=0,verbose=True)
# The probability of each grid vertex being inside the shape
prob_out = 1 - norm.cdf(scalar_mean,0,np.sqrt(scalar_var))
gx = grid_vertices[0]
gy = grid_vertices[1]
# Plot mean and variance side by side with colormap
fig, ax = plt.subplots(1,3)
m0 = ax[0].pcolormesh(gx,gy,np.reshape(scalar_mean,gx.shape), cmap='RdBu',shading='gouraud', vmin=-np.max(np.abs(scalar_mean)), vmax=np.max(np.abs(scalar_mean)))
ax[0].scatter(P[:,0],P[:,1],30 + 0*P[:,0])
q0 = ax[0].quiver(P[:,0],P[:,1],N[:,0],N[:,1])
ax[0].set_title('Mean')
divider = make_axes_locatable(ax[0])
cax = divider.append_axes('right', size='5%', pad=0.05)
fig.colorbar(m0, cax=cax, orientation='vertical')
m1 = ax[1].pcolormesh(gx,gy,np.reshape(np.sqrt(scalar_var),gx.shape), cmap='plasma',shading='gouraud')
ax[1].scatter(P[:,0],P[:,1],30 + 0*P[:,0])
q1 = ax[1].quiver(P[:,0],P[:,1],N[:,0],N[:,1])
ax[1].set_title('Variance')
divider = make_axes_locatable(ax[1])
cax = divider.append_axes('right', size='5%', pad=0.05)
fig.colorbar(m1, cax=cax, orientation='vertical')
m2 = ax[2].pcolormesh(gx,gy,np.reshape(prob_out,gx.shape), cmap='viridis',shading='gouraud')
ax[2].scatter(P[:,0],P[:,1],30 + 0*P[:,0])
q2 = ax[2].quiver(P[:,0],P[:,1],N[:,0],N[:,1])
ax[2].set_title('Probability of being inside')
divider = make_axes_locatable(ax[2])
cax = divider.append_axes('right', size='5%', pad=0.05)
fig.colorbar(m2, cax=cax, orientation='vertical')
plt.show()
Source code in src/gpytoolbox/stochastic_poisson_surface_reconstruction.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
|