Commit 774b8313 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[ADD] Stub for a dendrogram datastructure

parent 3633c3ea
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "WDendrogram.h"
WDendrogram::WDendrogram( unsigned int numElements )
: m_tree( numElements, Node() )
{
}
WDendrogram::~WDendrogram()
{
}
WDendrogram::Node::Node()
{
parentTreeIdx = 0;
minTreeIdx = 0;
maxTreeIdx = 0;
dataIdx = 0;
height = 0.0;
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WDENDROGRAM_H
#define WDENDROGRAM_H
#include <vector>
/**
* Hirachical binary tree datastructure with spatial layout information. Since
* join points in a dendrogram do normally not intersect a special index is
* needed. Additionally a parameter for each node and leaf, its height, is
* available.
*
* Each leaf and inner node will obtain a new index called TreeIndex, so the
* hirachy will not overlap or intersect. As a leaf already has an index we
* call this index the DataIndex. So a leaf with DataIndex 5 is the fifth data
* element in the dataset of which this dendrogram is used for. Where as a leaf
* with TreeIndex 5 is the fifth leaf from left.
*/
class WDendrogram
{
friend class WDendrogramTest;
public:
/**
* Creates a new Dendrogram with unjoined elements aka leafs.
*
* \param numElements The number of unjoined or initial elements
*
* TODO(math): Unsigned int is used to save memory here, but can't we use
* size_t (8bytes) => ask christian..
*/
explicit WDendrogram( unsigned int numElements );
/**
* Destructs a Dendrogram.
*/
virtual ~WDendrogram();
protected:
/**
* Representing a node inside of the Dendrogram.
*
* \note Be aware of the different kinds of indices used in here. See
* Description of the WDendrogram class for more details on TreeIndices and
* DataIndices.
*/
struct Node
{
/**
* Default constructor for a new node. So all members are an valid
* initial value: zero.
*/
Node();
/**
* The TreeIndex of the parent it belongs to.
*/
unsigned int parentTreeIdx;
/**
* All leafs grouped by this node have an bigger or equal TreeIndex
* then this \e minTreeIdx. In other words: The leftmost leaf of the
* subtree with this node as root has this TreeIndex.
*/
unsigned int minTreeIdx;
/**
* All leafs grouped by this node have an lower or equal TreeIndex then
* this \e maxTreeIdx. In other words: The rightmost leaf of the
* subtree with this node as root has this TreeIndex.
*/
unsigned int maxTreeIdx;
/**
* This is used to have a reference to the data element this node
* represents. For inner nodes clearly none exists, but for leafs this
* is the number inside of the dataset.
*/
unsigned int dataIdx;
/**
* The height of each node. Leafs have an default height of zero.
*/
double height;
};
private:
/**
* Save the whole dendrogram and keep track of the link from leafs to the
* dataset, as well as information of parents and leafs for each node.
*/
std::vector< Node > m_tree;
};
#endif // WDENDROGRAM_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WDENDROGRAM_TEST_H
#define WDENDROGRAM_TEST_H
#include <cxxtest/TestSuite.h>
#include "../WDendrogram.h"
/**
* TestSuite for the WDendrogram class
*/
class WDendrogramTest : public CxxTest::TestSuite
{
public:
/**
* When a new node is created, each member should be equal to zero.
*/
void testNewNodesHaveAlwaysZerosAssignedInitially( void )
{
WDendrogram d( 5 );
for( int i = 0; i < 5; ++i )
{
TS_ASSERT_EQUALS( d.m_tree[i].parentTreeIdx, 0 );
TS_ASSERT_EQUALS( d.m_tree[i].minTreeIdx, 0 );
TS_ASSERT_EQUALS( d.m_tree[i].maxTreeIdx, 0 );
TS_ASSERT_EQUALS( d.m_tree[i].dataIdx, 0 );
TS_ASSERT_EQUALS( d.m_tree[i].height, 0.0 );
}
}
};
#endif // WDENDROGRAM_TEST_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment