MRS  1.0
A C++ Class Library for Statistical Set Processing
subpavings::BooleanValueMappedSPnode Class Reference

A derived class based on MappedSPnode < bool >. More...

+ Inheritance diagram for subpavings::BooleanValueMappedSPnode:
+ Collaboration diagram for subpavings::BooleanValueMappedSPnode:

List of all members.

Public Types

typedef std::vector
< BooleanValueMappedSPnode * > 
Ptrs
typedef Ptrs::iterator PtrsItr
typedef std::vector< const
BooleanValueMappedSPnode * > 
ConstPtrs
typedef ConstPtrs::const_iterator ConstPtrsItr
typedef std::list
< BooleanValueMappedSPnode * > 
ListPtrs
typedef ListPtrs::iterator ListPtrsItr
typedef std::list< const
BooleanValueMappedSPnode * > 
ListConstPtrs
typedef
ListConstPtrs::const_iterator 
ListConstPtrsItr

Public Member Functions

virtual ~BooleanValueMappedSPnode ()
 Destructor.
 BooleanValueMappedSPnode ()
 No-argument constructor.
 BooleanValueMappedSPnode (const ivector &v)
 initialised constructor.
 BooleanValueMappedSPnode (const LabBox &lb)
 Initialised constructor.
 BooleanValueMappedSPnode (const ivector &v, bool range)
 Initialised constructor.
 BooleanValueMappedSPnode (const LabBox &lb, bool range)
 Initialised constructor.
 BooleanValueMappedSPnode (const ivector &v, const BooleanMappedValue &range)
 Initialised constructor.
 BooleanValueMappedSPnode (const LabBox &lb, const BooleanMappedValue &range)
 Initialised constructor.
 BooleanValueMappedSPnode (const SPnode &other)
 Copy constructor.
 BooleanValueMappedSPnode (const BooleanValueMappedSPnode &other)
 Copy constructor.
 BooleanValueMappedSPnode (const MappedSPnode< BooleanMappedValue > &other)
 Copy constructor.
BooleanValueMappedSPnodeoperator= (BooleanValueMappedSPnode rhs)
 Copy assignment operator.
BooleanValueMappedSPnodeoperator= (MappedSPnode< BooleanMappedValue > rhs)
 Copy assignment operator.
void replaceMe (BooleanValueMappedSPnode newNode)
 Replace the properties of this node and its descendents with the properties of another node and its descendents.
void replaceMe (MappedSPnode< BooleanMappedValue > newNode)
 Replace the properties of this node and its descendents with the properties of another node and its descendents.
BooleanValueMappedSPnodegetParent () const
 Accessor for the parent of a node.
BooleanValueMappedSPnodegetLeftChild () const
 Accessor for the left child of a node.
BooleanValueMappedSPnodegetRightChild () const
 Accessor for the right child of a node.
bool getRange () const
 Get the value represented by this, as a boolean.
const BooleanValueMappedSPnodefindContainingNode (const cxsc::rvector &pt, OPERATIONS_ON childInd=ON_PARENT) const
virtual void nodeExpand (int comp)
 Add two sibling child nodes to this provided this is a leaf.
virtual void nodeExpand ()
 Add two sibling child nodes to this provided this is a leaf.
virtual cxsc::real getTrueAreaOnBox () const
 Get the "area" of the true range over the box of this.
virtual cxsc::real getTotalLeafTrueAreaOnBox () const
 Get the total "area" of the true ranges over the boxes for the leaves of this.
PtrsgetLeaves (Ptrs &leaves)
 Return a reference to a container of nodes.
ConstPtrs & getConstLeaves (ConstPtrs &leaves) const
 Return a reference to a container of const nodes.
PtrsgetSubLeaves (Ptrs &subleaves)
 Return a reference to a container of nodes.
ConstPtrs & getConstSubLeaves (ConstPtrs &subleaves) const
 Return a reference to a container of const nodes.
void swapBMSP (BooleanValueMappedSPnode &spn)
virtual std::ostream & nodePrint (std::ostream &os) const
 Print the details of a specific node in a subpaving.
virtual std::ostream & leavesOutputTabsTrue (std::ostream &os) const
 Output all leaf nodes with true values mapped to them.
virtual std::ostream & leavesOutputTabsTrue (std::ostream &os, int prec) const
 Output all leaf nodes with true values mapped to them.

Detailed Description

