OpenWalnut  1.5.0dev
WNonBinDendroGeode.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 //---------------------------------------------------------------------------
26 //
27 // Project: hClustering
28 //
29 // Whole-Brain Connectivity-Based Hierarchical Parcellation Project
30 // David Moreno-Dominguez
31 // d.mor.dom@gmail.com
32 // moreno@cbs.mpg.de
33 // www.cbs.mpg.de/~moreno//
34 // This file is also part of OpenWalnut ( http://www.openwalnut.org ).
35 //
36 // hClustering is free software: you can redistribute it and/or modify
37 // it under the terms of the GNU Lesser General Public License as published by
38 // the Free Software Foundation, either version 3 of the License, or
39 // (at your option) any later version.
40 // http://creativecommons.org/licenses/by-nc/3.0
41 //
42 // hClustering is distributed in the hope that it will be useful,
43 // but WITHOUT ANY WARRANTY; without even the implied warranty of
44 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 // GNU Lesser General Public License for more details.
46 //
47 //---------------------------------------------------------------------------
48 
49 #ifndef WNONBINDENDROGEODE_H
50 #define WNONBINDENDROGEODE_H
51 
52 #include <vector>
53 
54 #include <osg/Geode>
55 #include <osg/Vec3>
56 #include <osg/Geometry>
57 #include <osg/MatrixTransform>
58 #include <osg/PositionAttitudeTransform>
59 
60 #include "core/common/WColor.h"
61 #include "WHtree.h"
62 
63 /**
64  * Class creates a dendrogram from a hierarchical clustering, and allows to click and select specific nodes
65  */
66 class WNonBinDendroGeode: public osg::Geode // NOLINT
67 {
68 public:
69  /**
70  * constructor
71  * \param tree tree object to work on
72  * \param displayColors vector of cluster selection colors
73  * \param cluster root cluster for the dendrogram
74  * \param xSize number of pixel to scale the tree on along the x axis
75  * \param ySize number of pixel to scale the tree on along the y axis
76  * \param xOffset translation alogn the x axis
77  * \param yOffset translation alogn the y axis
78  * \param useHLevel if true the height of a node is determined by the hierarchical level of the cluster
79  * \param triangleLeaves if set leaves will be joined by a straight line to the parent node
80  * \param hozLine if != 0 a horizontal cuttting line will be drawn across the tree
81  */
82  WNonBinDendroGeode( const WHtree& tree, const std::vector< WColor > &displayColors, size_t cluster, float xSize, float ySize,
83  float xOffset, float yOffset, bool useHLevel = false, bool triangleLeaves = false, float hozLine = 0 );
84 
85  /**
86  * destructor
87  */
89 
90  /**
91  * calculate which cluster was clicked from given pixel coordinates
92  * \param xClick the x coordinate
93  * \param yClick the y coordinate
94  * \return the cluster id, will return the root cluster if no cluster can be determinded
95  */
96  size_t getClickedCluster( int xClick, int yClick );
97 
98  /**
99  * calculates if the given position is within the view area of the dendrogram
100  * \param xClick the x coordinate
101  * \param yClick the y coordinate
102  * \return true if pos is within the dendrogram area, otherwise false
103  */
104  bool inDendrogramArea( int xClick, int yClick )const;
105 
106 protected:
107 private:
108  /**
109  * helper function the starts the layout process from the input data in the constructor
110  */
111  void create();
112 
113  /**
114  * recursive function that lays out the tree from top to bottom,
115  * height of the joins is determined by the hierarchical level of the cluster or distance value
116  * \param cluster the current node cluster to work on
117  * \param leftLimit left border of the current subcluster
118  * \param rightLimit right border of the current subcluster
119  */
120  void layout( const WHnode& cluster, const float leftLimit, const float rightLimit );
121 
122  /**
123  * recurse function that follows the layout to determine the cluster from pixel coordinates
124  * \param cluster cluster to check against coordinates
125  * \param leftLimit left boundary of cluster
126  * \param rightLimit right boundary of cluster
127  */
128  void findClickedCluster( size_t cluster, float leftLimit, float rightLimit );
129 
130 
131 
132 
133 
134  const WHtree m_tree; //!< the tree to work on
135 
136  size_t m_rootCluster; //!< top cluster to draw the tree from
137 
138  const std::vector< WColor > &m_displayColors; //!< stores a the current colors each node should be displayed, given the current selection
139 
140  osg::ref_ptr< osg::Vec4Array > m_lineColors; //!< stores a the colors of each line that should be drawn
141 
142  osg::Vec3Array* m_vertexArray; //!< vertex array
143 
144  osg::DrawElementsUInt* m_lineArray; //!< line array
145 
146  float m_xSize; //!< x size in pixel of the final dendrogram
147  float m_ySize; //!< y size in pixel of the final dendrogram
148  float m_xOff; //!< x offset for dendrogram drawing in the screen
149  float m_yOff; //!< y offset for dendrogram drawing in the screen
150  float m_xUnit; //!< helper variable for x position in the node selection recursive function
151  float m_yUnit; //!< helper variable for y position in the node selection recursive function
152 
153  float m_xClicked; //!< stores the click x position for use in the node selection recursive function
154  float m_yClicked; //!< stores the click y position for use in the node selection recursive function
155 
156  bool m_useHLevel; //!< flag indicating if the level or the value of a cluster will be used for the height of join
157  bool m_triangleLeaves; //!< option to join leaves with straight lines, giving a triangle appearance to the bottom level
158 
159  float m_hozLine; //!< determines if a horizontal line will be drawn to indicate aprtition level
160 
161  size_t m_clickedCluster; //!< ID of the clicked cluster
162 };
163 
164 #endif // WNONBINDENDROGEODE_H
this class implements a hierarchical tree node with several relevant attributes
Definition: WHnode.h:69
this class implements a hierarchical tree and provides functions for creation, partitioning,...
Definition: WHtree.h:81
Class creates a dendrogram from a hierarchical clustering, and allows to click and select specific no...
float m_yUnit
helper variable for y position in the node selection recursive function
float m_xOff
x offset for dendrogram drawing in the screen
bool m_useHLevel
flag indicating if the level or the value of a cluster will be used for the height of join
const std::vector< WColor > & m_displayColors
stores a the current colors each node should be displayed, given the current selection
const WHtree m_tree
the tree to work on
bool inDendrogramArea(int xClick, int yClick) const
calculates if the given position is within the view area of the dendrogram
~WNonBinDendroGeode()
destructor
void layout(const WHnode &cluster, const float leftLimit, const float rightLimit)
recursive function that lays out the tree from top to bottom, height of the joins is determined by th...
bool m_triangleLeaves
option to join leaves with straight lines, giving a triangle appearance to the bottom level
void create()
helper function the starts the layout process from the input data in the constructor
size_t m_clickedCluster
ID of the clicked cluster.
float m_xClicked
stores the click x position for use in the node selection recursive function
size_t getClickedCluster(int xClick, int yClick)
calculate which cluster was clicked from given pixel coordinates
float m_hozLine
determines if a horizontal line will be drawn to indicate aprtition level
WNonBinDendroGeode(const WHtree &tree, const std::vector< WColor > &displayColors, size_t cluster, float xSize, float ySize, float xOffset, float yOffset, bool useHLevel=false, bool triangleLeaves=false, float hozLine=0)
constructor
float m_yOff
y offset for dendrogram drawing in the screen
float m_yClicked
stores the click y position for use in the node selection recursive function
size_t m_rootCluster
top cluster to draw the tree from
float m_xUnit
helper variable for x position in the node selection recursive function
osg::Vec3Array * m_vertexArray
vertex array
float m_ySize
y size in pixel of the final dendrogram
osg::ref_ptr< osg::Vec4Array > m_lineColors
stores a the colors of each line that should be drawn
float m_xSize
x size in pixel of the final dendrogram
void findClickedCluster(size_t cluster, float leftLimit, float rightLimit)
recurse function that follows the layout to determine the cluster from pixel coordinates
osg::DrawElementsUInt * m_lineArray
line array