def refine(input_p, verbose=False, refinement_func=None, quality_meshing=True, min_angle=None): opts = "razj" if quality_meshing: if min_angle is not None: opts += "q%f" % min_angle else: opts += "q" if len(input_p.faces) != 0: opts += "p" if verbose: opts += "VV" else: opts += "Q" if refinement_func is not None: opts += "u" output_p = MeshInfo() internals.triangulate(opts, input_p, output_p, MeshInfo(), refinement_func) return output_p
def triangulate(self, options=None): if options is None: options = self._get_triangle_options() mesh_info = MeshInfo() mesh_info.set_points(self.vertices) if self.boundary is not None: segments = [] for b in self.boundary: segments += self.get_segments(b) mesh_info.set_facets(segments) if self.holes is not None: mesh_info.set_holes(self.holes) try: import locale except ImportError: use_locale = False else: use_locale = True prev_num_locale = locale.getlocale(locale.LC_NUMERIC) locale.setlocale(locale.LC_NUMERIC, "C") try: mesh = MeshInfo() internals.triangulate(options, mesh_info, mesh, MeshInfo(), None) finally: # restore previous locale if we've changed it if use_locale: locale.setlocale(locale.LC_NUMERIC, prev_num_locale) return mesh
def build(mesh_info, verbose=False, refinement_func=None, attributes=False, volume_constraints=False, max_volume=None, allow_boundary_steiner=True, allow_volume_steiner=True, quality_meshing=True, generate_edges=None, generate_faces=False, min_angle=None, mesh_order=None): """Triangulate the domain given in `mesh_info'.""" opts = "pzj" if quality_meshing: if min_angle is not None: opts += "q%f" % min_angle else: opts += "q" if mesh_order is not None: opts += "o%d" % mesh_order if verbose: opts += "VV" else: opts += "Q" if attributes: opts += "A" if volume_constraints: opts += "a" if max_volume: raise ValueError, "cannot specify both volume_constraints and max_area" elif max_volume: opts += "a%.20f" % max_volume if refinement_func is not None: opts += "u" if generate_edges is not None: from warnings import warn warn("generate_edges is deprecated--use generate_faces instead") generate_faces = generate_edges if generate_faces: opts += "e" if not allow_volume_steiner: opts += "YY" if allow_boundary_steiner: raise ValueError("cannot allow boundary Steiner points when volume " "Steiner points are forbidden") else: if not allow_boundary_steiner: opts += "Y" # restore "C" locale--otherwise triangle might mis-parse stuff like "a0.01" try: import locale except ImportError: have_locale = False else: have_locale = True prev_num_locale = locale.getlocale(locale.LC_NUMERIC) locale.setlocale(locale.LC_NUMERIC, "C") try: mesh = MeshInfo() internals.triangulate(opts, mesh_info, mesh, MeshInfo(), refinement_func) finally: # restore previous locale if we've changed it if have_locale: locale.setlocale(locale.LC_NUMERIC, prev_num_locale) return mesh