A derived class based on MappedSPnode < bool >.

The base class MappedSPnode is a node in the representation of a mapped regular subpaving as a binary tree, where the type mapped to the nodes is a real. A node represents a box (interval vector). MappedSPnodes are linked together to form the tree. The initial box of the subpaving is the box represented by the root node of the tree. A box which has been split will be represented as node with one or two children. A subpaving of [x] (union of non-overlapping sub- boxes of [x]) is represented by the leaves (degenerate/ child-less) nodes in the tree. Each node will have a single boolean value mapped to it.

A BooleanValueMappedSPnode provides the functionality of the MappedSPnode <bool> and extended functionality appropriate for boolean mapped nodes.


Member Typedef Documentation

@ name Definitions for collection types for BooleanValueMappedSPnodes


Constructor & Destructor Documentation

BooleanValueMappedSPnode::BooleanValueMappedSPnode ( const ivector &  v) [explicit]

initialised constructor.

Initialised with a box. Range is set to false.

Initialised constructor.

Initialised with a labeled box. Range is set to false.

BooleanValueMappedSPnode::BooleanValueMappedSPnode ( const ivector &  v,
bool  range 
)

Initialised constructor.

Initialised with a box and a boolean value for the range.

Initialised constructor.

Initialised with a labeled box and a boolean value for the range.

BooleanValueMappedSPnode::BooleanValueMappedSPnode ( const ivector &  v,
const BooleanMappedValue range 
)

Initialised constructor.

Initialised with a box and a BooleanMappedValue for the range.

Initialised constructor.

Initialised with a labeled box and a BooleanMappedValue for the range.

Copy constructor.

Range is set to false.

Copies from given SPnode downwards.

{
  
  if (!other.isEmpty()) {
    theBox = new ivector( other.getBox() );
  }
  nodeName = other.getNodeName();
  range = BooleanMappedValue(false);
  
  //recursion on the children
  if (other.hasLCwithBox()) {
    nodeAddLeft(new BooleanValueMappedSPnode(
      *(other.getLeftChild())));
  }
  else leftChild=NULL;

  if (other.hasRCwithBox()) {
    nodeAddRight(new BooleanValueMappedSPnode(
      *(other.getRightChild())));
  }
  else rightChild=NULL;

}

Copy constructor.

Copies from given BooleanValueMappedSPnode downwards.

{
  
  if (other.theBox != NULL) {
    theBox = new ivector( other.getBox() );
  }
  nodeName = other.getNodeName();
  range = other.getRange();
  
  //recursion on the children
  if (other.hasLCwithBox()) {
    nodeAddLeft(new BooleanValueMappedSPnode(
      *(other.getLeftChild())));
  }
  else leftChild=NULL;

  if (other.hasRCwithBox()) {
    nodeAddRight(new BooleanValueMappedSPnode(
      *(other.getRightChild())));
  }
  else rightChild=NULL;

}

Copy constructor.

Copies from a given MappedSPnode<BooleanMappedValue> node downwards.

{
  if (!other.isEmpty()) {
    theBox = new ivector( other.getBox() );
  }
  nodeName = other.getNodeName();
  range = other.getRange();
  
  //recursion on the children
  if (other.hasLCwithBox()) {
    nodeAddLeft(new BooleanValueMappedSPnode(
      *(other.getLeftChild())));
  }
  else leftChild=NULL;

  if (other.hasRCwithBox()) {
    nodeAddRight(new BooleanValueMappedSPnode(
      *(other.getRightChild())));
  }
  else rightChild=NULL;
}

Member Function Documentation

const BooleanValueMappedSPnode * BooleanValueMappedSPnode::findContainingNode ( const cxsc::rvector &  pt,
OPERATIONS_ON  childInd = ON_PARENT 
) const

Get a pointer to the leaf node descendent of this whose box contains the point pt.

