Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/ellipsoid_01.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/ellipsoid_02.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/ellipsoid_03.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/ellipsoid_04.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/ellipsoid_05.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/ellipsoid_06.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/ellipsoid_07.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/ellipsoid_08.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/ellipsoid_09.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/ellipsoid_10.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/groomed/ellipsoid_01_groomed.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/groomed/ellipsoid_02_groomed.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/groomed/ellipsoid_03_groomed.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/groomed/ellipsoid_04_groomed.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/groomed/ellipsoid_05_groomed.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/groomed/ellipsoid_06_groomed.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/groomed/ellipsoid_07_groomed.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/groomed/ellipsoid_08_groomed.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/groomed/ellipsoid_09_groomed.vtk
Git LFS file not shown
3 changes: 3 additions & 0 deletions Examples/Studio/MeshScalars/groomed/ellipsoid_10_groomed.vtk
Git LFS file not shown
90 changes: 90 additions & 0 deletions Examples/Studio/MeshScalars/make_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env python
"""
Build the Mesh Scalars example: ellipsoids that are nearly the same shape, each carrying a
scalar field ("scalar_value") with a patch whose position differs from subject to subject.

Geometry alone cannot tell where the patch is, so a model built from position only leaves the
patch smeared across particles. Using the field as a correspondence attribute makes the particles
follow it: untick "scalar_value" under Mesh Scalars in the Optimize panel and run again to compare.

python make_example.py [output_dir]
"""

import json
import os
import sys

import numpy as np
import vtk
from vtk.util.numpy_support import numpy_to_vtk, vtk_to_numpy

NUM_SUBJECTS = 10
RADII = np.array([20.0, 14.0, 10.0])
PATCH_WIDTH = np.radians(25.0) # standard deviation of the patch, as an angle
PATCH_RANGE = np.radians(35.0) # the patch center moves this far either side of the top


def ellipsoid(radii, subdivisions=4):
source = vtk.vtkPlatonicSolidSource()
source.SetSolidTypeToIcosahedron()
tri = vtk.vtkTriangleFilter()
tri.SetInputConnection(source.GetOutputPort())
sub = vtk.vtkLinearSubdivisionFilter()
sub.SetInputConnection(tri.GetOutputPort())
sub.SetNumberOfSubdivisions(subdivisions)
sub.Update()
out = vtk.vtkPolyData()
out.SetPoints(vtk.vtkPoints())
out.SetPolys(sub.GetOutput().GetPolys())
unit = vtk_to_numpy(sub.GetOutput().GetPoints().GetData()).astype(float)
unit /= np.linalg.norm(unit, axis=1, keepdims=True)
out.GetPoints().SetData(numpy_to_vtk(unit * radii, deep=True))
return out, unit


def main(out_dir):
os.makedirs(out_dir, exist_ok=True)
rng = np.random.default_rng(7)
data = []
angles = np.linspace(-PATCH_RANGE, PATCH_RANGE, NUM_SUBJECTS)
for i, angle in enumerate(angles):
radii = RADII * (1.0 + rng.uniform(-0.06, 0.06, 3))
mesh, unit = ellipsoid(radii)
# the patch sits on the top of the ellipsoid, shifted along its long axis
center = np.array([np.sin(angle), 0.0, np.cos(angle)])
separation = np.arccos(np.clip(unit @ center, -1.0, 1.0))
field = np.exp(-0.5 * (separation / PATCH_WIDTH) ** 2).astype(np.float32)
array = numpy_to_vtk(field, deep=True)
array.SetName("scalar_value")
mesh.GetPointData().SetScalars(array)
name = "ellipsoid_%02d.vtk" % (i + 1)
writer = vtk.vtkPolyDataWriter()
writer.SetFileName(os.path.join(out_dir, name))
writer.SetInputData(mesh)
writer.SetFileVersion(42)
writer.SetFileTypeToBinary()
writer.Write()
data.append({"name": "ellipsoid_%02d" % (i + 1), "shape_1": name})

