예제 #1
0
def box(min=[0, 0, 0],
        max=[1, 1, 1],
        filled=False,
        color=QColor("blue"),
        effect_f=CustomEffects.material,
        matrix=np.eye(4, dtype='f4'),
        name="box"):

    color = ensure_QColor(color)

    indices = [0,1,3, 3,2,0,   7,5,4, 4,6,7,   4,5,1, 1,0,4,   5,7,3, 3,1,5,   6,2,3, 3,7,6,   4,0,2, 2,6,4] if filled else\
              [0,1, 1,3, 3,2, 2,0,       4,5, 5,7, 7,6, 6,4,      0,4, 1,5, 2,6, 3,7]

    vertices = [
        [min[0], min[1], min[2]]  #0
        ,
        [min[0], min[1], max[2]]  #1
        ,
        [min[0], max[1], min[2]]  #2
        ,
        [min[0], max[1], max[2]]  #3
        ,
        [max[0], min[1], min[2]]  #4
        ,
        [max[0], min[1], max[2]]  #5
        ,
        [max[0], max[1], min[2]]  #6
        ,
        [max[0], max[1], max[2]]  #7
    ]

    normals = [
        [-0.577350269, -0.577350269, -0.577350269]  #0
        ,
        [-0.577350269, -0.577350269, 0.577350269]  #1
        ,
        [-0.577350269, 0.577350269, -0.577350269]  #2
        ,
        [-0.577350269, 0.577350269, 0.577350269]  #3
        ,
        [0.577350269, -0.577350269, -0.577350269]  #4
        ,
        [0.577350269, -0.577350269, 0.577350269]  #5
        ,
        [0.577350269, 0.577350269, -0.577350269]  #6
        ,
        [0.577350269, 0.577350269, 0.577350269]  #7
    ]

    return Actors.Actor(
        geometry=Geometry.Geometry(
            indices=Array.Array(ndarray=np.array(indices, 'u4')),
            attribs=Geometry.Attribs(
                vertices=Array.Array(ndarray=np.array(vertices, 'f4')),
                normals=Array.Array(ndarray=np.array(normals, 'f4'))),
            primitive_type=Geometry.PrimitiveType.TRIANGLES
            if filled else Geometry.PrimitiveType.LINES),
        effect=effect_f(color) if filled else CustomEffects.emissive(color),
        transform=ensure_Transform(matrix),
        name=name)
예제 #2
0
def lines(indices,
          vertices,
          color=QColor("blue"),
          matrix=np.eye(4, dtype='f4'),
          name="lines"):
    color = ensure_QColor(color)
    return Actors.Actor(geometry=Geometry.Geometry(
        indices=Array.Array(ndarray=indices),
        attribs=Geometry.Attribs(vertices=Array.Array(ndarray=vertices)),
        primitive_type=Geometry.PrimitiveType.LINES),
                        effect=CustomEffects.emissive(color),
                        transform=ensure_Transform(matrix),
                        name=name)
예제 #3
0
def text(text,
         font="Arial",
         font_size=6,
         line_width=1,
         color=QColor("blue"),
         matrix=np.eye(4, dtype='f4'),
         is_billboard=True,
         name="text",
         scale=0.1,
         origin=[0, 0, 0],
         u=[1, 0, 0],
         v=[0, 1, 0],
         w=[0, 0, 1]):
    '''
        Warning, this function can crash if called before any call to QApplication(sys.argv)
    '''

    color = ensure_QColor(color)

    origin = utils.to_numpy(origin)
    u = utils.to_numpy(u)
    v = utils.to_numpy(v)
    w = utils.to_numpy(w)

    indices = []
    vertices = []

    path = QPainterPath()
    path.addText(QPointF(0, 0), QFont(font, font_size), text)
    polygons = path.toSubpathPolygons()
    for polygon in polygons:
        for point in polygon:
            indices.append(len(vertices))
            p = utils.to_numpy([point.x(), point.y(), 0]) * scale
            vertices.append(origin + p[0] * u + p[1] * v + p[2] * w)
        indices.append(-1)

    return Actors.Actor(geometry=Geometry.Geometry(
        indices=Array.Array(ndarray=np.array(indices, 'u4')),
        attribs=Geometry.Attribs(vertices=Array.Array(
            ndarray=np.array(vertices, 'f4'))),
        primitive_type=Geometry.PrimitiveType.LINE_LOOP),
                        effect=CustomEffects.emissive(
                            color,
                            line_width=line_width,
                            is_billboard=is_billboard),
                        transform=ensure_Transform(matrix),
                        name=f"{name}_{text}")
예제 #4
0
def bbox(c=[0, 0, 0],
         d=[0, 0, 0],
         r=[0, 0, 0],
         color=QColor("blue"),
         effect_f=CustomEffects.material,
         matrix=np.eye(4, dtype='f4'),
         name="bbox",
         return_anchor=False,
         draw_orientation=True):

    color = ensure_QColor(color)

    indices = [
        0, 1, 1, 3, 3, 2, 2, 0, 4, 5, 5, 7, 7, 6, 6, 4, 0, 4, 1, 5, 2, 6, 3, 7
    ]
    vertices = linalg.bbox_to_8coordinates(c, d, r)
    vertices = np.vstack([vertices, np.mean(vertices[[5, 7]], axis=0)])

    if draw_orientation:
        # add central front point
        # and indices to draw the direction arrow
        indices += [1, 8, 3, 8]

    text_anchor = vertices[np.argmin(np.sum(vertices, axis=1))]
    vertices = vertices.astype('f4')

    actor = Actors.Actor(geometry=Geometry.Geometry(
        indices=Array.Array(ndarray=np.array(indices, 'u4')),
        attribs=Geometry.Attribs(vertices=Array.Array(ndarray=vertices)),
        primitive_type=Geometry.PrimitiveType.LINES),
                         effect=CustomEffects.emissive(color),
                         transform=ensure_Transform(matrix),
                         name=name)

    if return_anchor:
        return actor, vertices[-1]
    else:
        return actor