OpenWalnut  1.5.0dev
WMClusterDisplayVoxels.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 WMCLUSTERDISPLAYVOXELS_H
26 #define WMCLUSTERDISPLAYVOXELS_H
27 
28 #include <memory>
29 #include <queue>
30 #include <string>
31 #include <vector>
32 
33 #include <osg/Geode>
34 
35 #include "core/common/WHierarchicalTreeVoxels.h"
36 #include "core/dataHandler/WDataHandler.h"
37 #include "core/dataHandler/WDataSetScalar.h"
38 #include "core/dataHandler/WSubject.h"
39 #include "core/dataHandler/WValueSet.h"
40 #include "core/graphicsEngine/WGECamera.h"
41 #include "core/graphicsEngine/WGEManagedGroupNode.h"
42 #include "core/graphicsEngine/WGETexture.h"
43 #include "core/graphicsEngine/WPickHandler.h"
44 #include "core/graphicsEngine/geodes/WDendrogramGeode.h"
45 #include "core/graphicsEngine/widgets/WOSGButton.h"
46 #include "core/kernel/WModule.h"
47 #include "core/kernel/WModuleInputData.h"
48 #include "core/kernel/WModuleOutputData.h"
49 
50 /**
51  * Forward declaration of WTriangleMesh
52  */
53 class WTriangleMesh;
54 
55 const unsigned int MASK_2D = 0xF0000000; //!< used for osgWidget stuff
56 const unsigned int MASK_3D = 0x0F000000; //!< used for osgWidget stuff
57 
58 typedef enum
59 {
60  CDV_SINGLE,
61  CDV_BIGGEST,
62  CDV_X,
63  CDV_SIMILARITY,
64  CDV_LEVELSFROMTOP,
65  CDV_MINBRANCHLENGTH,
66  CDV_LOADED
67 }
68 CDV_DISPLAYMODE;
69 
70 /**
71  * Allows one to display and interact with clustered voxel data.
72  * \ingroup modules
73  */
75 {
76 public:
77  /**
78  *
79  */
81 
82  /**
83  *
84  */
85  virtual ~WMClusterDisplayVoxels();
86 
87  /**
88  * Gives back the name of this module.
89  * \return the module's name.
90  */
91  virtual const std::string getName() const;
92 
93  /**
94  * Gives back a description of this module.
95  * \return description to module.
96  */
97  virtual const std::string getDescription() const;
98 
99  /**
100  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
101  * should never be initialized or modified in some other way. A simple new instance is required.
102  *
103  * \return the prototype used to create every module in OpenWalnut.
104  */
105  virtual std::shared_ptr< WModule > factory() const;
106 
107  /**
108  * Get the icon for this module in XPM format.
109  * \return The icon.
110  */
111  virtual const char** getXPMIcon() const;
112 
113 protected:
114  /**
115  * Entry point after loading the module. Runs in separate thread.
116  */
117  virtual void moduleMain();
118 
119  /**
120  * Initialize the connectors this module is using.
121  */
122  virtual void connectors();
123 
124  /**
125  * Initialize the properties for this module.
126  */
127  virtual void properties();
128 
129 
130 private:
131  /**
132  * loads and parses the clustering text file
133  * \param clusterFile to the clustering file
134  * \return true if a meta file was successfully loaded, false otherwise
135  */
136  bool loadClustering( boost::filesystem::path clusterFile );
137 
138  /**
139  * creates a new texture
140  */
141  void createTexture();
142 
143  /**
144  * function to handle user input
145  */
146  void handleMinSizeChanged();
147 
148  /**
149  * after the active cluster list has changed this function updates the texture, triangulation and dendrogram
150  */
151  void updateAll();
152 
153  /**
154  * creates a triangulation from the selected clusters
155  */
156  void createMesh();
157 
158  /**
159  * renders the triangulated clusters
160  */
161  void renderMesh();
162 
163  /**
164  * inits the graphical widgets in the 3d scene
165  */
166  void initWidgets();
167 
168  /**
169  * updates the graphical widgets in the 3d scene
170  */
171  void updateWidgets();
172 
173  /**
174  * handles mouse clicks into the dendrogram
175  *
176  * \return true if handled
177  */
178  bool widgetClicked();
179 
180  /**
181  * updates property min/max values after loading a clustering file
182  */
183  void setPropertyBoundaries();
184 
185  /**
186  * listenes to the pickhandler and determines if a click into the dendrogram happened
187  * \param pickInfo the pickInfo object as sent out by the pickhandler
188  */
189  void dendrogramClick( WPickInfo pickInfo );
190 
191  /**
192  * update the output connector on demand, for performance reasons this is not done every time
193  * a change to the cluster selection is applied
194  */
195  void updateOutDataset();
196 
197  /**
198  * helper function to set the label on the in scene buttons depending on which labeling scheme is selected
199  */
200  void setButtonLabels();
201 
202  /**
203  * recursive function that initalizes a color for for every cluster, the biggest of the two children of a cluster
204  * inherits the color for its parent
205  * \param root cluster to work on
206  * \param index color index of the parent
207  */
208  void initColors( size_t root, size_t index );
209 
210 
211  /**
212  * An input connector that accepts order 1 datasets.
213  */
214  std::shared_ptr< WModuleInputData< WDataSetSingle > > m_input;
215 
216  /**
217  * An output connector for the output scalar dsataset.
218  */
219  std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output;
220 
221  /**
222  * This is a pointer to the dataset the module is currently working on.
223  */
224  std::shared_ptr< WDataSetSingle > m_dataSet;
225 
226  /**
227  * Point to the out dataset once it is invalid. Used to deregister from the datahandler
228  */
229  std::shared_ptr< WDataSetScalar > m_outDataOld;
230 
231  /**
232  * This is a pointer to the current output.
233  */
234  std::shared_ptr< WDataSetScalar > m_outData;
235 
236  /**
237  * stores a pointer to the texture we paint in
238  */
239  osg::ref_ptr<osg::Texture3D>m_texture;
240 
241  /**
242  * stores a pointer to the texture we paint in
243  */
244 // osg::ref_ptr< WGETexture3D > m_texture;
245 
246 
247  /**
248  * label vector for texture creation
249  */
250  std::vector< size_t >m_data;
251 
252  /**
253  * stores a pointer to the grid we use;
254  */
255  std::shared_ptr< WGridRegular3D > m_grid;
256 
257  /**
258  * the currently active display mode
259  */
260  CDV_DISPLAYMODE m_currentDisplayMode;
261 
262  /**
263  * the currently active display mode as string
264  */
266 
267  /**
268  * A condition used to notify about changes in several properties.
269  */
270  std::shared_ptr< WCondition > m_propCondition;
271 
272  WPropTrigger m_propReadTrigger; //!< This property triggers the actual reading,
273  WPropFilename m_propClusterFile; //!< The png files will be loaded form this directory
274 
275  /**
276  * the currently selected cluster
277  */
279 
280  /**
281  * the currently selected cluster
282  */
284 
285  /**
286  * the similarity value for selecting clusters
287  */
288  WPropDouble m_propValue;
289 
290  /**
291  * property to select a loaded partition
292  */
294 
295  /**
296  * how many levels to go down from top
297  */
299 
300  /**
301  * how many levels to go down from top
302  */
303  WPropInt m_propXClusters;
304 
305 
306  /**
307  * minimum branch length
308  */
310 
311  /**
312  * minimum branch size
313  */
315 
316  /**
317  * show or hide outliers
318  */
320 
321  /**
322  * show or hide outliers
323  */
325 
326  /**
327  * specifies a minimum size for a cluster so that too small cluster won't get an own color
328  */
330 
331  /**
332  * grouping the different selection methods
333  */
334  WPropGroup m_groupSelection;
335 
336  /**
337  * grouping the dendrogram manipulation properties
338  */
339  WPropGroup m_groupDendrogram;
340 
341  /**
342  * grouping the dendrogram manipulation properties
343  */
345 
346  /**
347  * controls the display of the dendrogram overlay
348  */
350 
351  /**
352  * controls plotting the height of a join
353  */
355 
356  /**
357  * if true position and size sliders will have no effect
358  */
360 
361  WPropTrigger m_propZoomIn; //!< zoom into tree, sets m_zoom true and m_zoomRoot to the currently selected cluster
362  WPropTrigger m_propZoomOut; //!< zooms out, m_zoom = false, dendrogram shows the whole tree
363  size_t m_zoomRoot; //!< control variable for zoom mode
364  bool m_zoom; //!< control variable for zoom mode
365 
366  WPropInt m_propDendrogramSizeX; //!< controls the width of the dendrogram
367  WPropInt m_propDendrogramSizeY; //!< controls the height of the dendrogram
368  WPropInt m_propDendrogramOffsetX; //!< controls the horizontal origin of the dendrogram
369  WPropInt m_propDendrogramOffsetY; //!< controls the vertical origin of the dendrogram
370 
371  /**
372  * if true position and size sliders will have no effect
373  */
375 
376  /**
377  * if true clusters not in the current selection list will be rendered grey in the texture and triangulation
378  */
380 
381  WHierarchicalTreeVoxels m_tree; //!< the tree object as loaded from the file
382 
383  osg::ref_ptr< WGEGroupNode > m_moduleNode; //!< Pointer to the modules group node.
384  osg::ref_ptr< WGEGroupNode > m_dendrogramNode; //!< Pointer to the dendrogram group node.
385  osg::ref_ptr< WGEGroupNode > m_meshNode; //!< Pointer to the mesh group node.
386 
387  std::vector<osg::ref_ptr< osg::Geode > > m_outputGeodes; //!< a vector of dendrogram nodes
388 
389  std::vector<std::shared_ptr< WTriangleMesh > >m_triMeshes; //!< triangulation of the active clusters
390 
391  std::shared_ptr< WTriangleMesh >m_nonActiveMesh; //!< triangulation of the voxels not in active clusters
392 
393  std::vector<size_t>m_activatedClusters; //!< stores the currently activated clusters
394 
395  /**
396  * list of buttons for the active cluster selection
397  */
398  std::vector< osg::ref_ptr<WOSGButton> >m_activeClustersButtonList;
399 
400  WGECamera* m_camera; //!< stores the camera object
401 
402  WDendrogramGeode* m_dendrogramGeode; //!< stores the dendrogram geode
403 
404  osgWidget::WindowManager* m_wm; //!< stores a pointer to the window manager used for osg wdgets and overlay stuff
405 
406  bool m_selectionChanged; //!< true if the selection changed and widgets need redrawing
407 
408  bool m_dendrogramDirty; //!< true if the dendrogram needs redrawing
409 
410  size_t m_rootCluster; //!< currently selected cluster + offset
411 
412  int m_oldViewHeight; //!< stores the old viewport resolution to check whether a resize happened
413 
414  int m_oldViewWidth; //!< stores the old viewport resolution to check whether a resize happened
415 
416  WPropInt m_infoCountLeafes; //!< info property
417  WPropInt m_infoCountClusters; //!< info property
418  WPropInt m_infoMaxLevel; //!< info property
419 
420  std::vector< std::vector<size_t> >m_loadedPartitions; //!< set partitions loaded from file
421 
422  /**
423  * updates the output connector on demand, as we don't want to do this every paint command
424  */
425  WPropTrigger m_buttonUpdateOutput;
426 
427  /**
428  * A list of cluster selection methods
429  */
430  std::shared_ptr< WItemSelection > m_clusterSelectionsList;
431 
432  /**
433  * Selection property for clusters
434  */
435  WPropSelection m_clusterSelection;
436 
437  /**
438  * triggers the cluster selection update
439  */
441 
442  /**
443  * A list of button labels
444  */
445  std::shared_ptr< WItemSelection > m_buttonLabelList;
446 
447  /**
448  * Selection property for button labels
449  */
450  WPropSelection m_buttonLabelSelection;
451 
452  /**
453  * stores a preset color for every cluster, so clusters can keep the same color through different selection methods
454  */
455  std::vector< WColor >m_clusterColors;
456 
457  size_t m_colorIndex; //!< temp variable for the initColors function
458 };
459 
460 #endif // WMCLUSTERDISPLAYVOXELS_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.
Allows one to display and interact with clustered voxel data.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
WPropBool m_propPlotHeightByLevel
controls plotting the height of a join
WPropGroup m_groupTriangulation
grouping the dendrogram manipulation properties
WPropBool m_propShowVoxelTriangulation
if true position and size sliders will have no effect
virtual const std::string getName() const
Gives back the name of this module.
std::string m_currentDisplayModeString
the currently active display mode as string
WPropGroup m_groupSelection
grouping the different selection methods
std::vector< std::shared_ptr< WTriangleMesh > > m_triMeshes
triangulation of the active clusters
WPropInt m_propSelectedLoadedPartion
property to select a loaded partition
std::shared_ptr< WItemSelection > m_buttonLabelList
A list of button labels.
void createMesh()
creates a triangulation from the selected clusters
WDendrogramGeode * m_dendrogramGeode
stores the dendrogram geode
WPropSelection m_buttonLabelSelection
Selection property for button labels.
void updateOutDataset()
update the output connector on demand, for performance reasons this is not done every time a change t...
WPropBool m_propShowSelectedButtons
show or hide outliers
size_t m_rootCluster
currently selected cluster + offset
std::vector< std::vector< size_t > > m_loadedPartitions
set partitions loaded from file
bool m_zoom
control variable for zoom mode
int m_oldViewWidth
stores the old viewport resolution to check whether a resize happened
WPropBool m_showNotInClusters
if true clusters not in the current selection list will be rendered grey in the texture and triangula...
virtual void moduleMain()
Entry point after loading the module.
WPropInt m_propDendrogramSizeY
controls the height of the dendrogram
void dendrogramClick(WPickInfo pickInfo)
listenes to the pickhandler and determines if a click into the dendrogram happened
virtual void properties()
Initialize the properties for this module.
std::shared_ptr< WDataSetScalar > m_outData
This is a pointer to the current output.
WPropTrigger m_propReadTrigger
This property triggers the actual reading,.
WPropBool m_propShowDendrogram
controls the display of the dendrogram overlay
std::shared_ptr< WModuleInputData< WDataSetSingle > > m_input
An input connector that accepts order 1 datasets.
WPropInt m_propSelectedCluster
the currently selected cluster
WPropTrigger m_buttonExecuteSelection
triggers the cluster selection update
std::vector< osg::ref_ptr< WOSGButton > > m_activeClustersButtonList
list of buttons for the active cluster selection
std::shared_ptr< WTriangleMesh > m_nonActiveMesh
triangulation of the voxels not in active clusters
WPropTrigger m_buttonUpdateOutput
updates the output connector on demand, as we don't want to do this every paint command
size_t m_zoomRoot
control variable for zoom mode
bool loadClustering(boost::filesystem::path clusterFile)
loads and parses the clustering text file
WPropInt m_propXClusters
how many levels to go down from top
WGECamera * m_camera
stores the camera object
std::shared_ptr< WItemSelection > m_clusterSelectionsList
A list of cluster selection methods.
WPropInt m_propXBiggestClusters
the currently selected cluster
int m_oldViewHeight
stores the old viewport resolution to check whether a resize happened
std::vector< WColor > m_clusterColors
stores a preset color for every cluster, so clusters can keep the same color through different select...
void updateWidgets()
updates the graphical widgets in the 3d scene
osg::ref_ptr< WGEGroupNode > m_meshNode
Pointer to the mesh group node.
osgWidget::WindowManager * m_wm
stores a pointer to the window manager used for osg wdgets and overlay stuff
void updateAll()
after the active cluster list has changed this function updates the texture, triangulation and dendro...
size_t m_colorIndex
temp variable for the initColors function
WPropInt m_propMinSizeToColor
specifies a minimum size for a cluster so that too small cluster won't get an own color
WPropInt m_propLevelsFromTop
how many levels to go down from top
WPropBool m_propResizeWithWindow
if true position and size sliders will have no effect
std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output
An output connector for the output scalar dsataset.
void setButtonLabels()
helper function to set the label on the in scene buttons depending on which labeling scheme is select...
void setPropertyBoundaries()
updates property min/max values after loading a clustering file
void initWidgets()
inits the graphical widgets in the 3d scene
WPropInt m_infoCountClusters
info property
WPropInt m_propDendrogramOffsetX
controls the horizontal origin of the dendrogram
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...
WPropTrigger m_propZoomOut
zooms out, m_zoom = false, dendrogram shows the whole tree
virtual const std::string getDescription() const
Gives back a description of this module.
osg::ref_ptr< osg::Texture3D > m_texture
stores a pointer to the texture we paint in
bool m_dendrogramDirty
true if the dendrogram needs redrawing
osg::ref_ptr< WGEGroupNode > m_dendrogramNode
Pointer to the dendrogram group node.
WPropInt m_infoMaxLevel
info property
std::vector< size_t > m_data
stores a pointer to the texture we paint in
CDV_DISPLAYMODE m_currentDisplayMode
the currently active display mode
WPropFilename m_propClusterFile
The png files will be loaded form this directory.
bool m_selectionChanged
true if the selection changed and widgets need redrawing
WPropSelection m_clusterSelection
Selection property for clusters.
WHierarchicalTreeVoxels m_tree
the tree object as loaded from the file
osg::ref_ptr< WGEGroupNode > m_moduleNode
Pointer to the modules group node.
WPropTrigger m_propZoomIn
zoom into tree, sets m_zoom true and m_zoomRoot to the currently selected cluster
std::vector< osg::ref_ptr< osg::Geode > > m_outputGeodes
a vector of dendrogram nodes
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
WPropInt m_infoCountLeafes
info property
std::shared_ptr< WDataSetSingle > m_dataSet
This is a pointer to the dataset the module is currently working on.
virtual void connectors()
Initialize the connectors this module is using.
void handleMinSizeChanged()
function to handle user input
WPropDouble m_propMinBranchLength
minimum branch length
WPropBool m_propHideOutliers
show or hide outliers
std::vector< size_t > m_activatedClusters
stores the currently activated clusters
void createTexture()
creates a new texture
void initColors(size_t root, size_t index)
recursive function that initalizes a color for for every cluster, the biggest of the two children of ...
std::shared_ptr< WGridRegular3D > m_grid
stores a pointer to the grid we use;
WPropInt m_propDendrogramOffsetY
controls the vertical origin of the dendrogram
void renderMesh()
renders the triangulated clusters
bool widgetClicked()
handles mouse clicks into the dendrogram
WPropInt m_propDendrogramSizeX
controls the width of the dendrogram
std::shared_ptr< WDataSetScalar > m_outDataOld
Point to the out dataset once it is invalid.
WPropDouble m_propValue
the similarity value for selecting clusters
WPropInt m_propMinBranchSize
minimum branch size
WPropGroup m_groupDendrogram
grouping the dendrogram manipulation properties
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
Encapsulates info for pick action.
Definition: WPickInfo.h:42
Triangle mesh data structure allowing for convenient access of the elements.
Definition: WTriangleMesh.h:46