<commit_before>/****************************************************************************
** 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 "mitkGeometry2DDataVtkMapper3D.h"
#include "QmitkSelectableGLWidget.h"
#include "QLevelWindowWidget.h"
#include <vtkSTLReader.h>
#include <vtkSTLWriter.h>
#include <vtkPolyDataReader.h>
#include <vtkPolyDataWriter.h>
#include <vtkImageData.h>
#include <vtkStructuredPoints.h>
#include <vtkStructuredPointsReader.h>
#include <vtkStructuredPointsWriter.h>
#include <map>
#include <mitkSurfaceData.h>
#include <mitkColorProperty.h>
#include <mitkBoolProperty.h>
#include <mitkLookupTableProperty.h>
#include "mitkProperties.h"

#include <mitkLevelWindowProperty.h>
#include <mitkVesselTreeFileReader.h>
#include <mitkVesselGraphFileReader.h>
#include <mitkLevelWindow.h>
#include <mitkDataTree.h>
#include <mitkFloatProperty.h>
#include <qregexp.h>
#include <string>

#include <mitkStringProperty.h>
#include <qstring.h>
#include "mitkImageTimeSelector.h"
#include "mitkImageChannelSelector.h"
//#include <mitkImageToItk.h>
//#include <itkThresholdImageFilter.h>

#include <mitkStateMachineFactory.h>
#include <mitkUndoController.h>
#include <mitkStateMachine.h>
#include <mitkEventMapper.h>
#include <mitkGlobalInteraction.h>

#include <mitkUSLookupTableSource.h>

#ifdef MBI_INTERNAL
#include <mitkDICOMFileReader.h>
#include <mitkDSRFileReader.h>
#include <mitkCylindricToCartesianFilter.h>
#endif

#include <mitkParRecFileReader.h>
#include <mitkInteractionConst.h>
#include <QmitkStatusBar/QmitkStatusBar.h>

mitk::FloatProperty::Pointer opacityprop=NULL;

void QmitkMainTemplate::fileNew()
{

}

void QmitkMainTemplate::fileOpen()
{
#ifdef MBI_INTERNAL
  QString fileName = QFileDialog::getOpenFileName(NULL,"all (*.seq *.pic *.pic.gz *.seq.gz *.pvtk *.stl *.vtk *.ves *.uvg *.par *.dcm hpsonos.db HPSONOS.DB);;DKFZ Pic (*.seq *.pic *.pic.gz *.seq.gz);;surface files (*.stl *.vtk);;stl files (*.stl);;vtk surface files (*.vtk);;vtk image files (*.pvtk);;vessel files (*.ves *.uvg);;par/rec files (*.par);;DSR files (hpsonos.db HPSONOS.DB);;DICOM files (*.dcm)");
#else
  QString fileName = QFileDialog::getOpenFileName(NULL,"all (*.seq *.pic *.pic.gz *.seq.gz *.pvtk *.stl *.vtk *.ves *.uvg *.par);;DKFZ Pic (*.seq *.pic *.pic.gz *.seq.gz);;surface files (*.stl *.vtk);;stl files (*.stl);;vtk surface files (*.vtk);;vtk image files (*.pvtk);;vessel files (*.ves *.uvg);;par/rec files (*.par)");
#endif

  if ( !fileName.isNull() )
  {
    fileOpen(fileName.ascii());
    mitkMultiWidget->updateMitkWidgets();
  }
}

void QmitkMainTemplate::fileOpen( const char * fileName )
{
  mitk::DataTreeNode::Pointer node=NULL;
  if(strstr(fileName, ".stl")!=0)
  {
    std::cout << "loading " << fileName << " as stl ... " << std::endl;

    vtkSTLReader *stlreader = vtkSTLReader::New();
    stlreader->SetFileName(fileName);
    stlreader->Update();

    if(stlreader->GetOutput()!=NULL)
    {
      mitk::SurfaceData::Pointer surface = mitk::SurfaceData::New();
      surface->SetVtkPolyData(stlreader->GetOutput());

      mitk::DataTreeIterator* it=tree->inorderIterator();

      node=mitk::DataTreeNode::New();
      node->SetData(surface);
      it->add(node);

      initWidgets(it);

      delete it;
    }
  }
  else if(strstr(fileName, ".vtk")!=0)
  {
    std::cout << "loading " << fileName << " as vtk ... " << std::endl;

    vtkPolyDataReader *reader = vtkPolyDataReader::New();
    reader->SetFileName(fileName);
    reader->Update();

    if(reader->GetOutput()!=NULL)
    {
      mitk::SurfaceData::Pointer surface = mitk::SurfaceData::New();
      surface->SetVtkPolyData(reader->GetOutput());

      mitk::DataTreeIterator* it=tree->inorderIterator();

      node=mitk::DataTreeNode::New();
      node->SetData(surface);
      it->add(node);

      initWidgets(it);

      delete it;
    }
  }
  else if((strstr(fileName, ".pic")!=0) || (strstr(fileName, ".seq")!=0))
  {
    ipPicDescriptor *header=ipPicGetHeader(const_cast<char *>(fileName), NULL);
    if(header!=NULL)
    {
      mitk::PicFileReader::Pointer reader;

      reader=mitk::PicFileReader::New();

      std::cout << "loading " << fileName << " as pic ... " << std::endl;

      reader->SetFileName(fileName);

      mitk::DataTreeIterator* it=tree->inorderIterator();

      node=mitk::DataTreeNode::New();
      node->SetData(reader->GetOutput());
      it->add(node);

      QString tmpName = fileName;
      tmpName = tmpName.right(tmpName.length() - tmpName.findRev("/") - 1);
      mitk::StringProperty::Pointer nameProp = new mitk::StringProperty(tmpName.ascii());
      node->SetProperty("fileName",nameProp);

      // disable volume rendering by default
      node->SetProperty("volumerendering",new mitk::BoolProperty(false));

      mitk::LevelWindowProperty::Pointer levWinProp = new mitk::LevelWindowProperty();
      mitk::LevelWindow levelWindow;
      reader->UpdateLargestPossibleRegion();
      levelWindow.SetAuto( reader->GetOutput()->GetPic() );
      levWinProp->SetLevelWindow(levelWindow);
      node->GetPropertyList()->SetProperty("levelwindow",levWinProp);

      mitkMultiWidget->levelWindowWidget->setLevelWindow(levelWindow);



      // example usage of a lookup table
      /*
  		mitk::LookupTableSource::Pointer LookupTableSource = new mitk::LookupTableSource();
      //LookupTableSource->SetUseHPDopplerLookupTable();
      //LookupTableSource->SetUseStrainLookupTable();
  		mitk::LookupTableSource::OutputTypePointer LookupTable = LookupTableSource->GetOutput();
      mitk::LookupTableProperty::Pointer LookupTableProp = new mitk::LookupTableProperty(*LookupTable);
    	node->SetProperty("LookupTable", LookupTableProp );
      */
      initWidgets(it);
    }
  }
  else if(strstr(fileName, ".par")!=0)
  {

    mitk::ParRecFileReader::Pointer reader;

    reader=mitk::ParRecFileReader::New();
    std::cout << "loading " << fileName << " as par/rec ... " << std::endl;
    reader->SetFileName(fileName);

    mitk::DataTreeIterator* it=tree->inorderIterator();

    node=mitk::DataTreeNode::New();
    node->SetData(reader->GetOutput());
    it->add(node);

    QString tmpName = fileName;
    tmpName = tmpName.right(tmpName.length() - tmpName.findRev("/") - 1);
    mitk::StringProperty::Pointer nameProp = new mitk::StringProperty(tmpName.ascii());
    node->SetProperty("fileName",nameProp);

    mitk::LevelWindowProperty::Pointer levWinProp = new mitk::LevelWindowProperty();
    mitk::LevelWindow levelWindow;
    reader->UpdateLargestPossibleRegion();
    levelWindow.SetAuto( reader->GetOutput()->GetPic() );
    levWinProp->SetLevelWindow(levelWindow);
    node->GetPropertyList()->SetProperty("levelwindow",levWinProp);

    mitkMultiWidget->levelWindowWidget->setLevelWindow(levelWindow);
    initWidgets(it);
  }
  else if(strstr(fileName, ".pvtk")!=0)
  {
    vtkStructuredPointsReader *vtkreader = vtkStructuredPointsReader::New();
    vtkreader->SetFileName(fileName);
    vtkreader->Update();

    if(vtkreader->GetOutput()!=NULL)
    {
      mitk::Image::Pointer image = mitk::Image::New();
      image->Initialize(vtkreader->GetOutput());
      image->SetVolume(vtkreader->GetOutput()->GetScalarPointer());

      vtkreader->Delete();

      mitk::DataTreeIterator* it=tree->inorderIterator();

      node=mitk::DataTreeNode::New();
      node->SetData(image);
      it->add(node);

      QString tmpName = fileName;
      tmpName = tmpName.right(tmpName.length() - tmpName.findRev("/") - 1);
      mitk::StringProperty::Pointer nameProp = new mitk::StringProperty(tmpName.ascii());
      node->SetProperty("fileName",nameProp);

      mitk::LevelWindowProperty::Pointer levWinProp = new mitk::LevelWindowProperty();
      mitk::LevelWindow levelWindow;
      levelWindow.SetAuto( image->GetPic() );
      levWinProp->SetLevelWindow(levelWindow);
      node->GetPropertyList()->SetProperty("levelwindow",levWinProp);

      mitkMultiWidget->levelWindowWidget->setLevelWindow(levelWindow);
      initWidgets(it);
    }
  }
  else if( strstr(fileName, ".ves")!=0 )
  {
    mitk::VesselTreeFileReader::Pointer reader = mitk::VesselTreeFileReader::New();
    std::cout << "loading " << fileName << " as ves ... " << std::endl;
    reader->SetFileName(fileName);
    reader->Update();
    mitk::DataTreeIterator* it=tree->inorderIterator();

    node=mitk::DataTreeNode::New();
    node->SetData(reader->GetOutput());
    it->add(node);

    initWidgets(it);
    delete it;
  }
  else if( strstr(fileName, ".uvg")!=0 )
  {
	  mitk::VesselGraphFileReader::Pointer reader = mitk::VesselGraphFileReader::New();
	  std::cout << "loading " << fileName << " as uvg ... " << std::endl;
	  reader->SetFileName(fileName);
	  reader->Update();
	  mitk::DataTreeIterator* it=tree->inorderIterator();

	  node=mitk::DataTreeNode::New();
	  node->SetData(reader->GetOutput());
	  it->add(node);

	  initWidgets(it);
	  delete it;
  }
#ifdef MBI_INTERNAL
  else if(strstr(fileName, "DCM")!=0)
  {
    mitk::DICOMFileReader::Pointer reader;

    reader=mitk::DICOMFileReader::New();
    std::cout << "loading " << fileName << " as pic ... " << std::endl;

    reader->SetFileName(fileName);

    mitk::DataTreeIterator* it=tree->inorderIterator();

    node=mitk::DataTreeNode::New();
    node->SetData(reader->GetOutput());
    it->add(node);

    mitk::LevelWindow levelWindow;
    reader->Update();
    levelWindow.SetAuto( reader->GetOutput()->GetPic() );
    node->SetLevelWindow(levelWindow, NULL);
    mitkMultiWidget->levelWindowWidget->setLevelWindow(levelWindow);

    initWidgets(it);

    delete it;
  }
  else if(strstr(fileName, "hpsonos.db")!=0 || strstr(fileName, "HPSONOS.DB")!=0)
  {

    if (strcmp(fileName,"HPSONOS.DB")==0)
    {
      std::cout << "renamed HPSONOS.DB to hpsonos.db" << std::endl;
      fileName = "hpsonos.db";
    }


    mitk::DSRFileReader::Pointer reader;

    reader=mitk::DSRFileReader::New();
    std::cout << "loading " << fileName << " as DSR ... " << std::endl;

    reader->SetFileName(fileName);
    mitk::ImageTimeSelector::Pointer timeSelector=mitk::ImageTimeSelector::New();
    timeSelector->SetInput(reader->GetOutput());
    timeSelector->SetTimeNr(0);

    mitk::CylindricToCartesianFilter::Pointer cyl2cart;
    mitk::CylindricToCartesianFilter::Pointer cyl2cartDoppler;

    cyl2cart = mitk::CylindricToCartesianFilter::New();
    cyl2cartDoppler = mitk::CylindricToCartesianFilter::New();

    mitk::DataTreeIterator* it=tree->inorderIterator();

    // Backscatter information
    timeSelector->SetChannelNr(0);
    timeSelector->Update();

    cyl2cart->SetInput(timeSelector->GetOutput());
    node=mitk::DataTreeNode::New();
    node->SetData(cyl2cart->GetOutput());
    it->add(node);

    //set properties for Backscatter
    node->SetProperty("Backscatter",new mitk::BoolProperty(true));
    node->SetProperty("layer", new mitk::IntProperty(-10) );
    mitk::LevelWindow levelWindow;
    cyl2cart->Update();
    levelWindow.SetAuto( cyl2cart->GetOutput()->GetPic() );
    node->SetLevelWindow(levelWindow, NULL);


    node->Update();

    // Doppler information
    timeSelector->SetChannelNr(1);
    timeSelector->Update();

    // add cartesian data to tree
    cyl2cartDoppler->SetInput(timeSelector->GetOutput());

    node=mitk::DataTreeNode::New();
    node->SetData(cyl2cartDoppler->GetOutput());
    it->add(node);

    //set properties for Doppler
    node->SetProperty("Doppler",new mitk::BoolProperty(true));
    node->SetProperty("layer", new mitk::IntProperty(-5) );

    cyl2cartDoppler->Update();
    levelWindow.SetAuto( cyl2cartDoppler->GetOutput()->GetPic() );
    node->SetLevelWindow(levelWindow, NULL);

    // TODO: HP map must be provided by DSRFilereader, since it
    // may be dependend on data ( baseline shift)
    mitk::USLookupTableSource::Pointer LookupTableSource = mitk::USLookupTableSource::New();
    // LookupTableSource->SetUseHPLookupTable();
    mitk::LookupTableSource::OutputTypePointer LookupTable = LookupTableSource->GetOutput();
    mitk::LookupTableProperty::Pointer LookupTableProp = new mitk::LookupTableProperty(*LookupTable);

    node->SetProperty("LookupTable", LookupTableProp );


    node->Update();

    mitkMultiWidget->levelWindowWidget->setLevelWindow(levelWindow);

    initWidgets(it);

    delete it;
  }
#endif
}

void QmitkMainTemplate::fileOpenImageSequence()
{
  QString fileName = QFileDialog::getOpenFileName(NULL,"DKFZ Pic (*.seq *.pic *.pic.gz *.seq.gz);;stl files (*.stl)");

  if ( !fileName.isNull() )
  {
    int fnstart = fileName.findRev( QRegExp("[/\\\\]"), fileName.length() );
    if(fnstart<0) fnstart=0;
    int start = fileName.find( QRegExp("[0-9]"), fnstart );
    if(start<0)
    {
      fileOpen(fileName.ascii());
      return;
    }

    char prefix[1024], pattern[1024];

    strncpy(prefix, fileName.ascii(), start);
    prefix[start]=0;

    int stop=fileName.find( QRegExp("[^0-9]"), start );
    sprintf(pattern, "%%s%%0%uu%s",stop-start,fileName.ascii()+stop);

    mitk::PicFileReader::Pointer reader;
    reader=mitk::PicFileReader::New();

    std::cout << "loading " << fileName << " interpreted as image sequence mask: prefix " << prefix << " pattern: " << pattern << std::endl;

    reader->SetFilePrefix(prefix);
    reader->SetFilePattern(pattern);

    mitk::DataTreeIterator* it=tree->inorderIterator();

    mitk::DataTreeNode::Pointer node;
    node=mitk::DataTreeNode::New();
    node->SetData(reader->GetOutput());
    it->add(node);

    initWidgets(it);

    mitkMultiWidget->updateMitkWidgets();

    delete it;
  }
}

void QmitkMainTemplate::initWidget(mitk::DataTreeIterator* it,
                                   QmitkSelectableGLWidget* widget,
                                   const Vector3f& normal, const Vector3f& right )
{

  mitk::PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New();

  //ohne den Pointer-Umweg meckert gcc
  mitk::PlaneView* view = new mitk::PlaneView(Plane<float>(Vector3f(0,0,0),normal),
    right,
    Vector2f(0,0),
    Vector2f(0,0)
    );
  plane->SetPlaneView(*view);
  delete view;

  widget->GetRenderer()->SetData(it);
  widget->GetRenderer()->SetWorldGeometry(plane);
  widget->GetRenderer()->GetDisplayGeometry()->Fit();

  //mitk::DataTreeNode::Pointer node=mitk::DataTreeNode::New();
  //node->SetData(widget->GetRenderer()->GetWorldGeometry2DData());
  //it->add(node);

  widget->update();
}

void QmitkMainTemplate::initWidget(mitk::DataTreeIterator* it,
                                   QmitkSelectableGLWidget* widget,
                                   const Vector3f& origin,
                                   const Vector3f& right,
                                   const Vector3f& bottom)
{

  mitk::PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New();

  //ohne den Pointer-Umweg meckert gcc
  mitk::PlaneView* view = new mitk::PlaneView(origin,right,bottom);
  plane->SetPlaneView(*view);
  delete view;

  widget->GetRenderer()->SetData(it);
  widget->GetRenderer()->SetWorldGeometry(plane);
  widget->GetRenderer()->GetDisplayGeometry()->Fit();

  widget->update();
}

void QmitkMainTemplate::fileSave()
{

}

