Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkFreeSurferParcellationHandler.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 #include <mitkBaseRenderer.h>
19 #include <mitkDataStorage.h>
20 #include <mitkDataNode.h>
21 #include <mitkImage.h>
25 #include <mitkMousePressEvent.h>
26 #include <mitkMouseWheelEvent.h>
27 #include <usGetModuleContext.h>
28 #include <usModule.h>
29 #include <usModuleRegistry.h>
30 #include <usServiceProperties.h>
31 #include <string>
32 using namespace mitk;
33 using namespace std;
34 US_USE_NAMESPACE
35 
37  m_LastPixelvalue( 0 ),
38  m_Translator( mitk::FreeSurferParcellationTranslator::New() )
39 {
41  props["name"] = std::string("ParcellationHandler");
42  us::ModuleContext* context = us::ModuleRegistry::GetModule(1)->GetModuleContext();
43  m_ServiceRegistration = context->RegisterService<InteractionEventObserver>( this, props);
44 }
46 {
48 }
49 
50 void QmitkFreeSurferParcellationHandler::Notify(InteractionEvent *interactionEvent, bool isHandled)
51 {
52  Q_UNUSED( isHandled )
53  typedef itk::VectorContainer<unsigned int, mitk::DataNode::Pointer> SetOfObjects;
54  BaseRenderer* sender = interactionEvent->GetSender();
55  InteractionPositionEvent* positionEvent = static_cast<InteractionPositionEvent*>(interactionEvent);
57  DataStorage::SetOfObjects::ConstPointer nodes = sender->GetDataStorage()->GetSubset(isImageData).GetPointer();
58  if(nodes.IsNull() || nodes->size() <= 0)
59  return;
60  Point3D worldposition = positionEvent->GetPositionInWorld();
61  for (unsigned int x = 0; x < nodes->size(); x++)
62  {
63  DataNode::Pointer node = static_cast<DataNode::Pointer>( nodes->at(x) );
64  if(node.IsNotNull())
65  {
66  Image::Pointer image = dynamic_cast<Image*>( node->GetData() );
67  if( image.IsNotNull() && image->GetGeometry()->IsInside(worldposition) )
68  {
69  string typeStr = image->GetPixelType().GetComponentTypeAsString();
70  int value = 0;
71  try
72  {
73  if( typeStr == "int" )
74  {
75  ImagePixelReadAccessor<int, 3> readAccess( image );
76  value = static_cast<int>( readAccess.GetPixelByWorldCoordinates( worldposition ) );
77  }
78  else if( typeStr == "unsigned_char" )
79  {
80  ImagePixelReadAccessor<unsigned char, 3> readAccess( image );
81  value = static_cast<int>( readAccess.GetPixelByWorldCoordinates( worldposition ) );
82  }
83  else
84  {
85  MITK_WARN("QmitkFreeSurferParcellationHandler") << "Pixeltype '" << typeStr << "' is not implemented yet.";
86  return;
87  }
88  emit this->changed( value );
89  QString name( QString::fromStdString( this->m_Translator->GetName( value ) ) );
90  emit this->changed( name );
91  MousePressEvent::Pointer mouseEvent = dynamic_cast<MousePressEvent*>( interactionEvent );
92  MouseWheelEvent::Pointer wheelEvent = dynamic_cast<MouseWheelEvent*>( interactionEvent );
93  if(mouseEvent.IsNotNull())
94  {
95  emit this->clicked( value );
96  emit this->clicked( name );
97  }
98  if( wheelEvent.IsNotNull() )
99  {
100  emit this->scrolled( value );
101  emit this->scrolled( name );
102  }
103  return; // exit loop
104  }
105  catch( const Exception& ex )
106  {
107  MITK_WARN("QmitkFreeSurferParcellationHandler") << "Could not access image for reading pixelvalue due to: " << ex.GetDescription();
108  }
109  catch(...)
110  {
111  MITK_WARN("QmitkFreeSurferParcellationHandler") << "Could not access image for reading pixelvalue.";
112  }
113  }
114  }
115  }
116 }
Super class for all position events.
Base class to implement InteractionEventObservers.
Gives locked and index-based read access for a particular image part. The class provides several set-...
BaseRenderer * GetSender() const
mitk::FreeSurferParcellationTranslator::Pointer m_Translator
Translator for coverting pixelvalue into anatomical label.
Organizes the rendering process.
static Module * GetModule(long id)
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
us::ServiceRegistration< InteractionEventObserver > m_ServiceRegistration
The mitkFreeSurferParcellationTranslator class.
void changed(int)
Emitted when pixelValue has changed.
void clicked(int)
Thrown if and only if the left mousebutton is pressed and pixelValue has changed. ...
itk::SmartPointer< const Self > ConstPointer
virtual DataStorage::Pointer GetDataStorage() const
#define MITK_WARN
Definition: mitkLogMacros.h:23
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
Definition: mitkException.h:49
void scrolled(int)
Thrown if mouse scrolled and pixelvalue changed.
Image class for storing images.
Definition: mitkImage.h:76
ModuleContext * GetModuleContext() const
Definition: usModule.cpp:206
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
virtual void Notify(InteractionEvent *interactionEvent, bool isHandled)
const TPixel & GetPixelByWorldCoordinates(mitk::Point3D position)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.