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

RealMappedShapeNodes are nodes in the representation of a non-regular non-rectangular non-axis aligned polygon-paving ("shape") as a binary tree, with each node having a real value mapped to it. More...

List of all members.

Public Types

typedef std::vector
< RealMappedShapeNode * > 
Ptrs
typedef Ptrs::iterator PtrsItr
typedef Ptrs::const_iterator PtrsConstItr
typedef std::vector< const
RealMappedShapeNode * > 
ConstPtrs
typedef ConstPtrs::const_iterator ConstPtrsItr

Public Member Functions

 RealMappedShapeNode (const RealMappedSPnode &rmsp, const std::vector< std::vector< double > > &backtransform, const std::vector< double > &scale, const std::vector< double > &shift)
 Constructor with a transformation matrix.
 RealMappedShapeNode (const RealMappedSPnode &rmsp, const std::vector< double > &scale, const std::vector< double > &shift)
 Constructor with no transformation matrix.
 RealMappedShapeNode (const cxsc::ivector &box, const std::vector< std::vector< double > > &backtransform, const std::vector< double > &scale, const std::vector< double > &shift, cxsc::real r=0.0)
 Constructor with a transformation matrix, box and range.
 RealMappedShapeNode (const cxsc::ivector &box, const std::vector< double > &scale, const std::vector< double > &shift, cxsc::real r=0.0)
 Constructor with a scale, shift, box and range.
 RealMappedShapeNode (const RealMappedShapeNode &other)
 Copy constructor.
virtual ~RealMappedShapeNode ()
 Destructor.
RealMappedShapeNodeoperator= (RealMappedShapeNode rhs)
 Copy assignment operator.
size_t getDimension () const
 Accessor for the dimension of theBox of a node.
std::vector< std::vector< real > > getVertices () const
 Accessor for vertices of the box associated with the node.
real getRange () const
 Accessor for the value mapped to this.
std::string getNodeName () const
 Get the node name.
bool isLeaf () const
 Check if this RealMappedShapeNode is a leaf.
void swap (RealMappedShapeNode &rmsn)
 Swap this and another node.
Accessors for links between the nodes.
Note:
Pointers for parent, leftChild, and rightChild are not reference counted so there could potentially be problems with the use of returned pointers (for instance, being used to delete nodes). These pointers might be better implemented with boost::shared_ptr.
RealMappedShapeNodegetParent () const
 Accessor for the parent of a node.
RealMappedShapeNodegetLeftChild () const
 Accessor for the left child of a node.
RealMappedShapeNodegetRightChild () const
 Accessor for the right child of a node.
Output for for <b>all leaves</b> of a binary tree.

Output intended for a txt file, in numeric form only.

Parameters:
osis the stream to send to
precis the precision used for printing.
std::ostream & leavesOutputTabs (std::ostream &os) const
std::ostream & leavesOutputTabs (std::ostream &os, int prec) const
Output for <b>all nodes</b> in binary tree.

Output for all nodes in binary tree representing a subpaving in tab-delimited form.

Output intended for console output.

std::ostream & nodesAllOutput (std::ostream &os, int level) const
std::ostream & nodesAllOutput (std::ostream &os, int level, int prec) const

Detailed Description

RealMappedShapeNodes are nodes in the representation of a non-regular non-rectangular non-axis aligned polygon-paving ("shape") as a binary tree, with each node having a real value mapped to it.

A RealMappedShapeNode represents a non-regular non-rectangular polygon shape with a real value mapped to it. RealMappedShapeNodes are linked together to form the tree. The initial polygon of the non-regular non-rectangular paving is the "root box" represented by the root node of the tree. A polygon which has been split will be represented as node with one or two children.

RealMappedShapeNodes have limited functionality compared to SPnode types and are intended to be able to display the results of transforming a RealMappedSPnode using transformations such as scaling, rotation and reflection, and also translation of the origin of the axes.


Constructor & Destructor Documentation

RealMappedShapeNode::RealMappedShapeNode ( const RealMappedSPnode rmsp,
const std::vector< std::vector< double > > &  backtransform,
const std::vector< double > &  scale,
const std::vector< double > &  shift 
)

Constructor with a transformation matrix.

This is constructed by applying a volume and angle-preserving back-transformation to the boxes in the paving represented by rmsp, then scaling as specifed in scale, then shifting as specified in shift.

The back-transformation is specified by the matrix represented by backtransform.

The scaling is specifed by the elements of scale. The ith element of scale is the scalar to be applied on the ith dimension of this.

The shifting is specifed by the elements of shift. The ith element of shidft is the shift to be applied on the ith dimension of this.

The tree rooted at this will have as many descendent nodes as rmsp and each node in the tree will have a box that is the result of applying the back-transformation matrix backtransform to the box of the equivalent node in rmsp, scaling it and shifting it, and then giving it a range value equal to the range value of the equivalent node in rmsp divided by the product of the elements in scale (ie adjusting for the change in the volume of the box that results from scaling the shapes in this).

