Public Types | Signals | Public Member Functions | Protected Types | Protected Slots | Protected Attributes

QmitkToolWorkingDataSelectionBox Class Reference
[Widgets]

Display the data selection of a ToolManager. More...

#include <QmitkToolWorkingDataSelectionBox.h>

Collaboration diagram for QmitkToolWorkingDataSelectionBox:
Collaboration graph
[legend]

List of all members.

Public Types

enum  DisplayMode { ListDataIfAllToolsMatch, ListDataIfAnyToolMatches }
 

What kind of items should be displayed.

More...

Signals

void WorkingNodeSelected (const mitk::DataNode *)

Public Member Functions

 QmitkToolWorkingDataSelectionBox (QWidget *parent=0, mitk::DataStorage *storage=0)
virtual ~QmitkToolWorkingDataSelectionBox ()
mitk::DataStorageGetDataStorage ()
void SetDataStorage (mitk::DataStorage &storage)
void UpdateDataDisplay ()
 Can be called to trigger an update of the list contents.
mitk::ToolManagerGetToolManager ()
 Returns the associated mitk::ToolManager.
void SetToolManager (mitk::ToolManager &)
 Tell this object to listen to another ToolManager.
mitk::ToolManager::DataVectorType GetAllNodes (bool onlyDerivedFromOriginal=true)
 A list of all displayed DataNode objects. This method might be convenient for program modules that want to display additional information about these nodes, like a total volume of all segmentations, etc.
mitk::ToolManager::DataVectorType GetSelectedNodes ()
 A list of all selected DataNode objects. This method might be convenient for program modules that want to display additional information about these nodes, like a total volume of all segmentations, etc.
mitk::DataNodeGetSelectedNode ()
 Like GetSelectedNodes(), but will only return one object. Will only return what QListView gives as selected object (documentation says nothing is returned if list is in Single selection mode).
void OnToolManagerWorkingDataModified ()
 Callback function, no need to call it. This is used to observe and react to changes in the mitk::ToolManager object.
void OnToolManagerReferenceDataModified ()
 Callback function, no need to call it. This is used to observe and react to changes in the mitk::ToolManager object.

Protected Types

typedef std::map
< QListWidgetItem
*, mitk::DataNode * > 
ItemNodeMapType

Protected Slots

void OnWorkingDataSelectionChanged ()

Protected Attributes

mitk::ToolManager::Pointer m_ToolManager
ItemNodeMapType m_Node
bool m_SelfCall
mitk::DataNodem_LastSelectedReferenceData
std::string m_ToolGroupsForFiltering
bool m_DisplayOnlyDerivedNodes

Detailed Description

Display the data selection of a ToolManager.

See also:
mitk::ToolManager
mitk::DataStorage

There is a separate page describing the general design of QmitkInteractiveSegmentation: QmitkInteractiveSegmentationTechnicalPage

Shows the working data of a ToolManager in a segmentation setting. By default only the segmentation name is shown.

The working images (segmentations) are listed in a QListView, each row telling the color and name of a single segmentation. One or several segmentations can be selected to be the "active" segmentations.

Author:
maleike

Definition at line 46 of file QmitkToolWorkingDataSelectionBox.h.


Member Typedef Documentation

typedef std::map< QListWidgetItem*, mitk::DataNode* > QmitkToolWorkingDataSelectionBox::ItemNodeMapType [protected]

Definition at line 127 of file QmitkToolWorkingDataSelectionBox.h.


Member Enumeration Documentation

What kind of items should be displayed.

Every mitk::Tool holds a NodePredicateBase object, telling the kind of data that this tool will successfully work with. There are two ways that this list box deals with these predicates.

DEFAULT is: list data if ANY one of the displayed tools' predicate matches. Other option: list data if ALL one of the displayed tools' predicate matches

Enumerator:
ListDataIfAllToolsMatch 
ListDataIfAnyToolMatches 

Definition at line 62 of file QmitkToolWorkingDataSelectionBox.h.


Constructor & Destructor Documentation

QmitkToolWorkingDataSelectionBox::QmitkToolWorkingDataSelectionBox ( QWidget *  parent = 0,
mitk::DataStorage storage = 0 
)

