lsst.afw  14.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
virtualDevice.py
Go to the documentation of this file.
1 from __future__ import absolute_import, division, print_function
2 from builtins import object
3 #
4 # LSST Data Management System
5 # Copyright 2008, 2009, 2010, 2015 LSST Corporation.
6 #
7 # This product includes software developed by the
8 # LSST Project (http://www.lsst.org/).
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the LSST License Statement and
21 # the GNU General Public License along with this program. If not,
22 # see <http://www.lsstcorp.org/LegalNotices/>.
23 #
24 
25 ##
26 # \file
27 # \brief A dummy image display
28 
29 
30 class DisplayImpl(object):
31  def __init__(self, display, verbose=False):
32  """! Initialise the display
33  \param display The display object that we're providing the implementation for
34  \param verbose be chatty?
35  """
36  self.display = display
37  self.verbose = verbose
38 
39  def __del__(self):
40  self._close()
41 
42  def _close(self):
43  """!Close the display, cleaning up any allocated resources"""
44  if hasattr(self, "verbose") and self.verbose and hasattr(self, "display"):
45  print("virtual[%s]._close()" % (self.frame))
46 
47  def _buffer(self, enable=True):
48  """!Enable or disable buffering of writes to the display
49  \param enable True or False, as appropriate
50  """
51  if self.verbose:
52  print("virtual[%s]._buffer(%s)" % (self.frame, enable))
53 
54  def _dot(self, symb, c, r, size, ctype, *args, **kwargs):
55  """!Draw symbol a symbol at (c, r)
56  \param symb The desired symbol. See dot() for details
57  \param c (x) column position
58  \param r (y) row position
59  \param size Size of symbol, in pixels
60  \param ctype The desired colour, either e.g. afw.display.RED or a colour name known to X11
61  \param args Extra arguments
62  \param kwargs Extra keyword arguments
63  """
64  if self.verbose:
65  print("virtual[%s]._dot('%s', %.2f, %.2f, size=%g, ctype=%s, %s, %s)" %
66  (self.frame, symb, c, r, size, ctype, args, kwargs))
67 
68  def _drawLines(self, points, ctype):
69  """!Draw line defined by the list points
70  \param points A list of 0-indexed positions [(x, y), (x, y), ...]
71  \param ctype The desired colour, either e.g. afw.display.RED or a colour name known to X11
72  """
73  if self.verbose:
74  print("virtual[%s]._drawLines(%s, ctype=%s)" %
75  (self.frame, points, ctype))
76 
77  def _erase(self):
78  """!Erase all glyphs drawn on display
79  """
80  if self.verbose:
81  print("virtual[%s]._erase()" % (self.frame))
82 
83  def _flush(self):
84  """!Flush any I/O buffers
85  """
86  if self.verbose:
87  print("virtual[%s]._flush()" % self.frame)
88 
89  def _setCallback(self, what, func):
90  if self.verbose > 1:
91  print("setCallback %s -> %s" % (what, func))
92 
93  def _getEvent(self):
94  """Return an event generated by a keypress or mouse click
95  """
96  from .interface import Event
97  ev = Event("q")
98 
99  if self.verbose:
100  print("virtual[%s]._getEvent() -> %s" % (self.frame, ev))
101 
102  return ev
103 
104  def _getMaskTransparency(self):
105  """Return the mask transparency for a display
106  """
107  if self.verbose:
108  print("virtual[%s]._getMaskTransparency()" % self.frame)
109 
110  def _mtv(self, image, wcs=None, mask=None, title=""):
111  """Display an image and maybe a mask overlay on a display
112  \param image afwImage.Image to display
113  \param mask afwImage.Mask to display
114  \param wcs A Wcs to associate with data
115  \param title Name to display with the data
116  """
117  if self.verbose:
118  print("virtual[%s]._mtv(image=%s, mask=%s, wcs=%s, title=\"%s\")" %
119  (self.frame, "Image" if image else None,
120  "Mask" if mask else None, "Wcs" if wcs else None, title))
121 
122  def _setMaskTransparency(self, transparency, maskplane):
123  """Set the transparency of a maskplane
124  \param transparency The desired transparency, in the range [0, 100]
125  \param maskplane The maskplane to set (None: all)
126  """
127  if self.verbose:
128  print("virtual[%s]._setMaskTransparency(%g, maskplane=\"%s\")" %
129  (self.frame, transparency, maskplane))
130 
131  def _scale(self, algorithm, min, max, unit=None, *args, **kwargs):
132  """Set the scaling from DN to displayed pixels
133  \param algorithm Scaling algorithm (e.g. linear)
134  \param min The minimum value of the stretch (or "zscale" or "minmax")
135  \param max The maximum value of the stretch
136  \param unit Units for min and max (e.g. Percent, Absolute, Sigma)
137  \param *args Optional arguments
138  \param **kwargs Optional keyword arguments
139  """
140  if self.verbose:
141  print("virtual[%s]._scale(%s, %s, %s, %s, %s, %s)" % (self.frame, algorithm,
142  min, max, unit, args, kwargs))
143 
144  def _show(self):
145  """Show the requested display
146  """
147  if self.verbose:
148  print("virtual[%s]._show()" % self.frame)
149 
150  def _pan(self, r, c):
151  """Pan to (colc, rowc)
152  \param c Desired column (x) position
153  \param r Desired row (y) position
154  """
155  if self.verbose:
156  print("virtual[%s]._pan(%.2f, %.2f)" % (self.frame, r, c))
157 
158  def _zoom(self, zoomfac):
159  """Set the zoom
160  \param zoomfac Zoom factor to use
161  """
162  if self.verbose:
163  print("virtual[%s]._zoom(%g)" % (self.frame, zoomfac))
def __init__
Initialise the display.
def _close
Close the display, cleaning up any allocated resources.