Classes | Functions
contrib/mul/mbl/mbl_mask.h File Reference

Class representing a binary mask, and related functions. More...

#include <vcl_algorithm.h>
#include <vcl_vector.h>
#include <vcl_stdexcept.h>
#include <vcl_iterator.h>
#include <vcl_string.h>
#include <vcl_iosfwd.h>
#include <vcl_cstddef.h>
#include <vcl_iostream.h>
#include <vul/vul_sprintf.h>

Go to the source code of this file.

Classes

class  mbl_mask
 Defines a binary mask. More...

Functions

void mbl_masks_from_index_set (const vcl_vector< unsigned > &indices, vcl_vector< mbl_mask > &masks)
 Given a collection of indices, produce a collection of masks that isolate each indexed set.
void mbl_mask_on_mask (const mbl_mask &A, mbl_mask &B)
 Replace 'true' values in B with values taken from A. size of A must match 'true' count in B.
template<typename ForwardIterator >
void mbl_mask_merge_values (const mbl_mask &mask, ForwardIterator first1, ForwardIterator last1, ForwardIterator first2, ForwardIterator last2, ForwardIterator result)
 Merge two input ranges according to a mask ('false' indicates element drawn from range 1, 'true' from range 2).
void mbl_mask_logic (const mbl_mask &A, mbl_mask &B, const vcl_string &operation)
 Apply a general logical operation between two masks.
void mbl_mask_logic_and (const mbl_mask &A, mbl_mask &B)
 Apply an "AND" (rule 0001) logical operation between two masks.
void mbl_mask_logic_or (const mbl_mask &A, mbl_mask &B)
 Apply an "OR" (rule 0111) logical operation between two masks.
void mbl_mask_logic_xor (const mbl_mask &A, mbl_mask &B)
 Apply an "XOR" (rule 0110) logical operation between two masks.
void mbl_mask_logic_nor (const mbl_mask &A, mbl_mask &B)
 Apply a "NOR" (rule 1000) logical operation between two masks.
void mbl_mask_logic_xnor (const mbl_mask &A, mbl_mask &B)
 Apply an "XNOR" (rule 1001) logical operation between two masks.
void mbl_mask_logic_nand (const mbl_mask &A, mbl_mask &B)
 Apply an "NAND" (rule 1110) logical operation between two masks.
template<typename ForwardIterator , typename OutputIterator >
void mbl_apply_mask (const mbl_mask &mask, ForwardIterator first, ForwardIterator last, OutputIterator target)
 Apply a mask to a range of values. Result inserted at 'target'.
template<typename T >
vcl_vector< T > mbl_apply_mask (const mbl_mask &mask, const vcl_vector< T > &values)
 Apply a mask to a vector, returning a new vector.
template<typename T >
void mbl_apply_mask (const mbl_mask &mask, const vcl_vector< T > &src, vcl_vector< T > &dst)
 Apply a mask to a vector, returning a new vector.
template<typename T >
void mbl_replace_using_mask (const mbl_mask &mask, const vcl_vector< T > &src1, const vcl_vector< T > &src2, vcl_vector< T > &dst)
 Use a mask to replace some values in a vector.
template<typename T >
void mbl_apply_mask (const mbl_mask &mask, vcl_vector< T > &values)
 Apply a mask to a vector in-place.
void mbl_save_mask (const mbl_mask &mask, vcl_ostream &stream)
 Save to file.
void mbl_save_mask (const mbl_mask &mask, const char *filename)
 Save to file.
void mbl_save_mask (const mbl_mask &mask, const vcl_string &filename)
 Save to file.
void mbl_load_mask (mbl_mask &mask, vcl_istream &stream)
 Load from file.
void mbl_load_mask (mbl_mask &mask, const char *filename)
 Load from file.
void mbl_load_mask (mbl_mask &mask, const vcl_string &filename)
 Load from file.
void mbl_mask_to_indices (const mbl_mask &mask, vcl_vector< unsigned > &inds)
 Convert a mask to a list of indices.
void mbl_indices_to_mask (const vcl_vector< unsigned > &inds, const unsigned n, mbl_mask &mask)
 Convert a list of indices to a mask.

Detailed Description

Class representing a binary mask, and related functions.

Author:
Barry Skellern

Definition in file mbl_mask.h.


Function Documentation

template<typename ForwardIterator , typename OutputIterator >
void mbl_apply_mask ( const mbl_mask mask,
ForwardIterator  first,
ForwardIterator  last,
OutputIterator  target 
)

Apply a mask to a range of values. Result inserted at 'target'.

Definition at line 79 of file mbl_mask.h.

template<typename T >
vcl_vector<T> mbl_apply_mask ( const mbl_mask mask,
const vcl_vector< T > &  values 
)

Apply a mask to a vector, returning a new vector.

This can be inefficient. See mbl_apply_mask(mask, src, dst) for an alternative.

Definition at line 91 of file mbl_mask.h.

template<typename T >
void mbl_apply_mask ( const mbl_mask mask,
const vcl_vector< T > &  src,
vcl_vector< T > &  dst 
)

Apply a mask to a vector, returning a new vector.

Parameters:
maskThe mask to apply.
srcThe source vector.
Return values:
dstThe destination vector (existing contents will be lost).

