LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | List of all members
lsst.gdb.afw.printers.GdbOptionParser.PrintImageCommand Class Reference
Inheritance diagram for lsst.gdb.afw.printers.GdbOptionParser.PrintImageCommand:

Public Member Functions

def __init__
 
def get
 
def invoke
 

Detailed Description

Print an Image

Definition at line 556 of file printers.py.

Constructor & Destructor Documentation

def lsst.gdb.afw.printers.GdbOptionParser.PrintImageCommand.__init__ (   self)

Definition at line 559 of file printers.py.

560  def __init__ (self):
561  super (PrintImageCommand, self).__init__ ("show image",
562  gdb.COMMAND_DATA,
563  gdb.COMPLETE_SYMBOL)

Member Function Documentation

def lsst.gdb.afw.printers.GdbOptionParser.PrintImageCommand.get (   self,
  var,
  x,
  y 
)

Definition at line 564 of file printers.py.

565  def get(self, var, x, y):
566  if False:
567  return var["operator()(int, int, bool)"](x, y, True)
568  else:
569  dimensions = var["_gilView"]["_dimensions"]
570  if x < 0 or x >= dimensions["x"] or y < 0 or y >= dimensions["y"]:
571  raise gdb.GdbError("Pixel (%d, %d) is out of range 0:%d, 0:%d" %
572  (x, y, dimensions["x"] - 1, dimensions["y"] - 1))
573 
574  pixels = var["_gilView"]["_pixels"]["_p"]
575  step = pixels["_step_fn"]["_step"]/var.type.template_argument(0).sizeof
576 
577  return pixels["m_iterator"][x + y*step]["_v0"]
def lsst.gdb.afw.printers.GdbOptionParser.PrintImageCommand.invoke (   self,
  args,
  fromTty 
)

Definition at line 578 of file printers.py.

579  def invoke (self, args, fromTty):
580  self.dont_repeat()
581 
582  parser = GdbOptionParser("show image" + ("" if argparse else " <image> [<nx> [<ny>]]"))
583  parser.add_option("-a", "--all", action="store_true", help="Display the whole image/mask")
584  parser.add_option("-c", "--center", type="str", nargs=2, default=(None, None,),
585  help="Center the output at (x, y)")
586  parser.add_option("-o", "--origin", type="str", nargs=2, default=(None, None,),
587  help="Print the region starting at (x, y)")
588  parser.add_option("-x", "--xy0", action="store_true", help="Obey the image's (x0, y0)")
589  parser.add_option("-f", "--formatWidth", type="int", default=8, help="Field width for values")
590  parser.add_option("-d", "--dataFmt", default="%.2f", help="Format for values")
591 
592  if argparse:
593  parser.add_option("image", help="Expression giving image to show")
594  parser.add_option("width", help="Width of patch to print", default=1, nargs="?")
595  parser.add_option("height", help="Height of patch to print", default=1, nargs="?")
596 
597  opts = parser.parse_args(args)
598  if opts.help:
599  return
600  else:
601  opts, args = parser.parse_args(args)
602  if opts.help:
603  return
604 
605  if not args:
606  raise gdb.GdbError("Please specify an image")
607 
608  opts.image = args.pop(0)
609 
610  opts.width, opts.height = 1, 1
611  if args:
612  opts.width = int(args.pop(0))
613  if args:
614  opts.height = int(args.pop(0))
615 
616  if args:
617  raise gdb.GdbError("Unrecognised trailing arguments: %s" % " ".join(args))
618 
619  for i in range(2):
620  val = "0"
621  if opts.origin[i] is None:
622  if opts.center[i] is not None:
623  val = opts.center[i]
624  else:
625  val = opts.origin[i]
626  if opts.center[i] is not None:
627  raise gdb.GdbError("You may not specify both --center and --origin")
628 
629  val = gdb.parse_and_eval(val)
630  if i == 0: x0 = val
631  else: y0 = val
632 
633  if opts.all:
634  nx, ny = 0, 0
635  else:
636  nx, ny = opts.width, opts.height
637 
638  var = gdb.parse_and_eval(opts.image)
639 
640  if re.search(r"shared_ptr<", str(var.type)):
641  var = var["px"].dereference()
642 
643  if not re.search(r"(lsst::afw::image::)?(Image|Mask|MaskedImage)", str(var.type.unqualified())):
644  raise gdb.GdbError("Please specify an image, not %s" % var.type)
645 
646  if re.search(r"MaskedImage", str(var.type)) and \
647  not re.search(r"::Image(\s*&)?$", str(var.type)):
648  print "N.b. %s is a MaskedImage; showing image" % (opts.image)
649  var = var["_image"]
650 
651  if re.search(r"shared_ptr<", str(var.type)):
652  var = var["px"].dereference()
653 
654  if var.type.code == gdb.TYPE_CODE_PTR:
655  var = var.dereference() # be nice
656 
657  pixelTypeName = str(var.type.template_argument(0))
658  if opts.dataFmt:
659  dataFmt = opts.dataFmt
660  elif pixelTypeName in ["short", "unsigned short"]:
661  dataFmt = "0x%x"
662  elif pixelTypeName in ["int", "unsigned int"]:
663  dataFmt = "%d"
664  else:
665  dataFmt = "%.2f"
666 
667  if nx == 0:
668  nx = var["_gilView"]["_dimensions"]["x"]
669  if ny == 0:
670  ny = var["_gilView"]["_dimensions"]["y"]
671 
672  if opts.center[0]:
673  x0 -= nx//2
674  y0 -= ny//2
675 
676  if opts.xy0 and not opts.all:
677  arr = var["_origin"]["_vector"]["m_storage"]["m_data"]["array"]
678 
679  x0 -= arr[0]
680  y0 -= arr[1]
681  #
682  # OK, finally time to print
683  #
684  print "%-4s" % "",
685  for x in range(x0, x0 + nx):
686  print "%*d" % (opts.formatWidth, x),
687  print ""
688 
689  for y in reversed(range(y0, y0 + ny)):
690  print "%-4d" % y,
691  for x in range(x0, x0 + nx):
692  print "%*s" % (opts.formatWidth, dataFmt % self.get(var, x, y)),
693  print ""
694 
PrintImageCommand()

The documentation for this class was generated from the following file: