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

QmitkPointListWidget Class Reference

Widget for regular operations on point sets. More...

#include <QmitkPointListWidget.h>

Collaboration diagram for QmitkPointListWidget:
Collaboration graph
[legend]

List of all members.

Public Slots

void DeactivateInteractor (bool deactivate)
void EnableEditButton (bool enabled)

Signals

void EditPointSets (bool active)
 signal to inform about the state of the EditPointSetButton, whether an interactor for setting points is active or not
void PointSelectionChanged ()
 signal to inform that the selection of a point in the pointset has changed
void PointListChanged ()
 signal to inform about cleared or loaded point sets

Public Member Functions

 QmitkPointListWidget (QWidget *parent=0, int orientation=0)
 ~QmitkPointListWidget ()
void SetupConnections ()
void SetPointSet (mitk::PointSet *newPs)
 assign a point set (contained in a node of DataStorage) for observation
mitk::PointSetGetPointSet ()
void SetPointSetNode (mitk::DataNode *newNode)
 assign a point set (contained in a node of DataStorage) for observation
mitk::DataNodeGetPointSetNode ()
void SetMultiWidget (QmitkStdMultiWidget *multiWidget)
 assign a QmitkStdMultiWidget for updating render window crosshair
void OnNodeDeleted (const itk::EventObject &e)
 itk observer for node "delete" events

Protected Slots

void OnBtnSavePoints ()
void OnBtnLoadPoints ()
void RemoveSelectedPoint ()
void MoveSelectedPointDown ()
void MoveSelectedPointUp ()
void OnBtnAddPoint (bool checked)
void OnListDoubleClick ()

Protected Member Functions

void SetupUi ()
void ObserveNewNode (mitk::DataNode *node)

Protected Attributes

QmitkPointListViewm_PointListView
QmitkStdMultiWidgetm_MultiWidget
mitk::DataNode::Pointer m_PointSetNode
int m_Orientation
QPushButton * m_MovePointUpBtn
QPushButton * m_MovePointDownBtn
QPushButton * m_RemovePointBtn
QPushButton * m_SavePointsBtn
QPushButton * m_LoadPointsBtn
QPushButton * m_ToggleAddPoint
mitk::PointSetInteractor::Pointer m_Interactor
int m_TimeStep
bool m_EditAllowed
unsigned long m_NodeObserverTag

Detailed Description

Widget for regular operations on point sets.

Displays a list of point coordinates and a couple of buttons which

The user/application module of this widget needs to assign a mitk::PointSet object to this widget. The user also has to decide whether it wants to put the point set into (a) DataStorage. This widget will not add/remove point sets to DataStorage.

If the render window crosshair should be moved to the currently selected point, the widget user has to provide a QmitkStdMultiWidget object.

Definition at line 39 of file QmitkPointListWidget.h.


Constructor & Destructor Documentation

QmitkPointListWidget::QmitkPointListWidget ( QWidget *  parent = 0,
int  orientation = 0 
)
QmitkPointListWidget::~QmitkPointListWidget (  )

Member Function Documentation

void QmitkPointListWidget::DeactivateInteractor ( bool  deactivate ) [slot]
void QmitkPointListWidget::EditPointSets ( bool  active ) [signal]

signal to inform about the state of the EditPointSetButton, whether an interactor for setting points is active or not

Referenced by OnBtnAddPoint().

void QmitkPointListWidget::EnableEditButton ( bool  enabled ) [slot]

Definition at line 352 of file QmitkPointListWidget.cpp.

References m_EditAllowed, m_ToggleAddPoint, and OnBtnAddPoint().

{
  m_EditAllowed = enabled;
  if (enabled == false)
    m_ToggleAddPoint->setEnabled(false);
  else
    m_ToggleAddPoint->setEnabled(true);
  OnBtnAddPoint(enabled);
}
mitk::PointSet * QmitkPointListWidget::GetPointSet (  )

Definition at line 255 of file QmitkPointListWidget.cpp.

References m_PointSetNode.

{
    return dynamic_cast<mitk::PointSet*>(m_PointSetNode->GetData());
}
mitk::DataNode * QmitkPointListWidget::GetPointSetNode (  )

Definition at line 260 of file QmitkPointListWidget.cpp.

References m_PointSetNode.

{
    return m_PointSetNode;
}
void QmitkPointListWidget::MoveSelectedPointDown (  ) [protected, slot]

