OpenWalnut  1.5.0dev
WMClusterDisplayVoxels.cpp
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 #include <memory>
26 #include <queue>
27 #include <string>
28 #include <vector>
29 
30 #include <osg/LightModel> //NOLINT
31 #include <osgGA/StateSetManipulator>
32 #include <osgViewer/ViewerEventHandlers>
33 #include <osgWidget/Util> //NOLINT
34 #include <osgWidget/ViewerEventHandlers> //NOLINT
35 #include <osgWidget/WindowManager> //NOLINT
36 
37 #include "WFileParser.h"
38 #include "WMClusterDisplayVoxels.h"
39 #include "WMClusterDisplayVoxels.xpm"
40 #include "core/common/WPathHelper.h"
41 #include "core/common/WPropertyHelper.h"
42 #include "core/common/WStringUtils.h"
43 #include "core/common/algorithms/WMarchingLegoAlgorithm.h"
44 #include "core/graphicsEngine/WGEColormapping.h"
45 #include "core/graphicsEngine/WGEUtils.h"
46 #include "core/kernel/WKernel.h"
47 #include "core/kernel/WSelectionManager.h"
48 
49 // This line is needed by the module loader to actually find your module. Do not remove. Do NOT add a ";" here.
50 W_LOADABLE_MODULE( WMClusterDisplayVoxels )
51 
52 WMClusterDisplayVoxels::WMClusterDisplayVoxels():
53  WModule(),
54  m_currentDisplayMode( CDV_SINGLE ),
55  m_currentDisplayModeString( "" ),
56  m_moduleNode( new WGEGroupNode() ),
57  m_dendrogramNode( new WGEGroupNode() ),
58  m_meshNode( new WGEGroupNode() ),
59  m_selectionChanged( false ),
60  m_dendrogramDirty( false )
61 {
62 }
63 
64 WMClusterDisplayVoxels::~WMClusterDisplayVoxels()
65 {
66  // Cleanup!
67 }
68 
69 std::shared_ptr< WModule > WMClusterDisplayVoxels::factory() const
70 {
71  // See "src/modules/template/" for an extensively documented example.
72  return std::shared_ptr< WModule >( new WMClusterDisplayVoxels() );
73 }
74 
76 {
77  return clusterDisplayVoxels_xpm;
78 }
79 const std::string WMClusterDisplayVoxels::getName() const
80 {
81  // Specify your module name here. This name must be UNIQUE!
82  return "ClusterDisplayVoxels";
83 }
84 
85 const std::string WMClusterDisplayVoxels::getDescription() const
86 {
87  // Specify your module description here. Be detailed. This text is read by the user.
88  // See "src/modules/template/" for an extensively documented example.
89  return "Visualizes voxel clusterings in texture and 3D view";
90 }
91 
93 {
94  // the input dataset is just used as source for resolurtion and transformation matrix
95  m_input = std::shared_ptr< WModuleInputData < WDataSetSingle > >(
96  new WModuleInputData< WDataSetSingle >( shared_from_this(), "in", "The input dataset." ) );
98 
99  m_output = std::shared_ptr< WModuleOutputData < WDataSetScalar > >(
100  new WModuleOutputData< WDataSetScalar >( shared_from_this(), "out", "The extracted image." ) );
102 
104 }
105 
107 {
108  m_propCondition = std::shared_ptr< WCondition >( new WCondition() );
109 
110  m_propClusterFile = m_properties->addProperty( "Cluster file", "", boost::filesystem::path( "/SCR/schurade/data/david/whole/avg.txt" ) );
111  m_propReadTrigger = m_properties->addProperty( "Do read", "Press!", WPVBaseTypes::PV_TRIGGER_READY, m_propCondition );
112 
113 
114  // Group selection
115  m_groupSelection = m_properties->addPropertyGroup( "Cluster selections", "Groups the different cluster selection methods" ); //NOLINT
116 
117  m_clusterSelectionsList = std::shared_ptr< WItemSelection >( new WItemSelection() );
118  m_clusterSelectionsList->addItem( "Single", "" );
119  m_clusterSelectionsList->addItem( "Biggest", "" );
120  m_clusterSelectionsList->addItem( "X Clusters", "" );
121  m_clusterSelectionsList->addItem( "Similarity", "" );
122  m_clusterSelectionsList->addItem( "Levels from top", "" );
123  m_clusterSelectionsList->addItem( "Minimum branch length", "" );
124  m_clusterSelectionsList->addItem( "Loaded partition", "" );
125 
126  m_clusterSelection = m_groupSelection->addProperty( "Selection method", "selection",
127  m_clusterSelectionsList->getSelectorFirst(), m_propCondition );
129 
130 
131 
132  m_propSelectedCluster = m_groupSelection->addProperty( "Selected Cluster", "Selects a single cluster by number.", 0, m_propCondition );
133  m_propSelectedCluster->setMin( 0 );
134  m_propSelectedCluster->setMax( 0 );
135 
136  m_propXBiggestClusters = m_groupSelection->addProperty( "Biggest Clusters", "Selects a number of biggest clusters.", 5, m_propCondition );
137  m_propXBiggestClusters->setMin( 1 );
138  m_propXBiggestClusters->setMax( 1000 );
139 
140  m_propXClusters = m_groupSelection->addProperty( "X Clusters", "Selects a number of clusters by dividing clusters.", 5, m_propCondition );
141  m_propXClusters->setMin( 1 );
142  m_propXClusters->setMax( 1000 );
143 
144  m_propValue = m_groupSelection->addProperty( "Similarity Value", "Selects clusters below a given similarity value", 1.0, m_propCondition );
145  m_propValue->setMin( 0.0 );
146  m_propValue->setMax( 1.0 );
147 
148  m_propLevelsFromTop = m_groupSelection->addProperty( "Levels from top", "", 0, m_propCondition );
149  m_propHideOutliers = m_groupSelection->addProperty( "Hide outliers", "", false, m_propCondition );
150 
151  m_propSelectedLoadedPartion = m_groupSelection->addProperty( "Loaded Partition", "Activates a predetermined partition, loaded from file", 0, m_propCondition ); // NOLINT
152  m_propSelectedLoadedPartion->setMin( 1 );
153  m_propSelectedLoadedPartion->setMax( 1 );
154 
155  m_propMinBranchLength = m_groupSelection->addProperty( "Minimum branch length", "", 0.1, m_propCondition );
156  m_propMinBranchLength->setMin( 0.0 );
157  m_propMinBranchLength->setMax( 1.0 );
158 
159  m_propMinBranchSize = m_groupSelection->addProperty( "Minimum branch size", "", 50, m_propCondition );
160  m_propMinBranchSize->setMin( 1 );
161  m_propMinBranchSize->setMax( 500 );
162 
164 
165  m_propShowSelectedButtons = m_groupSelection->addProperty( "Show Buttons", "Shows/Hides the buttons for selected cluster on the left side", true, m_propCondition ); //NOLINT
166 
167  m_buttonLabelList = std::shared_ptr< WItemSelection >( new WItemSelection() );
168  m_buttonLabelList->addItem( "Number", "" );
169  m_buttonLabelList->addItem( "Size", "" );
170  m_buttonLabelList->addItem( "Level", "" );
171  m_buttonLabelList->addItem( "Similarity", "" );
172 
173  m_buttonLabelSelection = m_groupSelection->addProperty( "Button label", "selection",
174  m_buttonLabelList->getSelectorFirst(), m_propCondition );
176 
177 
178  // Group Triangulation
179  m_groupTriangulation = m_properties->addPropertyGroup( "Triangulation", "Groups the triangulation properties" ); //NOLINT
180  m_propShowVoxelTriangulation = m_groupTriangulation->addProperty( "Triangulate", "", false, m_propCondition );
181  m_showNotInClusters = m_groupTriangulation->addProperty( "Show non active", "", false, m_propCondition );
182 
183  // Group Dendrogram
184  m_groupDendrogram = m_properties->addPropertyGroup( "Dendrogram", "Properties only related to the dendrogram." );
185 
186  m_propShowDendrogram = m_groupDendrogram->addProperty( "Show dendrogram", "", true, m_propCondition );
187  m_propPlotHeightByLevel = m_groupDendrogram->addProperty( "Height by Level or Value", "", false, m_propCondition );
188 
189  m_propMinSizeToColor = m_groupDendrogram->addProperty( "Min size to show", "Specifies a minimum size for a cluster to be drawn", 1, m_propCondition ); // NOLINT
190  m_propMinSizeToColor->setMin( 1 );
191  m_propMinSizeToColor->setMax( 200 );
192 
193  m_propZoomIn = m_groupDendrogram->addProperty( "Zoom in", "Press!", WPVBaseTypes::PV_TRIGGER_READY, m_propCondition );
194  m_propZoomOut = m_groupDendrogram->addProperty( "Zoom out", "Press!", WPVBaseTypes::PV_TRIGGER_READY, m_propCondition );
195 
196  m_propResizeWithWindow = m_groupDendrogram->addProperty( "Resize with window", "", true, m_propCondition );
197 
198  m_propDendrogramSizeX = m_groupDendrogram->addProperty( "Width", "", 100, m_propCondition );
199  m_propDendrogramSizeX->setMin( 0 );
200  m_propDendrogramSizeX->setMax( 10000 );
201  m_propDendrogramSizeY = m_groupDendrogram->addProperty( "Height", "", 100, m_propCondition );
202  m_propDendrogramSizeY->setMin( 0 );
203  m_propDendrogramSizeY->setMax( 10000 );
204  m_propDendrogramOffsetX = m_groupDendrogram->addProperty( "Horizontal position", "", 100, m_propCondition );
205  m_propDendrogramOffsetX->setMin( -9000 );
206  m_propDendrogramOffsetX->setMax( 1000 );
207  m_propDendrogramOffsetY = m_groupDendrogram->addProperty( "Verctical position", "", 100, m_propCondition );
208  m_propDendrogramOffsetY->setMin( -9000 );
209  m_propDendrogramOffsetY->setMax( 1000 );
210 
211  m_groupSelection->setHidden( true );
212  m_groupTriangulation->setHidden( true );
213  m_groupDendrogram->setHidden( true );
214 
215  m_buttonUpdateOutput = m_properties->addProperty( "Update output", "Updates the output connector",
217 
218 
219  // Info properties
220  m_infoCountLeafes = m_infoProperties->addProperty( "Count voxels", "", 0 );
221  m_infoCountClusters = m_infoProperties->addProperty( "Count clusters", "", 0 );
222  m_infoMaxLevel = m_infoProperties->addProperty( "Max Level", "", 0 );
223 
225 }
226 
228 {
231 
232  m_propSelectedCluster->setMin( 0 );
235 
239 
240  m_propMinSizeToColor->setMax( 1000 );
242 
243  m_propLevelsFromTop->setMin( 0 );
245 
246  if( m_loadedPartitions.empty() )
247  {
248  m_propSelectedLoadedPartion->setHidden( true );
249  }
250  else
251  {
252  m_propSelectedLoadedPartion->setMin( 1 );
254  }
255 
256  m_zoom = false;
258 }
259 
261 {
262  boost::signals2::connection con = WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getPickHandler()->getPickSignal()->
263  connect( boost::bind( &WMClusterDisplayVoxels::dendrogramClick, this, boost::placeholders::_1 ) );
264 
265 
266  m_moduleState.setResetable( true, true );
267  m_moduleState.add( m_input->getDataChangedCondition() );
269  m_moduleState.add( m_active->getUpdateCondition() );
270 
271  ready();
272 
273  // wait for a dataset to be connected, most likely an anatomy dataset
274  while( !m_shutdownFlag() )
275  {
277 
278  if( m_shutdownFlag() )
279  {
280  break;
281  }
282 
283  std::shared_ptr< WDataSetSingle > newDataSet = m_input->getData();
284  bool dataChanged = ( m_dataSet != newDataSet );
285  bool dataValid = ( newDataSet != NULL );
286 
287  if( dataValid )
288  {
289  if( dataChanged )
290  {
291  m_dataSet = newDataSet;
292  m_grid = std::dynamic_pointer_cast< WGridRegular3D >( m_dataSet->getGrid() );
293  break;
294  }
295  }
296  }
297 
298  // wait for a cluster file to be loaded
299  while( !m_shutdownFlag() )
300  {
302 
303  if( m_shutdownFlag() )
304  {
305  break;
306  }
307 
309  {
310  boost::filesystem::path fileName = m_propClusterFile->get();
312 
313  if( loadClustering( fileName ) )
314  {
315  m_propReadTrigger->setHidden( true );
316  m_propClusterFile->setHidden( true );
317  m_groupSelection->setHidden( false );
318  m_groupTriangulation->setHidden( false );
319  m_groupDendrogram->setHidden( false );
320  break;
321  }
322  }
323  }
324 
325  // initialize
326  if( !m_shutdownFlag() )
327  {
328  createTexture();
330  initWidgets();
331 
332  m_propSelectedCluster->get( true );
333  m_propSelectedLoadedPartion->get( true );
334  m_propMinSizeToColor->get( true );
335  m_propXClusters->get( true );
336  m_propXBiggestClusters->get( true );
337  m_propValue->get( true );
338  m_propMinBranchLength->get( true );
339  m_propMinBranchSize->get( true );
340  m_propLevelsFromTop->get( true );
341  m_propHideOutliers->get( true );
342  m_showNotInClusters->get( true );
343 
344  updateAll();
345  }
346 
347  // main loop, respond to controls
348  while( !m_shutdownFlag() )
349  {
351 
352  if( m_shutdownFlag() )
353  {
354  break;
355  }
356 
357  if( m_clusterSelection->changed( true ) )
358  {
359  m_propSelectedCluster->setHidden( true );
360  m_propXBiggestClusters->setHidden( true );
361  m_propXClusters->setHidden( true );
362  m_propValue->setHidden( true );
363  m_propLevelsFromTop->setHidden( true );
364  m_propHideOutliers->setHidden( true );
365  m_propMinBranchLength->setHidden( true );
366  m_propMinBranchSize->setHidden( true );
367  m_propSelectedLoadedPartion->setHidden( true );
368 
369  switch( m_clusterSelection->get( true ).getItemIndexOfSelected( 0 ) )
370  {
371  case 0:
372  m_propSelectedCluster->setHidden( false );
373  break;
374  case 1:
375  m_propSelectedCluster->setHidden( false );
376  m_propXBiggestClusters->setHidden( false );
377  break;
378  case 2:
379  m_propSelectedCluster->setHidden( false );
380  m_propXClusters->setHidden( false );
381  break;
382  case 3:
383  m_propValue->setHidden( false );
384  break;
385  case 4:
386  m_propLevelsFromTop->setHidden( false );
387  m_propHideOutliers->setHidden( false );
388  break;
389  case 5:
390  m_propMinBranchLength->setHidden( false );
391  m_propMinBranchSize->setHidden( false );
392  break;
393  case 6:
394  m_propSelectedLoadedPartion->setHidden( false );
395  break;
396  default:
397  m_propSelectedCluster->setHidden( false );
398  break;
399  }
400  }
401 
403  {
405  switch( m_clusterSelection->get( true ).getItemIndexOfSelected( 0 ) )
406  {
407  case 0:
408  m_currentDisplayMode = CDV_SINGLE;
409  break;
410  case 1:
411  m_currentDisplayMode = CDV_BIGGEST;
412  break;
413  case 2:
414  m_currentDisplayMode = CDV_X;
415  break;
416  case 3:
417  m_currentDisplayMode = CDV_SIMILARITY;
418  break;
419  case 4:
420  m_currentDisplayMode = CDV_LEVELSFROMTOP;
421  break;
422  case 5:
423  m_currentDisplayMode = CDV_MINBRANCHLENGTH;
424  break;
425  case 6:
426  m_currentDisplayMode = CDV_LOADED;
427  break;
428  default:
429  m_currentDisplayMode = CDV_SINGLE;
430  break;
431  }
432  updateAll();
433  }
434 
435  if( m_propShowVoxelTriangulation->changed( true ) )
436  {
437  createMesh();
438  renderMesh();
439  }
440 
441  if( m_showNotInClusters->changed( true ) )
442  {
443  updateAll();
444  }
445 
446  if( m_propMinSizeToColor->changed( true ) )
447  {
449  }
450 
451  if( m_buttonLabelSelection->changed() )
452  {
453  setButtonLabels();
454  }
455 
456  if( m_propShowDendrogram->changed( true ) || m_propResizeWithWindow->changed( true ) || m_propDendrogramSizeX->changed( true ) ||
457  m_propDendrogramSizeY->changed( true ) || m_propDendrogramOffsetX->changed( true ) || m_propDendrogramOffsetY->changed( true ) ||
458  m_propPlotHeightByLevel->changed( true ) || m_propShowSelectedButtons->changed() )
459  {
460  m_dendrogramDirty = true;
461  }
462 
464  {
467  }
468 
469  if( m_propZoomIn->changed( true ) )
470  {
471  m_zoom = true;
472  m_zoomRoot = m_propSelectedCluster->get( true );
473  m_dendrogramDirty = true;
475  m_propZoomIn->get( true );
476  }
477 
478  if( m_propZoomOut->changed( true ) )
479  {
480  m_zoom = false;
481  m_dendrogramDirty = true;
483  }
484  }
485 
486  con.disconnect();
487 
488  WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_moduleNode );
489 }
490 
492 {
493  switch( m_currentDisplayMode )
494  {
495  case CDV_SINGLE:
496  m_activatedClusters.clear();
497  m_activatedClusters.push_back( m_propSelectedCluster->get( true ) );
498  m_currentDisplayModeString = std::string( "Single selection" );
499  break;
500  case CDV_BIGGEST:
502  m_currentDisplayModeString = std::string( "Biggest clusters" );
503  break;
504  case CDV_X:
506  m_currentDisplayModeString = std::string( "X clusters" );
507  break;
508  case CDV_SIMILARITY:
510  m_currentDisplayModeString = std::string( "Similarity value selection" );
511  break;
512  case CDV_LEVELSFROMTOP:
514  m_currentDisplayModeString = std::string( "Levels from top" );
515  break;
516  case CDV_MINBRANCHLENGTH:
518  m_currentDisplayModeString = std::string( "Minimum branch length" );
519  break;
520  case CDV_LOADED:
522  m_currentDisplayModeString = std::string( "Loaded Partition" );
523  break;
524  default:
525  break;
526  };
527 
528 
529  // set colors for cluster in the tree
530  m_tree.colorCluster( m_tree.getClusterCount() - 1, WColor( 0.3, 0.3, 0.3, 1.0 ) );
531  for( size_t k = 0; k < m_activatedClusters.size(); ++k )
532  {
533  size_t current = m_activatedClusters[k];
534  //m_tree.colorCluster( current, wge::getNthHSVColor( k ) );
535  m_tree.colorCluster( current, m_clusterColors[current] );
536  }
537 
538  // redraw the texture
539  m_data.clear();
540  m_data.resize( m_grid->size(), 0 );
541  std::vector<size_t> vox = m_tree.getVoxelsForCluster( m_tree.getClusterCount() - 1 );
542  if( m_showNotInClusters->get() )
543  {
544  for( size_t k = 0; k < vox.size(); ++k )
545  {
546  m_data[vox[k]] = 999999;
547  }
548  }
549  for( size_t i = 0; i < m_activatedClusters.size(); ++i )
550  {
551  std::vector<size_t> voxels = m_tree.getVoxelsForCluster( m_activatedClusters[i] );
552 
553  for( size_t k = 0; k < voxels.size(); ++k )
554  {
555  m_data[voxels[k]] = i + 1;
556  }
557  }
558 
559  unsigned char* data = m_texture->getImage()->data();
560  for( size_t i = 0; i < m_grid->size(); ++i )
561  {
562  if( m_data[i] == 999999 )
563  {
564  data[i * 3 ] = 75;
565  data[i * 3 + 1] = 75;
566  data[i * 3 + 2] = 75;
567  }
568  else if( m_data[i] != 0 )
569  {
570  WColor color = m_clusterColors[m_activatedClusters[m_data[i]-1]];
571  data[i * 3 ] = color[0] * 255;
572  data[i * 3 + 1] = color[1] * 255;
573  data[i * 3 + 2] = color[2] * 255;
574  }
575  else
576  {
577  data[i * 3 ] = 0.0;
578  data[i * 3 + 1] = 0.0;
579  data[i * 3 + 2] = 0.0;
580  }
581  }
582  m_texture->dirtyTextureObject();
583 
584  createMesh();
585  renderMesh();
586 
587  m_selectionChanged = true;
588  m_dendrogramDirty = true;
589 }
590 
592 {
593  m_dendrogramDirty = true;
594 }
595 
596 bool WMClusterDisplayVoxels::loadClustering( boost::filesystem::path clusterFile )
597 {
598  debugLog() << "start parsing tree file...";
599 
600  WFileParser parser( clusterFile.string() );
601  if( !parser.readFile() )
602  {
603  debugLog() << "parser error";
604  return false;
605  }
606 
607  std::vector<std::string>lines = parser.getRawLines();
608 
609  if( lines.size() == 0 )
610  {
611  debugLog() << "file is empty";
612  return false;
613  }
614 
615  std::vector< std::vector< std::string> >coords = parser.getLinesForTagSeparated( "coordinates" );
616 
617  for( size_t i = 0; i < coords.size(); ++i )
618  {
619  std::vector< std::string > svec = coords[i];
620 
621  m_tree.addLeaf( m_grid->getVoxelNum( string_utils::fromString< size_t >( svec[0] ),
622  string_utils::fromString< size_t >( svec[1] ),
623  string_utils::fromString< size_t >( svec[2] ) ) );
624  }
625 
626  std::vector< std::vector< std::string> >clusters = parser.getLinesForTagSeparated( "clusters" );
627 
628  for( size_t i = 0; i < clusters.size(); ++i )
629  {
630  std::vector< std::string > svec = clusters[i];
631 
632  m_tree.addCluster( string_utils::fromString< size_t >( svec[0] ),
633  string_utils::fromString< size_t >( svec[1] ),
634  string_utils::fromString< float >( svec[2] ) );
635  }
636 
637  std::vector< std::vector< std::string> >partitions = parser.getLinesForTagSeparated( "partitions" );
638 
639  for( size_t i = 0; i < partitions.size(); ++i )
640  {
641  std::vector< std::string > svec = partitions[i];
642 
643  std::vector<size_t>partition;
644 
645  for( size_t k = 0; k < svec.size(); ++k )
646  {
647  partition.push_back( string_utils::fromString< size_t >( svec[k] ) );
648  }
649  m_loadedPartitions.push_back( partition );
650  }
651 
652  m_colorIndex = 0;
654  initColors( m_tree.getClusterCount() - 1, 0 );
655  return true;
656 }
657 
658 void WMClusterDisplayVoxels::initColors( size_t root, size_t index )
659 {
660  if( m_tree.size( root ) == 1 )
661  {
662  m_clusterColors[root] = wge::getNthHSVColor( index );
663  return;
664  }
665  m_clusterColors[root] = wge::getNthHSVColor( index );
666  size_t left = m_tree.getChildren( root ).first;
667  size_t right = m_tree.getChildren( root ).second;
668  if( m_tree.size( left ) >= m_tree.size( right ) )
669  {
670  initColors( left, index );
671  initColors( right, ++m_colorIndex );
672  }
673  else
674  {
675  initColors( left, ++m_colorIndex );
676  initColors( right, index );
677  }
678 }
679 
681 {
682  osg::ref_ptr< osg::Image > ima = new osg::Image;
683  ima->allocateImage( m_grid->getNbCoordsX(), m_grid->getNbCoordsY(), m_grid->getNbCoordsZ(), GL_RGB, GL_UNSIGNED_BYTE );
684  unsigned char* data = ima->data();
685  m_data.resize( m_grid->getNbCoordsX() * m_grid->getNbCoordsY() * m_grid->getNbCoordsZ(), 0 );
686 
687  for( unsigned int i = 0; i < m_grid->size() * 3; ++i )
688  {
689  data[i] = 0.0;
690  }
691 
692  m_texture = osg::ref_ptr<osg::Texture3D>( new osg::Texture3D );
693  m_texture->setFilter( osg::Texture3D::MIN_FILTER, osg::Texture3D::LINEAR );
694  m_texture->setFilter( osg::Texture3D::MAG_FILTER, osg::Texture3D::LINEAR );
695  m_texture->setWrap( osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_BORDER );
696  m_texture->setWrap( osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_BORDER );
697  m_texture->setWrap( osg::Texture::WRAP_R, osg::Texture::CLAMP_TO_BORDER );
698  m_texture->setImage( ima );
699  m_texture->setResizeNonPowerOfTwoHint( false );
700 
702  WKernel::getRunningKernel()->getSelectionManager()->setShader( 0 );
703  WKernel::getRunningKernel()->getSelectionManager()->setUseTexture( true );
704 
705  WDataHandler::getDefaultSubject()->getChangeCondition()->notify();
706 
707 
708 // osg::ref_ptr< osg::Image > ima = new osg::Image;
709 // ima->allocateImage( m_grid->getNbCoordsX(), m_grid->getNbCoordsY(), m_grid->getNbCoordsZ(), GL_RGB, GL_UNSIGNED_BYTE );
710 //
711 // unsigned char* data = ima->data();
712 // m_data.resize( m_grid->getNbCoordsX() * m_grid->getNbCoordsY() * m_grid->getNbCoordsZ(), 0 );
713 //
714 // for( unsigned int i = 0; i < m_grid->size() * 3; ++i )
715 // {
716 // data[i] = 0.0;
717 // }
718 //
719 // m_texture = osg::ref_ptr< WGETexture3D >( new WGETexture3D( ima ) );
720 // m_texture->setFilterMinMag( osg::Texture3D::LINEAR );
721 // m_texture->setWrapSTR( osg::Texture::CLAMP_TO_BORDER );
722 // m_texture->colormap()->set( m_texture->colormap()->get().newSelector( WItemSelector::IndexList( 1, 4 ) ) );
723 // m_properties->addProperty( m_texture->alpha() );
724 //
725 // WGEColormapping::registerTexture( m_texture, "Cluster Texture" );
726 }
727 
729 {
730  m_triMeshes.clear();
731 
732  for( size_t k = 1; k <= m_activatedClusters.size(); ++k )
733  {
734  WMarchingLegoAlgorithm mlAlgo;
735  m_triMeshes.push_back( mlAlgo.genSurfaceOneValue( m_grid->getNbCoordsX(), m_grid->getNbCoordsY(), m_grid->getNbCoordsZ(),
736  m_grid->getTransformationMatrix(),
737  &m_data,
738  k ) );
739  }
740 
741  if( m_showNotInClusters->get() )
742  {
743  WMarchingLegoAlgorithm mlAlgo;
744  m_nonActiveMesh = mlAlgo.genSurfaceOneValue( m_grid->getNbCoordsX(), m_grid->getNbCoordsY(), m_grid->getNbCoordsZ(),
745  m_grid->getTransformationMatrix(),
746  &m_data,
747  999999 );
748  }
749 }
750 
752 {
753  if( !m_outputGeodes.empty() )
754  {
755  for( size_t i = 0; i < m_outputGeodes.size(); ++i )
756  {
757  m_meshNode->remove( m_outputGeodes[i] );
758  }
759  m_outputGeodes.clear();
760  }
761 
762  if( m_propShowVoxelTriangulation->get( true ) )
763  {
764  for( size_t i = 0; i < m_triMeshes.size(); ++i )
765  {
766  osg::Geometry* surfaceGeometry = new osg::Geometry();
767  osg::ref_ptr< osg::Geode >outputGeode = osg::ref_ptr< osg::Geode >( new osg::Geode );
768 
769  outputGeode->setName( ( std::string( "cluster" ) + string_utils::toString( m_activatedClusters[i] ) ).c_str() );
770 
771  surfaceGeometry->setVertexArray( m_triMeshes[i]->getVertexArray() );
772 
773  // ------------------------------------------------
774  // normals
775  surfaceGeometry->setNormalArray( m_triMeshes[i]->getVertexNormalArray() );
776  surfaceGeometry->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
777 
778  // ------------------------------------------------
779  // colors
780  osg::Vec4Array* colors = new osg::Vec4Array;
781  colors->push_back( m_clusterColors[m_activatedClusters[i]] );
782  surfaceGeometry->setColorArray( colors );
783  surfaceGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );
784 
785  osg::DrawElementsUInt* surfaceElement = new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );
786 
787  std::vector< size_t >tris = m_triMeshes[i]->getTriangles();
788  surfaceElement->reserve( tris.size() );
789 
790  for( unsigned int vertId = 0; vertId < tris.size(); ++vertId )
791  {
792  surfaceElement->push_back( tris[vertId] );
793  }
794  surfaceGeometry->addPrimitiveSet( surfaceElement );
795  outputGeode->addDrawable( surfaceGeometry );
796 
797  osg::StateSet* state = outputGeode->getOrCreateStateSet();
798  osg::ref_ptr<osg::LightModel> lightModel = new osg::LightModel();
799  lightModel->setTwoSided( true );
800  state->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
801  state->setMode( GL_BLEND, osg::StateAttribute::ON );
802 
803  m_meshNode->insert( outputGeode );
804  m_outputGeodes.push_back( outputGeode );
805  }
806  }
807  if( m_propShowVoxelTriangulation->get( true ) && m_showNotInClusters->get() )
808  {
809  osg::Geometry* surfaceGeometry = new osg::Geometry();
810  osg::ref_ptr< osg::Geode >outputGeode = osg::ref_ptr< osg::Geode >( new osg::Geode );
811 
812  outputGeode->setName( ( std::string( "non active" ) ).c_str() );
813 
814  surfaceGeometry->setVertexArray( m_nonActiveMesh->getVertexArray() );
815 
816  // ------------------------------------------------
817  // normals
818  surfaceGeometry->setNormalArray( m_nonActiveMesh->getVertexNormalArray() );
819  surfaceGeometry->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
820 
821  // ------------------------------------------------
822  // colors
823  osg::Vec4Array* colors = new osg::Vec4Array;
824 
825  colors->push_back( osg::Vec4( 0.3, 0.3, 0.3, 1.0f ) );
826  surfaceGeometry->setColorArray( colors );
827  surfaceGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );
828 
829  osg::DrawElementsUInt* surfaceElement = new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );
830 
831  std::vector< size_t >tris = m_nonActiveMesh->getTriangles();
832  surfaceElement->reserve( tris.size() );
833 
834  for( unsigned int vertId = 0; vertId < tris.size(); ++vertId )
835  {
836  surfaceElement->push_back( tris[vertId] );
837  }
838  surfaceGeometry->addPrimitiveSet( surfaceElement );
839  outputGeode->addDrawable( surfaceGeometry );
840 
841  osg::StateSet* state = outputGeode->getOrCreateStateSet();
842  osg::ref_ptr<osg::LightModel> lightModel = new osg::LightModel();
843  lightModel->setTwoSided( true );
844  state->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
845  state->setMode( GL_BLEND, osg::StateAttribute::ON );
846 
847  m_meshNode->insert( outputGeode );
848  m_outputGeodes.push_back( outputGeode );
849  }
850 }
851 
853 {
854  osg::ref_ptr<osgViewer::View> viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getView();
855 
856  int height = viewer->getCamera()->getViewport()->height();
857  int width = viewer->getCamera()->getViewport()->width();
858 
859  m_oldViewHeight = height;
860  m_oldViewWidth = width;
861 
862  m_moduleNode = osg::ref_ptr< WGEManagedGroupNode >( new WGEManagedGroupNode( m_active ) );
863  m_dendrogramNode = osg::ref_ptr< WGEManagedGroupNode >( new WGEManagedGroupNode( m_active ) );
864  m_meshNode = osg::ref_ptr< WGEManagedGroupNode >( new WGEManagedGroupNode( m_active ) );
865  m_moduleNode->insert( m_dendrogramNode );
866  m_moduleNode->insert( m_meshNode );
867 
868  m_wm = new osgWidget::WindowManager( viewer, 0.0f, 0.0f, MASK_2D );
869 
870  m_camera = new WGECamera();
871  m_camera->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::PROTECTED | osg::StateAttribute::OFF );
872 
873  m_camera->setProjectionMatrix( osg::Matrix::ortho2D( 0.0, width, 0.0f, height ) );
874  m_camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
875  m_camera->setViewMatrix( osg::Matrix::identity() );
876  m_camera->setClearMask( GL_DEPTH_BUFFER_BIT );
877  m_camera->setRenderOrder( WGECamera::POST_RENDER );
878 
879  m_dendrogramNode->addChild( m_camera );
880  m_camera->addChild( m_wm );
881 
882  viewer->addEventHandler( new osgWidget::MouseHandler( m_wm ) );
883  viewer->addEventHandler( new osgWidget::KeyboardHandler( m_wm ) );
884  viewer->addEventHandler( new osgWidget::ResizeHandler( m_wm, m_camera ) );
885  viewer->addEventHandler( new osgWidget::CameraSwitchHandler( m_wm, m_camera ) );
886  viewer->addEventHandler( new osgViewer::StatsHandler() );
887  viewer->addEventHandler( new osgViewer::WindowSizeHandler() );
888  viewer->addEventHandler( new osgGA::StateSetManipulator( viewer->getCamera()->getOrCreateStateSet() ) );
889 
890  m_wm->resizeAllWindows();
891 
892  m_moduleNode->addUpdateCallback( new WGEFunctorCallback< osg::Node >( boost::bind( &WMClusterDisplayVoxels::updateWidgets, this ) ) );
893  WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_moduleNode );
894 }
895 
897 {
898  osg::ref_ptr<osgViewer::View> viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getView();
899 
900  int height = viewer->getCamera()->getViewport()->height();
901  int width = viewer->getCamera()->getViewport()->width();
902 
903  int rows = ( height - 20 ) / 20;
904  int buttonWidth = 70;
905 
906  if( ( height != m_oldViewHeight ) || width != m_oldViewWidth )
907  {
908  m_oldViewHeight = height;
909  m_oldViewWidth = width;
910 
911  m_dendrogramDirty = true;
912  }
913 
914  bool buttonClicked = widgetClicked();
915 
916  if( !buttonClicked && !m_dendrogramDirty )
917  {
918  return;
919  }
920 
922  {
923  for( size_t i = 0; i < m_activeClustersButtonList.size(); ++i )
924  {
925  m_wm->removeChild( m_activeClustersButtonList[i] );
926  }
927 
929 
930  if( m_propShowSelectedButtons->get( true ) )
931  {
932  for( size_t i = 0; i < m_activatedClusters.size(); ++i )
933  {
934  osg::ref_ptr<WOSGButton> newButton = osg::ref_ptr<WOSGButton>( new WOSGButton( std::string( "" ),
935  osgWidget::Box::VERTICAL, true, true ) );
936  newButton->setPosition( osg::Vec3( 5.f + ( i / rows ) * buttonWidth, ( i % rows ) * 20.f, 0 ) );
937  newButton->setId( m_activatedClusters[i] );
938  newButton->managed( m_wm );
939  m_wm->addChild( newButton );
940  m_activeClustersButtonList.push_back( newButton );
941  newButton->setBackgroundColor( m_clusterColors[m_activatedClusters[i]] );
942  }
943  }
944 
945  setButtonLabels();
946 
947  osg::ref_ptr<WOSGButton> newButton = osg::ref_ptr<WOSGButton>( new WOSGButton( std::string( "" ),
948  osgWidget::Box::VERTICAL, true, true ) );
949  newButton->setPosition( osg::Vec3( 5.f, height - 20.f, 0 ) );
950  newButton->setId( 0 );
951  newButton->setLabel( m_currentDisplayModeString );
952  newButton->managed( m_wm );
953  m_wm->addChild( newButton );
954  m_activeClustersButtonList.push_back( newButton );
955  newButton->setBackgroundColor( wge::getNthHSVColor( m_currentDisplayMode ) );
956 
957  m_selectionChanged = false;
958  }
959  m_wm->resizeAllWindows();
960 
961  if( m_propShowSelectedButtons && buttonClicked )
962  {
963  m_tree.colorCluster( m_tree.getClusterCount() - 1, WColor( 0.3, 0.3, 0.3, 1.0 ) );
964  for( size_t k = 0; k < m_activatedClusters.size(); ++k )
965  {
966  if( m_activeClustersButtonList[k]->pushed() )
967  {
968  size_t current = m_activatedClusters[k];
969  //m_tree.colorCluster( current, wge::getNthHSVColor( k ) );
970  m_tree.colorCluster( current, m_clusterColors[current] );
971  }
972  }
973  m_dendrogramDirty = true;
974  }
975 
976 
977 
978  if( m_dendrogramDirty )
979  {
980  m_camera->removeChild( m_dendrogramGeode );
981  //m_camera->removeChild( 1, 1 );
982 
983  int dwidth = m_propDendrogramSizeX->get( true );
984  int dheight = m_propDendrogramSizeY->get( true );
985  int dxOff = m_propDendrogramOffsetX->get( true );
986  int dyOff = m_propDendrogramOffsetY->get( true );
987 
988  if( m_propShowDendrogram->get( true ) )
989  {
990  size_t rootCluster = m_tree.getClusterCount() - 1;
991 
992  if( m_zoom )
993  {
994  rootCluster = m_zoomRoot;
995  }
996 
997 
998  if( m_propResizeWithWindow->get( true ) )
999  {
1000  if( m_propShowSelectedButtons->get() )
1001  {
1002  m_dendrogramGeode = new WDendrogramGeode( &m_tree, rootCluster, m_propPlotHeightByLevel->get( true ),
1003  m_propMinSizeToColor->get(), width - ( ( m_activatedClusters.size() / rows ) + 1 ) * buttonWidth, height / 2 ,
1004  ( ( m_activatedClusters.size() / rows ) + 1 ) * buttonWidth );
1005  }
1006  else
1007  {
1008  m_dendrogramGeode = new WDendrogramGeode( &m_tree, rootCluster, m_propPlotHeightByLevel->get( true ),
1009  m_propMinSizeToColor->get(), width - 20, height / 2 , 10 );
1010  }
1011  }
1012  else
1013  {
1014  m_dendrogramGeode = new WDendrogramGeode( &m_tree, rootCluster, m_propPlotHeightByLevel->get( true ),
1015  m_propMinSizeToColor->get(), dwidth, dheight, dxOff, dyOff );
1016  }
1017  m_camera->addChild( m_dendrogramGeode );
1018  }
1019  m_dendrogramDirty = false;
1020  }
1021 }
1022 
1024 {
1025  bool clicked = false;
1026  bool selectionChanged = false;
1027 
1028  for( size_t i = 0; i < m_activeClustersButtonList.size(); ++i )
1029  {
1030  if( m_activeClustersButtonList[i]->clicked() )
1031  {
1032  if( m_activeClustersButtonList[i]->getId() < 10000000 )
1033  {
1034  selectionChanged = true;
1035  clicked = true;
1036  }
1037  }
1038  }
1039 
1040  if( selectionChanged )
1041  {
1042  std::vector<size_t>activeClusters;
1043  for( size_t i = 0; i < m_activeClustersButtonList.size(); ++i )
1044  {
1045  if( m_activeClustersButtonList[i]->pushed() )
1046  {
1047  if( m_outputGeodes.size() > i )
1048  {
1049  m_outputGeodes[i]->setNodeMask( 0xFFFFFFFF );
1050  }
1051  }
1052  else
1053  {
1054  if( m_outputGeodes.size() > i )
1055  {
1056  m_outputGeodes[i]->setNodeMask( 0x00000000 );
1057  }
1058  }
1059  }
1060  }
1061  return clicked;
1062 }
1063 
1065 {
1066  if( !m_propShowDendrogram->get() || !( pickInfo.getName() == "nothing" ) )
1067  {
1068  return;
1069  }
1070  int x = pickInfo.getPickPixel().x();
1071  int y = pickInfo.getPickPixel().y();
1072 
1073  size_t cluster = m_dendrogramGeode->getClickedCluster( x, y );
1074  //std::cout << cluster << std::endl;
1075  m_propSelectedCluster->set( cluster );
1077 }
1078 
1080 {
1081  WAssert( m_dataSet, "" );
1082  WAssert( m_dataSet->getValueSet(), "" );
1083  WAssert( m_dataSet->getGrid(), "" );
1084 
1085  std::shared_ptr< std::vector< float > >ptr( new std::vector< float >( m_data.size() ) );
1086 
1087  for( size_t i = 0; i < m_data.size(); ++i )
1088  {
1089  ptr->at( i ) = static_cast<float>( m_data[i] );
1090  }
1091 
1092  std::shared_ptr< WValueSet< float > > vs =
1093  std::shared_ptr< WValueSet< float > >( new WValueSet< float >( 0, 1, ptr, W_DT_FLOAT ) );
1094 
1095  m_outData = std::shared_ptr< WDataSetScalar >( new WDataSetScalar( vs, m_grid ) );
1096  m_output->updateData( m_outData );
1097 }
1098 
1100 {
1101  if( m_propShowSelectedButtons->get() )
1102  {
1103  std::string ns;
1104  for( size_t i = 0; i < m_activatedClusters.size(); ++i )
1105  {
1106  if( m_buttonLabelSelection->get( true ).getItemIndexOfSelected( 0 ) == 0 )
1107  {
1109  }
1110  else if( m_buttonLabelSelection->get( true ).getItemIndexOfSelected( 0 ) == 1 )
1111  {
1113  }
1114  else if( m_buttonLabelSelection->get( true ).getItemIndexOfSelected( 0 ) == 2 )
1115  {
1117  }
1118  else
1119  {
1121  if( ns.size() > 8 )
1122  {
1123  ns = ns.substr( 0, 8 );
1124  }
1125  }
1126 
1127 
1128  for( size_t k = 8 - ns.size(); k > 0; --k )
1129  {
1130  if( k %2 == 1 )
1131  {
1132  ns = std::string( " " ) + ns;
1133  }
1134  else
1135  {
1136  ns = ns + std::string( " " );
1137  }
1138  }
1139  if( m_activeClustersButtonList.size() > i )
1140  {
1141  m_activeClustersButtonList[i]->setLabel( ns );
1142  }
1143  }
1144  }
1145 }
virtual void wait() const
Wait for the condition.
void setResetable(bool resetable=true, bool autoReset=true)
Sets the resetable flag.
virtual void add(std::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
Class to encapsulate boost::condition_variable_any.
Definition: WCondition.h:42
static std::shared_ptr< WSubject > getDefaultSubject()
Gets the subject with the ID SUBJECT_UNKNOWN.
This data set type contains scalars as values.
Class creates a dendrogram from a hierarchical clustering.
size_t getClickedCluster(int xClick, int yClick)
calculate which cluster was clicked from given pixel coordinates
class implements text file loading and several convinience methods to access
std::vector< std::vector< std::string > > getLinesForTagSeparated(std::string tag)
getter
std::vector< std::string > getRawLines()
getter
bool readFile()
helper function to read a text file
Class for wrapping around the OSG Camera class.
Definition: WGECamera.h:36
This callback allows you a simple usage of callbacks in your module.
Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.
Definition: WGEGroupNode.h:48
This class adds some convenience methods to WGEGroupNode.
std::vector< size_t > getVoxelsForCluster(size_t cluster)
getter
std::vector< size_t > findXClusters(size_t root, size_t number)
finds a number of clusters, the algorithm travers down the tree and will always split the cluster wit...
std::vector< size_t > findClustersForBranchLength(float value, size_t minSize=100)
finds the clusters for a given similarity value
std::vector< size_t > findClustersForValue(float value)
finds the clusters for a given similarity value
void addLeaf(size_t voxelnum)
A leaf is at the very bottom of the tree, it represents a single fiber or voxel, for several purposes...
void addCluster(size_t cluster1, size_t cluster2, float customData)
adds a cluster to the set, it combines 2 already existing clusters
size_t size(size_t cluster) const
getter
std::pair< size_t, size_t > getChildren(size_t cluster) const
getter
std::vector< size_t > downXLevelsFromTop(size_t level, bool hideOutliers=false) const
returns a number of clusters at a certain level down from top cluster
void colorCluster(size_t cluster, WColor color)
sets the color for a selected cluster and all sub clusters
float getCustomData(size_t cluster) const
getter
size_t getLevel(size_t cluster) const
getter
std::vector< size_t > findXBiggestClusters(size_t cluster, size_t number=10) const
finds the X biggest clusters for a given cluster
size_t getLeafCount() const
getter
size_t getClusterCount() const
getter
size_t getMaxLevel() const
getter
A class containing a list of named items.
std::shared_ptr< WSelectionManager > getSelectionManager()
get for selection manager
Definition: WKernel.cpp:214
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
Definition: WKernel.cpp:117
std::shared_ptr< WGraphicsEngine > getGraphicsEngine() const
Returns pointer to currently running instance of graphics engine.
Definition: WKernel.cpp:122
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
WPropDouble m_propValue
the similarity value for selecting clusters
WPropInt m_propMinBranchSize
minimum branch size
WPropGroup m_groupDendrogram
grouping the dendrogram manipulation properties
Creates a non interpolated triangulation of an isosurface.
std::shared_ptr< WTriangleMesh > genSurfaceOneValue(size_t nbCoordsX, size_t nbCoordsY, size_t nbCoordsZ, const WMatrix< double > &mat, const std::vector< size_t > *vals, size_t isoValue, std::shared_ptr< WProgressCombiner > progress=std::shared_ptr< WProgressCombiner >())
Generate the triangles for the surface on the given dataSet (inGrid, vals).
ValueT & y()
Access y element of vector.
ValueT & x()
Access x element of vector.
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
virtual void properties()
Initialize properties in this function.
Definition: WModule.cpp:212
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
Definition: WModule.cpp:575
void addConnector(std::shared_ptr< WModuleInputConnector > con)
Adds the specified connector to the list of inputs.
Definition: WModule.cpp:108
std::shared_ptr< WProperties > m_properties
The property object for the module.
Definition: WModule.h:640
std::shared_ptr< WProperties > m_infoProperties
The property object for the module containing only module whose purpose is "PV_PURPOSE_INFORMNATION".
Definition: WModule.h:647
void ready()
Call this whenever your module is ready and can react on property changes.
Definition: WModule.cpp:505
WConditionSet m_moduleState
The internal state of the module.
Definition: WModule.h:703
WPropBool m_active
True whenever the module should be active.
Definition: WModule.h:723
virtual void connectors()
Initialize connectors in this function.
Definition: WModule.cpp:208
Class implements an osgWidget::Box with a label that can be used as a button in the 3D scene.
Definition: WOSGButton.h:42
Encapsulates info for pick action.
Definition: WPickInfo.h:42
WVector2d getPickPixel() const
Returns the picked pixel coordinates in screen-space.
Definition: WPickInfo.h:275
std::string getName() const
Get name of picked object.
Definition: WPickInfo.h:243
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
Base Class for all value set types.
Definition: WValueSet.h:47
@ PV_TRIGGER_TRIGGERED
Trigger property: got triggered.
@ PV_TRIGGER_READY
Trigger property: is ready to be triggered (again)
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.
std::string toString(const T &value)
Convert a given value to a string.
Definition: WStringUtils.h:120
WColor getNthHSVColor(int n)
creates the nth color of a partition of the hsv color circle
Definition: WGEUtils.cpp:168