Definition at line 103 of file mbl_mask.h.

template<typename T >
void mbl_apply_mask ( const mbl_mask mask,
vcl_vector< T > &  values 
)

Apply a mask to a vector in-place.

Definition at line 157 of file mbl_mask.h.

void mbl_indices_to_mask ( const vcl_vector< unsigned > &  inds,
const unsigned  n,
mbl_mask mask 
)

Convert a list of indices to a mask.

Parameters:
indsList of (zero-based) indices.
nThe length of the output mask.
Return values:
maskOutput mask. mask[i]==true for all i in inds

Definition at line 205 of file mbl_mask.cxx.

void mbl_load_mask ( mbl_mask mask,
vcl_istream &  stream 
)

Load from file.

Definition at line 150 of file mbl_mask.cxx.

void mbl_load_mask ( mbl_mask mask,
const char *  filename 
)

Load from file.

Definition at line 171 of file mbl_mask.cxx.

void mbl_load_mask ( mbl_mask mask,
const vcl_string &  filename 
)

Load from file.

Definition at line 187 of file mbl_mask.cxx.

void mbl_mask_logic ( const mbl_mask A,
mbl_mask B,
const vcl_string &  operation 
)

Apply a general logical operation between two masks.

Definition at line 99 of file mbl_mask.cxx.

void mbl_mask_logic_and ( const mbl_mask A,
mbl_mask B 
)

Apply an "AND" (rule 0001) logical operation between two masks.

Definition at line 62 of file mbl_mask.cxx.

void mbl_mask_logic_nand ( const mbl_mask A,
mbl_mask B 
)

Apply an "NAND" (rule 1110) logical operation between two masks.

Definition at line 92 of file mbl_mask.cxx.

void mbl_mask_logic_nor ( const mbl_mask A,
mbl_mask B 
)

Apply a "NOR" (rule 1000) logical operation between two masks.

Definition at line 80 of file mbl_mask.cxx.

void mbl_mask_logic_or ( const mbl_mask A,
mbl_mask B 
)

Apply an "OR" (rule 0111) logical operation between two masks.

Definition at line 68 of file mbl_mask.cxx.

void mbl_mask_logic_xnor ( const mbl_mask A,
mbl_mask B 
)

Apply an "XNOR" (rule 1001) logical operation between two masks.

Definition at line 86 of file mbl_mask.cxx.

void mbl_mask_logic_xor ( const mbl_mask A,
mbl_mask B 
)

Apply an "XOR" (rule 0110) logical operation between two masks.

Definition at line 74 of file mbl_mask.cxx.

template<typename ForwardIterator >
void mbl_mask_merge_values ( const mbl_mask mask,
ForwardIterator  first1,
ForwardIterator  last1,
ForwardIterator  first2,
ForwardIterator  last2,
ForwardIterator  result 
)

Merge two input ranges according to a mask ('false' indicates element drawn from range 1, 'true' from range 2).

Definition at line 44 of file mbl_mask.h.

void mbl_mask_on_mask ( const mbl_mask A,
mbl_mask B 
)

Replace 'true' values in B with values taken from A. size of A must match 'true' count in B.

Definition at line 48 of file mbl_mask.cxx.

void mbl_mask_to_indices ( const mbl_mask mask,
vcl_vector< unsigned > &  inds 
)

Convert a mask to a list of indices.

Parameters:
maskInput mask.
Return values:
indsList of (zero-based) indices i where mask[i]==true.

Definition at line 194 of file mbl_mask.cxx.

void mbl_masks_from_index_set ( const vcl_vector< unsigned > &  indices,
vcl_vector< mbl_mask > &  masks 
)

Given a collection of indices, produce a collection of masks that isolate each indexed set.

The input index set does not need to be zero based or continuous The output vector of masks is sorted by corresponding index for example: (1,4,2,1,2) will make three masks: (1,0,0,1,0), (0,0,1,0,1) and (0,1,0,0,0) which correspond to the index sets 1,2,4

The input index set does not need to be zero based or continuous The output vector of masks is sorted such that for example: (1,4,2,1,2) will make three masks: (1,0,0,1,0), (0,0,1,0,1) and (0,1,0,0,0) which correspond to the sorted index sets 1,2,4

Definition at line 23 of file mbl_mask.cxx.

template<typename T >
void mbl_replace_using_mask ( const mbl_mask mask,
const vcl_vector< T > &  src1,
const vcl_vector< T > &  src2,
vcl_vector< T > &  dst 
)

Use a mask to replace some values in a vector.

Parameters:
maskThe mask to apply.
src1The source vector to be updated.
src2The source vector to be updated with.
Return values:
dstThe destination vector (existing contents will be lost).

Definition at line 128 of file mbl_mask.h.

void mbl_save_mask ( const mbl_mask mask,
vcl_ostream &  stream 
)

Save to file.

Definition at line 123 of file mbl_mask.cxx.

void mbl_save_mask ( const mbl_mask mask,
const char *  filename 
)

Save to file.

Definition at line 132 of file mbl_mask.cxx.

void mbl_save_mask ( const mbl_mask mask,
const vcl_string &  filename 
)

Save to file.

Definition at line 141 of file mbl_mask.cxx.