Parameters:
rmspthe RealMappedSPnode to use to provide the tree structure for this and the values to be adjusted for volume scaling to give the values mapped to nodes in this.
backtransformA representation of a volume preserving and angle preserving back-transformation matrix specified in row major order, ie the inner vectors of backtransform are the rows of the back-transformation matrix.
scaleThe scaling to be applied on each dimension. The ith element of scale is the scalar on the ith dimension of this.
shiftThe shiftg to be applied on each dimension. The ith element of shift is the translation on the ith dimension of this.
Precondition:
backtransform should represent a square matrix of dimension d where d is also the dimension of the subpaving represented by rmsp.
backtransform should be a volume-preserving transformation matrix.
scale and shift should both also be of dimension d.
scale should contain only strictly positive values.
    :  verticesPtr(NULL), range(rmsp.getRange()),
    parent(NULL), leftChild(NULL), rightChild(NULL), 
    nodeName(rmsp.getNodeName())
{
  
  if (rmsp.isEmpty()) {
    throw NoBox_Error("RealMappedShapeNode::RealMappedShapeNode(...)");
  }
  try {
    
    try {
      ivector box = rmsp.getBox();
      extractVertices(box, backtransform);
      scaleAndShiftShape(scale, shift);
    }
    catch (std::invalid_argument& ia) {
      throw std::invalid_argument(
        string("RealMappedShapeNode::RealMappedShapeNode(...) :\n")
          + ia.what() );
    }
    
    #ifdef MYDEBUG
      // output the name, range
      
      cout << nodeName << "\t" << range << "\t";

      // followed by vertices all on one line
      for (std::vector < std::vector < real > >::const_iterator 
            it = verticesPtr->begin();
            it < verticesPtr->end(); ++it) {
        
         ostream_iterator< real > out_it (cout,"\t");
         copy ( it->begin(), it->end(), out_it );
      }
      cout << endl;
    #endif
    //recursion on the children
    if (rmsp.getLeftChild()) {
      leftChild=new RealMappedShapeNode(*rmsp.getLeftChild(),
                        backtransform, 
                        scale, shift);
      leftChild->parent = this;
    }
    else leftChild=NULL;

    if (rmsp.getRightChild()) {
      rightChild=new RealMappedShapeNode(*rmsp.getRightChild(),
                        backtransform, 
                        scale, shift);
      rightChild->parent = this;
    }
    else rightChild=NULL;
  }
  catch (exception const& e) {
    constructor_error_handler();
  }
}
RealMappedShapeNode::RealMappedShapeNode ( const RealMappedSPnode rmsp,
const std::vector< double > &  scale,
const std::vector< double > &  shift 
)

Constructor with no transformation matrix.

This is constructed by scaling and shifting the subpaving represented in rmsp.

The scaling is specifed by the elements of scale. The ith element of scale is the scalar to be applied on the ith dimension of this.

The shifting is specifed by the elements of shift. The ith element of shidft is the shift to be applied on the ith dimension of this.

The tree rooted at this will have as many descendent nodes as rmsp and each node in the tree will have a box that is the result of scaling and shifting it the box of the equivalent node in rmsp, and then giving it a range value equal to the range value of the equivalent node in rmsp divided by the product of the elements in scale (ie adjusting for the change in the volume of the box that results from scaling the shapes in this).

Parameters:
rmspthe RealMappedSPnode to use to provide the tree structure for this and the values to be adjusted for volume scaling to give the values mapped to nodes in this.
scaleThe scaling to be applied on each dimension. The ith element of scale is the scalar on the ith dimension of this.
shiftThe shiftg to be applied on each dimension. The ith element of shift is the translation on the ith dimension of this.
Precondition:
scale and shift should both also be of dimension d where d is the dimension of the subpaving represented by rmsp.
scale should contain only strictly positive values.
    :  verticesPtr(NULL), range(rmsp.getRange()),
    parent(NULL), leftChild(NULL), rightChild(NULL), 
    nodeName(rmsp.getNodeName())
{
  
  if (rmsp.isEmpty()) {
    throw NoBox_Error("RealMappedShapeNode::RealMappedShapeNode(...)");
  }
  try {
    
    try {
      ivector box = rmsp.getBox();
      extractVertices(box);
      scaleAndShiftShape(scale, shift);
    }
    catch (std::invalid_argument& ia) {
      throw std::invalid_argument(
        string("RealMappedShapeNode::RealMappedShapeNode(...) :\n")
          + ia.what() );
    }
    
    #ifdef MYDEBUG
      // output the name, range
      
      cout << nodeName << "\t" << range << "\t";

      // followed by vertices all on one line
      for (std::vector < std::vector < real > >::const_iterator 
            it = verticesPtr->begin();
            it < verticesPtr->end(); ++it) {
        
         ostream_iterator< real > out_it (cout,"\t");
         copy ( it->begin(), it->end(), out_it );
      }
      cout << endl;
    #endif
    //recursion on the children
    if (rmsp.getLeftChild()) {
      leftChild=new RealMappedShapeNode(*rmsp.getLeftChild(),
                        scale, shift);
      leftChild->parent = this;
    }
    else leftChild=NULL;

    if (rmsp.getRightChild()) {
      rightChild=new RealMappedShapeNode(*rmsp.getRightChild(),
                        scale, shift);
      rightChild->parent = this;
    }
    else rightChild=NULL;
  }
  catch (exception const& e) {
    constructor_error_handler();
  }
}
subpavings::RealMappedShapeNode::RealMappedShapeNode ( const cxsc::ivector &  box,
const std::vector< std::vector< double > > &  backtransform,
const std::vector< double > &  scale,
const std::vector< double > &  shift,
cxsc::real  r = 0.0 
)

