Пример #1
0
    def draw_image(self):
        if not self.needs_refresh:
            return
        self.needs_refresh = False
        w, h = (self.w, self.h)
        clearws()
        setwindow(0, self.w, 0, self.h)
        setviewport(0, 1, 0, 1)

        setbackgroundcolor(1, 1, 1, 0)
        vertices, normals = triangulate(data, \
          (1.0/64, 1.0/64, 1.0/128), (-0.5, -0.5, -0.5), self.isolevel)
        mesh = createmesh(len(vertices)*3, vertices, normals, \
          ones(vertices.shape))
        drawmesh(mesh, 1, (0,0,0), (0,0,1), (0,1,0), (1,1,1), (1,1,1))
        center = spherical_to_cartesian(-2, pi*self.y/self.h+pi/2, pi*self.x/self.w)
        up = spherical_to_cartesian(1, pi*self.y/self.h+pi, pi*self.x/self.w)
        cameralookat(center[0], center[1], -0.25+center[2], 0, 0, -0.25, up[0], up[1], up[2])
        drawimage(0, self.w, 0, self.h, \
          self.w, self.h, GR3_Drawable.GR3_DRAWABLE_GKS)
        if self.export:
            export("mri.html", 800, 800)
            print("Saved current isosurface to mri.html")
            self.export = False
        clear()
        deletemesh(c_int(mesh.value))
Пример #2
0
    def draw_image(self):
        w, h = (self.w, self.h)
        clearws()
        setwindow(0, self.w, 0, self.h)
        setviewport(0, 1, 0, 1)

        setbackgroundcolor(1, 1, 1, 0)
        vertices, normals = triangulate(data, \
          (1.0/64, 1.0/64, 1.0/128), (-0.5, -0.5, -0.5), self.isolevel)
        mesh = createmesh(len(vertices)*3, vertices, normals, \
          ones(vertices.shape))
        drawmesh(mesh, 1, (0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 1, 1),
                 (1, 1, 1))
        center = spherical_to_cartesian(-2, pi * self.y / self.h + pi / 2,
                                        pi * self.x / self.w)
        up = spherical_to_cartesian(1, pi * self.y / self.h + pi,
                                    pi * self.x / self.w)
        cameralookat(center[0], center[1], -0.25 + center[2], 0, 0, -0.25,
                     up[0], up[1], up[2])
        drawimage(0, self.w, 0, self.h, \
          self.w, self.h, GR3_Drawable.GR3_DRAWABLE_GKS)
        if self.export:
            export("mri.html", 800, 800)
            print("Saved current isosurface to mri.html")
            self.export = False
        clear()
        deletemesh(c_int(mesh.value))
