OpenWalnut  1.5.0dev
WMClusterDisplay.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 WMCLUSTERDISPLAY_H
26 #define WMCLUSTERDISPLAY_H
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 #include <osg/Geode>
33 #include <osgGA/GUIEventAdapter>
34 #include <osgGA/GUIEventHandler>
35 
36 #include "core/common/WHierarchicalTreeFibers.h"
37 #include "core/graphicsEngine/WFiberDrawable.h"
38 #include "core/graphicsEngine/WGECamera.h"
39 #include "core/graphicsEngine/WGEManagedGroupNode.h"
40 #include "core/graphicsEngine/geodes/WDendrogramGeode.h"
41 #include "core/graphicsEngine/widgets/WOSGButton.h"
42 #include "core/kernel/WFiberSelector.h"
43 #include "core/kernel/WModule.h"
44 #include "core/kernel/WModuleInputData.h"
45 #include "core/kernel/WModuleOutputData.h"
46 
47 const unsigned int MASK_2D = 0xF0000000; //!< used for osgWidget stuff
48 const unsigned int MASK_3D = 0x0F000000; //!< used for osgWidget stuff
49 
50 /**
51  * Module offers several fiber selection and coloring options depending on a hierarchical clustering
52  *
53  * \ingroup modules
54  */
56 {
57 public:
58  /**
59  * constructor
60  */
62 
63  /**
64  * destructor
65  */
66  virtual ~WMClusterDisplay();
67 
68  /**
69  * Gives back the name of this module.
70  * \return the module's name.
71  */
72  virtual const std::string getName() const;
73 
74  /**
75  * Gives back a description of this module.
76  * \return description to module.
77  */
78  virtual const std::string getDescription() const;
79 
80  /**
81  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
82  * should never be initialized or modified in some other way. A simple new instance is required.
83  *
84  * \return the prototype used to create every module in OpenWalnut.
85  */
86  virtual std::shared_ptr< WModule > factory() const;
87 
88  /**
89  * Get the icon for this module in XPM format.
90  * \return The icon.
91  */
92  virtual const char** getXPMIcon() const;
93 
94 protected:
95  /**
96  * Entry point after loading the module. Runs in separate thread.
97  */
98  virtual void moduleMain();
99 
100  /**
101  * Initialize the connectors this module is using.
102  */
103  virtual void connectors();
104 
105  /**
106  * Initialize the properties for this module.
107  */
108  virtual void properties();
109 
110 
111 private:
112  /**
113  * Small event handler class to catch left mouse buttons clicks in the main view.
114  */
115  class MainViewEventHandler : public osgGA::GUIEventHandler
116  {
117  public:
118  /**
119  * Signal for handling left button signals
120  */
121  typedef boost::signals2::signal< bool ( WVector2f ) > LeftButtonPushSignalType;
122 
123  /**
124  * The OSG calls this function whenever a new event has occured.
125  *
126  * \param ea Event class for storing GUI events such as mouse or keyboard interation etc.
127  *
128  * \return true if the event was handled.
129  */
130  bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& /* aa */ );
131 
132  /**
133  * Registers a function slot to LEFT BUTTON PUSH events. Whenever the event occurs, the slot is called with current parameters.
134  *
135  * \param slot Function object having the appropriate signature according to the used SignalType.
136  */
137  void subscribeLeftButtonPush( LeftButtonPushSignalType::slot_type slot );
138 
139  private:
140  /**
141  * Signal used for notification of the LEFT BUTTON PUSH event.
142  */
144  };
145 
146  /**
147  * helper function to read a text file
148  * \param fileName
149  * \return string containing the file
150  */
151  std::vector< std::string > readFile( const std::string fileName );
152 
153  /**
154  * helper function to load and parse a tree file, the tree is stored in the member variable m_tree
155  * \param fileName
156  *
157  * \return true if successful.
158  */
159  bool loadTreeAscii( std::string fileName );
160 
161  /**
162  * inits the cluster navigation widgets
163  */
164  void initWidgets();
165 
166  /**
167  * updates all the overlay widgets within the osg thread
168  */
169  void updateWidgets();
170 
171  /**
172  * function checks all on screen buttons if they have been clicked
173  * \return true if a button was clicked
174  */
175  bool widgetClicked();
176 
177  /**
178  * colors subclusters depending on slider settings
179  * \param current root cluster to start from
180  */
181  void colorClusters( size_t current );
182 
183  /**
184  * sets a set of cluster to a single color
185  * \param clusters vector of clusters
186  * \param color new color
187  */
188  void setColor( std::vector<size_t> clusters, WColor color );
189 
190  /**
191  * function to handle user input
192  */
194 
195  /**
196  * function to handle user input
197  */
198  void handleOffsetChanged();
199 
200  /**
201  * function to handle user input
202  */
204 
205  /**
206  * function to handle user input
207  */
209 
210  /**
211  * function to handle user input
212  */
213  void handleColoringChanged();
214 
215  /**
216  * function to handle user input
217  */
218  void handleMinSizeChanged();
219 
220 
221  /**
222  * function to handle user input
223  */
224  void handleRoiChanged();
225 
226  /**
227  * function to handle user input
228  */
230 
231  /**
232  * creates a label depending ont he current labeling setting
233  *
234  * \param id of the cluster to create the label for
235  * \return string of the label
236  */
237  std::string createLabel( size_t id );
238 
239  /**
240  * handles clicks into the dendrogram
241  * \param pos the mouse position during the click
242  * \return true if it handled the click
243  */
244  bool dendrogramClick( const WVector2f& pos );
245 
246  /**
247  * helper function to initialize a fiber display node
248  */
249  void createFiberGeode();
250 
251  /**
252  * Input connector for a fiber dataset.
253  */
254  std::shared_ptr< WModuleInputData< const WDataSetFibers > > m_fiberInput;
255 
256  std::shared_ptr< const WDataSetFibers > m_dataSet; //!< pointer to dataSet to be able to access it throughout the whole module.
257 
258  /**
259  * A condition used to notify about changes in several properties.
260  */
261  std::shared_ptr< WCondition > m_propCondition;
262 
263  /**
264  * the currently selected cluster
265  */
267 
268  /**
269  * offset to the currently selected cluster, this allows tree navigation and return to the
270  * current cluster
271  */
273 
274  /**
275  * number of biggest sub cluster to determine and show
276  */
278 
279  /**
280  * number of subclusters to color differently
281  */
283 
284  /**
285  * specifies a minimum size for a cluster so that too small cluster won't get an own color
286  */
288 
289  /**
290  * number of clusters that are selected by the current roi setting and meet the ratio condition
291  */
293 
294  /**
295  * ratio of how many leafes of a cluster must be inside the roi setting to be considered
296  */
298 
299  /**
300  * controls the display of the tree navigation widget
301  */
302  WPropBool m_propShowTree;
303 
304  /**
305  * grouping the dendrogram manipulation properties
306  */
307  WPropGroup m_groupDendrogram;
308 
309  /**
310  * controls the display of the dendrogram overlay
311  */
313 
314  /**
315  * if true position and size sliders will have no effect
316  */
318 
319  WPropInt m_propDendrogramSizeX; //!< controls the width of the dendrogram
320  WPropInt m_propDendrogramSizeY; //!< controls the height of the dendrogram
321  WPropInt m_propDendrogramOffsetX; //!< controls the horizontal origin of the dendrogram
322  WPropInt m_propDendrogramOffsetY; //!< controls the vertical origin of the dendrogram
323 
324 
325  WPropTrigger m_readTriggerProp; //!< This property triggers the actual reading,
326  WPropFilename m_propTreeFile; //!< The tree will be read from this file, i hope we will get a real load button some time
327 
328  /**
329  * stores the tree object
330  */
332 
333  /**
334  * Point to a fiber selector, which is an adapater between the roi manager and the this module
335  */
336  std::shared_ptr< WFiberSelector>m_fiberSelector;
337 
338  /**
339  * stores pointer to the fiber drawer
340  */
341  osg::ref_ptr< WFiberDrawable > m_fiberDrawable;
342 
343  /**
344  * The root node used for this modules graphics.
345  */
346  osg::ref_ptr< WGEManagedGroupNode > m_rootNode;
347 
348  std::vector<size_t>m_biggestClusters; //!< stores the currently selected biggest clusters
349 
350  /**
351  * list of buttons for the tree widget
352  */
353  std::vector< osg::ref_ptr<WOSGButton> >m_treeButtonList;
354 
355  /**
356  * list of buttons for biggest cluster selection
357  */
358  std::vector< osg::ref_ptr<WOSGButton> >m_biggestClustersButtonList;
359 
360  WGECamera* m_camera; //!< stores the camera object
361 
362  WDendrogramGeode* m_dendrogramGeode; //!< stores the dendrogram geode
363 
364  osgWidget::WindowManager* m_wm; //!< stores a pointer to the window manager used for osg wdgets and overlay stuff
365 
366  bool m_widgetDirty; //!< true if the widgets need redrawing
367 
368  bool m_biggestClusterButtonsChanged; //!< true if the buttons for the biggest clusters need updating
369 
370  bool m_dendrogramDirty; //!< true if the dendrogram needs redrawing
371 
372  size_t m_rootCluster; //!< currently selected cluster + offset
373 
374  size_t m_labelMode; //!< indicates wheter the cluster number, size of custom data should be shown on labels
375 
376  int m_oldViewHeight; //!< stores the old viewport resolution to check whether a resize happened
377 
378  int m_oldViewWidth; //!< stores the old viewport resolution to check whether a resize happened
379 };
380 
381 #endif // WMCLUSTERDISPLAY_H
Class creates a dendrogram from a hierarchical clustering.
Class for wrapping around the OSG Camera class.
Definition: WGECamera.h:36
Class implements a hierarchical tree and provides helper functions for selection and navigation.
Small event handler class to catch left mouse buttons clicks in the main view.
bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &)
The OSG calls this function whenever a new event has occured.
void subscribeLeftButtonPush(LeftButtonPushSignalType::slot_type slot)
Registers a function slot to LEFT BUTTON PUSH events.
LeftButtonPushSignalType m_signalLeftButtonPush
Signal used for notification of the LEFT BUTTON PUSH event.
boost::signals2::signal< bool(WVector2f) > LeftButtonPushSignalType
Signal for handling left button signals.
Module offers several fiber selection and coloring options depending on a hierarchical clustering.
std::shared_ptr< WFiberSelector > m_fiberSelector
Point to a fiber selector, which is an adapater between the roi manager and the this module.
bool dendrogramClick(const WVector2f &pos)
handles clicks into the dendrogram
void colorClusters(size_t current)
colors subclusters depending on slider settings
osgWidget::WindowManager * m_wm
stores a pointer to the window manager used for osg wdgets and overlay stuff
bool m_widgetDirty
true if the widgets need redrawing
WDendrogramGeode * m_dendrogramGeode
stores the dendrogram geode
bool m_biggestClusterButtonsChanged
true if the buttons for the biggest clusters need updating
WMClusterDisplay()
constructor
WPropInt m_propMinSizeToColor
specifies a minimum size for a cluster so that too small cluster won't get an own color
WPropBool m_propShowTree
controls the display of the tree navigation widget
WPropInt m_propDendrogramOffsetX
controls the horizontal origin of the dendrogram
std::vector< std::string > readFile(const std::string fileName)
helper function to read a text file
std::vector< size_t > m_biggestClusters
stores the currently selected biggest clusters
WPropInt m_propSelectedCluster
the currently selected cluster
WPropFilename m_propTreeFile
The tree will be read from this file, i hope we will get a real load button some time.
WPropBool m_propShowDendrogram
controls the display of the dendrogram overlay
void handleMinSizeChanged()
function to handle user input
WPropGroup m_groupDendrogram
grouping the dendrogram manipulation properties
void handleOffsetChanged()
function to handle user input
virtual const std::string getName() const
Gives back the name of this module.
void updateWidgets()
updates all the overlay widgets within the osg thread
int m_oldViewWidth
stores the old viewport resolution to check whether a resize happened
std::shared_ptr< const WDataSetFibers > m_dataSet
pointer to dataSet to be able to access it throughout the whole module.
osg::ref_ptr< WGEManagedGroupNode > m_rootNode
The root node used for this modules graphics.
WPropTrigger m_readTriggerProp
This property triggers the actual reading,.
bool m_dendrogramDirty
true if the dendrogram needs redrawing
void initWidgets()
inits the cluster navigation widgets
WGECamera * m_camera
stores the camera object
virtual const std::string getDescription() const
Gives back a description of this module.
size_t m_labelMode
indicates wheter the cluster number, size of custom data should be shown on labels
void createFiberGeode()
helper function to initialize a fiber display node
WPropDouble m_propBoxClusterRatio
ratio of how many leafes of a cluster must be inside the roi setting to be considered
WPropBool m_propResizeWithWindow
if true position and size sliders will have no effect
void handleSelectedLevelChanged()
function to handle user input
WPropInt m_propSubClusters
number of biggest sub cluster to determine and show
void handleColoringChanged()
function to handle user input
bool loadTreeAscii(std::string fileName)
helper function to load and parse a tree file, the tree is stored in the member variable m_tree
virtual ~WMClusterDisplay()
destructor
std::shared_ptr< WModuleInputData< const WDataSetFibers > > m_fiberInput
Input connector for a fiber dataset.
void handleCreateRoi()
function to handle user input
virtual void moduleMain()
Entry point after loading the module.
WPropInt m_propSelectedClusterOffset
offset to the currently selected cluster, this allows tree navigation and return to the current clust...
std::vector< osg::ref_ptr< WOSGButton > > m_treeButtonList
list of buttons for the tree widget
virtual void connectors()
Initialize the connectors this module is using.
size_t m_rootCluster
currently selected cluster + offset
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
WPropInt m_propDendrogramOffsetY
controls the vertical origin of the dendrogram
int m_oldViewHeight
stores the old viewport resolution to check whether a resize happened
void handleSelectedClusterChanged()
function to handle user input
void handleRoiChanged()
function to handle user input
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
WPropInt m_propSubLevelsToColor
number of subclusters to color differently
std::string createLabel(size_t id)
creates a label depending ont he current labeling setting
osg::ref_ptr< WFiberDrawable > m_fiberDrawable
stores pointer to the fiber drawer
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
void handleBiggestClustersChanged()
function to handle user input
void setColor(std::vector< size_t > clusters, WColor color)
sets a set of cluster to a single color
std::vector< osg::ref_ptr< WOSGButton > > m_biggestClustersButtonList
list of buttons for biggest cluster selection
WPropInt m_propDendrogramSizeY
controls the height of the dendrogram
virtual void properties()
Initialize the properties for this module.
WPropInt m_propDendrogramSizeX
controls the width of the dendrogram
WHierarchicalTreeFibers m_tree
stores the tree object
bool widgetClicked()
function checks all on screen buttons if they have been clicked
WPropInt m_propMaxSubClusters
number of clusters that are selected by the current roi setting and meet the ratio condition
A fixed size matrix class.
Definition: WMatrixFixed.h:150
Class representing a single module of OpenWalnut.
Definition: WModule.h:72