Definition at line 284 of file QmitkPointListWidget.cpp.

References mitk::PointSet::GetSize(), m_PointListView, m_PointSetNode, QmitkPointListModel::MoveSelectedPointDown(), and PointListChanged().

Referenced by SetupConnections().

{

    if (!m_PointSetNode) return;
    mitk::PointSet* pointSet = dynamic_cast<mitk::PointSet*>( m_PointSetNode->GetData() );
    if (!pointSet) return;
    if (pointSet->GetSize() == 0) return;

    QmitkPointListModel* pointListModel = dynamic_cast<QmitkPointListModel*>( m_PointListView->model() );
    pointListModel->MoveSelectedPointDown();
    emit PointListChanged();
}
void QmitkPointListWidget::MoveSelectedPointUp (  ) [protected, slot]

Definition at line 297 of file QmitkPointListWidget.cpp.

References mitk::PointSet::GetSize(), m_PointListView, m_PointSetNode, QmitkPointListModel::MoveSelectedPointUp(), and PointListChanged().

Referenced by SetupConnections().

{

    if (!m_PointSetNode) return;
    mitk::PointSet* pointSet = dynamic_cast<mitk::PointSet*>( m_PointSetNode->GetData() );
    if (!pointSet) return;
    if (pointSet->GetSize() == 0) return;

    QmitkPointListModel* pointListModel = dynamic_cast<QmitkPointListModel*>( m_PointListView->model() );
    pointListModel->MoveSelectedPointUp();
    emit PointListChanged();
}
void QmitkPointListWidget::ObserveNewNode ( mitk::DataNode node ) [protected]

Definition at line 363 of file QmitkPointListWidget.cpp.

References mitk::GlobalInteraction::GetInstance(), m_EditAllowed, m_Interactor, m_LoadPointsBtn, m_NodeObserverTag, m_PointSetNode, m_RemovePointBtn, m_ToggleAddPoint, and OnNodeDeleted().

Referenced by QmitkPointListWidget(), SetPointSet(), and SetPointSetNode().

{
  // remove old observer
  if ( m_PointSetNode )
  {
    if (m_Interactor)
    {
      mitk::GlobalInteraction::GetInstance()->RemoveInteractor( m_Interactor );
      m_Interactor = NULL;
      m_ToggleAddPoint->setChecked( false );
    }

    m_PointSetNode->RemoveObserver( m_NodeObserverTag );
    m_NodeObserverTag = 0;
  }

  m_PointSetNode = node;

  // add new observer if necessary
  if ( m_PointSetNode )
  {
    itk::ReceptorMemberCommand<QmitkPointListWidget>::Pointer command = itk::ReceptorMemberCommand<QmitkPointListWidget>::New();
    command->SetCallbackFunction( this, &QmitkPointListWidget::OnNodeDeleted );
    m_NodeObserverTag = m_PointSetNode->AddObserver( itk::DeleteEvent(), command );
  }
  else
  {
    m_NodeObserverTag = 0;
  }

  if (m_EditAllowed == true)
    m_ToggleAddPoint->setEnabled( m_PointSetNode );
  else
    m_ToggleAddPoint->setEnabled( false );

  m_RemovePointBtn->setEnabled( m_PointSetNode );
  m_LoadPointsBtn->setEnabled( m_PointSetNode );
  m_LoadPointsBtn->setEnabled( m_PointSetNode );
}
void QmitkPointListWidget::OnBtnAddPoint ( bool  checked ) [protected, slot]

Definition at line 310 of file QmitkPointListWidget.cpp.

References EditPointSets(), mitk::BaseRenderer::GetInstance(), mitk::GlobalInteraction::GetInstance(), m_Interactor, m_MultiWidget, m_PointSetNode, QmitkStdMultiWidget::mitkWidget4, and mitk::PointSetInteractor::New().

Referenced by EnableEditButton(), and SetupConnections().

{
    if (m_PointSetNode)
    {
        if (checked)
        {
          m_Interactor = dynamic_cast<mitk::PointSetInteractor*>(m_PointSetNode->GetInteractor());
          
          if (m_Interactor.IsNull())//if not present, instanciate one
            m_Interactor = mitk::PointSetInteractor::New("pointsetinteractor", m_PointSetNode);
          
          //add it to global interaction to activate it
          mitk::GlobalInteraction::GetInstance()->AddInteractor( m_Interactor );
        }
        else if ( m_Interactor )
        {
            mitk::GlobalInteraction::GetInstance()->RemoveInteractor( m_Interactor );
            m_Interactor = NULL;
        }
        emit EditPointSets(checked);
        mitk::BaseRenderer::GetInstance(m_MultiWidget->mitkWidget4->GetRenderWindow())->RequestUpdate();
    }
}
void QmitkPointListWidget::OnBtnLoadPoints (  ) [protected, slot]

Definition at line 213 of file QmitkPointListWidget.cpp.

References mitk::RenderingManager::GetInstance(), mitk::PointSetReader::New(), PointListChanged(), and SetPointSet().

Referenced by SetupConnections().

{
    // get the name of the file to load
    QString filename = QFileDialog::getOpenFileName( NULL, "Open MITK Pointset", "", "MITK Point Sets (*.mps)");
    if ( filename.isEmpty() ) return;

    // attempt to load file
    try
    {
        mitk::PointSetReader::Pointer reader = mitk::PointSetReader::New();
        reader->SetFileName( filename.toLatin1() );
        reader->Update();

        mitk::PointSet::Pointer pointSet = reader->GetOutput();
        if ( pointSet.IsNull() )
        {
            QMessageBox::warning( this, "Load point set", QString("File reader could not read %1").arg(filename) );
            return;
        }

        // loading successful

        //      bool interactionOn( m_Interactor.IsNotNull() );
        //      if (interactionOn)
        //      {
        //        OnEditPointSetButtonToggled(false);
        //      }
        //
        this->SetPointSet(pointSet);
        //      if (interactionOn)
        //      {
        //        OnEditPointSetButtonToggled(true);
        //      }
    }
    catch(...)
    {
        QMessageBox::warning( this, "Load point set", QString("File reader collapsed while reading %1").arg(filename) );
    }
    emit PointListChanged();
    mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}
void QmitkPointListWidget::OnBtnSavePoints (  ) [protected, slot]

Definition at line 182 of file QmitkPointListWidget.cpp.

References m_PointSetNode, and mitk::PointSetWriter::New().

Referenced by SetupConnections().

{
    if ((dynamic_cast<mitk::PointSet*>(m_PointSetNode->GetData()))  == NULL)
        return; // don't write empty point sets. If application logic requires something else then do something else.
    if ((dynamic_cast<mitk::PointSet*>(m_PointSetNode->GetData()))->GetSize() == 0)
        return;

    // let the user choose a file
    std::string name("");

    QString fileNameProposal = QString("/PointSet.mps");//.arg(m_PointSetNode->GetName().c_str()); //"PointSet.mps";
    QString aFilename = QFileDialog::getSaveFileName( NULL, "Save point set", QDir::currentPath() + fileNameProposal, "MITK Pointset (*.mps)" );
    if ( aFilename.isEmpty() )
        return;

    try
    {
        // instantiate the writer and add the point-sets to write
        mitk::PointSetWriter::Pointer writer = mitk::PointSetWriter::New();
        writer->SetInput( dynamic_cast<mitk::PointSet*>(m_PointSetNode->GetData()) );
        writer->SetFileName( aFilename.toLatin1() );
        writer->Update();
    }
    catch(...)
    {
        QMessageBox::warning( this, "Save point set",
                              QString("File writer reported problems writing %1\n\n"
                                      "PLEASE CHECK output file!").arg(aFilename) );
    }
}
void QmitkPointListWidget::OnListDoubleClick (  ) [protected, slot]

Definition at line 342 of file QmitkPointListWidget.cpp.

Referenced by SetupConnections().

{
    ;
}
void QmitkPointListWidget::OnNodeDeleted ( const itk::EventObject &  e )
void QmitkPointListWidget::PointListChanged (  ) [signal]

signal to inform about cleared or loaded point sets

Referenced by MoveSelectedPointDown(), MoveSelectedPointUp(), OnBtnLoadPoints(), and RemoveSelectedPoint().

void QmitkPointListWidget::PointSelectionChanged (  ) [signal]

signal to inform that the selection of a point in the pointset has changed

void QmitkPointListWidget::RemoveSelectedPoint (  ) [protected, slot]

Definition at line 271 of file QmitkPointListWidget.cpp.

