-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add construct mesh from coeffs task * Move construct mesh from points task * Add construct mesh from array task * Add new construct tasks to init * Update mypy ignore for vtk
- Loading branch information
1 parent
f4a1759
commit 3113464
Showing
6 changed files
with
73 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import numpy as np | ||
from aicsshparam import shtools | ||
from vtk import vtkPolyData | ||
|
||
|
||
def construct_mesh_from_array(array: np.ndarray, reference: np.ndarray) -> vtkPolyData: | ||
_, angle = shtools.align_image_2d(image=reference) | ||
aligned_array = shtools.apply_image_alignment_2d(array, angle).squeeze() | ||
mesh, _, _ = shtools.get_mesh_from_image(image=aligned_array) | ||
return mesh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import numpy as np | ||
import pandas as pd | ||
from aicsshparam import shtools | ||
from vtk import vtkPolyData, vtkTransform, vtkTransformPolyDataFilter | ||
|
||
|
||
def construct_mesh_from_coeffs( | ||
coeffs: pd.DataFrame, | ||
order: int, | ||
prefix: str = "", | ||
suffix: str = "", | ||
scale: float = 1.0, | ||
) -> vtkPolyData: | ||
coeffs_map = np.zeros((2, order + 1, order + 1), dtype=np.float32) | ||
|
||
for l in range(order + 1): | ||
for m in range(order + 1): | ||
coeffs_map[0, l, m] = coeffs[f"{prefix}shcoeffs_L{l}M{m}C{suffix}"] | ||
coeffs_map[1, l, m] = coeffs[f"{prefix}shcoeffs_L{l}M{m}S{suffix}"] | ||
|
||
mesh, _ = shtools.get_reconstruction_from_coeffs(coeffs_map) | ||
|
||
if scale != 1: | ||
transform = vtkTransform() | ||
transform.Scale((scale, scale, scale)) | ||
|
||
transform_filter = vtkTransformPolyDataFilter() | ||
transform_filter.SetInputData(mesh) | ||
transform_filter.SetTransform(transform) | ||
transform_filter.Update() | ||
|
||
mesh = transform_filter.GetOutput(0) | ||
|
||
return mesh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import numpy as np | ||
import pandas as pd | ||
from sklearn.decomposition import PCA | ||
from vtk import vtkPolyData | ||
|
||
from abm_shape_collection.construct_mesh_from_coeffs import construct_mesh_from_coeffs | ||
|
||
|
||
def construct_mesh_from_points( | ||
pca: PCA, | ||
points: np.ndarray, | ||
feature_names: list[str], | ||
order: int, | ||
prefix: str = "", | ||
suffix: str = "", | ||
) -> vtkPolyData: | ||
"""Constructs mesh given PCA transformation points.""" | ||
coeffs = pd.Series(pca.inverse_transform(points), index=feature_names) | ||
return construct_mesh_from_coeffs(coeffs, order, prefix, suffix) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters