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

Program:   Medical Imaging & Interaction Toolkit
Module:    $RCSfile$
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.

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


/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
#include "mitkProperties.h"
#include "mitkStringProperty.h"
#include "mitkLevelWindowProperty.h"
#include "mitkGeometry2DDataMapper2D.h"
#include "mitkOpenGLRenderer.h"
#include "mitkPositionEvent.h"
#include "mitkInteractionConst.h"
#include "mitkGlobalInteraction.h"
#include "mitkPositionTracker.h"
#include "mitkPointSet.h"
#include "mitkStateEvent.h"
#include "mitkPlaneGeometry.h"
#include "mitkLine.h"

#include <vtkRenderer.h>
#include <vtkRenderWindow.h>


void QmitkStdMultiWidget::init()
{
  mitkWidget1->setPaletteBackgroundColor("red");
  mitkWidget2->setPaletteBackgroundColor("green");
  mitkWidget3->setPaletteBackgroundColor("blue");
  mitkWidget4->setPaletteBackgroundColor("yellow");

  planesIterator = NULL;
  m_PositionTracker = NULL;

  // transfer colors in WorldGeometry-Nodes of the associated Renderer
  QColor qcolor;
  float color[3] = {1.0f,1.0f,1.0f};
  mitk::DataTreeNode::Pointer planeNode;
  mitk::IntProperty::Pointer  layer;

  // ... of widget 1
  qcolor=mitkWidget1->paletteBackgroundColor();
  color[0]=qcolor.red()/255.0;
  color[1]=qcolor.green()/255.0;
  color[2]=qcolor.blue()/255.0;
  planeNode=mitkWidget1->GetRenderer()->GetCurrentWorldGeometry2DNode();
  planeNode->SetColor(color);
  layer = new mitk::IntProperty(1000);
  planeNode->SetProperty("layer",layer);

  // ... of widget 2
  qcolor=mitkWidget2->paletteBackgroundColor();
  color[0]=qcolor.red()/255.0;
  color[1]=qcolor.green()/255.0;
  color[2]=qcolor.blue()/255.0;
  planeNode=mitkWidget2->GetRenderer()->GetCurrentWorldGeometry2DNode();
  planeNode->SetColor(color);
  layer = new mitk::IntProperty(1000);
  planeNode->SetProperty("layer",layer);

  // ... of widget 3
  qcolor=mitkWidget3->paletteBackgroundColor();
  color[0]=qcolor.red()/255.0;
  color[1]=qcolor.green()/255.0;
  color[2]=qcolor.blue()/255.0;
  planeNode=mitkWidget3->GetRenderer()->GetCurrentWorldGeometry2DNode();
  planeNode->SetColor(color);
  layer = new mitk::IntProperty(1000);
  planeNode->SetProperty("layer",layer);

  // ... of widget 4
  qcolor=mitkWidget4->paletteBackgroundColor();
  color[0]=qcolor.red()/255.0;
  color[1]=qcolor.green()/255.0; 
  color[2]=qcolor.blue()/255.0;
  planeNode=mitkWidget4->GetRenderer()->GetCurrentWorldGeometry2DNode();
  planeNode->SetColor(color);
  layer = new mitk::IntProperty(1000);
  planeNode->SetProperty("layer",layer);

  // create a slice rotator
  // m_SlicesRotator = mitk::SlicesRotator::New();
  // @TODO next line causes sure memory leak
  // rotator will be created nonetheless (will be switched on and off)
  m_SlicesRotation = false; 
  m_SlicesRotator = new mitk::SlicesRotator("slices-rotator");
  m_SlicesRotator->AddSliceController( 
    mitkWidget1->GetSliceNavigationController() );
  m_SlicesRotator->AddSliceController( 
    mitkWidget2->GetSliceNavigationController() );
  m_SlicesRotator->AddSliceController(
    mitkWidget3->GetSliceNavigationController() );

  //initialize timeNavigationController: send time via sliceNavigationControllers
  timeNavigationController = mitk::SliceNavigationController::New(NULL);
  timeNavigationController->ConnectGeometryTimeEvent(
    mitkWidget1->GetSliceNavigationController(), false);
  timeNavigationController->ConnectGeometryTimeEvent(
    mitkWidget2->GetSliceNavigationController(), false);
  timeNavigationController->ConnectGeometryTimeEvent(
    mitkWidget3->GetSliceNavigationController(), false);
  timeNavigationController->ConnectGeometryTimeEvent(
    mitkWidget4->GetSliceNavigationController(), false);
  mitkWidget1->GetSliceNavigationController()
    ->ConnectGeometrySendEvent(mitkWidget4->GetRenderer());

  //reverse connection between sliceNavigationControllers and timeNavigationController
  mitkWidget1->GetSliceNavigationController()
    ->ConnectGeometryTimeEvent(timeNavigationController.GetPointer(), false);
  mitkWidget2->GetSliceNavigationController()
    ->ConnectGeometryTimeEvent(timeNavigationController.GetPointer(), false);
  mitkWidget3->GetSliceNavigationController()
    ->ConnectGeometryTimeEvent(timeNavigationController.GetPointer(), false);
  mitkWidget4->GetSliceNavigationController()
    ->ConnectGeometryTimeEvent(timeNavigationController.GetPointer(), false);

  // instantiate display interactor
  m_MoveAndZoomInteractor = mitk::DisplayVectorInteractor::New(
    "moveNzoom", new mitk::DisplayInteractor() );
  
  m_LastLeftClickPositionSupplier = 
    mitk::CoordinateSupplier::New("navigation", NULL);
  mitk::GlobalInteraction::GetInstance()->AddListener(
    m_LastLeftClickPositionSupplier
  );
  
  m_GradientBackground1 = mitk::GradientBackground::New();
  m_GradientBackground1->SetRenderWindow(
    mitkWidget1->GetRenderer()->GetRenderWindow() );
  m_GradientBackground1->Disable();
  
  m_GradientBackground2 = mitk::GradientBackground::New();
  m_GradientBackground2->SetRenderWindow( 
    mitkWidget2->GetRenderer()->GetRenderWindow() );
  m_GradientBackground2->Disable();
  
  m_GradientBackground3 = mitk::GradientBackground::New();
  m_GradientBackground3->SetRenderWindow( 
    mitkWidget3->GetRenderer()->GetRenderWindow() );
  m_GradientBackground3->Disable();
  
  m_GradientBackground4 = mitk::GradientBackground::New();
  m_GradientBackground4->SetRenderWindow(
    mitkWidget4->GetRenderer()->GetRenderWindow() );
  m_GradientBackground4->Enable();
}

void QmitkStdMultiWidget::changeLayoutTo2DImagesUp()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to 2D images up... " << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0,02, "QmitkStdMultiWidgetLayout");

  QHBoxLayout * layout4 = new QHBoxLayout( 0, 0, 6, "layout4");
  QGridLayout* layout3 = new QGridLayout( 0, 2, 1, 0, 6, "layout3");

  QHBoxLayout *TwoDLayout = new QHBoxLayout( 0, 0, 6, "2DLayout");

  mitkWidget1->setMaximumSize(2000,200);
  mitkWidget2->setMaximumSize(2000,200);
  mitkWidget3->setMaximumSize(2000,200);

  TwoDLayout->addWidget( mitkWidget1 );
  TwoDLayout->addWidget( mitkWidget2 );
  TwoDLayout->addWidget( mitkWidget3 );

  if ( mitkWidget1->isHidden() ) mitkWidget1->show();
  if ( mitkWidget2->isHidden() ) mitkWidget2->show();
  if ( mitkWidget3->isHidden() ) mitkWidget3->show();
  if ( mitkWidget4->isHidden() ) mitkWidget4->show();

  layout3->addLayout( TwoDLayout , 0, 0 );
  layout3->addWidget( mitkWidget4, 1, 0 );

  layout4->addLayout( layout3 );
  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_2D_IMAGES_UP;
}

void QmitkStdMultiWidget::changeLayoutTo2DImagesLeft()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to 2D images left... " << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0,0, "QmitkStdMultiWidgetLayout");

  QHBoxLayout *layout4 = new QHBoxLayout( 0, 0, 6, "layout4");
  QGridLayout *layout3 = new QGridLayout( 0, 1, 2, 0, 6, "layout3");

  QVBoxLayout *TwoDLayout = new QVBoxLayout( 0, 0, 6, "2DLayout");

  mitkWidget1->setMaximumSize(300,300);
  mitkWidget2->setMaximumSize(300,300);
  mitkWidget3->setMaximumSize(300,300);

  TwoDLayout->addWidget( mitkWidget1 );
  TwoDLayout->addWidget( mitkWidget2 );
  TwoDLayout->addWidget( mitkWidget3 );

  if ( mitkWidget1->isHidden() ) mitkWidget1->show();
  if ( mitkWidget2->isHidden() ) mitkWidget2->show();
  if ( mitkWidget3->isHidden() ) mitkWidget3->show();
  if ( mitkWidget4->isHidden() ) mitkWidget4->show();

  layout3->addLayout( TwoDLayout , 0, 0 );
  layout3->addWidget( mitkWidget4, 0,1 );

  layout4->addLayout( layout3 );
  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_2D_IMAGES_LEFT;
}

void QmitkStdMultiWidget::changeLayoutToDefault()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to default... " << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0, 0, "QmitkStdMultiWidgetLayout");

  QHBoxLayout *layout4 = new QHBoxLayout( 0, 0, 6, "layout4");
  QGridLayout *layout3 = new QGridLayout( 0, 2, 2, 0, 6, "layout3");

  mitkWidget1->setMaximumSize(2000,2000);
  mitkWidget2->setMaximumSize(2000,2000);
  mitkWidget3->setMaximumSize(2000,2000);

  layout3->addWidget( mitkWidget1,0,0 );
  layout3->addWidget( mitkWidget2,0,1 );
  layout3->addWidget( mitkWidget3,1,0 );
  layout3->addWidget( mitkWidget4,1,1 );

  if ( mitkWidget1->isHidden() ) mitkWidget1->show();
  if ( mitkWidget2->isHidden() ) mitkWidget2->show();
  if ( mitkWidget3->isHidden() ) mitkWidget3->show();
  if ( mitkWidget4->isHidden() ) mitkWidget4->show();

  layout4->addLayout( layout3 );
  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_DEFAULT;
}

void QmitkStdMultiWidget::changeLayoutToBig3D()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to big 3D ..." << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0, 0, "QmitkStdMultiWidgetLayout");

  QHBoxLayout *layout4 = new QHBoxLayout( 0, 0, 6, "layout4");
  mitkWidget1->hide();
  mitkWidget2->hide();
  mitkWidget3->hide();
  if ( mitkWidget4->isHidden() ) mitkWidget4->show();

  layout4->addWidget( mitkWidget4 );
  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_BIG_3D;
}

void QmitkStdMultiWidget::changeLayoutToWidget1()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to big Widget1 ..." << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0, 0, "QmitkStdMultiWidgetLayout");

  QHBoxLayout *layout4 = new QHBoxLayout( 0, 0, 6, "layout4");

  mitkWidget1->setMaximumSize(2000,2000);

  mitkWidget2->hide();
  mitkWidget3->hide();
  mitkWidget4->hide();
  if ( mitkWidget1->isHidden() ) mitkWidget1->show();

  layout4->addWidget( mitkWidget1 );
  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_WIDGET1;
}

void QmitkStdMultiWidget::changeLayoutToWidget2()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to big Widget2 ..." << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0, 0, "QmitkStdMultiWidgetLayout");
  QHBoxLayout *layout4 = new QHBoxLayout( 0, 0, 6, "layout4");

  mitkWidget2->setMaximumSize(2000,2000);

  mitkWidget1->hide();
  mitkWidget3->hide();
  mitkWidget4->hide();
  if ( mitkWidget2->isHidden() ) mitkWidget2->show();

  layout4->addWidget( mitkWidget2 );
  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_WIDGET2;
}

void QmitkStdMultiWidget::changeLayoutToWidget3()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to big Widget1 ..." << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0, 0, "QmitkStdMultiWidgetLayout");

  QHBoxLayout *layout4 = new QHBoxLayout( 0, 0, 6, "layout4");

  mitkWidget3->setMaximumSize(2000,2000);

  mitkWidget1->hide();
  mitkWidget2->hide();
  mitkWidget4->hide();
  if ( mitkWidget3->isHidden() ) mitkWidget3->show();

  layout4->addWidget( mitkWidget3 );
  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_WIDGET3;
}

void QmitkStdMultiWidget::changeLayoutTo2x2Dand3DWidget()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to 2 x 2D and 3D Widget" << std::endl;

  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0, 0, "QmitkStdMultiWidgetLayout");

  QVBoxLayout *layout1 = new QVBoxLayout( );
  QHBoxLayout *layout2 = new QHBoxLayout( );

  mitkWidget1->setMaximumSize(2000,2000);
  mitkWidget2->setMaximumSize(2000,2000);

  layout1->addWidget( mitkWidget1 );
  layout1->addWidget( mitkWidget2 );
  layout2->addLayout( layout1 );
  layout2->addWidget( mitkWidget4 );
  layout2->addWidget( levelWindowWidget );

  if ( mitkWidget1->isHidden() ) mitkWidget1->show();
  if ( mitkWidget2->isHidden() ) mitkWidget2->show();
  if ( !mitkWidget3->isHidden() ) mitkWidget3->hide();
  if ( mitkWidget4->isHidden() ) mitkWidget4->show();

  QmitkStdMultiWidgetLayout->addLayout( layout2 );

  m_Layout = LAYOUT_2X_2D_AND_3D_WIDGET;
}

void QmitkStdMultiWidget::changeLayoutToRowWidget3And4()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to Widget3 and 4 in a Row..." << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0, 0, "QmitkStdMultiWidgetLayout");
  QGridLayout *layout3 = new QGridLayout( 0, 2, 1, 0, 6, "layout3");
  QHBoxLayout *layout4 = new QHBoxLayout( 0, 0, 6, "layout4");

  mitkWidget1->hide();
  mitkWidget2->hide();
  if ( mitkWidget3->isHidden() ) mitkWidget3->show();
  if ( mitkWidget4->isHidden() ) mitkWidget4->show();

  mitkWidget3->setMaximumSize(2000,1000);
  mitkWidget4->setMaximumSize(2000,1000);

  layout3->addWidget( mitkWidget3,0,0);
  layout3->addWidget( mitkWidget4,1,0);

  layout4->addLayout(layout3);
  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_ROW_WIDGET_3_AND_4;
}

void QmitkStdMultiWidget::changeLayoutToColumnWidget3And4()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to Widget3 and 4 in one Column..." << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0, 0, "QmitkStdMultiWidgetLayout");
  QHBoxLayout *layout4 = new QHBoxLayout( 0, 0, 6, "layout4");

  mitkWidget1->hide();
  mitkWidget2->hide();
  if ( mitkWidget3->isHidden() ) mitkWidget3->show();
  if ( mitkWidget4->isHidden() ) mitkWidget4->show();

  mitkWidget3->setMaximumSize(1000,2000);
  mitkWidget4->setMaximumSize(1000,2000);

  layout4->addWidget( mitkWidget3);
  layout4->addWidget( mitkWidget4);

  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_COLUMN_WIDGET_3_AND_4;
}

void QmitkStdMultiWidget::SetData( mitk::DataTreeIteratorBase* it )
{
  mitkWidget1->GetRenderer()->SetData(it);
  mitkWidget2->GetRenderer()->SetData(it);
  mitkWidget3->GetRenderer()->SetData(it);
  mitkWidget4->GetRenderer()->SetData(it);
}

void QmitkStdMultiWidget::Fit()
{
  vtkRenderer * vtkrenderer;
  mitkWidget1->GetRenderer()->GetDisplayGeometry()->Fit();
  mitkWidget2->GetRenderer()->GetDisplayGeometry()->Fit();
  mitkWidget3->GetRenderer()->GetDisplayGeometry()->Fit();
  mitkWidget4->GetRenderer()->GetDisplayGeometry()->Fit();

  int w=vtkObject::GetGlobalWarningDisplay();
  vtkObject::GlobalWarningDisplayOff();
  vtkrenderer = ((mitk::OpenGLRenderer*)(mitkWidget1->GetRenderer()))
    ->GetVtkRenderer();
  if ( vtkrenderer!=NULL ) vtkrenderer->ResetCamera();
  vtkrenderer = ((mitk::OpenGLRenderer*)(mitkWidget2->GetRenderer()))
    ->GetVtkRenderer();

  if ( vtkrenderer!=NULL ) vtkrenderer->ResetCamera();
  vtkrenderer = ((mitk::OpenGLRenderer*)(mitkWidget3->GetRenderer()))
    ->GetVtkRenderer();

  if ( vtkrenderer!=NULL ) vtkrenderer->ResetCamera();
  vtkrenderer = ((mitk::OpenGLRenderer*)(mitkWidget4->GetRenderer()))
    ->GetVtkRenderer();

  if ( vtkrenderer!=NULL ) vtkrenderer->ResetCamera();
  vtkObject::SetGlobalWarningDisplay(w);
}

void QmitkStdMultiWidget::AddPositionTrackingPointSet(
  mitk::DataTreeIteratorBase* treeIterator)
{
  if (treeIterator) m_Tree = treeIterator->GetTree(); 

  //PoinSetNode for MouseOrientation
  m_PositionTrackerNode = mitk::DataTreeNode::New();
  m_PositionTrackerNode->SetProperty(
    "name", new mitk::StringProperty("Mouse Position"));
  m_PositionTrackerNode->SetData( mitk::PointSet::New() );
  m_PositionTrackerNode->SetColor(1.0,0.33,0.0);
  m_PositionTrackerNode->SetProperty(
    "layer", new mitk::IntProperty(1001));
  m_PositionTrackerNode->SetProperty(
    "visible", new mitk::BoolProperty(true) );
  m_PositionTrackerNode->SetProperty(
    "inputdevice", new mitk::BoolProperty(true) );
  m_PositionTrackerNode->SetProperty(
    "BaseRendererMapperID", new mitk::IntProperty(0) );//point position 2D mouse
  m_PositionTrackerNode->SetProperty(
    "baserenderer", new mitk::StringProperty("N/A"));
  
}
void QmitkStdMultiWidget
::AddDisplayPlaneSubTree(mitk::DataTreeIteratorBase* it)
{
  // add the diplayed planes of the multiwidget to a node to which the subtree 
  // @a planesSubTree points ...

  mitk::DataTreeNode::Pointer node=mitk::DataTreeNode::New();
  node->SetProperty("name", new mitk::StringProperty("Widgets"));
  mitk::DataTreeIteratorClone dit = it;
  dit->Add(node);
  dit->GoToChild(dit->ChildPosition(node));
  planesSubTree=dit->GetSubTree();

  float white[3] = {1.0f,1.0f,1.0f};
  mitk::DataTreeNode::Pointer planeNode;
  mitk::Geometry2DDataMapper2D::Pointer mapper;

  // ... of widget 1
  planeNode=mitkWidget1->GetRenderer()->GetCurrentWorldGeometry2DNode();
  planeNode->SetColor(white, mitkWidget4->GetRenderer());
  planeNode->SetProperty("name", new mitk::StringProperty("widget1Plane"));
  planeNode->SetProperty("includeInBoundingBox", new mitk::BoolProperty(false));
  mapper = mitk::Geometry2DDataMapper2D::New();
  planeNode->SetMapper(mitk::BaseRenderer::Standard2D, mapper);
  dit->Add(planeNode);
  mitk::DataTreeChildIterator childIterator(*(dit.GetPointer()));
  mapper->SetDataIteratorToOtherGeometry2Ds(&childIterator);

  // ... of widget 2
  planeNode=mitkWidget2->GetRenderer()->GetCurrentWorldGeometry2DNode();
  planeNode->SetColor(white, mitkWidget4->GetRenderer());
  planeNode->SetProperty("name", new mitk::StringProperty("widget2Plane"));
  planeNode->SetProperty("includeInBoundingBox", new mitk::BoolProperty(false));
  mapper = mitk::Geometry2DDataMapper2D::New();
  mapper->SetDataIteratorToOtherGeometry2Ds(&childIterator);
  planeNode->SetMapper(mitk::BaseRenderer::Standard2D, mapper);
  dit->Add(planeNode);

  // ... of widget 3
  planeNode=mitkWidget3->GetRenderer()->GetCurrentWorldGeometry2DNode();
  planeNode->SetColor(white, mitkWidget4->GetRenderer());
  planeNode->SetProperty("name", new mitk::StringProperty("widget3Plane"));
  planeNode->SetProperty("includeInBoundingBox", new mitk::BoolProperty(false));
  mapper = mitk::Geometry2DDataMapper2D::New();
  mapper->SetDataIteratorToOtherGeometry2Ds(&childIterator);
  planeNode->SetMapper(mitk::BaseRenderer::Standard2D, mapper);
  dit->Add(planeNode);

  planesIterator = dit;
}

mitk::SliceNavigationController* 
QmitkStdMultiWidget::GetTimeNavigationController()
{
  return timeNavigationController.GetPointer();
}


void QmitkStdMultiWidget::EnableStandardLevelWindow()
{
  levelWindowWidget->disconnect(this);
  mitk::DataTreeIteratorClone it = mitkWidget1->GetRenderer()->GetData();
  levelWindowWidget->setDataTree(dynamic_cast<mitk::DataTree*>(it->GetTree()));
  levelWindowWidget->show();
}


void QmitkStdMultiWidget::DisableStandardLevelWindow()
{
  levelWindowWidget->disconnect(this);
  levelWindowWidget->hide();
}


bool QmitkStdMultiWidget::InitializeStandardViews(
  mitk::DataTreeIteratorBase * it)
{
  bool boundingBoxInitialized = false;

  mitk::SliceNavigationController* sliceNavigatorTransversal =
    mitkWidget1->GetSliceNavigationController();
  mitk::SliceNavigationController* sliceNavigatorSagittal = 
    mitkWidget2->GetSliceNavigationController();
  mitk::SliceNavigationController* sliceNavigatorFrontal = 
    mitkWidget3->GetSliceNavigationController();
  mitk::SliceNavigationController* sliceNavigatorWidget4 = 
    mitkWidget4->GetSliceNavigationController();

  sliceNavigatorTransversal->SetViewDirection(
    mitk::SliceNavigationController::Transversal);
  sliceNavigatorSagittal->SetViewDirection(
    mitk::SliceNavigationController::Sagittal);
  sliceNavigatorFrontal->SetViewDirection(
    mitk::SliceNavigationController::Frontal);
  sliceNavigatorWidget4->SetViewDirection(
    mitk::SliceNavigationController::Original);

  if ( it==NULL )
  {
    sliceNavigatorTransversal->Update();
    sliceNavigatorSagittal->Update();
    sliceNavigatorFrontal->Update();
    timeNavigationController->Update();
    mitk::RenderingManager::GetInstance()->RequestUpdateAll();
  }
  else
  {
    const mitk::BoundingBox::Pointer boundingbox = 
      mitk::DataTree::ComputeVisibleBoundingBox(it, NULL, "includeInBoundingBox");
    if ( boundingbox->GetPoints()->Size()>0 )
    {
      mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New();
      geometry->Initialize();
      geometry->SetBounds(boundingbox->GetBounds());

      // let's see if we have data with a limited live-span ...
      mitk::TimeBounds timebounds =
        mitk::DataTree::ComputeTimeBounds(it, NULL, "includeInBoundingBox");

      if ( timebounds[1]<mitk::ScalarTypeNumericTraits::max() )
      {
        mitk::ScalarType duration = timebounds[1]-timebounds[0];

        mitk::TimeSlicedGeometry::Pointer timegeometry = 
          mitk::TimeSlicedGeometry::New();
        timegeometry->InitializeEvenlyTimed(geometry, (unsigned int) duration);
        timegeometry->SetTimeBounds(timebounds); //@bug really required? FIXME

        timebounds[1] = timebounds[0]+1.0f;
        geometry->SetTimeBounds(timebounds);

        geometry=timegeometry;
      }

      double diagonalLength  = const_cast<mitk::BoundingBox*>(
        geometry->GetBoundingBox())->GetDiagonalLength2();

      if ( (diagonalLength > mitk::eps) && (diagonalLength < mitk::large) )
      {
        boundingBoxInitialized=true;
        
        // steppers are set so that the cross is centered in the image
        sliceNavigatorTransversal->SetInputWorldGeometry(geometry.GetPointer());
        sliceNavigatorTransversal->Update();
        sliceNavigatorTransversal->GetSlice()->SetPos( 
          sliceNavigatorTransversal->GetSlice()->GetSteps()/2 );

        sliceNavigatorSagittal->SetInputWorldGeometry(geometry.GetPointer());
        sliceNavigatorSagittal->Update();
        sliceNavigatorSagittal->GetSlice()->SetPos( 
          sliceNavigatorSagittal->GetSlice()->GetSteps()/2 );

        sliceNavigatorFrontal->SetInputWorldGeometry(geometry.GetPointer());
        sliceNavigatorFrontal->Update();
        sliceNavigatorFrontal->GetSlice()->SetPos( 
          sliceNavigatorFrontal->GetSlice()->GetSteps()/2 );

        sliceNavigatorWidget4->SetInputWorldGeometry(geometry.GetPointer());
        sliceNavigatorWidget4->Update();

        timeNavigationController->SetInputWorldGeometry(geometry.GetPointer());
        timeNavigationController->Update();

        // Temporary solution: Use ForceImmediateUpdate instead of RequestUpdate so
        // that Fit() resets the camera according to the new geometry.
        //mitk::RenderingManager::GetInstance()->RequestUpdateAll();
        mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll();
        this->Fit();
      }
    }
  }
  return boundingBoxInitialized;
}


bool QmitkStdMultiWidget
::InitializeStandardViews( const mitk::Geometry3D * geometry )
{
  bool boundingBoxInitialized = false;

  mitk::SliceNavigationController* sliceNavigatorTransversal =
    mitkWidget1->GetSliceNavigationController();
  mitk::SliceNavigationController* sliceNavigatorSagittal =
    mitkWidget2->GetSliceNavigationController();
  mitk::SliceNavigationController* sliceNavigatorFrontal =
    mitkWidget3->GetSliceNavigationController();

  sliceNavigatorTransversal->SetViewDirection(
    mitk::SliceNavigationController::Transversal);
  sliceNavigatorSagittal->SetViewDirection(
    mitk::SliceNavigationController::Sagittal);<commit_msg>ENH: know using mitk::DataTree::ComputeVisibleBoundingGeometry3D: Compute the axis-parallel bounding geometry of the data tree (bounding box, minimal spacing of the considered nodes, live-span)<commit_after>/*=========================================================================

Program:   Medical Imaging & Interaction Toolkit
Module:    $RCSfile$
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.

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


/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
#include "mitkProperties.h"
#include "mitkStringProperty.h"
#include "mitkLevelWindowProperty.h"
#include "mitkGeometry2DDataMapper2D.h"
#include "mitkOpenGLRenderer.h"
#include "mitkPositionEvent.h"
#include "mitkInteractionConst.h"
#include "mitkGlobalInteraction.h"
#include "mitkPositionTracker.h"
#include "mitkPointSet.h"
#include "mitkStateEvent.h"
#include "mitkPlaneGeometry.h"
#include "mitkLine.h"

#include <vtkRenderer.h>
#include <vtkRenderWindow.h>


void QmitkStdMultiWidget::init()
{
  mitkWidget1->setPaletteBackgroundColor("red");
  mitkWidget2->setPaletteBackgroundColor("green");
  mitkWidget3->setPaletteBackgroundColor("blue");
  mitkWidget4->setPaletteBackgroundColor("yellow");

  planesIterator = NULL;
  m_PositionTracker = NULL;

  // transfer colors in WorldGeometry-Nodes of the associated Renderer
  QColor qcolor;
  float color[3] = {1.0f,1.0f,1.0f};
  mitk::DataTreeNode::Pointer planeNode;
  mitk::IntProperty::Pointer  layer;

  // ... of widget 1
  qcolor=mitkWidget1->paletteBackgroundColor();
  color[0]=qcolor.red()/255.0;
  color[1]=qcolor.green()/255.0;
  color[2]=qcolor.blue()/255.0;
  planeNode=mitkWidget1->GetRenderer()->GetCurrentWorldGeometry2DNode();
  planeNode->SetColor(color);
  layer = new mitk::IntProperty(1000);
  planeNode->SetProperty("layer",layer);

  // ... of widget 2
  qcolor=mitkWidget2->paletteBackgroundColor();
  color[0]=qcolor.red()/255.0;
  color[1]=qcolor.green()/255.0;
  color[2]=qcolor.blue()/255.0;
  planeNode=mitkWidget2->GetRenderer()->GetCurrentWorldGeometry2DNode();
  planeNode->SetColor(color);
  layer = new mitk::IntProperty(1000);
  planeNode->SetProperty("layer",layer);

  // ... of widget 3
  qcolor=mitkWidget3->paletteBackgroundColor();
  color[0]=qcolor.red()/255.0;
  color[1]=qcolor.green()/255.0;
  color[2]=qcolor.blue()/255.0;
  planeNode=mitkWidget3->GetRenderer()->GetCurrentWorldGeometry2DNode();
  planeNode->SetColor(color);
  layer = new mitk::IntProperty(1000);
  planeNode->SetProperty("layer",layer);

  // ... of widget 4
  qcolor=mitkWidget4->paletteBackgroundColor();
  color[0]=qcolor.red()/255.0;
  color[1]=qcolor.green()/255.0; 
  color[2]=qcolor.blue()/255.0;
  planeNode=mitkWidget4->GetRenderer()->GetCurrentWorldGeometry2DNode();
  planeNode->SetColor(color);
  layer = new mitk::IntProperty(1000);
  planeNode->SetProperty("layer",layer);

  // create a slice rotator
  // m_SlicesRotator = mitk::SlicesRotator::New();
  // @TODO next line causes sure memory leak
  // rotator will be created nonetheless (will be switched on and off)
  m_SlicesRotation = false; 
  m_SlicesRotator = new mitk::SlicesRotator("slices-rotator");
  m_SlicesRotator->AddSliceController( 
    mitkWidget1->GetSliceNavigationController() );
  m_SlicesRotator->AddSliceController( 
    mitkWidget2->GetSliceNavigationController() );
  m_SlicesRotator->AddSliceController(
    mitkWidget3->GetSliceNavigationController() );

  //initialize timeNavigationController: send time via sliceNavigationControllers
  timeNavigationController = mitk::SliceNavigationController::New(NULL);
  timeNavigationController->ConnectGeometryTimeEvent(
    mitkWidget1->GetSliceNavigationController(), false);
  timeNavigationController->ConnectGeometryTimeEvent(
    mitkWidget2->GetSliceNavigationController(), false);
  timeNavigationController->ConnectGeometryTimeEvent(
    mitkWidget3->GetSliceNavigationController(), false);
  timeNavigationController->ConnectGeometryTimeEvent(
    mitkWidget4->GetSliceNavigationController(), false);
  mitkWidget1->GetSliceNavigationController()
    ->ConnectGeometrySendEvent(mitkWidget4->GetRenderer());

  //reverse connection between sliceNavigationControllers and timeNavigationController
  mitkWidget1->GetSliceNavigationController()
    ->ConnectGeometryTimeEvent(timeNavigationController.GetPointer(), false);
  mitkWidget2->GetSliceNavigationController()
    ->ConnectGeometryTimeEvent(timeNavigationController.GetPointer(), false);
  mitkWidget3->GetSliceNavigationController()
    ->ConnectGeometryTimeEvent(timeNavigationController.GetPointer(), false);
  mitkWidget4->GetSliceNavigationController()
    ->ConnectGeometryTimeEvent(timeNavigationController.GetPointer(), false);

  // instantiate display interactor
  m_MoveAndZoomInteractor = mitk::DisplayVectorInteractor::New(
    "moveNzoom", new mitk::DisplayInteractor() );
  
  m_LastLeftClickPositionSupplier = 
    mitk::CoordinateSupplier::New("navigation", NULL);
  mitk::GlobalInteraction::GetInstance()->AddListener(
    m_LastLeftClickPositionSupplier
  );
  
  m_GradientBackground1 = mitk::GradientBackground::New();
  m_GradientBackground1->SetRenderWindow(
    mitkWidget1->GetRenderer()->GetRenderWindow() );
  m_GradientBackground1->Disable();
  
  m_GradientBackground2 = mitk::GradientBackground::New();
  m_GradientBackground2->SetRenderWindow( 
    mitkWidget2->GetRenderer()->GetRenderWindow() );
  m_GradientBackground2->Disable();
  
  m_GradientBackground3 = mitk::GradientBackground::New();
  m_GradientBackground3->SetRenderWindow( 
    mitkWidget3->GetRenderer()->GetRenderWindow() );
  m_GradientBackground3->Disable();
  
  m_GradientBackground4 = mitk::GradientBackground::New();
  m_GradientBackground4->SetRenderWindow(
    mitkWidget4->GetRenderer()->GetRenderWindow() );
  m_GradientBackground4->Enable();
}

void QmitkStdMultiWidget::changeLayoutTo2DImagesUp()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to 2D images up... " << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0,02, "QmitkStdMultiWidgetLayout");

  QHBoxLayout * layout4 = new QHBoxLayout( 0, 0, 6, "layout4");
  QGridLayout* layout3 = new QGridLayout( 0, 2, 1, 0, 6, "layout3");

  QHBoxLayout *TwoDLayout = new QHBoxLayout( 0, 0, 6, "2DLayout");

  mitkWidget1->setMaximumSize(2000,200);
  mitkWidget2->setMaximumSize(2000,200);
  mitkWidget3->setMaximumSize(2000,200);

  TwoDLayout->addWidget( mitkWidget1 );
  TwoDLayout->addWidget( mitkWidget2 );
  TwoDLayout->addWidget( mitkWidget3 );

  if ( mitkWidget1->isHidden() ) mitkWidget1->show();
  if ( mitkWidget2->isHidden() ) mitkWidget2->show();
  if ( mitkWidget3->isHidden() ) mitkWidget3->show();
  if ( mitkWidget4->isHidden() ) mitkWidget4->show();

  layout3->addLayout( TwoDLayout , 0, 0 );
  layout3->addWidget( mitkWidget4, 1, 0 );

  layout4->addLayout( layout3 );
  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_2D_IMAGES_UP;
}

void QmitkStdMultiWidget::changeLayoutTo2DImagesLeft()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to 2D images left... " << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0,0, "QmitkStdMultiWidgetLayout");

  QHBoxLayout *layout4 = new QHBoxLayout( 0, 0, 6, "layout4");
  QGridLayout *layout3 = new QGridLayout( 0, 1, 2, 0, 6, "layout3");

  QVBoxLayout *TwoDLayout = new QVBoxLayout( 0, 0, 6, "2DLayout");

  mitkWidget1->setMaximumSize(300,300);
  mitkWidget2->setMaximumSize(300,300);
  mitkWidget3->setMaximumSize(300,300);

  TwoDLayout->addWidget( mitkWidget1 );
  TwoDLayout->addWidget( mitkWidget2 );
  TwoDLayout->addWidget( mitkWidget3 );

  if ( mitkWidget1->isHidden() ) mitkWidget1->show();
  if ( mitkWidget2->isHidden() ) mitkWidget2->show();
  if ( mitkWidget3->isHidden() ) mitkWidget3->show();
  if ( mitkWidget4->isHidden() ) mitkWidget4->show();

  layout3->addLayout( TwoDLayout , 0, 0 );
  layout3->addWidget( mitkWidget4, 0,1 );

  layout4->addLayout( layout3 );
  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_2D_IMAGES_LEFT;
}

void QmitkStdMultiWidget::changeLayoutToDefault()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to default... " << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0, 0, "QmitkStdMultiWidgetLayout");

  QHBoxLayout *layout4 = new QHBoxLayout( 0, 0, 6, "layout4");
  QGridLayout *layout3 = new QGridLayout( 0, 2, 2, 0, 6, "layout3");

  mitkWidget1->setMaximumSize(2000,2000);
  mitkWidget2->setMaximumSize(2000,2000);
  mitkWidget3->setMaximumSize(2000,2000);

  layout3->addWidget( mitkWidget1,0,0 );
  layout3->addWidget( mitkWidget2,0,1 );
  layout3->addWidget( mitkWidget3,1,0 );
  layout3->addWidget( mitkWidget4,1,1 );

  if ( mitkWidget1->isHidden() ) mitkWidget1->show();
  if ( mitkWidget2->isHidden() ) mitkWidget2->show();
  if ( mitkWidget3->isHidden() ) mitkWidget3->show();
  if ( mitkWidget4->isHidden() ) mitkWidget4->show();

  layout4->addLayout( layout3 );
  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_DEFAULT;
}

void QmitkStdMultiWidget::changeLayoutToBig3D()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to big 3D ..." << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0, 0, "QmitkStdMultiWidgetLayout");

  QHBoxLayout *layout4 = new QHBoxLayout( 0, 0, 6, "layout4");
  mitkWidget1->hide();
  mitkWidget2->hide();
  mitkWidget3->hide();
  if ( mitkWidget4->isHidden() ) mitkWidget4->show();

  layout4->addWidget( mitkWidget4 );
  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_BIG_3D;
}

void QmitkStdMultiWidget::changeLayoutToWidget1()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to big Widget1 ..." << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0, 0, "QmitkStdMultiWidgetLayout");

  QHBoxLayout *layout4 = new QHBoxLayout( 0, 0, 6, "layout4");

  mitkWidget1->setMaximumSize(2000,2000);

  mitkWidget2->hide();
  mitkWidget3->hide();
  mitkWidget4->hide();
  if ( mitkWidget1->isHidden() ) mitkWidget1->show();

  layout4->addWidget( mitkWidget1 );
  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_WIDGET1;
}

void QmitkStdMultiWidget::changeLayoutToWidget2()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to big Widget2 ..." << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0, 0, "QmitkStdMultiWidgetLayout");
  QHBoxLayout *layout4 = new QHBoxLayout( 0, 0, 6, "layout4");

  mitkWidget2->setMaximumSize(2000,2000);

  mitkWidget1->hide();
  mitkWidget3->hide();
  mitkWidget4->hide();
  if ( mitkWidget2->isHidden() ) mitkWidget2->show();

  layout4->addWidget( mitkWidget2 );
  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_WIDGET2;
}

void QmitkStdMultiWidget::changeLayoutToWidget3()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to big Widget1 ..." << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0, 0, "QmitkStdMultiWidgetLayout");

  QHBoxLayout *layout4 = new QHBoxLayout( 0, 0, 6, "layout4");

  mitkWidget3->setMaximumSize(2000,2000);

  mitkWidget1->hide();
  mitkWidget2->hide();
  mitkWidget4->hide();
  if ( mitkWidget3->isHidden() ) mitkWidget3->show();

  layout4->addWidget( mitkWidget3 );
  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_WIDGET3;
}

void QmitkStdMultiWidget::changeLayoutTo2x2Dand3DWidget()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to 2 x 2D and 3D Widget" << std::endl;

  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0, 0, "QmitkStdMultiWidgetLayout");

  QVBoxLayout *layout1 = new QVBoxLayout( );
  QHBoxLayout *layout2 = new QHBoxLayout( );

  mitkWidget1->setMaximumSize(2000,2000);
  mitkWidget2->setMaximumSize(2000,2000);

  layout1->addWidget( mitkWidget1 );
  layout1->addWidget( mitkWidget2 );
  layout2->addLayout( layout1 );
  layout2->addWidget( mitkWidget4 );
  layout2->addWidget( levelWindowWidget );

  if ( mitkWidget1->isHidden() ) mitkWidget1->show();
  if ( mitkWidget2->isHidden() ) mitkWidget2->show();
  if ( !mitkWidget3->isHidden() ) mitkWidget3->hide();
  if ( mitkWidget4->isHidden() ) mitkWidget4->show();

  QmitkStdMultiWidgetLayout->addLayout( layout2 );

  m_Layout = LAYOUT_2X_2D_AND_3D_WIDGET;
}

void QmitkStdMultiWidget::changeLayoutToRowWidget3And4()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to Widget3 and 4 in a Row..." << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0, 0, "QmitkStdMultiWidgetLayout");
  QGridLayout *layout3 = new QGridLayout( 0, 2, 1, 0, 6, "layout3");
  QHBoxLayout *layout4 = new QHBoxLayout( 0, 0, 6, "layout4");

  mitkWidget1->hide();
  mitkWidget2->hide();
  if ( mitkWidget3->isHidden() ) mitkWidget3->show();
  if ( mitkWidget4->isHidden() ) mitkWidget4->show();

  mitkWidget3->setMaximumSize(2000,1000);
  mitkWidget4->setMaximumSize(2000,1000);

  layout3->addWidget( mitkWidget3,0,0);
  layout3->addWidget( mitkWidget4,1,0);

  layout4->addLayout(layout3);
  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_ROW_WIDGET_3_AND_4;
}

void QmitkStdMultiWidget::changeLayoutToColumnWidget3And4()
{
  delete QmitkStdMultiWidgetLayout ;

  std::cout << "changing layout to Widget3 and 4 in one Column..." << std::endl;
  QmitkStdMultiWidgetLayout = 
    new QHBoxLayout( this, 0, 0, "QmitkStdMultiWidgetLayout");
  QHBoxLayout *layout4 = new QHBoxLayout( 0, 0, 6, "layout4");

  mitkWidget1->hide();
  mitkWidget2->hide();
  if ( mitkWidget3->isHidden() ) mitkWidget3->show();
  if ( mitkWidget4->isHidden() ) mitkWidget4->show();

  mitkWidget3->setMaximumSize(1000,2000);
  mitkWidget4->setMaximumSize(1000,2000);

  layout4->addWidget( mitkWidget3);
  layout4->addWidget( mitkWidget4);

  layout4->addWidget( levelWindowWidget );
  QmitkStdMultiWidgetLayout->addLayout( layout4 );

  m_Layout = LAYOUT_COLUMN_WIDGET_3_AND_4;
}

void QmitkStdMultiWidget::SetData( mitk::DataTreeIteratorBase* it )
{
  mitkWidget1->GetRenderer()->SetData(it);
  mitkWidget2->GetRenderer()->SetData(it);
  mitkWidget3->GetRenderer()->SetData(it);
  mitkWidget4->GetRenderer()->SetData(it);
}

void QmitkStdMultiWidget::Fit()
{
  vtkRenderer * vtkrenderer;
  mitkWidget1->GetRenderer()->GetDisplayGeometry()->Fit();
  mitkWidget2->GetRenderer()->GetDisplayGeometry()->Fit();
  mitkWidget3->GetRenderer()->GetDisplayGeometry()->Fit();
  mitkWidget4->GetRenderer()->GetDisplayGeometry()->Fit();

  int w=vtkObject::GetGlobalWarningDisplay();
  vtkObject::GlobalWarningDisplayOff();
  vtkrenderer = ((mitk::OpenGLRenderer*)(mitkWidget1->GetRenderer()))
    ->GetVtkRenderer();
  if ( vtkrenderer!=NULL ) vtkrenderer->ResetCamera();
  vtkrenderer = ((mitk::OpenGLRenderer*)(mitkWidget2->GetRenderer()))
    ->GetVtkRenderer();

  if ( vtkrenderer!=NULL ) vtkrenderer->ResetCamera();
  vtkrenderer = ((mitk::OpenGLRenderer*)(mitkWidget3->GetRenderer()))
    ->GetVtkRenderer();

  if ( vtkrenderer!=NULL ) vtkrenderer->ResetCamera();
  vtkrenderer = ((mitk::OpenGLRenderer*)(mitkWidget4->GetRenderer()))
    ->GetVtkRenderer();

  if ( vtkrenderer!=NULL ) vtkrenderer->ResetCamera();
  vtkObject::SetGlobalWarningDisplay(w);
}

void QmitkStdMultiWidget::AddPositionTrackingPointSet(
  mitk::DataTreeIteratorBase* treeIterator)
{
  if (treeIterator) m_Tree = treeIterator->GetTree(); 

  //PoinSetNode for MouseOrientation
  m_PositionTrackerNode = mitk::DataTreeNode::New();
  m_PositionTrackerNode->SetProperty(
    "name", new mitk::StringProperty("Mouse Position"));
  m_PositionTrackerNode->SetData( mitk::PointSet::New() );
  m_PositionTrackerNode->SetColor(1.0,0.33,0.0);
  m_PositionTrackerNode->SetProperty(
    "layer", new mitk::IntProperty(1001));
  m_PositionTrackerNode->SetProperty(
    "visible", new mitk::BoolProperty(true) );
  m_PositionTrackerNode->SetProperty(
    "inputdevice", new mitk::BoolProperty(true) );
  m_PositionTrackerNode->SetProperty(
    "BaseRendererMapperID", new mitk::IntProperty(0) );//point position 2D mouse
  m_PositionTrackerNode->SetProperty(
    "baserenderer", new mitk::StringProperty("N/A"));
  
}
void QmitkStdMultiWidget
::AddDisplayPlaneSubTree(mitk::DataTreeIteratorBase* it)
{
  // add the diplayed planes of the multiwidget to a node to which the subtree 
  // @a planesSubTree points ...

  mitk::DataTreeNode::Pointer node=mitk::DataTreeNode::New();
  node->SetProperty("name", new mitk::StringProperty("Widgets"));
  mitk::DataTreeIteratorClone dit = it;
  dit->Add(node);
  dit->GoToChild(dit->ChildPosition(node));
  planesSubTree=dit->GetSubTree();

  float white[3] = {1.0f,1.0f,1.0f};
  mitk::DataTreeNode::Pointer planeNode;
  mitk::Geometry2DDataMapper2D::Pointer mapper;

  // ... of widget 1
  planeNode=mitkWidget1->GetRenderer()->GetCurrentWorldGeometry2DNode();
  planeNode->SetColor(white, mitkWidget4->GetRenderer());
  planeNode->SetProperty("name", new mitk::StringProperty("widget1Plane"));
  planeNode->SetProperty("includeInBoundingBox", new mitk::BoolProperty(false));
  mapper = mitk::Geometry2DDataMapper2D::New();
  planeNode->SetMapper(mitk::BaseRenderer::Standard2D, mapper);
  dit->Add(planeNode);
  mitk::DataTreeChildIterator childIterator(*(dit.GetPointer()));
  mapper->SetDataIteratorToOtherGeometry2Ds(&childIterator);

  // ... of widget 2
  planeNode=mitkWidget2->GetRenderer()->GetCurrentWorldGeometry2DNode();
  planeNode->SetColor(white, mitkWidget4->GetRenderer());
  planeNode->SetProperty("name", new mitk::StringProperty("widget2Plane"));
  planeNode->SetProperty("includeInBoundingBox", new mitk::BoolProperty(false));
  mapper = mitk::Geometry2DDataMapper2D::New();
  mapper->SetDataIteratorToOtherGeometry2Ds(&childIterator);
  planeNode->SetMapper(mitk::BaseRenderer::Standard2D, mapper);
  dit->Add(planeNode);

  // ... of widget 3
  planeNode=mitkWidget3->GetRenderer()->GetCurrentWorldGeometry2DNode();
  planeNode->SetColor(white, mitkWidget4->GetRenderer());
  planeNode->SetProperty("name", new mitk::StringProperty("widget3Plane"));
  planeNode->SetProperty("includeInBoundingBox", new mitk::BoolProperty(false));
  mapper = mitk::Geometry2DDataMapper2D::New();
  mapper->SetDataIteratorToOtherGeometry2Ds(&childIterator);
  planeNode->SetMapper(mitk::BaseRenderer::Standard2D, mapper);
  dit->Add(planeNode);

  planesIterator = dit;
}

mitk::SliceNavigationController* 
QmitkStdMultiWidget::GetTimeNavigationController()
{
  return timeNavigationController.GetPointer();
}


void QmitkStdMultiWidget::EnableStandardLevelWindow()
{
  levelWindowWidget->disconnect(this);
  mitk::DataTreeIteratorClone it = mitkWidget1->GetRenderer()->GetData();
  levelWindowWidget->setDataTree(dynamic_cast<mitk::DataTree*>(it->GetTree()));
  levelWindowWidget->show();
}


void QmitkStdMultiWidget::DisableStandardLevelWindow()
{
  levelWindowWidget->disconnect(this);
  levelWindowWidget->hide();
}


bool QmitkStdMultiWidget::InitializeStandardViews(
  mitk::DataTreeIteratorBase * it)
{
  bool boundingBoxInitialized = false;

  mitk::SliceNavigationController* sliceNavigatorTransversal =
    mitkWidget1->GetSliceNavigationController();
  mitk::SliceNavigationController* sliceNavigatorSagittal = 
    mitkWidget2->GetSliceNavigationController();
  mitk::SliceNavigationController* sliceNavigatorFrontal = 
    mitkWidget3->GetSliceNavigationController();
  mitk::SliceNavigationController* sliceNavigatorWidget4 = 
    mitkWidget4->GetSliceNavigationController();

  sliceNavigatorTransversal->SetViewDirection(
    mitk::SliceNavigationController::Transversal);
  sliceNavigatorSagittal->SetViewDirection(
    mitk::SliceNavigationController::Sagittal);
  sliceNavigatorFrontal->SetViewDirection(
    mitk::SliceNavigationController::Frontal);
  sliceNavigatorWidget4->SetViewDirection(
    mitk::SliceNavigationController::Original);

  if ( it==NULL )
  {
    sliceNavigatorTransversal->Update();
    sliceNavigatorSagittal->Update();
    sliceNavigatorFrontal->Update();
    timeNavigationController->Update();
    mitk::RenderingManager::GetInstance()->RequestUpdateAll();
  }
  else
  {
    mitk::Geometry3D::Pointer geometry = mitk::DataTree::ComputeVisibleBoundingGeometry3D(it, NULL, "includeInBoundingBox");
    if ( geometry.IsNotNull() )
    {
      //lets see if we have data with a limited live-span ...
      mitk::TimeBounds timebounds = geometry->GetTimeBounds();
      if ( timebounds[1]<mitk::ScalarTypeNumericTraits::max() )
      {
        mitk::ScalarType duration = timebounds[1]-timebounds[0];

        mitk::TimeSlicedGeometry::Pointer timegeometry = 
          mitk::TimeSlicedGeometry::New();
        timegeometry->InitializeEvenlyTimed(geometry, (unsigned int) duration);
        timegeometry->SetTimeBounds(timebounds); //@bug really required? FIXME

        timebounds[1] = timebounds[0]+1.0f;
        geometry->SetTimeBounds(timebounds);

        geometry=timegeometry;
      }

      double diagonalLength  = const_cast<mitk::BoundingBox*>(
        geometry->GetBoundingBox())->GetDiagonalLength2();

      if ( (diagonalLength > mitk::eps) && (diagonalLength < mitk::large) )
      {
        boundingBoxInitialized=true;
        
        // steppers are set so that the cross is centered in the image
        sliceNavigatorTransversal->SetInputWorldGeometry(geometry.GetPointer());
        sliceNavigatorTransversal->Update();
        sliceNavigatorTransversal->GetSlice()->SetPos( 
          sliceNavigatorTransversal->GetSlice()->GetSteps()/2 );

        sliceNavigatorSagittal->SetInputWorldGeometry(geometry.GetPointer());
        sliceNavigatorSagittal->Update();
        sliceNavigatorSagittal->GetSlice()->SetPos( 
          sliceNavigatorSagittal->GetSlice()->GetSteps()/2 );

        sliceNavigatorFrontal->SetInputWorldGeometry(geometry.GetPointer());
        sliceNavigatorFrontal->Update();
        sliceNavigatorFrontal->GetSlice()->SetPos( 
          sliceNavigatorFrontal->GetSlice()->GetSteps()/2 );

        sliceNavigatorWidget4->SetInputWorldGeometry(geometry.GetPointer());
        sliceNavigatorWidget4->Update();

        timeNavigationController->SetInputWorldGeometry(geometry.GetPointer());
        timeNavigationController->Update();

        // Temporary solution: Use ForceImmediateUpdate instead of RequestUpdate so
        // that Fit() resets the camera according to the new geometry.
        //mitk::RenderingManager::GetInstance()->RequestUpdateAll();
        this->Fit();
        mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll();
      }
    }
  }
  return boundingBoxInitialized;
}


bool QmitkStdMultiWidget
::InitializeStandardViews( const mitk::Geometry3D * geometry )
{
  bool boundingBoxInitialized = false;

  mitk::SliceNavigationController* sliceNavigatorTransversal =
    mitkWidget1->GetSliceNavigationController();
  mitk::SliceNavigationController* sliceNavigatorSagittal =
    mitkWidget2->GetSliceNavigationController();
  mitk::SliceNavigationController* sliceNavigatorFrontal =
    mitkWidget3->GetSliceNavigationController();

  sliceNavigatorTransversal->SetViewDirection(
    mitk::SliceNavigationController::Transversal);
  sliceNavigatorSagittal->SetViewDirection(
    mitk::SliceNavigationController::Sagittal);
{'fraction_non_alphanumeric': 0.14498990434622994, 'fraction_numerical': 0.027492810670800106, 'mean_word_length': 5.753719008264463, 'pattern_counts': {'":': 0, '<': 95, '<?xml version=': 0, '>': 674, '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': '2109953', 'n_tokens_mistral': 16283, 'n_tokens_neox': 15415, 'n_words': 2526}