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
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
lsst::afw::image::Mask< MaskPixelT > Class Template Reference

Represent a 2-dimensional array of bitmask pixels. More...

#include <Mask.h>

Inheritance diagram for lsst::afw::image::Mask< MaskPixelT >:
lsst::afw::image::ImageBase< MaskPixelT > lsst::daf::base::Persistable lsst::daf::base::Citizen

Classes

struct  ImageTypeFactory
 A templated class to return this classes' type (present in Image/Mask/MaskedImage) More...
 

Public Types

typedef boost::shared_ptr< MaskPtr
 
typedef boost::shared_ptr
< const Mask
ConstPtr
 
typedef detail::MaskPlaneDict MaskPlaneDict
 
typedef detail::Mask_tag image_category
 
- Public Types inherited from lsst::afw::image::ImageBase< MaskPixelT >
typedef boost::shared_ptr
< ImageBase< MaskPixelT > > 
Ptr
 A shared_ptr to an ImageBase. More...
 
typedef boost::shared_ptr
< const ImageBase< MaskPixelT > > 
ConstPtr
 A shared_ptr to a const ImageBase. More...
 
typedef detail::basic_tag image_category
 trait class to identify type of image More...
 
typedef MaskPixelT SinglePixel
 A single Pixel of the same type as those in the ImageBase. More...
 
typedef MaskPixelT Pixel
 A pixel in this ImageBase. More...
 
typedef Reference< MaskPixelT >
::type 
PixelReference
 A Reference to a PixelT. More...
 
typedef ConstReference
< MaskPixelT >::type 
PixelConstReference
 A ConstReference to a PixelT. More...
 
typedef _view_t::xy_locator xy_locator
 An xy_locator. More...
 
typedef
_view_t::xy_locator::const_t 
const_xy_locator
 A const_xy_locator. More...
 
typedef _view_t::iterator iterator
 An STL compliant iterator. More...
 
typedef _const_view_t::iterator const_iterator
 An STL compliant const iterator. More...
 
typedef _view_t::reverse_iterator reverse_iterator
 An STL compliant reverse iterator. More...
 
typedef
_const_view_t::reverse_iterator 
const_reverse_iterator
 An STL compliant const reverse iterator. More...
 
typedef _view_t::x_iterator x_iterator
 An iterator for traversing the pixels in a row. More...
 
typedef x_iterator fast_iterator
 
typedef _view_t::x_iterator xy_x_iterator
 An iterator for traversing the pixels in a row, created from an xy_locator. More...
 
typedef _const_view_t::x_iterator const_x_iterator
 A const iterator for traversing the pixels in a row. More...
 
typedef _view_t::y_iterator y_iterator
 An iterator for traversing the pixels in a column. More...
 
typedef _view_t::y_iterator xy_y_iterator
 An iterator for traversing the pixels in a row, created from an xy_locator. More...
 
typedef _const_view_t::y_iterator const_y_iterator
 A const iterator for traversing the pixels in a column. More...
 
typedef ndarray::Array
< MaskPixelT, 2, 1 > 
Array
 A mutable ndarray representation of the image. More...
 
typedef ndarray::Array
< MaskPixelTconst, 2, 1 > 
ConstArray
 An immutable ndarray representation of the image. More...
 
- Public Types inherited from lsst::daf::base::Persistable
typedef boost::shared_ptr
< Persistable
Ptr
 
- Public Types inherited from lsst::daf::base::Citizen
enum  { magicSentinel = 0xdeadbeef }
 
typedef unsigned long memId
 Type of the block's ID. More...
 
typedef memId(* memNewCallback )(const memId cid)
 A function used to register a callback. More...
 
typedef memId(* memCallback )(const Citizen *ptr)
 

Public Member Functions

 Mask (unsigned int width, unsigned int height, MaskPlaneDict const &planeDefs=MaskPlaneDict())
 Construct a Mask initialized to 0x0. More...
 
 Mask (unsigned int width, unsigned int height, MaskPixelT initialValue, MaskPlaneDict const &planeDefs=MaskPlaneDict())
 Construct a Mask initialized to a specified value. More...
 
 Mask (geom::Extent2I const &dimensions=geom::Extent2I(), MaskPlaneDict const &planeDefs=MaskPlaneDict())
 Construct a Mask initialized to 0x0. More...
 
 Mask (geom::Extent2I const &dimensions, MaskPixelT initialValue, MaskPlaneDict const &planeDefs=MaskPlaneDict())
 Construct a Mask initialized to a specified value. More...
 
 Mask (geom::Box2I const &bbox, MaskPlaneDict const &planeDefs=MaskPlaneDict())
 Construct a Mask initialized to 0x0. More...
 
 Mask (geom::Box2I const &bbox, MaskPixelT initialValue, MaskPlaneDict const &planeDefs=MaskPlaneDict())
 Construct a Mask initialized to a specified value. More...
 
 Mask (std::string const &fileName, int hdu=0, boost::shared_ptr< lsst::daf::base::PropertySet > metadata=boost::shared_ptr< lsst::daf::base::PropertySet >(), geom::Box2I const &bbox=geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false)
 Construct a Mask by reading a regular FITS file. More...
 
 Mask (fits::MemFileManager &manager, int hdu=0, boost::shared_ptr< lsst::daf::base::PropertySet > metadata=boost::shared_ptr< lsst::daf::base::PropertySet >(), geom::Box2I const &bbox=geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false)
 Construct a Mask by reading a FITS image in memory. More...
 
 Mask (fits::Fits &fitsfile, boost::shared_ptr< lsst::daf::base::PropertySet > metadata=boost::shared_ptr< lsst::daf::base::PropertySet >(), geom::Box2I const &bbox=geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false)
 Construct a Mask from an already-open FITS object. More...
 
template<typename OtherPixelT >
 Mask (Mask< OtherPixelT > const &rhs, const bool deep)
 
 Mask (const Mask &src, const bool deep=false)
 Construct a Mask from another Mask. More...
 
 Mask (const Mask &src, const geom::Box2I &bbox, ImageOrigin const origin=PARENT, const bool deep=false)
 Construct a Mask from a subregion of another Mask. More...
 
 Mask (ndarray::Array< MaskPixelT, 2, 1 > const &array, bool deep=false, geom::Point2I const &xy0=geom::Point2I())
 
void swap (Mask &rhs)
 
Maskoperator= (MaskPixelT const rhs)
 
Maskoperator= (const Mask &rhs)
 
void operator|= (Mask const &rhs)
 OR a Mask into a Mask. More...
 
void operator|= (MaskPixelT const rhs)
 OR a bitmask into a Mask. More...
 
void operator&= (Mask const &rhs)
 AND a Mask into a Mask. More...
 
void operator&= (MaskPixelT const rhs)
 AND a bitmask into a Mask. More...
 
void operator^= (Mask const &rhs)
 XOR a Mask into a Mask. More...
 
void operator^= (MaskPixelT const rhs)
 XOR a bitmask into a Mask. More...
 
ImageBase< MaskPixelT >
::PixelReference 
operator() (int x, int y)
 get a reference to the specified pixel More...
 
ImageBase< MaskPixelT >
::PixelConstReference 
operator() (int x, int y) const
 get the specified pixel (const version) More...
 
bool operator() (int x, int y, int plane) const
 is the specified mask plane set in the specified pixel? More...
 
ImageBase< MaskPixelT >
::PixelReference 
operator() (int x, int y, CheckIndices const &)
 get a reference to the specified pixel checking array bounds More...
 
ImageBase< MaskPixelT >
::PixelConstReference 
operator() (int x, int y, CheckIndices const &) const
 get the specified pixel with array checking (const version) More...
 
bool operator() (int x, int y, int plane, CheckIndices const &) const
 is the specified mask plane set in the specified pixel, checking array bounds? More...
 
void writeFits (std::string const &fileName, boost::shared_ptr< lsst::daf::base::PropertySet const > metadata=boost::shared_ptr< lsst::daf::base::PropertySet >(), std::string const &mode="w") const
 Write a mask to a regular FITS file. More...
 
