Exemplo n.º 1
0
def extrude_edge(occedge, pydirection, height):
    edge_midpt = calculate.edge_midpt(occedge)
    location_pt = modify.move_pt(edge_midpt, pydirection, height)
    edge2 = fetch.shape2shapetype(modify.move(edge_midpt, location_pt,
                                              occedge))
    edge_wire = make_wire_frm_edges([occedge])
    edge_wire2 = make_wire_frm_edges([edge2])
    edgeface = make_loft_with_wires([edge_wire, edge_wire2])
    facelist = fetch.geom_explorer(edgeface, "face")
    return facelist[0]
Exemplo n.º 2
0
def extrude(occface, pydir, height):
    orig_pt = calculate.face_midpt(occface)
    dest_pt = modify.move_pt(orig_pt, pydir, height)
    moved_face = modify.move(orig_pt, dest_pt, occface)
    loft = make_loft([occface, moved_face])
    face_list = fetch.geom_explorer(loft, "face")
    face_list.append(occface)
    face_list.append(moved_face)
    shell = make_shell_frm_faces(face_list)[0]
    solid = make_solid(shell)
    solid = modify.fix_close_solid(solid)
    return solid
Exemplo n.º 3
0
 def scrabbleit(self, playerinput):
     validity = mainrules(playerinput, self.board, self.players[self.turn].rack, validity=self.validitymode, filename=self.filename)   # verifying validity of move
     if validity[0]:
         gameended = False
         self.players[self.turn].score += scorer(validity[1], validity[2], self.board)  # updating score of player
         moveboard = move(validity[1][0], validity[1][1], self.players[self.turn], self.board)  # updating board
         self.board = moveboard
         if len(self.pouch.letters) > 0:
             self.pouch.pick(self.players[self.turn])  # picking new tiles
         else:
             if len(self.players[self.turn].rack) == 0:  # if the game ends by the rack of a person going empty
                 endscore(self.players, self.turn)
                 gameended = True
         self.turn += 1
         self.turn %= self.numberofplayers  # updating turn
         return True, gameended
     else:
         return False, validity[2]
