<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.

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


#ifndef MITKIMAGEACCESSBYITK_H_HEADER_INCLUDED
#define MITKIMAGEACCESSBYITK_H_HEADER_INCLUDED
 
#include <itkCastImageFilter.h>
#include <mitkImageToItk.h>

#ifndef DOXYGEN_SKIP
#define _accessByItk(mitkImage, itkImageTypeFunction, pixeltype, dimension)            \
  if ( typeId == typeid(pixeltype) )                                                   \
{                                                                                      \
    typedef itk::Image<pixeltype, dimension> ImageType;                                \
    typedef mitk::ImageToItk<ImageType> ImageToItkType;                                \
    itk::SmartPointer<ImageToItkType> imagetoitk = ImageToItkType::New();                                  \
    imagetoitk->SetInput(mitkImage);                                                   \
    imagetoitk->Update();                                                              \
    itkImageTypeFunction(imagetoitk->GetOutput());               \
}                                                              

#define _accessAllTypesByItk(mitkImage, itkImageTypeFunction, dimension)               \
      _accessByItk(mitkImage, itkImageTypeFunction, double, dimension) else            \
      _accessByItk(mitkImage, itkImageTypeFunction, float, dimension) else             \
      _accessByItk(mitkImage, itkImageTypeFunction, int, dimension) else               \
      _accessByItk(mitkImage, itkImageTypeFunction, unsigned int, dimension) else      \
      _accessByItk(mitkImage, itkImageTypeFunction, short, dimension) else             \
      _accessByItk(mitkImage, itkImageTypeFunction, unsigned short, dimension) else    \
      _accessByItk(mitkImage, itkImageTypeFunction, char, dimension) else              \
      _accessByItk(mitkImage, itkImageTypeFunction, unsigned char,  dimension)         \

#endif //DOXYGEN_SKIP

//##Documentation
//## @brief Access an mitk-image by an itk-image
//## 
//## Define a templated function or method (@a itkImageTypeFunction) 
//## within which the mitk-image (@a mitkImage) is accessed:
//## \code
//##   template < typename TPixel, unsigned int VImageDimension > 
//##     void ExampleFunction( itk::Image<TPixel, VImageDimension>* itkImage, TPixel* dummy = NULL );
//## \endcode
//## Instantiate the function using
//## \code
//##   InstantiateAccessFunction(ExampleFunction);
//## \endcode
//## Within the itk::Image passed to the function/method has the same
//## data-pointer as the mitk-image. So you have full read- and write-
//## access to the data vector of the mitk-image using the itk-image.
//## Call by:
//## \code
//##  // inputMitkImage being of type mitk::Image*
//##  AccessByItk(inputMitkImage, ExampleFunction);
//## \endcode
//## @note If your inputMitkImage is an mitk::Image::Pointer, use 
//## inputMitkImage.GetPointer()
//## @note If you need to pass an additional parameter to your 
//## access-function (@a itkImageTypeFunction), use AccessByItk.
//## @note If you know the dimension of your input mitk-image,
//## it is better to use AccessFixedDimensionByItk (less code
//## is generated).
//## \sa AccessFixedDimensionByItk
//## \sa AccessFixedTypeByItk
//## \sa AccessFixedPixelTypeByItk
//## \sa AccessByItk_1
//## \sa AccessByItk_2
//## @ingroup Adaptor
#define AccessByItk(mitkImage, itkImageTypeFunction)                                   \
{                                                                                      \
  const std::type_info& typeId=*mitkImage->GetPixelType().GetTypeId();                 \
  const mitk::Image* constImage = mitkImage;                                           \
  const_cast<mitk::Image*>(constImage)->Update();                                      \
  assert(mitkImage->GetDimension()>=2 && mitkImage->GetDimension()<=3);                \
  if(mitkImage->GetDimension()==2)                                                     \
  {                                                                                    \
    _accessAllTypesByItk(mitkImage, itkImageTypeFunction, 2);                          \
  }                                                                                    \
  else                                                                                 \
  {                                                                                    \
    _accessAllTypesByItk(mitkImage, itkImageTypeFunction, 3)                           \
  }                                                                                    \
}