void writeFits (fits::MemFileManager &manager, boost::shared_ptr< lsst::daf::base::PropertySet const > metadata=boost::shared_ptr< lsst::daf::base::PropertySet >(), std::string const &mode="w") const
 Write a mask to a FITS RAM file. More...
 
void writeFits (fits::Fits &fitsfile, boost::shared_ptr< lsst::daf::base::PropertySet const > metadata=boost::shared_ptr< lsst::daf::base::PropertySet const >()) const
 Write a mask to an open FITS file object. More...
 
std::string getAsString (int x, int y)
 
void clearAllMaskPlanes ()
 Clear all the pixels. More...
 
void clearMaskPlane (int plane)
 Clear the specified bit in all pixels. More...
 
void setMaskPlaneValues (const int plane, const int x0, const int x1, const int y)
 Set the bit specified by "planeId" for pixels (x0, y) ... (x1, y) More...
 
void removeAndClearMaskPlane (const std::string &name, bool const removeFromDefault=false)
 Clear all pixels of the specified mask and remove the plane from the mask plane dictionary; optionally remove the plane from the default dictionary too. More...
 
MaskPlaneDict const & getMaskPlaneDict () const
 
void printMaskPlanes () const
 print the mask plane dictionary to std::cout More...
 
void conformMaskPlanes (const MaskPlaneDict &masterPlaneDict)
 Adjust this mask to conform to the standard Mask class's mask plane dictionary, adding any new mask planes to the standard. More...
 
- Public Member Functions inherited from lsst::afw::image::ImageBase< MaskPixelT >
 ImageBase (const geom::Extent2I &dimensions=geom::Extent2I())
 
 ImageBase (const geom::Box2I &bbox)
 
 ImageBase (const ImageBase &src, const bool deep=false)
 
 ImageBase (const ImageBase &src, const geom::Box2I &bbox, const ImageOrigin origin=PARENT, const bool deep=false)
 
 ImageBase (const ImageBase< OtherPixelT > &rhs, const bool deep)
 
 ImageBase (Array const &array, bool deep=false, geom::Point2I const &xy0=geom::Point2I())
 
virtual ~ImageBase ()
 
ImageBaseoperator= (const ImageBase &rhs)
 
ImageBaseoperator= (const MaskPixelTrhs)
 
void operator<<= (const ImageBase &rhs)
 
PixelReference operator() (int x, int y)
 
PixelReference operator() (int x, int y, CheckIndices const &)
 
PixelConstReference operator() (int x, int y) const
 
PixelConstReference operator() (int x, int y, CheckIndices const &) const
 
PixelConstReference get0 (int x, int y) const
 
PixelConstReference get0 (int x, int y, CheckIndices const &check) const
 
void set0 (int x, int y, const MaskPixelTv)
 
void set0 (int x, int y, const MaskPixelTv, CheckIndices const &check)
 
int getWidth () const
 Return the number of columns in the image. More...
 
int getHeight () const
 Return the number of rows in the image. More...
 
int getX0 () const
 
int getY0 () const
 
geom::Point2I getXY0 () const
 
std::pair< int, double > positionToIndex (double const pos, lsst::afw::image::xOrY const xy) const
 Convert image position to index (nearest integer and fractional parts) More...
 
double indexToPosition (double ind, lsst::afw::image::xOrY const xy) const
 Convert image index to image position. More...
 
geom::Extent2I getDimensions () const
 Return the image's size; useful for passing to constructors. More...
 
void swap (ImageBase &rhs)
 
Array getArray ()
 
ConstArray getArray () const
 
iterator begin () const
 
fast_iterator begin (bool) const
 
iterator end () const
 
fast_iterator end (bool) const
 
reverse_iterator rbegin () const
 
reverse_iterator rend () const
 
iterator at (int x, int y) const
 
x_iterator row_begin (int y) const
 
x_iterator row_end (int y) const
 Return an x_iterator to the end of the y'th row. More...
 
x_iterator x_at (int x, int y) const
 Return an x_iterator to the point (x, y) in the image. More...
 
y_iterator col_begin (int x) const
 
y_iterator col_end (int x) const
 Return an y_iterator to the end of the y'th row. More...
 
y_iterator y_at (int x, int y) const
 Return an y_iterator to the point (x, y) in the image. More...
 
xy_locator xy_at (int x, int y) const
 
void setXY0 (geom::Point2I const origin)
 
void setXY0 (int const x0, int const y0)
 
geom::Box2I getBBox (ImageOrigin origin=PARENT) const
 
- Public Member Functions inherited from lsst::daf::base::Persistable
 Persistable (void)
 
virtual ~Persistable (void)
 
template<class Archive >
void serialize (Archive &, unsigned int const)
 
- Public Member Functions inherited from lsst::daf::base::Citizen
 Citizen (const std::type_info &)
 
 Citizen (Citizen const &)
 
 ~Citizen ()
 
Citizenoperator= (Citizen const &)
 
std::string repr () const
 Return a string representation of a Citizen. More...
 
void markPersistent (void)
 Mark a Citizen as persistent and not destroyed until process end. More...
 
memId getId () const
 Return the Citizen's ID. More...
 

Static Public Member Functions

static MaskPixelT getPlaneBitMask (const std::vector< std::string > &names)
 Return the bitmask corresponding to a vector of plane names OR'd together. More...
 
static Mask readFits (std::string const &filename, int hdu=0)
 Read a Mask from a regular FITS file. More...
 
static Mask readFits (fits::MemFileManager &manager, int hdu=0)
 Read a Mask from a FITS RAM file. More...
 
static std::string interpret (MaskPixelT value)
 Interpret a mask value as a comma-separated list of mask plane names. More...
 
static MaskPlaneDict parseMaskPlaneMetadata (boost::shared_ptr< lsst::daf::base::PropertySet const >)
 Given a PropertySet that contains the MaskPlane assignments, setup the MaskPlanes. More...
 
static void clearMaskPlaneDict ()
 Reset the maskPlane dictionary. More...
 
static int addMaskPlane (const std::string &name)
 
static void removeMaskPlane (const std::string &name)
 
static int getMaskPlane (const std::string &name)
 Return the mask plane number corresponding to a plane name. More...
 
static MaskPixelT getPlaneBitMask (const std::string &name)
 Return the bitmask corresponding to a plane name. More...
 
static int getNumPlanesMax ()
 
static int getNumPlanesUsed ()
 Reset the maskPlane dictionary. More...
 
static void addMaskPlanesToMetadata (boost::shared_ptr< lsst::daf::base::PropertySet >)
 Given a PropertySet, replace any existing MaskPlane assignments with the current ones. More...
 
- Static Public Member Functions inherited from lsst::afw::image::ImageBase< MaskPixelT >
static SinglePixel PixelCast (SinglePixelT rhs)
 Convert a type to our SinglePixel type. More...
 
- Static Public Member Functions inherited from lsst::daf::base::Citizen
static bool hasBeenCorrupted ()
 Check all allocated blocks for corruption. More...
 
static memId getNextMemId ()
 Return the memId of the next object to be allocated. More...
 
static int init ()
 Called once when the memory system is being initialised. More...
 
static int census (int, memId startingMemId=0)
 How many active Citizens are there? More...
 
static void census (std::ostream &stream, memId startingMemId=0)
 Print a list of all active Citizens to stream, sorted by ID. More...
 
static const std::vector
< const Citizen * > * 
census ()
 Return a (newly allocated) std::vector of active Citizens sorted by ID. More...
 
static memId setNewCallbackId (memId id)
 Call the NewCallback when block is allocated. More...
 
static memId setDeleteCallbackId (memId id)
 Call the current DeleteCallback when block is deleted. More...
 
static memNewCallback setNewCallback (memNewCallback func)
 Set the NewCallback function. More...
 
static memCallback setDeleteCallback (memCallback func)
 Set the DeleteCallback function. More...
 
static memCallback setCorruptionCallback (memCallback func)
 Set the CorruptionCallback function. More...
 

Private Member Functions

void _initializePlanes (MaskPlaneDict const &planeDefs)
 Initialise mask planes; called by constructors. More...
 
void checkMaskDictionaries (Mask const &other)
 

Static Private Member Functions

static boost::shared_ptr
< detail::MaskDict
_maskPlaneDict ()
 
static int _setMaskPlaneDict (MaskPlaneDict const &mpd)
 
