Example #1
0
 def draw_axis(self, axis, label):
     if self.minimum_covering_sphere is None:
         self.update_minimum_covering_sphere()
     s = self.minimum_covering_sphere
     scale = max(max(s.box_max()), abs(min(s.box_min())))
     gltbx.fonts.ucs_bitmap_8x13.setup_call_lists()
     gl.glDisable(gl.GL_LIGHTING)
     if self.settings.black_background:
         gl.glColor3f(1.0, 1.0, 1.0)
     else:
         gl.glColor3f(0.0, 0.0, 0.0)
     gl.glLineWidth(1.0)
     gl.glBegin(gl.GL_LINES)
     gl.glVertex3f(0.0, 0.0, 0.0)
     gl.glVertex3f(axis[0] * scale, axis[1] * scale, axis[2] * scale)
     gl.glEnd()
     gl.glRasterPos3f(0.5 + axis[0] * scale, 0.2 + axis[1] * scale,
                      0.2 + axis[2] * scale)
     gltbx.fonts.ucs_bitmap_8x13.render_string(label)
     gl.glEnable(gl.GL_LINE_STIPPLE)
     gl.glLineStipple(4, 0xAAAA)
     gl.glBegin(gl.GL_LINES)
     gl.glVertex3f(0.0, 0.0, 0.0)
     gl.glVertex3f(-axis[0] * scale, -axis[1] * scale, -axis[2] * scale)
     gl.glEnd()
     gl.glDisable(gl.GL_LINE_STIPPLE)
Example #2
0
 def draw_spheres(self, solid=False):
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gray = 0.3
     gl.glColor3f(gray, gray, gray)
     if solid:
         gl.glEnable(gl.GL_LIGHTING)
         gl.glEnable(gl.GL_LIGHT0)
         gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, [1, 1, 1, 1])
         gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, [0, 0, 1, 0])
         gl.glEnable(gl.GL_BLEND)
         gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
         gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, [1, 1, 1, 0.5])
         sphere = gltbx.util.SolidSphere
         grid = 50
     else:
         sphere = gltbx.util.WireSphere
         grid = 20
     for i, (x, r) in enumerate(self.spheres):
         gl.glPushMatrix()
         gl.glTranslated(*(x))
         sphere(radius=r, slices=grid, stacks=grid)
         gl.glPopMatrix()
     if solid:
         gl.glDisable(gl.GL_LIGHTING)
         gl.glDisable(gl.GL_LIGHT0)
         gl.glDisable(gl.GL_BLEND)
Example #3
0
 def draw_cross_at(self, position_tuple, color=(1, 1, 1), f=0.1):
     (x, y, z) = position_tuple
     gl.glBegin(gl.GL_LINES)
     gl.glColor3f(*color)
     gl.glVertex3f(x - f, y, z)
     gl.glVertex3f(x + f, y, z)
     gl.glVertex3f(x, y - f, z)
     gl.glVertex3f(x, y + f, z)
     gl.glVertex3f(x, y, z - f)
     gl.glVertex3f(x, y, z + f)
     gl.glEnd()
Example #4
0
 def draw_lab_axis(self, start, end, label):
     mid = tuple([0.5 * (s + e) for s, e in zip(start, end)])
     gltbx.fonts.ucs_bitmap_8x13.setup_call_lists()
     gl.glDisable(gl.GL_LIGHTING)
     gl.glColor3f(1.0, 1.0, 0.0)
     gl.glLineWidth(1.0)
     gl.glBegin(gl.GL_LINES)
     gl.glVertex3f(*start)
     gl.glVertex3f(*end)
     gl.glEnd()
     gl.glRasterPos3f(*mid)
     gltbx.fonts.ucs_bitmap_8x13.render_string(label)
Example #5
0
 def draw_labels(self, color=(1, 1, 1)):
     if self.labels_display_list is None:
         font = gltbx.fonts.ucs_bitmap_8x13
         font.setup_call_lists()
         self.labels_display_list = gltbx.gl_managed.display_list()
         self.labels_display_list.compile()
         gl.glColor3f(*color)
         for label, point in zip(self.labels, self.points):
             gl.glRasterPos3f(*point)
             font.render_string(label)
         self.labels_display_list.end()
     self.labels_display_list.call()
