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

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

// ####### Blueberry includes #######
#include <berryISelectionService.h>
#include <berryIWorkbenchWindow.h>

// ####### Qmitk includes #######
#include "QmitkBrainNetworkAnalysisView.h"
#include "QmitkStdMultiWidget.h"

// ####### Qt includes #######
#include <QMessageBox>

// ####### ITK includes #######
#include <itkRGBAPixel.h>

// ####### MITK includes #######

#include <mitkConnectomicsConstantsManager.h>
#include "mitkConnectomicsSyntheticNetworkGenerator.h"
#include "mitkConnectomicsSimulatedAnnealingManager.h"
#include "mitkConnectomicsSimulatedAnnealingPermutationModularity.h"
#include "mitkConnectomicsSimulatedAnnealingCostFunctionModularity.h"

// Includes for image casting between ITK and MITK
#include "mitkImageCast.h"
#include "mitkITKImageImport.h"
#include "mitkImageAccessByItk.h"

const std::string QmitkBrainNetworkAnalysisView::VIEW_ID = "org.mitk.views.brainnetworkanalysis";

QmitkBrainNetworkAnalysisView::QmitkBrainNetworkAnalysisView()
: QmitkFunctionality()
, m_Controls( 0 )
, m_MultiWidget( NULL )  
, m_ConnectomicsNetworkCreator( mitk::ConnectomicsNetworkCreator::New() ) 
, m_demomode( false )
, m_currentIndex( 0 )
{
}

QmitkBrainNetworkAnalysisView::~QmitkBrainNetworkAnalysisView()
{
}


void QmitkBrainNetworkAnalysisView::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::QmitkBrainNetworkAnalysisViewControls;
    m_Controls->setupUi( parent );

    QObject::connect( m_Controls->convertToRGBAImagePushButton, SIGNAL(clicked()), this, SLOT(OnConvertToRGBAImagePushButtonClicked()) );
    QObject::connect( m_Controls->networkifyPushButton, SIGNAL(clicked()), this, SLOT(OnNetworkifyPushButtonClicked()) );
    QObject::connect( m_Controls->syntheticNetworkCreationPushButton, SIGNAL(clicked()), this, SLOT(OnSyntheticNetworkCreationPushButtonClicked()) );
    QObject::connect( (QObject*)( m_Controls->syntheticNetworkComboBox ), SIGNAL(currentIndexChanged (int)),	this, SLOT(OnSyntheticNetworkComboBoxCurrentIndexChanged(int)) );
    QObject::connect( (QObject*)( m_Controls->modularizePushButton ), SIGNAL(clicked()),	this, SLOT(OnModularizePushButtonClicked()) );
  }

  // GUI is different for developer and demo mode
  m_demomode = false;
  if( m_demomode )
  {
    this->m_Controls->convertToRGBAImagePushButton->hide();
    this->m_Controls->networkifyPushButton->show();
    this->m_Controls->networkifyPushButton->setText( "Create Network" );
    this->m_Controls->modularizePushButton->show();

    this->m_Controls->syntheticNetworkOptionsGroupBox->hide();
  }
  else
  {
    this->m_Controls->convertToRGBAImagePushButton->show();
    this->m_Controls->networkifyPushButton->show();
    this->m_Controls->networkifyPushButton->setText( "Networkify" );
    this->m_Controls->modularizePushButton->show();

    this->m_Controls->syntheticNetworkOptionsGroupBox->show();
    //--------------------------- fill comboBox---------------------------
    this->m_Controls->syntheticNetworkComboBox->insertItem(0,"Regular lattice");
    this->m_Controls->syntheticNetworkComboBox->insertItem(1,"Heterogenic sphere");
    this->m_Controls->syntheticNetworkComboBox->insertItem(2,"Random network");
    this->m_Controls->syntheticNetworkComboBox->insertItem(3,"Scale free network");
    this->m_Controls->syntheticNetworkComboBox->insertItem(4,"Small world network");
  }

  this->WipeDisplay();
}


void QmitkBrainNetworkAnalysisView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget)
{
  m_MultiWidget = &stdMultiWidget;
}


void QmitkBrainNetworkAnalysisView::StdMultiWidgetNotAvailable()
{
  m_MultiWidget = NULL;
}

void QmitkBrainNetworkAnalysisView::WipeDisplay()
{
  m_Controls->lblWarning->setVisible( true );
  m_Controls->inputImageOneNameLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->inputImageOneNameLabel->setVisible( false );
  m_Controls->inputImageOneLabel->setVisible( false );
  m_Controls->inputImageTwoNameLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->inputImageTwoNameLabel->setVisible( false );
  m_Controls->inputImageTwoLabel->setVisible( false );
  m_Controls->numberOfVerticesLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->numberOfEdgesLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->numberOfSelfLoopsLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->averageDegreeLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->connectionDensityLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->efficiencyLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->globalClusteringLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->betweennessNetworkHistogramCanvas->SetHistogram(   NULL );
  m_Controls->degreeNetworkHistogramCanvas->SetHistogram(       NULL );
  m_Controls->shortestPathNetworkHistogramCanvas->SetHistogram( NULL );
  m_Controls->betweennessNetworkHistogramCanvas->Clear();
  m_Controls->degreeNetworkHistogramCanvas->Clear();
  m_Controls->shortestPathNetworkHistogramCanvas->Clear();
  m_Controls->betweennessNetworkHistogramCanvas->update();
  m_Controls->degreeNetworkHistogramCanvas->update();
  m_Controls->shortestPathNetworkHistogramCanvas->update();
}

void QmitkBrainNetworkAnalysisView::OnSelectionChanged( std::vector<mitk::DataNode*> nodes )
{
  this->WipeDisplay();

  // Valid options are either
  // 1 image (parcellation)
  //
  // 1 image (parcellation)
  // 1 fiber bundle
  //
  // 1 network
  if( nodes.size() > 2 )
  {
    return;
  }<commit_msg>Now the plots clear as planned<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.

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

// ####### Blueberry includes #######
#include <berryISelectionService.h>
#include <berryIWorkbenchWindow.h>

// ####### Qmitk includes #######
#include "QmitkBrainNetworkAnalysisView.h"
#include "QmitkStdMultiWidget.h"

// ####### Qt includes #######
#include <QMessageBox>

// ####### ITK includes #######
#include <itkRGBAPixel.h>

// ####### MITK includes #######

#include <mitkConnectomicsConstantsManager.h>
#include "mitkConnectomicsSyntheticNetworkGenerator.h"
#include "mitkConnectomicsSimulatedAnnealingManager.h"
#include "mitkConnectomicsSimulatedAnnealingPermutationModularity.h"
#include "mitkConnectomicsSimulatedAnnealingCostFunctionModularity.h"

// Includes for image casting between ITK and MITK
#include "mitkImageCast.h"
#include "mitkITKImageImport.h"
#include "mitkImageAccessByItk.h"

const std::string QmitkBrainNetworkAnalysisView::VIEW_ID = "org.mitk.views.brainnetworkanalysis";

QmitkBrainNetworkAnalysisView::QmitkBrainNetworkAnalysisView()
: QmitkFunctionality()
, m_Controls( 0 )
, m_MultiWidget( NULL )  
, m_ConnectomicsNetworkCreator( mitk::ConnectomicsNetworkCreator::New() ) 
, m_demomode( false )
, m_currentIndex( 0 )
{
}

QmitkBrainNetworkAnalysisView::~QmitkBrainNetworkAnalysisView()
{
}


void QmitkBrainNetworkAnalysisView::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::QmitkBrainNetworkAnalysisViewControls;
    m_Controls->setupUi( parent );

    QObject::connect( m_Controls->convertToRGBAImagePushButton, SIGNAL(clicked()), this, SLOT(OnConvertToRGBAImagePushButtonClicked()) );
    QObject::connect( m_Controls->networkifyPushButton, SIGNAL(clicked()), this, SLOT(OnNetworkifyPushButtonClicked()) );
    QObject::connect( m_Controls->syntheticNetworkCreationPushButton, SIGNAL(clicked()), this, SLOT(OnSyntheticNetworkCreationPushButtonClicked()) );
    QObject::connect( (QObject*)( m_Controls->syntheticNetworkComboBox ), SIGNAL(currentIndexChanged (int)),	this, SLOT(OnSyntheticNetworkComboBoxCurrentIndexChanged(int)) );
    QObject::connect( (QObject*)( m_Controls->modularizePushButton ), SIGNAL(clicked()),	this, SLOT(OnModularizePushButtonClicked()) );
  }

  // GUI is different for developer and demo mode
  m_demomode = false;
  if( m_demomode )
  {
    this->m_Controls->convertToRGBAImagePushButton->hide();
    this->m_Controls->networkifyPushButton->show();
    this->m_Controls->networkifyPushButton->setText( "Create Network" );
    this->m_Controls->modularizePushButton->show();

    this->m_Controls->syntheticNetworkOptionsGroupBox->hide();
  }
  else
  {
    this->m_Controls->convertToRGBAImagePushButton->show();
    this->m_Controls->networkifyPushButton->show();
    this->m_Controls->networkifyPushButton->setText( "Networkify" );
    this->m_Controls->modularizePushButton->show();

    this->m_Controls->syntheticNetworkOptionsGroupBox->show();
    //--------------------------- fill comboBox---------------------------
    this->m_Controls->syntheticNetworkComboBox->insertItem(0,"Regular lattice");
    this->m_Controls->syntheticNetworkComboBox->insertItem(1,"Heterogenic sphere");
    this->m_Controls->syntheticNetworkComboBox->insertItem(2,"Random network");
    this->m_Controls->syntheticNetworkComboBox->insertItem(3,"Scale free network");
    this->m_Controls->syntheticNetworkComboBox->insertItem(4,"Small world network");
  }

  this->WipeDisplay();
}


