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

A derived class based on MappedSPnode < cxsc::interval >. More...

+ Inheritance diagram for subpavings::IntervalMappedSPnode:
+ Collaboration diagram for subpavings::IntervalMappedSPnode:

List of all members.

Classes

class  Measurer
 Inner interface for types measuring nodes. More...

Public Types

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

Public Member Functions

virtual ~IntervalMappedSPnode ()
 Destructor.
 IntervalMappedSPnode ()
 No-argument constructor.
 IntervalMappedSPnode (const ivector &v)
 initialised constructor.
 IntervalMappedSPnode (const LabBox &lb)
 Initialised constructor.
 IntervalMappedSPnode (const ivector &v, const cxsc::interval &range)
 Initialised constructor.
 IntervalMappedSPnode (const LabBox &lb, const cxsc::interval &range)
 Initialised constructor.
 IntervalMappedSPnode (const SPnode &other)
 Copy constructor.
 IntervalMappedSPnode (const IntervalMappedSPnode &other)
 Copy constructor.
 IntervalMappedSPnode (const MappedSPnode< cxsc::interval > &other)
 Copy constructor.
IntervalMappedSPnodeoperator= (IntervalMappedSPnode rhs)
 Copy assignment operator.
IntervalMappedSPnodeoperator= (MappedSPnode< cxsc::interval > rhs)
 Copy assignment operator.
void replaceMe (IntervalMappedSPnode newNode)
 Replace the properties of this node and its descendents with the properties of another node and its descendents.
void replaceMe (MappedSPnode< cxsc::interval > newNode)
 Replace the properties of this node and its descendents with the properties of another node and its descendents.
IntervalMappedSPnodegetParent () const
 Accessor for the parent of a node.
IntervalMappedSPnodegetLeftChild () const
 Accessor for the left child of a node.
IntervalMappedSPnodegetRightChild () const
 Accessor for the right child of a node.
bool operator< (const IntervalMappedSPnode &rhs) const
 Less-than operator.
IntervalMappedSPnodeoperator+= (const real &val)
 Self-scalar addition operator with real scalar.
const IntervalMappedSPnode operator+ (const real &val) const
 Scalar addition operator with real scalar.
IntervalMappedSPnodeoperator-= (const real &val)
 Self-scalar subraction operator with real scalar.
const IntervalMappedSPnode operator- (const real &val) const
 Scalar subtraction operator with real scalar.
IntervalMappedSPnodeoperator*= (const real &val)
 Self-scalar multiplication operator with real scalar.
const IntervalMappedSPnode operator* (const real &val) const
 Scalar multiplication operator with real scalar.
IntervalMappedSPnodeoperator/= (const real &val)
 Self-scalar division operator with real scalar.
const IntervalMappedSPnode operator/ (const real &val) const
 Scalar division operator with real scalar.
