LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
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 403 of file Mask.cc.

407  :
408  ImageBase<MaskPixelT>(afwGeom::ExtentI(width, height)) {
409  _initializePlanes(planeDefs);
410  *this = 0x0;
411 }
void _initializePlanes(MaskPlaneDict const &planeDefs)
Initialise mask planes; called by constructors.
Definition: Mask.cc:393
Extent< int, 2 > ExtentI
Definition: Extent.h:347
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 417 of file Mask.cc.

422  :
423  ImageBase<MaskPixelT>(afwGeom::ExtentI(width, height)) {
424  _initializePlanes(planeDefs);
425  *this = initialValue;
426 }
void _initializePlanes(MaskPlaneDict const &planeDefs)
Initialise mask planes; called by constructors.
Definition: Mask.cc:393
Extent< int, 2 > ExtentI
Definition: Extent.h:347
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 432 of file Mask.cc.

435  :
436  ImageBase<MaskPixelT>(dimensions) {
437  _initializePlanes(planeDefs);
438  *this = 0x0;
439 }
void _initializePlanes(MaskPlaneDict const &planeDefs)
Initialise mask planes; called by constructors.
Definition: Mask.cc:393
afw::table::Key< afw::table::Point< int > > dimensions
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 445 of file Mask.cc.

449  :
450  ImageBase<MaskPixelT>(dimensions) {
451  _initializePlanes(planeDefs);
452  *this = initialValue;
453 }
void _initializePlanes(MaskPlaneDict const &planeDefs)
Initialise mask planes; called by constructors.
Definition: Mask.cc:393
afw::table::Key< afw::table::Point< int > > dimensions
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 459 of file Mask.cc.

462  :
463  ImageBase<MaskPixelT>(bbox) {
464  _initializePlanes(planeDefs);
465  *this = 0x0;
466 }
void _initializePlanes(MaskPlaneDict const &planeDefs)
Initialise mask planes; called by constructors.
Definition: Mask.cc:393
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 472 of file Mask.cc.

476  :
477  ImageBase<MaskPixelT>(bbox) {
478  _initializePlanes(planeDefs);
479  *this = initialValue;
480 }
void _initializePlanes(MaskPlaneDict const &planeDefs)
Initialise mask planes; called by constructors.
Definition: Mask.cc:393
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 499 of file Mask.cc.

502  :
503  ImageBase<MaskPixelT>(rhs, deep), _maskDict(rhs._maskDict) {
504 }
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 486 of file Mask.cc.

491  :
492  ImageBase<MaskPixelT>(rhs, bbox, origin, deep), _maskDict(rhs._maskDict) {
493 }
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 507 of file Mask.cc.

508  :
509  image::ImageBase<MaskPixelT>(array, deep, xy0),
511 }
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 393 of file Mask.cc.

393  {
394  pexLog::Trace("afw.Mask", 5, boost::format("Number of mask planes: %d") % getNumPlanesMax());
395 
397 }
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 1245 of file Mask.cc.

1246 {
1248 }
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 699 of file Mask.cc.

700 {
701  int id = getMaskPlaneNoThrow(name); // see if the plane is already available
702 
703  if (id < 0) { // doesn't exist
704  id = _maskPlaneDict()->getUnusedPlane();
705  }
706 
707  // build new entry, adding the plane to all Masks where this is no contradiction
708 
709  if (id >= getNumPlanesMax()) { // Max number of planes is already allocated
710  throw LSST_EXCEPT(pexExcept::RuntimeError,
711  str(boost::format("Max number of planes (%1%) already used") % getNumPlanesMax()));
712  }
713 
714  _state.forEachMaskDict(addPlaneFunctor(name, id));
715 
716  return id;
717 }
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:839
#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:1245
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 725 of file Mask.cc.

728  {
729  if (planeId < 0 || planeId >= getNumPlanesMax()) {
730  throw LSST_EXCEPT(pexExcept::RangeError,
731  str(boost::format("mask plane ID must be between 0 and %1%") % (getNumPlanesMax() - 1)));
732  }
733 
734  _maskPlaneDict()->add(name, planeId);
735 
736  return planeId;
737 }
#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:1245
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 1154 of file Mask.cc.

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