References mitk::PointSet::GetSize(), m_PointListView, m_PointSetNode, PointListChanged(), and QmitkPointListModel::RemoveSelectedPoint().

Referenced by SetupConnections().

{

    if (!m_PointSetNode) return;
    mitk::PointSet* pointSet = dynamic_cast<mitk::PointSet*>( m_PointSetNode->GetData() );
    if (!pointSet) return;
    if (pointSet->GetSize() == 0) return;

    QmitkPointListModel* pointListModel = dynamic_cast<QmitkPointListModel*>( m_PointListView->model() );
    pointListModel->RemoveSelectedPoint();
    emit PointListChanged();
}
void QmitkPointListWidget::SetMultiWidget ( QmitkStdMultiWidget multiWidget )
void QmitkPointListWidget::SetPointSet ( mitk::PointSet newPs )

assign a point set (contained in a node of DataStorage) for observation

Definition at line 162 of file QmitkPointListWidget.cpp.

References m_PointListView, m_PointSetNode, ObserveNewNode(), and SetPointSetNode().

Referenced by OnBtnLoadPoints().

{
  if(newPs == NULL)
    return;

  this->m_PointSetNode->SetData(newPs);
  dynamic_cast<QmitkPointListModel*>(this->m_PointListView->model())->SetPointSetNode(m_PointSetNode);
  ObserveNewNode(m_PointSetNode);
}
void QmitkPointListWidget::SetPointSetNode ( mitk::DataNode newNode )
void QmitkPointListWidget::SetupConnections (  )

Definition at line 53 of file QmitkPointListWidget.cpp.

References m_LoadPointsBtn, m_MovePointDownBtn, m_MovePointUpBtn, m_PointListView, m_RemovePointBtn, m_SavePointsBtn, m_ToggleAddPoint, MoveSelectedPointDown(), MoveSelectedPointUp(), OnBtnAddPoint(), OnBtnLoadPoints(), OnBtnSavePoints(), OnListDoubleClick(), and RemoveSelectedPoint().

Referenced by QmitkPointListWidget().

{
    //m_PointListView->setModel(m_PointListModel);

    connect(this->m_LoadPointsBtn, SIGNAL(clicked()), this, SLOT(OnBtnLoadPoints()));
    connect(this->m_SavePointsBtn, SIGNAL(clicked()), this, SLOT(OnBtnSavePoints()));
    connect(this->m_MovePointUpBtn, SIGNAL(clicked()), this, SLOT(MoveSelectedPointUp()));
    connect(this->m_MovePointDownBtn, SIGNAL(clicked()), this, SLOT(MoveSelectedPointDown()));
    connect(this->m_RemovePointBtn, SIGNAL(clicked()), this, SLOT(RemoveSelectedPoint()));
    connect(this->m_ToggleAddPoint, SIGNAL(toggled(bool)), this, SLOT(OnBtnAddPoint(bool)));
    connect(this->m_PointListView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(OnListDoubleClick()));
}
void QmitkPointListWidget::SetupUi (  ) [protected]

Definition at line 66 of file QmitkPointListWidget.cpp.

References m_LoadPointsBtn, m_MovePointDownBtn, m_MovePointUpBtn, m_Orientation, m_PointListView, m_RemovePointBtn, m_SavePointsBtn, and m_ToggleAddPoint.

Referenced by QmitkPointListWidget().

