reach_for_the_spheres
ReachForTheSpheresState
An object to keep state during the iterations of the Reach for the
Spheres method.
Meant to be used in conjunction with reach_for_the_spheres_iteration
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
V |
(n,dim) numpy double array
|
Matrix of mesh vertices of the initial mesh |
required |
F |
(m,dim) numpy int array
|
Matrix of triangle indices into V of the initlal mesh |
required |
U |
(k,dim) numpy double array, optional (default: None)
|
Matrix of SDF sample positions. The sdf will be sampled at these points |
None
|
S |
(k,dim) nummpy double array, optional (default: None)
|
Matrix of SDF samples at the sample positions in U. If this is not provided, it will be computed using sdf. |
None
|
sdf |
The signed distance function to be reconstructed. This function must take in a (ks,dim) matrix of sample points and return a (ks,) array of SDF values at these points. |
None
|
|
V_active |
(na,dim) numpy double array, optional (default: None)
|
Matrix of mesh vertices active during iteration |
None
|
F_active |
(ma,dim) numpy int array, optional (default: None)
|
Matrix of triangle indices into V_active of the mesh active during iteration |
None
|
V_inactive |
(na,dim) numpy double array, optional (default: None)
|
Matrix of mesh vertices inactive during iteration |
None
|
F_inactive |
(ma,dim) numpy int array, optional (default: None)
|
Matrix of triangle indices into V_inactive of the mesh inactive during iteration |
None
|
rng |
numpy random generator, optional (default: None)
|
numpy rng object used to create randomness during iterations |
None
|
h |
float (default None)
|
The method's initial target mesh length for the reconstructed mesh. This will change during iteration, set min_h if you want to control the minimum edge length overall. |
None
|
min_h |
float (default None)
|
The method's minimal target edge length for the reconstructed mesh. |
None
|
best_performance |
float (default None)
|
Remembers the method's best performance |
None
|
convergence_counter |
int (default None)
|
The method's convergence counter, used to track for how long progress has not been made. |
None
|
best_avg_error |
float (default None)
|
Remembers the method's average error. |
None
|
resample_counter |
int (default None)
|
Tracks how often the SDF has been resampled. |
None
|
V_last_converged |
(nl,dim) numpy double array, optional (default: None)
|
Matrix of mesh vertices for the last known converged mesh. |
None
|
F_last_converged |
(ml,dim) numpy int array, optional (default: None)
|
Matrix of triangle indices into V_last_converged for the last known converged mesh. |
None
|
U_batch |
(kb,dim) numpy double array, optional (default: None)
|
Matrix of SDF sample positions as used during the last batching operation. |
None
|
S_batch |
(kb,dim) nummpy double array, optional (default: None)
|
Matrix of SDF samples at the sample positions in U as used during the last batching operation. |
None
|
Notes
If you create this object yourself, you should supply V, F, U, S, sdf. Supply all other parameters only as explicitly needed.
Examples:
import gpytoolbox as gpy
import numpy as npy
# Get a signed distance function
V,F = gpy.read_mesh("my_mesh.obj")
# Create an SDF for the mesh
j = 20
sdf = lambda x: gpy.signed_distance(x, V, F)[0]
gx, gy, gz = np.meshgrid(np.linspace(-1.0, 1.0, j+1), np.linspace(-1.0, 1.0, j+1), np.linspace(-1.0, 1.0, j+1))
U = np.vstack((gx.flatten(), gy.flatten(), gz.flatten())).T
# Create ReachForTheSpheresState to use in iterative method later
V0, F0 = gpy.icosphere(2)
state = ReachForTheSpheresState(V=V0, F=F0, sdf=sdf, U=U)
# Run one iteration of Reach for the Spheres
converged = gpy.reach_for_the_spheres_iteration(state)
# Reconstruct triangle mesh
Vr,Fr = state.V,state.F
#The reconstructed mesh after one iteration is now Vr,Fr
Source code in src/gpytoolbox/reach_for_the_spheres.py
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 |
|
reach_for_the_spheres(U, sdf, V, F, S=None, return_U=False, verbose=False, max_iter=None, tol=None, h=None, min_h=None, linesearch=None, min_t=None, max_t=None, dt=None, inside_outside_test=None, resample=None, resample_samples=None, feature_detection=None, output_sensitive=None, remesh_iterations=None, batch_size=None, fix_boundary=None, clamp=None, pseudosdf_interior=None)
Creates a mesh from a signed distance function (SDF) using the "Reach for the Spheres" method of S. Sellán, C. Batty, and O. Stein [2023].
This method takes in an sdf, sample points (do not need to be on a grid), and an initial mesh. It then flows this initial mesh into a reconstructed mesh that fulfills the signed distance function.
This method works in dimension 2 (dim==2), where it reconstructs a polyline, and in dimension 3 (dim==3), where it reconstructs a triangle mesh.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
U |
(k,dim) numpy double array
|
Matrix of SDF sample positions. The sdf will be sampled at these points |
required |
sdf |
The signed distance function to be reconstructed. This function must take in a (ks,dim) matrix of sample points and return a (ks,) array of SDF values at these points. |
required | |
V |
(n,dim) numpy double array
|
Matrix of mesh vertices of the initial mesh |
required |
F |
(m,dim) numpy int array
|
Matrix of triangle indices into V of the initlal mesh |
required |
S |
(k,dim) nummpy double array, optional (default: None)
|
Matrix of SDF samples at the sample positions in U. If this is not provided, it will be computed using sdf. |
None
|
return_U |
bool, optional (default: False)
|
Whether to return the matrix of SDF sample positions along with the reconstructed mesh. |
False
|
verbose |
bool (default false)
|
Whether to print method statistics during operation. |
False
|
max_iter |
int (default None)
|
The maximum number of iterations to perform for the method. If not supplied, a sensible default is used. |
None
|
tol |
float (default None)
|
The method's tolerance for the sphere tangency test. If not supplied, a sensible default is used. |
None
|
h |
float (default None)
|
The method's initial target mesh length for the reconstructed mesh. This will change during iteration, set min_h if you want to control the minimum edge length overall. If not supplied, a sensible default is used. |
None
|
min_h |
float (default None)
|
The method's minimal target edge length for the reconstructed mesh. If not supplied, a sensible default is used. |
None
|
linesearch |
bool (default None)
|
Whether to use a linesearch-like heuristic for the method's timestep. If not supplied, linesearch is used. |
None
|
min_t |
float (default None)
|
The method's minimum timestep. If not supplied, a sensible default is used. |
None
|
max_t |
float (default None)
|
The method's minimum timestep. If not supplied, a sensible default is used. |
None
|
dt |
float (default None)
|
The method's default timestep. If not supplied, a sensible default is used. |
None
|
inside_outside_test |
bool (default None)
|
Whether to use inside-outside testing when projecting points to be tangent to the sphere. Turn this off if your distance function is unsigned. If not supplied, inside-outside test is used |
None
|
resample |
int (default None)
|
How often to resample the SDF after convergence to extract more information. If not supplied, resampling is not performed. |
None
|
resample_samples |
int (default None)
|
How many samples to use when resampling. If not supplied, a sensible default is used. |
None
|
feature_detection |
string (default None)
|
Which feature detection mode to use. If not supplied, aggressive feature detection is used. |
None
|
output_sensitive |
bool (default None)
|
Whether to use output-sensitive remeshing. If not supplied, remeshing is output-sensitive. |
None
|
remesh_iterations |
int (default None)
|
How many iterations of the remesher to run each step. If not supplied, a sensible default is used. |
None
|
batch_size |
int (default None)
|
For large amounts of sample points, the method is sped up using sample point batching. This parameter specifies how many samples to take for each batch. Set it to 0 to disable batching. If not supplied, a sensible default is used. |
None
|
fix_boundary |
bool (default None)
|
Whether to fix the boundary of the mesh during iteration. If not supplied, the boundary is not fixed. |
None
|
clamp |
float (default None)
|
If sdf is a clamped SDF, the clamp value to use. np.inf for no clamping. If not supplied, there is no clamping. |
None
|
pseudosdf_interior |
bool (default None)
|
If enabled, treats every negative SDF value as a bound on the signed distance, as opposed to an exact signed distance, for use in SDFs resulting from CSG unions as described by Marschner et al. "Constructive Solid Geometry on Neural Signed Distance Fields" [2023]. If not supplied, this feature is disabled. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Vr |
(nr,dim) numpy double array
|
Matrix of mesh vertices of the reconstructed triangle mesh |
Fr |
(mr,dim) numpy int array
|
Matrix of triangle indices into Vr of the reconstructed mesh |
Ur |
(kr,dim) numpy double array, if requested
|
Matrix of SDF sample positions. This can be different from the supplied Ur if the method is set to resample. |
See Also
marching_squares, marching_cubes
Notes
This method has a number of limitations that are described in the paper. E.g., the method will only work for SDFs that describe surfaces with the same topology as the initial surface.
Examples:
import gpytoolbox as gpy
import numpy as npy
# Get a signed distance function
V,F = gpy.read_mesh("my_mesh.obj")
# Create an SDF for the mesh
j = 20
sdf = lambda x: gpy.signed_distance(x, V, F)[0]
gx, gy, gz = np.meshgrid(np.linspace(-1.0, 1.0, j+1), np.linspace(-1.0, 1.0, j+1), np.linspace(-1.0, 1.0, j+1))
U = np.vstack((gx.flatten(), gy.flatten(), gz.flatten())).T
# Choose an initial surface for reach_for_the_spheres
V0, F0 = gpy.icosphere(2)
# Reconstruct triangle mesh
Vr,Fr = gpy.reach_for_the_spheres(U, sdf, V0, F0)
#The reconstructed triangle mesh is now Vr,Fr.
Source code in src/gpytoolbox/reach_for_the_spheres.py
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 |
|
reach_for_the_spheres_iteration(state, max_iter=None, tol=None, linesearch=None, min_t=None, max_t=None, dt=None, inside_outside_test=None, resample=None, resample_samples=None, feature_detection=None, output_sensitive=None, remesh_iterations=None, batch_size=None, fix_boundary=None, clamp=None, pseudosdf_interior=None, verbose=False)
Performs one iteration of the "Reach for the Spheres" method of S. Sellán, C. Batty, and O. Stein [2023]. This method is used to create a mesh from a signed distance function (SDF).
This method takes in the current state of the method in the form of a ReachForTheSpheresState object, and stores its results as well as any temporary information needed in that state object.
This method works in dimension 2 (dim==2), where it reconstructs a polyline, and in dimension 3 (dim==3), where it reconstructs a triangle mesh.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state |
Stores all needed information about the current state of the method. |
required | |
max_iter |
int (default None)
|
The maximum number of iterations to perform for the method. If not supplied, a sensible default is used. |
None
|
tol |
float (default None)
|
The method's tolerance for the sphere tangency test. If not supplied, a sensible default is used. |
None
|
linesearch |
bool (default None)
|
Whether to use a linesearch-like heuristic for the method's timestep. If not supplied, linesearch is used. |
None
|
min_t |
float (default None)
|
The method's minimum timestep. If not supplied, a sensible default is used. |
None
|
max_t |
float (default None)
|
The method's minimum timestep. If not supplied, a sensible default is used. |
None
|
dt |
float (default None)
|
The method's default timestep. If not supplied, a sensible default is used. |
None
|
inside_outside_test |
bool (default None)
|
Whether to use inside-outside testing when projecting points to be tangent to the sphere. Turn this off if your distance function is unsigned. If not supplied, inside-outside test is used |
None
|
resample |
int (default None)
|
How often to resample the SDF after convergence to extract more information. If not supplied, resampling is not performed. |
None
|
resample_samples |
int (default None)
|
How many samples to use when resampling. If not supplied, a sensible default is used. |
None
|
feature_detection |
string (default None)
|
Which feature detection mode to use. If not supplied, aggressive feature detection is used. |
None
|
output_sensitive |
bool (default None)
|
Whether to use output-sensitive remeshing. If not supplied, remeshing is output-sensitive. |
None
|
remesh_iterations |
int (default None)
|
How many iterations of the remesher to run each step. If not supplied, a sensible default is used. |
None
|
batch_size |
int (default None)
|
For large amounts of sample points, the method is sped up using sample point batching. This parameter specifies how many samples to take for each batch. Set it to 0 to disable batching. If not supplied, a sensible default is used. |
None
|
fix_boundary |
bool (default None)
|
Whether to fix the boundary of the mesh during iteration. If not supplied, the boundary is not fixed. |
None
|
clamp |
float (default None)
|
If sdf is a clamped SDF, the clamp value to use. np.inf for no clamping. If not supplied, there is no clamping. |
None
|
pseudosdf_interior |
bool (default None)
|
If enabled, treats every negative SDF value as a bound on the signed distance, as opposed to an exact signed distance, for use in SDFs resulting from CSG unions as described by Marschner et al. "Constructive Solid Geometry on Neural Signed Distance Fields" [2023]. If not supplied, this feature is disabled. |
None
|
verbose |
bool (default false)
|
Whether to print method statistics during operation. |
False
|
Returns:
Name | Type | Description |
---|---|---|
converged |
bool
|
Whether the method has converged after this iteration or not. |
See Also
reach_for_the_spheres, marching_squares, marching_cubes
Notes
This method has a number of limitations that are described in the paper. E.g., the method will only work for SDFs that describe surfaces with the same topology as the initial surface.
Examples:
import gpytoolbox as gpy
import numpy as npy
# Get a signed distance function
V,F = gpy.read_mesh("my_mesh.obj")
# Create an SDF for the mesh
j = 20
sdf = lambda x: gpy.signed_distance(x, V, F)[0]
gx, gy, gz = np.meshgrid(np.linspace(-1.0, 1.0, j+1), np.linspace(-1.0, 1.0, j+1), np.linspace(-1.0, 1.0, j+1))
U = np.vstack((gx.flatten(), gy.flatten(), gz.flatten())).T
# Create ReachForTheSpheresState to use in iterative method later
V0, F0 = gpy.icosphere(2)
state = ReachForTheSpheresState(V=V0, F=F0, sdf=sdf, U=U)
# Run one iteration of Reach for the Spheres
converged = gpy.reach_for_the_spheres_iteration(state)
# Reconstruct triangle mesh
Vr,Fr = state.V,state.F
#The reconstructed mesh after one iteration is now Vr,Fr
Source code in src/gpytoolbox/reach_for_the_spheres.py
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 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 |
|