Definition at line 1052 of file Mask.cc.

1052  {
1053  if (*_maskDict != *other._maskDict) {
1054  throw LSST_EXCEPT(pexExcept::RuntimeError, "Mask dictionaries do not match");
1055  }
1056 }
#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 888 of file Mask.cc.

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

Clear the specified bit in all pixels.

Definition at line 896 of file Mask.cc.

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

Reset the maskPlane dictionary.

Definition at line 880 of file Mask.cc.

880  {
881  _maskPlaneDict()->clear();
882 }
static boost::shared_ptr< detail::MaskDict > _maskPlaneDict()
Definition: Mask.cc:1245
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 912 of file Mask.cc.

915 {
916  PTR(detail::MaskDict) currentMD = detail::MaskDict::makeMaskDict(currentPlaneDict);
917 
918  if (*_maskDict == *currentMD) {
920  return; // nothing to do
921  }
922  } else {
923  //
924  // Find out which planes need to be permuted
925  //
926  MaskPixelT keepBitmask = 0; // mask of bits to keep
927  MaskPixelT canonicalMask[sizeof(MaskPixelT)*8]; // bits in lsst::afw::image::Mask that should be
928  MaskPixelT currentMask[sizeof(MaskPixelT)*8]; // mapped to these bits
929  int numReMap = 0;
930 
931  for (MaskPlaneDict::const_iterator i = currentPlaneDict.begin(); i != currentPlaneDict.end() ; i++) {
932  std::string const name = i->first; // name of mask plane
933  int const currentPlaneNumber = i->second; // plane number currently in use
934  int canonicalPlaneNumber = getMaskPlaneNoThrow(name); // plane number in lsst::afw::image::Mask
935 
936  if (canonicalPlaneNumber < 0) { // no such plane; add it
937  canonicalPlaneNumber = addMaskPlane(name);
938  }
939 
940  if (canonicalPlaneNumber == currentPlaneNumber) {
941  keepBitmask |= getBitMask(canonicalPlaneNumber); // bit is unchanged, so preserve it
942  } else {
943  canonicalMask[numReMap] = getBitMask(canonicalPlaneNumber);
944  currentMask[numReMap] = getBitMaskNoThrow(currentPlaneNumber);
945  numReMap++;
946  }
947  }
948 
949  // Now loop over all pixels in Mask
950  if (numReMap > 0) {
951  for (int r = 0; r != this->getHeight(); ++r) { // "this->": Meyers, Effective C++, Item 43
952  for (typename Mask::x_iterator ptr = this->row_begin(r), end = this->row_end(r);
953  ptr != end; ++ptr) {
954  MaskPixelT const pixel = *ptr;
955 
956  MaskPixelT newPixel = pixel & keepBitmask; // value of invariant mask bits
957  for (int i = 0; i < numReMap; i++) {
958  if (pixel & currentMask[i]) newPixel |= canonicalMask[i];
959  }
960 
961  *ptr = newPixel;
962  }
963  }
964  }
965  }
966  // We've made the planes match the current mask dictionary
968 }
#define PTR(...)
Definition: base.h:41
static MaskPixelT getBitMaskNoThrow(int plane)
Return the bitmask corresponding to a plane ID, or 0 if invalid.
Definition: Mask.cc:792
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: Image.h:151
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:839
table::Key< table::Point< int > > pixel
static MaskPixelT getBitMask(int plane)
Return the bitmask corresponding to plane ID.
Definition: Mask.cc:802
x_iterator row_end(int y) const
Return an x_iterator to the end of the y&#39;th row.
Definition: Image.h:324
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
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:699
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)); }
static std::string interpret(MaskPixelT value)
Interpret a mask value as a comma-separated list of mask plane names.
Definition: Mask.cc:683
int y
int 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 802 of file Mask.cc.