const IntervalMappedSPnodefindContainingNode (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 void hullPropagation ()
 Propagate the interval hull of the children upwards.
cxsc::real getRangeDiameter () const
 Get the diameter of interval range of this.
virtual cxsc::real getIntervalAreaOnBox () const
 Get the "area" of the interval range over the box of this.
virtual cxsc::real getTotalLeafIntervalAreaOnBox () const
 Get the total "area" of the interval ranges over the boxes for the leaves of this.
cxsc::real getIntervalAreaDiffToChildren () const
 Get the difference between the "area" of the interval range over the box of this and the sum of the "areas" of the interval ranges of the children over their boxes.
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 swapIMSP (IntervalMappedSPnode &spn)
virtual std::ostream & nodePrint (std::ostream &os) const
 Print the details of a specific node in a subpaving.

Detailed Description

A derived class based on MappedSPnode < cxsc::interval >.

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 interval value mapped to it.

A IntervalMappedSPnode provides the functionality of the MappedSPnode <interval> and extended functionality appropriate for interval mapped nodes.

Todo:
Could add the the arithmetic operations provided for intervals
  • see cxsc imath files.

Member Typedef Documentation

@ name Definitions for collection types for IntervalMappedSPnodes


Constructor & Destructor Documentation

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

initialised constructor.

Initialised with a box. Range is set to cxsc::interval(0.0,0.0).

  :   MappedSPnode<cxsc::interval>(v, cxsc::interval(0.0,0.0))
   {}

Initialised constructor.

Initialised with a labeled box. Range is set to cxsc::interval(0.0,0.0).

  :   MappedSPnode<cxsc::interval>(lb, cxsc::interval(0.0,0.0))
   {}
IntervalMappedSPnode::IntervalMappedSPnode ( const ivector &  v,
const cxsc::interval &  range 
)

Initialised constructor.

Initialised with a box and an interval value for the rangeCollection.

IntervalMappedSPnode::IntervalMappedSPnode ( const LabBox lb,
const cxsc::interval &  range 
)

Initialised constructor.

Initialised with a labeled box and an interval value for the rangeCollection.

IntervalMappedSPnode::IntervalMappedSPnode ( const SPnode other) [explicit]

Copy constructor.

Range is set to csxc::interval(0.0, 0.0).

Copies from given SPnode downwards.

{
  
  if (!other.isEmpty()) {
    theBox = new ivector( other.getBox() );
  }
  nodeName = other.getNodeName();
  range = cxsc::interval(0.0,0.0);
  
  //recursion on the children
  if (other.hasLCwithBox()) {
    nodeAddLeft(new IntervalMappedSPnode(
      *(other.getLeftChild())));
  }
  else leftChild=NULL;

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

}

Copy constructor.

Copies from given IntervalMappedSPnode 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 IntervalMappedSPnode(
      *(other.getLeftChild())));
  }
  else leftChild=NULL;

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

}
IntervalMappedSPnode::IntervalMappedSPnode ( const MappedSPnode< cxsc::interval > &  other)

Copy constructor.

Copies from a given MappedSPnode<cxsc::interval> 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 IntervalMappedSPnode(
      *(other.getLeftChild())));
  }
  else leftChild=NULL;

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

Member Function Documentation

const IntervalMappedSPnode * IntervalMappedSPnode::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 IntervalMappedSPnode* 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;
}
IntervalMappedSPnode::ConstPtrs & IntervalMappedSPnode::getConstLeaves ( IntervalMappedSPnode::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;
}
IntervalMappedSPnode::ConstPtrs & IntervalMappedSPnode::getConstSubLeaves ( IntervalMappedSPnode::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;
  
  
}

Get the difference between the "area" of the interval range over the box of this and the sum of the "areas" of the interval ranges of the children over their boxes.

Returns:
The volume of box represented by this multiplied by diameter of interval range of this, less sum of the same for the children (returns interval area of this if no children.)
{
  cxsc::real retr(0.0);
  
  if (isLeaf() ) {
    retr = getIntervalAreaOnBox();
  }
  else {
    retr = nodeRealVolume() * (getRangeDiameter() 
        - 0.5*(getLeftChild()->getRangeDiameter() 
            + getRightChild()->getRangeDiameter() ) );
  }
  
  return retr;
}
cxsc::real IntervalMappedSPnode::getIntervalAreaOnBox ( ) const [virtual]

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

The "area" returned is calculated as the volume of the box represented by this multiplied by the diameter of the interval range of this (which can also be seen as the volume of the box represented by this with the interval range of this added as an extra dimension).

Returns:
volume of box represented by this multiplied by diameter of interval range of this.
{
  cxsc::real retr(0.0);
  
  if (!cxsc::IsEmpty(range)) {
    retr = getRangeDiameter() * nodeRealVolume();
  }
  return retr;
}

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< cxsc::interval >.

Accessor for the parent of a node.

Returns a copy of the pointer to parent node.

Reimplemented from subpavings::MappedSPnode< cxsc::interval >.

Accessor for the right child of a node.

Returns a copy of the pointer to rightChild node.