Returns:
NULL if no leaf node descendent of this contains pt, otherwise a pointer to the leaf node descendent of this whose box contains the point pt.
{
  if ( isEmpty() ) {
    throw NoBox_Error(
    "IntervalMappedSPnode::findContainingNode(const cxsc::rvector&, OPERATIONS_ON)");
  }
  // start at the top
  const BooleanValueMappedSPnode* retObj = NULL;
  
  if(nodeContains(pt, childInd)) {
    
    if(isLeaf()) {

      // give this node as return value
      retObj = this;

    } // end of isLeaf

    // if not a leaf and contains data
    // recurse on the children if any
    else {

      if(hasRCwithBox()){
        
        retObj =
        (getRightChild())->findContainingNode(
          pt, ON_RIGHT);
        
      }
      // only try left if we did not find on the right
      if(retObj == NULL && hasLCwithBox()) {
        retObj =
        (getLeftChild())->findContainingNode(
          pt, ON_LEFT);
        
      }
    }

  } // end if node contains

  // will return null if does not contain the data
  
  return retObj;
}
BooleanValueMappedSPnode::ConstPtrs & BooleanValueMappedSPnode::getConstLeaves ( BooleanValueMappedSPnode::ConstPtrs &  leaves) const

Return a reference to a container of const nodes.

Contents of container are the leaves descended from this, or this if this is a leaf, left to right order.

{
  //if children, recurse on the children
  if (hasLCwithBox()) {
    getLeftChild()->getConstLeaves(leaves);
  }

  if (hasRCwithBox()) {
    getRightChild()->getConstLeaves(leaves);
  }

  if ( isLeaf() ) { // this is a leaf
    leaves.push_back(this);
  }
  return leaves;
}
BooleanValueMappedSPnode::ConstPtrs & BooleanValueMappedSPnode::getConstSubLeaves ( BooleanValueMappedSPnode::ConstPtrs &  subleaves) const

Return a reference to a container of const nodes.

Contents of container are the sub-leaves descended from this, or this if this is a sub-leaf, left to right order.

A sub-leaf (aka "cherry") is a node with two leaf child nodes.

{
  if (isSubLeaf()) { // this is a subleaf
    subleaves.push_back(this);
  }
  
  //if children, recurse on the children
  else if (!isLeaf()) {
    getLeftChild()->getConstSubLeaves(subleaves);
    getRightChild()->getConstSubLeaves(subleaves);
  }

  return subleaves;
  
  
}

Return a reference to a container of nodes.

Contents of container are the leaves descended from this, or this if this is a leaf, left to right order.

{
  //if children, recurse on the children
  if (hasLCwithBox()) {
    getLeftChild()->getLeaves(leaves);
  }

  if (hasRCwithBox()) {
    getRightChild()->getLeaves(leaves);
  }

  if ( isLeaf() ) { // this is a leaf
    leaves.push_back(this);
  }
  return leaves;
}

Accessor for the left child of a node.

Returns a copy of the pointer to leftChild node.

Reimplemented from subpavings::MappedSPnode< BooleanMappedValue >.

Accessor for the parent of a node.

Returns a copy of the pointer to parent node.

Reimplemented from subpavings::MappedSPnode< BooleanMappedValue >.

Accessor for the right child of a node.

Returns a copy of the pointer to rightChild node.

Reimplemented from subpavings::MappedSPnode< BooleanMappedValue >.

Return a reference to a container of nodes.

Contents of container are the sub-leaves descended from this, or this if this is a sub-leaf, left to right order.

A sub-leaf (aka "cherry") is a node with two leaf child nodes.

{
  if (isSubLeaf()) { // this is a subleaf
    subleaves.push_back(this);
  }
  
  //if children, recurse on the children
  else if (!isLeaf()) {
    getLeftChild()->getSubLeaves(subleaves);
    getRightChild()->getSubLeaves(subleaves);
  }

  return subleaves;
  
  
}

Get the total "area" of the true ranges over the boxes for the leaves of this.

For each leaf descendent of this the "area" returned is calculated as the volume of the box if the range it true, else 0.0.

Returns:
total over all leaf descendents of this of (volume of box represented for all true leaves).
cxsc::real BooleanValueMappedSPnode::getTrueAreaOnBox ( ) const [virtual]

Get the "area" of the true range over the box of this.

The "area" returned is calculated as the volume of the box represented by this if the range is true, 0.0 otherwise.

Returns:
volume of box represented by this if range is true 0.0 otherwise.
{
  cxsc::real retr(0.0);
  
  if (range.getValue()) {
    retr = nodeRealVolume();
  }
  return retr;
}
std::ostream & BooleanValueMappedSPnode::leavesOutputTabsTrue ( std::ostream &  os,
int  prec 
) const [virtual]

Output all leaf nodes with true values mapped to them.

