<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.

===================================================================*/
// Blueberry
#include <mitkIRenderingManager.h>
#include <mitkIRenderWindowPart.h>
#include <mitkILinkedRenderWindowPart.h>


// Qmitk
#include "QmitkToFUtilView.h"
#include <QmitkStdMultiWidget.h>
#include <QmitkTextOverlay.h>

// Qt
#include <QMessageBox>
#include <QString>

// MITK
#include <mitkBaseRenderer.h>
#include <mitkGlobalInteraction.h>
#include <mitkLookupTableProperty.h>
#include <mitkToFDistanceImageToPointSetFilter.h>
#include <mitkTransferFunction.h>
#include <mitkTransferFunctionProperty.h>

// VTK
#include <vtkCamera.h>

// ITK
#include <itkCommand.h>

const std::string QmitkToFUtilView::VIEW_ID = "org.mitk.views.tofutil";

QmitkToFUtilView::QmitkToFUtilView()
: QmitkAbstractView()
, m_Controls(NULL), m_MultiWidget( NULL )
, m_MitkDistanceImage(NULL), m_MitkAmplitudeImage(NULL), m_MitkIntensityImage(NULL), m_Surface(NULL)
, m_DistanceImageNode(NULL), m_AmplitudeImageNode(NULL), m_IntensityImageNode(NULL), m_RGBImageNode(NULL), m_SurfaceNode(NULL)
, m_ToFImageRecorder(NULL), m_ToFImageGrabber(NULL), m_ToFDistanceImageToSurfaceFilter(NULL), m_ToFCompositeFilter(NULL)
, m_SurfaceDisplayCount(0), m_2DDisplayCount(0)
, m_RealTimeClock(NULL)
, m_StepsForFramerate(100)
, m_2DTimeBefore(0.0)
, m_2DTimeAfter(0.0)
, m_VideoEnabled(false)
{
  this->m_Frametimer = new QTimer(this);

  this->m_ToFDistanceImageToSurfaceFilter = mitk::ToFDistanceImageToSurfaceFilter::New();
  this->m_ToFCompositeFilter = mitk::ToFCompositeFilter::New();
  this->m_ToFImageRecorder = mitk::ToFImageRecorder::New();
  this->m_ToFSurfaceVtkMapper3D = mitk::ToFSurfaceVtkMapper3D::New();
}

QmitkToFUtilView::~QmitkToFUtilView()
{
  OnToFCameraStopped();
  OnToFCameraDisconnected();
  ResetGUIToDefault();
}

void QmitkToFUtilView::SetFocus()
{
  m_Controls->m_ToFConnectionWidget->setFocus();
}

void QmitkToFUtilView::CreateQtPartControl( QWidget *parent )
{
  // build up qt view, unless already done
  if ( !m_Controls )
  {
    // create GUI widgets from the Qt Designer's .ui file
    m_Controls = new Ui::QmitkToFUtilViewControls;
    m_Controls->setupUi( parent );

    connect(m_Frametimer, SIGNAL(timeout()), this, SLOT(OnUpdateCamera()));
    connect( (QObject*)(m_Controls->m_ToFConnectionWidget), SIGNAL(ToFCameraConnected()), this, SLOT(OnToFCameraConnected()) );
    connect( (QObject*)(m_Controls->m_ToFConnectionWidget), SIGNAL(ToFCameraDisconnected()), this, SLOT(OnToFCameraDisconnected()) );
    connect( (QObject*)(m_Controls->m_ToFConnectionWidget), SIGNAL(ToFCameraSelected(const QString)), this, SLOT(OnToFCameraSelected(const QString)) );
    connect( (QObject*)(m_Controls->m_ToFRecorderWidget), SIGNAL(ToFCameraStarted()), this, SLOT(OnToFCameraStarted()) );
    connect( (QObject*)(m_Controls->m_ToFRecorderWidget), SIGNAL(ToFCameraStopped()), this, SLOT(OnToFCameraStopped()) );
    connect( (QObject*)(m_Controls->m_ToFRecorderWidget), SIGNAL(RecordingStarted()), this, SLOT(OnToFCameraStopped()) );
    connect( (QObject*)(m_Controls->m_ToFRecorderWidget), SIGNAL(RecordingStopped()), this, SLOT(OnToFCameraStarted()) );
    connect( (QObject*)(m_Controls->m_TextureCheckBox), SIGNAL(toggled(bool)), this, SLOT(OnTextureCheckBoxChecked(bool)) );
    connect( (QObject*)(m_Controls->m_VideoTextureCheckBox), SIGNAL(toggled(bool)), this, SLOT(OnVideoTextureCheckBoxChecked(bool)) );
  }
}

void QmitkToFUtilView::Activated()
{
  //get the current RenderWindowPart or open a new one if there is none
  if(this->GetRenderWindowPart(OPEN))
  {
    mitk::ILinkedRenderWindowPart* linkedRenderWindowPart = dynamic_cast<mitk::ILinkedRenderWindowPart*>(this->GetRenderWindowPart());
    if(linkedRenderWindowPart == 0)
    {
      MITK_ERROR << "No linked StdMultiWidget avaiable!!!";
    }
    else
    {
      linkedRenderWindowPart->EnableSlicingPlanes(false);
    }
    GetRenderWindowPart()->GetRenderWindow("transversal")->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Transversal);
    GetRenderWindowPart()->GetRenderWindow("transversal")->GetSliceNavigationController()->SliceLockedOn();
    GetRenderWindowPart()->GetRenderWindow("sagittal")->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Transversal);
    GetRenderWindowPart()->GetRenderWindow("sagittal")->GetSliceNavigationController()->SliceLockedOn();
    GetRenderWindowPart()->GetRenderWindow("coronal")->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Transversal);
    GetRenderWindowPart()->GetRenderWindow("coronal")->GetSliceNavigationController()->SliceLockedOn();

    this->GetRenderWindowPart()->GetRenderingManager()->InitializeViews();

    this->UseToFVisibilitySettings(true);

    m_Controls->m_ToFCompositeFilterWidget->SetToFCompositeFilter(this->m_ToFCompositeFilter);
    m_Controls->m_ToFCompositeFilterWidget->SetDataStorage(this->GetDataStorage());
    m_Controls->tofMeasurementWidget->InitializeWidget(this->GetRenderWindowPart()->GetRenderWindows(),this->GetDataStorage());

    if (this->m_ToFImageGrabber.IsNull())
    {
      m_Controls->m_ToFRecorderWidget->setEnabled(false);
      m_Controls->m_ToFVisualisationSettingsWidget->setEnabled(false);
      m_Controls->m_ToFCompositeFilterWidget->setEnabled(false);
      m_Controls->tofMeasurementWidget->setEnabled(false);
      m_Controls->SurfacePropertiesBox->setEnabled(false);
    }
  }
}

void QmitkToFUtilView::ActivatedZombieView(berry::IWorkbenchPartReference::Pointer /*zombieView*/)
{
  ResetGUIToDefault();
}

void QmitkToFUtilView::Deactivated()
{
}

void QmitkToFUtilView::Visible()
{
}

void QmitkToFUtilView::Hidden()
{
}
<commit_msg>Moved function calls from Destructor to Deactivated method.<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.

===================================================================*/
// Blueberry
#include <mitkIRenderingManager.h>
#include <mitkIRenderWindowPart.h>
#include <mitkILinkedRenderWindowPart.h>


// Qmitk
#include "QmitkToFUtilView.h"
#include <QmitkStdMultiWidget.h>
#include <QmitkTextOverlay.h>

// Qt
#include <QMessageBox>
#include <QString>

// MITK
#include <mitkBaseRenderer.h>
#include <mitkGlobalInteraction.h>
#include <mitkLookupTableProperty.h>
#include <mitkToFDistanceImageToPointSetFilter.h>
#include <mitkTransferFunction.h>
#include <mitkTransferFunctionProperty.h>

// VTK
#include <vtkCamera.h>

// ITK
#include <itkCommand.h>

const std::string QmitkToFUtilView::VIEW_ID = "org.mitk.views.tofutil";

QmitkToFUtilView::QmitkToFUtilView()
: QmitkAbstractView()
, m_Controls(NULL), m_MultiWidget( NULL )
, m_MitkDistanceImage(NULL), m_MitkAmplitudeImage(NULL), m_MitkIntensityImage(NULL), m_Surface(NULL)
, m_DistanceImageNode(NULL), m_AmplitudeImageNode(NULL), m_IntensityImageNode(NULL), m_RGBImageNode(NULL), m_SurfaceNode(NULL)
, m_ToFImageRecorder(NULL), m_ToFImageGrabber(NULL), m_ToFDistanceImageToSurfaceFilter(NULL), m_ToFCompositeFilter(NULL)
, m_SurfaceDisplayCount(0), m_2DDisplayCount(0)
, m_RealTimeClock(NULL)
, m_StepsForFramerate(100)
, m_2DTimeBefore(0.0)
, m_2DTimeAfter(0.0)
, m_VideoEnabled(false)
{
  this->m_Frametimer = new QTimer(this);

  this->m_ToFDistanceImageToSurfaceFilter = mitk::ToFDistanceImageToSurfaceFilter::New();
  this->m_ToFCompositeFilter = mitk::ToFCompositeFilter::New();
  this->m_ToFImageRecorder = mitk::ToFImageRecorder::New();
  this->m_ToFSurfaceVtkMapper3D = mitk::ToFSurfaceVtkMapper3D::New();
}

QmitkToFUtilView::~QmitkToFUtilView()
{
}

void QmitkToFUtilView::SetFocus()
{
  m_Controls->m_ToFConnectionWidget->setFocus();
}

void QmitkToFUtilView::CreateQtPartControl( QWidget *parent )
{
  // build up qt view, unless already done
  if ( !m_Controls )
  {
    // create GUI widgets from the Qt Designer's .ui file
    m_Controls = new Ui::QmitkToFUtilViewControls;
    m_Controls->setupUi( parent );

    connect(m_Frametimer, SIGNAL(timeout()), this, SLOT(OnUpdateCamera()));
    connect( (QObject*)(m_Controls->m_ToFConnectionWidget), SIGNAL(ToFCameraConnected()), this, SLOT(OnToFCameraConnected()) );
    connect( (QObject*)(m_Controls->m_ToFConnectionWidget), SIGNAL(ToFCameraDisconnected()), this, SLOT(OnToFCameraDisconnected()) );
    connect( (QObject*)(m_Controls->m_ToFConnectionWidget), SIGNAL(ToFCameraSelected(const QString)), this, SLOT(OnToFCameraSelected(const QString)) );
    connect( (QObject*)(m_Controls->m_ToFRecorderWidget), SIGNAL(ToFCameraStarted()), this, SLOT(OnToFCameraStarted()) );
    connect( (QObject*)(m_Controls->m_ToFRecorderWidget), SIGNAL(ToFCameraStopped()), this, SLOT(OnToFCameraStopped()) );
    connect( (QObject*)(m_Controls->m_ToFRecorderWidget), SIGNAL(RecordingStarted()), this, SLOT(OnToFCameraStopped()) );
    connect( (QObject*)(m_Controls->m_ToFRecorderWidget), SIGNAL(RecordingStopped()), this, SLOT(OnToFCameraStarted()) );
    connect( (QObject*)(m_Controls->m_TextureCheckBox), SIGNAL(toggled(bool)), this, SLOT(OnTextureCheckBoxChecked(bool)) );
    connect( (QObject*)(m_Controls->m_VideoTextureCheckBox), SIGNAL(toggled(bool)), this, SLOT(OnVideoTextureCheckBoxChecked(bool)) );
  }
}

void QmitkToFUtilView::Activated()
{
  //get the current RenderWindowPart or open a new one if there is none
  if(this->GetRenderWindowPart(OPEN))
  {
    mitk::ILinkedRenderWindowPart* linkedRenderWindowPart = dynamic_cast<mitk::ILinkedRenderWindowPart*>(this->GetRenderWindowPart());
    if(linkedRenderWindowPart == 0)
    {
      MITK_ERROR << "No linked StdMultiWidget avaiable!!!";
    }
    else
    {
      linkedRenderWindowPart->EnableSlicingPlanes(false);
    }
    GetRenderWindowPart()->GetRenderWindow("transversal")->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Transversal);
    GetRenderWindowPart()->GetRenderWindow("transversal")->GetSliceNavigationController()->SliceLockedOn();
    GetRenderWindowPart()->GetRenderWindow("sagittal")->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Transversal);
    GetRenderWindowPart()->GetRenderWindow("sagittal")->GetSliceNavigationController()->SliceLockedOn();
    GetRenderWindowPart()->GetRenderWindow("coronal")->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Transversal);
    GetRenderWindowPart()->GetRenderWindow("coronal")->GetSliceNavigationController()->SliceLockedOn();

    this->GetRenderWindowPart()->GetRenderingManager()->InitializeViews();

    this->UseToFVisibilitySettings(true);

    m_Controls->m_ToFCompositeFilterWidget->SetToFCompositeFilter(this->m_ToFCompositeFilter);
    m_Controls->m_ToFCompositeFilterWidget->SetDataStorage(this->GetDataStorage());
    m_Controls->tofMeasurementWidget->InitializeWidget(this->GetRenderWindowPart()->GetRenderWindows(),this->GetDataStorage());

    if (this->m_ToFImageGrabber.IsNull())
    {
      m_Controls->m_ToFRecorderWidget->setEnabled(false);
      m_Controls->m_ToFVisualisationSettingsWidget->setEnabled(false);
      m_Controls->m_ToFCompositeFilterWidget->setEnabled(false);
      m_Controls->tofMeasurementWidget->setEnabled(false);
      m_Controls->SurfacePropertiesBox->setEnabled(false);
    }
  }
}

void QmitkToFUtilView::ActivatedZombieView(berry::IWorkbenchPartReference::Pointer /*zombieView*/)
{
  ResetGUIToDefault();
}

void QmitkToFUtilView::Deactivated()
{
  OnToFCameraStopped();
  OnToFCameraDisconnected();
  ResetGUIToDefault();
}

void QmitkToFUtilView::Visible()
{
}

void QmitkToFUtilView::Hidden()
{
}

{'fraction_non_alphanumeric': 0.15018581354015187, 'fraction_numerical': 0.0024236548715462916, 'mean_word_length': 7.835831548893648, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 163, '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': '4555100', 'n_tokens_mistral': 4069, 'n_tokens_neox': 3997, 'n_words': 541}