OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
ossimBitMaskWriter Class Reference

Class for computing a mask from an input image source and writing the mask file to disk. More...

#include <ossimBitMaskWriter.h>

Inheritance diagram for ossimBitMaskWriter:
ossimOutputSource ossimSource ossimConnectableObject ossimErrorStatusInterface ossimObject ossimListenerManager ossimPropertyInterface ossimReferenced

Public Member Functions

 ossimBitMaskWriter ()
 Default constructor typically used when reading a mask from disk. More...
 
 ~ossimBitMaskWriter ()
 
void setBogusPixel (double pixel_value)
 Sets the NULL pixel value to consider when computing mask: More...
 
void setBogusPixelRange (double min, double max)
 Sets the range of pixels (inclusive) to be regarded as NULL pixels when computing mask. More...
 
void setStartingResLevel (ossim_uint32 res_level)
 Sets the starting resolution level for the mask. More...
 
void generateMask (ossimRefPtr< ossimImageData > tile, ossim_uint32 rLevel)
 Given a source's tile, derives the alpha mask and saves it in buffer for later writing to disk. More...
 
bool buildOverviews (ossim_uint32 total_num_rlevels)
 For imagery that already has overviews built, but with artifact edge pixels (such as JP2- compressed data), it is preferred to build the mask overviews directly from the R0 mask. More...
 
virtual bool loadState (const ossimKeywordlist &spec, const char *prefix=0)
 Computes and writes the mask file according to the specification in the KWL. More...
 
virtual bool isOpen () const
 
virtual bool open ()
 
virtual void close ()
 Writes the mask file to path specified. Returns TRUE if successful. More...
 
virtual bool canConnectMyInputTo (ossim_int32 myInputIndex, const ossimConnectableObject *object) const
 required to be overriden by derived classes More...
 