Reimplemented from subpavings::MappedSPnode< cxsc::interval >.

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 interval 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 represented multiplied by the diameter of the interval range of the node (which can also be seen as the volume of the box represented with the interval range of the node added as an extra dimension).

Returns:
total over all leaf descendents of this of (volume of box represented multiplied by diameter of interval range).

Propagate the interval hull of the children upwards.

hullPropagates children then recalculates the range for this node as the interval hull of the ranges of the children.

{
  #ifdef MYDEBUGHULL
    std::cout << "In hullPropagation, I am " << nodeName << std::endl;
  #endif 
  // first recursively deal with the children of the children
  if (hasLCwithBox())
    getLeftChild()->hullPropagation();
  if (hasRCwithBox())
    getRightChild()->hullPropagation();

  // now deal with this
  if (hasLCwithBox() && hasRCwithBox()) {
    
    #ifdef MYDEBUGHULL
      std::cout << "Back in hullPropagation for " << nodeName << std::endl;
      std::cout << "my range is " << range << std::endl;
      std::cout << "getLeftChild()->range is " << (getLeftChild()->range) << std::endl;
      std::cout << "getRightChild()->range is " << (getRightChild()->range) << std::endl;
      std::cout << "(getLeftChild()->getRange() | getRightChild()->getRange()) is " << ((getLeftChild()->getRange() | getRightChild()->getRange())) << std::endl;
    
    #endif 
      
    // hull
    range = (getLeftChild()->getRange() | getRightChild()->getRange());

  }
}
void IntervalMappedSPnode::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< cxsc::interval >.

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

  // only do something if this node is a leaf
  if (isLeaf()) {
    
    IntervalMappedSPnode* newLC = NULL;
    IntervalMappedSPnode* 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 IntervalMappedSPnode(lC, range);
      newRC = new IntervalMappedSPnode(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");

      // new children have summary from this
    }
    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< cxsc::interval >.

{
  int maxdiamcomp; // variable to hold first longest dimension
  double temp = ::MaxDiam(getBox(), maxdiamcomp);
  nodeExpand(maxdiamcomp); // complete nodeExpand
}
const IntervalMappedSPnode IntervalMappedSPnode::operator* ( const real &  val) const

Scalar multiplication operator with real scalar.

Note:
that because there are implicit conversions from types integer and double to cxsc::real in the cxsc::library, this operation also provides equivalent functionality for operand val of type integer and double.
Parameters:
valthe value to multiply this by to give the object returned.
Returns:
a mapped paving with the same tree structure as this before the operation with range equal to the range of this before the operation multiplied by cxsc::interval(val).
{
  return this->MappedSPnode<cxsc::interval>::operator*(cxsc::interval(val));;
}
IntervalMappedSPnode & IntervalMappedSPnode::operator*= ( const real &  val)

Self-scalar multiplication operator with real scalar.

Note:
that because there are implicit conversions from types integer and double to cxsc::real in the cxsc::library, this operation also provides equivalent functionality for operand val of type integer and double.
Parameters:
valthe value to multiply this by.
Postcondition:
this has the same tree structure as before the operation with a range equal to the range of this before the operation multiplied by cxsc::interval(val).
{
  MappedSPnode<cxsc::interval>::operator*=(cxsc::interval(val));
  return *this;
}
const IntervalMappedSPnode IntervalMappedSPnode::operator+ ( const real &  val) const

Scalar addition operator with real scalar.

Note:
that because there are implicit conversions from types integer and double to cxsc::real in the cxsc::library, this operation also provides equivalent functionality for operand val of type integer and double.
Parameters:
valthe value to add to this to give the object returned.
Returns:
a mapped paving with the same tree structure as this before the operation with range equal to the range of this before the operation plus cxsc::interval(val).
{
  return this->MappedSPnode<cxsc::interval>::operator+(cxsc::interval(val));;
}
IntervalMappedSPnode & IntervalMappedSPnode::operator+= ( const real &  val)

Self-scalar addition operator with real scalar.

Note:
that because there are implicit conversions from types integer and double to cxsc::real in the cxsc::library, this operation also provides equivalent functionality for operand val of type integer and double.
Parameters:
valthe value to add to this.
Postcondition:
this has the same tree structure as before the operation with a range equal to the range of this before the operation plus cxsc::interval(val).
{
  MappedSPnode<cxsc::interval>::operator+=(cxsc::interval(val));
  return *this;
}
const IntervalMappedSPnode IntervalMappedSPnode::operator- ( const real &  val) const

Scalar subtraction operator with real scalar.

Note:
that because there are implicit conversions from types integer and double to cxsc::real in the cxsc::library, this operation also provides equivalent functionality for operand val of type integer and double.
Parameters:
valthe value to subtract from this to give the object returned.
Returns:
a mapped paving with the same tree structure as this before the operation with range equal to the range of this before the operation minus cxsc::interval(val).
{
  return this->MappedSPnode<cxsc::interval>::operator-(cxsc::interval(val));;
}
IntervalMappedSPnode & IntervalMappedSPnode::operator-= ( const real &  val)

Self-scalar subraction operator with real scalar.

Note:
that because there are implicit conversions from types integer and double to cxsc::real in the cxsc::library, this operation also provides equivalent functionality for operand val of type integer and double.
Parameters:
valthe value to subtract from this.
Postcondition:
this has the same tree structure as before the operation with a range equal to the range of this before the operation minus cxsc::interval(val).
{
  MappedSPnode<cxsc::interval>::operator-=(cxsc::interval(val));
  return *this;
}
const IntervalMappedSPnode IntervalMappedSPnode::operator/ ( const real &  val) const

Scalar division operator with real scalar.

Note:
that because there are implicit conversions from types integer and double to cxsc::real in the cxsc::library, this operation also provides equivalent functionality for operand val of type integer and double.
Parameters:
valthe value to divide this by to give the object returned.
Returns:
a mapped paving with the same tree structure as this before the operation with range equal to the range of this before the operation divided by cxsc::interval(val).
Precondition:
val != 0.0.
{
  return this->MappedSPnode<cxsc::interval>::operator/(cxsc::interval(val));;
}
IntervalMappedSPnode & IntervalMappedSPnode::operator/= ( const real &  val)

Self-scalar division operator with real scalar.

Note:
that because there are implicit conversions from types integer and double to cxsc::real in the cxsc::library, this operation also provides equivalent functionality for operand val of type integer and double.
Parameters:
valthe value to divide this by.
Postcondition:
this has the same tree structure as before the operation with a range equal to the range of this before the operation divided by cxsc::interval(val).
Precondition:
val != 0.0.
{
  MappedSPnode<cxsc::interval>::operator/=(cxsc::interval(val));
  return *this;
}
bool IntervalMappedSPnode::operator< ( const IntervalMappedSPnode rhs) const

Less-than operator.

Returns:
true iff the range of this is < range of rhs.
{
  return (getRange() < rhs.getRange());
}
IntervalMappedSPnode & IntervalMappedSPnode::operator= ( IntervalMappedSPnode  rhs)

Copy assignment operator.

Copies from given IntervalMappedSPnode downwards.

{
  rhs.swapIMSP(*this); // make sure we use our version of swap
  return(*this);
}
IntervalMappedSPnode & IntervalMappedSPnode::operator= ( MappedSPnode< cxsc::interval >  rhs)

Copy assignment operator.

Copies from a given MappedSPnode<cxsc::interval> node downwards.

Reimplemented from subpavings::MappedSPnode< cxsc::interval >.

{
  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.

{
  
  IntervalMappedSPnode* pNode = getParent();
  newNode.swapIMSP(*this);
  
  if (NULL != pNode) {
    
    this->parent = pNode;
  }
}
void IntervalMappedSPnode::replaceMe ( MappedSPnode< cxsc::interval >  newNode)

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< cxsc::interval >.

{
  
  IntervalMappedSPnode* 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