802  {
803  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
804 
805  for (MaskPlaneDict::const_iterator i = mpd.begin(); i != mpd.end(); ++i) {
806  if (planeId == i->second) {
807  MaskPixelT const bitmask = getBitMaskNoThrow(planeId);
808  if (bitmask == 0) { // failed
809  break;
810  }
811  return bitmask;
812  }
813  }
814  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
815  str(boost::format("Invalid mask plane ID: %d") % planeId));
816 }
static MaskPixelT getBitMaskNoThrow(int plane)
Return the bitmask corresponding to a plane ID, or 0 if invalid.
Definition: Mask.cc:792
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:1245
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 792 of file Mask.cc.

792  {
793  return (planeId >= 0 && planeId < getNumPlanesMax()) ? (1 << planeId) : 0;
794 }
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 824 of file Mask.cc.

824  {
825  int const plane = getMaskPlaneNoThrow(name);
826 
827  if (plane < 0) {
828  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
829  str(boost::format("Invalid mask plane name: %s") % name));
830  } else {
831  return plane;
832  }
833 }
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:839
#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 744 of file Mask.cc.

745 {
746  return _maskDict->getMaskPlaneDict();
747 }
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 839 of file Mask.cc.

839  {
840  return _maskPlaneDict()->getMaskPlane(name);
841 }
static boost::shared_ptr< detail::MaskDict > _maskPlaneDict()
Definition: Mask.cc:1245
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 871 of file Mask.cc.

872 {
873  return _maskPlaneDict()->size();
874 }
static boost::shared_ptr< detail::MaskDict > _maskPlaneDict()
Definition: Mask.cc:1245
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 859 of file Mask.cc.

859  {
860  MaskPixelT mpix = 0x0;
861  for (std::vector<std::string>::const_iterator it = name.begin(); it != name.end(); ++it) {
862  mpix |= getBitMask(getMaskPlane(*it));
863  }
864  return mpix;
865 }
static int getMaskPlane(const std::string &name)
Return the mask plane number corresponding to a plane name.
Definition: Mask.cc:824
static MaskPixelT getBitMask(int plane)
Return the bitmask corresponding to plane ID.
Definition: Mask.cc:802
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 849 of file Mask.cc.

849  {
850  return getBitMask(getMaskPlane(name));
851 }
static int getMaskPlane(const std::string &name)
Return the mask plane number corresponding to a plane name.
Definition: Mask.cc:824
static MaskPixelT getBitMask(int plane)
Return the bitmask corresponding to plane ID.
Definition: Mask.cc:802
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 683 of file Mask.cc.

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

AND a Mask into a Mask.

Definition at line 1103 of file Mask.cc.

