BitMask.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef _BITMASK_
00011 #define _BITMASK_
00012 
00013 #include "Serializable.h"
00014 #include "TypesFile.h"
00015 
00016 /**
00017  *  Mask for selecting indiviual pixel locations
00018  *
00019  *  The BitMask class provides a means of selecting individual pixels within
00020  *  a scene.  A pixel coordinate is marked as either 'on' or 'off'.  The bounding
00021  *  box contains the outer most coordinates of selected pixels.  The BitMask is
00022  *  underlying part of an AOI to represent selected pixel locations in a scene.
00023  *
00024  *  @see        AOI
00025  */
00026 class BitMask : public Serializable
00027 {
00028 public:
00029    /**
00030     *  clear member function.
00031     *
00032     *  Re-initializes a bitmask to have no bits set
00033     */
00034    virtual void clear () = 0;
00035 
00036    /**
00037     *  In-place bitwise 'OR' operator.
00038     *
00039     *  Merges two BitMasks. Upon return, the bitmask 'OR'ed with
00040     *  the parameter bitmask will have all bits set that it had
00041     *  originally, plus all that are set in the parameter bitmask.
00042     *  This can be looked at as the union of the two masks.
00043     *
00044     *  @param   rhs
00045     *           "Right Hand Side". The mask to merge from.
00046     */
00047    virtual void merge (const BitMask& rhs) = 0;
00048 
00049    /**
00050     *  In-place bitwise 'AND' operator.
00051     *
00052     *  Merges two BitMasks. Upon return, the bitmask 'AND'ed with
00053     *  the parameter bitmask will have all bits set that were originally
00054     *  set in both it and the parameter bitmask. This can be looked at
00055     *  as the intersection of the two masks.
00056     *
00057     *  @param   rhs
00058     *           "Right Hand Side". The mask to merge from.
00059     */
00060    virtual void intersect (const BitMask& rhs) = 0;
00061 
00062    /**
00063     *  Equivalence operator.
00064     *
00065     *  Compares two bitmasks.
00066     *
00067     *  @param   rhs
00068     *           "Right Hand Side". The mask to compare with.
00069     *
00070     *  @return  true if the two masks are identical in content
00071     *         ` false otherwise
00072     */
00073    virtual bool compare (const BitMask& rhs) const = 0;
00074 
00075    /**
00076     *  Mask inversion method.
00077     *
00078     *  Inverts all bits in the mask. All 1's become 0's and all 0's
00079     *  become 1's. It uses the ~ operator internally to perform the
00080     *  inversion operation
00081     */
00082    virtual void invert () = 0;
00083 
00084    /**
00085     *  Subset comparison method.
00086     *
00087     *  Compares two bitmasks.
00088     *
00089     *  @param   source
00090     *           The mask to compare with.
00091     *
00092     *  @return  true if all bits set in the left-hand-side mask are also
00093     *           set in the parameter mask. Ensures that ~lhs | source == 1 
00094     *           for all bits in the masks. false otherwise.
00095     */
00096    virtual bool isSubsetOf (const BitMask &source) const = 0;
00097 
00098    /**
00099     *  setPixel method.
00100     *
00101     *  Sets a specified bit on or off.
00102     *
00103     *  @param   x
00104     *           The column of the pixel to set.
00105     *  @param   y
00106     *           The row of the pixel to set.
00107     *  @param   value
00108     *           A flag indicating whether or not to set pixel to 1 or not. 
00109     *           True means set the pixel to 1, false means set to 0.
00110     */
00111    virtual void setPixel (int x, int y, bool value) = 0;
00112 
00113    /**
00114     *  getPixel method.
00115     *
00116     *  Gets a specified bit.
00117     *
00118     *  @param   x
00119     *           The column of the pixel to get.
00120     *  @param   y
00121     *           The row of the pixel to get.
00122     *
00123     *  @return  the value of the pixel specified
00124     */
00125    virtual bool getPixel (int x, int y) const = 0;
00126 
00127    /**
00128     *  getBoundingBox method.
00129     *
00130     *  Gets the bounding box of set pixels in the bitmap. If no pixels are set
00131     *  in the bitmap, it sets the values to (0,0);(0,0).
00132     *
00133     *  @param  x1
00134     *          The column of the lower-left corner.
00135     *  @param  y1
00136     *          The row of the lower-left corner.
00137     *  @param  x2
00138     *          The column of the upper-right corner.
00139     *  @param  y2
00140     *          The row of the upper-right corner.
00141     */
00142    virtual void getBoundingBox (int &x1, int &y1, int &x2, int &y2) const = 0;
00143 
00144    /**
00145     *  Access the state of points outside the bounding box.
00146     *
00147     *  @return If this is true, than all points outside of the bounding box are selected.
00148     *          If this is false, that all points outside of the bounding box are not selected.
00149     *
00150     *  @see getBoundingBox(), getPixel()
00151     */
00152    virtual bool isOutsideSelected() const = 0;
00153 
00154    /**
00155     *  getCount method.
00156     *
00157     *  Gets the number of bits that are set in the mask.
00158     *
00159     *  @return  the number of bits that are set in the mask
00160     */
00161    virtual int getCount () const = 0;
00162 
00163    /**
00164     *  getRegion method.
00165     *
00166     *  Gets all of the bits in a rectangular region. They are returned as a 2D array 
00167     *  of bools. This
00168     *  array is owned by the BitMask and should not be modified or deleted. The
00169     *  array will remain unchanged until the next call to getRegion.
00170     *
00171     *  @param   x1,y1
00172     *           The coordinate of the lower-left corner of the region to get
00173     *  @param   x2,y2
00174     *           The coordinate of the upper-right corner of the region to get
00175     *
00176     *  @return  a 2D array of bools representing the region specified
00177     */
00178    virtual const bool **getRegion (int x1, int y1, int x2, int y2) = 0;
00179 
00180    /**
00181     *  GetPixels method.
00182     *
00183     *  Gets pixels 32 at a time.
00184     *
00185     *  @param   x
00186     *           The column of the pixels to get. Must be a multiple of 32.
00187     *  @param   y
00188     *           The row of the starting pixel.
00189     *
00190     *  @return  the 32 bits specified, packed into an unsigned int
00191     */
00192    virtual unsigned int getPixels (int x, int y) const = 0;
00193 
00194    /**
00195     *  SetPixels method.
00196     *
00197     *  Sets pixels 32 at a time.
00198     *
00199     *  @param   x
00200     *           The column of the pixels to set. Must be a multiple of 32.
00201     *  @param   y
00202     *           The row of the starting pixel.
00203     *  @param   values
00204     *           An unsigned int containing the states for 32 bits, packed
00205     *           into an unsigned int
00206     */
00207    virtual void setPixels (int x, int y, unsigned int values) = 0;
00208 
00209    /**
00210     *  Changes a region of a bitmask.
00211     *
00212     *  If op is DRAW, if fills the region.  If op is ERASE, it clears the region.
00213     *  If op is TOGGLE, it toggles all pixels in the region.
00214     *
00215     *  @param   x1
00216     *           The lower left x-coordinate of the region to change.
00217     *  @param   y1
00218     *           The lower left y-coordinate of the region to change.
00219     *  @param   x2
00220     *           The upper right x-coordinate of the region to change
00221     *  @param   y2
00222     *           The upper right y-coordinate of the region to change
00223     *  @param   op
00224     *           The drawing mode
00225     */
00226    virtual void setRegion (int x1, int y1, int x2, int y2, ModeType op) = 0;
00227 
00228    /**
00229     *  Merges two BitMasks.
00230     *
00231     *  In-place bitwise 'XOR' operator.
00232     *
00233     *  @param   rhs
00234     *           "Right Hand Side". The mask to merge from.
00235     */
00236    virtual void toggle (const BitMask& rhs) = 0;
00237 
00238    /**
00239     *   Gets the actual bounding box of set pixels in the bitmap.
00240     *
00241     *   If points have been removed from the BitMask, BitMask::getBoundingBox() may not
00242     *   be the minimum box needed to enclose the pixels.  This method will
00243     *   always be the minimum.  If no pixels are set in the bitmap, it sets 
00244     *   the values to (0,0);(0,0).
00245     *
00246     *  @param  x1
00247     *          The column of the lower-left corner.
00248     *  @param  y1
00249     *          The row of the lower-left corner.
00250     *  @param  x2
00251     *          The column of the upper-right corner.
00252     *  @param  y2
00253     *          The row of the upper-right corner.
00254     */
00255     virtual void getMinimalBoundingBox(int &x1, int &y1, int &x2, int &y2) const = 0;
00256 
00257 protected:
00258    /**
00259     * This should be destroyed by calling ObjectFactory::destroyObject.
00260     */
00261    virtual ~BitMask() {}
00262 };
00263 
00264 #endif // _BITMASK_

Software Development Kit - Opticks 4.9.0 Build 16218