Parameters:
precthe precision for the output
{
  os << cxsc::SaveOpt;
  os << cxsc::Variable << cxsc::SetPrecision(prec+2,prec);

  leavesOutputTabsTrue(os);
  os << cxsc::RestoreOpt;
  
  return os;

}
void BooleanValueMappedSPnode::nodeExpand ( int  comp) [virtual]

Add two sibling child nodes to this provided this is a leaf.

Each new child gets half of the box associated with this, splitting the box in half normal to dimension set by comp.

Reimplemented from subpavings::MappedSPnode< BooleanMappedValue >.

{
  // can only expand if there is a box
  if (NULL == theBox) {
    throw NoBox_Error("BooleanValueMappedSPnode::nodeExpand(int)");
  }

  // only do something if this node is a leaf
  if (isLeaf()) {
    
    BooleanValueMappedSPnode* newLC = NULL;
    BooleanValueMappedSPnode* newRC = NULL;
    
    try {

      // ivectors to become boxes for new children
      ivector lC, rC;
      // Call Lower() and Upper() to put split boxes
      // into lC and rC respectively
      Lower(getBox(), lC, comp);
      Upper(getBox(), rC, comp);

      // make and add the new children
      newLC = new BooleanValueMappedSPnode(lC, range);
      newRC = new BooleanValueMappedSPnode(rC, range);
      
      nodeAddLeft(newLC);
      nodeAddRight(newRC);
      // both children get the same range as this
      
      //name the new children
      getLeftChild()->setNodeName(nodeName + "L");
      getRightChild()->setNodeName(nodeName + "R");

    }
    catch(std::exception& e) {
    // overkill, but try to deal with all eventualities...
      try {
        if (getLeftChild() != NULL) {
          delete (getLeftChild());
          leftChild = NULL;
        }
        
        if (getRightChild() != NULL) {
          delete (getRightChild());
          rightChild = NULL;
        }
        if (newLC != NULL) {
          delete newLC;
          newLC = NULL;
        }
        if (newRC != NULL) {
          delete newRC;
          newRC = NULL;
        }
      }
      catch(std::exception& e) {} //catch and swallow
      
      throw; // rethrow original exception
    }
  }
}

Add two sibling child nodes to this provided this is a leaf.

Each new child gets half of the box associated with this, splitting the box in half normal to the first longest dimension of the box associated with this.

Reimplemented from subpavings::MappedSPnode< BooleanMappedValue >.

{
  int maxdiamcomp; // variable to hold first longest dimension
  double temp = ::MaxDiam(getBox(), maxdiamcomp);
  nodeExpand(maxdiamcomp); // complete nodeExpand
}
BooleanValueMappedSPnode & BooleanValueMappedSPnode::operator= ( BooleanValueMappedSPnode  rhs)

Copy assignment operator.

Copies from given BooleanValueMappedSPnode downwards.

{
  rhs.swapBMSP(*this); // make sure we use our version of swap
  return(*this);
}
BooleanValueMappedSPnode & BooleanValueMappedSPnode::operator= ( MappedSPnode< BooleanMappedValue rhs)

Copy assignment operator.

Copies from a given MappedSPnode<BooleanMappedValue> node downwards.

Reimplemented from subpavings::MappedSPnode< BooleanMappedValue >.

{
  rhs.swapMSPSR(*this); // make sure we use our version of swap
  return(*this);
}

Replace the properties of this node and its descendents with the properties of another node and its descendents.

Copies newNode node downwards into this, but keeps the relationship of this with its parent, ie if this is a node in a tree, the part of the tree rooted at this is made identical to newNode but the relationship to the rest of the tree,through the link between this and its parent, is retained.

{
  
  BooleanValueMappedSPnode* pNode = getParent();
  newNode.swapBMSP(*this);
  
  if (NULL != pNode) {
    
    this->parent = pNode;
  }
}

Replace the properties of this node and its descendents with the properties of another node and its descendents.

Copies newNode node downwards into this, but keeps the relationship of this with its parent, ie if this is a node in a tree, the part of the tree rooted at this is made identical to newNode but the relationship to the rest of the tree,through the link between this and its parent, is retained.

Reimplemented from subpavings::MappedSPnode< BooleanMappedValue >.

{
  
  BooleanValueMappedSPnode* pNode = getParent();
  newNode.swapMSPSR(*this);
  
  if (NULL != pNode) {
    
    this->parent = pNode;
  }
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends