<commit_before>/*===================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

===================================================================*/

#include "QmitkSlicesInterpolator.h"

#include "QmitkStdMultiWidget.h"
#include "QmitkSelectableGLWidget.h"

#include "mitkToolManager.h"
#include "mitkDataNodeFactory.h"
#include "mitkLevelWindowProperty.h"
#include "mitkColorProperty.h"
#include "mitkProperties.h"
#include "mitkRenderingManager.h"
#include "mitkOverwriteSliceImageFilter.h"
#include "mitkProgressBar.h"
#include "mitkGlobalInteraction.h"
#include "mitkOperationEvent.h"
#include "mitkUndoController.h"
#include "mitkInteractionConst.h"
#include "mitkApplyDiffImageOperation.h"
#include "mitkDiffImageApplier.h"
#include "mitkSegTool2D.h"
#include "mitkCoreObjectFactory.h"
#include "mitkSurfaceToImageFilter.h"

#include <itkCommand.h>

#include <QCheckBox>
#include <QPushButton>
#include <QMenu>
#include <QCursor>
#include <QHBoxLayout>
#include <QMessageBox>


#define ROUND(a)     ((a)>0 ? (int)((a)+0.5) : -(int)(0.5-(a)))

const std::map<QAction*, unsigned int> QmitkSlicesInterpolator::createActionToSliceDimension()
{
  std::map<QAction*, unsigned int> actionToSliceDimension;
  actionToSliceDimension[new QAction("Axial (red window)", 0)] = 2;
  actionToSliceDimension[new QAction("Sagittal (green window)", 0)] = 0;
  actionToSliceDimension[new QAction("Coronal (blue window)", 0)] = 1;
  return actionToSliceDimension;
}


