Пример #1
0
    def __init__(self, session, name='Head', size=0.3, image_file=None):
        Model.__init__(self, name, session)
        self.room_position = None

        r = size / 2
        from chimerax.surface import box_geometry
        va, na, ta = box_geometry((-r, -r, -0.1 * r), (r, r, 0.1 * r))

        if image_file is None:
            from os.path import join, dirname
            image_file = join(dirname(__file__), self.default_face_file)
        from PyQt5.QtGui import QImage
        qi = QImage(image_file)
        aspect = qi.width() / qi.height()
        va[:, 0] *= aspect
        from chimerax.graphics import qimage_to_numpy, Texture
        rgba = qimage_to_numpy(qi)
        from numpy import zeros, float32
        tc = zeros((24, 2), float32)
        tc[:] = 0.5
        tc[8:12, :] = ((0, 0), (1, 0), (0, 1), (1, 1))

        self.set_geometry(va, na, ta)
        self.color = (255, 255, 255, 255)
        self.texture = Texture(rgba)
        self.texture_coordinates = tc
Пример #2
0
def image_file_as_rgba(path):
    from os.path import expanduser, isfile
    p = expanduser(path)
    if not isfile(p):
        from chimerax.core.errors import UserError
        raise UserError('texture image file "%s" does not exist' % p)
    from PyQt5.QtGui import QImage
    qi = QImage(p)
    from chimerax.graphics import qimage_to_numpy
    rgba = qimage_to_numpy(qi)
    return rgba
Пример #3
0
 def update_image(self, base64_image_bytes):
     image_bytes = _decode_face_image(base64_image_bytes)
     from PyQt5.QtGui import QImage
     qi = QImage()
     qi.loadFromData(image_bytes)
     aspect = qi.width() / qi.height()
     va = self.vertices
     caspect = va[:, 0].max() / va[:, 1].max()
     va[:, 0] *= aspect / caspect
     self.set_geometry(va, self.normals, self.triangles)
     from chimerax.graphics import qimage_to_numpy, Texture
     rgba = qimage_to_numpy(qi)
     r = self.session.main_view.render
     r.make_current()
     self.texture.delete_texture()
     self.texture = Texture(rgba)