void QmitkMainTemplate::fileSaveAs()
{
  mitk::DataTreeIterator* it=tree->inorderIterator()->clone();
  while(it->hasNext())
  {
    it->next();
    mitk::DataTreeNode::Pointer node=it->get();
    if(node->GetData()!=NULL)
    {
      mitk::Image::Pointer image = dynamic_cast<mitk::Image*>(node->GetData());
      if( image.IsNotNull() )
      {
        QString fileName = QFileDialog::getSaveFileName(NULL,"pvtk (*.pvtk)");
        if ( !fileName.isNull() )
        {
          if(fileName.endsWith(".pvtk")==false) fileName+=".pvtk";
          vtkStructuredPointsWriter *writer=vtkStructuredPointsWriter::New();
          writer->SetInput(image->GetVtkImageData());
          writer->SetFileName(fileName.ascii());
          writer->SetFileTypeToBinary();
          writer->Write();
          writer->Delete();
        }
      }
      mitk::SurfaceData::Pointer surface = dynamic_cast<mitk::SurfaceData*>(node->GetData());
      if( image.IsNotNull() )
      {<commit_msg>check after loading of DSR files, if Doppler information is avaiable. added property "ultrasound" describing the characteristics of the data, i.e., doppler,backscatter,transformed,original<commit_after>/****************************************************************************
** 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 "mitkGeometry2DDataVtkMapper3D.h"
#include "QmitkSelectableGLWidget.h"
#include "QLevelWindowWidget.h"
#include <vtkSTLReader.h>
#include <vtkSTLWriter.h>
#include <vtkPolyDataReader.h>
#include <vtkPolyDataWriter.h>
#include <vtkImageData.h>
#include <vtkStructuredPoints.h>
#include <vtkStructuredPointsReader.h>
#include <vtkStructuredPointsWriter.h>
#include <map>
#include <mitkSurfaceData.h>
#include <mitkColorProperty.h>
#include <mitkBoolProperty.h>
#include <mitkLookupTableProperty.h>
#include "mitkProperties.h"

#include <mitkLevelWindowProperty.h>
#include <mitkVesselTreeFileReader.h>
#include <mitkVesselGraphFileReader.h>
#include <mitkLevelWindow.h>
#include <mitkDataTree.h>
#include <mitkFloatProperty.h>
#include <qregexp.h>
#include <string>

#include <mitkStringProperty.h>
#include <qstring.h>
#include "mitkImageTimeSelector.h"
#include "mitkImageChannelSelector.h"
//#include <mitkImageToItk.h>
//#include <itkThresholdImageFilter.h>

#include <mitkStateMachineFactory.h>
#include <mitkUndoController.h>
#include <mitkStateMachine.h>
#include <mitkEventMapper.h>
#include <mitkGlobalInteraction.h>

#include <mitkUSLookupTableSource.h>

#ifdef MBI_INTERNAL
#include <mitkDICOMFileReader.h>
#include <mitkDSRFileReader.h>
#include <mitkCylindricToCartesianFilter.h>
#endif

#include <mitkParRecFileReader.h>
#include <mitkInteractionConst.h>
#include <QmitkStatusBar/QmitkStatusBar.h>

mitk::FloatProperty::Pointer opacityprop=NULL;

void QmitkMainTemplate::fileNew()
{

}

void QmitkMainTemplate::fileOpen()
{
#ifdef MBI_INTERNAL
  QString fileName = QFileDialog::getOpenFileName(NULL,"all (*.seq *.pic *.pic.gz *.seq.gz *.pvtk *.stl *.vtk *.ves *.uvg *.par *.dcm hpsonos.db HPSONOS.DB);;DKFZ Pic (*.seq *.pic *.pic.gz *.seq.gz);;surface files (*.stl *.vtk);;stl files (*.stl);;vtk surface files (*.vtk);;vtk image files (*.pvtk);;vessel files (*.ves *.uvg);;par/rec files (*.par);;DSR files (hpsonos.db HPSONOS.DB);;DICOM files (*.dcm)");
#else
  QString fileName = QFileDialog::getOpenFileName(NULL,"all (*.seq *.pic *.pic.gz *.seq.gz *.pvtk *.stl *.vtk *.ves *.uvg *.par);;DKFZ Pic (*.seq *.pic *.pic.gz *.seq.gz);;surface files (*.stl *.vtk);;stl files (*.stl);;vtk surface files (*.vtk);;vtk image files (*.pvtk);;vessel files (*.ves *.uvg);;par/rec files (*.par)");
#endif

  if ( !fileName.isNull() )
  {
    fileOpen(fileName.ascii());
    mitkMultiWidget->updateMitkWidgets();
  }
}

void QmitkMainTemplate::fileOpen( const char * fileName )
{
  mitk::DataTreeNode::Pointer node=NULL;
  if(strstr(fileName, ".stl")!=0)
  {
    std::cout << "loading " << fileName << " as stl ... " << std::endl;

    vtkSTLReader *stlreader = vtkSTLReader::New();
    stlreader->SetFileName(fileName);
    stlreader->Update();

    if(stlreader->GetOutput()!=NULL)
    {
      mitk::SurfaceData::Pointer surface = mitk::SurfaceData::New();
      surface->SetVtkPolyData(stlreader->GetOutput());

      mitk::DataTreeIterator* it=tree->inorderIterator();

      node=mitk::DataTreeNode::New();
      node->SetData(surface);
      it->add(node);

      initWidgets(it);

      delete it;
    }
  }
  else if(strstr(fileName, ".vtk")!=0)
  {
    std::cout << "loading " << fileName << " as vtk ... " << std::endl;

    vtkPolyDataReader *reader = vtkPolyDataReader::New();
    reader->SetFileName(fileName);
    reader->Update();

    if(reader->GetOutput()!=NULL)
    {
      mitk::SurfaceData::Pointer surface = mitk::SurfaceData::New();
      surface->SetVtkPolyData(reader->GetOutput());

      mitk::DataTreeIterator* it=tree->inorderIterator();

      node=mitk::DataTreeNode::New();
      node->SetData(surface);
      it->add(node);

      initWidgets(it);

      delete it;
    }
  }
  else if((strstr(fileName, ".pic")!=0) || (strstr(fileName, ".seq")!=0))
  {
    ipPicDescriptor *header=ipPicGetHeader(const_cast<char *>(fileName), NULL);
    if(header!=NULL)
    {
      mitk::PicFileReader::Pointer reader;

      reader=mitk::PicFileReader::New();

      std::cout << "loading " << fileName << " as pic ... " << std::endl;

      reader->SetFileName(fileName);

      mitk::DataTreeIterator* it=tree->inorderIterator();

      node=mitk::DataTreeNode::New();
      node->SetData(reader->GetOutput());
      it->add(node);

      QString tmpName = fileName;
      tmpName = tmpName.right(tmpName.length() - tmpName.findRev("/") - 1);
      mitk::StringProperty::Pointer nameProp = new mitk::StringProperty(tmpName.ascii());
      node->SetProperty("fileName",nameProp);

      // disable volume rendering by default
      node->SetProperty("volumerendering",new mitk::BoolProperty(false));

      mitk::LevelWindowProperty::Pointer levWinProp = new mitk::LevelWindowProperty();
      mitk::LevelWindow levelWindow;
      reader->UpdateLargestPossibleRegion();
      levelWindow.SetAuto( reader->GetOutput()->GetPic() );
      levWinProp->SetLevelWindow(levelWindow);
      node->GetPropertyList()->SetProperty("levelwindow",levWinProp);

      mitkMultiWidget->levelWindowWidget->setLevelWindow(levelWindow);

      initWidgets(it);
    }
  }
  else if(strstr(fileName, ".par")!=0)
  {

    mitk::ParRecFileReader::Pointer reader;

    reader=mitk::ParRecFileReader::New();
    std::cout << "loading " << fileName << " as par/rec ... " << std::endl;
    reader->SetFileName(fileName);

    mitk::DataTreeIterator* it=tree->inorderIterator();

    node=mitk::DataTreeNode::New();
    node->SetData(reader->GetOutput());
    it->add(node);

    QString tmpName = fileName;
    tmpName = tmpName.right(tmpName.length() - tmpName.findRev("/") - 1);
    mitk::StringProperty::Pointer nameProp = new mitk::StringProperty(tmpName.ascii());
    node->SetProperty("fileName",nameProp);

    mitk::LevelWindowProperty::Pointer levWinProp = new mitk::LevelWindowProperty();
    mitk::LevelWindow levelWindow;
    reader->UpdateLargestPossibleRegion();
    levelWindow.SetAuto( reader->GetOutput()->GetPic() );
    levWinProp->SetLevelWindow(levelWindow);
    node->GetPropertyList()->SetProperty("levelwindow",levWinProp);

    mitkMultiWidget->levelWindowWidget->setLevelWindow(levelWindow);
    initWidgets(it);
  }
  else if(strstr(fileName, ".pvtk")!=0)
  {
    vtkStructuredPointsReader *vtkreader = vtkStructuredPointsReader::New();
    vtkreader->SetFileName(fileName);
    vtkreader->Update();

    if(vtkreader->GetOutput()!=NULL)
    {
      mitk::Image::Pointer image = mitk::Image::New();
      image->Initialize(vtkreader->GetOutput());
      image->SetVolume(vtkreader->GetOutput()->GetScalarPointer());

      vtkreader->Delete();

      mitk::DataTreeIterator* it=tree->inorderIterator();

      node=mitk::DataTreeNode::New();
      node->SetData(image);
      it->add(node);

      QString tmpName = fileName;
      tmpName = tmpName.right(tmpName.length() - tmpName.findRev("/") - 1);
      mitk::StringProperty::Pointer nameProp = new mitk::StringProperty(tmpName.ascii());
      node->SetProperty("fileName",nameProp);

      mitk::LevelWindowProperty::Pointer levWinProp = new mitk::LevelWindowProperty();
      mitk::LevelWindow levelWindow;
      levelWindow.SetAuto( image->GetPic() );
      levWinProp->SetLevelWindow(levelWindow);
      node->GetPropertyList()->SetProperty("levelwindow",levWinProp);

      mitkMultiWidget->levelWindowWidget->setLevelWindow(levelWindow);
      initWidgets(it);
    }
  }
  else if( strstr(fileName, ".ves")!=0 )
  {
    mitk::VesselTreeFileReader::Pointer reader = mitk::VesselTreeFileReader::New();
    std::cout << "loading " << fileName << " as ves ... " << std::endl;
    reader->SetFileName(fileName);
    reader->Update();
    mitk::DataTreeIterator* it=tree->inorderIterator();

    node=mitk::DataTreeNode::New();
    node->SetData(reader->GetOutput());
    it->add(node);

    initWidgets(it);
    delete it;
  }
  else if( strstr(fileName, ".uvg")!=0 )
  {
	  mitk::VesselGraphFileReader::Pointer reader = mitk::VesselGraphFileReader::New();
	  std::cout << "loading " << fileName << " as uvg ... " << std::endl;
	  reader->SetFileName(fileName);
	  reader->Update();
	  mitk::DataTreeIterator* it=tree->inorderIterator();

	  node=mitk::DataTreeNode::New();
	  node->SetData(reader->GetOutput());
	  it->add(node);

	  initWidgets(it);
	  delete it;
  }
#ifdef MBI_INTERNAL
  else if(strstr(fileName, "DCM")!=0)
  {
    mitk::DICOMFileReader::Pointer reader;

    reader=mitk::DICOMFileReader::New();
    std::cout << "loading " << fileName << " as pic ... " << std::endl;

    reader->SetFileName(fileName);

    mitk::DataTreeIterator* it=tree->inorderIterator();

    node=mitk::DataTreeNode::New();
    node->SetData(reader->GetOutput());
    it->add(node);

    mitk::LevelWindow levelWindow;
    reader->Update();
    levelWindow.SetAuto( reader->GetOutput()->GetPic() );
    node->SetLevelWindow(levelWindow, NULL);
    mitkMultiWidget->levelWindowWidget->setLevelWindow(levelWindow);

    initWidgets(it);

    delete it;
  }
  else if(strstr(fileName, "hpsonos.db")!=0 || strstr(fileName, "HPSONOS.DB")!=0)
  {

    if (strcmp(fileName,"HPSONOS.DB")==0)
    {
      std::cout << "renamed HPSONOS.DB to hpsonos.db" << std::endl;
      fileName = "hpsonos.db";
    }


    mitk::DSRFileReader::Pointer reader;

    reader=mitk::DSRFileReader::New();
    std::cout << "loading " << fileName << " as DSR ... " << std::endl;

    reader->SetFileName(fileName);
    
    mitk::ImageTimeSelector::Pointer timeSelector=mitk::ImageTimeSelector::New();
    mitk::ImageTimeSelector::Pointer DopplerTimeSelector=mitk::ImageTimeSelector::New();


    mitk::CylindricToCartesianFilter::Pointer cyl2cart = mitk::CylindricToCartesianFilter::New();;
    mitk::CylindricToCartesianFilter::Pointer cyl2cartDoppler = mitk::CylindricToCartesianFilter::New();

		cyl2cart->SetTargetXSize(128);
		cyl2cartDoppler->SetTargetXSize(128); 
		//
    // insert just timeslice nr.0
    // @TODO: insert complete 4D data
    reader->Update();

		bool haveDoppler = false;
    if (reader->GetOutput()->IsValidChannel(0))
    {
				std::cout << "    have channel data 0 (backscatter) ... " << std::endl;
		}

    if (reader->GetOutput()->IsValidChannel(1))
    {
				std::cout << "    have channel data 1 (doppler) ... " << std::endl;
				haveDoppler = true;
		}

				
    timeSelector->SetInput(reader->GetOutput());
    timeSelector->SetTimeNr(0);

   
    DopplerTimeSelector->SetInput(reader->GetOutput());
    DopplerTimeSelector->SetTimeNr(0);


    mitk::DataTreeIterator* it=tree->inorderIterator();


    //
    // switch to Backscatter information
    //    
    timeSelector->SetChannelNr(0);
    timeSelector->Update();
    ipPicPut("timeselect.pic",timeSelector->GetOutput()->GetPic());    
        
    //
    // insert original (in cylinric coordinates) Backscatter information
    //
    node = mitk::DataTreeNode::New();
    node->SetData(timeSelector->GetOutput());
    mitk::StringProperty::Pointer ultrasoundProp = new mitk::StringProperty("OriginalBackscatter");    
    node->SetProperty("ultrasound",ultrasoundProp);
    mitk::StringProperty::Pointer nameProp = new mitk::StringProperty("OriginalBackscatter");
    node->SetProperty("fileName",nameProp);
    node->SetProperty("layer", new mitk::IntProperty(-11) );
    mitk::LevelWindow levelWindow;
    levelWindow.SetAuto( timeSelector->GetOutput()->GetPic() );
    node->SetLevelWindow(levelWindow, NULL);
    node->SetVisibility(false,NULL);
    node->Update();
    it->add(node);    

    //
    // insert transformed (in cartesian coordinates) Backscatter information
    //
    cyl2cart->SetInput(timeSelector->GetOutput());
    node=mitk::DataTreeNode::New();
    node->SetData(cyl2cart->GetOutput());
    ultrasoundProp = new mitk::StringProperty("TransformedBackscatter");
    node->SetProperty("ultrasound",ultrasoundProp);
    nameProp = new mitk::StringProperty("TransformedBackscatter");
    node->SetProperty("fileName",nameProp);
    node->SetProperty("layer", new mitk::IntProperty(-10) );
//    mitk::LevelWindow levelWindow;
    cyl2cart->Update();
    levelWindow.SetAuto( cyl2cart->GetOutput()->GetPic() );
    node->SetLevelWindow(levelWindow, NULL);
    node->Update();
    it->add(node);    

    if (haveDoppler)
    {
				
	    //
  	  // switch to Doppler information
	    //
  	  DopplerTimeSelector->SetChannelNr(1);
	    DopplerTimeSelector->Update();

	    //
  	  // create a Doppler lookup table
    	// TODO: HP map must be provided by DSRFilereader, since it
	    // may be dependend on data ( baseline shift)
  	  //
	    mitk::USLookupTableSource::Pointer LookupTableSource = mitk::USLookupTableSource::New();
  	  LookupTableSource->SetUseDSRDopplerLookupTable();
	    LookupTableSource->Update();
  	  mitk::LookupTableSource::OutputTypePointer LookupTable = LookupTableSource->GetOutput();
	    mitk::LookupTableProperty::Pointer LookupTableProp = new mitk::LookupTableProperty(*LookupTable);


			//
	    // insert original (in cylindric coordinates) Doppler information
  	  //
	    node=mitk::DataTreeNode::New();
	 	  node->SetData(DopplerTimeSelector->GetOutput());
	    ultrasoundProp = new mitk::StringProperty("OriginalDoppler");
  	  node->SetProperty("ultrasound",ultrasoundProp);
	    nameProp = new mitk::StringProperty("OriginalDoppler");
	    node->SetProperty("fileName",nameProp);
	    node->SetProperty("layer", new mitk::IntProperty(-6) );
//    levelWindow.SetAuto( timeSelector->GetOutput()->GetPic() );
//    node->SetLevelWindow(levelWindow, NULL);
//    node->SetProperty("LookupTable", LookupTableProp );
	    node->SetProperty("LookupTable", LookupTableProp );
  	  node->SetVisibility(false,NULL);
	    node->Update();
  	  it->add(node);

			//
  	  // insert transformed (in cartesian coordinates) Doppler information
    	//
	    cyl2cartDoppler->SetInput(DopplerTimeSelector->GetOutput());
  	  node=mitk::DataTreeNode::New();
	    node->SetData(cyl2cartDoppler->GetOutput());
  	  ultrasoundProp = new mitk::StringProperty("TransformedDoppler");
	    node->SetProperty("ultrasound",ultrasoundProp);
	    nameProp = new mitk::StringProperty("TransformedDoppler");
  	  node->SetProperty("fileName",nameProp);
	    node->SetProperty("layer", new mitk::IntProperty(-5) );
  	  cyl2cartDoppler->Update();
//    levelWindow.SetAuto( cyl2cartDoppler->GetOutput()->GetPic() );
//    node->SetLevelWindow(levelWindow, NULL);
    	node->SetProperty("LookupTable", LookupTableProp );
	    node->Update();
  	  it->add(node);
		}

		
   
    mitkMultiWidget->levelWindowWidget->setLevelWindow(levelWindow);

    initWidgets(it);

    delete it;
  }
#endif
}

void QmitkMainTemplate::fileOpenImageSequence()
{
  QString fileName = QFileDialog::getOpenFileName(NULL,"DKFZ Pic (*.seq *.pic *.pic.gz *.seq.gz);;stl files (*.stl)");

  if ( !fileName.isNull() )
  {
    int fnstart = fileName.findRev( QRegExp("[/\\\\]"), fileName.length() );
    if(fnstart<0) fnstart=0;
    int start = fileName.find( QRegExp("[0-9]"), fnstart );
    if(start<0)
    {
      fileOpen(fileName.ascii());
      return;
    }

    char prefix[1024], pattern[1024];

    strncpy(prefix, fileName.ascii(), start);
    prefix[start]=0;

    int stop=fileName.find( QRegExp("[^0-9]"), start );
    sprintf(pattern, "%%s%%0%uu%s",stop-start,fileName.ascii()+stop);

    mitk::PicFileReader::Pointer reader;
    reader=mitk::PicFileReader::New();

    std::cout << "loading " << fileName << " interpreted as image sequence mask: prefix " << prefix << " pattern: " << pattern << std::endl;

    reader->SetFilePrefix(prefix);
    reader->SetFilePattern(pattern);

    mitk::DataTreeIterator* it=tree->inorderIterator();

    mitk::DataTreeNode::Pointer node;
    node=mitk::DataTreeNode::New();
    node->SetData(reader->GetOutput());
    it->add(node);

    initWidgets(it);

    mitkMultiWidget->updateMitkWidgets();

    delete it;
  }
}

void QmitkMainTemplate::initWidget(mitk::DataTreeIterator* it,
                                   QmitkSelectableGLWidget* widget,
                                   const Vector3f& normal, const Vector3f& right )
{

  mitk::PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New();

  //ohne den Pointer-Umweg meckert gcc
  mitk::PlaneView* view = new mitk::PlaneView(Plane<float>(Vector3f(0,0,0),normal),
    right,
    Vector2f(0,0),
    Vector2f(0,0)
    );
  plane->SetPlaneView(*view);
  delete view;

  widget->GetRenderer()->SetData(it);
  widget->GetRenderer()->SetWorldGeometry(plane);
  widget->GetRenderer()->GetDisplayGeometry()->Fit();

  //mitk::DataTreeNode::Pointer node=mitk::DataTreeNode::New();
  //node->SetData(widget->GetRenderer()->GetWorldGeometry2DData());
  //it->add(node);

  widget->update();
}

void QmitkMainTemplate::initWidget(mitk::DataTreeIterator* it,
                                   QmitkSelectableGLWidget* widget,
                                   const Vector3f& origin,
                                   const Vector3f& right,
                                   const Vector3f& bottom)
{

  mitk::PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New();

  //ohne den Pointer-Umweg meckert gcc
  mitk::PlaneView* view = new mitk::PlaneView(origin,right,bottom);
  plane->SetPlaneView(*view);
  delete view;

  widget->GetRenderer()->SetData(it);
  widget->GetRenderer()->SetWorldGeometry(plane);
  widget->GetRenderer()->GetDisplayGeometry()->Fit();

  widget->update();
}

void QmitkMainTemplate::fileSave()
{

}

void QmitkMainTemplate::fileSaveAs()
{
  mitk::DataTreeIterator* it=tree->inorderIterator()->clone();
  while(it->hasNext())
  {
    it->next();
    mitk::DataTreeNode::Pointer node=it->get();
    if(node->GetData()!=NULL)
    {
      mitk::Image::Pointer image = dynamic_cast<mitk::Image*>(node->GetData());
      if( image.IsNotNull() )
      {
        QString fileName = QFileDialog::getSaveFileName(NULL,"pvtk (*.pvtk)");
        if ( !fileName.isNull() )
        {
          if(fileName.endsWith(".pvtk")==false) fileName+=".pvtk";
          vtkStructuredPointsWriter *writer=vtkStructuredPointsWriter::New();
          writer->SetInput(image->GetVtkImageData());
          writer->SetFileName(fileName.ascii());
          writer->SetFileTypeToBinary();
          writer->Write();
          writer->Delete();
        }
      }
      mitk::SurfaceData::Pointer surface = dynamic_cast<mitk::SurfaceData*>(node->GetData());
      if( surface.IsNotNull() )
      {
{'fraction_non_alphanumeric': 0.17062038654420467, 'fraction_numerical': 0.00428241392911478, 'mean_word_length': 4.150174114915845, 'pattern_counts': {'":': 0, '<': 261, '<?xml version=': 0, '>': 466, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5824341', 'n_tokens_mistral': 11663, 'n_tokens_neox': 11288, 'n_words': 1796}