static int addMaskPlane (std::string name, int plane)
 set the name of a mask plane, with minimal checking. More...
 
static int getMaskPlaneNoThrow (const std::string &name)
 Return the mask plane number corresponding to a plane name, or -1 if not found. More...
 
static MaskPixelT getBitMaskNoThrow (int plane)
 Return the bitmask corresponding to a plane ID, or 0 if invalid. More...
 
static MaskPixelT getBitMask (int plane)
 Return the bitmask corresponding to plane ID. More...
 

Private Attributes

boost::shared_ptr
< detail::MaskDict
_maskDict
 

Static Private Attributes

static const std::string maskPlanePrefix
 

Additional Inherited Members

- Protected Member Functions inherited from lsst::afw::image::ImageBase< MaskPixelT >
_view_t _getRawView () const
 
bool isContiguous () const
 
- Static Protected Member Functions inherited from lsst::afw::image::ImageBase< MaskPixelT >
static _view_t _allocateView (geom::Extent2I const &dimensions, Manager::Ptr &manager)
 
static _view_t _makeSubView (geom::Extent2I const &dimensions, geom::Extent2I const &offset, const _view_t &view)
 

Detailed Description

template<typename MaskPixelT = lsst::afw::image::MaskPixel>
class lsst::afw::image::Mask< MaskPixelT >

Represent a 2-dimensional array of bitmask pixels.

Some mask planes are always defined (although you can add more with Mask::addMaskPlane):

Examples:
footprintFunctor.cc.

Definition at line 93 of file Mask.h.

Member Typedef Documentation

template<typename MaskPixelT = lsst::afw::image::MaskPixel>
typedef boost::shared_ptr<const Mask> lsst::afw::image::Mask< MaskPixelT >::ConstPtr

Definition at line 96 of file Mask.h.

template<typename MaskPixelT = lsst::afw::image::MaskPixel>
typedef detail::Mask_tag lsst::afw::image::Mask< MaskPixelT >::image_category

Definition at line 99 of file Mask.h.

template<typename MaskPixelT = lsst::afw::image::MaskPixel>
typedef detail::MaskPlaneDict lsst::afw::image::Mask< MaskPixelT >::MaskPlaneDict

Definition at line 97 of file Mask.h.

template<typename MaskPixelT = lsst::afw::image::MaskPixel>
typedef boost::shared_ptr<Mask> lsst::afw::image::Mask< MaskPixelT >::Ptr

Definition at line 95 of file Mask.h.

Constructor & Destructor Documentation

template<typename MaskPixelT >
lsst::afw::image::Mask< MaskPixelT >::Mask ( unsigned int  width,
unsigned int  height,
MaskPlaneDict const &  planeDefs = MaskPlaneDict() 
)
explicit

Construct a Mask initialized to 0x0.

Parameters
widthnumber of columns
heightnumber of rows
planeDefsdesired mask planes

Definition at line 404 of file Mask.cc.

408  :
409  ImageBase<MaskPixelT>(afwGeom::ExtentI(width, height)) {
410  _initializePlanes(planeDefs);
411  *this = 0x0;
412 }
void _initializePlanes(MaskPlaneDict const &planeDefs)
Initialise mask planes; called by constructors.
Definition: Mask.cc:394
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
Extent< int, 2 > ExtentI
Definition: Extent.h:352
template<typename MaskPixelT>
lsst::afw::image::Mask< MaskPixelT >::Mask ( unsigned int  width,
unsigned int  height,
MaskPixelT  initialValue,
MaskPlaneDict const &  planeDefs = MaskPlaneDict() 
)
explicit

Construct a Mask initialized to a specified value.

Parameters
widthnumber of columns
heightnumber of rows
initialValueInitial value
planeDefsdesired mask planes

Definition at line 418 of file Mask.cc.

423  :
424  ImageBase<MaskPixelT>(afwGeom::ExtentI(width, height)) {
425  _initializePlanes(planeDefs);
426  *this = initialValue;
427 }
void _initializePlanes(MaskPlaneDict const &planeDefs)
Initialise mask planes; called by constructors.
Definition: Mask.cc:394
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
Extent< int, 2 > ExtentI
Definition: Extent.h:352
template<typename MaskPixelT>
lsst::afw::image::Mask< MaskPixelT >::Mask ( geom::Extent2I const &  dimensions = geom::Extent2I(),
MaskPlaneDict const &  planeDefs = MaskPlaneDict() 
)
explicit

Construct a Mask initialized to 0x0.

Parameters
dimensionsNumber of columns, rows
planeDefsdesired mask planes

Definition at line 433 of file Mask.cc.

436  :
437  ImageBase<MaskPixelT>(dimensions) {
438  _initializePlanes(planeDefs);
439  *this = 0x0;
440 }
void _initializePlanes(MaskPlaneDict const &planeDefs)
Initialise mask planes; called by constructors.
Definition: Mask.cc:394
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:42
template<typename MaskPixelT>
lsst::afw::image::Mask< MaskPixelT >::Mask ( geom::Extent2I const &  dimensions,
MaskPixelT  initialValue,
MaskPlaneDict const &  planeDefs = MaskPlaneDict() 
)
explicit

Construct a Mask initialized to a specified value.

Parameters
dimensionsNumber of columns, rows
initialValueInitial value
planeDefsdesired mask planes

Definition at line 446 of file Mask.cc.

450  :
451  ImageBase<MaskPixelT>(dimensions) {
452  _initializePlanes(planeDefs);
453  *this = initialValue;
454 }
void _initializePlanes(MaskPlaneDict const &planeDefs)
Initialise mask planes; called by constructors.
Definition: Mask.cc:394
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:42
template<typename MaskPixelT>
lsst::afw::image::Mask< MaskPixelT >::Mask ( geom::Box2I const &  bbox,
MaskPlaneDict const &  planeDefs = MaskPlaneDict() 
)
explicit

Construct a Mask initialized to 0x0.

Parameters
bboxDesired number of columns/rows and origin
planeDefsdesired mask planes

Definition at line 460 of file Mask.cc.

463  :
464  ImageBase<MaskPixelT>(bbox) {
465  _initializePlanes(planeDefs);
466  *this = 0x0;
467 }
void _initializePlanes(MaskPlaneDict const &planeDefs)
Initialise mask planes; called by constructors.
Definition: Mask.cc:394
template<typename MaskPixelT>
lsst::afw::image::Mask< MaskPixelT >::Mask ( geom::Box2I const &  bbox,
MaskPixelT  initialValue,
MaskPlaneDict const &  planeDefs = MaskPlaneDict() 
)
explicit

Construct a Mask initialized to a specified value.

Parameters
bboxDesired number of columns/rows and origin
initialValueInitial value
planeDefsdesired mask planes

Definition at line 473 of file Mask.cc.

477  :
478  ImageBase<MaskPixelT>(bbox) {
479  _initializePlanes(planeDefs);
480  *this = initialValue;
481 }
void _initializePlanes(MaskPlaneDict const &planeDefs)
Initialise mask planes; called by constructors.
Definition: Mask.cc:394
template<typename MaskPixelT = lsst::afw::image::MaskPixel>
lsst::afw::image::Mask< MaskPixelT >::Mask ( std::string const &  fileName,
int  hdu = 0,
boost::shared_ptr< lsst::daf::base::PropertySet metadata = boost::shared_ptr< lsst::daf::base::PropertySet >(),
geom::Box2I const &  bbox = geom::Box2I(),
ImageOrigin  origin = PARENT,
bool  conformMasks = false 
)
explicit

Construct a Mask by reading a regular FITS file.

Parameters
[in]fileNameFile to read.
[in]hduHDU to read, 1-indexed (i.e. 1=Primary HDU). The special value of 0 reads the Primary HDU unless it is empty, in which case it reads the first extension HDU.
[in,out]metadataMetadata read from the header (may be null).
[in]bboxIf non-empty, read only the pixels within the bounding box.
[in]originCoordinate system of the bounding box; if PARENT, the bounding box should take into account the xy0 saved with the image.
[in]conformMasksIf true, make Mask conform to the mask layout in the file.