Exemplo n.º 4
0
def generate_falsecolour_bar(minval, maxval, unit_str, bar_length, 
                             description_str = None, bar_pos = (0,0,0),
                             inverse = False):
    """
    This function constructs a falsecolour diagram.
 
    Parameters
    ----------
    minval : float
        The minimum value of the falsecolour bar.
        
    maxval : float
        The maximum value of the falsecolour bar.
        
    unit_str : str
        The string of the unit to be displayed on the bar.
        
    bar_length : float
        The length of the falsecolour bar.
        
    description_str : str, optional
        Description for the falsecolour bar, Default = None.
        
    bar_pos : tuple of floats, optional
        The position of the bar, Default = (0,0,0).
    
    inverse : bool
        False for red being max, True for blue being maximum.
        
    Returns
    -------
    falsecolour bar : list of OCCfaces
        The falsecolor bar which is a list of OCCfaces. 
        
    bar colour : list of tuple of floats
        Each tuple is a r,g,b that is specifying the colour of the bar.
        
    geometries of text: OCCcompound
        The geometries of the text.
        
    str_colour_list : list of tuple of floats
        Each tuple is a r,g,b that is specifying the colour of the string.
        
    value of each falsecolour : list of floats
        The value of each falsecolour.
    """
    import numpy
    interval = 10.0
    xdim = bar_length/interval
    ydim = bar_length
    rectangle = construct.make_rectangle(xdim, ydim)
    rec_mid_pt = calculate.face_midpt(rectangle)
    moved_rectangle = fetch.topo2topotype(modify.move(rec_mid_pt, bar_pos, rectangle))
    
    grid_srfs = construct.grid_face(moved_rectangle, xdim, xdim)

    #generate uniform results between max and min
    inc1 = (maxval-minval)/(interval)
    value_range = list(numpy.arange(minval, maxval+0.1, inc1))
    inc2 = inc1/2.0
    value_range_midpts = list(numpy.arange(minval+inc2, maxval, inc1))
    bar_colour = falsecolour(value_range_midpts, minval, maxval, inverse=inverse)
    grid_srfs2 = []
    moved_str_face_list = []
    srf_cnt = 0
    for srf in grid_srfs:
        reversed_srf = modify.reverse_face(srf)
        grid_srfs2.append(reversed_srf)
        res_label = round(value_range[srf_cnt],2)
        brep_str = fetch.topo2topotype(construct.make_brep_text(str(res_label), xdim/2))
        orig_pt = calculate.get_centre_bbox(brep_str)
        loc_pt = calculate.face_midpt(srf)
        loc_pt = modify.move_pt(loc_pt, (1,-0.3,0), xdim*1.2)
        moved_str = modify.move(orig_pt, loc_pt, brep_str)
        moved_str_face_list.append(moved_str)
        
        if srf_cnt == len(grid_srfs)-1:
            res_label = round(value_range[srf_cnt+1],2)
            brep_str = fetch.topo2topotype(construct.make_brep_text(str(res_label), xdim/2))
            orig_pt = calculate.get_centre_bbox(brep_str)
            loc_pt3 = modify.move_pt(loc_pt, (0,1,0), xdim)
            moved_str = modify.move(orig_pt, loc_pt3, brep_str)
            moved_str_face_list.append(moved_str)
        
            brep_str_unit = construct.make_brep_text(str(unit_str), xdim)
            orig_pt2 = calculate.get_centre_bbox(brep_str_unit)
            loc_pt2 = modify.move_pt(loc_pt, (0,1,0), xdim*2)
            moved_str = modify.move(orig_pt2, loc_pt2, brep_str_unit)
            moved_str_face_list.append(moved_str)
            
        if description_str !=None:    
            if srf_cnt == 0:
                d_str = fetch.topo2topotype(construct.make_brep_text(description_str, xdim/2))
                orig_pt2 = calculate.get_centre_bbox(d_str)
                loc_pt2 = modify.move_pt(loc_pt, (0,-1,0), xdim*5)
                moved_str = modify.move(orig_pt2, loc_pt2, d_str)
                moved_str_face_list.append(moved_str)
            

        srf_cnt+=1
        
    cmpd = construct.make_compound(moved_str_face_list)
    face_list = fetch.topo_explorer(cmpd, "face")
    meshed_list = []
    for face in face_list:    
        meshed_face_list = construct.simple_mesh(face)
        mface = construct.make_shell(meshed_face_list)
        face_mid_pt =  calculate.face_midpt(face)
        str_mid_pt = calculate.get_centre_bbox(mface)
        moved_mface = modify.move(str_mid_pt,face_mid_pt,mface)
        meshed_list.append(moved_mface)
        
    meshed_str_cmpd =construct.make_compound(meshed_list)
    str_colour_list = [(0,0,0)]
    return grid_srfs2, bar_colour, meshed_str_cmpd, str_colour_list, value_range_midpts