{
    //Setup the buttons

    m_ToggleAddPoint = new QPushButton();//iconSetPoints, "", this);
    m_ToggleAddPoint->setMaximumSize(25,25);
    m_ToggleAddPoint->setCheckable(true);
    m_ToggleAddPoint->setToolTip("Toggle point editing (use SHIFT  + Left Mouse Button to add Points)");
    QIcon iconAdd(btnSetPoints_xpm);
    m_ToggleAddPoint->setIcon(iconAdd);

    m_RemovePointBtn = new QPushButton();
    m_RemovePointBtn->setMaximumSize(25, 25);
    const QIcon iconDel(btnClear_xpm);
    m_RemovePointBtn->setIcon(iconDel);
    m_RemovePointBtn->setToolTip("Erase one point from list   (Hotkey: DEL)");


    m_MovePointUpBtn = new QPushButton();
    m_MovePointUpBtn->setMaximumSize(25, 25);
    const QIcon iconUp(btnUp_xpm);
    m_MovePointUpBtn->setIcon(iconUp);
    m_MovePointUpBtn->setToolTip("Swap selected point upwards   (Hotkey: F2)");

    m_MovePointDownBtn = new QPushButton();
    m_MovePointDownBtn->setMaximumSize(25, 25);
    const QIcon iconDown(btnDown_xpm);
    m_MovePointDownBtn->setIcon(iconDown);
    m_MovePointDownBtn->setToolTip("Swap selected point downwards   (Hotkey: F3)");

    m_SavePointsBtn = new QPushButton();
    m_SavePointsBtn->setMaximumSize(25, 25);
    QIcon iconSave(btnSave_xpm);
    m_SavePointsBtn->setIcon(iconSave);
    m_SavePointsBtn->setToolTip("Save points to file");

    m_LoadPointsBtn = new QPushButton();
    m_LoadPointsBtn->setMaximumSize(25, 25);
    QIcon iconLoad(btnLoad_xpm);
    m_LoadPointsBtn->setIcon(iconLoad);
    m_LoadPointsBtn->setToolTip("Load list of points from file (REPLACES current content)");


    int i;

      QBoxLayout* lay1;
      QBoxLayout* lay2;

      switch (m_Orientation)
      {
      case 0:
          lay1 = new QVBoxLayout(this);
          lay2 = new QHBoxLayout();
          i = 0;
          break;

      case 1:
          lay1 = new QHBoxLayout(this);
          lay2 = new QVBoxLayout();
          i=-1;
          break;

      case 2:
          lay1 = new QHBoxLayout(this);
          lay2 = new QVBoxLayout();
          i=0;
          break;

      default:
          lay1 = new QVBoxLayout(this);
          lay2 = new QHBoxLayout();
          i=-1;
          break;

      }

      //setup Layouts

      this->setLayout(lay1);
      lay1->addLayout(lay2);

      lay2->stretch(true);
      lay2->addWidget(m_ToggleAddPoint);
      lay2->addWidget(m_RemovePointBtn);
      lay2->addWidget(m_MovePointUpBtn);
      lay2->addWidget(m_MovePointDownBtn);
      lay2->addWidget(m_SavePointsBtn);
      lay2->addWidget(m_LoadPointsBtn);


      //lay2->addSpacing();;

      lay1->insertWidget(i,m_PointListView);
      this->setLayout(lay1);
}

Member Data Documentation

Definition at line 109 of file QmitkPointListWidget.h.

Referenced by EnableEditButton(), and ObserveNewNode().

Definition at line 107 of file QmitkPointListWidget.h.

Referenced by ObserveNewNode(), OnBtnAddPoint(), and ~QmitkPointListWidget().

QPushButton* QmitkPointListWidget::m_LoadPointsBtn [protected]

Definition at line 103 of file QmitkPointListWidget.h.

Referenced by ObserveNewNode(), OnNodeDeleted(), SetupConnections(), and SetupUi().

QPushButton* QmitkPointListWidget::m_MovePointDownBtn [protected]

Definition at line 100 of file QmitkPointListWidget.h.

Referenced by SetupConnections(), and SetupUi().

QPushButton* QmitkPointListWidget::m_MovePointUpBtn [protected]

Definition at line 99 of file QmitkPointListWidget.h.

Referenced by SetupConnections(), and SetupUi().

Definition at line 92 of file QmitkPointListWidget.h.

Referenced by OnBtnAddPoint(), SetMultiWidget(), and ~QmitkPointListWidget().

unsigned long QmitkPointListWidget::m_NodeObserverTag [protected]

Definition at line 110 of file QmitkPointListWidget.h.

Referenced by ObserveNewNode(), OnNodeDeleted(), and ~QmitkPointListWidget().

Definition at line 97 of file QmitkPointListWidget.h.

Referenced by QmitkPointListWidget(), and SetupUi().

QPushButton* QmitkPointListWidget::m_RemovePointBtn [protected]

Definition at line 101 of file QmitkPointListWidget.h.

Referenced by ObserveNewNode(), OnNodeDeleted(), SetupConnections(), and SetupUi().

QPushButton* QmitkPointListWidget::m_SavePointsBtn [protected]

Definition at line 102 of file QmitkPointListWidget.h.

Referenced by SetupConnections(), and SetupUi().

Definition at line 108 of file QmitkPointListWidget.h.

QPushButton* QmitkPointListWidget::m_ToggleAddPoint [protected]

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