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