Exemplo n.º 5
0
def generate_falsecolour_bar(minval,
                             maxval,
                             unit_str,
                             bar_length,
                             description_str=None,
                             bar_pos=(0, 0, 0),
                             inverse=False):
    """
    This function constructs a falsecolour diagram.
 
    Parameters
    ----------
    minval : float
        The minimum value of the falsecolour bar.
        
    maxval : float
        The maximum value of the falsecolour bar.
        
    unit_str : str
        The string of the unit to be displayed on the bar.
        
    bar_length : float
        The length of the falsecolour bar.
        
    description_str : str, optional
        Description for the falsecolour bar, Default = None.
        
    bar_pos : tuple of floats, optional
        The position of the bar, Default = (0,0,0).
    
    inverse : bool
        False for red being max, True for blue being maximum.
        
    Returns
    -------
    falsecolour bar : list of OCCfaces
        The falsecolor bar which is a list of OCCfaces. 
        
    bar colour : list of tuple of floats
        Each tuple is a r,g,b that is specifying the colour of the bar.
        
    geometries of text: OCCcompound
        The geometries of the text.
        
    str_colour_list : list of tuple of floats
        Each tuple is a r,g,b that is specifying the colour of the string.
        
    value of each falsecolour : list of floats
        The value of each falsecolour.
    """
    import numpy
    interval = 10.0
    xdim = bar_length / interval
    ydim = bar_length
    rectangle = construct.make_rectangle(xdim, ydim)
    rec_mid_pt = calculate.face_midpt(rectangle)
    moved_rectangle = fetch.topo2topotype(
        modify.move(rec_mid_pt, bar_pos, rectangle))

    grid_srfs = construct.grid_face(moved_rectangle, xdim, xdim)

    #generate uniform results between max and min
    inc1 = (maxval - minval) / (interval)
    value_range = list(numpy.arange(minval, maxval + 0.1, inc1))
    inc2 = inc1 / 2.0
    value_range_midpts = list(numpy.arange(minval + inc2, maxval, inc1))
    bar_colour = falsecolour(value_range_midpts,
                             minval,
                             maxval,
                             inverse=inverse)
    grid_srfs2 = []
    moved_str_face_list = []
    srf_cnt = 0
    for srf in grid_srfs:
        reversed_srf = modify.reverse_face(srf)
        grid_srfs2.append(reversed_srf)
        res_label = round(value_range[srf_cnt], 2)
        brep_str = fetch.topo2topotype(
            construct.make_brep_text(str(res_label), xdim / 2))
        orig_pt = calculate.get_centre_bbox(brep_str)
        loc_pt = calculate.face_midpt(srf)
        loc_pt = modify.move_pt(loc_pt, (1, -0.3, 0), xdim * 1.2)
        moved_str = modify.move(orig_pt, loc_pt, brep_str)
        moved_str_face_list.append(moved_str)

        if srf_cnt == len(grid_srfs) - 1:
            res_label = round(value_range[srf_cnt + 1], 2)
            brep_str = fetch.topo2topotype(
                construct.make_brep_text(str(res_label), xdim / 2))
            orig_pt = calculate.get_centre_bbox(brep_str)
            loc_pt3 = modify.move_pt(loc_pt, (0, 1, 0), xdim)
            moved_str = modify.move(orig_pt, loc_pt3, brep_str)
            moved_str_face_list.append(moved_str)

            brep_str_unit = construct.make_brep_text(str(unit_str), xdim)
            orig_pt2 = calculate.get_centre_bbox(brep_str_unit)
            loc_pt2 = modify.move_pt(loc_pt, (0, 1, 0), xdim * 2)
            moved_str = modify.move(orig_pt2, loc_pt2, brep_str_unit)
            moved_str_face_list.append(moved_str)

        if description_str != None:
            if srf_cnt == 0:
                d_str = fetch.topo2topotype(
                    construct.make_brep_text(description_str, xdim / 2))
                orig_pt2 = calculate.get_centre_bbox(d_str)
                loc_pt2 = modify.move_pt(loc_pt, (0, -1, 0), xdim * 5)
                moved_str = modify.move(orig_pt2, loc_pt2, d_str)
                moved_str_face_list.append(moved_str)

        srf_cnt += 1

    cmpd = construct.make_compound(moved_str_face_list)
    face_list = fetch.topo_explorer(cmpd, "face")
    meshed_list = []
    for face in face_list:
        meshed_face_list = construct.simple_mesh(face)
        mface = construct.make_shell(meshed_face_list)
        face_mid_pt = calculate.face_midpt(face)
        str_mid_pt = calculate.get_centre_bbox(mface)
        moved_mface = modify.move(str_mid_pt, face_mid_pt, mface)
        meshed_list.append(moved_mface)

    meshed_str_cmpd = construct.make_compound(meshed_list)
    str_colour_list = [(0, 0, 0)]
    return grid_srfs2, bar_colour, meshed_str_cmpd, str_colour_list, value_range_midpts
