Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkConnectomicsNetworkMapper3D.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 #include <vtkMutableUndirectedGraph.h>
20 #include "vtkGraphLayout.h"
21 #include <vtkPoints.h>
22 #include "vtkGraphToPolyData.h"
23 #include <vtkPassThroughLayoutStrategy.h>
24 #include "vtkGlyph3D.h"
25 #include "vtkGlyphSource2D.h"
26 
37 #include <mbilog.h>
38 #include <vtkIndent.h>
39 
40 #include <string>
41 
42 #include <algorithm>
43 
45 {
48 }
49 
51 {
52  m_NetworkAssembly->Delete();
53 }
54 
56 {
57  if( this-> GetInput() == nullptr )
58  {
59  renderer-> GetOverlayManager()-> RemoveOverlay( m_TextOverlay3D.GetPointer() );
60  return;
61  }
62 
63  bool propertiesHaveChanged = this-> PropertiesChanged();
64 
65  if( this-> GetInput()-> GetIsModified() || propertiesHaveChanged )
66  {
67 
68  m_NetworkAssembly-> Delete();
69  m_NetworkAssembly = vtkPropAssembly::New();
70 
71  // Here is the part where a graph is given and converted to points and connections between points...
72  std::vector< mitk::ConnectomicsNetwork::NetworkNode > vectorOfNodes = this->GetInput()->GetVectorOfAllNodes();
73  std::vector< std::pair<
74  std::pair< mitk::ConnectomicsNetwork::NetworkNode, mitk::ConnectomicsNetwork::NetworkNode >
75  , mitk::ConnectomicsNetwork::NetworkEdge > > vectorOfEdges = this->GetInput()->GetVectorOfAllEdges();
76 
77  // Decide on the style of rendering due to property
78  if( m_ChosenRenderingScheme == connectomicsRenderingMITKScheme )
79  {
80  mitk::Point3D tempWorldPoint, tempCNFGeometryPoint;
81 
83  if( ( m_ChosenNodeLabel == "" || m_ChosenNodeLabel == "-1" ) && m_TextOverlay3D )
84  {
85  renderer-> GetOverlayManager()-> RemoveOverlay( m_TextOverlay3D.GetPointer() );
86  GetDataNode()-> SetProperty( connectomicsRenderingBalloonTextName.c_str(), mitk::StringProperty::New(""), nullptr );
87  GetDataNode()-> SetProperty( connectomicsRenderingBalloonNodeStatsName.c_str(), mitk::StringProperty::New(""), nullptr );
88  }
89 
91  std::vector< double > vectorOfNodeRadiusParameterValues;
92  vectorOfNodeRadiusParameterValues.resize( vectorOfNodes.size() );
93  double maxNodeRadiusParameterValue( FillNodeParameterVector( &vectorOfNodeRadiusParameterValues, m_NodeRadiusParameter ) );
94 
95  std::vector< double > vectorOfNodeColorParameterValues;
96  vectorOfNodeColorParameterValues.resize( vectorOfNodes.size() );
97  double maxNodeColorParameterValue( FillNodeParameterVector( &vectorOfNodeColorParameterValues, m_NodeColorParameter ) );
98 
99  std::vector< double > vectorOfEdgeRadiusParameterValues;
100  vectorOfEdgeRadiusParameterValues.resize( vectorOfEdges.size() );
101  double maxEdgeRadiusParameterValue( FillEdgeParameterVector( &vectorOfEdgeRadiusParameterValues, m_EdgeRadiusParameter ) );
102 
103  std::vector< double > vectorOfEdgeColorParameterValues;
104  vectorOfEdgeColorParameterValues.resize( vectorOfEdges.size() );
105  double maxEdgeColorParameterValue( FillEdgeParameterVector( &vectorOfEdgeColorParameterValues, m_EdgeColorParameter ) );
106 
108  // true will be rendered
109  std::vector< bool > vectorOfNodeFilterBools( vectorOfNodes.size(), true );
110  if( m_ChosenNodeFilter == connectomicsRenderingNodeThresholdingFilter )
111  {
112  FillNodeFilterBoolVector( &vectorOfNodeFilterBools, m_NodeThresholdParameter );
113  }
114 
115  std::vector< bool > vectorOfEdgeFilterBools( vectorOfEdges.size(), true );
116  if( m_ChosenEdgeFilter == connectomicsRenderingEdgeThresholdFilter )
117  {
118  FillEdgeFilterBoolVector( &vectorOfEdgeFilterBools, m_EdgeThresholdParameter );
119  }
120 
121 
123  std::stringstream nodeLabelStream; //local stream variable to hold csv list of node label names and node label numbers.
124 
125  for(unsigned int i = 0; i < vectorOfNodes.size(); i++)
126  {
127  vtkSmartPointer<vtkSphereSource> sphereSource =
129 
130  for(unsigned int dimension = 0; dimension < 3; dimension++)
131  {
132  tempCNFGeometryPoint.SetElement( dimension , vectorOfNodes[i].coordinates[dimension] );
133  }
134 
135  GetDataNode()->GetData()->GetGeometry()->IndexToWorld( tempCNFGeometryPoint, tempWorldPoint );
136 
137  sphereSource->SetCenter( tempWorldPoint[0] , tempWorldPoint[1], tempWorldPoint[2] );
138 
139  // determine radius
140  double radiusFactor = vectorOfNodeRadiusParameterValues[i] / maxNodeRadiusParameterValue;
141 
142  double radius = m_NodeRadiusStart + ( m_NodeRadiusEnd - m_NodeRadiusStart) * radiusFactor;
143  sphereSource->SetRadius( radius );
144 
145  vtkSmartPointer<vtkPolyDataMapper> mapper =
147  mapper->SetInputConnection(sphereSource->GetOutputPort());
148 
149  vtkSmartPointer<vtkActor> actor =
151  actor->SetMapper(mapper);
152 
153  // determine color
154  double colorFactor = vectorOfNodeColorParameterValues[i] / maxNodeColorParameterValue;
155 
156  double redStart = m_NodeColorStart.GetElement( 0 );
157  double greenStart = m_NodeColorStart.GetElement( 1 );
158  double blueStart = m_NodeColorStart.GetElement( 2 );
159  double redEnd = m_NodeColorEnd.GetElement( 0 );
160  double greenEnd = m_NodeColorEnd.GetElement( 1 );
161  double blueEnd = m_NodeColorEnd.GetElement( 2 );
162 
163  double red = redStart + ( redEnd - redStart ) * colorFactor;
164  double green = greenStart + ( greenEnd - greenStart ) * colorFactor;
165  double blue = blueStart + ( blueEnd - blueStart ) * colorFactor;
166 
167  actor->GetProperty()->SetColor( red, green, blue);
168 
169  //append to csv list of nodelabels.
170  nodeLabelStream << m_Translator-> GetName( std::stoi( vectorOfNodes[i].label ) )
171  << ": " << vectorOfNodes[i].label << ",";
172 
173  if( vectorOfNodeFilterBools[i] )
174  {
175  if( vectorOfNodes[i].label == m_ChosenNodeLabel )
176  { // if chosen and enabled, show information in Balloon or TextOverlay:
177  // What to show:
178  std::stringstream balloonStringstream;
179  balloonStringstream << "Node id: " << vectorOfNodes[i].id
180  << "\nlabel: " << vectorOfNodes[i].label
181  << "\nname: "
182  << m_Translator-> GetName( std::stoi( vectorOfNodes[i].label ) )
183  << std::endl;
184  m_BalloonText = balloonStringstream.str();
185  GetDataNode()->
186  SetProperty( connectomicsRenderingBalloonTextName.c_str(),
187  mitk::StringProperty::New( m_BalloonText.c_str()), nullptr );
188 
189  std::stringstream balloonNodeStatsStream;
190  balloonNodeStatsStream
191  << "Coordinates: (" << vectorOfNodes[i].coordinates[0]
192  << " ; " << vectorOfNodes[i].coordinates[1]
193  << " ; " << vectorOfNodes[i].coordinates[2] << " )"
194  << "\nDegree: "
195  << ( this-> GetInput()-> GetDegreeOfNodes() ).at( vectorOfNodes[i].id )
196  << "\nBetweenness centrality: "
197  << ( this->GetInput()->GetNodeBetweennessVector() ).at( vectorOfNodes[i].id )
198  << "\nClustering coefficient: "
199  << ( this->GetInput()->GetLocalClusteringCoefficients()).at( vectorOfNodes[i].id )
200  << std::endl;
201  m_BalloonNodeStats = balloonNodeStatsStream.str();
202  GetDataNode()->
203  SetProperty( connectomicsRenderingBalloonNodeStatsName.c_str(),
204  mitk::StringProperty::New( m_BalloonNodeStats.c_str()), nullptr );
205 
206  // Where to show:
207  float r[3];
208  r[0]= vectorOfNodes[i].coordinates[0];
209  r[1]= vectorOfNodes[i].coordinates[1];
210  r[2]= vectorOfNodes[i].coordinates[2];
211  mitk::Point3D BalloonAnchor( r );
212  mitk::Point3D BalloonAnchorWorldCoord( r );
213  GetDataNode()-> GetData()-> GetGeometry()-> IndexToWorld( BalloonAnchor, BalloonAnchorWorldCoord );
214 
215  // How to show:
216  if( m_ChosenNodeLabel != "-1" )
217  {
218  if (m_TextOverlay3D != nullptr)
219  {
220  renderer-> GetOverlayManager()-> RemoveOverlay( m_TextOverlay3D.GetPointer() );
221  }
222  m_TextOverlay3D = mitk::TextOverlay3D::New();
223  renderer-> GetOverlayManager()-> AddOverlay( m_TextOverlay3D.GetPointer() );
224  m_TextOverlay3D-> SetFontSize( 2 );
225  m_TextOverlay3D-> SetColor( 0.96, 0.69, 0.01 );
226  m_TextOverlay3D-> SetOpacity( 0.81 );
227  m_TextOverlay3D-> SetPosition3D( BalloonAnchorWorldCoord );
228  m_TextOverlay3D-> SetText( "...." + m_BalloonText );
229  m_TextOverlay3D-> SetForceInForeground( true ); // TODO: does not work anymore.
230  m_TextOverlay3D-> SetVisibility( GetDataNode()-> IsVisible( renderer ) );
231  renderer-> GetOverlayManager()-> UpdateOverlays( renderer );
232  // Colorize chosen node:
233  actor-> GetProperty()-> SetColor( 1.0, 0.69, 0.01);
234  }
235  }
236  m_NetworkAssembly-> AddPart( actor );
237  }
238  }
239  m_AllNodeLabels = nodeLabelStream.str(); // Store all Node Names and Node Labels in 1 Property.
240  m_AllNodeLabels.erase( m_AllNodeLabels.rfind(","), 1 ); // remove trailing ,.
241  GetDataNode()->
243  mitk::StringProperty::New( m_AllNodeLabels.c_str() ), nullptr );
244 
245 
247  for(unsigned int i = 0; i < vectorOfEdges.size(); i++)
248  {
249 
250  vtkSmartPointer<vtkLineSource> lineSource =
252 
253  for(unsigned int dimension = 0; dimension < 3; dimension++)
254  {
255  tempCNFGeometryPoint[ dimension ] = vectorOfEdges[i].first.first.coordinates[dimension];
256  }
257 
258  GetDataNode()->GetData()->GetGeometry()->IndexToWorld( tempCNFGeometryPoint, tempWorldPoint );
259 
260  lineSource->SetPoint1(tempWorldPoint[0], tempWorldPoint[1],tempWorldPoint[2] );
261 
262  for(unsigned int dimension = 0; dimension < 3; dimension++)
263  {
264  tempCNFGeometryPoint[ dimension ] = vectorOfEdges[i].first.second.coordinates[dimension];
265  }
266 
267  GetDataNode()->GetData()->GetGeometry()->IndexToWorld( tempCNFGeometryPoint, tempWorldPoint );
268 
269  lineSource->SetPoint2(tempWorldPoint[0], tempWorldPoint[1], tempWorldPoint[2] );
270 
271  vtkSmartPointer<vtkTubeFilter> tubes = vtkSmartPointer<vtkTubeFilter>::New();
272  tubes->SetInputConnection( lineSource->GetOutputPort() );
273  tubes->SetNumberOfSides( 12 );
274 
275  // determine radius
276  double radiusFactor = vectorOfEdgeRadiusParameterValues[i] / maxEdgeRadiusParameterValue;
277 
278  double radius = m_EdgeRadiusStart + ( m_EdgeRadiusEnd - m_EdgeRadiusStart) * radiusFactor;
279  tubes->SetRadius( radius );
280 
281  // originally we used a logarithmic scaling,
282  // double radiusFactor = 1.0 + ((double) vectorOfEdges[i].second.weight) / 10.0 ;
283  // tubes->SetRadius( std::log10( radiusFactor ) );
284 
285  vtkSmartPointer<vtkPolyDataMapper> mapper2 =
287  mapper2->SetInputConnection( tubes->GetOutputPort() );
288 
289  vtkSmartPointer<vtkActor> actor =
291  actor->SetMapper(mapper2);
292 
293  // determine color
294  double colorFactor = vectorOfEdgeColorParameterValues[i] / maxEdgeColorParameterValue;
295 
296  double redStart = m_EdgeColorStart.GetElement( 0 );
297  double greenStart = m_EdgeColorStart.GetElement( 1 );
298  double blueStart = m_EdgeColorStart.GetElement( 2 );
299  double redEnd = m_EdgeColorEnd.GetElement( 0 );
300  double greenEnd = m_EdgeColorEnd.GetElement( 1 );
301  double blueEnd = m_EdgeColorEnd.GetElement( 2 );
302 
303  double red = redStart + ( redEnd - redStart ) * colorFactor;
304  double green = greenStart + ( greenEnd - greenStart ) * colorFactor;
305  double blue = blueStart + ( blueEnd - blueStart ) * colorFactor;
306 
307  actor->GetProperty()->SetColor( red, green, blue);
308 
309  if( vectorOfEdgeFilterBools[i] )
310  {
311  m_NetworkAssembly->AddPart(actor);
312  }
313  }
314  }
315  else if( m_ChosenRenderingScheme == connectomicsRenderingVTKScheme )
316  {
317  vtkSmartPointer<vtkMutableUndirectedGraph> graph =
319 
320  std::vector< vtkIdType > networkToVTKvector;
321  networkToVTKvector.resize(vectorOfNodes.size());
322 
323  for(unsigned int i = 0; i < vectorOfNodes.size(); i++)
324  {
325  networkToVTKvector[vectorOfNodes[i].id] = graph->AddVertex();
326  }
327 
328  for(unsigned int i = 0; i < vectorOfEdges.size(); i++)
329  {
330  graph->AddEdge(networkToVTKvector[vectorOfEdges[i].first.first.id],
331  networkToVTKvector[vectorOfEdges[i].first.second.id]);
332  }
333 
334  vtkSmartPointer<vtkPoints> points =
336  for(unsigned int i = 0; i < vectorOfNodes.size(); i++)
337  {
338  double x = vectorOfNodes[i].coordinates[0];
339  double y = vectorOfNodes[i].coordinates[1];
340  double z = vectorOfNodes[i].coordinates[2];
341  points->InsertNextPoint( x, y, z);
342  }
343 
344  graph->SetPoints(points);
345 
346  vtkGraphLayout* layout = vtkGraphLayout::New();
347  layout->SetInputData(graph);
348  vtkPassThroughLayoutStrategy* ptls = vtkPassThroughLayoutStrategy::New();
349  layout->SetLayoutStrategy( ptls );
350 
351  vtkGraphToPolyData* graphToPoly = vtkGraphToPolyData::New();
352  graphToPoly->SetInputConnection(layout->GetOutputPort());
353 
354  // Create the standard VTK polydata mapper and actor
355  // for the connections (edges) in the tree.
356  vtkPolyDataMapper* edgeMapper = vtkPolyDataMapper::New();
357  edgeMapper->SetInputConnection(graphToPoly->GetOutputPort());
358  vtkActor* edgeActor = vtkActor::New();
359  edgeActor->SetMapper(edgeMapper);
360  edgeActor->GetProperty()->SetColor(0.0, 0.5, 1.0);
361 
362  // Glyph the points of the tree polydata to create
363  // VTK_VERTEX cells at each vertex in the tree.
364  vtkGlyph3D* vertGlyph = vtkGlyph3D::New();
365  vertGlyph->SetInputConnection(0, graphToPoly->GetOutputPort());
366  vtkGlyphSource2D* glyphSource = vtkGlyphSource2D::New();
367  glyphSource->SetGlyphTypeToVertex();
368  vertGlyph->SetInputConnection(1, glyphSource->GetOutputPort());
369 
370  // Create a mapper for the vertices, and tell the mapper
371  // to use the specified color array.
372  vtkPolyDataMapper* vertMapper = vtkPolyDataMapper::New();
373  vertMapper->SetInputConnection(vertGlyph->GetOutputPort());
374  /*if (colorArray)
375  {
376  vertMapper->SetScalarModeToUsePointFieldData();
377  vertMapper->SelectColorArray(colorArray);
378  vertMapper->SetScalarRange(colorRange);
379  }*/
380 
381  // Create an actor for the vertices. Move the actor forward
382  // in the z direction so it is drawn on top of the edge actor.
383  vtkActor* vertActor = vtkActor::New();
384  vertActor->SetMapper(vertMapper);
385  vertActor->GetProperty()->SetPointSize(5);
386  vertActor->SetPosition(0, 0, 0.001);
387  //vtkProp3D.h: virtual void SetPosition(double,double,double):
388  //Set/Get/Add the position of the Prop3D in world coordinates.
389  m_NetworkAssembly->AddPart(edgeActor);
390  m_NetworkAssembly->AddPart(vertActor);
391  }
392 
393  (static_cast<mitk::ConnectomicsNetwork * > ( GetDataNode()->GetData() ) )-> SetIsModified( false );
394  }
395 }
396 
398 {
399  return static_cast<const mitk::ConnectomicsNetwork * > ( GetDataNode()->GetData() );
400 }
401 
403 {
404  // Initialize enumeration properties
405  mitk::ConnectomicsRenderingSchemeProperty::Pointer connectomicsRenderingScheme =
407  mitk::ConnectomicsRenderingEdgeFilteringProperty::Pointer connectomicsRenderingEdgeFiltering =
409  mitk::ConnectomicsRenderingNodeFilteringProperty::Pointer connectomicsRenderingNodeFiltering =
411 
412  mitk::ConnectomicsRenderingNodeColorParameterProperty::Pointer connectomicsRenderingNodeGradientColorParameter =
414  mitk::ConnectomicsRenderingNodeRadiusParameterProperty::Pointer connectomicsRenderingNodeRadiusParameter =
416  mitk::ConnectomicsRenderingEdgeColorParameterProperty::Pointer connectomicsRenderingEdgeGradientColorParameter =
418  mitk::ConnectomicsRenderingEdgeRadiusParameterProperty::Pointer connectomicsRenderingEdgeRadiusParameter =
420 
421  mitk::ConnectomicsRenderingNodeThresholdParameterProperty::Pointer connectomicsRenderingNodeThresholdParameter =
423  mitk::ConnectomicsRenderingEdgeThresholdParameterProperty::Pointer connectomicsRenderingEdgeThresholdParameter =
425 
427 
428  // set the properties
430  connectomicsRenderingScheme, renderer, overwrite );
431 
433  connectomicsRenderingEdgeFiltering, renderer, overwrite );
435  connectomicsRenderingEdgeThresholdParameter, renderer, overwrite );
438 
440  connectomicsRenderingNodeFiltering, renderer, overwrite );
442  connectomicsRenderingNodeThresholdParameter, renderer, overwrite );
445 
451  connectomicsRenderingNodeGradientColorParameter, renderer, overwrite );
452 
454  connectomicsRenderingNodeRadiusStartDefault, renderer, overwrite );
456  connectomicsRenderingNodeRadiusEndDefault, renderer, overwrite );
458  connectomicsRenderingNodeRadiusParameter, renderer, overwrite );
459 
461  connectomicsRenderingNodeChosenNodeDefault, renderer, overwrite );
462 
468  connectomicsRenderingEdgeGradientColorParameter, renderer, overwrite );
469 
471  connectomicsRenderingEdgeRadiusStartDefault, renderer, overwrite );
473  connectomicsRenderingEdgeRadiusEndDefault, renderer, overwrite );
475  connectomicsRenderingEdgeRadiusParameter, renderer, overwrite );
476 
477  node-> AddProperty( connectomicsRenderingBalloonTextName.c_str(), balloonText,
478  nullptr, overwrite ); // renderer=nullptr: Property is renderer independent.
479 
480  Superclass::SetDefaultProperties(node, renderer, overwrite);
481 }
482 
484 {
485  mapper-> ImmediateModeRenderingOn();
486 }
487 
489 {
490  //TODO: implement
491 }
492 
494 {
495  return m_NetworkAssembly;
496 }
497 
499 {
502  this->GetDataNode()->GetProperty( connectomicsRenderingSchemePropertyName.c_str() ) );
505  this->GetDataNode()->GetProperty( connectomicsRenderingEdgeFilteringPropertyName.c_str() ) );
506  mitk::FloatProperty * edgeThreshold = static_cast< mitk::FloatProperty * > (
507  this->GetDataNode()->GetProperty( connectomicsRenderingEdgeThresholdFilterThresholdName.c_str() ) );
510  this->GetDataNode()->GetProperty( connectomicsRenderingNodeFilteringPropertyName.c_str() ) );
511 
514  this->GetDataNode()->GetProperty( connectomicsRenderingNodeThresholdFilterParameterName.c_str() ) );
517  this->GetDataNode()->GetProperty( connectomicsRenderingEdgeThresholdFilterParameterName.c_str() ) );
518 
519  mitk::FloatProperty * nodeThreshold = static_cast< mitk::FloatProperty * > (
520  this->GetDataNode()->GetProperty( connectomicsRenderingNodeThresholdFilterThresholdName.c_str() ) );
521  mitk::ColorProperty * nodeColorStart = static_cast< mitk::ColorProperty * > (
522  this->GetDataNode()->GetProperty( connectomicsRenderingNodeGradientStartColorName.c_str() ) );
523  mitk::ColorProperty * nodeColorEnd = static_cast< mitk::ColorProperty * > (
524  this->GetDataNode()->GetProperty( connectomicsRenderingNodeGradientEndColorName.c_str() ) );
525  mitk::FloatProperty * nodeRadiusStart = static_cast< mitk::FloatProperty * > (
526  this->GetDataNode()->GetProperty( connectomicsRenderingNodeRadiusStartName.c_str() ) );
527  mitk::FloatProperty * nodeRadiusEnd = static_cast< mitk::FloatProperty * > (
528  this->GetDataNode()->GetProperty( connectomicsRenderingNodeRadiusEndName.c_str() ) );
529  mitk::StringProperty * chosenNode = static_cast< mitk::StringProperty * > (
530  this->GetDataNode()->GetProperty( connectomicsRenderingNodeChosenNodeName.c_str() ) );
531  mitk::ColorProperty * edgeColorStart = static_cast< mitk::ColorProperty * > (
532  this->GetDataNode()->GetProperty( connectomicsRenderingEdgeGradientStartColorName.c_str() ) );
533  mitk::ColorProperty * edgeColorEnd = static_cast< mitk::ColorProperty * > (
534  this->GetDataNode()->GetProperty( connectomicsRenderingEdgeGradientEndColorName.c_str() ) );
535  mitk::FloatProperty * edgeRadiusStart = static_cast< mitk::FloatProperty * > (
536  this->GetDataNode()->GetProperty( connectomicsRenderingEdgeRadiusStartName.c_str() ) );
537  mitk::FloatProperty * edgeRadiusEnd = static_cast< mitk::FloatProperty * > (
538  this->GetDataNode()->GetProperty( connectomicsRenderingEdgeRadiusEndName.c_str() ) );
541  this->GetDataNode()->GetProperty( connectomicsRenderingNodeGradientColorParameterName.c_str() ) );
544  this->GetDataNode()->GetProperty( connectomicsRenderingNodeRadiusParameterName.c_str() ) );
547  this->GetDataNode()->GetProperty( connectomicsRenderingEdgeGradientColorParameterName.c_str() ) );
550  this->GetDataNode()->GetProperty( connectomicsRenderingEdgeRadiusParameterName.c_str() ) );
551 
552  if(
553  m_ChosenRenderingScheme != renderingScheme->GetValueAsString() ||
554  m_ChosenEdgeFilter != edgeFilter->GetValueAsString() ||
555  m_EdgeThreshold != edgeThreshold->GetValue() ||
556  m_EdgeThresholdParameter != edgeThresholdParameter->GetValueAsString() ||
557  m_ChosenNodeFilter != nodeFilter->GetValueAsString() ||
558  m_NodeThreshold != nodeThreshold->GetValue() ||
559  m_NodeThresholdParameter != nodeThresholdParameter->GetValueAsString() ||
560  m_NodeColorStart != nodeColorStart->GetValue() ||
561  m_NodeColorEnd != nodeColorEnd->GetValue() ||
562  m_NodeRadiusStart != nodeRadiusStart->GetValue() ||
563  m_NodeRadiusEnd != nodeRadiusEnd->GetValue() ||
564  m_ChosenNodeLabel != chosenNode->GetValueAsString() ||
565  m_EdgeColorStart != edgeColorStart->GetValue() ||
566  m_EdgeColorEnd != edgeColorEnd->GetValue() ||
567  m_EdgeRadiusStart != edgeRadiusStart->GetValue() ||
568  m_EdgeRadiusEnd != edgeRadiusEnd->GetValue() ||
569  m_NodeColorParameter != nodeColorParameter->GetValueAsString() ||
570  m_NodeRadiusParameter != nodeRadiusParameter->GetValueAsString() ||
571  m_EdgeColorParameter != edgeColorParameter->GetValueAsString() ||
572  m_EdgeRadiusParameter != edgeRadiusParameter->GetValueAsString() )
573  {
574  m_ChosenRenderingScheme = renderingScheme->GetValueAsString();
575  m_ChosenEdgeFilter = edgeFilter->GetValueAsString();
576  m_EdgeThreshold = edgeThreshold->GetValue();
577  m_EdgeThresholdParameter = edgeThresholdParameter->GetValueAsString();
578  m_ChosenNodeFilter = nodeFilter->GetValueAsString();
579  m_NodeThreshold = nodeThreshold->GetValue();
580  m_NodeThresholdParameter = nodeThresholdParameter->GetValueAsString();
581  m_NodeColorStart = nodeColorStart->GetValue();
582  m_NodeColorEnd = nodeColorEnd->GetValue();
583  m_NodeRadiusStart = nodeRadiusStart->GetValue();
584  m_NodeRadiusEnd = nodeRadiusEnd->GetValue();
585  m_ChosenNodeLabel = chosenNode->GetValueAsString();
586  m_EdgeColorStart = edgeColorStart->GetValue();
587  m_EdgeColorEnd = edgeColorEnd->GetValue();
588  m_EdgeRadiusStart = edgeRadiusStart->GetValue();
589  m_EdgeRadiusEnd = edgeRadiusEnd->GetValue();
590  m_NodeColorParameter = nodeColorParameter->GetValueAsString();
591  m_NodeRadiusParameter = nodeRadiusParameter->GetValueAsString();
592  m_EdgeColorParameter = edgeColorParameter->GetValueAsString();
593  m_EdgeRadiusParameter = edgeRadiusParameter->GetValueAsString();
594 
595  return true;
596  }
597 
598  return false;
599 }
600 
601 double mitk::ConnectomicsNetworkMapper3D::FillNodeParameterVector( std::vector< double > * parameterVector, std::string parameterName )
602 {
603  int end( parameterVector->size() );
604 
605  // constant parameter - uniform style
606  if( parameterName == connectomicsRenderingNodeParameterConstant )
607  {
608  for(int index(0); index < end; index++)
609  {
610  parameterVector->at( index ) = 1.0;
611  }
612  return 1.0;
613  }
614 
615  double maximum( 0.0 );
616 
617  // using the degree as parameter
618  if( parameterName == connectomicsRenderingNodeParameterDegree )
619  {
620  std::vector< int > vectorOfDegree = this->GetInput()->GetDegreeOfNodes();
621  for(int index(0); index < end; index++)
622  {
623  parameterVector->at( index ) = vectorOfDegree[ index ];
624  }
625  maximum = *std::max_element( parameterVector->begin(), parameterVector->end() );
626  }
627 
628  // using betweenness centrality as parameter
629  if( parameterName == connectomicsRenderingNodeParameterBetweenness )
630  {
631  std::vector< double > vectorOfBetweenness = this->GetInput()->GetNodeBetweennessVector();
632  for(int index(0); index < end; index++)
633  {
634  parameterVector->at( index ) = vectorOfBetweenness[index];
635  }
636  maximum = *std::max_element( parameterVector->begin(), parameterVector->end() );
637  }
638 
639  // using clustering coefficient as parameter
640  if( parameterName == connectomicsRenderingNodeParameterClustering )
641  {
642  const std::vector< double > vectorOfClustering = this->GetInput()->GetLocalClusteringCoefficients();
643  for(int index(0); index < end; index++)
644  {
645  parameterVector->at( index ) = vectorOfClustering[index];
646  }
647  maximum = *std::max_element( parameterVector->begin(), parameterVector->end() );
648  }
649 
650  // using distance to a specific node as parameter
652  {
653  bool labelFound( this->GetInput()->CheckForLabel( m_ChosenNodeLabel ) );
654  // check whether the chosen node is valid
655  if( !labelFound )
656  {
657  MITK_WARN << "Node chosen for rendering is not valid.";
658  for(int index(0); index < end; index++)
659  {
660  parameterVector->at( index ) = 1.0;
661  }
662  return 1.0;
663  }
664  else
665  {
666  const std::vector< double > distanceVector = this->GetInput()->GetShortestDistanceVectorFromLabel( m_ChosenNodeLabel );
667  for(int index(0); index < end; index++)
668  {
669  parameterVector->at( index ) = distanceVector[index];
670  }
671  maximum = *std::max_element( parameterVector->begin(), parameterVector->end() );
672  }
673  }
674 
675  // if the maximum is nearly zero
676  if( std::abs( maximum ) < mitk::eps )
677  {
678  maximum = 1.0;
679  }
680 
681  return maximum;
682 }
683 
684 double mitk::ConnectomicsNetworkMapper3D::FillEdgeParameterVector( std::vector< double > * parameterVector, std::string parameterName )
685 {
686  int end( parameterVector->size() );
687 
688  // constant parameter - uniform style
689  if( parameterName == connectomicsRenderingEdgeParameterConstant )
690  {
691  for(int index(0); index < end; index++)
692  {
693  parameterVector->at( index ) = 1.0;
694  }
695  return 1.0;
696  }
697 
698  double maximum( 0.0 );
699 
700  // using the weight as parameter
701  if( parameterName == connectomicsRenderingEdgeParameterWeight )
702  {
703  std::vector< std::pair<
704  std::pair< mitk::ConnectomicsNetwork::NetworkNode, mitk::ConnectomicsNetwork::NetworkNode >
705  , mitk::ConnectomicsNetwork::NetworkEdge > > vectorOfEdges = this->GetInput()->GetVectorOfAllEdges();
706  for(int index(0); index < end; index++)
707  {
708  parameterVector->at( index ) = vectorOfEdges[ index ].second.weight;
709  }
710  maximum = *std::max_element( parameterVector->begin(), parameterVector->end() );
711  }
712 
713  // using the edge centrality as parameter
714  if( parameterName == connectomicsRenderingEdgeParameterCentrality )
715  {
716  const std::vector< double > vectorOfCentrality = this->GetInput()->GetEdgeBetweennessVector();
717  for(int index(0); index < end; index++)
718  {
719  parameterVector->at( index ) = vectorOfCentrality[index];
720  }
721  maximum = *std::max_element( parameterVector->begin(), parameterVector->end() );
722  }
723 
724  // if the maximum is nearly zero
725  if( std::abs( maximum ) < mitk::eps )
726  {
727  maximum = 1.0;
728  }
729 
730  return maximum;
731 }
732 
733 void mitk::ConnectomicsNetworkMapper3D::FillNodeFilterBoolVector( std::vector< bool > * boolVector, std::string parameterName )
734 {
735  std::vector< double > parameterVector;
736  parameterVector.resize( boolVector->size() );
737  int end( parameterVector.size() );
738 
739  // using the degree as parameter
740  if( parameterName == connectomicsRenderingNodeParameterDegree )
741  {
742  std::vector< int > vectorOfDegree = this->GetInput()->GetDegreeOfNodes();
743  for(int index(0); index < end; index++)
744  {
745  parameterVector.at( index ) = vectorOfDegree[ index ];
746  }
747  }
748 
749  // using betweenness centrality as parameter
750  if( parameterName == connectomicsRenderingNodeParameterBetweenness )
751  {
752  std::vector< double > vectorOfBetweenness = this->GetInput()->GetNodeBetweennessVector();
753  for(int index(0); index < end; index++)
754  {
755  parameterVector.at( index ) = vectorOfBetweenness[index];
756  }
757  }
758 
759  // using clustering coefficient as parameter
760  if( parameterName == connectomicsRenderingNodeParameterClustering )
761  {
762  const std::vector< double > vectorOfClustering = this->GetInput()->GetLocalClusteringCoefficients();
763  for(int index(0); index < end; index++)
764  {
765  parameterVector.at( index ) = vectorOfClustering[index];
766  }
767  }
768 
769  for( int index( 0 ), end( boolVector->size() ); index < end; index++ )
770  {
771  if( parameterVector.at( index ) >= m_NodeThreshold )
772  {
773  boolVector->at( index ) = true;
774  }
775  else
776  {
777  boolVector->at( index ) = false;
778  }
779  }
780  return;
781 }
782 
783 void mitk::ConnectomicsNetworkMapper3D::FillEdgeFilterBoolVector( std::vector< bool > * boolVector, std::string parameterName )
784 {
785  std::vector< double > parameterVector;
786  parameterVector.resize( boolVector->size() );
787  int end( parameterVector.size() );
788 
789 
790  // using the weight as parameter
791  if( parameterName == connectomicsRenderingEdgeParameterWeight )
792  {
793  std::vector< std::pair<
794  std::pair< mitk::ConnectomicsNetwork::NetworkNode, mitk::ConnectomicsNetwork::NetworkNode >
795  , mitk::ConnectomicsNetwork::NetworkEdge > > vectorOfEdges = this->GetInput()->GetVectorOfAllEdges();
796 
797  for(int index(0); index < end; index++)
798  {
799  parameterVector.at( index ) = vectorOfEdges[ index ].second.weight;
800  }
801  }
802 
803  // using the edge centrality as parameter
804  if( parameterName == connectomicsRenderingEdgeParameterCentrality )
805  {
806  const std::vector< double > vectorOfCentrality = this->GetInput()->GetEdgeBetweennessVector();
807  for(int index(0); index < end; index++)
808  {
809  parameterVector.at( index ) = vectorOfCentrality[index];
810  }
811  }
812 
813  for( int index( 0 ), end( boolVector->size() ); index < end; index++ )
814  {
815  if( parameterVector.at( index ) >= m_EdgeThreshold )
816  {
817  boolVector->at( index ) = true;
818  }
819  else
820  {
821  boolVector->at( index ) = false;
822  }
823  }
824  return;
825 }
virtual std::string GetValueAsString() const override
const std::string connectomicsRenderingNodeThresholdingFilter
Only show nodes above a certain parameter threshold.
virtual std::string GetValueAsString() const override
const std::string connectomicsRenderingEdgeGradientStartColorName
Start Color.
const mitk::FloatProperty::Pointer connectomicsRenderingNodeRadiusStartDefault
const std::string connectomicsRenderingEdgeFilteringPropertyName
Edge filter option.
const std::string connectomicsRenderingEdgeRadiusParameterName
Radius parameter.
const std::string connectomicsRenderingEdgeThresholdFilterThresholdName
Threshold.
const std::string connectomicsRenderingNodeRadiusParameterName
Radius parameter.
const std::string connectomicsRenderingNodeParameterBetweenness
Using the node betweenness as parameter.
mitk::FreeSurferParcellationTranslator::Pointer m_Translator
virtual void GenerateDataForRenderer(mitk::BaseRenderer *renderer) override
Generate the data needed for rendering into renderer.
const std::string connectomicsRenderingNodeGradientStartColorName
Start Color.
const std::string connectomicsRenderingEdgeThresholdFilter
Show only edges above a certain parameter threshold.
const std::string connectomicsRenderingSchemePropertyName
Define the rendering scheme to be used.
const mitk::ColorProperty::Pointer connectomicsRenderingNodeGradientStartColorDefault
Organizes the rendering process.
const mitk::ColorProperty::Pointer connectomicsRenderingEdgeGradientEndColorDefault
const mitk::FloatProperty::Pointer connectomicsRenderingEdgeRadiusStartDefault
const std::string connectomicsRenderingEdgeParameterConstant
Constant.
double FillEdgeParameterVector(std::vector< double > *parameterVector, std::string parameterName)
const std::string connectomicsRenderingNodeThresholdFilterParameterName
Parameter to be thresholded.
bool PropertiesChanged()
Returns true if the properties have changed since the last data generation.
const std::string connectomicsRenderingNodeGradientEndColorName
End Color.
const std::string connectomicsRenderingNodeParameterClustering
Using the node clustering coefficient as parameter.
const mitk::FloatProperty::Pointer connectomicsRenderingEdgeThresholdFilterThresholdDefault
void FillNodeFilterBoolVector(std::vector< bool > *boolVector, std::string parameterName)
const std::string connectomicsRenderingNodeGradientColorParameterName
Color parameter.
const mitk::FloatProperty::Pointer connectomicsRenderingNodeThresholdFilterThresholdDefault
T::Pointer GetData(const std::string &name)
const mitk::FloatProperty::Pointer connectomicsRenderingEdgeRadiusEndDefault
This file defines the rendering properties available for connectomics networks in MITK...
The ColorProperty class RGB color property.
const std::string connectomicsRenderingMITKScheme
Slower but with several visualisation options.
const std::string connectomicsRenderingEdgeRadiusEndName
End Radius.
void AddProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr, bool overwrite=false)
Add the property (instance of BaseProperty) if it does not exist (or always ifoverwrite istrue) with ...
#define MITK_WARN
Definition: mitkLogMacros.h:23
const std::string connectomicsRenderingNodeThresholdFilterThresholdName
Threshold.
const std::string connectomicsRenderingEdgeRadiusStartName
Start Radius.
const std::string connectomicsRenderingEdgeParameterWeight
Using the weight as parameter.
const std::string connectomicsRenderingVTKScheme
Much faster but less features.
static void SetVtkMapperImmediateModeRendering(vtkMapper *mapper)
const std::string connectomicsRenderingBalloonAllNodeLabelsName
const std::string connectomicsRenderingEdgeParameterCentrality
Using the edge centrality as parameter.
const std::string connectomicsRenderingNodeParameterConstant
Constant.
const std::string connectomicsRenderingNodeRadiusEndName
End Radius.
void FillEdgeFilterBoolVector(std::vector< bool > *boolVector, std::string parameterName)
const std::string connectomicsRenderingNodeParameterDegree
Using the node degree as parameter.
const mitk::ColorProperty::Pointer connectomicsRenderingEdgeGradientStartColorDefault
const std::string connectomicsRenderingNodeFilteringPropertyName
Node filter option.
const std::string connectomicsRenderingNodeRadiusStartName
Start Radius.
static void SetDefaultProperties(DataNode *node, BaseRenderer *renderer=nullptr, bool overwrite=false)
double FillNodeParameterVector(std::vector< double > *parameterVector, std::string parameterName)
const std::string connectomicsRenderingEdgeThresholdFilterParameterName
Parameter to be thresholded.
const std::string connectomicsRenderingBalloonNodeStatsName
const std::string connectomicsRenderingNodeChosenNodeName
The chosen node label.
const std::string connectomicsRenderingEdgeGradientEndColorName
End Color.
MITKCORE_EXPORT const ScalarType eps
static std::string GetName(std::string fileName, std::string suffix)
virtual vtkProp * GetVtkProp(mitk::BaseRenderer *renderer) override
Property for strings.
const mitk::Color & GetValue() const
const mitk::StringProperty::Pointer connectomicsRenderingNodeChosenNodeDefault
virtual const mitk::ConnectomicsNetwork * GetInput()
Connectomics Network Class.
static Pointer New()
static Pointer New()
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
const mitk::FloatProperty::Pointer connectomicsRenderingNodeRadiusEndDefault
const std::string connectomicsRenderingBalloonTextName
Balloon controls and content.
const std::string connectomicsRenderingNodeParameterColoringShortestPath
Color nodes by shortest path length to a chosen node.
const std::string connectomicsRenderingEdgeGradientColorParameterName
Color parameter.
virtual T GetValue() const
const mitk::ColorProperty::Pointer connectomicsRenderingNodeGradientEndColorDefault
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.