void QmitkBrainNetworkAnalysisView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget)
{
  m_MultiWidget = &stdMultiWidget;
}


void QmitkBrainNetworkAnalysisView::StdMultiWidgetNotAvailable()
{
  m_MultiWidget = NULL;
}

void QmitkBrainNetworkAnalysisView::WipeDisplay()
{
  m_Controls->lblWarning->setVisible( true );
  m_Controls->inputImageOneNameLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->inputImageOneNameLabel->setVisible( false );
  m_Controls->inputImageOneLabel->setVisible( false );
  m_Controls->inputImageTwoNameLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->inputImageTwoNameLabel->setVisible( false );
  m_Controls->inputImageTwoLabel->setVisible( false );
  m_Controls->numberOfVerticesLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->numberOfEdgesLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->numberOfSelfLoopsLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->averageDegreeLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->connectionDensityLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->efficiencyLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->globalClusteringLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH );
  m_Controls->betweennessNetworkHistogramCanvas->SetHistogram(   NULL );
  m_Controls->degreeNetworkHistogramCanvas->SetHistogram(       NULL );
  m_Controls->shortestPathNetworkHistogramCanvas->SetHistogram( NULL );
  m_Controls->betweennessNetworkHistogramCanvas->update();
  m_Controls->degreeNetworkHistogramCanvas->update();
  m_Controls->shortestPathNetworkHistogramCanvas->update();
  m_Controls->betweennessNetworkHistogramCanvas->Clear();
  m_Controls->degreeNetworkHistogramCanvas->Clear();
  m_Controls->shortestPathNetworkHistogramCanvas->Clear();
  m_Controls->betweennessNetworkHistogramCanvas->Replot();
  m_Controls->degreeNetworkHistogramCanvas->Replot();
  m_Controls->shortestPathNetworkHistogramCanvas->Replot();
}

void QmitkBrainNetworkAnalysisView::OnSelectionChanged( std::vector<mitk::DataNode*> nodes )
{
  this->WipeDisplay();

  // Valid options are either
  // 1 image (parcellation)
  //
  // 1 image (parcellation)
  // 1 fiber bundle
  //
  // 1 network
  if( nodes.size() > 2 )
  {
    return;
  }
{'fraction_non_alphanumeric': 0.15, 'fraction_numerical': 0.0018099547511312218, 'mean_word_length': 6.5820468839336765, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 221, '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': '6277813', 'n_tokens_mistral': 4009, 'n_tokens_neox': 3868, 'n_words': 600}