The meaning of the bitplanes is given in the header. If conformMasks is false (default), the bitvalues will be changed to match those in Mask's plane dictionary. If it's true, the bitvalues will be left alone, but Mask's dictionary will be modified to match the on-disk version.

template<typename MaskPixelT = lsst::afw::image::MaskPixel>
lsst::afw::image::Mask< MaskPixelT >::Mask ( fits::MemFileManager manager,
int  hdu = 0,
boost::shared_ptr< lsst::daf::base::PropertySet metadata = boost::shared_ptr< lsst::daf::base::PropertySet >(),
geom::Box2I const &  bbox = geom::Box2I(),
ImageOrigin  origin = PARENT,
bool  conformMasks = false 
)
explicit

Construct a Mask by reading a FITS image in memory.

Parameters
[in]managerAn object that manages the memory buffer to read.
[in]hduHDU to read, 1-indexed (i.e. 1=Primary HDU). The special value of 0 reads the Primary HDU unless it is empty, in which case it reads the first extension HDU.
[in,out]metadataMetadata read from the header (may be null).
[in]bboxIf non-empty, read only the pixels within the bounding box.
[in]originCoordinate system of the bounding box; if PARENT, the bounding box should take into account the xy0 saved with the image.
[in]conformMasksIf true, make Mask conform to the mask layout in the file.

The meaning of the bitplanes is given in the header. If conformMasks is false (default), the bitvalues will be changed to match those in Mask's plane dictionary. If it's true, the bitvalues will be left alone, but Mask's dictionary will be modified to match the on-disk version.

template<typename MaskPixelT = lsst::afw::image::MaskPixel>
lsst::afw::image::Mask< MaskPixelT >::Mask ( fits::Fits fitsfile,
boost::shared_ptr< lsst::daf::base::PropertySet metadata = boost::shared_ptr< lsst::daf::base::PropertySet >(),
geom::Box2I const &  bbox = geom::Box2I(),
ImageOrigin  origin = PARENT,
bool  conformMasks = false 
)
explicit

Construct a Mask from an already-open FITS object.

Parameters
[in]fitsfileA FITS object to read from, already at the desired HDU.
[in,out]metadataMetadata read from the header (may be null).
[in]bboxIf non-empty, read only the pixels within the bounding box.
[in]originCoordinate system of the bounding box; if PARENT, the bounding box should take into account the xy0 saved with the image.
[in]conformMasksIf true, make Mask conform to the mask layout in the file.

The meaning of the bitplanes is given in the header. If conformMasks is false (default), the bitvalues will be changed to match those in Mask's plane dictionary. If it's true, the bitvalues will be left alone, but Mask's dictionary will be modified to match the on-disk version.

template<typename MaskPixelT = lsst::afw::image::MaskPixel>
template<typename OtherPixelT >
lsst::afw::image::Mask< MaskPixelT >::Mask ( Mask< OtherPixelT > const &  rhs,
const bool  deep 
)
inline

Definition at line 211 of file Mask.h.

211  :
212  image::ImageBase<MaskPixelT>(rhs, deep),
213  _maskDict(rhs._maskDict) {}
boost::shared_ptr< detail::MaskDict > _maskDict
Definition: Mask.h:342
template<typename MaskPixelT>
lsst::afw::image::Mask< MaskPixelT >::Mask ( const Mask< MaskPixelT > &  src,
const bool  deep = false 
)

Construct a Mask from another Mask.

Parameters
srcmask to copy
deepdeep copy? (construct a view with shared pixels if false)

Definition at line 500 of file Mask.cc.

503  :
504  ImageBase<MaskPixelT>(rhs, deep), _maskDict(rhs._maskDict) {
505 }
boost::shared_ptr< detail::MaskDict > _maskDict
Definition: Mask.h:342
template<typename MaskPixelT>
lsst::afw::image::Mask< MaskPixelT >::Mask ( const Mask< MaskPixelT > &  src,
const geom::Box2I bbox,
ImageOrigin const  origin = PARENT,
const bool  deep = false 
)

Construct a Mask from a subregion of another Mask.

Parameters
srcmask to copy
bboxsubregion to copy
origincoordinate system of the bbox
deepdeep copy? (construct a view with shared pixels if false)

Definition at line 487 of file Mask.cc.

492  :
493  ImageBase<MaskPixelT>(rhs, bbox, origin, deep), _maskDict(rhs._maskDict) {
494 }
boost::shared_ptr< detail::MaskDict > _maskDict
Definition: Mask.h:342
template<typename MaskPixelT>
lsst::afw::image::Mask< MaskPixelT >::Mask ( ndarray::Array< MaskPixelT, 2, 1 > const &  array,
bool  deep = false,
geom::Point2I const &  xy0 = geom::Point2I() 
)
explicit

Definition at line 508 of file Mask.cc.

509  :
510  image::ImageBase<MaskPixelT>(array, deep, xy0),
512 }
static boost::shared_ptr< MaskDict > makeMaskDict()
Definition: Mask.cc:289
boost::shared_ptr< detail::MaskDict > _maskDict
Definition: Mask.h:342

Member Function Documentation

template<typename MaskPixelT >
void lsst::afw::image::Mask< MaskPixelT >::_initializePlanes ( MaskPlaneDict const &  planeDefs)
private

Initialise mask planes; called by constructors.

Definition at line 394 of file Mask.cc.

394  {
395  pexLog::Trace("afw.Mask", 5, boost::format("Number of mask planes: %d") % getNumPlanesMax());
396 
398 }
limited backward compatibility to the DC2 run-time trace facilities
Definition: Trace.h:93
static int getNumPlanesMax()
Definition: Mask.h:330
static boost::shared_ptr< MaskDict > makeMaskDict()
Definition: Mask.cc:289
boost::shared_ptr< detail::MaskDict > _maskDict
Definition: Mask.h:342
template<typename MaskPixelT >
boost::shared_ptr< detail::MaskDict > lsst::afw::image::Mask< MaskPixelT >::_maskPlaneDict ( )
staticprivate

Definition at line 1246 of file Mask.cc.

1247 {
1249 }
static boost::shared_ptr< MaskDict > makeMaskDict()
Definition: Mask.cc:289
template<typename MaskPixelT = lsst::afw::image::MaskPixel>
static int lsst::afw::image::Mask< MaskPixelT >::_setMaskPlaneDict ( MaskPlaneDict const &  mpd)
staticprivate
template<typename MaskPixelT >
int lsst::afw::image::Mask< MaskPixelT >::addMaskPlane ( const std::string &  name)
static

Definition at line 700 of file Mask.cc.