optimize = {
"number_of_particles": "128",
"initialization_mode": "split",
"iterations_per_split": "1000",
"optimization_iterations": "1000",
"relative_weighting": "10",
"initial_relative_weighting": "0.05",
"starting_regularization": "1000",
"ending_regularization": "10",
"procrustes": "false",
"field_attributes": "scalar_value",
"field_attribute_weights": "100",
}
# the meshes are already clean and aligned; grooming only has to pass them (and the field) through
groom = {"1": {"remesh": "false", "fill_holes": "false", "alignment_enabled": "false"}}
project = {"data": data, "groom": groom, "optimize": optimize}
json.dump(project, open(os.path.join(out_dir, "mesh_scalars.swproj"), "w"), indent=1)
print("wrote %d meshes and mesh_scalars.swproj to %s" % (len(data), out_dir))


if __name__ == "__main__":
main(sys.argv[1] if len(sys.argv) > 1 else ".")
64 changes: 64 additions & 0 deletions Examples/Studio/MeshScalars/mesh_scalars.swproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"data": [
{
"name": "ellipsoid_01",
"shape_1": "ellipsoid_01.vtk"
},
{
"name": "ellipsoid_02",
"shape_1": "ellipsoid_02.vtk"
},
{
"name": "ellipsoid_03",
"shape_1": "ellipsoid_03.vtk"
},
{
"name": "ellipsoid_04",
"shape_1": "ellipsoid_04.vtk"
},
{
"name": "ellipsoid_05",
"shape_1": "ellipsoid_05.vtk"
},
{
"name": "ellipsoid_06",
"shape_1": "ellipsoid_06.vtk"
},
{
"name": "ellipsoid_07",
"shape_1": "ellipsoid_07.vtk"
},
{
"name": "ellipsoid_08",
"shape_1": "ellipsoid_08.vtk"
},
{
"name": "ellipsoid_09",
"shape_1": "ellipsoid_09.vtk"
},
{
"name": "ellipsoid_10",
"shape_1": "ellipsoid_10.vtk"
}
],
"groom": {
"1": {
"remesh": "false",
"fill_holes": "false",
"alignment_enabled": "false"
}
},
"optimize": {
"number_of_particles": "128",
"initialization_mode": "split",
"iterations_per_split": "1000",
"optimization_iterations": "1000",
"relative_weighting": "10",
"initial_relative_weighting": "0.05",
"starting_regularization": "1000",
"ending_regularization": "10",
"procrustes": "false",
"field_attributes": "scalar_value",
"field_attribute_weights": "100"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
-18.7834 -2.22089 -3.56731
-5.689 14.0233 -0.804953
-7.20985 -13.6932 -0.314514
6.50741 -12.8958 3.61539
-13.8393 3.30333 7.17799
10.514 5.28448 -8.00475
-11.4093 0.440759 -8.52961
5.54925 4.76924 -9.34466
-18.089 6.62185 -0.252678
11.4604 11.3095 -3.01659
-5.10178 -12.0159 5.3135
12.4556 -2.80567 -7.90269
-3.24204 7.85374 8.56395
3.11597 8.37511 -8.32217
-8.734 -9.41312 -6.54331
12.9345 -10.0019 3.68552
-17.2276 1.80864 -5.30108
-5.75376 4.73467 -9.3192
-7.76167 -9.34765 6.89982
16.9932 -6.65357 3.12984
4.21845 13.283 3.79002
19.5663 3.61587 0.972713
2.43851 -9.58221 -7.71541
7.06192 -8.37709 -7.66897
-6.04538 12.2801 -4.71955
-15.6291 8.8059 2.20135
-2.70049 -8.18103 8.45425
20.0992 -0.0157727 -1.41258
-10.7539 0.923604 8.72958
7.72851 10.674 5.87622
-18.7904 -2.84626 3.33354
11.3059 -10.9726 -3.70776
-16.3385 -5.11809 -4.94151
-1.66998 10.3604 -7.25187
-10.5672 -11.7734 -2.97481
6.31099 -5.01757 9.15725
-12.683 9.46153 4.52096
14.9511 9.9028 0.287426
-4.07872 -3.14883 -9.86737
4.64553 -0.369171 -10.0441
-16.9357 6.10356 -3.71736
8.95859 13.1023 0.799231
-1.57308 -14.1793 -2.48129
15.8441 -6.46206 -4.56124
0.849068 1.65461 10.2485
1.41344 2.95398 -10.0894
-12.2662 -4.51939 -7.58508
10.0762 -12.7112 0.396584
-9.91731 4.86656 -8.32716
-2.9139 1.51376 -10.1589
-13.0287 -9.32465 4.40973
13.2411 -2.33306 7.64465
-6.0949 10.2835 6.66632
16.8101 6.33712 3.67949
-5.87535 -12.468 -4.53293
-1.12997 -6.95534 -9.07231
-9.73607 9.07333 -6.42129
-10.9889 12.2198 1.12798
0.796094 -5.80615 9.47189
17.1979 6.8665 -2.55549
-6.79897 0.9667 9.70216
12.1224 10.3165 3.95764
-12.8435 -11.3174 0.576439
16.9639 -2.03565 -5.48182
-19.6109 2.22406 -2.1127
-1.56774 13.5956 -3.76318
-9.27562 -12.1668 3.29065
3.14089 -9.95612 7.4121
-9.63977 7.6705 7.29808
13.2536 7.79307 -5.55818
-8.63301 -4.19428 -8.86255
8.83019 0.888783 -9.27139
-19.5351 2.82432 1.96351
6.90258 12.1462 -4.59496
-0.345955 -12.2717 5.64078
13.5562 1.80388 -7.57763
-0.422288 12.0427 5.87878
7.8458 8.89018 -7.16928
-2.80247 -10.7738 -6.85101
8.5821 -9.69517 6.38917
-15.0108 -1.2106 -6.89244
-7.42493 0.217489 -9.60293
-12.2152 -5.44115 7.30482
12.3774 -5.89669 7.04078
0.148608 14.6548 0.198925
16.7932 1.55347 5.69159
1.37174 -12.7174 -5.07938
6.74986 -11.9351 -4.90648
-5.73138 8.79098 -7.7267
-14.3711 10.0929 -1.58752
-5.54598 -3.4003 9.63908
18.2924 -2.08601 4.21135
-8.87772 -3.99038 8.85011
2.7156 9.05503 7.99819
-20.101 -2.0129 0.0553259
15.2473 -9.59387 -0.825386
-18.0872 -6.46832 -1.01909
2.40004 12.1622 -5.62434
-15.0972 -9.10502 -2.53737
2.59258 -1.72449 10.1655
-16.7557 4.89668 4.68946
11.8934 6.53202 6.99098
-5.71987 -7.44127 -8.40292
8.06883 -4.02188 -9.03537
-13.4126 8.09135 -5.24562
4.40946 14.2269 -1.05753
2.17388 -14.3709 1.68982
11.7121 -7.36981 -6.64262
0.115603 5.1379 9.67154
-1.14358 6.41235 -9.26742
-12.5728 -8.14338 -5.71713
4.94715 -14.0185 -1.64361
-13.8475 4.03459 -6.98599
0.217728 -2.15301 -10.2145
-16.0136 -3.52862 5.82789
7.7776 0.209254 9.53288
-3.46226 13.6603 3.29215
12.1051 2.64124 8.07158
-2.99228 -14.3491 1.46102
3.44161 -5.20385 -9.49237
-10.1891 12.0148 -2.84247
-7.92899 12.4431 3.67686
-3.1252 -0.970184 10.1773
17.095 3.07029 -5.12548
-5.59942 3.70556 9.5732
6.05598 5.31523 9.11451
-16.4889 -7.99509 2.10075
19.1271 -4.75159 -0.753882
Loading
Loading