//##Documentation
//## @brief Access an mitk-image with known dimension by an itk-image
//## 
//## For usage, see AccessByItk.
//## @param dimension dimension of the mitk-image. 
//##
//## If the image has a different dimension, an exception is thrown 
//## (by assert).
//## If you do not know the dimension for sure, use AccessByItk.
//## \sa AccessByItk
//## \sa AccessFixedDimensionByItk
//## \sa AccessFixedTypeByItk
//## \sa AccessFixedPixelTypeByItk
//## @ingroup Adaptor
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)          \
{                                                                                      \
  const std::type_info& typeId=*mitkImage->GetPixelType().GetTypeId();                 \
  const mitk::Image* constImage = mitkImage;                                           \
  const_cast<mitk::Image*>(constImage)->Update();                                      \
  assert(mitkImage->GetDimension()==dimension);                                        \
  _accessAllTypesByItk(mitkImage, itkImageTypeFunction, dimension)                     \
}

//##Documentation
//## @brief Access an mitk-image with known type (pixel type and dimension) 
//## by an itk-image
//## 
//## For usage, see AccessByItk.
//## @param dimension dimension of the mitk-image. If the image 
//## has a different dimension, an exception is thrown (by assert).
//## If you do not know the dimension for sure, use AccessByItk.
//## \sa AccessByItk
//## \sa AccessFixedDimensionByItk
//## \sa AccessFixedTypeByItk
//## \sa AccessFixedPixelTypeByItk
//## @ingroup Adaptor
#define AccessFixedTypeByItk(mitkImage, itkImageTypeFunction, pixeltype, dimension)              \
{                                                                                                \
  const std::type_info& typeId=*mitkImage->GetPixelType().GetTypeId();                           \
   const mitk::Image* constImage = mitkImage;                                                    \
  const_cast<mitk::Image*>(constImage)->Update();                                                \
  assert(mitkImage->GetDimension()==dimension);                                                  \
  _accessByItk(mitkImage, itkImageTypeFunction, pixeltype, dimension)                            \
}

//##Documentation
//## @brief Access an mitk-image with known pixeltype (but unknown dimension) 
//## by an itk-image and pass two additional parameters to the access-function
//## 
//## For usage, see AccessByItk.
//## @param pixeltype pixel type of the mitk-image. 
//##
//## If the image has a different pixel type, an exception is 
//## thrown (by assert).
//## If you do not know the pixel type for sure, use AccessByItk.
//## \sa AccessByItk
//## \sa AccessFixedDimensionByItk
//## \sa AccessFixedTypeByItk
//## \sa AccessFixedPixelTypeByItk
//## @ingroup Adaptor
#define AccessFixedPixelTypeByItk(mitkImage, itkImageTypeFunction, pixeltype)                    \
{                                                                                                \
  const std::type_info& typeId=*mitkImage->GetPixelType().GetTypeId();                           \
  const mitk::Image* constImage = mitkImage;                                                     \
  const_cast<mitk::Image*>(constImage)->Update();                                                \
  assert(mitkImage->GetDimension()>=2 && mitkImage->GetDimension()<=3);                          \
  if(mitkImage->GetDimension()==2)                                                               \
  {                                                                                              \
    _accessByItk(mitkImage, itkImageTypeFunction, pixeltype, 2);                                 \
  }                                                                                              \
  else                                                                                           \
  {                                                                                              \
    _accessByItk(mitkImage, itkImageTypeFunction, pixeltype, 3);                                 \
  }                                                                                              \
}

//----------------------- version with 1 additional paramater ------------------<commit_msg>some more parantheses in preprocessor macros<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.

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


#ifndef MITKIMAGEACCESSBYITK_H_HEADER_INCLUDED
#define MITKIMAGEACCESSBYITK_H_HEADER_INCLUDED
 
