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

Program:   Medical Imaging & Interaction Toolkit
Language:  C++
Date:      $Date: 2008-02-07 17:17:57 +0100 (Do, 07 Feb 2008) $
Version:   $Revision: 11989 $

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.

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


#ifndef __mitkDiffusionImage__h
#define __mitkDiffusionImage__h

#include "mitkImage.h"
#include "itkVectorImage.h"
#include "itkVectorImageToImageAdaptor.h"

namespace mitk
{

  /**
  * \brief this class encapsulates diffusion volumes (vectorimages not
  * yet supported by mitkImage)
  */
  template<class TPixelType>
  class DiffusionImage : public Image
  {

  public:
    typedef TPixelType PixelType;
    typedef typename itk::VectorImage<TPixelType, 3>
                                                ImageType;
    typedef vnl_vector_fixed< double, 3 >       GradientDirectionType;
    typedef itk::VectorContainer< unsigned int,
      GradientDirectionType >                   GradientDirectionContainerType;
    typedef itk::VectorImageToImageAdaptor< TPixelType, 3 >
                                                AdaptorType;
    typedef vnl_matrix_fixed< double, 3, 3 >      MeasurementFrameType;

    mitkClassMacro( DiffusionImage, Image );
    itkNewMacro(Self);

    //void SetRequestedRegionToLargestPossibleRegion();
    //bool RequestedRegionIsOutsideOfTheBufferedRegion();
    //virtual bool VerifyRequestedRegion();
    //void SetRequestedRegion(itk::DataObject *data);

    void AverageRedundantGradients(double precision);

    GradientDirectionContainerType::Pointer CalcAveragedDirectionSet(double precision, GradientDirectionContainerType::Pointer directions);

    void CorrectDKFZBrokenGradientScheme(double precision);

    typename ImageType::Pointer GetVectorImage()
    { return m_VectorImage; }
    void SetVectorImage(typename ImageType::Pointer image )
    { this->m_VectorImage = image; }

    void InitializeFromVectorImage();
    void SetDisplayIndexForRendering(int displayIndex);

    GradientDirectionContainerType::Pointer GetDirections()
    { return m_Directions; }
    void SetDirections( GradientDirectionContainerType::Pointer directions )
    { this->m_Directions = directions; }
    void SetDirections(const std::vector<itk::Vector<double,3> > directions)
    {
      m_Directions = GradientDirectionContainerType::New();
      for(unsigned int i=0; i<directions.size(); i++)
      {
        m_Directions->InsertElement( i, directions[i].Get_vnl_vector() );
      }
    }
    GradientDirectionContainerType::Pointer GetOriginalDirections()
    { return m_OriginalDirections; }
    void SetOriginalDirections( GradientDirectionContainerType::Pointer directions )
    { this->m_OriginalDirections = directions; this->ApplyMeasurementFrame(); }
    void SetOriginalDirections(const std::vector<itk::Vector<double,3> > directions)
    {
      m_OriginalDirections = GradientDirectionContainerType::New();
      for(unsigned int i=0; i<directions.size(); i++)
      {
        m_OriginalDirections->InsertElement( i, directions[i].Get_vnl_vector() );
      }
      this->ApplyMeasurementFrame();
    }

    MeasurementFrameType GetMeasurementFrame()
    { return m_MeasurementFrame; }
    void SetMeasurementFrame( MeasurementFrameType mFrame )
    { this->m_MeasurementFrame = mFrame; this->ApplyMeasurementFrame(); }

    itkGetMacro(B_Value, float);
    itkSetMacro(B_Value, float);

    float GetB_Value(int i)
    {
      if(i > m_Directions->Size()-1)
        return -1;

      if(m_Directions->ElementAt(i).one_norm() <= 0.0)
      {
        return 0;
      }
      else
      {
        double twonorm = m_Directions->ElementAt(i).two_norm();
        return m_B_Value*twonorm*twonorm ;
      }
    }

    bool AreAlike(GradientDirectionType g1, GradientDirectionType g2, double precision);

    int GetNumDirections();
    int GetNumB0();
    std::vector<int> GetB0Indices();
    bool IsMultiBval();

  protected:
    DiffusionImage();
    virtual ~DiffusionImage();

    void ApplyMeasurementFrame();

    typename ImageType::Pointer               m_VectorImage;
    GradientDirectionContainerType::Pointer   m_Directions;
    GradientDirectionContainerType::Pointer   m_OriginalDirections;
    float                                     m_B_Value;
    typename AdaptorType::Pointer             m_VectorImageAdaptor;
    int                                       m_DisplayIndex;
    MeasurementFrameType                      m_MeasurementFrame;
  };

} // namespace mitk

#include "mitkDiffusionImage.txx"<commit_msg>add method : void GetBvalueList( std::vector<type> * vec )<commit_after>/*=========================================================================

Program:   Medical Imaging & Interaction Toolkit
Language:  C++
Date:      $Date: 2008-02-07 17:17:57 +0100 (Do, 07 Feb 2008) $
Version:   $Revision: 11989 $

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.

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


#ifndef __mitkDiffusionImage__h
#define __mitkDiffusionImage__h

#include "mitkImage.h"
#include "itkVectorImage.h"
#include "itkVectorImageToImageAdaptor.h"
#include <iomanip>