QmitkSlicesInterpolator::QmitkSlicesInterpolator(QWidget* parent, const char*  /*name*/)
  :QWidget(parent),
    ACTION_TO_SLICEDIMENSION( createActionToSliceDimension() ),
    m_Interpolator( mitk::SegmentationInterpolationController::New() ),
    m_MultiWidget(NULL),
    m_ToolManager(NULL),
    m_Initialized(false),
    m_LastSliceDimension(2),
    m_LastSliceIndex(0),
    m_2DInterpolationEnabled(false),
    m_3DInterpolationEnabled(false)
{

  m_SurfaceInterpolator = mitk::SurfaceInterpolationController::GetInstance();
  QHBoxLayout* layout = new QHBoxLayout(this);

  m_GroupBoxEnableExclusiveInterpolationMode = new QGroupBox("Interpolation", this);
  QGridLayout* grid = new QGridLayout(m_GroupBoxEnableExclusiveInterpolationMode);

  m_RBtnEnable3DInterpolation = new QRadioButton("3D",this);
  connect(m_RBtnEnable3DInterpolation, SIGNAL(toggled(bool)), this, SLOT(On3DInterpolationEnabled(bool)));
  m_RBtnEnable3DInterpolation->setChecked(true);
  grid->addWidget(m_RBtnEnable3DInterpolation,0,0);

  m_BtnAccept3DInterpolation = new QPushButton("Accept", this);
  m_BtnAccept3DInterpolation->setEnabled(false);
  connect(m_BtnAccept3DInterpolation, SIGNAL(clicked()), this, SLOT(OnAccept3DInterpolationClicked()));
  grid->addWidget(m_BtnAccept3DInterpolation, 0,1);

  m_CbShowMarkers = new QCheckBox("Show Position Nodes", this);
  m_CbShowMarkers->setChecked(false);
  connect(m_CbShowMarkers, SIGNAL(toggled(bool)), this, SLOT(OnShowMarkers(bool)));
  connect(m_CbShowMarkers, SIGNAL(toggled(bool)), this, SIGNAL(SignalShowMarkerNodes(bool)));
  grid->addWidget(m_CbShowMarkers,0,2);

  m_RBtnEnable2DInterpolation = new QRadioButton("2D",this);
  connect(m_RBtnEnable2DInterpolation, SIGNAL(toggled(bool)), this, SLOT(On2DInterpolationEnabled(bool)));
  grid->addWidget(m_RBtnEnable2DInterpolation,1,0);

  m_BtnAcceptInterpolation = new QPushButton("Accept", this);
  m_BtnAcceptInterpolation->setEnabled( false );
  connect( m_BtnAcceptInterpolation, SIGNAL(clicked()), this, SLOT(OnAcceptInterpolationClicked()) );
  grid->addWidget(m_BtnAcceptInterpolation,1,1);

  m_BtnAcceptAllInterpolations = new QPushButton("... for all slices", this);
  m_BtnAcceptAllInterpolations->setEnabled( false );
  connect( m_BtnAcceptAllInterpolations, SIGNAL(clicked()), this, SLOT(OnAcceptAllInterpolationsClicked()) );
  grid->addWidget(m_BtnAcceptAllInterpolations,1,2);

  m_RBtnDisableInterpolation = new QRadioButton("Disable", this);
  connect(m_RBtnDisableInterpolation, SIGNAL(toggled(bool)), this, SLOT(OnInterpolationDisabled(bool)));
  grid->addWidget(m_RBtnDisableInterpolation, 2,0);

  layout->addWidget(m_GroupBoxEnableExclusiveInterpolationMode);
  this->setLayout(layout);

  itk::ReceptorMemberCommand<QmitkSlicesInterpolator>::Pointer command = itk::ReceptorMemberCommand<QmitkSlicesInterpolator>::New();
  command->SetCallbackFunction( this, &QmitkSlicesInterpolator::OnInterpolationInfoChanged );
  InterpolationInfoChangedObserverTag = m_Interpolator->AddObserver( itk::ModifiedEvent(), command );

  itk::ReceptorMemberCommand<QmitkSlicesInterpolator>::Pointer command2 = itk::ReceptorMemberCommand<QmitkSlicesInterpolator>::New();
  command2->SetCallbackFunction( this, &QmitkSlicesInterpolator::OnSurfaceInterpolationInfoChanged );
  SurfaceInterpolationInfoChangedObserverTag = m_SurfaceInterpolator->AddObserver( itk::ModifiedEvent(), command2 );

  // feedback node and its visualization properties
  m_FeedbackNode = mitk::DataNode::New();
  mitk::CoreObjectFactory::GetInstance()->SetDefaultProperties( m_FeedbackNode );

  m_FeedbackNode->SetProperty( "binary", mitk::BoolProperty::New(true) );
  m_FeedbackNode->SetProperty( "outline binary", mitk::BoolProperty::New(true) );
  m_FeedbackNode->SetProperty( "color", mitk::ColorProperty::New(255.0, 255.0, 0.0) );
  m_FeedbackNode->SetProperty( "texture interpolation", mitk::BoolProperty::New(false) );
  m_FeedbackNode->SetProperty( "layer", mitk::IntProperty::New( 20 ) );
  m_FeedbackNode->SetProperty( "levelwindow", mitk::LevelWindowProperty::New( mitk::LevelWindow(0, 1) ) );
  m_FeedbackNode->SetProperty( "name", mitk::StringProperty::New("Interpolation feedback") );
  m_FeedbackNode->SetProperty( "opacity", mitk::FloatProperty::New(0.8) );
  m_FeedbackNode->SetProperty( "helper object", mitk::BoolProperty::New(true) );<commit_msg>Added tooltips.<commit_after>/*===================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

===================================================================*/

#include "QmitkSlicesInterpolator.h"

#include "QmitkStdMultiWidget.h"
#include "QmitkSelectableGLWidget.h"

#include "mitkToolManager.h"
#include "mitkDataNodeFactory.h"
#include "mitkLevelWindowProperty.h"
#include "mitkColorProperty.h"
#include "mitkProperties.h"
#include "mitkRenderingManager.h"
#include "mitkOverwriteSliceImageFilter.h"
#include "mitkProgressBar.h"
#include "mitkGlobalInteraction.h"
#include "mitkOperationEvent.h"
#include "mitkUndoController.h"
#include "mitkInteractionConst.h"
#include "mitkApplyDiffImageOperation.h"
#include "mitkDiffImageApplier.h"
#include "mitkSegTool2D.h"
#include "mitkCoreObjectFactory.h"
#include "mitkSurfaceToImageFilter.h"

#include <itkCommand.h>

#include <QCheckBox>
#include <QPushButton>
#include <QMenu>
#include <QCursor>
#include <QHBoxLayout>
#include <QMessageBox>


#define ROUND(a)     ((a)>0 ? (int)((a)+0.5) : -(int)(0.5-(a)))

const std::map<QAction*, unsigned int> QmitkSlicesInterpolator::createActionToSliceDimension()
{
  std::map<QAction*, unsigned int> actionToSliceDimension;
  actionToSliceDimension[new QAction("Axial (red window)", 0)] = 2;
  actionToSliceDimension[new QAction("Sagittal (green window)", 0)] = 0;
  actionToSliceDimension[new QAction("Coronal (blue window)", 0)] = 1;
  return actionToSliceDimension;
}


QmitkSlicesInterpolator::QmitkSlicesInterpolator(QWidget* parent, const char*  /*name*/)
  :QWidget(parent),
    ACTION_TO_SLICEDIMENSION( createActionToSliceDimension() ),
    m_Interpolator( mitk::SegmentationInterpolationController::New() ),
    m_MultiWidget(NULL),
    m_ToolManager(NULL),
    m_Initialized(false),
    m_LastSliceDimension(2),
    m_LastSliceIndex(0),
    m_2DInterpolationEnabled(false),
    m_3DInterpolationEnabled(false)
{

  m_SurfaceInterpolator = mitk::SurfaceInterpolationController::GetInstance();
  QHBoxLayout* layout = new QHBoxLayout(this);

  m_GroupBoxEnableExclusiveInterpolationMode = new QGroupBox("Interpolation", this);
  QGridLayout* grid = new QGridLayout(m_GroupBoxEnableExclusiveInterpolationMode);

  m_RBtnEnable3DInterpolation = new QRadioButton("3D",this);
  connect(m_RBtnEnable3DInterpolation, SIGNAL(toggled(bool)), this, SLOT(On3DInterpolationEnabled(bool)));
  m_RBtnEnable3DInterpolation->setChecked(true);
  m_RBtnEnable3DInterpolation->setToolTip("Interpolate a binary volume from a set of arbitrarily arranged contours.");
  grid->addWidget(m_RBtnEnable3DInterpolation,0,0);

  m_BtnAccept3DInterpolation = new QPushButton("Accept", this);
  m_BtnAccept3DInterpolation->setEnabled(false);
  connect(m_BtnAccept3DInterpolation, SIGNAL(clicked()), this, SLOT(OnAccept3DInterpolationClicked()));
  grid->addWidget(m_BtnAccept3DInterpolation, 0,1);

  m_CbShowMarkers = new QCheckBox("Show Position Nodes", this);
  m_CbShowMarkers->setChecked(false);
  connect(m_CbShowMarkers, SIGNAL(toggled(bool)), this, SLOT(OnShowMarkers(bool)));
  connect(m_CbShowMarkers, SIGNAL(toggled(bool)), this, SIGNAL(SignalShowMarkerNodes(bool)));
  grid->addWidget(m_CbShowMarkers,0,2);

  m_RBtnEnable2DInterpolation = new QRadioButton("2D",this);
  connect(m_RBtnEnable2DInterpolation, SIGNAL(toggled(bool)), this, SLOT(On2DInterpolationEnabled(bool)));
  m_RBtnEnable2DInterpolation ->setToolTip("Interpolate contours in left-out slices from a set of slice-by-slice arranged contours.");
  grid->addWidget(m_RBtnEnable2DInterpolation,1,0);

  m_BtnAcceptInterpolation = new QPushButton("Accept", this);
  m_BtnAcceptInterpolation->setEnabled( false );
  connect( m_BtnAcceptInterpolation, SIGNAL(clicked()), this, SLOT(OnAcceptInterpolationClicked()) );
  grid->addWidget(m_BtnAcceptInterpolation,1,1);

  m_BtnAcceptAllInterpolations = new QPushButton("... for all slices", this);
  m_BtnAcceptAllInterpolations->setEnabled( false );
  connect( m_BtnAcceptAllInterpolations, SIGNAL(clicked()), this, SLOT(OnAcceptAllInterpolationsClicked()) );
  grid->addWidget(m_BtnAcceptAllInterpolations,1,2);

  m_RBtnDisableInterpolation = new QRadioButton("Disable", this);
  connect(m_RBtnDisableInterpolation, SIGNAL(toggled(bool)), this, SLOT(OnInterpolationDisabled(bool)));
  m_RBtnDisableInterpolation->setToolTip("Disable interpolation.");
  grid->addWidget(m_RBtnDisableInterpolation, 2,0);

  layout->addWidget(m_GroupBoxEnableExclusiveInterpolationMode);
  this->setLayout(layout);

  itk::ReceptorMemberCommand<QmitkSlicesInterpolator>::Pointer command = itk::ReceptorMemberCommand<QmitkSlicesInterpolator>::New();
  command->SetCallbackFunction( this, &QmitkSlicesInterpolator::OnInterpolationInfoChanged );
  InterpolationInfoChangedObserverTag = m_Interpolator->AddObserver( itk::ModifiedEvent(), command );

  itk::ReceptorMemberCommand<QmitkSlicesInterpolator>::Pointer command2 = itk::ReceptorMemberCommand<QmitkSlicesInterpolator>::New();
  command2->SetCallbackFunction( this, &QmitkSlicesInterpolator::OnSurfaceInterpolationInfoChanged );
  SurfaceInterpolationInfoChangedObserverTag = m_SurfaceInterpolator->AddObserver( itk::ModifiedEvent(), command2 );

  // feedback node and its visualization properties
  m_FeedbackNode = mitk::DataNode::New();
  mitk::CoreObjectFactory::GetInstance()->SetDefaultProperties( m_FeedbackNode );

  m_FeedbackNode->SetProperty( "binary", mitk::BoolProperty::New(true) );
  m_FeedbackNode->SetProperty( "outline binary", mitk::BoolProperty::New(true) );
  m_FeedbackNode->SetProperty( "color", mitk::ColorProperty::New(255.0, 255.0, 0.0) );
  m_FeedbackNode->SetProperty( "texture interpolation", mitk::BoolProperty::New(false) );
  m_FeedbackNode->SetProperty( "layer", mitk::IntProperty::New( 20 ) );
  m_FeedbackNode->SetProperty( "levelwindow", mitk::LevelWindowProperty::New( mitk::LevelWindow(0, 1) ) );
  m_FeedbackNode->SetProperty( "name", mitk::StringProperty::New("Interpolation feedback") );
  m_FeedbackNode->SetProperty( "opacity", mitk::FloatProperty::New(0.8) );
  m_FeedbackNode->SetProperty( "helper object", mitk::BoolProperty::New(true) );
{'fraction_non_alphanumeric': 0.14367088607594936, 'fraction_numerical': 0.010443037974683544, 'mean_word_length': 8.81444099378882, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 90, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '923415', 'n_tokens_mistral': 4136, 'n_tokens_neox': 4108, 'n_words': 659}