#include <itkCastImageFilter.h>
#include <mitkImageToItk.h>

#ifndef DOXYGEN_SKIP
#define _accessByItk(mitkImage, itkImageTypeFunction, pixeltype, dimension)            \
  if ( typeId == typeid(pixeltype) )                                                   \
{                                                                                      \
    typedef itk::Image<pixeltype, dimension> ImageType;                                \
    typedef mitk::ImageToItk<ImageType> ImageToItkType;                                \
    itk::SmartPointer<ImageToItkType> imagetoitk = ImageToItkType::New();                                  \
    imagetoitk->SetInput(mitkImage);                                                   \
    imagetoitk->Update();                                                              \
    itkImageTypeFunction(imagetoitk->GetOutput());               \
}                                                              

#define _accessAllTypesByItk(mitkImage, itkImageTypeFunction, dimension)               \
      _accessByItk(mitkImage, itkImageTypeFunction, double, dimension) else            \
      _accessByItk(mitkImage, itkImageTypeFunction, float, dimension) else             \
      _accessByItk(mitkImage, itkImageTypeFunction, int, dimension) else               \
      _accessByItk(mitkImage, itkImageTypeFunction, unsigned int, dimension) else      \
      _accessByItk(mitkImage, itkImageTypeFunction, short, dimension) else             \
      _accessByItk(mitkImage, itkImageTypeFunction, unsigned short, dimension) else    \
      _accessByItk(mitkImage, itkImageTypeFunction, char, dimension) else              \
      _accessByItk(mitkImage, itkImageTypeFunction, unsigned char,  dimension)         \

#endif //DOXYGEN_SKIP

//##Documentation
//## @brief Access an mitk-image by an itk-image
//## 
//## Define a templated function or method (@a itkImageTypeFunction) 
//## within which the mitk-image (@a mitkImage) is accessed:
//## \code
//##   template < typename TPixel, unsigned int VImageDimension > 
//##     void ExampleFunction( itk::Image<TPixel, VImageDimension>* itkImage, TPixel* dummy = NULL );
//## \endcode
//## Instantiate the function using
//## \code
//##   InstantiateAccessFunction(ExampleFunction);
//## \endcode
//## Within the itk::Image passed to the function/method has the same
//## data-pointer as the mitk-image. So you have full read- and write-
//## access to the data vector of the mitk-image using the itk-image.
//## Call by:
//## \code
//##  // inputMitkImage being of type mitk::Image*
//##  AccessByItk(inputMitkImage, ExampleFunction);
//## \endcode
//## @note If your inputMitkImage is an mitk::Image::Pointer, use 
//## inputMitkImage.GetPointer()
//## @note If you need to pass an additional parameter to your 
//## access-function (@a itkImageTypeFunction), use AccessByItk.
//## @note If you know the dimension of your input mitk-image,
//## it is better to use AccessFixedDimensionByItk (less code
//## is generated).
//## \sa AccessFixedDimensionByItk
//## \sa AccessFixedTypeByItk
//## \sa AccessFixedPixelTypeByItk
//## \sa AccessByItk_1
//## \sa AccessByItk_2
//## @ingroup Adaptor
#define AccessByItk(mitkImage, itkImageTypeFunction)                                   \
{                                                                                      \
  const std::type_info& typeId=*(mitkImage)->GetPixelType().GetTypeId();                 \
  const mitk::Image* constImage = mitkImage;                                           \
  const_cast<mitk::Image*>(constImage)->Update();                                      \
  assert((mitkImage)->GetDimension()>=2 && (mitkImage)->GetDimension()<=3);                \
  if((mitkImage)->GetDimension()==2)                                                     \
  {                                                                                    \
    _accessAllTypesByItk(mitkImage, itkImageTypeFunction, 2);                          \
  }                                                                                    \
  else                                                                                 \
  {                                                                                    \
    _accessAllTypesByItk(mitkImage, itkImageTypeFunction, 3)                           \
  }                                                                                    \
}

