From 8ccca8f95f2a9743ef5f11e982ae1a93febadead Mon Sep 17 00:00:00 2001 From: dominiquef Date: Mon, 17 Jun 2024 16:19:55 -0700 Subject: [PATCH 1/2] Better handling of cases --- octree_creation_app/utils.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/octree_creation_app/utils.py b/octree_creation_app/utils.py index 7615976..126e7e5 100644 --- a/octree_creation_app/utils.py +++ b/octree_creation_app/utils.py @@ -68,6 +68,11 @@ def create_octree_from_octrees(meshes: list[Octree | TreeMesh]) -> TreeMesh: - mesh.max_level + mesh.cell_levels_by_index(np.arange(mesh.nC)) ) + else: + raise TypeError( + f"All meshes must be Octree or TreeMesh, not {type(mesh)} " + "and must have octree cells defined." + ) treemesh.insert_cells(centers, levels, finalize=False) @@ -86,10 +91,17 @@ def collocate_octrees(global_mesh: Octree, local_meshes: list[Octree]): attributes = get_octree_attributes(global_mesh) cell_size = attributes["cell_size"] - if global_mesh.octree_cells is not None: - u_grid = global_mesh.octree_cells["I"] * global_mesh.u_cell_size - v_grid = global_mesh.octree_cells["J"] * global_mesh.v_cell_size - w_grid = global_mesh.octree_cells["K"] * global_mesh.w_cell_size + if ( + global_mesh.octree_cells is None + or global_mesh.u_cell_size is None + or global_mesh.v_cell_size is None + or global_mesh.w_cell_size is None + ): + raise ValueError("Global mesh must have octree_cells and cell sizes.") + + u_grid = global_mesh.octree_cells["I"] * global_mesh.u_cell_size + v_grid = global_mesh.octree_cells["J"] * global_mesh.v_cell_size + w_grid = global_mesh.octree_cells["K"] * global_mesh.w_cell_size xyz = np.c_[u_grid, v_grid, w_grid] + attributes["origin"] tree = cKDTree(xyz) From 471426bf23438530b674ac9ab332ef90bb90da59 Mon Sep 17 00:00:00 2001 From: dominiquef Date: Mon, 17 Jun 2024 16:20:31 -0700 Subject: [PATCH 2/2] More pylints --- octree_creation_app/utils.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/octree_creation_app/utils.py b/octree_creation_app/utils.py index 126e7e5..d87429f 100644 --- a/octree_creation_app/utils.py +++ b/octree_creation_app/utils.py @@ -140,6 +140,10 @@ def densify_curve(curve: Curve, increment: float) -> np.ndarray: if curve.cells is not None and curve.vertices is not None: logic = curve.parts == part cells = curve.cells[np.all(logic[curve.cells], axis=1)] + + if len(cells) == 0: + continue + vert_ind = np.r_[cells[:, 0], cells[-1, 1]] locs = curve.vertices[vert_ind, :] locations.append(resample_locations(locs, increment)) @@ -232,12 +236,26 @@ def octree_2_treemesh( # pylint: disable=too-many-locals :return: Resulting TreeMesh. """ - if mesh.octree_cells is None: + if ( + mesh.octree_cells is None + or mesh.u_count is None + or mesh.v_count is None + or mesh.w_count is None + ): return None - small_cell = [mesh.u_cell_size, mesh.v_cell_size, mesh.w_cell_size] - n_cell_dim = [mesh.u_count, mesh.v_count, mesh.w_count] - cell_sizes = [np.ones(nr) * sz for nr, sz in zip(n_cell_dim, small_cell)] + n_cell_dim, cell_sizes = [], [] + for ax in "uvw": + if ( + getattr(mesh, f"{ax}_cell_size") is None + or getattr(mesh, f"{ax}_count") is None + ): + raise ValueError(f"Cell size in {ax} direction is not defined.") + + n_cell_dim.append(getattr(mesh, f"{ax}_count")) + cell_sizes.append( + np.ones(getattr(mesh, f"{ax}_count")) * getattr(mesh, f"{ax}_cell_size") + ) if any(np.any(cell_size < 0) for cell_size in cell_sizes): raise NotImplementedError("Negative cell sizes not supported.")