<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 <vtkSTLReader.h>
#include <mitkSurfaceData.h>
#include <mitkColorProperty.h>
#include <mitkFloatProperty.h>
#include <qregexp.h>

mitk::FloatProperty::Pointer opacityprop=NULL;

void QmitkMainTemplate::fileNew()
{

}

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

    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());
                //surface->Register(); //FIXME: das weakpointer-Problem! ...

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

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

            //FIXME: das folgende sollte berflssig sein. Problem ist aber, das es z.Z. noch keine Mglichkeit gibt festzustellen, wann der Baum zuletzt gendert wurde.
            //mitkMultiWidget->mitkWidget1->GetRenderer()->SetData(it);
            //mitkMultiWidget->mitkWidget2->GetRenderer()->SetData(it);
            //mitkMultiWidget->mitkWidget3->GetRenderer()->SetData(it);
            mitkMultiWidget->mitkWidget4->GetRenderer()->SetData(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->Register(); //FIXME: das WeakPointer problem!

            reader->SetFileName(fileName);


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

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

	initWidgets(node);
	    
            //mitk::DataTreeNode::Pointer node2=mitk::DataTreeNode::New();
            //node2->SetData(mitkMultiWidget->mitkWidget3->GetRenderer()->GetWorldGeometry2DData());
            //it->add(node2);


            mitkMultiWidget->mitkWidget4->GetRenderer()->SetMapperID(2);
            mitkMultiWidget->mitkWidget4->GetRenderer()->SetData(it);
            mitkMultiWidget->mitkWidget4->GetRenderer()->GetDisplayGeometry()->Fit();
            // schrg
            //initWidget(it,
            //	   mitkMultiWidget->mitkWidget4,
            //	   Vector3f(0,0,0),
            //	   Vector3f(header->n[0],header->n[1],0),
            //	   Vector3f(0,0,header->n[2])
            //	   );
            //       ipPicFree(header);
            delete it;
        }
    }
    if(node != NULL)
    {
        static int count = 0;
	if(count>0)
        {
            //sliderFP->setMinValue(0);
            //sliderFP->setMaxValue(100);
            //sliderFP->setValue(50);

            float color[3]={1.0f,0.0f,0.0f};
            mitk::ColorProperty::Pointer colorprop = new mitk::ColorProperty(color);
            node->GetPropertyList()->SetProperty("color", colorprop);

            //mitk::FloatProperty::Pointer 
                opacityprop = new mitk::FloatProperty(0.5f);
            node->GetPropertyList()->SetProperty("opacity", opacityprop);
        }
        ++count;
    }
}

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

    if ( !fileName.isNull() )
    {
        int start = fileName.find( QRegExp("[0-9]"), 0 );
        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);<commit_msg>loading of image sequences improved.<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 <vtkSTLReader.h>
#include <mitkSurfaceData.h>
#include <mitkColorProperty.h>
#include <mitkFloatProperty.h>
#include <qregexp.h>

mitk::FloatProperty::Pointer opacityprop=NULL;

void QmitkMainTemplate::fileNew()
{

}

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

    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());
                //surface->Register(); //FIXME: das weakpointer-Problem! ...

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

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

            //FIXME: das folgende sollte berflssig sein. Problem ist aber, das es z.Z. noch keine Mglichkeit gibt festzustellen, wann der Baum zuletzt gendert wurde.
            //mitkMultiWidget->mitkWidget1->GetRenderer()->SetData(it);
            //mitkMultiWidget->mitkWidget2->GetRenderer()->SetData(it);
            //mitkMultiWidget->mitkWidget3->GetRenderer()->SetData(it);
            mitkMultiWidget->mitkWidget4->GetRenderer()->SetData(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->Register(); //FIXME: das WeakPointer problem!

            reader->SetFileName(fileName);


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

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

	initWidgets(node);
	    
            //mitk::DataTreeNode::Pointer node2=mitk::DataTreeNode::New();
            //node2->SetData(mitkMultiWidget->mitkWidget3->GetRenderer()->GetWorldGeometry2DData());
            //it->add(node2);


            mitkMultiWidget->mitkWidget4->GetRenderer()->SetMapperID(2);
            mitkMultiWidget->mitkWidget4->GetRenderer()->SetData(it);
            mitkMultiWidget->mitkWidget4->GetRenderer()->GetDisplayGeometry()->Fit();
            // schrg
            //initWidget(it,
            //	   mitkMultiWidget->mitkWidget4,
            //	   Vector3f(0,0,0),
            //	   Vector3f(header->n[0],header->n[1],0),
            //	   Vector3f(0,0,header->n[2])
            //	   );
            //       ipPicFree(header);
            delete it;
        }
    }
    if(node != NULL)
    {
        static int count = 0;
	if(count>0)
        {
            //sliderFP->setMinValue(0);
            //sliderFP->setMaxValue(100);
            //sliderFP->setValue(50);

            float color[3]={1.0f,0.0f,0.0f};
            mitk::ColorProperty::Pointer colorprop = new mitk::ColorProperty(color);
            node->GetPropertyList()->SetProperty("color", colorprop);

            //mitk::FloatProperty::Pointer 
                opacityprop = new mitk::FloatProperty(0.5f);
            node->GetPropertyList()->SetProperty("opacity", opacityprop);
        }
        ++count;
    }
}

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);
{'fraction_non_alphanumeric': 0.18241356062794953, 'fraction_numerical': 0.012424154868535105, 'mean_word_length': 2.563486616334935, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 125, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5444292', 'n_tokens_mistral': 3184, 'n_tokens_neox': 3105, 'n_words': 518}