def mono_centering(data): if VERBOSE: print(f"Centering: {data['meta_data']['name']}") mesh = data["poly_data"] remesh = PolyData(mesh.points.copy(), mesh.faces.copy()) offset = mesh.center remesh.translate(np.zeros_like(offset) - offset) return remesh
def center(self): if VERBOSE: print("Centering") tmp_mesh = [] for mesh, full_mesh_stuff in zip(self.history[-1], self.full_data): remesh = PolyData(mesh.points.copy(), mesh.faces.copy()) offset = mesh.center remesh.translate(np.zeros_like(offset) - offset) tmp_mesh.append(remesh) self.history.append(tmp_mesh)
def process_spider_box_unit_cell( spider: pv.PolyData = get_unit_cell_spider(), box: pv.PolyData = get_unit_cell_box(), scale: float = 1.0, rotation: List[Tuple[str, float]] = None, translation: List[Union[int, float]] = None, ) -> Tuple[pv.PolyData, pv.PolyData]: """Process the spider-box unit cell through operations including scaling, rotations, and translations. Args: spider (pv.PolyData, optional): Polydata containing the spider unit. Defaults to get_unit_cell_spider(). box (pv.PolyData, optional): Polydata containing the box unit. Defaults to get_unit_cell_box(). scale (float, optional): scaling factor. Defaults to 1.0. rotation (List[Tuple[str, float]], optional): list of steps for rotation, in the form of list of tuples, and the tuple containing the direction (``"x"``, ``"y"``, or ``"z"``) in the first element, and the degrees in the second direction. Example: ``[("x", 90), ("z", 180)]``. Under the hood, the `rotate_x <https://docs.pyvista.org/core/common.html#pyvista.Common.rotate_x>`_, `rotate_y <https://docs.pyvista.org/core/common.html#pyvista.Common.rotate_y>`_, and `rotate_z <https://docs.pyvista.org/core/common.html#pyvista.Common.rotate_z>`_ methods in ``pv.PolyData`` are called. Defaults to None. translation (List[Union[int, float]], optional): Length of 3 list or array to translate the polydata. Under the hood, the `translate <https://docs.pyvista.org/core/common.html#pyvista.Common.translate>`_ method in ``pv.PolyData`` is called. Defaults to None. Returns: Tuple[pv.PolyData, pv.PolyData]: A tuple of ``pv.Polydata`` containing the spider and box. """ spider.points *= scale box.points *= scale if isinstance(rotation, list): for step in rotation: if step[0] == "x": spider.rotate_x(step[1]) if step[0] == "y": spider.rotate_y(step[1]) if step[0] == "z": spider.rotate_z(step[1]) if isinstance(translation, list): spider.translate(translation) box.translate(translation) return (spider, box)