// Helper function to get an image from a data node.
static mitk::Image::Pointer GetImage(mitk::DataNode::Pointer dataNode)
{
  if (dataNode.IsNull())
    mitkThrow();

  mitk::Image::Pointer image = dynamic_cast<mitk::Image*>(dataNode->GetData());

  if (image.IsNull())
    mitkThrow();

  return image;
}
void QmitkFiducialRegistrationWidget::SetTrackerFiducialsNode( mitk::DataNode::Pointer trackerFiducialsNode )
{
  if(trackerFiducialsNode.IsNull())
  {
    FRW_WARN<< "tracker fiducial node is NULL";
    return;
  }
  m_Controls->m_RegistrationTrackingPoints->SetPointSetNode(trackerFiducialsNode); // pass node to pointListWidget
  if(m_MultiWidget == NULL)
  {
    FRW_WARN<< "stdMultiWidget is NULL";
    return;
  }
  m_Controls->m_RegistrationTrackingPoints->SetMultiWidget(m_MultiWidget); // pass multiWidget to pointListWidget
}
  bool mitk::NodeDisplacementFilter::AddNode( mitk::DataNode::Pointer node )
  {
    // Consistency Checks
    if (node.IsNull())
    {
      MITK_WARN("NodeDisplacementFilter")
        << "Null Node passed to NodeDisplacementFilter. Ignoring Node....";
      return false;
    }
    if (node->GetData() == 0)
    {
      MITK_WARN("NodeDisplacementFilter")
        << "Empty Node passed to NodeDisplacementFilter. Ignoring Node....";
      return false;
    }
    if(m_SelectedInput == -1)
    {
      MITK_ERROR("NodeDisplacementFilter")
        << "Cannot add nodes before input Stream was selected";
      mitkThrow() << "Cannot add nodes before input Stream was selected";
    }

    this->Update(); // make sure we are working on current data
    mitk::NavigationData::Pointer reference = this->GetOutput(m_SelectedInput);

    if (! reference->IsDataValid())
    {
      MITK_WARN("NodeDisplacementFilter")
        << "Cannot add node while selected tool is not tracked. Ignoring Node....";
      return false;
    }

    // find transformation and add node
    mitk::AffineTransform3D::Pointer inverseAffineTransform = mitk::AffineTransform3D::New();
    if ( ! reference->GetAffineTransform3D()->GetInverse(inverseAffineTransform) )
    {
      MITK_ERROR("NodeDisplacementFilter")
        << "Could not get the inverse transformation of the navigation data transformation.";
      mitkThrow() << "Could not get the inverse transformation of the navigation data transformation.";
    }

    inverseAffineTransform->Compose(node->GetData()->GetGeometry()->GetIndexToWorldTransform(), true);
    m_Transforms.push_back(inverseAffineTransform);
    m_Nodes.push_back(node);

    return true;
  }
  foreach ( mitk::DataNode::Pointer referenceNode, selectedNodes )
  {

    if (referenceNode.IsNull()) return;

    mitk::LabelSetImage::Pointer referenceImage = dynamic_cast<mitk::LabelSetImage*>( referenceNode->GetData() );
    assert(referenceImage);

    std::string sName = referenceNode->GetName();
    QString qName;
    qName.sprintf("%s.lsetp",sName.c_str());
    QString filename = QFileDialog::getOpenFileName(nullptr,"Load file",QString(),"LabelSet Preset(*.lsetp)");
    if ( filename.isEmpty() )
      return;

    std::string fileName = filename.toStdString();
    mitk::LabelSetIOHelper::LoadLabelSetImagePreset(fileName, referenceImage);
  }