def to_hm(doc, node, obj, name, fmt, afields, cb): name = name.encode('utf-8') naf = ct.c_int(len(afields)) af = (ct.c_char_p * len(afields))() for i in range(len(afields)): af[i] = afields[i].encode('utf-8') ccall_cb(cport.g3_to_hm, cb, doc, node, obj, name, fmt, naf, af)
def import_grid3(doc, node, cb=None): rgrid = ct.c_void_p() rname = ct.create_string_buffer(1024) ccall_cb(cport.read_grid3, cb, doc, node, ct.byref(rgrid), rname) return rgrid, rname.value
def stripe_grid(obj, partition, tipalgo, bnd, cb): npartition = ct.c_int(len(partition)) partition = list_to_c(partition, float) bnd = list_to_c(supplement(bnd, 4), int) ret = ct.c_void_p() ccall_cb(cport.g2_stripe_grid, cb, obj, npartition, partition, tipalgo, bnd, ct.byref(ret)) return ret
def custom_rectangular_grid(algo, left, bottom, right, top, herw, rinvalid, cb): herw = list_to_c(supplement(herw, 4), float) rinvalid = ct.c_int(rinvalid) ret = ct.c_void_p() ccall_cb(cport.g2_custom_rect_grid, cb, algo, left, bottom, right, top, herw, rinvalid, ct.byref(ret)) return ret
def unite_grids(obj1, obj2, buf, fixbnd, emptyholes, angle0, filler, cb): buf = ct.c_double(buf) fixbnd = ct.c_int(fixbnd) emptyholes = ct.c_int(emptyholes) angle0 = ct.c_double(angle0) ret = ct.c_void_p() ccall_cb(cport.g2_unite_grids, cb, obj1, obj2, buf, fixbnd, emptyholes, angle0, filler, ct.byref(ret)) return ret
def tetrahedral_fill(sobjs, constrs, pts, pt_sizes, cb): nsobjs = ct.c_int(len(sobjs)) sobjs = list_to_c(sobjs, 'void*') nconstrs = ct.c_int(len(constrs)) constrs = list_to_c(constrs, 'void*') npts = ct.c_int(len(pts)) pts = list_to_c(concat(pts), float) pt_sizes = list_to_c(pt_sizes, float) ret = ct.c_void_p() ccall_cb(cport.g3_tetrahedral_fill, cb, nsobjs, sobjs, nconstrs, constrs, npts, pts, pt_sizes, ct.byref(ret)) return ret
def map_grid(base_obj, target_obj, base_points, target_points, snap, bt_from_contour, algo, is_reversed, rinvalid, cb): npoints = min(len(base_points), len(target_points)) base_points = base_points[:npoints] target_points = target_points[:npoints] npoints = ct.c_int(npoints) base_points = list_to_c(concat(base_points), float) target_points = list_to_c(concat(target_points), float) bt_from_contour = ct.c_int(bt_from_contour) is_reversed = ct.c_int(is_reversed) rinvalid = ct.c_int(rinvalid) ret = ct.c_void_p() ccall_cb(cport.g2_map_grid, cb, base_obj, target_obj, npoints, base_points, target_points, snap, bt_from_contour, algo, is_reversed, rinvalid, ct.byref(ret)) return ret
def to_msh(obj, fname, btypes, per_data, cb=None): """ per_data : [bnd_per-0, bnd_shadow-0, pnt_per-0 as [x, y, z], pnt_shadow-0, ...] """ fname = fname.encode('utf-8') btypes = CBoundaryNames(btypes) n_per_data = ct.c_int(len(per_data) / 4) it = iter(per_data) tmp = [] while 1: try: tmp.append(next(it)) tmp.append(next(it)) tmp.extend(next(it)) tmp.extend(next(it)) except StopIteration: break per_data = list_to_c(tmp, float) ccall_cb(cport.g3_to_msh, cb, obj, fname, btypes, n_per_data, per_data)
def to_hm(doc, node, obj, name, fmt, cb): name = name.encode('utf-8') ccall_cb(cport.s3_to_hm, cb, doc, node, obj, name, fmt)
def surface_to_vtk(obj, fname, cb): fname = fname.encode('utf-8') ccall_cb(cport.g3_surface_to_vtk, cb, obj, fname)
def to_gmsh(obj, fname, btypes, cb=None): fname = fname.encode('utf-8') btypes = CBoundaryNames(btypes) ccall_cb(cport.g3_to_gmsh, cb, obj, fname, btypes)
def merge(obj1, obj2, cb=None): ret = ct.c_void_p() ccall_cb(cport.g3_merge, cb, obj1, obj2, ct.byref(ret)) return ret
def boundary_layer_grid(opt, cb=None): """ ->grid2. opt - options dictionary object. Same as gridcom.BuildBoundaryGrid options['opt'] dictionary except for 'source' field is a proper Contour2.cdata object. All fields must be filled cb - callback of CB_CANCEL2 type """ # prepare c input data class COptStruct(ct.Structure): def __init__(self, opt_entry): self.cont = opt_entry['source'] n = len(opt_entry['partition']) self.Npartition = ct.c_int(n) self.partition = (ct.c_double * n)(*opt_entry['partition']) self.direction = ct.c_char_p({ 1: 'LEFT', -1: 'RIGHT' }[opt_entry['direction']]) self.mesh_cont = ct.c_char_p({ 0: 'NO', 1: 'KEEP_ORIGIN', 2: 'KEEP_SHAPE', 3: 'IGNORE_ALL', 4: "INCREMENTAL", }[opt_entry['mesh_cont']]) self.mesh_cont_step = ct.c_double(opt_entry['mesh_cont_step']) self.start = (ct.c_double * 2)(opt_entry['start'][0], opt_entry['start'][1]) self.end = (ct.c_double * 2)(opt_entry['end'][0], opt_entry['end'][1]) self.force_conformal = ct.c_int( 1 if opt_entry['force_conf'] else 0) self.angle_range = (ct.c_double * 4)(opt_entry['algo_acute'], opt_entry['algo_right'], opt_entry['algo_straight'], opt_entry['algo_reentr']) self.step_start = ct.c_double(opt_entry['step_start']) self.step_end = ct.c_double(opt_entry['step_end']) _fields_ = [ ('cont', ct.c_void_p), ('Npartition', ct.c_int), ('partition', ct.POINTER(ct.c_double)), ('direction', ct.c_char_p), ('mesh_cont', ct.c_char_p), ('mesh_cont_step', ct.c_double), ('start', ct.c_double * 2), ('end', ct.c_double * 2), ('force_conformal', ct.c_int), ('angle_range', ct.c_double * 4), ('step_start', ct.c_double), ('step_end', ct.c_double), ] # 2) build array of c structures nopt = ct.c_int(len(opt)) c_opt_type = COptStruct * len(opt) c_opt = c_opt_type() for i, co in enumerate(opt): c_opt[i] = COptStruct(co) ret = ct.c_void_p() ccall_cb(cport.g2_boundary_layer, cb, nopt, c_opt, ct.byref(ret)) return ret
def grid_excl_cont(obj, cont, isinner, cb): isinner = ct.c_int(isinner) ret = ct.c_void_p() ccall_cb(cport.g2_exclude_cont, cb, obj, cont, isinner, ct.byref(ret)) return ret