def add_rect_contour(p0, p1, bnd=0): """Adds four point closed rectangular contour. :param list-of-floats p0: :param list-of-floats p1: bottom left and top right coordinates of the contour :param bnd: single or list of 4 boundary identifiers (bottom, right, top, left) for contour segments. With the default value no boundary types will be set. :return: Contour identifier """ icheck(0, Point2D()) icheck(1, Point2D(grthan=p0)) icheck(2, ListOr1(ZType(), llen=4)) if isinstance(bnd, list): b = bnd[0:4] else: b = [bnd, bnd, bnd, bnd] c = com.contcom.AddRectCont({"p0": p0, "p1": p1, "bnds": b}) flow.exec_command(c) return c.added_contours2()[0]
def create_spline_contour(pnts, bnds=0, nedges=100): """ Creates singly connected contour as a parametric cubic spline. :param list-of-list-of-floats pnts: sequence of points. If coordinates of first and last points are equal then resulting contour will be closed. :param single-or-list-of-boundary-identifiers bnds: boundary type for each contour segment bounded by **pnts** or single identifier for the whole contour. :param int nedges: number of line segments of resulting contour. Should be equal or greater than the number of sections defined by **pnts**. :returns: contour identifier """ icheck(0, List(Point2D(), minlen=3)) icheck(1, ListOr1(ZType(), llen=len(pnts) - 1)) icheck(2, UInt(minv=len(pnts) - 1)) b = bnds if isinstance(bnds, list) else [bnds] c = com.contcom.CreateSpline({"points": pnts, "bnds": b, "nedges": nedges}) flow.exec_command(c) return c.added_contours2()[0]
def add_circ_contour(p0, rad, n_arc, bnd=0): """Adds circle contour from given center and radius. :param list-of-floats p0: circle center in [x, y] format :param float rad: circle radius :param int n_arc: partition of circle arc :param bnd: boundary identifier for contour. :return: Contour identifier """ icheck(0, Point2D()) icheck(1, Float(grthan=0.0)) icheck(2, UInt(minv=3)) icheck(3, ZType()) c = com.contcom.AddCircCont({ "p0": p0, "rad": rad, "na": n_arc, "bnd": bnd }) flow.exec_command(c) return c.added_contours2()[0]
def tetrahedral_fill(domain): """ Fills 3D domain with tetrahedral mesh :param domain: surface/3d grid identifier (or list of identifiers) :returns: 3d grid identifier Domain is defined by any number of closed surfaces passed in **domain** argument. Internal nesting procedure will be executed to built target domain out of given surfaces. Boundary surface could possibly contain faces built by any number of vertices. However if boundary face is not a triangle than a n-side pyramid will be built at its site. Hence resulting grid will not be strictly tetrahedral. .. note:: By now program uses simplified bounding box based nesting algorithm. It could give improper results for complicated surface structures. Be sure that passed surface list nesting equals nesting of respective surface bounding boxes. """ icheck(0, UListOr1(ASurf3D())) if not isinstance(domain, list): domain = [domain] c = com.grid3dcom.TetrahedralFill({"source": domain}) flow.exec_command(c) return c.added_grids3()[0]
def remove_all(): """ Completely removes all geometry objects and boundary types :returns: None """ c = com.objcom.RemoveAll({}) flow.exec_command(c)
def add_triangle_grid(p0, p1, p2, nedge, bnd=0): """Creates structured grid in triangle area :param list-of-floats p0: :param list-of-floats p1: :param list-of-floats p2: triangle vertices in [x, y] format :param int nedge: partition of triangle edges :param int-or-list-of-int bnd: boundary types for outer contour :return: identifier of newly created grid Resulting grid will contain quadrangle cells everywhere except area near ``p0``-``p2`` edge where triangle cells will be built. """ icheck(0, Point2D()) icheck(1, Point2D(noteq=[p0])) icheck(2, Point2D(noteq=[p0, p1])) icheck(3, UInt(minv=1)) icheck(4, ListOr1(ZType(), llen=3)) bnd = bnd[:3] if isinstance(bnd, list) else [bnd, bnd, bnd] c = com.gridcom.AddTriGrid({ "vertices": [p0, p1, p2], "nedge": nedge, "bnd": bnd }) flow.exec_command(c) return c.added_grids2()[0]
def simplify_contour(cont, simplify=True, angle=0., separate=False): """ Separates and simplify user contour :param cont: source contour or grid identifier :param bool simplify: do simplification, i.e. make all segments non-collinear Collinear segments will not be splitted if they have different boundary types. :param degree angle: maximum allowed angle between simplified segments (deg, >=0). :param bool separate: assemble list of singly connected contours from multiply connected source contour :returns: list of created contours ids """ icheck(0, ACont2D()) icheck(1, Bool()) icheck(2, Float(within=[0., 180., '[]'])) icheck(3, Bool()) c = com.contcom.SimplifyContours({"names": [cont], "simplify": simplify, "angle": angle, "separate": separate}) flow.exec_command(c) return c.added_contours2()
def add_unf_hex_grid(area, cell_radius, strict=False): """ Builds grid with regular hexagonal cells :param area: defines meshing area. If given as ``[[x, y], radius]`` then represents hexagonal area; if ``[[x0, y0], [x1, y1]]`` then it is a rectangle defined by bottom-left and top-right points. :param float cell_radius: radius of hexagonal cell. :param bool strict: forces grid stretch to guarantee that all outer rectangle corners lie in the centers of cells. See details in :ref:`hexgrid` """ icheck(0, List(Any())) icheck( 0, CompoundList(Point2D(), Or(Float(grthan=0.0), Point2D(grthan=area[0])), llen=2)) icheck(1, Float(grthan=0.)) icheck(2, Bool()) simpar = [area[0][0], area[0][1]] if isinstance(area[1], list): simpar.append(area[1][0]) simpar.append(area[1][1]) else: simpar.append(area[1]) args = {"area": simpar, "crad": cell_radius, "strict": strict} c = com.gridcom.AddUnfHexGrid(args) flow.exec_command(c) return c.added_grids2()[0]
def clip_domain(dom1, dom2, operation, simplify=True): """ Executes domain clipping procedure :param dom1: :param dom2: contour identifiers :param str operatrion: operation code * ``"union"`` * ``"difference"`` * ``"intersection"`` * ``"xor"`` :param bool simplify: whether to keep all source points (False) or return simplified contour :returns: created contour identifier or None if resulting domain is empty """ icheck(0, ACont2D()) icheck(1, ACont2D()) icheck(2, OneOf("union", "difference", "intersection", "xor")) icheck(3, Bool()) c = com.contcom.ClipDomain({"c1": dom1, "c2": dom2, "oper": operation, "simplify": simplify}) flow.exec_command(c) if len(c.added_contours2()) > 0: return c.added_contours2()[0] else: return None
def matched_partition(cont, step, influence, ref_conts=[], ref_pts=[], angle0=30., power=3.): """ Makes a contour partition with respect to other contours partitions and given reference points :param cont: target contour. :param float step: default contour step size. :param float influence: influence radius of size conditions. :param ref_conts: list of contours which segmentation will be treated as target segmentation conditions. :param ref_pts: reference points given as ``[step0, [x0, y0], step1, [x1, y1], ...]`` list. :param float angle0: existing contour vertices which provide turns outside of ``[180 - angle0, 180 + angle0]`` degrees range will be preserved regardless of other options :param positive-float power: shows power of weight calculation function. As this parameter increases size transitions along contour become less smooth and more sensible to size conditions. See :ref:`matchedcontmeshing` for details. """ icheck(0, ACont2D()) icheck(1, Float(grthan=0.0)) icheck(2, Float(grthan=0.0)) icheck(3, UList(ACont2D())) icheck(4, CompoundList(Float(grthan=0.0), Point2D())) icheck(5, Float(within=[-1., 180., '[]'])) icheck(6, Float(grthan=0.0)) if not isinstance(ref_conts, list): ref_conts = [ref_conts] rp = [] for i in range(len(ref_pts) / 2): rp.append(ref_pts[2 * i]) rp.extend(ref_pts[2 * i + 1]) args = {"base": cont, "cconts": ref_conts, "cpts": rp, "step": step, "infdist": influence, "angle0": angle0, "power": power } c = com.contcom.MatchedPartition(args) flow.exec_command(c) return c.added_contours2()[0]
def remove_geom(objs): """ Completely removes object or list of objects :param objs: identifier or list of identifiers of removing objects :returns: None """ icheck(0, UListOr1(AObject())) ob = objs if isinstance(objs, list) else [objs] c = com.objcom.RemoveGeom({"names": ob}) flow.exec_command(c)
def unite_contours(conts): """ Unites contours to single multiply connected contour :param conts: list of contours identifiers to unite :return: contour identifier Equal nodes and segments of input contours will be merged. """ icheck(0, List(ACont2D())) c = com.contcom.UniteContours({"sources": conts}) flow.exec_command(c) return c.added_contours2()[0]
def add_circ_rect_grid(p0, rad, step, sqrside=1.0, rcoef=1.0, algo="linear"): """ Creates quadrangular cell grid in a circular area. See details in :ref:`circrect_grid`. :param list-of-floats p0: center point of circle area in [x, y] format. :param positive-float rad: radius of circle area. :param positive-float step: approximate partition step of the outer boundary. :param positive-float sqrside: side of the inner square normalized by the circle radius. Values greater than 1.4 are not allowed. :param positive-float rcoef: radius direction refinement of the ring part of the grid. Values less then unity lead to refinement towards outer boundary. :param str algo: Algorithms of assembling the ring part of the grid. * ``'linear'`` - use weighted approach for each ray partition * ``'laplace'`` - use algebraic mapping for building each 45 degree sector. * ``'orthogonal_circ'`` - build orthogonal grid keeping uniform grid at outer circle * ``'orthogonal_rect'`` - build orthogonal grid keeping uniform grid at inner rectangle :return: new grid identifier """ icheck(0, Point2D()) icheck(1, Float(grthan=0.0)) icheck(2, Float(grthan=0.0)) icheck(3, Float(within=[0., 1.4, '[)'])) icheck(4, Float(grthan=0.0)) icheck(5, OneOf('linear', 'laplace', 'orthogonal_circ', 'orthogonal_rect')) # call args = { 'algo': algo, 'p0': p0, 'rad': rad, 'step': step, 'sqrside': sqrside, 'rcoef': rcoef } c = com.gridcom.AddCirc4Grid(args) flow.exec_command(c) return c.added_grids2()[0]
def copy_geom(objs): """ Creates deep copies of geometry objects :param objs: identifier or list of identifiers of objects to copy :returns: list of identifiers of copied objects in oder prescribed by input list """ icheck(0, ListOr1(AObject())) if not isinstance(objs, list): objs = [objs] c = com.objcom.CopyGeom({"names": objs}) flow.exec_command(c) return c.odered_output()
def grid_bnd_to_contour(gid, simplify=True): """ Extracts grid boundary to user contour. :param gid: grid identifier :param bool simplify: if true deletes all non-significant points. Otherwise resulting contour will contain all boundary grid edges. :returns: contour identifier """ icheck(0, Grid2D()) icheck(1, Bool()) c = com.contcom.GridBndToContour({"grid_name": gid, "simplify": simplify}) flow.exec_command(c) return c.added_contours2()[0]
def add_unf_ring_grid(p0, radinner, radouter, na, nr, coef=1.0, bnd=0): """Builds ring grid :param list-of-floats p0: center coordinates as [x, y] :param float radinner: :param float radouter: inner and outer radii :param int na: :param int nr: arc and radius partition respectively :param float coef: refinement coefficient: * ``coef = 1``: equidistant radius division * ``coef > 1``: refinement towards center of circle * ``0 < coef < 1``: refinement towards outer arc :param int-or-list-of-int bnd: boundary types for inner and outer ring boundaries :return: created grid identifier """ if radinner > radouter: radinner, radouter = radouter, radinner icheck(0, Point2D()) icheck(1, Float(grthan=0.0)) icheck(2, Float(grthan=0.0)) icheck(3, UInt(minv=3)) icheck(4, UInt(minv=1)) icheck(5, Float(grthan=0.0)) icheck(6, ListOr1(ZType(), llen=2)) bnd = bnd[:2] if isinstance(bnd, list) else [bnd, bnd] c = com.gridcom.AddUnfRingGrid({ "p0": p0, "radinner": radinner, "radouter": radouter, "na": na, "nr": nr, "coef": coef, "bnd": bnd }) flow.exec_command(c) return c.added_grids2()[0]
def connect_subcontours(sources, fix=[], close="no", shiftnext=True): """ Connects sequence of open contours into a single contour even if neighboring contours have no equal end points :param sources: list of open contour identifiers :param list-of-int fix: indicies of **sources** contours which could not be shifted or stretched. :param str close: last connection algorithm: ``no``, ``yes`` or ``force`` :param bool shiftnext: if True then each next contour will be shifted to the end point of previous one, otherwise both contours will be stretched to match average end point. To connect given contours this procedure implements stretching and shifting of those ones not listed in **fix** list. If two adjacent source contours are marked as fixed but have no common end points an exception will be raised. If **close** is ``yes`` then last contour of **sources** will be connected with the first one with algorithm depending on **fix** and **shiftnext** options. If **close** is ``no`` then ending contours will be left as they are. In that case resulting contour will be open until first and last points are exactly equal. **close** = ``force`` algorithm works like **close** = ``no`` but creates a section which explicitly connects first and last contours by a straight line. """ icheck(0, UList(Cont2D())) icheck(1, UList(UInt(maxv=len(sources) - 1), maxlen=len(sources))) icheck(2, OneOf('no', 'yes', 'force')) icheck(3, Bool()) args = {} args['src'] = sources args['fix'] = copy.deepcopy(fix) args['close'] = close args['shiftnext'] = shiftnext c = com.contcom.ConnectSubcontours(args) flow.exec_command(c) return c.added_contours2()[0]
def merge_grids3(g1, g2): """ Merges 3d grids into single one. :param g1: :param g2: 3d source grids identifiers. :returns: new grid identifier. Merge procedure will process only strictly coincident boundary primitives. """ icheck(0, Grid3D()) icheck(1, Grid3D()) c = com.grid3dcom.Merge({"src1": g1, "src2": g2}) flow.exec_command(c) return c.added_grids3()[0]
def rotate_geom(objs, angle, pc=[0.0, 0.0]): """ Rotates group of 2d objects :param objs: identifier or list of identifiers of rotating 2d objects :param float angle: degree of rotation. Positive angle corresponds to counterclockwise rotation :param list-of-float pc: center of rotation :returns: None """ icheck(0, UListOr1(ACont2D())) icheck(1, Float()) icheck(2, Point2D()) ob = objs if isinstance(objs, list) else [objs] c = com.objcom.RotateGeom({"names": ob, "angle": angle, "p0": pc}) flow.exec_command(c)
def decompose_contour(cont): """ Returns set of simple singly connected contours built from input contour :param cont: contour identifier :returns: list of new contour identifiers All resulting contour vertices will have no more than two adjacent edges. If input contour has vertices with more than two connections (or self intersections) it will be splitted at these points. Tries to assemble as many closed contours as possible. """ icheck(0, ACont2D()) c = com.contcom.DecomposeContour({"source": cont}) flow.exec_command(c) return c.added_contours2()
def reflect_geom(objs, pnt1, pnt2): """ Makes a reflection of 2d geometry objects over a given line :param objs: identifier or list of identifiers of 2d objects to reflect :param list-of-float pnt1: :param list-of-float pnt2: points in [x, y] format which define a line to reflect over :returns: None """ icheck(0, UListOr1(ACont2D())) icheck(1, Point2D()) icheck(2, Point2D(noteq=[pnt1])) ob = objs if isinstance(objs, list) else [objs] c = com.objcom.ReflectGeom({"names": ob, "p1": pnt1, "p2": pnt2}) flow.exec_command(c)
def add_boundary_type(index, name="boundary1"): """ Register boundary type name. :param int index: index of boundary (>0) :param str name: user defined name of the boundary :returns: integer boundary identifier If boundary with ``index`` already exists it will be overwritten. Name of the boundary should be unique, if name already exists it will be changed automatically. """ icheck(0, ZType()) icheck(1, String()) c = com.contcom.EditBoundaryType({"index": index, "name": name}) flow.exec_command(c) return index
def grid3_bnd_to_surface(gid, separate=False): """ Returns surface object built out of grid boundary :param gid: 3D grid identifier :param bool separate: whether grid surface should be separated into singly connected set of surfaces :returns: grid identifier if **separate** is False or list of grid identifiers otherwise """ icheck(0, Grid3D()) icheck(1, Bool()) c = com.surfcom.Grid3BndToSurface({"grid_name": gid, "separate": separate}) flow.exec_command(c) if separate: return c.added_surfaces3() else: return c.added_surfaces3()[0]
def scale_geom(objs, xpc=100., ypc=100., zpc=100., refp=[0.0, 0.0, 0.0]): """ Scales objects :param objs: identifier or list of identifiers of scaling objects :param float xpc: :param float ypc: :param float zpc: percentages of scaling in x, y and z directions :param list-of-float refp: reference point as ``[x, y, z]`` which stays fixed after transformation :returns: None if **objs** contains only 2d objects **zpc** is ignored and could be ommitted, **refp** could by given as ``[x, y]``. """ icheck(0, UListOr1(AObject())) icheck(1, Float(grthan=0.)) icheck(2, Float(grthan=0.)) icheck(3, Float(grthan=0.)) icheck(4, APoint()) # for backward compatibility check if zpc was omitted if isinstance(zpc, list): refp = zpc zpc = 100. if len(refp) == 2: refp = [refp[0], refp[1], 0.] ob = objs if isinstance(objs, list) else [objs] c = com.objcom.ScaleGeom({ "names": ob, "xpc": xpc, "ypc": ypc, "zpc": zpc, "p0": refp }) flow.exec_command(c)
def move_geom(objs, dx, dy, dz=0.): """ Moves a list of objects :param objs: identifier or list of identifiers of moving objects :param float dx: :param float dy: :param float dz: shifts in x, y and z direction. Z moves take place only for 3d objects :returns: None """ icheck(0, UListOr1(AObject())) icheck(1, Float()) icheck(2, Float()) icheck(3, Float()) ob = objs if isinstance(objs, list) else [objs] c = com.objcom.MoveGeom({"names": ob, "dx": dx, "dy": dy, "dz": dz}) flow.exec_command(c)
def extract_subcontours(source, plist, project_to="vertex"): """ Extracts singly connected subcontours from given contour. :param source: source contour identifier :param list-of-list-of-float plist: consecutive list of subcontours end points :param str project_to: defines projection rule for **plist** entries * ``"line"`` projects to closest point on the source contour * ``"vertex"`` projects to closest contour vertex * ``"corner"`` projects to closest contour corner vertex :returns: list of new contours identifiers Length of **plist** should be equal or greater than two. First and last points in **plist** define first and last points of **source** segment to extract. All internal points define internal division of this segment. Hence number of resulting subcontours will equal number of points in **plist** minus one. For closed **source** contour first and last **plist** points could coincide. In that case the sum of resulting subcontours will be equal to **source**. """ icheck(0, ACont2D()) icheck(1, List(Point2D(), minlen=2)) icheck(2, OneOf("line", "vertex", "corner")) c = com.contcom.ExtractSubcontours({ 'src': source, 'plist': plist, 'project_to': project_to }) flow.exec_command(c) return c.added_contours2()
def create_contour(pnts, bnds=0): """ Create singly connected contour from sequence of points. :param list-of-list-of-floats pnts: sequence of points. If coordinates of first and last points are equal then contour is considered closed. :param single-or-list-of-boundary-identifiers bnds: boundary type for each contour segment or single identifier for the whole contour. :returns: contour identifier Example: >>> hmscript.create_contour([[0, 0], [1, 0], [1, 1], [0, 0]], [b1, b2, b3]) """ icheck(0, List(Point2D(), minlen=2)) icheck(1, ListOr1(ZType())) b = bnds if isinstance(bnds, list) else [bnds] c = com.contcom.CreateContour({"points": pnts, "bnds": b}) flow.exec_command(c) return c.added_contours2()[0]
def stripe(cont, partition, tip='no', bnd=0): """ Build a structured grid to the both sides of contour line :param cont: closed or open contour identifier :param ascending-list-of-double partition: partition perpendicular to source contour :param str tip: stripe endings meshing algorithm * ``"no"`` - no grid at endings * ``"radial"`` - radial grid at endings :param float-or-list-of-floats bnd: boundary types for input grid. List of four values provides respective values for bottom, left, right, top sides of resulting grid with respect to contour direction. :return: grid identifier Horizontal partition is taken from contour partition. Vertical partition is given by user with ``partition`` list parameter. If it starts with non zero value then grid will not contain contour nodes as its vertices. Use :func:`partition_segment` to define non-equidistant **partition** with any desired refinement if needed. """ icheck(0, ACont2D()) icheck(1, IncList(Float(grthan=0.0))) icheck(2, OneOf('no', 'radial')) icheck(3, ListOr1(ZType(), llen=4)) bnd = bnd[:4] if isinstance(bnd, list) else [bnd, bnd, bnd, bnd] arg = {"source": cont, "partition": partition, "tip": tip, "bnd": bnd} c = com.gridcom.StripeGrid(arg) flow.exec_command(c) return c.added_grids2()[0]
def _triquad(domain, constr, pts, tp): if not isinstance(domain, list): domain = [domain] if constr is not None: if not isinstance(constr, list): constr = [constr] else: constr = [] if pts is None: p2 = [] else: p2 = [] for i in range(len(pts) / 2): p2.extend(pts[2 * i + 1]) p2.append(pts[2 * i]) arg = {"domain": domain, "constr": constr, "pts": p2} if (tp == '4'): c = com.gridcom.QuadrangulateArea(arg) elif (tp == 'pebi'): c = com.gridcom.PebiFill(arg) else: c = com.gridcom.TriangulateArea(arg) flow.exec_command(c) return c.added_grids2()[0]
def partition_contour(cont, algo, step=1., angle0=30., keep_bnd=False, nedges=None, crosses=[], keep_pts=[], start=None, end=None): """ Makes connected contour partition :param cont: Contour or grid identifier :param str algo: Partition algorithm: * ``'const'``: partition with defined constant step * ``'ref_points'``: partition with step function given by a set of values refered to basic points * ``'ref_weights'``: partition with step function given by a set of values refered to local contour [0, 1] coordinate * ``'ref_lengths'``: partition with step function given by a set of values refered to local contour length coordinate :param step: For ``algo='const'`` a float number defining partition step; For ``algo='ref_points'`` - list of step values and point coordinates given as ``[ step_0, [x_0, y_0], step_1, [x_1, y_1], ....]``. For ``algo='ref_weights'`` - list of step values and point normalized 1d coordinates given as ``[ step_0, w_0, step_1, w_1, ....]``. For ``algo='ref_lengths'`` - list of step values and point 1d coordinates given as ``[ step_0, s_0, step_1, s_1, ....]``. Negative ``s_i`` shows length coordinate started from end point in reversed direction. :param float angle0: existing contour vertices which provide turns outside of ``[180 - angle0, 180 + angle0]`` degrees range will be preserved regardless of other options :param bool keep_bnd: if that is True than vertices which have different boundary features on their right and left sides will be preserved :param int nedges: if this parameter is not None then it provides exact number of edges in the resulting contour. To satisfy this condition **step** value will be multiplied by an appropriate factor. If it can not be satisfied (due to other restrictions) then an exception will be raised. :param crosses: represents set of contour which cross points with target contour will be present in resulting contour. :param keep_pts: list of points as ``[[x1, y1], [x2, y2], ...]`` list which should present in output partition. :param start: :param end: start and end points which define processing segment :returns: new contour identifier Points set defined by user for ``algo='ref_points'`` algorithm will not present in resulting contour (as well as points defined implicitly by other ``'ref_'`` algorithms). It just shows locations where step size of given length should be applied. If any point of this set is not located on the input contour then it will be projected to it. For constant stepping any contour including multiply connected ones could be passed. For ``ref_`` stepping only singly connected contours (open or closed) are allowed. If **start** and **end** points are defined then only segment between these points will be parted. Note that all closed contours are treated in counterclockwise direction. Given start/end points will be projected to closest contour vertices. ``ref_weights``, ``ref_lengths`` partition methods require definition of **start** point (To process whole contour ``end`` point could be omitted). Example: .. literalinclude:: ../../testing/py/fromdoc/ex_partcontour.py :start-after: vvvvvvvvvvvvvvvvvvvvvvvv :end-before: ^^^^^^^^^^^^^^^^^^^^^^^^ See also: :ref:`simplecontmeshing` """ if nedges <= 0: nedges = None icheck(0, ACont2D()) icheck(1, OneOf("const", "ref_points", "ref_weights", "ref_lengths")) if algo == "const": icheck(2, Float(grthan=0.0)) elif algo == "ref_points": icheck(2, CompoundList(Float(grthan=0.0), Point2D(), minlen=2)) elif algo == "ref_weights": icheck(2, CompoundList(Float(grthan=0.0), Float(within=[-1, 1, '[]']), minlen=2)) elif algo == "ref_lengths": icheck(2, CompoundList(Float(grthan=0.0), Float(), minlen=2)) icheck(3, Float()) icheck(4, Bool()) icheck(5, NoneOr(UInt(minv=1))) icheck(6, List(ACont2D())) icheck(7, List(Point2D())) icheck(8, NoneOr(Point2D())) icheck(9, NoneOr(Point2D())) if start is None and algo in ['ref_weights', 'ref_lengths']: raise InvalidArgument("Define start point for %s partition" % algo) # prepare arguments for command if algo == "const": plain_step = [step] elif algo == "ref_points": plain_step = [] for i in range(len(step) / 2): plain_step.append(step[2 * i]) plain_step.extend(step[2 * i + 1]) elif algo in ["ref_weights", "ref_lengths"]: plain_step = copy.deepcopy(step) sp, ep = None, None if start is not None: sp = [start[0], start[1]] if end is not None: ep = [end[0], end[1]] kp = [] if keep_pts is not None: for p in keep_pts: kp.append([p[0], p[1]]) args = {"algo": algo, "step": plain_step, "angle0": angle0, "keepbnd": keep_bnd, "base": cont, "nedges": nedges, "crosses": crosses, "start": sp, "end": ep, "keep_pts": kp} # call c = com.contcom.PartitionContour(args) flow.exec_command(c) return c.added_contours2()[0]