Пример #3
0
    def draw_image(self):
        if not self.needs_refresh:
            return
        self.needs_refresh = False
        gr.clearws()
        gr.setwindow(0, self.w, 0, self.h)
        gr.setviewport(0, 1, 0, 1)

        gr3.setbackgroundcolor(1, 1, 1, 0)
        vertices, normals = gr3.triangulate(data,
                                            (1.0 / 64, 1.0 / 64, 1.0 / 128),
                                            (-0.5, -0.5, -0.5), self.isolevel)
        mesh = gr3.createmesh(
            len(vertices) * 3, vertices, normals, np.ones(vertices.shape))
        gr3.drawmesh(mesh, 1, (0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 1, 1),
                     (1, 1, 1))
        center = spherical_to_cartesian(-2,
                                        np.pi * self.y / self.h + np.pi / 2,
                                        np.pi * self.x / self.w)
        up = spherical_to_cartesian(1, np.pi * self.y / self.h + np.pi,
                                    np.pi * self.x / self.w)
        gr3.cameralookat(center[0], center[1], -0.25 + center[2], 0, 0, -0.25,
                         up[0], up[1], up[2])
        gr3.drawimage(0, self.w, 0, self.h, self.w, self.h,
                      gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
        if self.export:
            gr3.export("mri.html", 800, 800)
            print("Saved current isosurface to mri.html")
            self.export = False
        gr3.clear()
        gr3.deletemesh(c_int(mesh.value))
Пример #4
0
 def save_screenshot(self, file_name, width=3840, height=2160, first=True, last=True):
     """
     Save a screenshot in the given resolution.
     ``first`` and ``last`` can be used to indicate if the first or last screenshot is taken when
     multiple images are saved in a loop for example.
     """
     if first and self.assigned_opengl_context is not None:
         self.assigned_opengl_context.makeCurrent()
     gr3.export(file_name, width, height)
     if last and self.assigned_opengl_context is not None:
         self.assigned_opengl_context.doneCurrent()
Пример #5
0
def keyboard(key, *args):
    if not isinstance(key, str):
        key = key.decode('utf-8')
    if key == 'p':
        gr3.export("test.pov", 0, 0)
    elif key == 'j':
        gr3.export("test.html", 800, 800)
    elif key == 'n':
        gr3.export("test.png", 800, 800)
    elif key == 'm':
        gr3.export("test.jpg", 800, 800)
    elif key == ' ':
        gr3.terminate()
        glutDestroyWindow(window_id)
        sys.exit()
    elif key == '0':
        gr3.setquality(0)
    elif key == '1':
        gr3.setquality(2)
    elif key == '2':
        gr3.setquality(4)
    elif key == '3':
        gr3.setquality(8)
    elif key == '4':
        gr3.setquality(3)
    elif key == '5':
        gr3.setquality(5)
    elif key == '6':
        gr3.setquality(9)
    else:
        print(key, ord(key))
Пример #6
0
def keyboard(key, *args):
    if key == 'p':
        gr3.export("test.pov", 0, 0)
    elif key == 'j':
        gr3.export("test.html", 800, 800)
    elif key == 'n':
        gr3.export("test.png", 800, 800)
    elif key == 'm':
        gr3.export("test.jpg", 800, 800)
    elif key == ' ':
        gr3.terminate()
        sys.exit()
    elif key == '0':
        gr3.setquality(0)
    elif key == '1':
        gr3.setquality(2)
    elif key == '2':
        gr3.setquality(4)
    elif key == '3':
        gr3.setquality(8)
    elif key == '4':
        gr3.setquality(3)
    elif key == '5':
        gr3.setquality(5)
    elif key == '6':
        gr3.setquality(9)
    else:
        print key, ord(key)
Пример #7
0
def keyboard(key, *args):
    if key == 'p':
        gr3.export("test.pov",0,0)
    elif key == 'j':
        gr3.export("test.html",800,800)
    elif key == 'n':
        gr3.export("test.png",800,800)
    elif key == 'm':
        gr3.export("test.jpg",800,800)
    elif key == ' ':
        gr3.terminate()
        sys.exit()
    elif key == '0':
        gr3.setquality(0)
    elif key == '1':
        gr3.setquality(2)
    elif key == '2':
        gr3.setquality(4)
    elif key == '3':
        gr3.setquality(8)
    elif key == '4':
        gr3.setquality(3)
    elif key == '5':
        gr3.setquality(5)
    elif key == '6':
        gr3.setquality(9)
    else:
        print key, ord(key)
Пример #8
0
def on_export_menu(entry):
    if entry == 1:
        filename = "scene.pov"
    elif entry == 2:
        filename = "scene.html"
    elif entry == 3:
        filename = "scene.jpg"
    elif entry == 4:
        filename = "scene.png"
    else:
        return 1
    gr3.setquality(export_quality)
    gr3.export(filename, 800, 800)
    gr3.setquality(0)
    return 0
Пример #9
0
def on_export_menu(entry):
    if entry == 1:
        filename = "scene.pov"
    elif entry == 2:
        filename = "scene.html"
    elif entry == 3:
        filename = "scene.jpg"
    elif entry == 4:
        filename = "scene.png"
    else:
        return 1
    gr3.setquality(export_quality)
    gr3.export(filename,800,800)
    gr3.setquality(0)
    return 0
Пример #10
0
def export(molecule,
           file_name,
           width=500,
           height=500,
           show_bonds=True,
           bonds_method='radii',
           bonds_param=None,
           camera=None):
    """
    Draw the given molecule into a given file. The file type is determined by
    the file extension, e.g. '.png' or '.html'. By default, bonds are drawn,
    if this is undesired the show_bonds parameter can be set to False.
    For information on the bond calculation, see Molecule.calculate_bonds.
    If you pass a tuple of camera position, center of view and an up vector to
    the camera parameter, the camera will be set accordingly. Otherwise the
    molecule will be viewed in the direction of the z axis, with the y axis
    pointing upward.
    """
    global _camera
    molecule.positions -= np.mean(molecule.positions, axis=0)
    max_atom_distance = np.max(la.norm(molecule.positions, axis=1))
    if show_bonds:
        molecule.calculate_bonds(bonds_method, bonds_param)

    if camera is None:
        if _camera is None:
            camera_distance = -max_atom_distance * 2.5
            camera = ((0, 0, camera_distance), (0, 0, 0), (0, 1, 0))
        else:
            camera = _camera
    camera = np.array(camera)
    _camera = camera

    # Create the GR3 scene
    gr3.setbackgroundcolor(255, 255, 255, 0)
    _set_gr3_camera()
    _create_gr3_scene(molecule, show_bonds)
    glEnable(GL_DEPTH_TEST)
    gr3.setquality(gr3.GR3_Quality.GR3_QUALITY_OPENGL_16X_SSAA)
    gr3.export(file_name, width, height)
    glBindFramebuffer(GL_FRAMEBUFFER, 0)
    glDisable(GL_DEPTH_TEST)
Пример #11
0
def export(molecule, file_name, width=500, height=500,
           show_bonds=True, bonds_method='radii', bonds_param=None,
           camera=None):
    """
    Draw the given molecule into a given file. The file type is determined by
    the file extension, e.g. '.png' or '.html'. By default, bonds are drawn,
    if this is undesired the show_bonds parameter can be set to False.
    For information on the bond calculation, see Molecule.calculate_bonds.
    If you pass a tuple of camera position, center of view and an up vector to
    the camera parameter, the camera will be set accordingly. Otherwise the
    molecule will be viewed in the direction of the z axis, with the y axis
    pointing upward.
    """
    global _camera
    molecule.positions -= np.mean(molecule.positions, axis=0)
    max_atom_distance = np.max(la.norm(molecule.positions, axis=1))
    if show_bonds:
        molecule.calculate_bonds(bonds_method, bonds_param)

    if camera is None:
        if _camera is None:
            camera_distance = -max_atom_distance*2.5
            camera = ((0, 0, camera_distance),
                      (0, 0, 0),
                      (0, 1, 0))
        else:
            camera = _camera
    camera = np.array(camera)
    _camera = camera

    # Create the GR3 scene
    gr3.setbackgroundcolor(255, 255, 255, 0)
    _set_gr3_camera()
    _create_gr3_scene(molecule, show_bonds)
    glEnable(GL_DEPTH_TEST)
    gr3.export(file_name, width, height)
    glBindFramebuffer(GL_FRAMEBUFFER, 0)
    glDisable(GL_DEPTH_TEST)
Пример #12
0
    np.save(filename+'.npy', filedata)
print('Done.')

positions = filedata[:, :3].astype(np.int32)
directions = filedata[:, 3:].astype(np.float32)

# define the values used for calculating the isosurface and the isolevel
isovalue = 0
values = directions[:, 2]

# negate the values, as we want negative z to define "inside"
isovalue = -isovalue
values = -values

# transform the values to the range [0, 1]
isovalue -= values.min()
values -= values.min()
isovalue /= values.max()
values /= values.max()

# write them into a contiguous array
nx, ny, nz = positions.max(axis=0)+1
data = np.zeros((nx, ny, nz), np.float32)
ix, iy, iz = positions.T
data[ix, iy, iz] = values

# write out an HTML file
gr3.cameralookat(0, 0, 2, 0, 0, 0, 0, 1, 0)
gr3.drawisosurfacemesh(data, isovalue=isovalue, step=[2.0/(nx-1), 2.0/(ny-1), 2.0/(nz-1)], offset=[-1, -1, -1], position=(0, 0, 0))
gr3.export("output.html", 1024, 1024)
Пример #13
0
directions = filedata[:, 3:].astype(np.float32)

# define the values used for calculating the isosurface and the isolevel
isovalue = 0
values = directions[:, 2]

# negate the values, as we want negative z to define "inside"
isovalue = -isovalue
values = -values

# transform the values to the range [0, 1]
isovalue -= values.min()
values -= values.min()
isovalue /= values.max()
values /= values.max()

# write them into a contiguous array
nx, ny, nz = positions.max(axis=0) + 1
data = np.zeros((nx, ny, nz), np.float32)
ix, iy, iz = positions.T
data[ix, iy, iz] = values

# write out an HTML file
gr3.cameralookat(0, 0, 2, 0, 0, 0, 0, 1, 0)
gr3.drawisosurfacemesh(data,
                       isovalue=isovalue,
                       step=[2.0 / (nx - 1), 2.0 / (ny - 1), 2.0 / (nz - 1)],
                       offset=[-1, -1, -1],
                       position=(0, 0, 0))
gr3.export("output.html", 1024, 1024)