Exemplo n.º 6
0
def write_2_collada_falsecolour(occface_list,
                                result_list,
                                unit_str,
                                dae_filepath,
                                description_str=None,
                                minval=None,
                                maxval=None,
                                other_occface_list=None,
                                other_occedge_list=None):
    """
    This function writes a falsecolour 3D model into a Collada file.
 
    Parameters
    ----------
    occface_list : list of OCCfaces
        The geometries to be visualised with the results. The list of geometries must correspond to the list of results. Other OCCtopologies
        are also accepted, but the OCCtopology must contain OCCfaces. OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, 
        OCCsolid, OCCshell, OCCface. 
        
    result_list : list of floats
        The results to be visualised. The list of results must correspond to the occface_list.
        
    unit_str : str
        The string of the unit to be displayed on the bar.
        
    dae_filepath : str
        The file path of the DAE (Collada) file.
        
    description_str : str, optional
        Description for the falsecolour bar, Default = None.
        
    minval : float, optional
        The minimum value of the falsecolour rgb, Default = None. If None the maximum value is equal to the maximum value from the results.
        
    maxval : float, optional
        The maximum value of the falsecolour rgb, Default = None. If None the maximum value is equal to the minimum value from the results.
        
    other_occface_list : list of OCCfaces, optional
        Other geometries to be visualised together with the results, Default = None. Other OCCtopologies
        are also accepted, but the OCCtopology must contain OCCfaces. OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, 
        OCCsolid, OCCshell, OCCface. 
        
    other_occedge_list : list of OCCedges, optional
        Other OCCedges to be visualised together with the results, Default = None.
        
    Returns
    -------
    None : None
        The geometries are written to a DAE file.
    """
    if minval == None:
        minval = min(result_list)
    if maxval == None:
        maxval = max(result_list)

    #FOR CREATING THE FALSECOLOUR BAR AND LABELS
    topo_cmpd = construct.make_compound(occface_list)
    xmin, ymin, zmin, xmax, ymax, zmax = calculate.get_bounding_box(topo_cmpd)
    topo_centre_pt = calculate.get_centre_bbox(topo_cmpd)
    otopo_centre_pt = (topo_centre_pt[0], topo_centre_pt[1], zmin)
    topo_cmpd = modify.move(otopo_centre_pt, (0, 0, 0), topo_cmpd)
    xmin, ymin, zmin, xmax, ymax, zmax = calculate.get_bounding_box(topo_cmpd)
    x_extend = xmax - xmin
    y_extend = ymax - ymin
    topo_centre_pt = calculate.get_centre_bbox(topo_cmpd)
    topo_centre_pt = (topo_centre_pt[0], topo_centre_pt[1], zmin)
    loc_pt = modify.move_pt(topo_centre_pt, (1, 0, 0), x_extend / 1.5)

    grid_srfs, bar_colour, str_cmpd, str_colour_list, value_midpts = utility.generate_falsecolour_bar(
        minval,
        maxval,
        unit_str,
        y_extend,
        description_str=description_str,
        bar_pos=loc_pt)

    #DIVIDE THE RESULT INTO 10 DIVISION LIKE THE FALSECOLOUR BAR
    falsecolour_list = []
    for result in result_list:
        if result >= maxval:
            falsecolour_list.append(bar_colour[-1])

        elif result <= minval:
            falsecolour_list.append(bar_colour[0])

        else:
            inc = (value_midpts[1] - value_midpts[0]) / 2.0
            ur_cnt = 0
            for midpt in value_midpts:
                if midpt - inc <= result <= midpt + inc:
                    falsecolour_list.append(bar_colour[ur_cnt])
                    break
                ur_cnt += 1

    #ARRANGE THE SURFACE AS ACCORDING TO ITS COLOUR
    colour_list = []
    c_srf_list = []
    for r_cnt in range(len(falsecolour_list)):
        fcolour = falsecolour_list[r_cnt]
        rf = occface_list[r_cnt]
        rf = modify.move(otopo_centre_pt, (0, 0, 0), rf)
        if fcolour not in colour_list:
            colour_list.append(fcolour)
            c_srf_list.append([rf])

        elif fcolour in colour_list:
            c_index = colour_list.index(fcolour)
            c_srf_list[c_index].append(rf)

    cmpd_list = []
    #SORT EACH SURFACE AS A COMPOUND
    for c_cnt in range(len(c_srf_list)):
        c_srfs = c_srf_list[c_cnt]
        compound = construct.make_compound(c_srfs)
        cmpd_list.append(compound)

    if other_occface_list != None:
        other_cmpd = construct.make_compound(other_occface_list)
        other_cmpd = modify.move(otopo_centre_pt, (0, 0, 0), other_cmpd)
        other_colour_list = [(1, 1, 1)]
        to_be_written_occface_list = cmpd_list + grid_srfs + [str_cmpd
                                                              ] + [other_cmpd]
        to_be_written_colour_list = colour_list + bar_colour + str_colour_list + other_colour_list

    else:
        to_be_written_occface_list = cmpd_list + grid_srfs + [str_cmpd]
        to_be_written_colour_list = colour_list + bar_colour + str_colour_list

    if other_occedge_list != None:
        edge_cmpd = construct.make_compound(other_occedge_list)
        edge_cmpd = modify.move(otopo_centre_pt, (0, 0, 0), edge_cmpd)
        other_occedge_list = fetch.topo_explorer(edge_cmpd, "edge")
        mesh = occtopo_2_collada(
            dae_filepath,
            occface_list=to_be_written_occface_list,
            face_rgb_colour_list=to_be_written_colour_list,
            occedge_list=other_occedge_list)
        mesh.write(dae_filepath)
    else:
        mesh = occtopo_2_collada(
            dae_filepath,
            occface_list=to_be_written_occface_list,
            face_rgb_colour_list=to_be_written_colour_list)
        mesh.write(dae_filepath)
