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

Program:   Medical Imaging & Interaction Toolkit
Language:  C++
Date:      $Date$
Version:   $Revision$

Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.

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

#include "QmitkImageCropper.h"

#include <QAction>
#include <QCheckBox>
#include <QColorDialog>
#include <QInputDialog>
#include <QMessageBox>
#include <QSpinBox>
#include <QSlider>
#include <QApplication>

#include <vtkCommand.h>
#include <vtkCubeSource.h>
#include <vtkObjectFactory.h>
#include <vtkRenderWindow.h>
#include <vtkPlaneWidget.h>
#include <vtkProperty.h>
#include <vtkSmartPointer.h>
#include <vtkTransform.h>
#include <vtkTransformFilter.h>

#include <mitkBoundingShapeInteractor.h>
#include <mitkBoundingShapeCropper.h>
#include <mitkDisplayInteractor.h>
#include <mitkIDataStorageService.h>
#include <mitkImageCast.h> // Includes for image casting between ITK and MITK: added after using Plugin Generator
#include <mitkImageAccessByItk.h>
#include <mitkImageStatisticsHolder.h>
#include <mitkInteractionConst.h>
#include <mitkITKImageImport.h>
#include <mitkLabelSetImage.h>
#include <mitkNodePredicateDataType.h>
#include <mitkNodePredicateAnd.h>
#include <mitkNodePredicateNot.h>
#include <mitkNodePredicateProperty.h>
#include <mitkNodePredicateFunction.h>
#include <mitkRenderingManager.h>
#include <mitkProperties.h>

#include <itkBoundingBox.h>
#include <itkCommand.h>

#include <usModuleRegistry.h>
#include <usGetModuleContext.h>

const std::string QmitkImageCropper::VIEW_ID = "org.mitk.views.qmitkimagecropper";

QmitkImageCropper::QmitkImageCropper(QObject *)
  : m_ParentWidget(0),
  m_ImageNode(nullptr),
  m_CroppingObject(nullptr),
  m_CroppingObjectNode(nullptr),
  m_BoundingShapeInteractor(nullptr),
  m_CropOutsideValue(0),
  m_Advanced(0),
  m_Active(0),
  m_ScrollEnabled(true)
{
  CreateBoundingShapeInteractor(false);
}

QmitkImageCropper::~QmitkImageCropper()
{
  //delete pointer objects
  m_CroppingObjectNode = nullptr;
  m_CroppingObject = nullptr;

  //disable interactor
  if (m_BoundingShapeInteractor != nullptr)
  {
    m_BoundingShapeInteractor->SetDataNode(nullptr);
    m_BoundingShapeInteractor->EnableInteraction(false);
  }
}

void QmitkImageCropper::SetFocus()
{
  m_Controls.buttonCreateNewBoundingBox->setFocus();
}

void QmitkImageCropper::CreateQtPartControl(QWidget *parent)
{
  // create GUI widgets from the Qt Designer's .ui file
  m_Controls.setupUi(parent);

  m_Controls.boundingShapeSelector->SetDataStorage(this->GetDataStorage());
  m_Controls.boundingShapeSelector->SetPredicate(mitk::NodePredicateAnd::New(
    mitk::TNodePredicateDataType<mitk::GeometryData>::New(),
    mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("helper object"))));
  m_CroppingObjectNode = m_Controls.boundingShapeSelector->GetSelectedNode();

  connect(m_Controls.buttonCropping, SIGNAL(clicked()), this, SLOT(DoCropping()));
  connect(m_Controls.buttonMasking, SIGNAL(clicked()), this, SLOT(DoMasking()));
  connect(m_Controls.boundingShapeSelector, SIGNAL(OnSelectionChanged(const mitk::DataNode*)),
    this, SLOT(OnDataSelectionChanged(const mitk::DataNode*)));
  connect(m_Controls.buttonCreateNewBoundingBox, SIGNAL(clicked()), this, SLOT(DoCreateNewBoundingObject()));
  connect(m_Controls.buttonAdvancedSettings, SIGNAL(clicked()), this, SLOT(OnAdvancedSettingsButtonToggled()));
  connect(m_Controls.spinBoxOutsidePixelValue, SIGNAL(valueChanged(int)), this, SLOT(OnSliderValueChanged(int)));

  setDefaultGUI();
  m_Controls.labelWarningRotation->setVisible(false);

  m_Advanced = false;
  this->OnAdvancedSettingsButtonToggled();
  m_ParentWidget = parent;
}