Constructor with a transformation matrix, box and range.

This is constructed by applying a volume and angle-preserving back-transformation to the boxbox, then scaling as specifed in scale, then shifting as specified in shift.

The back-transformation is specified by the matrix represented by backtransform.

The scaling is specifed by the elements of scale. The ith element of scale is the scalar to be applied on the ith dimension of this.

The shifting is specifed by the elements of shift. The ith element of shidft is the shift to be applied on the ith dimension of this.

The tree rooted at this will consist of a single leaf node. That node will have a box that is the result of applying the back-transformation matrix backtransform to the box box, scaling it and shifting it, and then giving it a range value equal to the value of r divided by the product of the elements in scale (ie adjusting for the change in the volume of the box that results from scaling the shapes in this).

Parameters:
boxthe box to use to find the vertices of this after scaling and shifting and back transforming.
backtransformA representation of a volume preserving and angle preserving back-transformation matrix specified in row major order, ie the inner vectors of backtransform are the rows of the back-transformation matrix.
scaleThe scaling to be applied on each dimension. The ith element of scale is the scalar on the ith dimension of this.
shiftThe shift to be applied on each dimension. The ith element of shift is the translation on the ith dimension of this.
rThe value to be used for the range of this after adjusting for changes in scaling.
Precondition:
backtransform should represent a square matrix of dimension d where d is also the dimension of the subpaving represented by rmsp.
backtransform should be a volume-preserving transformation matrix.
scale and shift should both also be of dimension d.
scale should contain only strictly positive values.
subpavings::RealMappedShapeNode::RealMappedShapeNode ( const cxsc::ivector &  box,
const std::vector< double > &  scale,
const std::vector< double > &  shift,
cxsc::real  r = 0.0 
)

Constructor with a scale, shift, box and range.

This is constructed scaling as specifed in scale, then shifting as specified in shift.

The scaling is specifed by the elements of scale. The ith element of scale is the scalar to be applied on the ith dimension of this.

The shifting is specifed by the elements of shift. The ith element of shidft is the shift to be applied on the ith dimension of this.

The tree rooted at this will consist of a single leaf node. That node will have a box that is the result of scaling box it and shifting it, and then giving it a range value equal to the value of r divided by the product of the elements in scale (ie adjusting for the change in the volume of the box that results from scaling the shapes in this).

Parameters:
boxthe box to use to find the vertices of this after scaling and shifting and back transforming.
scaleThe scaling to be applied on each dimension. The ith element of scale is the scalar on the ith dimension of this.
shiftThe shift to be applied on each dimension. The ith element of shift is the translation on the ith dimension of this.
rThe value to be used for the range of this after adjusting for changes in scaling.
Precondition:
scale and shift should both also be of dimension d where d is the dimension of the subpaving represented by rmsp.
scale should contain only strictly positive values.

Member Function Documentation

Accessor for the left child of a node.

Returns a pointer to leftChild node.

{ return leftChild; }

Accessor for the parent of a node.

Returns a pointer to parent node.

{ return parent; }

Accessor for the right child of a node.

Returns a pointer to rightChild node.

{ return rightChild; }

Check if this RealMappedShapeNode is a leaf.

Returns:
true if this has no children, false otherwise.
{return ( (NULL == leftChild) && (NULL == rightChild)); }

Swap this and another node.

Swaps all the data members of this with the other node.

Parameters:
spna reference to the node to swap with
Postcondition:
this is identical,in terms of its data members, to spn before the swap, and spn is identical to this after the swap.
{
  std::swap(verticesPtr, rmsn.verticesPtr); 
  std::swap(range, rmsn.range);
  std::swap(nodeName, rmsn.nodeName);
  std::swap(parent, rmsn.parent);
  // can just swap child pointers
  std::swap(leftChild, rmsn.leftChild);
  std::swap(rightChild, rmsn.rightChild);
  // children have to be repointed to the new swapped parents
  if (leftChild != NULL) leftChild->parent = this;
  if (rightChild != NULL) rightChild->parent = this;
  if (rmsn.leftChild != NULL) rmsn.leftChild->parent = &rmsn;
  if (rmsn.rightChild != NULL) rmsn.rightChild->parent = &rmsn;
  
}

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