OpenWalnut
1.5.0dev
|
Hirachical binary tree datastructure with spatial layout information called dendrogram. More...
#include <WDendrogram.h>
Public Member Functions | |
virtual const std::string | getName () const |
Gets the name of this prototype. More... | |
virtual const std::string | getDescription () const |
Gets the description for this prototype. More... | |
WDendrogram (size_t n) | |
Constructs a new dendrogram for n many objects. More... | |
WDendrogram () | |
Default constructs an empty dendrogram. More... | |
size_t | merge (size_t i, size_t j, double height) |
Merges two elements (either inner nodes or leafs) given via the indices i and j. More... | |
std::string | toString () const |
Transform this dendrogram into a string, where each leaf or inner node is mapped to a special string. More... | |
const std::vector< size_t > & | getParents () const |
Returns const reference to the internal parents array. More... | |
const std::vector< double > & | getHeights () const |
Const reference to the heights array. More... | |
Public Member Functions inherited from WTransferable | |
WTransferable () | |
Default constructor. More... | |
virtual | ~WTransferable () |
Destructor. More... | |
Public Member Functions inherited from WPrototyped | |
WPrototyped () | |
Default constructor. More... | |
virtual | ~WPrototyped () |
Destructor. More... | |
template<typename T > | |
bool | isA () |
Checks whether the actual prototype has the specified runtime type. More... | |
Static Public Member Functions | |
static std::shared_ptr< WPrototyped > | getPrototype () |
Returns a prototype instantiated with the true type of the deriving class. More... | |
Static Protected Attributes | |
static std::shared_ptr< WPrototyped > | m_prototype = std::shared_ptr< WPrototyped >() |
The prototype as singleton. More... | |
Private Member Functions | |
void | reset (size_t n) |
Resets the whole dendrogram to the number of elements it should be used for. More... | |
void | checkAndThrowExceptionIfUsedUninitialized (std::string caller) const |
Checks if this instance is initialized. More... | |
Private Attributes | |
std::vector< size_t > | m_parents |
Stores the parents of leafs as well as of inner nodes. More... | |
std::vector< double > | m_heights |
Stores only for the inner nodes their heights. More... | |
Friends | |
class | WDendrogramTest |
Access for test class. More... | |
Hirachical binary tree datastructure with spatial layout information called dendrogram.
Please note that there are some limitations of this implementation: First of all there are exactly n-1
many inner nodes, and only inner nodes may have a height. In order to use this class for your objects ensure that the objects are labeled from 0,...,n-1
.
The following description is taken from: http://en.wikipedia.org/wiki/Dendrogram A dendrogram (from Greek dendron "tree", -gramma "drawing") is a tree diagram frequently used to illustrate the arrangement of clusters produced by hierarchical clustering. Please note that each level has its height.
| ,------'--. --- 4th level | | |```````| | --- 3rd level | | | | | ...'... --- 2nd level | | | | |''''''''| | | | --- 1st level | | | | | | | | | | o o o o o --- 0 level
Definition at line 62 of file WDendrogram.h.
|
explicit |
Constructs a new dendrogram for n
many objects.
n | The number of leafs. |
Definition at line 60 of file WDendrogram.cpp.
References reset().
WDendrogram::WDendrogram | ( | ) |
Default constructs an empty dendrogram.
Definition at line 53 of file WDendrogram.cpp.
Referenced by getPrototype().
|
private |
Checks if this instance is initialized.
If not, it throws an exception.
WOutOfBounds |
caller | A string identifying the class member function. |
Definition at line 74 of file WDendrogram.cpp.
References m_parents.
Referenced by merge(), and toString().
|
inlinevirtual |
Gets the description for this prototype.
Implements WPrototyped.
Definition at line 169 of file WDendrogram.h.
const std::vector< double > & WDendrogram::getHeights | ( | ) | const |
Const reference to the heights array.
Definition at line 171 of file WDendrogram.cpp.
References m_heights.
Referenced by WTreeNode::WTreeNode().
|
inlinevirtual |
Gets the name of this prototype.
Implements WPrototyped.
Definition at line 164 of file WDendrogram.h.
const std::vector< size_t > & WDendrogram::getParents | ( | ) | const |
Returns const reference to the internal parents array.
Definition at line 166 of file WDendrogram.cpp.
References m_parents.
Referenced by WTreeNode::WTreeNode().
|
static |
Returns a prototype instantiated with the true type of the deriving class.
Definition at line 44 of file WDendrogram.cpp.
References m_prototype, and WDendrogram().
size_t WDendrogram::merge | ( | size_t | i, |
size_t | j, | ||
double | height | ||
) |
Merges two elements (either inner nodes or leafs) given via the indices i and j.
i | The index referring either to an inner node or to a leaf. |
j | The other index of a leaf or inner node. |
height | The height at which those to elements join. |
Definition at line 82 of file WDendrogram.cpp.
References checkAndThrowExceptionIfUsedUninitialized(), m_heights, and m_parents.
Referenced by WDendrogramTest::testStringCreation().
|
private |
Resets the whole dendrogram to the number of elements it should be used for.
n | number of leafs |
Definition at line 66 of file WDendrogram.cpp.
References m_heights, and m_parents.
Referenced by WDendrogram().
std::string WDendrogram::toString | ( | ) | const |
Transform this dendrogram into a string, where each leaf or inner node is mapped to a special string.
"(level, (all leafs incorporated by this node), (the two direct predecessors), height if available )"
Definition at line 101 of file WDendrogram.cpp.
References checkAndThrowExceptionIfUsedUninitialized(), m_heights, and m_parents.
Referenced by WDendrogramTest::testStringCreation().
|
friend |
Access for test class.
Definition at line 64 of file WDendrogram.h.
|
private |
Stores only for the inner nodes their heights.
Definition at line 161 of file WDendrogram.h.
Referenced by getHeights(), merge(), reset(), and toString().
|
private |
Stores the parents of leafs as well as of inner nodes.
The first half of the arrary corresponds to the parents of the leafs and the second of the inner nodes. The last inner node is the top of the dendrogram.
Definition at line 156 of file WDendrogram.h.
Referenced by checkAndThrowExceptionIfUsedUninitialized(), getParents(), merge(), reset(), and toString().
|
staticprotected |
The prototype as singleton.
Definition at line 134 of file WDendrogram.h.
Referenced by getPrototype().