|
| 1 | +from typing import Optional, Union |
| 2 | +import numpy as np |
| 3 | + |
| 4 | +try: |
| 5 | + from skimage.measure import marching_cubes |
| 6 | +except ImportError: |
| 7 | + logger.warning("Using deprecated version of scikit-image") |
| 8 | + from skimage.measure import marching_cubes_lewiner as marching_cubes |
| 9 | + |
| 10 | +from LoopStructural.interpolators import GeologicalInterpolator |
| 11 | +from LoopStructural.utils import BoundingBox |
| 12 | + |
| 13 | +surface_list = dict[str, tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]] |
| 14 | + |
| 15 | + |
| 16 | +class LoopIsosurfacer: |
| 17 | + def __init__(self, bounding_box: BoundingBox, interpolator: GeologicalInterpolator): |
| 18 | + self.bounding_box = bounding_box |
| 19 | + self.interpolator = interpolator |
| 20 | + |
| 21 | + def fit(self, values: Union[list, int, float]) -> surface_list: |
| 22 | + surfaces = {} |
| 23 | + all_values = self.interpolator.evaluate_value(self.bounding_box.regular_grid) |
| 24 | + if isinstance(values, list): |
| 25 | + isovalues = values |
| 26 | + elif isinstance(values, float): |
| 27 | + isovalues = [values] |
| 28 | + elif isinstance(values, int): |
| 29 | + isovalues = np.linspace(np.min(all_values), np.max(all_values), values) |
| 30 | + for isovalue in isovalues: |
| 31 | + surfaces[isovalue] = marching_cubes( |
| 32 | + all_values.reshape(self.bounding_box.nsteps, order="C"), |
| 33 | + isovalue, |
| 34 | + spacing=self.bounding_box.step_vector, |
| 35 | + ) |
| 36 | + return surfaces |
0 commit comments