OpenWalnut  1.5.0dev
WMCoordinateSystem.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 <algorithm>
26 #include <memory>
27 #include <string>
28 #include <utility>
29 #include <vector>
30 
31 #include <osg/Geode>
32 #include <osg/Geometry>
33 
34 #include "WMCoordinateSystem.h"
35 #include "WMCoordinateSystem.xpm"
36 #include "WTalairachConverter.h"
37 #include "core/common/WPropertyHelper.h"
38 #include "core/dataHandler/WDataHandler.h"
39 #include "core/dataHandler/WDataSet.h"
40 #include "core/dataHandler/WDataSetScalar.h"
41 #include "core/dataHandler/WSubject.h"
42 #include "core/dataHandler/exceptions/WDHNoSuchSubject.h"
43 #include "core/graphicsEngine/WGEGeodeUtils.h"
44 #include "core/kernel/WKernel.h"
45 #include "core/kernel/WSelectionManager.h"
46 
47 // This line is needed by the module loader to actually find your module.
48 W_LOADABLE_MODULE( WMCoordinateSystem )
49 
51  WModule(), m_dirty( false ), m_drawOffset( 0.02 ),
52  m_viewAngle( 0 )
53 {
54 }
55 
57 {
58 }
59 
60 std::shared_ptr< WModule > WMCoordinateSystem::factory() const
61 {
62  return std::shared_ptr< WMCoordinateSystem >( new WMCoordinateSystem() );
63 }
64 
65 const char** WMCoordinateSystem::getXPMIcon() const
66 {
67  return coordinateSystem_xpm;
68 }
69 
71 {
72  // initialize connectors
73  m_input = std::shared_ptr< WModuleInputData< WDataSetScalar > >( new WModuleInputData< WDataSetScalar > ( shared_from_this(), "in",
74  "Dataset to create atlas surfaces from." ) );
75  // add it to the list of connectors. Please note, that a connector NOT added via addConnector will not work as expected.
77 
78  // call WModules initialization
80 }
81 
83 {
84  m_moduleState.setResetable( true, true );
85  m_moduleState.add( m_input->getDataChangedCondition() );
86 
87  // signal ready state
88  ready();
89 
90  // loop until the module container requests the module to quit
91  while( !m_shutdownFlag() )
92  {
94 
95  if( m_shutdownFlag() )
96  {
97  break;
98  }
99 
100  if( m_dataSet != m_input->getData() )
101  {
102  // acquire data from the input connector
103  m_dataSet = m_input->getData();
104 
105  if( m_dataSet )
106  {
107  findBoundingBox();
108  createGeometry();
109  m_dirty = true;
110  }
111  }
112  }
113  // clean up stuff
114  // NOTE: ALWAYS remove your osg nodes!
115  WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_rootNode );
116 }
117 
118 const std::string WMCoordinateSystem::getName() const
119 {
120  return "Coordinate System";
121 }
122 
123 const std::string WMCoordinateSystem::getDescription() const
124 {
125  return "This module displays coordinate systems as overlay within the main 3D view.";
126 }
127 
129 {
131 
132  m_showAxial = m_properties->addProperty( "Show rulers on axial", "", true, propertyCallback );
133  m_showCoronal = m_properties->addProperty( "Show rulers on coronal", "", false, propertyCallback );
134  m_showSagittal = m_properties->addProperty( "Show rulers on sagittal", "", false, propertyCallback );
135 
136  m_possibleSelections = std::shared_ptr< WItemSelection >( new WItemSelection() );
137  m_possibleSelections->addItem( "World", "" ); // NOTE: you can add XPM images here.
138  m_possibleSelections->addItem( "Canonical", "" );
139  m_possibleSelections->addItem( "Talairach", "" );
140 
141  m_csSelection = m_properties->addProperty( "Select coordinate system", "", m_possibleSelections->getSelectorFirst(), propertyCallback );
142 
145 
146  m_showGridAxial = m_properties->addProperty( "Show grid on axial", "", false, propertyCallback );
147  m_showGridCoronal = m_properties->addProperty( "Show grid on coronal", "", false, propertyCallback );
148  m_showGridSagittal = m_properties->addProperty( "Show grid on sagittal", "", false, propertyCallback );
149 
150  m_showNumbersOnRulers = m_properties->addProperty( "Show numbers on rulers", "Does exactly what it says", true, propertyCallback );
151 
152  WPosition ch = WKernel::getRunningKernel()->getSelectionManager()->getCrosshair()->getPosition();
153  m_crosshair = m_properties->addProperty( "Crosshair", "", ch );
154  // initialize the properties with a certain standard set
155  // those properties will be updatet as soon as the first dataset is looaded
156  m_flt = m_infoProperties->addProperty( "Front left top", "", WPosition( 0.0, 0.0, 0.0 ) );
157  m_brb = m_infoProperties->addProperty( "Bottom right back", "", WPosition( 160.0, 200.0, 160.0 ) );
158 
159  m_ac = m_infoProperties->addProperty( "Anterior commisure", "", WPosition( 80.0, 119.0, 80.0 ) );
160  m_pc = m_infoProperties->addProperty( "Posterior commisure", "", WPosition( 80.0, 80.0, 80.0 ) );
161  m_ihp = m_infoProperties->addProperty( "Interhemispherical point", "", WPosition( 80.0, 119.0, 110.0 ) );
162 
163  m_acTrigger = m_properties->addProperty( "Set AC", "Press me.", WPVBaseTypes::PV_TRIGGER_READY, propertyCallback );
164  m_pcTrigger = m_properties->addProperty( "Set PC", "Press me.", WPVBaseTypes::PV_TRIGGER_READY, propertyCallback );
165  m_ihpTrigger = m_properties->addProperty( "Set IHP", "Press me.", WPVBaseTypes::PV_TRIGGER_READY, propertyCallback );
166 
168 }
169 
171 {
172  if( m_csSelection->changed() )
173  {
174  WItemSelector s = m_csSelection->get( true );
175  infoLog() << "Selected " << s.at( 0 )->getName() << " coordinate system.";
176  m_coordConverter->setCoordinateSystemMode( static_cast< coordinateSystemMode > ( s.getItemIndexOfSelected( 0 ) ) );
177  }
178 
179  if( m_acTrigger->get( true ) == WPVBaseTypes::PV_TRIGGER_TRIGGERED )
180  {
182  m_ac->set( m_crosshair->get() );
184  infoLog() << "Set new AC point.";
185  }
186  if( m_pcTrigger->get( true ) == WPVBaseTypes::PV_TRIGGER_TRIGGERED )
187  {
189  m_pc->set( m_crosshair->get() );
191  infoLog() << "Set new PC point.";
192  }
194  {
196  m_ihp->set( m_crosshair->get() );
198  infoLog() << "Set new IHP point.";
199  }
200  m_dirty = true;
201 }
202 
204 {
205  // Activate/Deactivate the coordinate system
206  if( m_active->get() )
207  {
208  m_rootNode->setNodeMask( 0xFFFFFFFF );
209  }
210  else
211  {
212  m_rootNode->setNodeMask( 0x0 );
213  }
214 
215  // Always call WModule's activate!
217 }
218 
220 {
221  m_rootNode = osg::ref_ptr< WGEGroupNode >( new WGEGroupNode() );
222 
223 // m_rootNode->insert( wge::generateBoundingBoxGeode( m_coordConverter->getBoundingBox().first, m_coordConverter->getBoundingBox().second, WColor(
224 // 0.3, 0.3, 0.3, 1 ) ) );
225 
226  m_rulerNode = osg::ref_ptr< osg::Group >( new osg::Group() );
227  m_rootNode->insert( m_rulerNode );
228 
229  WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_rootNode );
230 
231  m_rootNode->addUpdateCallback( new WGEFunctorCallback< osg::Node >( boost::bind( &WMCoordinateSystem::updateCallback, this ) ) );
232 
233  if( m_active->get() )
234  {
235  m_rootNode->setNodeMask( 0xFFFFFFFF );
236  }
237  else
238  {
239  m_rootNode->setNodeMask( 0x0 );
240  }
241 }
242 
244 {
245  if( WKernel::getRunningKernel()->getSelectionManager()->getFrontSector() != m_viewAngle )
246  {
248  m_dirty = true;
249  }
250 
251  WPosition ch = WKernel::getRunningKernel()->getSelectionManager()->getCrosshair()->getPosition();
252  WPosition cho = m_crosshair->get();
253 
254  if( ch[0] != cho[0] || ch[1] != cho[1] || ch[2] != cho[2] || m_dirty )
255  {
256  m_crosshair->set( ch );
257  }
258  else
259  {
260  return;
261  }
262 
263  // *******************************************************************************************************
264  // osg::ref_ptr<osg::Drawable> old = osg::ref_ptr<osg::Drawable>( m_boxNode->getDrawable( 0 ) );
265  // m_boxNode->replaceDrawable( old, createGeometryNode() );
266  std::shared_ptr< WGridRegular3D > grid = std::dynamic_pointer_cast< WGridRegular3D >( m_dataSet->getGrid() );
267 
268  double xOff = grid->getOffsetX();
269  double yOff = grid->getOffsetY();
270  double zOff = grid->getOffsetZ();
271 
272  m_rulerNode->removeChildren( 0, m_rulerNode->getNumChildren() );
273 
274  if( m_showSagittal->get() )
275  {
277  }
278  if( m_showGridSagittal->get() )
279  {
280  addSagittalGrid( m_crosshair->get()[0] + 0.5 * xOff + m_drawOffset );
281  addSagittalGrid( m_crosshair->get()[0] + 0.5 * xOff - m_drawOffset );
282  }
283 
284  if( m_showCoronal->get() )
285  {
287  }
288  if( m_showGridCoronal->get() )
289  {
290  addCoronalGrid( m_crosshair->get()[1] + 0.5 * yOff + m_drawOffset );
291  addCoronalGrid( m_crosshair->get()[1] + 0.5 * yOff - m_drawOffset );
292  }
293 
294  if( m_showAxial->get() )
295  {
296  addRulersAxial();
297  }
298  if( m_showGridAxial->get() )
299  {
300  addAxialGrid( m_crosshair->get()[2] + 0.5 * zOff + m_drawOffset );
301  addAxialGrid( m_crosshair->get()[2] + 0.5 * zOff - m_drawOffset );
302  }
303 
304  // *******************************************************************************************************
305  m_dirty = false;
306 }
307 
309 {
310  // get bounding from dataset
311  std::shared_ptr< WGridRegular3D > grid = std::dynamic_pointer_cast< WGridRegular3D >( m_dataSet->getGrid() );
312 
313  double xOff = grid->getOffsetX();
314  double yOff = grid->getOffsetY();
315  double zOff = grid->getOffsetZ();
316 
317  WVector3d offset( xOff, yOff, zOff );
318  m_coordConverter = std::shared_ptr< WCoordConverter >( new WCoordConverter( grid->getTransformationMatrix(), grid->getOrigin(), offset ) );
319 
320  WItemSelector s = m_csSelection->get( true );
321  m_coordConverter->setCoordinateSystemMode( static_cast< coordinateSystemMode > ( s.getItemIndexOfSelected( 0 ) ) );
322  m_coordConverter->setBoundingBox( m_dataSet->getGrid()->getBoundingBox() );
323 
324  // now compute the innerBoundingBox for the actual data
325  WPosition flt = m_flt->get();
326  WPosition brb = m_brb->get();
327 
328  for( size_t x = 0; x < grid->getNbCoordsX(); ++x )
329  {
330  int count = 0;
331  for( size_t y = 0; y < grid->getNbCoordsY(); ++y )
332  {
333  for( size_t z = 0; z < grid->getNbCoordsZ(); ++z )
334  {
335  double v = m_dataSet->getValueAt( x, y, z );
336  if( v > 0 )
337  {
338  ++count;
339  }
340  }
341  }
342  if( count > 5 )
343  {
344  flt[0] = static_cast< float > ( x * xOff );
345  break;
346  }
347  }
348  for( int x = grid->getNbCoordsX() - 1; x > -1; --x )
349  {
350  int count = 0;
351  for( size_t y = 0; y < grid->getNbCoordsY(); ++y )
352  {
353  for( size_t z = 0; z < grid->getNbCoordsZ(); ++z )
354  {
355  double v = m_dataSet->getValueAt( x, y, z );
356  if( v > 0 )
357  {
358  ++count;
359  }
360  }
361  }
362  if( count > 5 )
363  {
364  brb[0] = static_cast< float > ( x * xOff );
365  break;
366  }
367  }
368 
369  for( size_t y = 0; y < grid->getNbCoordsY(); ++y )
370  {
371  int count = 0;
372  for( size_t x = 0; x < grid->getNbCoordsX(); ++x )
373  {
374  for( size_t z = 0; z < grid->getNbCoordsZ(); ++z )
375  {
376  double v = m_dataSet->getValueAt( x, y, z );
377  if( v > 0 )
378  {
379  ++count;
380  }
381  }
382  }
383  if( count > 5 )
384  {
385  flt[1] = static_cast< float > ( y * yOff );
386  break;
387  }
388  }
389  for( int y = grid->getNbCoordsY() - 1; y > -1; --y )
390  {
391  int count = 0;
392  for( size_t x = 0; x < grid->getNbCoordsX(); ++x )
393  {
394  for( size_t z = 0; z < grid->getNbCoordsZ(); ++z )
395  {
396  double v = m_dataSet->getValueAt( x, y, z );
397  if( v > 0 )
398  {
399  ++count;
400  }
401  }
402  }
403  if( count > 5 )
404  {
405  brb[1] = static_cast< float > ( y * yOff );
406  break;
407  }
408  }
409 
410  for( size_t z = 0; z < grid->getNbCoordsZ(); ++z )
411  {
412  int count = 0;
413  for( size_t x = 0; x < grid->getNbCoordsX(); ++x )
414  {
415  for( size_t y = 0; y < grid->getNbCoordsY(); ++y )
416  {
417  double v = m_dataSet->getValueAt( x, y, z );
418  if( v > 0 )
419  {
420  ++count;
421  }
422  }
423  }
424  if( count > 5 )
425  {
426  flt[2] = static_cast< float > ( z * zOff );
427  break;
428  }
429  }
430  for( int z = grid->getNbCoordsZ() - 1; z > -1; --z )
431  {
432  int count = 0;
433  for( size_t x = 0; x < grid->getNbCoordsX(); ++x )
434  {
435  for( size_t y = 0; y < grid->getNbCoordsY(); ++y )
436  {
437  double v = m_dataSet->getValueAt( x, y, z );
438  if( v > 0 )
439  {
440  ++count;
441  }
442  }
443  }
444  if( count > 5 )
445  {
446  brb[2] = static_cast< float > ( z * zOff );
447  break;
448  }
449  }
450 
451  WPosition tmpflt = m_coordConverter->worldCoordTransformed( flt );
452  WPosition tmpbrb = m_coordConverter->worldCoordTransformed( brb );
453 
454  flt[0] = std::min( tmpflt[0], tmpbrb[0] );
455  flt[1] = std::max( tmpflt[1], tmpbrb[1] );
456  flt[2] = std::max( tmpflt[2], tmpbrb[2] );
457  brb[0] = std::max( tmpflt[0], tmpbrb[0] );
458  brb[1] = std::min( tmpflt[1], tmpbrb[1] );
459  brb[2] = std::min( tmpflt[2], tmpbrb[2] );
460 
461  m_flt->set( flt );
462  m_brb->set( brb );
463 
465 }
466 
468 {
469  WVector3d ac_c( m_coordConverter->w2c( m_ac->get() ) );
470  WVector3d pc_c( m_coordConverter->w2c( m_pc->get() ) );
471  WVector3d ihp_c( m_coordConverter->w2c( m_ihp->get() ) );
472  std::shared_ptr< WTalairachConverter > talairachConverter =
473  std::shared_ptr< WTalairachConverter >( new WTalairachConverter( ac_c, pc_c, ihp_c ) );
474 
475  WVector3d flt_c( m_coordConverter->w2c( m_flt->get() ) );
476  WVector3d brb_c( m_coordConverter->w2c( m_brb->get() ) );
477 
478  WVector3d ap( flt_c[0], 0., 0. );
479  WVector3d pp( brb_c[0], 0., 0. );
480  WVector3d lp( 0., flt_c[1], 0. );
481  WVector3d rp( 0., brb_c[1], 0. );
482  WVector3d sp( 0., 0., flt_c[2] );
483  WVector3d ip( 0., 0., brb_c[2] );
484 
485  talairachConverter->setAp( ap );
486  talairachConverter->setPp( pp );
487  talairachConverter->setSp( sp );
488  talairachConverter->setIp( ip );
489  talairachConverter->setLp( lp );
490  talairachConverter->setRp( rp );
491 
492  m_coordConverter->setTalairachConverter( talairachConverter );
493 }
494 
496 {
497  float offset = 0.0;
498  if( m_viewAngle < 4 )
499  {
500  offset = -1.0;
501  }
502  else
503  {
504  offset = 1.0;
505  }
506 
507  osg::ref_ptr< WRulerOrtho > ruler1 = osg::ref_ptr< WRulerOrtho >(
508  new WRulerOrtho( m_coordConverter, osg::Vec3( m_crosshair->get()[0] + offset, m_crosshair->get()[1], m_crosshair->get()[2] ),
509  RULER_ALONG_Y_AXIS_SCALE_Z, m_showNumbersOnRulers->get() ) );
510  osg::ref_ptr< WRulerOrtho > ruler2 = osg::ref_ptr< WRulerOrtho >(
511  new WRulerOrtho( m_coordConverter, osg::Vec3( m_crosshair->get()[0] + offset, m_crosshair->get()[1], m_crosshair->get()[2] ),
512  RULER_ALONG_Z_AXIS_SCALE_Y, m_showNumbersOnRulers->get() ) );
513 
514  m_rulerNode->addChild( ruler1 );
515  m_rulerNode->addChild( ruler2 );
516 }
517 
519 {
520  float offset = 0.0;
521  if( ( m_viewAngle == 1 ) || ( m_viewAngle == 2 ) || ( m_viewAngle == 5 ) || ( m_viewAngle == 6 ) )
522  {
523  offset = 1.0;
524  }
525  else
526  {
527  offset = -1.0;
528  }
529 
530  osg::ref_ptr< WRulerOrtho > ruler1 = osg::ref_ptr< WRulerOrtho >(
531  new WRulerOrtho( m_coordConverter, osg::Vec3( m_crosshair->get()[0], m_crosshair->get()[1], m_crosshair->get()[2] + offset ),
532  RULER_ALONG_X_AXIS_SCALE_Y, m_showNumbersOnRulers->get() ) );
533  osg::ref_ptr< WRulerOrtho > ruler2 = osg::ref_ptr< WRulerOrtho >(
534  new WRulerOrtho( m_coordConverter, osg::Vec3( m_crosshair->get()[0], m_crosshair->get()[1], m_crosshair->get()[2] + offset ),
535  RULER_ALONG_Y_AXIS_SCALE_X, m_showNumbersOnRulers->get() ) );
536 
537  m_rulerNode->addChild( ruler1 );
538  m_rulerNode->addChild( ruler2 );
539 }
540 
542 {
543  float offset = 0.0;
544  if( ( m_viewAngle == 2 ) || ( m_viewAngle == 3 ) || ( m_viewAngle == 4 ) || ( m_viewAngle == 5 ) )
545  {
546  offset = 1.0;
547  }
548  else
549  {
550  offset = - 1.0;
551  }
552 
553  osg::ref_ptr< WRulerOrtho > ruler1 = osg::ref_ptr< WRulerOrtho >(
554  new WRulerOrtho( m_coordConverter, osg::Vec3( m_crosshair->get()[0], m_crosshair->get()[1] + offset, m_crosshair->get()[2] ),
555  RULER_ALONG_X_AXIS_SCALE_Z, m_showNumbersOnRulers->get() ) );
556  osg::ref_ptr< WRulerOrtho > ruler2 = osg::ref_ptr< WRulerOrtho >(
557  new WRulerOrtho( m_coordConverter, osg::Vec3( m_crosshair->get()[0], m_crosshair->get()[1] + offset, m_crosshair->get()[2] ),
558  RULER_ALONG_Z_AXIS_SCALE_X, m_showNumbersOnRulers->get() ) );
559 
560  m_rulerNode->addChild( ruler1 );
561  m_rulerNode->addChild( ruler2 );
562 }
563 
565 {
566  if( m_viewAngle < 4 )
567  {
568  position -= 1.0;
569  }
570  else
571  {
572  position += 1.0;
573  }
574 
575  osg::ref_ptr< osg::Geode > gridGeode = osg::ref_ptr< osg::Geode >( new osg::Geode() );
576  osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >( new osg::Geometry() );
577  osg::Vec3Array* vertices = new osg::Vec3Array;
578 
579  WBoundingBox boundingBox = m_coordConverter->getBoundingBox();
580  WPosition p1 = boundingBox.getMin();
581  WPosition p2 = boundingBox.getMax();
582 
583  switch( m_coordConverter->getCoordinateSystemMode() )
584  {
585  case CS_WORLD:
586  case CS_CANONICAL:
587  for( int i = p1[1]; i < p2[1] + 2; ++i )
588  {
589  if( m_coordConverter->numberToCsY( i ) % 10 == 0 )
590  {
591  vertices->push_back( osg::Vec3( position, i, p1[2] ) );
592  vertices->push_back( osg::Vec3( position, i, p2[2] + 1 ) );
593  }
594  }
595  for( int i = p1[2]; i < p2[2] + 2; ++i )
596  {
597  if( m_coordConverter->numberToCsZ( i ) % 10 == 0 )
598  {
599  vertices->push_back( osg::Vec3( position, p1[1], i ) );
600  vertices->push_back( osg::Vec3( position, p2[1] + 1, i ) );
601  }
602  }
603  break;
604  case CS_TALAIRACH:
605  {
606  std::shared_ptr< WTalairachConverter > tc = m_coordConverter->getTalairachConverter();
607 
608  for( int i = -110; i < 81; i += 10 )
609  {
610  WVector3d tmpPoint1 = m_coordConverter->t2w( WVector3d( i, 0, -50 ) );
611  WVector3d tmpPoint2 = m_coordConverter->t2w( WVector3d( i, 0, 80 ) );
612 
613  vertices->push_back( osg::Vec3( position, tmpPoint1[1], tmpPoint1[2] ) );
614  vertices->push_back( osg::Vec3( position, tmpPoint2[1], tmpPoint2[2] ) );
615  }
616  for( int i = -50; i < 81; i += 10 )
617  {
618  WVector3d tmpPoint1 = m_coordConverter->t2w( WVector3d( -110, 0, i ) );
619  WVector3d tmpPoint2 = m_coordConverter->t2w( WVector3d( 80, 0, i ) );
620 
621  vertices->push_back( osg::Vec3( position, tmpPoint1[1], tmpPoint1[2] ) );
622  vertices->push_back( osg::Vec3( position, tmpPoint2[1], tmpPoint2[2] ) );
623  }
624  }
625  break;
626  }
627 
628  geometry->setVertexArray( vertices );
629  osg::DrawElementsUInt* lines = new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 );
630 
631  for( size_t i = 0; i < vertices->size(); ++i )
632  {
633  lines->push_back( i );
634  }
635  geometry->addPrimitiveSet( lines );
636 
637  osg::StateSet* state = geometry->getOrCreateStateSet();
638  state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
639 
640  gridGeode->addDrawable( geometry );
641 
642  m_rulerNode->addChild( gridGeode );
643 }
644 
646 {
647  if( ( m_viewAngle == 2 ) || ( m_viewAngle == 3 ) || ( m_viewAngle == 4 ) || ( m_viewAngle == 5 ) )
648  {
649  position += 1.0;
650  }
651  else
652  {
653  position -= 1.0;
654  }
655 
656  osg::ref_ptr< osg::Geode > gridGeode = osg::ref_ptr< osg::Geode >( new osg::Geode() );
657  osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >( new osg::Geometry() );
658  osg::Vec3Array* vertices = new osg::Vec3Array;
659 
660  WBoundingBox boundingBox = m_coordConverter->getBoundingBox();
661  WPosition p1 = boundingBox.getMin();
662  WPosition p2 = boundingBox.getMax();
663 
664  switch( m_coordConverter->getCoordinateSystemMode() )
665  {
666  case CS_WORLD:
667  case CS_CANONICAL:
668  for( int i = p1[0]; i < p2[0] + 2; ++i )
669  {
670  if( m_coordConverter->numberToCsX( i ) % 10 == 0 )
671  {
672  vertices->push_back( osg::Vec3( i, position, p1[2] ) );
673  vertices->push_back( osg::Vec3( i, position, p2[2] + 1 ) );
674  }
675  }
676  for( int i = p1[2]; i < p2[2] + 2; ++i )
677  {
678  if( m_coordConverter->numberToCsZ( i ) % 10 == 0 )
679  {
680  vertices->push_back( osg::Vec3( p1[1], position, i ) );
681  vertices->push_back( osg::Vec3( p2[1] + 1, position, i ) );
682  }
683  }
684  break;
685  case CS_TALAIRACH:
686  {
687  std::shared_ptr< WTalairachConverter > tc = m_coordConverter->getTalairachConverter();
688 
689  for( int i = -80; i < 81; i += 10 )
690  {
691  WVector3d tmpPoint1 = m_coordConverter->t2w( WVector3d( 0, i, -50 ) );
692  WVector3d tmpPoint2 = m_coordConverter->t2w( WVector3d( 0, i, 80 ) );
693 
694  vertices->push_back( osg::Vec3( tmpPoint1[0], position, tmpPoint1[2] ) );
695  vertices->push_back( osg::Vec3( tmpPoint2[0], position, tmpPoint2[2] ) );
696  }
697  for( int i = -50; i < 81; i += 10 )
698  {
699  WVector3d tmpPoint1 = m_coordConverter->t2w( WVector3d( 0, -80, i ) );
700  WVector3d tmpPoint2 = m_coordConverter->t2w( WVector3d( 0, 80, i ) );
701 
702  vertices->push_back( osg::Vec3( tmpPoint1[0], position, tmpPoint1[2] ) );
703  vertices->push_back( osg::Vec3( tmpPoint2[0], position, tmpPoint2[2] ) );
704  }
705  }
706  break;
707  }
708 
709  geometry->setVertexArray( vertices );
710  osg::DrawElementsUInt* lines = new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 );
711 
712  for( size_t i = 0; i < vertices->size(); ++i )
713  {
714  lines->push_back( i );
715  }
716  geometry->addPrimitiveSet( lines );
717 
718  osg::StateSet* state = geometry->getOrCreateStateSet();
719  state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
720 
721  gridGeode->addDrawable( geometry );
722 
723  m_rulerNode->addChild( gridGeode );
724 }
725 
726 void WMCoordinateSystem::addAxialGrid( float position )
727 {
728  if( ( m_viewAngle == 1 ) || ( m_viewAngle == 2 ) || ( m_viewAngle == 5 ) || ( m_viewAngle == 6 ) )
729  {
730  position += 1.0;
731  }
732  else
733  {
734  position -= 1.0;
735  }
736 
737  osg::ref_ptr< osg::Geode > gridGeode = osg::ref_ptr< osg::Geode >( new osg::Geode() );
738  osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >( new osg::Geometry() );
739  osg::Vec3Array* vertices = new osg::Vec3Array;
740 
741  WBoundingBox boundingBox = m_coordConverter->getBoundingBox();
742  WPosition p1 = boundingBox.getMin();
743  WPosition p2 = boundingBox.getMax();
744 
745  switch( m_coordConverter->getCoordinateSystemMode() )
746  {
747  case CS_WORLD:
748  case CS_CANONICAL:
749  for( int i = p1[1]; i < p2[1] + 2; ++i )
750  {
751  if( m_coordConverter->numberToCsY( i ) % 10 == 0 )
752  {
753  vertices->push_back( osg::Vec3( p1[0], i, position ) );
754  vertices->push_back( osg::Vec3( p2[0] + 1, i, position ) );
755  }
756  }
757  for( int i = p1[0]; i < p2[0] + 2; ++i )
758  {
759  if( m_coordConverter->numberToCsZ( i ) % 10 == 0 )
760  {
761  vertices->push_back( osg::Vec3( i, p1[1], position ) );
762  vertices->push_back( osg::Vec3( i, p2[1] + 1, position ) );
763  }
764  }
765  break;
766  case CS_TALAIRACH:
767  {
768  std::shared_ptr< WTalairachConverter > tc = m_coordConverter->getTalairachConverter();
769 
770  for( int i = -80; i < 81; i += 10 )
771  {
772  WVector3d tmpPoint1 = m_coordConverter->t2w( WVector3d( -110, i, 0 ) );
773  WVector3d tmpPoint2 = m_coordConverter->t2w( WVector3d( 80, i, 0 ) );
774 
775  vertices->push_back( osg::Vec3( tmpPoint1[0], tmpPoint1[1], position ) );
776  vertices->push_back( osg::Vec3( tmpPoint2[0], tmpPoint2[1], position ) );
777  }
778  for( int i = -110; i < 81; i += 10 )
779  {
780  WVector3d tmpPoint1 = m_coordConverter->t2w( WVector3d( i, -80, 0 ) );
781  WVector3d tmpPoint2 = m_coordConverter->t2w( WVector3d( i, 80, 0 ) );
782 
783  vertices->push_back( osg::Vec3( tmpPoint1[0], tmpPoint1[1], position ) );
784  vertices->push_back( osg::Vec3( tmpPoint2[0], tmpPoint2[1], position ) );
785  }
786  }
787  break;
788  }
789 
790  geometry->setVertexArray( vertices );
791  osg::DrawElementsUInt* lines = new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 );
792 
793  for( size_t i = 0; i < vertices->size(); ++i )
794  {
795  lines->push_back( i );
796  }
797  geometry->addPrimitiveSet( lines );
798 
799  osg::StateSet* state = geometry->getOrCreateStateSet();
800  state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
801 
802  gridGeode->addDrawable( geometry );
803 
804  m_rulerNode->addChild( gridGeode );
805 }
const vec_type & getMax() const
Gives the back upper right aka maximum corner.
Definition: WBoundingBox.h:308
const vec_type & getMin() const
Gives the front lower left aka minimum corner.
Definition: WBoundingBox.h:302
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 provide conversion for a given coordinate in 3D space.
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
A class containing a list of named items.
This class represents a subset of a WItemSelection.
Definition: WItemSelector.h:53
virtual const std::shared_ptr< WItemSelectionItem > at(size_t index) const
Gets the selected item with the given index.
virtual size_t getItemIndexOfSelected(size_t index) const
Helps to get the index of an selected item in the WItemSelection.
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
class that implements the various coordinate systems as overlays within the 3D view
std::shared_ptr< WCoordConverter > m_coordConverter
stores pointer
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
void propertyChanged()
Callback to listen for property changes.
WPropPosition m_brb
upper boundary of the dataset
bool m_dirty
flag true if something happened that requires redrawing of gfx
void addRulersSagittal()
helper function to create rulers
osg::ref_ptr< osg::Group > m_rulerNode
node for the bounding box
std::shared_ptr< WModuleInputData< WDataSetScalar > > m_input
Input connector required by this module.
virtual const std::string getName() const
void addRulersAxial()
helper function to create rulers
int m_viewAngle
stores the last view angle
WPropPosition m_ac
anterior commissure
WMCoordinateSystem()
standard constructor
virtual void moduleMain()
WPropBool m_showSagittal
show rulers on the sagittal slice
WPropTrigger m_ihpTrigger
button to reset the ihp point;
WPropPosition m_flt
lower boundary of the dataset
WPropBool m_showGridAxial
show grid on the axial slice
WPropBool m_showCoronal
show rulers on the coronal slice
WPropBool m_showAxial
show rulers on the axial slice
void updateCallback()
the shader object for this module
WPropPosition m_ihp
inter hemispherical point
WPropSelection m_csSelection
selection for coordinate system mode
std::shared_ptr< WItemSelection > m_possibleSelections
selection for coordinate system mode
void addSagittalGrid(float position)
helper function to create a grid overlay on the sagittal slice
void findBoundingBox()
helper function that computes the innerBoundingBox for the actual data
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...
void initTalairachConverter()
creates and initializes a talairach converter object
virtual ~WMCoordinateSystem()
destructor
osg::ref_ptr< WGEGroupNode > m_rootNode
the root node for this module
WPropTrigger m_pcTrigger
button to reset the pc point
std::shared_ptr< const WDataSetScalar > m_dataSet
pointer to dataSet to be able to access it throughout the whole module.
virtual void connectors()
Initialize the connectors this module is using.
WPropBool m_showGridCoronal
show grid on the coronal slice
virtual const std::string getDescription() const
void addAxialGrid(float position)
helper function to create a grid overlay on the axial slice
WPropTrigger m_acTrigger
button to reset the ac point
WPropPosition m_crosshair
position of the navigation slices
virtual void activate()
Callback for m_active.
void properties()
initialize the properties for this module
WPropPosition m_pc
posterior commissure
void addRulersCoronal()
helper function to create rulers
void addCoronalGrid(float position)
helper function to create a grid overlay on the coronal slice
float m_drawOffset
offset from slices to draw geometry on
WPropBool m_showGridSagittal
show grid on the sagittal slice
WPropBool m_showNumbersOnRulers
show/hide numbers on rulers
void createGeometry()
initial creation function for the slice geometry
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
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
virtual void activate()
Callback for m_active.
Definition: WModule.cpp:220
WPropBool m_active
True whenever the module should be active.
Definition: WModule.h:723
wlog::WStreamedLogger infoLog() const
Logger instance for comfortable info logging.
Definition: WModule.cpp:565
virtual void connectors()
Initialize connectors in this function.
Definition: WModule.cpp:208
This only is a 3d double vector.
boost::function< void(std::shared_ptr< WPropertyBase >)> PropertyChangeNotifierType
Signal signature emitted during set operations.
class to implement rulers orthogonally
Definition: WRulerOrtho.h:52
class to provide conversions between world or voxel space coordinates und Talairach coordinates
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
@ 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_NOTEMPTY constraint to the property.
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.