namespace mitk
{

/**
  * \brief this class encapsulates diffusion volumes (vectorimages not
  * yet supported by mitkImage)
  */
template<class TPixelType>
class DiffusionImage : public Image
{

public:
    typedef TPixelType PixelType;
    typedef typename itk::VectorImage<TPixelType, 3>
    ImageType;
    typedef vnl_vector_fixed< double, 3 >       GradientDirectionType;
    typedef itk::VectorContainer< unsigned int,
    GradientDirectionType >                   GradientDirectionContainerType;
    typedef itk::VectorImageToImageAdaptor< TPixelType, 3 >
    AdaptorType;
    typedef vnl_matrix_fixed< double, 3, 3 >      MeasurementFrameType;

    mitkClassMacro( DiffusionImage, Image );
    itkNewMacro(Self);

    //void SetRequestedRegionToLargestPossibleRegion();
    //bool RequestedRegionIsOutsideOfTheBufferedRegion();
    //virtual bool VerifyRequestedRegion();
    //void SetRequestedRegion(itk::DataObject *data);

    void AverageRedundantGradients(double precision);

    GradientDirectionContainerType::Pointer CalcAveragedDirectionSet(double precision, GradientDirectionContainerType::Pointer directions);

    void CorrectDKFZBrokenGradientScheme(double precision);

    typename ImageType::Pointer GetVectorImage()
    { return m_VectorImage; }
    void SetVectorImage(typename ImageType::Pointer image )
    { this->m_VectorImage = image; }

    void InitializeFromVectorImage();
    void SetDisplayIndexForRendering(int displayIndex);

    GradientDirectionContainerType::Pointer GetDirections()
    { return m_Directions; }
    void SetDirections( GradientDirectionContainerType::Pointer directions )
    { this->m_Directions = directions; }
    void SetDirections(const std::vector<itk::Vector<double,3> > directions)
    {
        m_Directions = GradientDirectionContainerType::New();
        for(unsigned int i=0; i<directions.size(); i++)
        {
            m_Directions->InsertElement( i, directions[i].Get_vnl_vector() );
        }
    }
    GradientDirectionContainerType::Pointer GetOriginalDirections()
    { return m_OriginalDirections; }
    void SetOriginalDirections( GradientDirectionContainerType::Pointer directions )
    { this->m_OriginalDirections = directions; this->ApplyMeasurementFrame(); }
    void SetOriginalDirections(const std::vector<itk::Vector<double,3> > directions)
    {
        m_OriginalDirections = GradientDirectionContainerType::New();
        for(unsigned int i=0; i<directions.size(); i++)
        {
            m_OriginalDirections->InsertElement( i, directions[i].Get_vnl_vector() );
        }
        this->ApplyMeasurementFrame();
    }

    MeasurementFrameType GetMeasurementFrame()
    { return m_MeasurementFrame; }
    void SetMeasurementFrame( MeasurementFrameType mFrame )
    { this->m_MeasurementFrame = mFrame; this->ApplyMeasurementFrame(); }

    itkGetMacro(B_Value, float);
    itkSetMacro(B_Value, float);

    float GetB_Value(int i)
    {
        if(i > m_Directions->Size()-1)
            return -1;

        if(m_Directions->ElementAt(i).one_norm() <= 0.0)
        {
            return 0;
        }
        else
        {
            double twonorm = m_Directions->ElementAt(i).two_norm();
            return m_B_Value*twonorm*twonorm ;
        }
    }

    bool AreAlike(GradientDirectionType g1, GradientDirectionType g2, double precision);

    int GetNumDirections();
    int GetNumB0();
    std::vector<int> GetB0Indices();
    bool IsMultiBval();

    void GetBvalueList(std::vector<float> * bValVec)
    {
        if(bValVec != 0){
            if(IsMultiBval())
            {
                std::map<double, int> valueMap;
                std::map<double, int>::iterator it;
                int gradients = m_OriginalDirections->Size();
                for (int i=0; i<gradients; i++)
                {
                    float currentBvalue = std::floor(GetB_Value(i));

                    float rounded = int((currentBvalue+10)/100)*100;

                    if((valueMap.find( rounded )) == valueMap.end() )
                    {
                        valueMap[rounded] = 1;
                    }else{
                        valueMap[rounded] += 1;
                    }
                }

                for(it = valueMap.begin(); it != valueMap.end(); it ++)
                {
                    bValVec->push_back((*it).first);
                    MITK_INFO  << "BValue : "<< std::setprecision(10)  << (*it).first << " Count : " << (*it).second;
                }

            }else{
                bValVec->push_back(GetB_Value());
            }
        }
    }

protected:
    DiffusionImage();
    virtual ~DiffusionImage();

    void ApplyMeasurementFrame();

    typename ImageType::Pointer               m_VectorImage;
    GradientDirectionContainerType::Pointer   m_Directions;
    GradientDirectionContainerType::Pointer   m_OriginalDirections;
    float                                     m_B_Value;
    typename AdaptorType::Pointer             m_VectorImageAdaptor;
    int                                       m_DisplayIndex;
    MeasurementFrameType                      m_MeasurementFrame;
};

} // namespace mitk

#include "mitkDiffusionImage.txx"
{'fraction_non_alphanumeric': 0.11786935396796833, 'fraction_numerical': 0.009717473456901205, 'mean_word_length': 3.0774027879677184, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5016277', 'n_tokens_mistral': 3240, 'n_tokens_neox': 2982, 'n_words': 643}