//##Documentation
//## @brief Access an mitk-image with known dimension by an itk-image
//## 
//## For usage, see AccessByItk.
//## @param dimension dimension of the mitk-image. 
//##
//## If the image has a different dimension, an exception is thrown 
//## (by assert).
//## If you do not know the dimension for sure, use AccessByItk.
//## \sa AccessByItk
//## \sa AccessFixedDimensionByItk
//## \sa AccessFixedTypeByItk
//## \sa AccessFixedPixelTypeByItk
//## @ingroup Adaptor
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)          \
{                                                                                      \
  const std::type_info& typeId=*(mitkImage)->GetPixelType().GetTypeId();                 \
  const mitk::Image* constImage = mitkImage;                                           \
  const_cast<mitk::Image*>(constImage)->Update();                                      \
  assert((mitkImage)->GetDimension()==dimension);                                        \
  _accessAllTypesByItk(mitkImage, itkImageTypeFunction, dimension)                     \
}

//##Documentation
//## @brief Access an mitk-image with known type (pixel type and dimension) 
//## by an itk-image
//## 
//## For usage, see AccessByItk.
//## @param dimension dimension of the mitk-image. If the image 
//## has a different dimension, an exception is thrown (by assert).
//## If you do not know the dimension for sure, use AccessByItk.
//## \sa AccessByItk
//## \sa AccessFixedDimensionByItk
//## \sa AccessFixedTypeByItk
//## \sa AccessFixedPixelTypeByItk
//## @ingroup Adaptor
#define AccessFixedTypeByItk(mitkImage, itkImageTypeFunction, pixeltype, dimension)              \
{                                                                                                \
  const std::type_info& typeId=*(mitkImage)->GetPixelType().GetTypeId();                           \
   const mitk::Image* constImage = mitkImage;                                                    \
  const_cast<mitk::Image*>(constImage)->Update();                                                \
  assert((mitkImage)->GetDimension()==dimension);                                                  \
  _accessByItk(mitkImage, itkImageTypeFunction, pixeltype, dimension)                            \
}

//##Documentation
//## @brief Access an mitk-image with known pixeltype (but unknown dimension) 
//## by an itk-image and pass two additional parameters to the access-function
//## 
//## For usage, see AccessByItk.
//## @param pixeltype pixel type of the mitk-image. 
//##
//## If the image has a different pixel type, an exception is 
//## thrown (by assert).
//## If you do not know the pixel type for sure, use AccessByItk.
//## \sa AccessByItk
//## \sa AccessFixedDimensionByItk
//## \sa AccessFixedTypeByItk
//## \sa AccessFixedPixelTypeByItk
//## @ingroup Adaptor
#define AccessFixedPixelTypeByItk(mitkImage, itkImageTypeFunction, pixeltype)                    \
{                                                                                                \
  const std::type_info& typeId=*(mitkImage)->GetPixelType().GetTypeId();                           \
  const mitk::Image* constImage = mitkImage;                                                     \
  const_cast<mitk::Image*>(constImage)->Update();                                                \
  assert((mitkImage)->GetDimension()>=2 && (mitkImage)->GetDimension()<=3);                          \
  if((mitkImage)->GetDimension()==2)                                                               \
  {                                                                                              \
    _accessByItk(mitkImage, itkImageTypeFunction, pixeltype, 2);                                 \
  }                                                                                              \
  else                                                                                           \
  {                                                                                              \
    _accessByItk(mitkImage, itkImageTypeFunction, pixeltype, 3);                                 \
  }                                                                                              \
}

//----------------------- version with 1 additional paramater ------------------
{'fraction_non_alphanumeric': 0.11631427825632994, 'fraction_numerical': 0.001357347950926651, 'mean_word_length': 1.4150277357539083, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 164, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6944716', 'n_tokens_mistral': 4547, 'n_tokens_neox': 4494, 'n_words': 1117}