Definition at line 21 of file QmitkToolWorkingDataSelectionBox.cpp.

References m_ToolManager, mitk::ToolManager::New(), OnToolManagerReferenceDataModified(), OnToolManagerWorkingDataModified(), and OnWorkingDataSelectionChanged().

:QListWidget(parent),
m_SelfCall(false),
m_LastSelectedReferenceData(NULL),
m_ToolGroupsForFiltering("default"),
m_DisplayOnlyDerivedNodes(true)
{
  m_ToolManager = mitk::ToolManager::New( storage ); // this widget should be placeable from designer so it can't take other than the defaul parameters

  QListWidget::setSelectionMode( QListWidget::MultiSelection );
  QListWidget::setDragDropMode(QListWidget::InternalMove);

  connect( this, SIGNAL(itemSelectionChanged()), this, SLOT(OnWorkingDataSelectionChanged()) );

  m_ToolManager->ReferenceDataChanged += mitk::MessageDelegate<QmitkToolWorkingDataSelectionBox>( this, &QmitkToolWorkingDataSelectionBox::OnToolManagerReferenceDataModified );
  m_ToolManager->WorkingDataChanged += mitk::MessageDelegate<QmitkToolWorkingDataSelectionBox>( this, &QmitkToolWorkingDataSelectionBox::OnToolManagerWorkingDataModified );
}
QmitkToolWorkingDataSelectionBox::~QmitkToolWorkingDataSelectionBox (  ) [virtual]

Definition at line 39 of file QmitkToolWorkingDataSelectionBox.cpp.

{

}

Member Function Documentation

mitk::ToolManager::DataVectorType QmitkToolWorkingDataSelectionBox::GetAllNodes ( bool  onlyDerivedFromOriginal = true )

A list of all displayed DataNode objects. This method might be convenient for program modules that want to display additional information about these nodes, like a total volume of all segmentations, etc.

Build up predicate:

  • ask each tool that is displayed for a predicate (indicating the type of data that this tool will work with)
  • connect all predicates using AND or OR, depending on the parameter m_DisplayMode (ListDataIfAllToolsMatch or ListDataIfAnyToolMatches)
    See also:
    SetDisplayMode
    Two modes here:
  • display only nodes below reference data from ToolManager (onlyDerivedFromOriginal == true)
  • display everything matching the predicate (else)

Definition at line 203 of file QmitkToolWorkingDataSelectionBox.cpp.

References mitk::DataStorage::GetAll(), mitk::DataStorage::GetDerivations(), mitk::Tool::GetGroup(), mitk::Tool::GetName(), mitk::DataStorage::GetSubset(), mitk::Tool::GetWorkingDataPreference(), m_ToolGroupsForFiltering, m_ToolManager, and mitk::NodePredicateOr::New().

Referenced by UpdateDataDisplay().