virtual ossim_int32 connectMyInputTo (ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
 Will try to connect this objects input to the passed in object. More...
 
- Public Member Functions inherited from ossimOutputSource
 ossimOutputSource (ossimObject *owner=NULL)
 
 ossimOutputSource (ossimObject *owner, ossim_uint32 inputListSize, ossim_uint32 outputListSize, bool inputListIsFixedFlag=true, bool outputListIsFixedFlag=true)
 
virtual ~ossimOutputSource ()
 
virtual bool open (const ossimString &outputName)
 
virtual void setOutputName (const ossimString &outputName)
 
virtual const ossimStringgetOutputName ()
 
virtual bool saveState (ossimKeywordlist &kwl, const char *prefix=0) const
 
- Public Member Functions inherited from ossimSource
 ossimSource (ossimObject *owner=0)
 
 ossimSource (ossimObject *owner, ossim_uint32 inputListSize, ossim_uint32 outputListSize, bool inputListIsFixedFlag=true, bool outputListIsFixedFlag=true)
 
virtual ~ossimSource ()
 
virtual bool isSourceEnabled () const
 
virtual void enableSource ()
 
virtual void disableSource ()
 
virtual bool getEnableFlag () const
 
virtual void setEnableFlag (bool flag)
 
virtual bool isInitialized () const
 
virtual void setInitializedFlag (bool flag)
 
virtual void initialize ()
 
virtual void setProperty (ossimRefPtr< ossimProperty > property)
 
virtual ossimRefPtr< ossimPropertygetProperty (const ossimString &name) const
 
virtual void getPropertyNames (std::vector< ossimString > &propertyNames) const
 
virtual std::ostream & print (std::ostream &out) const
 Outputs theErrorStatus as an ossimErrorCode and an ossimString. More...
 
- Public Member Functions inherited from ossimConnectableObject
 ossimConnectableObject (ossimObject *owner=0)
 Base constructor of this object. More...
 
 ossimConnectableObject (ossimObject *owner, ossim_int32 inputListSize, ossim_int32 outputListSize, bool inputListIsFixedFlag=true, bool outputListIsFixedFlag=true)
 
virtual ~ossimConnectableObject ()
 
void setId (const ossimId &id)
 All connectable objects will have id's. More...
 
const ossimIdgetId () const
 Will allow us to get this object's id. More...
 
const ossimObjectgetOwner () const
 Fetches the current owner, most likely a container but not limited to one. More...
 
virtual void changeOwner (ossimObject *owner)
 Permits changing the object's owner. More...
 
virtual void setDescription (const ossimString &description)
 
virtual ossimString getDescription () const
 
virtual bool isConnected (ossimConnectableObjectDirectionType direction=CONNECTABLE_DIRECTION_INPUT) const
 will check the direction specified to see if all slots are full. More...
 
 OSSIM_DEPRECATE_METHOD (virtual ossimConnectableObject *findConnectableObject(const ossimId &id))
 
 OSSIM_DEPRECATE_METHOD (virtual ossimConnectableObject *findObjectOfType(RTTItypeid typeId, ossimConnectableObjectDirectionType directionType, bool recurse=true))
 
 OSSIM_DEPRECATE_METHOD (virtual ossimConnectableObject *findObjectOfType(const ossimString &obj, ossimConnectableObjectDirectionType directionType, bool recurse=true))
 
 OSSIM_DEPRECATE_METHOD (virtual ossimConnectableObject *findInputObjectOfType(const ossimString &className))
 
virtual ossim_int32 findInputIndex (const ossimConnectableObject *object)
 Return a valid index of the input list if the passed in object is found else return -1. More...
 
virtual ossim_int32 findInputIndex (const ossimId &id)
 Return a valid index of the input list if the passed id is found else return -1. More...
 
virtual ossim_int32 findOutputIndex (const ossimConnectableObject *object)
 Return a valid index of the output list if the passed in object is found else return -1. More...
 
virtual ossim_int32 findOutputIndex (const ossimId &id)
 Return a valid index of the output list if the passed in object is found else return -1. More...
 
virtual ossim_int32 getMyInputIndexToConnectTo (ossimConnectableObject *object) const
 Should return the first available index to connect to. More...
 
virtual ossim_int32 getMyOutputIndexToConnectTo (ossimConnectableObject *object) const
 Should return the first available index to connect to. More...
 
virtual bool canConnectMyOutputTo (ossim_int32 myOutputIndex, const ossimConnectableObject *object) const
 default implementation is to allow anyone to connect to us. More...
 
virtual void disconnect (ossimConnectableObject *object=0)
 Will disconnect the object passed in. More...
 
virtual void disconnect (const ossimId &id)
 Will disconnect the object passed in. More...
 
virtual ossimRefPtr< ossimConnectableObjectdisconnectMyInput (ossim_int32 inputIndex, bool disconnectOutputFlag=true, bool createEventFlag=true)
 Will disconnect the object at the given input index and generate a connection event. More...
 
virtual void disconnectMyInput (ossimConnectableObject *input, bool disconnectOutputFlag=true, bool createEventFlag=true)
 Finds the index of the passed in input and calls disconnectMyInput(inputIndex, disconnectOutputFlag, createEventFlag);. More...
 
virtual void disconnectMyInputs (ConnectableObjectList &inputList, bool disconnectOutputFlag=true, bool createEventFlag=true)
 
virtual ossimRefPtr< ossimConnectableObjectdisconnectMyOutput (ossim_int32 outputIndex, bool disconnectInputFlag=true, bool createEventFlag=true)
 Will disconnect the object at the given output index and generate a connection event. More...
 
virtual void disconnectMyOutput (ossimConnectableObject *output, bool disconnectInputFlag=true, bool createEventFlag=true)
 Will disconnect the output object. More...
 
virtual void disconnectMyOutputs (ConnectableObjectList &outputList, bool disconnectOutputFlag=true, bool createEventFlag=true)
 
virtual void disconnectAllInputs ()
 Will disconnect all of the input objects. More...
 
virtual void disconnectAllOutputs ()
 Will disconnect all of the output objects. More...
 
virtual ossim_int32 connectMyInputTo (ossim_int32 inputIndex, ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
 Will connect the specified input to the passed in object. More...
 
virtual bool connectMyInputTo (ConnectableObjectList &inputList, bool makeOutputConnection=true, bool createEventFlag=true)
 
virtual ossim_int32 connectMyOutputTo (ossimConnectableObject *outputObject, bool makeInputConnection=true, bool createEventFlag=true)
 Will try to connect this objects output to the passed in object. More...
 
virtual bool connectMyOutputTo (ConnectableObjectList &outputList, bool makeInputConnection=true, bool createEventFlag=true)
 
virtual bool connectInputList (ConnectableObjectList &inputList)
 Will disconnect itself from all inputs and reset to the passed in input list. More...
 
virtual bool connectOutputList (ConnectableObjectList &outputList)
 Will disconnect itself from all outputs and reset to the passed in output list. More...
 
virtual ossim_uint32 getNumberOfInputs () const
 Returns the number of input objects. More...
 
virtual ossim_uint32 getNumberOfOutputs () const
 Return the number of output objects. More...
 
ossimConnectableObjectgetInput (ossim_uint32 index=0)
 returns the object at the specified index. More...
 
const ossimConnectableObjectgetInput (ossim_uint32 index=0) const
 returns the object at the specified index. More...
 
ossimConnectableObjectgetOutput (ossim_uint32 index=0)
 returns the object at the specified index. More...
 
const ossimConnectableObjectgetOutput (ossim_uint32 index=0) const
 returns the object at the specified index. More...
 
virtual void setNumberOfInputs (ossim_int32 numberOfInputs)
 Will set the number of inputs. More...
 
virtual bool getInputListIsFixedFlag () const
 
virtual bool getOutputListIsFixedFlag () const
 
virtual void setNumberOfOutputs (ossim_int32 numberOfInputs)
 Will set the number of outputs. More...
 
const ConnectableObjectListgetInputList () const
 
const ConnectableObjectListgetOutputList () const
 
ConnectableObjectListgetInputList ()
 
ConnectableObjectListgetOutputList ()
 
 OSSIM_DEPRECATE_METHOD (virtual void findAllObjectsOfType(ConnectableObjectList &result, const RTTItypeid &typeInfo, bool recurse=true))
 
 OSSIM_DEPRECATE_METHOD (virtual void findAllObjectsOfType(ConnectableObjectList &result, const ossimString &className, bool recurse=true))
 
virtual void propagateEventToOutputs (ossimEvent &event)
 
virtual void propagateEventToInputs (ossimEvent &event)
 
virtual void setProperty (const ossimString &name, const ossimString &value)
 
virtual ossim_uint32 saveStateOfAllInputs (ossimKeywordlist &kwl, bool saveThisStateFlag=true, ossim_uint32 objectIndex=1, const char *prefix=0) const
 Save the state of all inputs to a keyword list. More...
 
virtual bool fillContainer (ossimConnectableContainer &container)
 Inserts this object and all of its children and inputs into the container provided. More...
 
bool moveInputUp (const ossimId &id)
 Moves the input connection matching id up one in the connection list. More...
 
bool moveInputDown (const ossimId &id)
 Moves the input connection matching id down one in the connection list. More...
 
bool moveInputToTop (const ossimId &id)
 Moves the input connection matching id to the top of the connection list. More...
 
bool moveInputToBottom (const ossimId &id)
 Moves the input connection matching id to the bottom of the connection list. More...
 
virtual void accept (ossimVisitor &visitor)
 We will add a visitor interface for all connectable objects. More...
 
- Public Member Functions inherited from ossimObject
 ossimObject ()
 
virtual ~ossimObject ()
 
virtual ossimObjectdup () const
 
virtual ossimString getShortName () const
 
virtual ossimString getLongName () const
 
virtual ossimString getClassName () const
 
virtual RTTItypeid getType () const
 
virtual bool canCastTo (ossimObject *obj) const
 
virtual bool canCastTo (const RTTItypeid &id) const
 
virtual bool canCastTo (const ossimString &parentClassName) const
 
virtual bool isEqualTo (const ossimObject &obj, ossimCompareType compareType=OSSIM_COMPARE_FULL) const
 
- Public Member Functions inherited from ossimReferenced
 ossimReferenced ()
 
 ossimReferenced (const ossimReferenced &)
 
ossimReferencedoperator= (const ossimReferenced &)
 
void ref () const
 increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void unref () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unref_nodelete () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
int referenceCount () const
 
- Public Member Functions inherited from ossimListenerManager
 ossimListenerManager ()
 
virtual ~ossimListenerManager ()
 
virtual void fireEvent (ossimEvent &event)
 
virtual bool addListener (ossimListener *listener)
 
virtual bool removeListener (ossimListener *listener)
 
virtual bool findListener (ossimListener *listener)
 
- Public Member Functions inherited from ossimPropertyInterface
 ossimPropertyInterface ()
 
virtual ~ossimPropertyInterface ()
 
virtual ossimString getPropertyValueAsString (const ossimString &name) const
 
void getPropertyList (std::vector< ossimRefPtr< ossimProperty > > &propertyList) const
 
void setProperties (std::vector< ossimRefPtr< ossimProperty > > &propertyList)
 
- Public Member Functions inherited from ossimErrorStatusInterface
 ossimErrorStatusInterface ()
 
virtual ~ossimErrorStatusInterface ()
 
virtual ossimErrorCode getErrorStatus () const
 
virtual ossimString getErrorStatusString () const
 
virtual void setErrorStatus (ossimErrorCode error_status) const
 
virtual void setErrorStatus () const
 
virtual void clearErrorStatus () const
 
bool hasError () const
 

Static Public Attributes

static const char * BM_STARTING_RLEVEL_KW = "starting_rlevel"
 
static const char * MASK_FILE_MAGIC_NUMBER = "OSSIM_BIT_MASK"
 

Protected Member Functions

void initializeFlipper ()
 Initializes the flipper (used for identifying pixels for masking) to default values. More...
 
void reset ()
 Deletes allocated buffers and resets all values to defaults. More...
 
ossimIpt computeImageSize (ossim_uint32 rlevel, ossimImageData *tile) const
 Since overviews may not yet exist when the mask is being written, we must compute the size of the source image based on the original R0 image size. More...
 
- Protected Member Functions inherited from ossimSource
 ossimSource (const ossimSource &rhs)
 
const ossimSourceoperator= (const ossimSource &rhs)
 
- Protected Member Functions inherited from ossimConnectableObject
ossimConnectableObjectfindObjectOfType (ConnectableObjectList *connectableList, ossimVisitor &visitor)
 
- Protected Member Functions inherited from ossimReferenced
virtual ~ossimReferenced ()
 
- Protected Member Functions inherited from ossimListenerManager
 ossimListenerManager (const ossimListenerManager &rhs)
 

Protected Attributes

ossimRefPtr< ossimPixelFlipperm_flipper
 
ossimRefPtr< ossimMemoryImageSourcem_memoryImage
 
vector< ossim_uint8 * > m_buffers
 
vector< ossimIptm_bufferSizes
 
ossim_uint32 m_startingResLevel
 
ossimIpt m_imageSize
 Size of full res source image. More...
 
- Protected Attributes inherited from ossimOutputSource
ossimString theOutputName
 
- Protected Attributes inherited from ossimSource
bool theEnableFlag
 
bool theInitializedFlag
 
- Protected Attributes inherited from ossimConnectableObject
ossimId theId
 
ossimString theDescription
 
ossimObjecttheOwner
 
bool theInputListIsFixedFlag
 Indicates whether the theInputObjectList is fixed. More...
 
bool theOutputListIsFixedFlag
 Indicates whether the theOutputObjectList is fixed. More...
 
ConnectableObjectList theInputObjectList
 Holds a list of input objects. More...
 
ConnectableObjectList theOutputObjectList
 Holds a list of output objects. More...
 
- Protected Attributes inherited from ossimListenerManager
std::list< ossimListener * > theListenerList
 
bool theEnabledFlag
 
std::list< ossimListener * > theDelayedAdd
 
std::list< ossimListener * > theDelayedRemove
 
bool theFireEventFlag
 
- Protected Attributes inherited from ossimErrorStatusInterface
ossimErrorCode theErrorStatus
 

Friends

class ossimBitMaskTileSource
 

Additional Inherited Members

- Public Types inherited from ossimConnectableObject
enum  ossimConnectableObjectDirectionType { CONNECTABLE_DIRECTION_NONE = 0, CONNECTABLE_DIRECTION_INPUT = 1, CONNECTABLE_DIRECTION_OUTPUT = 2 }
 
typedef std::vector< ossimRefPtr< ossimConnectableObject > > ConnectableObjectList
 

Detailed Description

Class for computing a mask from an input image source and writing the mask file to disk.

This class takes care of all details associated with computing, writing and reading the custom, bit-compressed OSSIM bit mask file format.

When the developer needs to mask an image, the following needs to be done:

Creating the Mask:

  1. A mask file first needs to be created using ossimBitMaskWriter and a source image. The app "img2rr --create-mask" directs that program to use ossimBitMaskWriter to generate a mask
    during overview generation. There is also create-bitmask app that will generate the mask.
  2. An OSSIM ".mask" file should exist on disk after step 0. This is typically the same base name as the source image file being masked.

Using the Mask:

  1. An ossimBitMaskTileSource (derived from ossimImageHandler) needs to be instantiated and the mask file name used to open it.
  2. An ossimMaskFilter (derived from ossimImageCombiner) is the actual filter that combines the source image handler and the ossimBitMaskTileSource object to provide the resultant masked tiles.

The OSSIM bit mask file contains a small header that consists of: magic number, starting res level, number of res levels num columns at starting res level, num rows at starting res level, num columns at 2nd res level, num rows at 2nd res level, etc., for all res levels <space> <compressed binary="" mask="" data>="">

The number of rows and columns represents the number of bytes in the mask, with each byte containing 8 alpha mask bits representing 8 pixels in the original image.

The mask is computed here using the specified values for bogus pixels. If a pixel in the source image is in the range of bogus values, a mask of 0 is assigned to that pixel, otherwise 1.

Definition at line 69 of file ossimBitMaskWriter.h.

Constructor & Destructor Documentation

◆ ossimBitMaskWriter()

ossimBitMaskWriter::ossimBitMaskWriter ( )

Default constructor typically used when reading a mask from disk.

Definition at line 29 of file ossimBitMaskWriter.cpp.

30  : m_flipper(0),
31  m_memoryImage(0),
33 {
34 }
ossim_uint32 m_startingResLevel
ossimRefPtr< ossimMemoryImageSource > m_memoryImage
ossimRefPtr< ossimPixelFlipper > m_flipper

◆ ~ossimBitMaskWriter()

ossimBitMaskWriter::~ossimBitMaskWriter ( )

Definition at line 39 of file ossimBitMaskWriter.cpp.

References close(), and isOpen().

40 {
41  // Make sure the mask file was written out before disappearing:
42  if (isOpen())
43  close();
44 }
virtual bool isOpen() const
virtual void close()
Writes the mask file to path specified. Returns TRUE if successful.

Member Function Documentation

◆ buildOverviews()

bool ossimBitMaskWriter::buildOverviews ( ossim_uint32  total_num_rlevels)

For imagery that already has overviews built, but with artifact edge pixels (such as JP2- compressed data), it is preferred to build the mask overviews directly from the R0 mask.

This method will build the remaining number of R-levels from the last defined mask buffer such that the total number of R-levels (counting R0) are represented. Returns TRUE if successful.

Definition at line 387 of file ossimBitMaskWriter.cpp.

References m_buffers, m_bufferSizes, m_startingResLevel, ossimIpt::x, x, ossimIpt::y, and y.

388 {
389  // First establish the remaining number of R-levels to generate, and the last valid R-level
390  // currently in memory:
391  if (m_buffers.size() == 0)
392  return false;
393  if (m_buffers.size() == total_num_rlevels)
394  return true; // nothing to do
395  ossim_uint32 ref_rlevel = m_startingResLevel + (ossim_uint32)m_buffers.size() - 1;
396  ossim_uint32 ovr_rlevel = ref_rlevel + 1;
397 
398  ossimIpt ref_size(m_bufferSizes[ref_rlevel - m_startingResLevel]);
399  ossim_uint8 *ref_buf = m_buffers[ref_rlevel - m_startingResLevel];
400  ossim_uint32 ref_index = 0, ovr_index = 0;
401  ossim_uint8 *ovr_buf = 0;
402  ossim_uint32 size_of_refbuf = ref_size.x * ref_size.y;
403 
404  // Loop over all remaining res levels:
405  while (ovr_rlevel != total_num_rlevels)
406  {
407  // Allocate the buffer at this R-level:
408  ossimIpt ovr_size((ref_size.x + 1) / 2, (ref_size.y + 1) / 2);
409  ossim_uint32 size_of_ovrbuf = ovr_size.x * ovr_size.y;
410  if (size_of_ovrbuf == 0)
411  return false;
412  ovr_buf = new ossim_uint8[size_of_ovrbuf];
413  memset(ovr_buf, 0, size_of_ovrbuf);
414  m_buffers.push_back(ovr_buf);
415  m_bufferSizes.push_back(ovr_size);
416 
417  // Loop over each output overview pixel, considering the underlying rlevel (equivalent to
418  // nearest-neighbor resampling for overview at 2X decimation):
419  for (int y = 0; y < ovr_size.y; y++)
420  {
421  ref_index = 2 * y * ref_size.x;
422  ovr_index = y * ovr_size.x;
423 
424  for (int x = 0; x < ovr_size.x; x++)
425  {
426  ossim_uint8 a = 0;
427  ossim_uint8 b = 0;
428  if (ref_index < size_of_refbuf)
429  {
430  a = ref_buf[ref_index++];
431  if ((x < (ovr_size.x - 1)) || !(ref_size.x & 1))
432  b = ref_buf[ref_index++];
433  }
434  ovr_buf[ovr_index++] = ((a & 0x80) |
435  ((a & 0x20) << 1) |
436  ((a & 0x08) << 2) |
437  ((a & 0x02) << 3) |
438  ((b & 0x80) >> 4) |
439  ((b & 0x20) >> 3) |
440  ((b & 0x08) >> 2) |
441  ((b & 0x02) >> 1));
442  }
443  }
444 
445  // Advance to next rlevel:
446  ref_buf = ovr_buf;
447  ref_size = ovr_size;
448  size_of_refbuf = size_of_ovrbuf;
449  ++ovr_rlevel;
450  }
451 
452  return true;
453 }
ossim_uint32 x
vector< ossimIpt > m_bufferSizes
ossim_uint32 y
ossim_uint32 m_startingResLevel
vector< ossim_uint8 * > m_buffers
unsigned int ossim_uint32
unsigned char ossim_uint8

◆ canConnectMyInputTo()

bool ossimBitMaskWriter::canConnectMyInputTo ( ossim_int32  myInputIndex,
const ossimConnectableObject object 
) const
virtual

required to be overriden by derived classes

Implements ossimConnectableObject.

Definition at line 285 of file ossimBitMaskWriter.cpp.

287 {
288  const ossimImageSource *ois = dynamic_cast<const ossimImageSource *>(object);
289  return (ois != NULL);
290 }

◆ close()

void ossimBitMaskWriter::close ( )
virtual

Writes the mask file to path specified. Returns TRUE if successful.

Implements ossimOutputSource.

Definition at line 188 of file ossimBitMaskWriter.cpp.

References ossimString::chars(), ossimString::empty(), m_buffers, m_bufferSizes, m_startingResLevel, MASK_FILE_MAGIC_NUMBER, ossimNotify(), ossimNotifyLevel_WARN, reset(), ossimOutputSource::theOutputName, x, and y.

Referenced by ~ossimBitMaskWriter().

189 {
190  static const char *MODULE = "ossimBitMaskWriter::writeMask()";
191  static const ossimString MASK_EXTENSION("mask");
192 
193  // Open the output file. Use default name if none provided.
194  if (theOutputName.empty()) // Couldn't figure out the name
195  {
196  ossimNotify(ossimNotifyLevel_WARN) << MODULE << " -- Error encountered trying to create mask file"
197  " for writing because output file name was never initialized.";
198  return;
199  }
200 
201  ofstream maskFileStream(theOutputName.chars(), ios::out | ios::binary);
202  if (!maskFileStream.is_open())
203  {
204  ossimNotify(ossimNotifyLevel_WARN) << MODULE << " -- Error encountered trying to create mask file"
205  "<"
206  << theOutputName << "> for writing. Cannot write mask.";
207  return;
208  }
209 
210  // Write the header info:
211  ossim_uint32 num_rlevels = (ossim_uint32)m_buffers.size();
212  maskFileStream << MASK_FILE_MAGIC_NUMBER << " " << m_startingResLevel << " " << num_rlevels << " ";
213  for (ossim_uint32 r = 0; r < num_rlevels; r++)
214  maskFileStream << m_bufferSizes[r].x << " " << m_bufferSizes[r].y << " ";
215  maskFileStream << ends;
216 
217  // Loop over each res level and write buffers to disk:
218  for (ossim_uint32 rlevel = 0; rlevel < num_rlevels; ++rlevel)
219  {
220  ossim_uint32 bufsize = m_bufferSizes[rlevel].x * m_bufferSizes[rlevel].y;
221  maskFileStream.write((char *)(m_buffers[rlevel]), bufsize);
222  }
223 
224  maskFileStream.close();
225  reset();
226 
227  return;
228 }
ossim_uint32 x
vector< ossimIpt > m_bufferSizes
ossim_uint32 y
ossim_uint32 m_startingResLevel
static const char * MASK_FILE_MAGIC_NUMBER
vector< ossim_uint8 * > m_buffers
ossimString theOutputName
unsigned int ossim_uint32
const char * chars() const
For backward compatibility.
Definition: ossimString.h:77
bool empty() const
Definition: ossimString.h:411
void reset()
Deletes allocated buffers and resets all values to defaults.
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ computeImageSize()

ossimIpt ossimBitMaskWriter::computeImageSize ( ossim_uint32  rlevel,
ossimImageData tile 
) const
protected

Since overviews may not yet exist when the mask is being written, we must compute the size of the source image based on the original R0 image size.

Since overviews may not yet exist when the mask is being written, we must compute the size of the mask buffer based on the original R0 image size.

Definition at line 361 of file ossimBitMaskWriter.cpp.

References ossimImageData::getHeight(), ossimImageData::getWidth(), m_imageSize, ossimIpt::x, and ossimIpt::y.

Referenced by generateMask().

362 {
363  if (rlevel == 0)
364  return m_imageSize;
365 
366  ossimIpt isize(m_imageSize);
367  for (ossim_uint32 r = 1; r <= rlevel; r++)
368  {
369  isize.x = (isize.x + 1) / 2;
370  isize.y = (isize.y + 1) / 2;
371  }
372 
373  // Adjust size n X direction to even mask boundary:
374  ossimIpt tile_size(tile->getWidth(), tile->getHeight());
375  isize.x = ((int)(isize.x + 7) / 8) * 8;
376 
377  return isize;
378 }
virtual ossim_uint32 getWidth() const
ossimIpt m_imageSize
Size of full res source image.
virtual ossim_uint32 getHeight() const
unsigned int ossim_uint32
ossim_int32 x
Definition: ossimIpt.h:141

◆ connectMyInputTo()

ossim_int32 ossimBitMaskWriter::connectMyInputTo ( ossimConnectableObject inputObject,
bool  makeOutputConnection = true,
bool  createEventFlag = true 
)
virtual

Will try to connect this objects input to the passed in object.

It will return a valid index >= 0 if successful. Will use the getMyInputIndexToConnectTo method to implement the connection

Reimplemented from ossimConnectableObject.

Definition at line 295 of file ossimBitMaskWriter.cpp.

References ossimConnectableObject::accept(), ossimConnectableObject::connectMyInputTo(), ossimString::contains(), ossimConnectableObject::disconnectAllInputs(), ossimString::empty(), ossimRefPtr< T >::get(), ossimImageHandler::getBoundingRect(), ossimImageHandler::getFilename(), ossimCollectionVisitor::getObject(), initializeFlipper(), m_flipper, m_imageSize, ossimFilename::noExtension(), ossimFilename::setExtension(), ossimIrect::size(), ossimOutputSource::theOutputName, ossimRefPtr< T >::valid(), ossimVisitor::VISIT_CHILDREN, and ossimVisitor::VISIT_INPUTS.

Referenced by ossimOverviewSequencer::setImageHandler().

298 {
299  ossimImageSource *input_source = dynamic_cast<ossimImageSource *>(inputObject);
300  if (input_source == NULL)
301  return -1;
302 
303  // Base class takes care of connection with this object:
304  ossimConnectableObject::connectMyInputTo(input_source, makeOutputConnection, createEventFlag);
305 
306  // This input should be an image handler, but may need to search the objects inputs in case
307  // it is chained:
308  ossimImageHandler *handler = dynamic_cast<ossimImageHandler *>(input_source);
309  if (handler == NULL)
310  {
311  // Need to search:
312  ossimTypeNameVisitor visitor(ossimString("ossimImageHandler"),
313  true,
315 
316  input_source->accept(visitor);
317  ossimRefPtr<ossimObject> obj = visitor.getObject();
318  if (obj.valid())
319  {
320  handler = dynamic_cast<ossimImageHandler *>(obj.get());
321  }
322  }
323 
324  // Should have a handler:
325  if (!handler)
326  {
328  return -1;
329  }
330 
331  // A handler has been identified. Need the filename:
332  ossimFilename imageFile = handler->getFilename();
333  if (imageFile.contains("ovr.tmp"))
334  {
335  // The handler is actually an overview, need some massaging to work since the overview may
336  // not have an R0 entry and R1 rect must be requested instead:
337  m_imageSize = handler->getBoundingRect(1).size() * 2;
338  imageFile = imageFile.noExtension();
339  }
340  else
341  {
342  // This is normal image handler so it is OK to request R0 rect:
343  m_imageSize = handler->getBoundingRect(0).size();
344  }
345  if (theOutputName.empty())
346  theOutputName = imageFile.setExtension("mask");
347 
348  // Check if the pixel flipper was initialized:
349  if (m_flipper.valid())
350  m_flipper->connectMyInputTo(input_source);
351  else
353 
354  return 0;
355 }
ossimFilename noExtension() const
ossimIpt m_imageSize
Size of full res source image.
bool valid() const
Definition: ossimRefPtr.h:75
bool contains(char aChar) const
Definition: ossimString.h:58
ossimIpt size() const
Definition: ossimIrect.h:510
ossimString theOutputName
void initializeFlipper()
Initializes the flipper (used for identifying pixels for masking) to default values.
virtual const ossimFilename & getFilename() const
Returns the filename.
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
ossimRefPtr< ossimPixelFlipper > m_flipper
This class defines an abstract Handler which all image handlers(loaders) should derive from...
bool empty() const
Definition: ossimString.h:411
virtual void accept(ossimVisitor &visitor)
We will add a visitor interface for all connectable objects.
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
Returns zero-based bounding rectangle of the image.
virtual void disconnectAllInputs()
Will disconnect all of the input objects.
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.

◆ generateMask()

void ossimBitMaskWriter::generateMask ( ossimRefPtr< ossimImageData tile,
ossim_uint32  rLevel 
)

Given a source's tile, derives the alpha mask and saves it in buffer for later writing to disk.

Definition at line 105 of file ossimBitMaskWriter.cpp.

References computeImageSize(), ossimRefPtr< T >::get(), ossimImageData::getImageRectangle(), ossimPixelFlipper::getTile(), ossimPixelFlipper::initialize(), initializeFlipper(), ossimImageData::isNull(), m_buffers, m_bufferSizes, m_flipper, m_memoryImage, m_startingResLevel, ossimMemoryImageSource::setImage(), ossimRefPtr< T >::valid(), ossimIpt::x, x, ossimIpt::y, and y.

106 {
107  static const ossim_uint8 MASK_BITS_0[] = {0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0xFE};
108  static const ossim_uint8 MASK_BITS_1[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
109 
110  // We don't start doing anything until starting res or higher requested:
111  ossim_uint32 mask_rlevel = rLevel - m_startingResLevel;
112  if (!tile.valid())
113  return;
114 
115  // We should have had this done by now, but just in case:
116  if (!m_flipper.valid())
118 
120  m_memoryImage->setImage(tile);
122  flipTile = m_flipper->getTile(tile->getImageRectangle());
123  ossimIpt image_size = computeImageSize(rLevel, flipTile.get());
124  ossim_uint32 num_mask_cols = (image_size.x + 7) / 8; // size of mask buffer after compression
125  ossim_uint32 num_mask_rows = image_size.y;
126  ossim_uint8 *maskbuf = 0;
127 
128  // Check if mask buffer for this R-level has already been allocated:
129  if (m_buffers.size() <= mask_rlevel)
130  {
131  ossim_uint32 size_of_maskbuf = num_mask_rows * num_mask_cols;
132  maskbuf = new ossim_uint8[size_of_maskbuf];
133  memset(maskbuf, 0, size_of_maskbuf);
134  m_buffers.push_back(maskbuf);
135  m_bufferSizes.push_back(ossimIpt(num_mask_cols, num_mask_rows));
136  }
137  else
138  maskbuf = m_buffers[mask_rlevel];
139 
140  ossim_uint32 mask_index = 0, tile_index = 0, start_bit = 0;
141  ossimIrect tile_rect(flipTile->getImageRectangle());
142  ossimIpt ul(tile_rect.ul());
143  ossimIpt lr(tile_rect.lr());
144 
145  // Scan each pixel in the source tile and decide on mask value:
146  for (int y = ul.y; (y <= lr.y) && (y < image_size.y); y++)
147  {
148  mask_index = y * num_mask_cols + ul.x / 8;
149  start_bit = ul.x % 8; // may not start on even mask byte boundary
150 
151  for (int x = ul.x; (x <= lr.x); /* incremented in bit loop below */)
152  {
153  if (x < image_size.x)
154  {
155  // Process 8 samples and pack resultant mask into one byte:
156  maskbuf[mask_index] = 0;
157  for (ossim_uint32 mask_bit = start_bit; mask_bit < 8; ++mask_bit)
158  {
159  // Decide whether to mask depending on pixel flipper outputting a NULL pixel.
160  if (flipTile->isNull(tile_index++))
161  maskbuf[mask_index] &= MASK_BITS_0[mask_bit];
162  else
163  maskbuf[mask_index] |= MASK_BITS_1[mask_bit];
164 
165  // Advance the pixel column and check for end of image rect:
166  ++x;
167  if ((x >= image_size.x) || (x > lr.x))
168  break;
169  }
170  ++mask_index; // advance the mask buffer index 1 after processing 8 tile samples
171  start_bit = 0;
172  }
173  else
174  {
175  ++x;
176 
177  ++tile_index;
178  }
179  }
180  } // Finished looping over all pixels in input tile
181 
182  return;
183 }
ossim_uint32 x
vector< ossimIpt > m_bufferSizes
ossim_uint32 y
ossim_uint32 m_startingResLevel
bool valid() const
Definition: ossimRefPtr.h:75
void setImage(ossimRefPtr< ossimImageData > image)
vector< ossim_uint8 * > m_buffers
virtual void initialize()
Initializes the state of the object from theInputConnection.
void initializeFlipper()
Initializes the flipper (used for identifying pixels for masking) to default values.
bool isNull(ossim_uint32 offset) const
ossimRefPtr< ossimMemoryImageSource > m_memoryImage
unsigned int ossim_uint32
virtual ossimIrect getImageRectangle() const
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tile_rect, ossim_uint32 resLevel=0)
ossimRefPtr< ossimPixelFlipper > m_flipper
ossim_int32 y
Definition: ossimIpt.h:142
ossimIpt computeImageSize(ossim_uint32 rlevel, ossimImageData *tile) const
Since overviews may not yet exist when the mask is being written, we must compute the size of the sou...
ossim_int32 x
Definition: ossimIpt.h:141
unsigned char ossim_uint8

◆ initializeFlipper()

void ossimBitMaskWriter::initializeFlipper ( )
protected

Initializes the flipper (used for identifying pixels for masking) to default values.

Definition at line 259 of file ossimBitMaskWriter.cpp.

References ossimConnectableObject::connectMyInputTo(), ossimRefPtr< T >::get(), m_flipper, m_memoryImage, ossimPixelFlipper::REPLACE_ONLY_FULL_TARGETS, ossimPixelFlipper::setReplacementMode(), ossimPixelFlipper::setReplacementValue(), ossimPixelFlipper::setTargetValue(), ossimConnectableObject::theInputObjectList, and ossimRefPtr< T >::valid().

Referenced by connectMyInputTo(), generateMask(), loadState(), setBogusPixel(), and setBogusPixelRange().

260 {
261  if (!m_flipper.valid())
262  {
267  }
268  if (!m_memoryImage)
269  {
272  }
273 
274  // This method gets called when an input connection is made as well as other times, so keep an
275  // eye out for valid input connection:
276  if (theInputObjectList.size() != 0)
277  {
279  }
280 }
bool valid() const
Definition: ossimRefPtr.h:75
void setReplacementMode(ossimPixelFlipper::ReplacementMode mode)
ossimRefPtr< ossimMemoryImageSource > m_memoryImage
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
ossimRefPtr< ossimPixelFlipper > m_flipper
ConnectableObjectList theInputObjectList
Holds a list of input objects.
void setReplacementValue(ossim_float64 replacement_value)
void setTargetValue(ossim_float64 target_value)
Class to scan pixels and flip target dn value to a replacement dn value.

◆ isOpen()

bool ossimBitMaskWriter::isOpen ( ) const
virtual

Implements ossimOutputSource.

Definition at line 49 of file ossimBitMaskWriter.cpp.

References m_buffers.

Referenced by ~ossimBitMaskWriter().

50 {
51  return (m_buffers.size() != 0);
52 }
vector< ossim_uint8 * > m_buffers

◆ loadState()

bool ossimBitMaskWriter::loadState ( const ossimKeywordlist kwl,
const char *  prefix = 0 
)
virtual

Computes and writes the mask file according to the specification in the KWL.

Constructor accepts keywordlist with all info necessary to compute a mask.

Returns TRUE if successful.

The caller will still need to call writeMask().

Reimplemented from ossimOutputSource.

Definition at line 234 of file ossimBitMaskWriter.cpp.

References BM_STARTING_RLEVEL_KW, ossimString::empty(), ossimKeywordlist::find(), initializeFlipper(), ossimPixelFlipper::loadState(), m_flipper, m_startingResLevel, ossimKeywordNames::OUTPUT_FILE_KW, ossimOutputSource::theOutputName, and ossimString::toUInt32().

235 {
236  // static const char* MODULE = "ossimBitMaskWriter::writeMask(kwl)";
237 
239 
240  // Fetch optional output filename:
242 
243  // Initialize the pixel flipper. This filter is used to identify pixels targeted for masking by
244  // remapping them to the null pixel:
245  m_flipper->loadState(kwl, prefix);
246 
247  // Read Starting res level:
248  m_startingResLevel = 0;
249  ossimString kw_value = kwl.find(prefix, BM_STARTING_RLEVEL_KW);
250  if (!kw_value.empty())
251  m_startingResLevel = kw_value.toUInt32();
252 
253  return true;
254 }
static const char * OUTPUT_FILE_KW
static const char * BM_STARTING_RLEVEL_KW
ossim_uint32 m_startingResLevel
const char * find(const char *key) const
ossim_uint32 toUInt32() const
ossimString theOutputName
void initializeFlipper()
Initializes the flipper (used for identifying pixels for masking) to default values.
ossimRefPtr< ossimPixelFlipper > m_flipper
bool empty() const
Definition: ossimString.h:411
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.

◆ open()

bool ossimBitMaskWriter::open ( )
virtual

Allows a generic interface to open a consumer for writing. If you are a display writer then you would probably show the window or init the device context for writing.

Implements ossimOutputSource.

Definition at line 57 of file ossimBitMaskWriter.cpp.

58 {
59  // Nothing to do yet. Eventually want to open the output stream here and write the buffer after
60  // each R-level is completed, so we don't need to keep vector of buffers in memory.
61  return true;
62 }

◆ reset()

void ossimBitMaskWriter::reset ( void  )
protected

Deletes allocated buffers and resets all values to defaults.

Definition at line 67 of file ossimBitMaskWriter.cpp.

References m_buffers, and m_bufferSizes.

Referenced by close().

68 {
69  // Wipe the mask buffers:
70  vector<ossim_uint8 *>::iterator iter = m_buffers.begin();
71  while (iter != m_buffers.end())
72  {
73  delete[](*iter);
74  iter++;
75  }
76  m_buffers.clear();
77  m_bufferSizes.clear();
78 }
vector< ossimIpt > m_bufferSizes
vector< ossim_uint8 * > m_buffers

◆ setBogusPixel()

void ossimBitMaskWriter::setBogusPixel ( double  pixel_value)

Sets the NULL pixel value to consider when computing mask:

Definition at line 83 of file ossimBitMaskWriter.cpp.

References initializeFlipper(), m_flipper, ossimPixelFlipper::setTargetValue(), and ossimRefPtr< T >::valid().

84 {
85  if (!m_flipper.valid())
87 
88  m_flipper->setTargetValue(pixel_value);
89 }
bool valid() const
Definition: ossimRefPtr.h:75
void initializeFlipper()
Initializes the flipper (used for identifying pixels for masking) to default values.
ossimRefPtr< ossimPixelFlipper > m_flipper
void setTargetValue(ossim_float64 target_value)

◆ setBogusPixelRange()

void ossimBitMaskWriter::setBogusPixelRange ( double  min,
double  max 
)

Sets the range of pixels (inclusive) to be regarded as NULL pixels when computing mask.

Definition at line 94 of file ossimBitMaskWriter.cpp.

References initializeFlipper(), m_flipper, max, min, ossimPixelFlipper::setTargetRange(), and ossimRefPtr< T >::valid().

95 {
96  if (!m_flipper.valid())
98 
100 }
bool valid() const
Definition: ossimRefPtr.h:75
void initializeFlipper()
Initializes the flipper (used for identifying pixels for masking) to default values.
ossimRefPtr< ossimPixelFlipper > m_flipper
void setTargetRange(ossim_float64 target_min, ossim_float64 target_max)
Instead of a single value for a target, this method allows for specifying a range of values to flip t...
#define max(a, b)
Definition: auxiliary.h:76
#define min(a, b)
Definition: auxiliary.h:75

◆ setStartingResLevel()

void ossimBitMaskWriter::setStartingResLevel ( ossim_uint32  res_level)
inline

Sets the starting resolution level for the mask.

Definition at line 87 of file ossimBitMaskWriter.h.

87 { m_startingResLevel = res_level; }
ossim_uint32 m_startingResLevel

Friends And Related Function Documentation

◆ ossimBitMaskTileSource

friend class ossimBitMaskTileSource
friend

Definition at line 114 of file ossimBitMaskWriter.h.

Member Data Documentation

◆ BM_STARTING_RLEVEL_KW

const char * ossimBitMaskWriter::BM_STARTING_RLEVEL_KW = "starting_rlevel"
static

Definition at line 72 of file ossimBitMaskWriter.h.

Referenced by loadState().

◆ m_buffers

vector<ossim_uint8 *> ossimBitMaskWriter::m_buffers
protected

◆ m_bufferSizes

vector<ossimIpt> ossimBitMaskWriter::m_bufferSizes
protected

◆ m_flipper

ossimRefPtr<ossimPixelFlipper> ossimBitMaskWriter::m_flipper
protected

◆ m_imageSize

ossimIpt ossimBitMaskWriter::m_imageSize
protected

Size of full res source image.

Definition at line 131 of file ossimBitMaskWriter.h.

Referenced by computeImageSize(), and connectMyInputTo().

◆ m_memoryImage

ossimRefPtr<ossimMemoryImageSource> ossimBitMaskWriter::m_memoryImage
protected

Definition at line 127 of file ossimBitMaskWriter.h.

Referenced by generateMask(), and initializeFlipper().

◆ m_startingResLevel

ossim_uint32 ossimBitMaskWriter::m_startingResLevel
protected

◆ MASK_FILE_MAGIC_NUMBER

const char * ossimBitMaskWriter::MASK_FILE_MAGIC_NUMBER = "OSSIM_BIT_MASK"
static

Definition at line 73 of file ossimBitMaskWriter.h.

Referenced by close(), and ossimBitMaskTileSource::open().


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