OpenWalnut  1.3.1
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 "../../common/WHierarchicalTreeFibers.h"
35 
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 protected:
73 private:
74  /**
75  * helper function the starts the layout process from the input data in the constructor
76  */
77  void create();
78 
79  /**
80  * recursive funtion that lays out the tree from top to bottom,
81  * height of the joins is determined by the level of the cluster
82  * \param cluster the current cluster to work on
83  * \param left left border of the current subcluster
84  * \param right right border of the current subcluster
85  */
86  void layoutLevel( size_t cluster, float left, float right );
87 
88  /**
89  * recursive funtion that lays out the tree from top to bottom,
90  * height of the joins is determined by the similarity value of the cluster
91  * \param cluster the current cluster to work on
92  * \param left left border of the current subcluster
93  * \param right right border of the current subcluster
94  */
95  void layoutValue( size_t cluster, float left, float right );
96 
97 
98  /**
99  * recurse function that follows the layout to determine the cluster from pixel coordinates, used when the level of the cluster
100  * is used for height
101  *
102  * \param cluster cluster to check against coordinates
103  * \param left left boundary of cluster
104  * \param right right boundary of cluster
105  */
106  void getClickClusterRecursive( size_t cluster, float left, float right );
107 
108  /**
109  * recurse function that follows the layout to determine the cluster from pixel coordinates, used when the customData value is used
110  * for height
111  *
112  * \param cluster cluster to check against coordinates
113  * \param left left boundary of cluster
114  * \param right right boundary of cluster
115  */
116  void getClickClusterRecursive2( size_t cluster, float left, float right );
117 
118 
119  WHierarchicalTree* m_tree; //!< the tree to work on
120 
121  size_t m_rootCluster; //!< top cluster to draw the tree from
122 
123  osg::ref_ptr<osg::Vec4Array> m_colors; //!< color array
124 
125  osg::Vec3Array* m_vertexArray; //!< vertex array
126 
127  osg::DrawElementsUInt* m_lineArray; //!< line array
128 
129  size_t m_minClusterSize; //!< minimum cluster size to be considered while laying out the dendrogram
130 
131  float m_xSize; //!< x size in pixel of the final dendrogram
132  float m_ySize; //!< y size in pixel of the final dendrogram
133  float m_xOff; //!< x offset
134  float m_yOff; //!< y offset
135  float m_xMult; //!< helper variable for the recursive function
136  float m_yMult; //!< helper variable for the recursive function
137 
138  int m_xClicked; //!< stores the click position for use int he recursive function
139  int m_yClicked; //!< stores the click position for use int he recursive function
140 
141  bool m_useLevel; //!< flag indicating if the level or the value of a cluster will be used for the height of join
142 
143  size_t m_clickedCluster; //!< the clicked cluster
144 };
145 
146 #endif // WDENDROGRAMGEODE_H