Example #6
0
 def draw_cell(self, axes, color):
     astar, bstar, cstar = axes[0], axes[1], axes[2]
     gltbx.fonts.ucs_bitmap_8x13.setup_call_lists()
     gl.glDisable(gl.GL_LIGHTING)
     gl.glColor3f(*color)
     gl.glLineWidth(2.0)
     gl.glBegin(gl.GL_LINES)
     gl.glVertex3f(0.0, 0.0, 0.0)
     gl.glVertex3f(*astar.elems)
     gl.glVertex3f(0.0, 0.0, 0.0)
     gl.glVertex3f(*bstar.elems)
     gl.glVertex3f(0.0, 0.0, 0.0)
     gl.glVertex3f(*cstar.elems)
     gl.glEnd()
     gl.glRasterPos3f(*(1.01 * astar).elems)
     gltbx.fonts.ucs_bitmap_8x13.render_string("a*")
     gl.glRasterPos3f(*(1.01 * bstar).elems)
     gltbx.fonts.ucs_bitmap_8x13.render_string("b*")
     gl.glRasterPos3f(*(1.01 * cstar).elems)
     gltbx.fonts.ucs_bitmap_8x13.render_string("c*")
     gl.glEnable(gl.GL_LINE_STIPPLE)
     gl.glLineStipple(4, 0xAAAA)
     farpoint = astar + bstar + cstar
     # a* face
     gl.glBegin(gl.GL_LINE_LOOP)
     gl.glVertex3f(*farpoint.elems)
     gl.glVertex3f(*(farpoint - bstar).elems)
     gl.glVertex3f(*(farpoint - bstar - cstar).elems)
     gl.glVertex3f(*(farpoint - cstar).elems)
     gl.glEnd()
     # b* face
     gl.glBegin(gl.GL_LINE_LOOP)
     gl.glVertex3f(*farpoint.elems)
     gl.glVertex3f(*(farpoint - astar).elems)
     gl.glVertex3f(*(farpoint - astar - cstar).elems)
     gl.glVertex3f(*(farpoint - cstar).elems)
     gl.glEnd()
     # c* face
     gl.glBegin(gl.GL_LINE_LOOP)
     gl.glVertex3f(*farpoint.elems)
     gl.glVertex3f(*(farpoint - bstar).elems)
     gl.glVertex3f(*(farpoint - bstar - astar).elems)
     gl.glVertex3f(*(farpoint - astar).elems)
     gl.glEnd()
     gl.glDisable(gl.GL_LINE_STIPPLE)
Example #7
0
 def draw_lines(self):
     if self.lines_display_list is None:
         self.lines_display_list = gltbx.gl_managed.display_list()
         self.lines_display_list.compile()
         assert self.line_width > 0
         for i_seqs in self.line_i_seqs:
             color = self.line_colors.get(tuple(i_seqs))
             if color is None:
                 color = self.line_colors.get(tuple(reversed(i_seqs)))
                 if color is None:
                     color = (1, 0, 1)
             gl.glColor3f(*color)
             gl.glLineWidth(self.line_width)
             gl.glBegin(gl.GL_LINES)
             gl.glVertex3f(*self.points[i_seqs[0]])
             gl.glVertex3f(*self.points[i_seqs[1]])
             gl.glEnd()
         self.lines_display_list.end()
     self.lines_display_list.call()
Example #8
0
 def draw_minimum_covering_sphere(self):
     if self.minimum_covering_sphere_display_list is None:
         self.minimum_covering_sphere_display_list = gltbx.gl_managed.display_list()
         self.minimum_covering_sphere_display_list.compile()
         s = self.minimum_covering_sphere
         c = s.center()
         r = s.radius()
         gray = 0.3
         gl.glColor3f(gray, gray, gray)
         gl.glBegin(gl.GL_POLYGON)
         for i in range(360):
             a = i * math.pi / 180
             rs = r * math.sin(a)
             rc = r * math.cos(a)
             gl.glVertex3f(c[0], c[1] + rs, c[2] + rc)
         gl.glEnd()
         self.draw_cross_at(c, color=(1, 0, 0))
         self.minimum_covering_sphere_display_list.end()
     self.minimum_covering_sphere_display_list.call()
Example #9
0
 def label_nearest_point(self):
     ann = AnnAdaptorSelfInclude(self.points.as_double(), 3)
     ann.query(self.rotation_center)
     i = ann.nn[0]
     gltbx.fonts.ucs_bitmap_8x13.setup_call_lists()
     gl.glDisable(gl.GL_LIGHTING)
     gl.glColor3f(1.0, 1.0, 1.0)
     gl.glLineWidth(1.0)
     xyz = self.points_data["xyz"][i]
     exp_id = self.points_data["id"][i]
     panel = self.points_data["panel"][i]
     d_spacing = self.points_data["d_spacing"][i]
     label = (f"id: {exp_id}; panel: {panel}\n"
              f"xyz: {xyz[0]:.1f} {xyz[1]:.1f} {xyz[2]:.1f}\n"
              f"res: {d_spacing:.2f} Angstrom")
     if "miller_index" in self.points_data and exp_id != -1:
         hkl = self.points_data["miller_index"][i]
         label += f"\nhkl: {hkl}"
     line_spacing = round(gltbx.fonts.ucs_bitmap_8x13.height())
     for j, string in enumerate(label.splitlines()):
         gl.glRasterPos3f(*self.points[i])
         gl.glBitmap(0, 0, 0.0, 0.0, line_spacing, -j * line_spacing, b" ")
         gltbx.fonts.ucs_bitmap_8x13.render_string(string)