Exemplo n.º 7
0
def write_2_collada(dae_filepath,
                    occface_list=None,
                    face_rgb_colour_list=None,
                    occedge_list=None,
                    text_string=None):
    """
    This function writes a 3D model into a Collada file.
 
    Parameters
    ----------
    dae_filepath : str
        The file path of the DAE (Collada) file.
        
    occface_list : list of OCCfaces, optional
        The geometries to be visualised with the results. The list of geometries must correspond to the list of results. Other OCCtopologies
        are also accepted, but the OCCtopology must contain OCCfaces. OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, 
        OCCsolid, OCCshell, OCCface. 
        
    face_rgb_colour_list : list of tuple of floats, optional
        Each tuple is a r,g,b that is specifying the colour of the face,Default = None. 
        The number of colours must correspond to the number of OCCfaces.
        
    occedge_list : list of OCCedges, optional
        OCCedges to be visualised together, Default = None.
        
    text_string : str, optional
        Description for the 3D model, Default = None.
        
    Returns
    -------
    None : None
        The geometries are written to a DAE file.
    """
    if text_string != None:
        if occface_list != None:
            overall_cmpd = construct.make_compound(occface_list)
        else:
            overall_cmpd = construct.make_compound(occedge_list)
            occface_list = []

        xmin, ymin, zmin, xmax, ymax, zmax = calculate.get_bounding_box(
            overall_cmpd)
        xdim = xmax - xmin
        d_str = fetch.topo2topotype(
            construct.make_brep_text(text_string, xdim / 10))
        xmin1, ymin1, zmin1, xmax1, ymax1, zmax1 = calculate.get_bounding_box(
            d_str)
        corner_pt = (xmin1, ymax1, zmin1)
        corner_pt2 = (xmin, ymin, zmin)
        moved_str = modify.move(corner_pt, corner_pt2, d_str)
        face_list = fetch.topo_explorer(moved_str, "face")
        meshed_list = []
        for face in face_list:
            meshed_face_list = construct.simple_mesh(face)
            mface = construct.make_shell(meshed_face_list)
            face_mid_pt = calculate.face_midpt(face)
            str_mid_pt = calculate.get_centre_bbox(mface)
            moved_mface = modify.move(str_mid_pt, face_mid_pt, mface)
            meshed_list.append(moved_mface)

        meshed_str_cmpd = construct.make_compound(meshed_list)
        occface_list.append(meshed_str_cmpd)

        if face_rgb_colour_list != None:
            face_rgb_colour_list.append((0, 0, 0))

    mesh = occtopo_2_collada(dae_filepath,
                             occface_list=occface_list,
                             face_rgb_colour_list=face_rgb_colour_list,
                             occedge_list=occedge_list)

    mesh.write(dae_filepath)