1103  {
1104  checkMaskDictionaries(rhs);
1105 
1106  if (this->getDimensions() != rhs.getDimensions()) {
1107  throw LSST_EXCEPT(pexExcept::LengthError,
1108  str(boost::format("Images are of different size, %dx%d v %dx%d") %
1109  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
1110  }
1111  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(), bl::ret<MaskPixelT>(bl::_1 & bl::_2));
1112 }
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:1052
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 1095 of file Mask.cc.

1095  {
1096  transform_pixels(_getRawView(), _getRawView(), bl::ret<MaskPixelT>(bl::_1 & val));
1097 }
ImageT val
Definition: CR.cc:154
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 976 of file Mask.cc.

979  {
980  return this->ImageBase<MaskPixelT>::operator()(x, y);
981 }
int y
int x
PixelReference operator()(int x, int y)
Return a reference to the pixel (x, y)
Definition: Image.cc:232
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 999 of file Mask.cc.

1002  {
1003  return this->ImageBase<MaskPixelT>::operator()(x, y);
1004 }
int y
int x
PixelReference operator()(int x, int y)
Return a reference to the pixel (x, y)
Definition: Image.cc:232
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 1022 of file Mask.cc.

1026  {
1027  // !! converts an int to a bool
1028  return !!(this->ImageBase<MaskPixelT>::operator()(x, y) & getBitMask(planeId));
1029 }
int y
static MaskPixelT getBitMask(int plane)
Return the bitmask corresponding to plane ID.
Definition: Mask.cc:802
int x
PixelReference operator()(int x, int y)
Return a reference to the pixel (x, y)
Definition: Image.cc:232
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 987 of file Mask.cc.

991  {
992  return this->ImageBase<MaskPixelT>::operator()(x, y, check);
993 }
int y
int x
PixelReference operator()(int x, int y)
Return a reference to the pixel (x, y)
Definition: Image.cc:232
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 1010 of file Mask.cc.

1014  {
1015  return this->ImageBase<MaskPixelT>::operator()(x, y, check);
1016 }
int y
int x
PixelReference operator()(int x, int y)
Return a reference to the pixel (x, y)
Definition: Image.cc:232
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 1035 of file Mask.cc.

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

Definition at line 537 of file Mask.cc.

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

Definition at line 529 of file Mask.cc.

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

XOR a Mask into a Mask.

Definition at line 1126 of file Mask.cc.

1126  {
1127  checkMaskDictionaries(rhs);
1128 
1129  if (this->getDimensions() != rhs.getDimensions()) {
1130  throw LSST_EXCEPT(pexExcept::LengthError,
1131  str(boost::format("Images are of different size, %dx%d v %dx%d") %
1132  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
1133  }
1134  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(), bl::ret<MaskPixelT>(bl::_1 ^ bl::_2));
1135 }
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:1052
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 1118 of file Mask.cc.

1118  {
1119  transform_pixels(_getRawView(), _getRawView(), bl::ret<MaskPixelT>(bl::_1 ^ val));
1120 }
ImageT val
Definition: CR.cc:154
template<typename MaskPixelT >
void lsst::afw::image::Mask< MaskPixelT >::operator|= ( Mask< MaskPixelT > const &  rhs)

OR a Mask into a Mask.

Definition at line 1080 of file Mask.cc.

1080  {
1081  checkMaskDictionaries(rhs);
1082 
1083  if (this->getDimensions() != rhs.getDimensions()) {
1084  throw LSST_EXCEPT(pexExcept::LengthError,
1085  str(boost::format("Images are of different size, %dx%d v %dx%d") %
1086  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
1087  }
1088  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(), bl::ret<MaskPixelT>(bl::_1 | bl::_2));
1089 }
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:1052
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 1072 of file Mask.cc.

1072  {
1073  transform_pixels(_getRawView(), _getRawView(), bl::ret<MaskPixelT>(bl::_1 | val));
1074 }
ImageT val
Definition: CR.cc:154
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 1187 of file Mask.cc.

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

1234 {
1235  _maskDict->print();
1236 }
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 768 of file Mask.cc.

772 {
773  clearMaskPlane(getMaskPlane(name)); // clear this bits in this Mask
774 
775  if (_maskDict == detail::MaskDict::makeMaskDict() && removeFromDefault) { // we are the default
776  ;
777  } else {
778  _maskDict = _maskDict->clone();
779  }
780 
781  _maskDict->erase(name);
782 
783  if (removeFromDefault && detail::MaskDict::makeMaskDict()->getMaskPlane(name) >= 0) {
784  removeMaskPlane(name);
785  }
786 }
static int getMaskPlane(const std::string &name)
Return the mask plane number corresponding to a plane name.
Definition: Mask.cc:824
static void removeMaskPlane(const std::string &name)
Definition: Mask.cc:750
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:896
template<typename MaskPixelT >
void lsst::afw::image::Mask< MaskPixelT >::removeMaskPlane ( const std::string &  name)
static

Definition at line 750 of file Mask.cc.

751 {
752  if (detail::MaskDict::makeMaskDict()->getMaskPlane(name) < 0) {
753  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
754  str(boost::format("Plane %s doesn't exist in the default Mask") % name));
755  }
756 
757  detail::MaskDict::incrDefaultVersion(); // leave current Masks alone
758  _maskPlaneDict()->erase(name);
759 }
static int getMaskPlane(const std::string &name)
Return the mask plane number corresponding to a plane name.
Definition: Mask.cc:824
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:1245
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 1141 of file Mask.cc.

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

Definition at line 516 of file Mask.cc.

516  {
517  using std::swap; // See Meyers, Effective C++, Item 25
518 
520  swap(_maskDict, rhs._maskDict);
521 }
void swap(ImageBase< PixelT > &a, ImageBase< PixelT > &b)
Definition: Image.cc:287
void swap(ImageBase &rhs)
Definition: Image.cc:278
void swap(Mask &rhs)
Definition: Mask.cc:516
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: