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

 Program:   Medical Imaging & Interaction Toolkit
 Language:  C++
 Date:      $Date: 2010-03-31 16:40:27 +0200 (Mi, 31 Mrz 2010) $
 Version:   $Revision: 21975 $

 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.

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


#include "mitkFiberBundleX.h"

#include <mitkPlanarCircle.h>
#include <mitkPlanarPolygon.h>
#include <mitkPlanarFigureComposite.h>


#include <vtkPointData.h>
#include <vtkDataArray.h>
#include <vtkUnsignedCharArray.h>
#include <vtkPolyLine.h>
#include <vtkCellArray.h>
#include <vtkCellData.h>
#include <vtkIdFilter.h>
#include <vtkClipPolyData.h>
#include <vtkPlane.h>

const char* mitk::FiberBundleX::COLORCODING_ORIENTATION_BASED = "Color_Orient";
const char* mitk::FiberBundleX::COLORCODING_FA_BASED = "Color_FA";
const char* mitk::FiberBundleX::FIBER_ID_ARRAY = "Fiber_IDs";
const char* mitk::FiberBundleX::FA_VALUE_ARRAY = "FA_Values";

mitk::FiberBundleX::FiberBundleX( vtkPolyData* fiberPolyData )
    : m_currentColorCoding(NULL)
    , m_isModified(false)
    , m_NumFibers(0)
{
    if (fiberPolyData == NULL)
        m_FiberPolyData = vtkSmartPointer<vtkPolyData>::New();
    else
        m_FiberPolyData = fiberPolyData;

    m_NumFibers = m_FiberPolyData->GetNumberOfLines();

    UpdateFiberGeometry();
}

mitk::FiberBundleX::~FiberBundleX()
{

}

mitk::FiberBundleX::Pointer mitk::FiberBundleX::GetDeepCopy()
{
    mitk::FiberBundleX::Pointer newFib = mitk::FiberBundleX::New();

    //  newFib->m_FiberIdDataSet = vtkSmartPointer<vtkDataSet>::New();
    //  newFib->m_FiberIdDataSet->DeepCopy(m_FiberIdDataSet);
    newFib->m_FiberPolyData = vtkSmartPointer<vtkPolyData>::New();
    newFib->m_FiberPolyData->DeepCopy(m_FiberPolyData);
    newFib->SetColorCoding(m_currentColorCoding);
    newFib->m_isModified = m_isModified;
    newFib->m_NumFibers = m_NumFibers;
    newFib->UpdateFiberGeometry();

    return newFib;
}

mitk::FiberBundleX::Pointer mitk::FiberBundleX::GenerateNewFiberBundleByIds(std::vector<unsigned long> fiberIds)
{
    mitk::FiberBundleX::Pointer newFib = mitk::FiberBundleX::New();
    vtkSmartPointer<vtkPolyData> newFiberPolyData = vtkSmartPointer<vtkPolyData>::New();
    vtkSmartPointer<vtkCellArray> newLineSet = vtkSmartPointer<vtkCellArray>::New();

    MITK_INFO << "\n=====FINAL RESULT: fib_id ======\n";
    std::vector<unsigned long>::iterator finIt = fiberIds.begin();
    while ( finIt != fiberIds.end() )
    {
        MITK_INFO << *finIt;
        vtkSmartPointer<vtkCell> fiber = m_FiberIdDataSet->GetCell(*finIt);//->DeepCopy(fiber);
        vtkSmartPointer<vtkPoints> fibPoints = fiber->GetPoints();

        for(int i=0; i<fibPoints->GetNumberOfPoints(); i++)
        {
            MITK_INFO << "id: " << fiber->GetPointId(i);
            MITK_INFO << fibPoints->GetPoint(i)[0] << " | " << fibPoints->GetPoint(i)[1] << " | " << fibPoints->GetPoint(i)[2];

            if (m_FiberIdDataSet->GetPointData()->HasArray(FA_VALUE_ARRAY)){
                MITK_INFO << m_FiberIdDataSet->GetPointData()->GetArray(FA_VALUE_ARRAY)->GetTuple(fiber->GetPointId(i));
            }

            if (m_FiberIdDataSet->GetPointData()->HasArray(COLORCODING_ORIENTATION_BASED)){
                MITK_INFO << m_FiberIdDataSet->GetPointData()->GetArray(COLORCODING_ORIENTATION_BASED)->GetTuple(fiber->GetPointId(i));
            }

        }



        //        newLineSet->InsertNextCell(fiber);


        ++finIt;
    }
    MITK_INFO << "=====================\n";


}

// merge two fiber bundles
mitk::FiberBundleX::Pointer mitk::FiberBundleX::operator+(mitk::FiberBundleX* fib)
{

    vtkSmartPointer<vtkPolyData> vNewPolyData = vtkSmartPointer<vtkPolyData>::New();<commit_msg>returning cutting fiberbundle<commit_after>/*=========================================================================

 Program:   Medical Imaging & Interaction Toolkit
 Language:  C++
 Date:      $Date: 2010-03-31 16:40:27 +0200 (Mi, 31 Mrz 2010) $
 Version:   $Revision: 21975 $

 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.

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


#include "mitkFiberBundleX.h"

#include <mitkPlanarCircle.h>
#include <mitkPlanarPolygon.h>
#include <mitkPlanarFigureComposite.h>


#include <vtkPointData.h>
#include <vtkDataArray.h>
#include <vtkUnsignedCharArray.h>
#include <vtkPolyLine.h>
#include <vtkCellArray.h>
#include <vtkCellData.h>
#include <vtkIdFilter.h>
#include <vtkClipPolyData.h>
#include <vtkPlane.h>

const char* mitk::FiberBundleX::COLORCODING_ORIENTATION_BASED = "Color_Orient";
const char* mitk::FiberBundleX::COLORCODING_FA_BASED = "Color_FA";
const char* mitk::FiberBundleX::FIBER_ID_ARRAY = "Fiber_IDs";
const char* mitk::FiberBundleX::FA_VALUE_ARRAY = "FA_Values";

mitk::FiberBundleX::FiberBundleX( vtkPolyData* fiberPolyData )
    : m_currentColorCoding(NULL)
    , m_isModified(false)
    , m_NumFibers(0)
{
    if (fiberPolyData == NULL)
        m_FiberPolyData = vtkSmartPointer<vtkPolyData>::New();
    else
        m_FiberPolyData = fiberPolyData;

    m_NumFibers = m_FiberPolyData->GetNumberOfLines();

    UpdateFiberGeometry();
}

mitk::FiberBundleX::~FiberBundleX()
{

}

mitk::FiberBundleX::Pointer mitk::FiberBundleX::GetDeepCopy()
{
    mitk::FiberBundleX::Pointer newFib = mitk::FiberBundleX::New();

    //  newFib->m_FiberIdDataSet = vtkSmartPointer<vtkDataSet>::New();
    //  newFib->m_FiberIdDataSet->DeepCopy(m_FiberIdDataSet);
    newFib->m_FiberPolyData = vtkSmartPointer<vtkPolyData>::New();
    newFib->m_FiberPolyData->DeepCopy(m_FiberPolyData);
    newFib->SetColorCoding(m_currentColorCoding);
    newFib->m_isModified = m_isModified;
    newFib->m_NumFibers = m_NumFibers;
    newFib->UpdateFiberGeometry();

    return newFib;
}

mitk::FiberBundleX::Pointer mitk::FiberBundleX::GenerateNewFiberBundleByIds(std::vector<unsigned long> fiberIds)
{

    vtkSmartPointer<vtkPolyData> newFiberPolyData = vtkSmartPointer<vtkPolyData>::New();
    vtkSmartPointer<vtkCellArray> newLineSet = vtkSmartPointer<vtkCellArray>::New();
    vtkSmartPointer<vtkPoints> newPointSet = vtkSmartPointer<vtkPoints>::New();

    MITK_INFO << "\n=====FINAL RESULT: fib_id ======\n";
    MITK_INFO << "Number of new Fibers: " << fiberIds.size();
    // iterate through the vectorcontainer hosting all desired fiber Ids

    std::vector<unsigned long>::iterator finIt = fiberIds.begin();
    while ( finIt != fiberIds.end() )
    {
//        MITK_INFO << *finIt;
        vtkSmartPointer<vtkCell> fiber = m_FiberIdDataSet->GetCell(*finIt);//->DeepCopy(fiber);
        vtkSmartPointer<vtkPoints> fibPoints = fiber->GetPoints();

        vtkSmartPointer<vtkPolyLine> newFiber = vtkSmartPointer<vtkPolyLine>::New();
        newFiber->GetPointIds()->SetNumberOfIds( fibPoints->GetNumberOfPoints() );

        for(int i=0; i<fibPoints->GetNumberOfPoints(); i++)
        {
//            MITK_INFO << "id: " << fiber->GetPointId(i);
//            MITK_INFO << fibPoints->GetPoint(i)[0] << " | " << fibPoints->GetPoint(i)[1] << " | " << fibPoints->GetPoint(i)[2];
            newFiber->GetPointIds()->SetId(i, newPointSet->GetNumberOfPoints());
            newPointSet->InsertNextPoint(fibPoints->GetPoint(i)[0], fibPoints->GetPoint(i)[1], fibPoints->GetPoint(i)[2]);

            if (m_FiberIdDataSet->GetPointData()->HasArray(FA_VALUE_ARRAY)){
                MITK_INFO << m_FiberIdDataSet->GetPointData()->GetArray(FA_VALUE_ARRAY)->GetTuple(fiber->GetPointId(i));
            }

            if (m_FiberIdDataSet->GetPointData()->HasArray(COLORCODING_ORIENTATION_BASED)){
                MITK_INFO << m_FiberIdDataSet->GetPointData()->GetArray(COLORCODING_ORIENTATION_BASED)->GetTuple(fiber->GetPointId(i));
            }
        }

        newLineSet->InsertNextCell(newFiber);
        ++finIt;
    }

    newFiberPolyData->SetPoints(newPointSet);
    newFiberPolyData->SetLines(newLineSet);
    MITK_INFO << "new fiberbundle polydata points: " << newFiberPolyData->GetNumberOfPoints();
    MITK_INFO << "new fiberbundle polydata lines: " << newFiberPolyData->GetNumberOfLines();
    MITK_INFO << "=====================\n";

    mitk::FiberBundleX::Pointer newFib = mitk::FiberBundleX::New(newFiberPolyData);
    return newFib;
}

// merge two fiber bundles
mitk::FiberBundleX::Pointer mitk::FiberBundleX::operator+(mitk::FiberBundleX* fib)
{

    vtkSmartPointer<vtkPolyData> vNewPolyData = vtkSmartPointer<vtkPolyData>::New();
{'fraction_non_alphanumeric': 0.16824258232800782, 'fraction_numerical': 0.0077165525486360175, 'mean_word_length': 4.85741565881604, 'pattern_counts': {'":': 0, '<': 119, '<?xml version=': 0, '>': 135, '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': '2279055', 'n_tokens_mistral': 3206, 'n_tokens_neox': 3061, 'n_words': 473}