{
  mitk::DataStorage* dataStorage = m_ToolManager->GetDataStorage();
  if (!dataStorage)
  {
    return mitk::ToolManager::DataVectorType();
  }

  std::vector< mitk::NodePredicateBase::ConstPointer > m_Predicates;
  mitk::NodePredicateBase::ConstPointer completePredicate = NULL;
  bool rebuildNeeded = true;
  if (rebuildNeeded)
  {
    m_Predicates.clear();

    const mitk::ToolManager::ToolVectorTypeConst allTools = m_ToolManager->GetTools();

    for ( mitk::ToolManager::ToolVectorTypeConst::const_iterator iter = allTools.begin();
      iter != allTools.end();
      ++iter )
    {
      const mitk::Tool* tool = *iter;

      if ( (m_ToolGroupsForFiltering.empty()) || ( m_ToolGroupsForFiltering.find( tool->GetGroup() ) != std::string::npos ) ||
        ( m_ToolGroupsForFiltering.find( tool->GetName() )  != std::string::npos )
        )
      {
        if (completePredicate.IsNotNull())
        {

          m_Predicates.push_back( mitk::NodePredicateOr::New( completePredicate, tool->GetWorkingDataPreference()).GetPointer() );

          completePredicate = m_Predicates.back();
        }
        else
        {
          completePredicate = tool->GetWorkingDataPreference();
        }
      }
    }
  }

  // TODO delete all m_Predicates
  mitk::DataStorage::SetOfObjects::ConstPointer allObjects;

  if ( onlyDerivedFromOriginal )
  {
    mitk::DataNode* sourceNode( m_ToolManager->GetReferenceData(0) );
    if (sourceNode)
    {
      allObjects = dataStorage->GetDerivations( sourceNode, completePredicate, false );
    }
    else
    {
      allObjects = mitk::DataStorage::SetOfObjects::New();
    }
  }
  else
  {
    if (completePredicate)
    {
      allObjects = dataStorage->GetSubset( completePredicate );
    }
    else
    {
      allObjects = dataStorage->GetAll();
    }
  }

  m_Predicates.clear();
  completePredicate = NULL;

  mitk::ToolManager::DataVectorType resultVector;

  for ( mitk::DataStorage::SetOfObjects::const_iterator objectIter = allObjects->begin();
    objectIter != allObjects->end();
    ++objectIter )
  {
    mitk::DataNode* node = (*objectIter).GetPointer();
    resultVector.push_back( node );
  }

  return resultVector;
}
mitk::DataStorage * QmitkToolWorkingDataSelectionBox::GetDataStorage (  )

Definition at line 44 of file QmitkToolWorkingDataSelectionBox.cpp.

References m_ToolManager.

{
  return m_ToolManager->GetDataStorage();
}
mitk::DataNode * QmitkToolWorkingDataSelectionBox::GetSelectedNode (  )

Like GetSelectedNodes(), but will only return one object. Will only return what QListView gives as selected object (documentation says nothing is returned if list is in Single selection mode).

Definition at line 188 of file QmitkToolWorkingDataSelectionBox.cpp.

References m_Node.

{
  QListWidgetItem* item = QListWidget::selectedItems().first();
  if (item)
  {
    ItemNodeMapType::iterator iter = m_Node.find(item);
    if ( iter != m_Node.end() )
    {
      return iter->second;
    }
  }

  return NULL;
}
mitk::ToolManager::DataVectorType QmitkToolWorkingDataSelectionBox::GetSelectedNodes (  )

A list of all selected DataNode objects. This method might be convenient for program modules that want to display additional information about these nodes, like a total volume of all segmentations, etc.

Definition at line 158 of file QmitkToolWorkingDataSelectionBox.cpp.

References m_Node.

Referenced by OnWorkingDataSelectionChanged().

{
  mitk::ToolManager::DataVectorType result;

  QList<QListWidgetItem *> items;
  for (int j=0; j<this->count(); j++)
  {
    if (this->item(j)->isSelected())
      items.append(this->item(j));
  }

  for (int i=0; i<items.size();++i)
  {

    QListWidgetItem* item = items.at(i);
    if (item)
    {
      ItemNodeMapType::iterator it = m_Node.find(item);
      if (it != m_Node.end())
      {
        mitk::DataNode::Pointer node =   it->second;
        if (node)
          result.push_back(node);
      }
    }
  }

  return result;
}
mitk::ToolManager * QmitkToolWorkingDataSelectionBox::GetToolManager (  )

Returns the associated mitk::ToolManager.

Definition at line 55 of file QmitkToolWorkingDataSelectionBox.cpp.

References m_ToolManager.

{
  return m_ToolManager;
}
void QmitkToolWorkingDataSelectionBox::OnToolManagerReferenceDataModified (  )

Callback function, no need to call it. This is used to observe and react to changes in the mitk::ToolManager object.

Definition at line 106 of file QmitkToolWorkingDataSelectionBox.cpp.

References m_LastSelectedReferenceData, m_ToolManager, and UpdateDataDisplay().

Referenced by QmitkToolWorkingDataSelectionBox(), and SetToolManager().

{
  if ( m_ToolManager->GetReferenceData(0) != m_LastSelectedReferenceData )
  {
    m_ToolManager->SetWorkingData(NULL);
    UpdateDataDisplay();

    m_LastSelectedReferenceData = m_ToolManager->GetReferenceData(0);
  }
}
void QmitkToolWorkingDataSelectionBox::OnToolManagerWorkingDataModified (  )

