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
Functions | Variables
lsst.afw.cameraGeom.rotateBBoxBy90 Namespace Reference

Functions

def rotateBBoxBy90
 Rotate a bounding box by an integer multiple of 90 degrees. More...
 

Variables

list __all__ = ["rotateBBoxBy90"]
 

Function Documentation

def lsst.afw.cameraGeom.rotateBBoxBy90.rotateBBoxBy90 (   bbox,
  n90,
  dimensions 
)

Rotate a bounding box by an integer multiple of 90 degrees.

Todo:
document dimensions better; what does it specify?
Parameters
bboxbbox to rotate
n90number of quarter rotations to perform
dimensionsdimensions of the parent grid
Returns
rotated bounding box

Definition at line 28 of file rotateBBoxBy90.py.

28 
29 def rotateBBoxBy90(bbox, n90, dimensions):
30  """!Rotate a bounding box by an integer multiple of 90 degrees
31 
32  @todo document dimensions better; what does it specify?
33 
34  @param bbox bbox to rotate
35  @param n90 number of quarter rotations to perform
36  @param dimensions dimensions of the parent grid
37  @return rotated bounding box
38  """
39  while n90 < 0:
40  n90 += 4
41  n90 %= 4
42 
43  # sin/cos of the rotation angle
44  s = 0
45  c = 0
46  if n90 == 0:
47  s = 0
48  c = 1
49  elif n90 == 1:
50  s = 1
51  c = 0
52  elif n90 == 2:
53  s = 0
54  c = -1
55  elif n90 == 3:
56  s = -1
57  c = 0
58  else:
59  raise ValueError("n90 must be an integer")
60 
61  centerPixel = afwGeom.Point2I(int(dimensions[0]/2), int(dimensions[1]/2))
62 
63  xCorner = numpy.array([(corner.getX() - centerPixel[0]) for corner in bbox.getCorners()])
64  yCorner = numpy.array([(corner.getY() - centerPixel[1]) for corner in bbox.getCorners()])
65  x0 = int((c*xCorner - s*yCorner).min())
66  y0 = int((s*xCorner + c*yCorner).min())
67  x1 = int((c*xCorner - s*yCorner).max())
68  y1 = int((s*xCorner + c*yCorner).max())
69 
70  # Fiddle things a little if the detector has an even number of pixels so that square BBoxes
71  # will map into themselves
72 
73  if n90 == 1 :
74  if dimensions[0]%2 == 0:
75  x0 -= 1
76  x1 -= 1
77  elif n90 == 2:
78  if dimensions[0]%2 == 0:
79  x0 -= 1
80  x1 -= 1
81  if dimensions[1]%2 == 0:
82  y0 -= 1
83  y1 -= 1
84  elif n90 == 3:
85  if dimensions[1]%2 == 0:
86  y0 -= 1
87  y1 -= 1
88 
89  LLC = afwGeom.Point2I(centerPixel[0] + x0, centerPixel[1] + y0)
90  URC = afwGeom.Point2I(centerPixel[0] + x1, centerPixel[1] + y1)
91 
92  newBbox = afwGeom.Box2I(LLC, URC)
93 
94  dxy0 = centerPixel[0] - centerPixel[1]
95  if n90%2 == 1 and not dxy0 == 0:
96  newBbox.shift(afwGeom.Extent2I(-dxy0, dxy0))
97 
98  return newBbox
An integer coordinate rectangle.
Definition: Box.h:53
def rotateBBoxBy90
Rotate a bounding box by an integer multiple of 90 degrees.

Variable Documentation

list lsst.afw.cameraGeom.rotateBBoxBy90.__all__ = ["rotateBBoxBy90"]

Definition at line 26 of file rotateBBoxBy90.py.