コード例 #1
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))
コード例 #2
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))
コード例 #3
0
def draw(mesh, x=None, y=None, z=None):
    gr3.clear()
    gr3.drawmesh(mesh, 1, (0,0,0), (0,0,1), (0,1,0), (1,1,1), (1,1,1))
    gr3.drawslicemeshes(data,  x=x, y=y, z=z)
    gr.clearws()
    gr3.drawimage(0, 1, 0, 1, 500, 500, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr.updatews()
コード例 #4
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))
コード例 #5
0
ファイル: slices.py プロジェクト: cfelder/python-gr
def draw(mesh, x=None, y=None, z=None):
    gr3.clear()
    gr3.drawmesh(mesh, 1, (0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 1, 1),
                 (1, 1, 1))
    gr3.drawslicemeshes(data, x=x, y=y, z=z)
    gr.clearws()
    gr3.drawimage(0, 1, 0, 1, 500, 500, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr.updatews()
コード例 #6
0
def _plot_iso(v):
    global _plt
    viewport = _plt.kwargs['viewport']
    if viewport[3] - viewport[2] < viewport[1] - viewport[0]:
        width = viewport[3] - viewport[2]
        center_x = 0.5 * (viewport[0] + viewport[1])
        x_min = max(center_x - 0.5 * width, viewport[0])
        x_max = min(center_x + 0.5 * width, viewport[1])
        y_min = viewport[2]
        y_max = viewport[3]
    else:
        height = viewport[1] - viewport[0]
        center_y = 0.5 * (viewport[2] + viewport[3])
        x_min = viewport[0]
        x_max = viewport[1]
        y_min = max(center_y - 0.5 * height, viewport[2])
        y_max = min(center_y + 0.5 * height, viewport[3])

    gr.selntran(0)
    usable_vs = v[np.abs(v) != np.inf]
    if np.prod(usable_vs.shape) == 0:
        return
    v_max = usable_vs.max()
    v_min = usable_vs.min()
    if v_min == v_max:
        return
    uint16_max = np.iinfo(np.uint16).max
    v = (np.clip(v, v_min, v_max) - v_min) / (v_max - v_min) * uint16_max
    values = v.astype(np.uint16)
    nx, ny, nz = v.shape
    isovalue = _plt.kwargs.get('isovalue', 0.5)
    rotation = np.radians(_plt.kwargs.get('rotation', 40))
    tilt = np.radians(_plt.kwargs.get('tilt', 70))
    gr3.clear()
    mesh = gr3.createisosurfacemesh(values,
                                    (2 / (nx - 1), 2 / (ny - 1), 2 / (nz - 1)),
                                    (-1., -1., -1.),
                                    int(isovalue * uint16_max))
    color = _plt.kwargs.get('color', (0.0, 0.5, 0.8))
    gr3.setbackgroundcolor(1, 1, 1, 0)
    gr3.drawmesh(mesh, 1, (0, 0, 0), (0, 0, 1), (0, 1, 0), color, (1, 1, 1))
    r = 2.5
    gr3.cameralookat(r * np.sin(tilt) * np.sin(rotation), r * np.cos(tilt),
                     r * np.sin(tilt) * np.cos(rotation), 0, 0, 0, 0, 1, 0)
    gr3.drawimage(x_min, x_max, y_min, y_max, 500, 500,
                  gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr3.deletemesh(mesh)
    gr.selntran(1)
コード例 #7
0
ファイル: visualization.py プロジェクト: sciapp/pyMolDyn
 def draw_cavities(self, cavities, color, cavity_type, indices=None):
     if indices is None:
         indices = range(self.results.domains.number)
     for index in set(indices):
         if 0 <= index < len(cavities.triangles):
             triangles = cavities.triangles[index]
             gr3._gr3.gr3_setobjectid(gr3.c_int(len(self.objectids)))
             self.objectids.append((cavity_type, index))
             mesh = gr3.createmesh(triangles.shape[1] * 3,
                                   triangles[0, :, :, :],
                                   triangles[1, :, :, :],
                                   [color] * (triangles.shape[1] * 3))
             gr3.drawmesh(mesh, 1, (0, 0, 0), (0, 0, 1), (0, 1, 0),
                          (1, 1, 1), (1, 1, 1))
             gr3.deletemesh(c_int(mesh.value))
     gr3._gr3.gr3_setobjectid(gr3.c_int(0))
コード例 #8
0
def _plot_iso(v):
    global _plt
    viewport = _plt.kwargs['viewport']
    if viewport[3] - viewport[2] < viewport[1] - viewport[0]:
        width = viewport[3] - viewport[2]
        center_x = 0.5 * (viewport[0] + viewport[1])
        x_min = max(center_x - 0.5 * width, viewport[0])
        x_max = min(center_x + 0.5 * width, viewport[1])
        y_min = viewport[2]
        y_max = viewport[3]
    else:
        height = viewport[1] - viewport[0]
        center_y = 0.5 * (viewport[2] + viewport[3])
        x_min = viewport[0]
        x_max = viewport[1]
        y_min = max(center_y - 0.5 * height, viewport[2])
        y_max = min(center_y + 0.5 * height, viewport[3])

    gr.selntran(0)
    usable_vs = v[np.abs(v) != np.inf]
    if np.prod(usable_vs.shape) == 0:
        return
    v_max = usable_vs.max()
    v_min = usable_vs.min()
    if v_min == v_max:
        return
    uint16_max = np.iinfo(np.uint16).max
    v = (np.clip(v, v_min, v_max) - v_min) / (v_max - v_min) * uint16_max
    values = v.astype(np.uint16)
    nx, ny, nz = v.shape
    isovalue = _plt.kwargs.get('isovalue', 0.5)
    rotation = np.radians(_plt.kwargs.get('rotation', 40))
    tilt = np.radians(_plt.kwargs.get('tilt', 70))
    gr3.clear()
    mesh = gr3.createisosurfacemesh(values, (2/(nx-1), 2/(ny-1), 2/(nz-1)),
                                    (-1., -1., -1.),
                                    int(isovalue * uint16_max))
    color = _plt.kwargs.get('color', (0.0, 0.5, 0.8))
    gr3.setbackgroundcolor(1, 1, 1, 0)
    gr3.drawmesh(mesh, 1, (0, 0, 0), (0, 0, 1), (0, 1, 0), color, (1, 1, 1))
    r = 2.5
    gr3.cameralookat(r*np.sin(tilt)*np.sin(rotation), r*np.cos(tilt), r*np.sin(tilt)*np.cos(rotation), 0, 0, 0, 0, 1, 0)
    gr3.drawimage(x_min, x_max, y_min, y_max, 500, 500, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
    gr3.deletemesh(mesh)
    gr.selntran(1)