void QmitkImageCropper::OnDataSelectionChanged(const mitk::DataNode*)
{
  m_Controls.boundingShapeSelector->setEnabled(true);
  m_CroppingObjectNode = m_Controls.boundingShapeSelector->GetSelectedNode();

  if (m_CroppingObjectNode.IsNotNull() && dynamic_cast<mitk::GeometryData*>(this->m_CroppingObjectNode->GetData()))
  {
    m_Controls.buttonAdvancedSettings->setEnabled(true);
    m_Controls.labelWarningBB->setVisible(false);
    m_CroppingObject = dynamic_cast<mitk::GeometryData*>(m_CroppingObjectNode->GetData());
    m_Advanced = true;
<commit_msg>Enabled interaction of the selected bounding box in OnDataSelectionChanged<commit_after>/*=========================================================================

Program:   Medical Imaging & Interaction Toolkit
Language:  C++
Date:      $Date$
Version:   $Revision$

Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.

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

#include "QmitkImageCropper.h"

#include <QAction>
#include <QCheckBox>
#include <QColorDialog>
#include <QInputDialog>
#include <QMessageBox>
#include <QSpinBox>
#include <QSlider>
#include <QApplication>

#include <vtkCommand.h>
#include <vtkCubeSource.h>
#include <vtkObjectFactory.h>
#include <vtkRenderWindow.h>
#include <vtkPlaneWidget.h>
#include <vtkProperty.h>
#include <vtkSmartPointer.h>
#include <vtkTransform.h>
#include <vtkTransformFilter.h>

#include <mitkBoundingShapeInteractor.h>
#include <mitkBoundingShapeCropper.h>
#include <mitkDisplayInteractor.h>
#include <mitkIDataStorageService.h>
#include <mitkImageCast.h> // Includes for image casting between ITK and MITK: added after using Plugin Generator
#include <mitkImageAccessByItk.h>
#include <mitkImageStatisticsHolder.h>
#include <mitkInteractionConst.h>
#include <mitkITKImageImport.h>
#include <mitkLabelSetImage.h>
#include <mitkNodePredicateDataType.h>
#include <mitkNodePredicateAnd.h>
#include <mitkNodePredicateNot.h>
#include <mitkNodePredicateProperty.h>
#include <mitkNodePredicateFunction.h>
#include <mitkRenderingManager.h>
#include <mitkProperties.h>

#include <itkBoundingBox.h>
#include <itkCommand.h>

#include <usModuleRegistry.h>
#include <usGetModuleContext.h>

const std::string QmitkImageCropper::VIEW_ID = "org.mitk.views.qmitkimagecropper";

QmitkImageCropper::QmitkImageCropper(QObject *)
  : m_ParentWidget(0),
  m_ImageNode(nullptr),
  m_CroppingObject(nullptr),
  m_CroppingObjectNode(nullptr),
  m_BoundingShapeInteractor(nullptr),
  m_CropOutsideValue(0),
  m_Advanced(0),
  m_Active(0),
  m_ScrollEnabled(true)
{
  CreateBoundingShapeInteractor(false);
}

QmitkImageCropper::~QmitkImageCropper()
{
  //delete pointer objects
  m_CroppingObjectNode = nullptr;
  m_CroppingObject = nullptr;

  //disable interactor
  if (m_BoundingShapeInteractor != nullptr)
  {
    m_BoundingShapeInteractor->SetDataNode(nullptr);
    m_BoundingShapeInteractor->EnableInteraction(false);
  }
}

void QmitkImageCropper::SetFocus()
{
  m_Controls.buttonCreateNewBoundingBox->setFocus();
}

void QmitkImageCropper::CreateQtPartControl(QWidget *parent)
{
  // create GUI widgets from the Qt Designer's .ui file
  m_Controls.setupUi(parent);

  m_Controls.boundingShapeSelector->SetDataStorage(this->GetDataStorage());
  m_Controls.boundingShapeSelector->SetPredicate(mitk::NodePredicateAnd::New(
    mitk::TNodePredicateDataType<mitk::GeometryData>::New(),
    mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("helper object"))));
  m_CroppingObjectNode = m_Controls.boundingShapeSelector->GetSelectedNode();

  connect(m_Controls.buttonCropping, SIGNAL(clicked()), this, SLOT(DoCropping()));
  connect(m_Controls.buttonMasking, SIGNAL(clicked()), this, SLOT(DoMasking()));
  connect(m_Controls.boundingShapeSelector, SIGNAL(OnSelectionChanged(const mitk::DataNode*)),
    this, SLOT(OnDataSelectionChanged(const mitk::DataNode*)));
  connect(m_Controls.buttonCreateNewBoundingBox, SIGNAL(clicked()), this, SLOT(DoCreateNewBoundingObject()));
  connect(m_Controls.buttonAdvancedSettings, SIGNAL(clicked()), this, SLOT(OnAdvancedSettingsButtonToggled()));
  connect(m_Controls.spinBoxOutsidePixelValue, SIGNAL(valueChanged(int)), this, SLOT(OnSliderValueChanged(int)));

  setDefaultGUI();
  m_Controls.labelWarningRotation->setVisible(false);

  m_Advanced = false;
  this->OnAdvancedSettingsButtonToggled();
  m_ParentWidget = parent;
}

void QmitkImageCropper::OnDataSelectionChanged(const mitk::DataNode*)
{
  m_Controls.boundingShapeSelector->setEnabled(true);
  m_CroppingObjectNode = m_Controls.boundingShapeSelector->GetSelectedNode();

  if (m_CroppingObjectNode.IsNotNull() && dynamic_cast<mitk::GeometryData*>(this->m_CroppingObjectNode->GetData()))
  {
    m_Controls.buttonAdvancedSettings->setEnabled(true);
    m_Controls.labelWarningBB->setVisible(false);
    m_CroppingObject = dynamic_cast<mitk::GeometryData*>(m_CroppingObjectNode->GetData());
    m_Advanced = true;

    m_BoundingShapeInteractor->EnableInteraction(true);
    m_BoundingShapeInteractor->SetDataNode(m_CroppingObjectNode);

{'fraction_non_alphanumeric': 0.14330874604847207, 'fraction_numerical': 0.0008429926238145417, 'mean_word_length': 7.987689393939394, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 119, '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': '259779', 'n_tokens_mistral': 3096, 'n_tokens_neox': 2986, 'n_words': 516}