Callback function, no need to call it. This is used to observe and react to changes in the mitk::ToolManager object.

Definition at line 96 of file QmitkToolWorkingDataSelectionBox.cpp.

References m_SelfCall, m_ToolManager, UpdateDataDisplay(), and WorkingNodeSelected().

Referenced by QmitkToolWorkingDataSelectionBox(), and SetToolManager().

{
  if (m_SelfCall) return;

  const mitk::DataNode* node = m_ToolManager->GetWorkingData(0);
  emit WorkingNodeSelected(node);

  UpdateDataDisplay();
}
void QmitkToolWorkingDataSelectionBox::OnWorkingDataSelectionChanged (  ) [protected, slot]

Definition at line 73 of file QmitkToolWorkingDataSelectionBox.cpp.

References GetSelectedNodes(), m_SelfCall, m_ToolManager, and WorkingNodeSelected().

Referenced by QmitkToolWorkingDataSelectionBox().

{
  static mitk::ToolManager::DataVectorType previouslySelectedNodes;

  mitk::ToolManager::DataVectorType selection = this->GetSelectedNodes();

  previouslySelectedNodes = selection;

  if (selection.size() >0)
  {
    const mitk::DataNode* node = selection[0];
    emit WorkingNodeSelected(node);
  }
  else
  {
    emit WorkingNodeSelected(NULL);
  }

  m_SelfCall = true;
  m_ToolManager->SetWorkingData( selection ); // maybe empty
  m_SelfCall = false;
}
void QmitkToolWorkingDataSelectionBox::SetDataStorage ( mitk::DataStorage storage )

Definition at line 49 of file QmitkToolWorkingDataSelectionBox.cpp.

References m_ToolManager.

{
  m_ToolManager->SetDataStorage(storage);
}
void QmitkToolWorkingDataSelectionBox::SetToolManager ( mitk::ToolManager newManager )
void QmitkToolWorkingDataSelectionBox::UpdateDataDisplay (  )

Can be called to trigger an update of the list contents.

Definition at line 117 of file QmitkToolWorkingDataSelectionBox.cpp.

References GetAllNodes(), mitk::DataNode::GetColor(), mitk::DataNode::GetName(), and m_Node.

Referenced by OnToolManagerReferenceDataModified(), OnToolManagerWorkingDataModified(), and SetToolManager().

{

  // clear all
  QListWidget::clear();
  m_Node.clear();

  // rebuild contents
  mitk::ToolManager::DataVectorType allObjects = GetAllNodes( false );
  for ( mitk::ToolManager::DataVectorType::const_iterator objectIter = allObjects.begin();
    objectIter != allObjects.end();
    ++objectIter)
  {
    mitk::DataNode* node = *objectIter;

    if (node) // delete this check when datastorage is really used
    {
      // get name and color 
      std::string name = node->GetName();
      float rgb[3]; rgb[0] = 1.0; rgb[1] = 0.0; rgb[2] = 0.0;
      node->GetColor(rgb);
      QRgb qrgb = qRgb( (int)(rgb[0]*255.0), (int)(rgb[1]*255.0),  (int)(rgb[2]*255.0) );

      QPixmap pixmap(25,18);
      pixmap.fill(QColor(qrgb));
      
      // create a list item
      QListWidgetItem* newItem = new QListWidgetItem();
      QString qname = QString::fromLocal8Bit(name.c_str());

      //set name and color
      newItem->setText(qname);
      newItem->setIcon(QIcon(pixmap));

      this->addItem(newItem);

      m_Node.insert( std::make_pair( newItem, node ) );
    }
  }
}
void QmitkToolWorkingDataSelectionBox::WorkingNodeSelected ( const mitk::DataNode  ) [signal]

Member Data Documentation

Definition at line 139 of file QmitkToolWorkingDataSelectionBox.h.

Definition at line 137 of file QmitkToolWorkingDataSelectionBox.h.

Referenced by GetAllNodes().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines