OpenWalnut  1.5.0dev
WDendrogramGeode.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WDENDROGRAMGEODE_H
26 #define WDENDROGRAMGEODE_H
27 
28 #include <osg/Geode>
29 #include <osg/Vec3>
30 #include <osg/Geometry>
31 #include <osg/MatrixTransform>
32 #include <osg/PositionAttitudeTransform>
33 
34 #include "core/common/math/linearAlgebra/WVectorFixed.h"
35 #include "core/common/WHierarchicalTreeFibers.h"
36 
37 /**
38  * Class creates a dendrogram from a hierarchical clustering
39  */
40 class WDendrogramGeode : public osg::Geode // NOLINT
41 {
42 public:
43  /**
44  * constructor
45  *
46  * \param tree reference to the tree object to work on
47  * \param cluster root cluster for the dendrogram
48  * \param useLevel if true the height of a node is determined by the level of the cluster
49  * \param minClusterSize minimum for cluster to be drawn, when i the whole tree is drawn
50  * \param xSize number of pixel to scale the tree on along the x axis
51  * \param ySize number of pixel to scale the tree on along the y axis
52  * \param xOffset translation alogn the x axis
53  * \param yOffset translation alogn the y axis
54  *
55  */
56  WDendrogramGeode( WHierarchicalTree* tree, size_t cluster, bool useLevel = true, size_t minClusterSize = 1, float xSize = 1000.f,
57  float ySize = 500.f, float xOffset = 0.0f, float yOffset = 0.0f );
58 
59  /**
60  * destructor
61  */
63 
64  /**
65  * calculate which cluster was clicked from given pixel coordinates
66  * \param xClick the x coordinate
67  * \param yClick the y coordinate
68  * \return the cluster id, will return the root cluster if no cluster can be determinded
69  */
70  size_t getClickedCluster( int xClick, int yClick );
71 
72  /**
73  * calculates if the given position is within the view area of the dendrogram
74  * \param pos the position within the view
75  * \return true if pos is within the dendrogram area, otherwise false
76  */
77  bool inDendrogramArea( const WVector2f& pos ) const;
78 
79 protected:
80 private:
81  /**
82  * helper function the starts the layout process from the input data in the constructor
83  */
84  void create();
85 
86  /**
87  * recursive funtion that lays out the tree from top to bottom,
88  * height of the joins is determined by the level of the cluster
89  * \param cluster the current cluster to work on
90  * \param left left border of the current subcluster
91  * \param right right border of the current subcluster
92  */
93  void layoutLevel( size_t cluster, float left, float right );
94 
95  /**
96  * recursive funtion that lays out the tree from top to bottom,
97  * height of the joins is determined by the similarity value of the cluster
98  * \param cluster the current cluster to work on
99  * \param left left border of the current subcluster
100  * \param right right border of the current subcluster
101  */
102  void layoutValue( size_t cluster, float left, float right );
103 
104 
105  /**
106  * recurse function that follows the layout to determine the cluster from pixel coordinates, used when the level of the cluster
107  * is used for height
108  *
109  * \param cluster cluster to check against coordinates
110  * \param left left boundary of cluster
111  * \param right right boundary of cluster
112  */
113  void getClickClusterRecursive( size_t cluster, float left, float right );
114 
115  /**
116  * recurse function that follows the layout to determine the cluster from pixel coordinates, used when the customData value is used
117  * for height
118  *
119  * \param cluster cluster to check against coordinates
120  * \param left left boundary of cluster
121  * \param right right boundary of cluster
122  */
123  void getClickClusterRecursive2( size_t cluster, float left, float right );
124 
125 
126  WHierarchicalTree* m_tree; //!< the tree to work on
127 
128  size_t m_rootCluster; //!< top cluster to draw the tree from
129 
130  osg::ref_ptr<osg::Vec4Array> m_colors; //!< color array
131 
132  osg::Vec3Array* m_vertexArray; //!< vertex array
133 
134  osg::DrawElementsUInt* m_lineArray; //!< line array
135 
136  size_t m_minClusterSize; //!< minimum cluster size to be considered while laying out the dendrogram
137 
138  float m_xSize; //!< x size in pixel of the final dendrogram
139  float m_ySize; //!< y size in pixel of the final dendrogram
140  float m_xOff; //!< x offset
141  float m_yOff; //!< y offset
142  float m_xMult; //!< helper variable for the recursive function
143  float m_yMult; //!< helper variable for the recursive function
144 
145  int m_xClicked; //!< stores the click position for use int he recursive function
146  int m_yClicked; //!< stores the click position for use int he recursive function
147 
148  bool m_useLevel; //!< flag indicating if the level or the value of a cluster will be used for the height of join
149 
150  size_t m_clickedCluster; //!< the clicked cluster
151 };
152 
153 #endif // WDENDROGRAMGEODE_H
Class creates a dendrogram from a hierarchical clustering.
bool m_useLevel
flag indicating if the level or the value of a cluster will be used for the height of join
void getClickClusterRecursive(size_t cluster, float left, float right)
recurse function that follows the layout to determine the cluster from pixel coordinates,...
size_t getClickedCluster(int xClick, int yClick)
calculate which cluster was clicked from given pixel coordinates
int m_xClicked
stores the click position for use int he recursive function
int m_yClicked
stores the click position for use int he recursive function
size_t m_rootCluster
top cluster to draw the tree from
float m_xMult
helper variable for the recursive function
osg::ref_ptr< osg::Vec4Array > m_colors
color array
WHierarchicalTree * m_tree
the tree to work on
float m_ySize
y size in pixel of the final dendrogram
void layoutValue(size_t cluster, float left, float right)
recursive funtion that lays out the tree from top to bottom, height of the joins is determined by the...
bool inDendrogramArea(const WVector2f &pos) const
calculates if the given position is within the view area of the dendrogram
~WDendrogramGeode()
destructor
float m_xOff
x offset
WDendrogramGeode(WHierarchicalTree *tree, size_t cluster, bool useLevel=true, size_t minClusterSize=1, float xSize=1000.f, float ySize=500.f, float xOffset=0.0f, float yOffset=0.0f)
constructor
osg::DrawElementsUInt * m_lineArray
line array
size_t m_minClusterSize
minimum cluster size to be considered while laying out the dendrogram
size_t m_clickedCluster
the clicked cluster
float m_yMult
helper variable for the recursive function
void layoutLevel(size_t cluster, float left, float right)
recursive funtion that lays out the tree from top to bottom, height of the joins is determined by the...
float m_yOff
y offset
osg::Vec3Array * m_vertexArray
vertex array
void create()
helper function the starts the layout process from the input data in the constructor
float m_xSize
x size in pixel of the final dendrogram
void getClickClusterRecursive2(size_t cluster, float left, float right)
recurse function that follows the layout to determine the cluster from pixel coordinates,...
base class for hierarchical tree implementations
A fixed size matrix class.
Definition: WMatrixFixed.h:150