701 {
702  int id = getMaskPlaneNoThrow(name); // see if the plane is already available
703 
704  if (id < 0) { // doesn't exist
705  id = _maskPlaneDict()->getUnusedPlane();
706  }
707 
708  // build new entry, adding the plane to all Masks where this is no contradiction
709 
710  if (id >= getNumPlanesMax()) { // Max number of planes is already allocated
711  throw LSST_EXCEPT(pexExcept::RuntimeError,
712  str(boost::format("Max number of planes (%1%) already used") % getNumPlanesMax()));
713  }
714 
715  _state.forEachMaskDict(addPlaneFunctor(name, id));
716 
717  return id;
718 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
static int getMaskPlaneNoThrow(const std::string &name)
Return the mask plane number corresponding to a plane name, or -1 if not found.
Definition: Mask.cc:840
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
static int getNumPlanesMax()
Definition: Mask.h:330
int id
Definition: CR.cc:151
static boost::shared_ptr< detail::MaskDict > _maskPlaneDict()
Definition: Mask.cc:1246
template<typename MaskPixelT >
int lsst::afw::image::Mask< MaskPixelT >::addMaskPlane ( std::string  name,
int  planeId 
)
staticprivate

set the name of a mask plane, with minimal checking.

This is a private function and is mainly used by setMaskPlaneMetadata

Parameters
namenew name of mask plane
planeIdID of mask plane to be (re)named

Definition at line 726 of file Mask.cc.

729  {
730  if (planeId < 0 || planeId >= getNumPlanesMax()) {
731  throw LSST_EXCEPT(pexExcept::RangeError,
732  str(boost::format("mask plane ID must be between 0 and %1%") % (getNumPlanesMax() - 1)));
733  }
734 
735  _maskPlaneDict()->add(name, planeId);
736 
737  return planeId;
738 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
static int getNumPlanesMax()
Definition: Mask.h:330
static boost::shared_ptr< detail::MaskDict > _maskPlaneDict()
Definition: Mask.cc:1246
template<typename MaskPixelT = lsst::afw::image::MaskPixel>
void lsst::afw::image::Mask< MaskPixelT >::addMaskPlanesToMetadata ( boost::shared_ptr< lsst::daf::base::PropertySet )
static

Given a PropertySet, replace any existing MaskPlane assignments with the current ones.

Definition at line 1155 of file Mask.cc.

1155  {
1156  if (!metadata) {
1157  throw LSST_EXCEPT(pexExcept::InvalidParameterError, "Null PTR(PropertySet)");
1158  }
1159 
1160  // First, clear existing MaskPlane metadata
1161  typedef std::vector<std::string> NameList;
1162  NameList paramNames = metadata->paramNames(false);
1163  for (NameList::const_iterator i = paramNames.begin(); i != paramNames.end(); ++i) {
1164  if (i->compare(0, maskPlanePrefix.size(), maskPlanePrefix) == 0) {
1165  metadata->remove(*i);
1166  }
1167  }
1168 
1169  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
1170 
1171  // Add new MaskPlane metadata
1172  for (MaskPlaneDict::const_iterator i = mpd.begin(); i != mpd.end() ; ++i) {
1173  std::string const& planeName = i->first;
1174  int const planeNumber = i->second;
1175 
1176  if (planeName != "") {
1177  metadata->add(maskPlanePrefix + planeName, planeNumber);
1178  }
1179  }
1180 }
detail::MaskPlaneDict MaskPlaneDict
Definition: Mask.h:97
static const std::string maskPlanePrefix
Definition: Mask.h:346
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
static boost::shared_ptr< detail::MaskDict > _maskPlaneDict()
Definition: Mask.cc:1246
template<typename MaskPixelT >
void lsst::afw::image::Mask< MaskPixelT >::checkMaskDictionaries ( Mask< MaskPixelT > const &  other)
private

Definition at line 1053 of file Mask.cc.

1053  {
1054  if (*_maskDict != *other._maskDict) {
1055  throw LSST_EXCEPT(pexExcept::RuntimeError, "Mask dictionaries do not match");
1056  }
1057 }
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
boost::shared_ptr< detail::MaskDict > _maskDict
Definition: Mask.h:342
template<typename MaskPixelT >
void lsst::afw::image::Mask< MaskPixelT >::clearAllMaskPlanes ( )

Clear all the pixels.

Definition at line 889 of file Mask.cc.

889  {
890  *this = 0;
891 }
template<typename MaskPixelT >
void lsst::afw::image::Mask< MaskPixelT >::clearMaskPlane ( int  plane)

Clear the specified bit in all pixels.

Definition at line 897 of file Mask.cc.

897  {
898  *this &= ~getBitMask(planeId);
899 }
static MaskPixelT getBitMask(int plane)
Return the bitmask corresponding to plane ID.
Definition: Mask.cc:803
template<typename MaskPixelT >
void lsst::afw::image::Mask< MaskPixelT >::clearMaskPlaneDict ( )
static

Reset the maskPlane dictionary.

Definition at line 881 of file Mask.cc.

881  {
882  _maskPlaneDict()->clear();
883 }
static boost::shared_ptr< detail::MaskDict > _maskPlaneDict()
Definition: Mask.cc:1246
template<typename MaskPixelT >
void lsst::afw::image::Mask< MaskPixelT >::conformMaskPlanes ( const MaskPlaneDict masterPlaneDict)

Adjust this mask to conform to the standard Mask class's mask plane dictionary, adding any new mask planes to the standard.

Ensures that this mask (presumably from some external source) has the same plane assignments as the Mask class. If a change in plane assignments is needed, the bits within each pixel are permuted as required. The provided currentPlaneDict describes the true state of the bits in this Mask's pixels and overrides its current MaskDict

Any new mask planes found in this mask are added to unused slots in the Mask class's mask plane dictionary.

Parameters
masterPlaneDictmask plane dictionary currently in use for this mask

Definition at line 913 of file Mask.cc.

916 {
917  PTR(detail::MaskDict) currentMD = detail::MaskDict::makeMaskDict(currentPlaneDict);
918 
919  if (*_maskDict == *currentMD) {
921  return; // nothing to do
922  }
923  } else {
924  //
925  // Find out which planes need to be permuted
926  //
927  MaskPixelT keepBitmask = 0; // mask of bits to keep
928  MaskPixelT canonicalMask[sizeof(MaskPixelT)*8]; // bits in lsst::afw::image::Mask that should be
929  MaskPixelT currentMask[sizeof(MaskPixelT)*8]; // mapped to these bits
930  int numReMap = 0;
931 
932  for (MaskPlaneDict::const_iterator i = currentPlaneDict.begin(); i != currentPlaneDict.end() ; i++) {
933  std::string const name = i->first; // name of mask plane
934  int const currentPlaneNumber = i->second; // plane number currently in use
935  int canonicalPlaneNumber = getMaskPlaneNoThrow(name); // plane number in lsst::afw::image::Mask
936 
937  if (canonicalPlaneNumber < 0) { // no such plane; add it
938  canonicalPlaneNumber = addMaskPlane(name);
939  }
940 
941  if (canonicalPlaneNumber == currentPlaneNumber) {
942  keepBitmask |= getBitMask(canonicalPlaneNumber); // bit is unchanged, so preserve it
943  } else {
944  canonicalMask[numReMap] = getBitMask(canonicalPlaneNumber);
945  currentMask[numReMap] = getBitMaskNoThrow(currentPlaneNumber);
946  numReMap++;
947  }
948  }
949 
950  // Now loop over all pixels in Mask
951  if (numReMap > 0) {
952  for (int r = 0; r != this->getHeight(); ++r) { // "this->": Meyers, Effective C++, Item 43
953  for (typename Mask::x_iterator ptr = this->row_begin(r), end = this->row_end(r);
954  ptr != end; ++ptr) {
955  MaskPixelT const pixel = *ptr;
956 
957  MaskPixelT newPixel = pixel & keepBitmask; // value of invariant mask bits
958  for (int i = 0; i < numReMap; i++) {
959  if (pixel & currentMask[i]) newPixel |= canonicalMask[i];
960  }
961 
962  *ptr = newPixel;
963  }
964  }
965  }
966  }
967  // We've made the planes match the current mask dictionary
969 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
static MaskPixelT getBitMaskNoThrow(int plane)
Return the bitmask corresponding to a plane ID, or 0 if invalid.
Definition: Mask.cc:793
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: Image.h:151
#define PTR(...)
Definition: base.h:41
static int getMaskPlaneNoThrow(const std::string &name)
Return the mask plane number corresponding to a plane name, or -1 if not found.
Definition: Mask.cc:840
static MaskPixelT getBitMask(int plane)
Return the bitmask corresponding to plane ID.
Definition: Mask.cc:803
x_iterator row_end(int y) const
Return an x_iterator to the end of the y&#39;th row.
Definition: Image.h:324
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
Definition: saturated.cc:47
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:239
static boost::shared_ptr< MaskDict > makeMaskDict()
Definition: Mask.cc:289
table::PointKey< int > pixel
x_iterator row_begin(int y) const
Definition: Image.h:319
boost::shared_ptr< detail::MaskDict > _maskDict
Definition: Mask.h:342
static int addMaskPlane(const std::string &name)
Definition: Mask.cc:700
template<typename MaskPixelT = lsst::afw::image::MaskPixel>
std::string lsst::afw::image::Mask< MaskPixelT >::getAsString ( int  x,
int  y 
)
inline

Definition at line 311 of file Mask.h.

311 { return interpret((*this)(x, y)); }
int y
static std::string interpret(MaskPixelT value)
Interpret a mask value as a comma-separated list of mask plane names.
Definition: Mask.cc:684
double x
template<typename MaskPixelT >
MaskPixelT lsst::afw::image::Mask< MaskPixelT >::getBitMask ( int  planeId)
staticprivate

Return the bitmask corresponding to plane ID.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorif plane is invalid

Definition at line 803 of file Mask.cc.

803  {
804  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
805 
806  for (MaskPlaneDict::const_iterator i = mpd.begin(); i != mpd.end(); ++i) {
807  if (planeId == i->second) {
808  MaskPixelT const bitmask = getBitMaskNoThrow(planeId);
809  if (bitmask == 0) { // failed
810  break;
811  }
812  return bitmask;
813  }
814  }
815  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
816  str(boost::format("Invalid mask plane ID: %d") % planeId));
817 }
static MaskPixelT getBitMaskNoThrow(int plane)
Return the bitmask corresponding to a plane ID, or 0 if invalid.
Definition: Mask.cc:793
detail::MaskPlaneDict MaskPlaneDict
Definition: Mask.h:97
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
static boost::shared_ptr< detail::MaskDict > _maskPlaneDict()
Definition: Mask.cc:1246
template<typename MaskPixelT >
MaskPixelT lsst::afw::image::Mask< MaskPixelT >::getBitMaskNoThrow ( int  plane)
staticprivate

Return the bitmask corresponding to a plane ID, or 0 if invalid.

Definition at line 793 of file Mask.cc.

793  {
794  return (planeId >= 0 && planeId < getNumPlanesMax()) ? (1 << planeId) : 0;
795 }
static int getNumPlanesMax()
Definition: Mask.h:330
template<typename MaskPixelT >
int lsst::afw::image::Mask< MaskPixelT >::getMaskPlane ( const std::string &  name)
static

Return the mask plane number corresponding to a plane name.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorif plane is invalid

Definition at line 825 of file Mask.cc.

825  {
826  int const plane = getMaskPlaneNoThrow(name);
827 
828  if (plane < 0) {
829  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
830  str(boost::format("Invalid mask plane name: %s") % name));
831  } else {
832  return plane;
833  }
834 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
static int getMaskPlaneNoThrow(const std::string &name)
Return the mask plane number corresponding to a plane name, or -1 if not found.
Definition: Mask.cc:840
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
template<typename MaskPixelT >
detail::MaskPlaneDict const & lsst::afw::image::Mask< MaskPixelT >::getMaskPlaneDict ( ) const

Return the Mask's maskPlaneDict

Definition at line 745 of file Mask.cc.

746 {
747  return _maskDict->getMaskPlaneDict();
748 }
boost::shared_ptr< detail::MaskDict > _maskDict
Definition: Mask.h:342
template<typename MaskPixelT >
int lsst::afw::image::Mask< MaskPixelT >::getMaskPlaneNoThrow ( const std::string &  name)
staticprivate

Return the mask plane number corresponding to a plane name, or -1 if not found.

Definition at line 840 of file Mask.cc.

840  {
841  return _maskPlaneDict()->getMaskPlane(name);
842 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
static boost::shared_ptr< detail::MaskDict > _maskPlaneDict()
Definition: Mask.cc:1246
template<typename MaskPixelT = lsst::afw::image::MaskPixel>
static int lsst::afw::image::Mask< MaskPixelT >::getNumPlanesMax ( )
inlinestatic

Definition at line 330 of file Mask.h.

330 { return 8*sizeof(MaskPixelT); }
template<typename MaskPixelT >
int lsst::afw::image::Mask< MaskPixelT >::getNumPlanesUsed ( )
static

Reset the maskPlane dictionary.

Definition at line 872 of file Mask.cc.

873 {
874  return _maskPlaneDict()->size();
875 }
static boost::shared_ptr< detail::MaskDict > _maskPlaneDict()
Definition: Mask.cc:1246
template<typename MaskPixelT >
MaskPixelT lsst::afw::image::Mask< MaskPixelT >::getPlaneBitMask ( const std::vector< std::string > &  name)
static

Return the bitmask corresponding to a vector of plane names OR'd together.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorif plane is invalid

Definition at line 860 of file Mask.cc.

860  {
861  MaskPixelT mpix = 0x0;
862  for (std::vector<std::string>::const_iterator it = name.begin(); it != name.end(); ++it) {
863  mpix |= getBitMask(getMaskPlane(*it));
864  }
865  return mpix;
866 }
static int getMaskPlane(const std::string &name)
Return the mask plane number corresponding to a plane name.
Definition: Mask.cc:825
static MaskPixelT getBitMask(int plane)
Return the bitmask corresponding to plane ID.
Definition: Mask.cc:803
template<typename MaskPixelT >
MaskPixelT lsst::afw::image::Mask< MaskPixelT >::getPlaneBitMask ( const std::string &  name)
static

Return the bitmask corresponding to a plane name.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorif plane is invalid

Definition at line 850 of file Mask.cc.

850  {
851  return getBitMask(getMaskPlane(name));
852 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
static int getMaskPlane(const std::string &name)
Return the mask plane number corresponding to a plane name.
Definition: Mask.cc:825
static MaskPixelT getBitMask(int plane)
Return the bitmask corresponding to plane ID.
Definition: Mask.cc:803
template<typename MaskPixelT>
std::string lsst::afw::image::Mask< MaskPixelT >::interpret ( MaskPixelT  value)
static

Interpret a mask value as a comma-separated list of mask plane names.

Definition at line 684 of file Mask.cc.

685 {
686  std::string result = "";
687  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
688  for (MaskPlaneDict::const_iterator iter = mpd.begin(); iter != mpd.end(); ++iter) {
689  if (value & getBitMask(iter->second)) {
690  if (result.size() > 0) {
691  result += ",";
692  }
693  result += iter->first;
694  }
695  }
696  return result;
697 }
int iter
detail::MaskPlaneDict MaskPlaneDict
Definition: Mask.h:97
static MaskPixelT getBitMask(int plane)
Return the bitmask corresponding to plane ID.
Definition: Mask.cc:803
static boost::shared_ptr< detail::MaskDict > _maskPlaneDict()
Definition: Mask.cc:1246
template<typename MaskPixelT >
void lsst::afw::image::Mask< MaskPixelT >::operator&= ( Mask< MaskPixelT > const &  rhs)

AND a Mask into a Mask.

Definition at line 1104 of file Mask.cc.

1104  {
1105  checkMaskDictionaries(rhs);
1106 
1107  if (this->getDimensions() != rhs.getDimensions()) {
1108  throw LSST_EXCEPT(pexExcept::LengthError,
1109  str(boost::format("Images are of different size, %dx%d v %dx%d") %
1110  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
1111  }
1112  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(), bl::ret<MaskPixelT>(bl::_1 & bl::_2));
1113 }
geom::Extent2I getDimensions() const
Return the image&#39;s size; useful for passing to constructors.
Definition: Image.h:298
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:239
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
void checkMaskDictionaries(Mask const &other)
Definition: Mask.cc:1053
int getWidth() const
Return the number of columns in the image.
Definition: Image.h:237
template<typename MaskPixelT>
void lsst::afw::image::Mask< MaskPixelT >::operator&= ( MaskPixelT const  rhs)

AND a bitmask into a Mask.

Definition at line 1096 of file Mask.cc.

1096  {
1097  transform_pixels(_getRawView(), _getRawView(), bl::ret<MaskPixelT>(bl::_1 & val));
1098 }
bool val
template<typename MaskPixelT >
ImageBase< MaskPixelT >::PixelReference lsst::afw::image::Mask< MaskPixelT >::operator() ( int  x,
int  y 
)

get a reference to the specified pixel

Parameters
xx index
yy index

Definition at line 977 of file Mask.cc.

980  {
981  return this->ImageBase<MaskPixelT>::operator()(x, y);
982 }
int y
double x
PixelReference operator()(int x, int y)
Return a reference to the pixel (x, y)
Definition: Image.cc:236
template<typename MaskPixelT >
ImageBase< MaskPixelT >::PixelConstReference lsst::afw::image::Mask< MaskPixelT >::operator() ( int  x,
int  y 
) const

get the specified pixel (const version)

Parameters
xx index
yy index

Definition at line 1000 of file Mask.cc.

1003  {
1004  return this->ImageBase<MaskPixelT>::operator()(x, y);
1005 }
int y
double x
PixelReference operator()(int x, int y)
Return a reference to the pixel (x, y)
Definition: Image.cc:236
template<typename MaskPixelT >
bool lsst::afw::image::Mask< MaskPixelT >::operator() ( int  x,
int  y,
int  planeId 
) const

is the specified mask plane set in the specified pixel?

Parameters
xx index
yy index
planeIdplane ID

Definition at line 1023 of file Mask.cc.

1027  {
1028  // !! converts an int to a bool
1029  return !!(this->ImageBase<MaskPixelT>::operator()(x, y) & getBitMask(planeId));
1030 }
int y
static MaskPixelT getBitMask(int plane)
Return the bitmask corresponding to plane ID.
Definition: Mask.cc:803
double x
PixelReference operator()(int x, int y)
Return a reference to the pixel (x, y)
Definition: Image.cc:236
template<typename MaskPixelT >
ImageBase< MaskPixelT >::PixelReference lsst::afw::image::Mask< MaskPixelT >::operator() ( int  x,
int  y,
CheckIndices const &  check 
)

get a reference to the specified pixel checking array bounds

Parameters
xx index
yy index
checkCheck array bounds?

Definition at line 988 of file Mask.cc.

992  {
993  return this->ImageBase<MaskPixelT>::operator()(x, y, check);
994 }
int y
double x
PixelReference operator()(int x, int y)
Return a reference to the pixel (x, y)
Definition: Image.cc:236
template<typename MaskPixelT >
ImageBase< MaskPixelT >::PixelConstReference lsst::afw::image::Mask< MaskPixelT >::operator() ( int  x,
int  y,
CheckIndices const &  check 
) const

get the specified pixel with array checking (const version)

Parameters
xx index
yy index
checkCheck array bounds?

Definition at line 1011 of file Mask.cc.

1015  {
1016  return this->ImageBase<MaskPixelT>::operator()(x, y, check);
1017 }
int y
double x
PixelReference operator()(int x, int y)
Return a reference to the pixel (x, y)
Definition: Image.cc:236
template<typename MaskPixelT >
bool lsst::afw::image::Mask< MaskPixelT >::operator() ( int  x,
int  y,
int  planeId,
CheckIndices const &  check 
) const

is the specified mask plane set in the specified pixel, checking array bounds?

Parameters
xx index
yy index
planeIdplane ID
checkCheck array bounds?

Definition at line 1036 of file Mask.cc.

1041  {
1042  // !! converts an int to a bool
1043  return !!(this->ImageBase<MaskPixelT>::operator()(x, y, check) & getBitMask(planeId));
1044 }
int y
static MaskPixelT getBitMask(int plane)
Return the bitmask corresponding to plane ID.
Definition: Mask.cc:803
double x
PixelReference operator()(int x, int y)
Return a reference to the pixel (x, y)
Definition: Image.cc:236
template<typename MaskPixelT>
Mask< MaskPixelT > & lsst::afw::image::Mask< MaskPixelT >::operator= ( MaskPixelT const  rhs)

Definition at line 538 of file Mask.cc.

538  {
539  fill_pixels(_getRawView(), rhs);
540 
541  return *this;
542 }
template<typename MaskPixelT>
Mask< MaskPixelT > & lsst::afw::image::Mask< MaskPixelT >::operator= ( const Mask< MaskPixelT > &  rhs)

Definition at line 530 of file Mask.cc.

530  {
531  Mask tmp(rhs);
532  swap(tmp); // See Meyers, Effective C++, Item 11
533 
534  return *this;
535 }
Mask(unsigned int width, unsigned int height, MaskPlaneDict const &planeDefs=MaskPlaneDict())
Construct a Mask initialized to 0x0.
Definition: Mask.cc:404
void swap(Mask &rhs)
Definition: Mask.cc:517
template<typename MaskPixelT >
void lsst::afw::image::Mask< MaskPixelT >::operator^= ( Mask< MaskPixelT > const &  rhs)

XOR a Mask into a Mask.

Definition at line 1127 of file Mask.cc.

1127  {
1128  checkMaskDictionaries(rhs);
1129 
1130  if (this->getDimensions() != rhs.getDimensions()) {
1131  throw LSST_EXCEPT(pexExcept::LengthError,
1132  str(boost::format("Images are of different size, %dx%d v %dx%d") %
1133  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
1134  }
1135  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(), bl::ret<MaskPixelT>(bl::_1 ^ bl::_2));
1136 }
geom::Extent2I getDimensions() const
Return the image&#39;s size; useful for passing to constructors.
Definition: Image.h:298
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:239
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
void checkMaskDictionaries(Mask const &other)
Definition: Mask.cc:1053
int getWidth() const
Return the number of columns in the image.
Definition: Image.h:237
template<typename MaskPixelT>
void lsst::afw::image::Mask< MaskPixelT >::operator^= ( MaskPixelT const  rhs)

XOR a bitmask into a Mask.

Definition at line 1119 of file Mask.cc.

1119  {
1120  transform_pixels(_getRawView(), _getRawView(), bl::ret<MaskPixelT>(bl::_1 ^ val));
1121 }
bool val
template<typename MaskPixelT >
void lsst::afw::image::Mask< MaskPixelT >::operator|= ( Mask< MaskPixelT > const &  rhs)

OR a Mask into a Mask.

Definition at line 1081 of file Mask.cc.

1081  {
1082  checkMaskDictionaries(rhs);
1083 
1084  if (this->getDimensions() != rhs.getDimensions()) {
1085  throw LSST_EXCEPT(pexExcept::LengthError,
1086  str(boost::format("Images are of different size, %dx%d v %dx%d") %
1087  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
1088  }
1089  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(), bl::ret<MaskPixelT>(bl::_1 | bl::_2));
1090 }
geom::Extent2I getDimensions() const
Return the image&#39;s size; useful for passing to constructors.
Definition: Image.h:298
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:239
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
void checkMaskDictionaries(Mask const &other)
Definition: Mask.cc:1053
int getWidth() const
Return the number of columns in the image.
Definition: Image.h:237
template<typename MaskPixelT>
void lsst::afw::image::Mask< MaskPixelT >::operator|= ( MaskPixelT const  rhs)

OR a bitmask into a Mask.

Definition at line 1073 of file Mask.cc.

1073  {
1074  transform_pixels(_getRawView(), _getRawView(), bl::ret<MaskPixelT>(bl::_1 | val));
1075 }
bool val
template<typename MaskPixelT = lsst::afw::image::MaskPixel>
Mask< MaskPixelT >::MaskPlaneDict lsst::afw::image::Mask< MaskPixelT >::parseMaskPlaneMetadata ( boost::shared_ptr< lsst::daf::base::PropertySet const >  )
static

Given a PropertySet that contains the MaskPlane assignments, setup the MaskPlanes.

Returns
a dictionary of mask plane name: plane ID

Definition at line 1188 of file Mask.cc.

1190  {
1191  MaskPlaneDict newDict;
1192 
1193  // First, clear existing MaskPlane metadata
1194  typedef std::vector<std::string> NameList;
1195  NameList paramNames = metadata->paramNames(false);
1196  int numPlanesUsed = 0; // number of planes used
1197 
1198  // Iterate over childless properties with names starting with maskPlanePrefix
1199  for (NameList::const_iterator i = paramNames.begin(); i != paramNames.end(); ++i) {
1200  if (i->compare(0, maskPlanePrefix.size(), maskPlanePrefix) == 0) {
1201  // split off maskPlanePrefix to obtain plane name
1202  std::string planeName = i->substr(maskPlanePrefix.size());
1203  int const planeId = metadata->getAsInt(*i);
1204 
1205  MaskPlaneDict::const_iterator plane = newDict.find(planeName);
1206  if (plane != newDict.end() && planeId != plane->second) {
1207  throw LSST_EXCEPT(pexExcept::RuntimeError,
1208  "File specifies plane " + planeName + " twice");
1209  }
1210  for (MaskPlaneDict::const_iterator j = newDict.begin(); j != newDict.end(); ++j) {
1211  if (planeId == j->second) {
1212  throw LSST_EXCEPT(pexExcept::RuntimeError,
1213  str(boost::format("File specifies plane %s has same value (%d) as %s") %
1214  planeName % planeId % j->first));
1215  }
1216  }
1217  // build new entry
1218  if (numPlanesUsed >= getNumPlanesMax()) {
1219  // Max number of planes already allocated
1220  throw LSST_EXCEPT(pexExcept::RuntimeError,
1221  str(boost::format("Max number of planes (%1%) already used") %
1222  getNumPlanesMax()));
1223  }
1224  newDict[planeName] = planeId;
1225  }
1226  }
1227  return newDict;
1228 }
detail::MaskPlaneDict MaskPlaneDict
Definition: Mask.h:97
static const std::string maskPlanePrefix
Definition: Mask.h:346
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
static int getNumPlanesMax()
Definition: Mask.h:330
template<typename MaskPixelT >
void lsst::afw::image::Mask< MaskPixelT >::printMaskPlanes ( ) const

print the mask plane dictionary to std::cout

Definition at line 1234 of file Mask.cc.

1235 {
1236  _maskDict->print();
1237 }
boost::shared_ptr< detail::MaskDict > _maskDict
Definition: Mask.h:342
template<typename MaskPixelT = lsst::afw::image::MaskPixel>
static Mask lsst::afw::image::Mask< MaskPixelT >::readFits ( std::string const &  filename,
int  hdu = 0 
)
inlinestatic

Read a Mask from a regular FITS file.

Parameters
[in]filenameName of the file to read.
[in]hduNumber of the "header-data unit" to read (where 1 is the Primary HDU). The default value of 0 is interpreted as "the first HDU with NAXIS != 0".

Definition at line 294 of file Mask.h.

294  {
295  return Mask<MaskPixelT>(filename, hdu);
296  }
template<typename MaskPixelT = lsst::afw::image::MaskPixel>
static Mask lsst::afw::image::Mask< MaskPixelT >::readFits ( fits::MemFileManager manager,
int  hdu = 0 
)
inlinestatic

Read a Mask from a FITS RAM file.

Parameters
[in]managerObject that manages the memory to be read.
[in]hduNumber of the "header-data unit" to read (where 1 is the Primary HDU). The default value of 0 is interpreted as "the first HDU with NAXIS != 0".

Definition at line 305 of file Mask.h.

305  {
306  return Mask<MaskPixelT>(manager, hdu);
307  }
template<typename MaskPixelT >
void lsst::afw::image::Mask< MaskPixelT >::removeAndClearMaskPlane ( const std::string &  name,
bool const  removeFromDefault = false 
)

Clear all pixels of the specified mask and remove the plane from the mask plane dictionary; optionally remove the plane from the default dictionary too.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorif plane is invalid
Parameters
namename of maskplane
removeFromDefaultremove from default mask plane dictionary too

Definition at line 769 of file Mask.cc.

773 {
774  clearMaskPlane(getMaskPlane(name)); // clear this bits in this Mask
775 
776  if (_maskDict == detail::MaskDict::makeMaskDict() && removeFromDefault) { // we are the default
777  ;
778  } else {
779  _maskDict = _maskDict->clone();
780  }
781 
782  _maskDict->erase(name);
783 
784  if (removeFromDefault && detail::MaskDict::makeMaskDict()->getMaskPlane(name) >= 0) {
786  }
787 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
static int getMaskPlane(const std::string &name)
Return the mask plane number corresponding to a plane name.
Definition: Mask.cc:825
static void removeMaskPlane(const std::string &name)
Definition: Mask.cc:751
static boost::shared_ptr< MaskDict > makeMaskDict()
Definition: Mask.cc:289
boost::shared_ptr< detail::MaskDict > _maskDict
Definition: Mask.h:342
void clearMaskPlane(int plane)
Clear the specified bit in all pixels.
Definition: Mask.cc:897
template<typename MaskPixelT >
void lsst::afw::image::Mask< MaskPixelT >::removeMaskPlane ( const std::string &  name)
static

Definition at line 751 of file Mask.cc.

752 {
754  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
755  str(boost::format("Plane %s doesn't exist in the default Mask") % name));
756  }
757 
758  detail::MaskDict::incrDefaultVersion(); // leave current Masks alone
759  _maskPlaneDict()->erase(name);
760 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
static int getMaskPlane(const std::string &name)
Return the mask plane number corresponding to a plane name.
Definition: Mask.cc:825
static boost::shared_ptr< MaskDict > incrDefaultVersion()
Definition: Mask.cc:326
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
static boost::shared_ptr< MaskDict > makeMaskDict()
Definition: Mask.cc:289
static boost::shared_ptr< detail::MaskDict > _maskPlaneDict()
Definition: Mask.cc:1246
template<typename MaskPixelT >
void lsst::afw::image::Mask< MaskPixelT >::setMaskPlaneValues ( const int  plane,
const int  x0,
const int  x1,
const int  y 
)

Set the bit specified by "planeId" for pixels (x0, y) ... (x1, y)

Definition at line 1142 of file Mask.cc.

1143  {
1144  MaskPixelT const bitMask = getBitMask(planeId);
1145 
1146  for (int x = x0; x <= x1; x++) {
1147  operator()(x, y) = operator()(x, y) | bitMask;
1148  }
1149 }
int y
int const x0
Definition: saturated.cc:45
ImageBase< MaskPixelT >::PixelReference operator()(int x, int y)
get a reference to the specified pixel
Definition: Mask.cc:977
static MaskPixelT getBitMask(int plane)
Return the bitmask corresponding to plane ID.
Definition: Mask.cc:803
double x
template<typename PixelT >
void lsst::afw::image::Mask< PixelT >::swap ( Mask< MaskPixelT > &  rhs)

Definition at line 517 of file Mask.cc.

517  {
518  using std::swap; // See Meyers, Effective C++, Item 25
519 
521  swap(_maskDict, rhs._maskDict);
522 }
void swap(ImageBase< PixelT > &a, ImageBase< PixelT > &b)
Definition: Image.cc:291
void swap(ImageBase &rhs)
Definition: Image.cc:282
void swap(Mask &rhs)
Definition: Mask.cc:517
boost::shared_ptr< detail::MaskDict > _maskDict
Definition: Mask.h:342
template<typename MaskPixelT = lsst::afw::image::MaskPixel>
void lsst::afw::image::Mask< MaskPixelT >::writeFits ( std::string const &  fileName,
boost::shared_ptr< lsst::daf::base::PropertySet const >  metadata = boost::shared_ptr< lsst::daf::base::PropertySet >(),
std::string const &  mode = "w" 
) const

Write a mask to a regular FITS file.

Parameters
[in]fileNameName of the file to write.
[in]metadataAdditional values to write to the header (may be null).
[in]mode"w"=Create a new file; "a"=Append a new HDU.
template<typename MaskPixelT = lsst::afw::image::MaskPixel>
void lsst::afw::image::Mask< MaskPixelT >::writeFits ( fits::MemFileManager manager,
boost::shared_ptr< lsst::daf::base::PropertySet const >  metadata = boost::shared_ptr< lsst::daf::base::PropertySet >(),
std::string const &  mode = "w" 
) const

Write a mask to a FITS RAM file.

Parameters
[in]managerManager object for the memory block to write to.
[in]metadataAdditional values to write to the header (may be null).
[in]mode"w"=Create a new file; "a"=Append a new HDU.
template<typename MaskPixelT = lsst::afw::image::MaskPixel>
void lsst::afw::image::Mask< MaskPixelT >::writeFits ( fits::Fits fitsfile,
boost::shared_ptr< lsst::daf::base::PropertySet const >  metadata = boost::shared_ptr< lsst::daf::base::PropertySet const  >() 
) const

Write a mask to an open FITS file object.

Parameters
[in]fitsfileA FITS file already open to the desired HDU.
[in]metadataAdditional values to write to the header (may be null).

Member Data Documentation

template<typename MaskPixelT = lsst::afw::image::MaskPixel>
boost::shared_ptr< detail::MaskDict > lsst::afw::image::Mask< MaskPixelT >::_maskDict
private

Definition at line 342 of file Mask.h.

template<typename MaskPixelT = lsst::afw::image::MaskPixel>
std::string const lsst::afw::image::Mask< MaskPixelT >::maskPlanePrefix
staticprivate

Definition at line 346 of file Mask.h.


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