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

  Program:   Insight Segmentation & Registration Toolkit
  Module:    itkImageComputeOffsetAndIndexTest.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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.

=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include <iostream>
#define ITK_LEAN_AND_MEAN

#include "itkImage.h"
#include "itkImageHelper.h"
#include "itkTimeProbesCollectorBase.h"

template <class TImage>
void ComputeIndex(TImage *image, unsigned int count, unsigned int repeat)
{
  typename TImage::IndexType index;
  for (unsigned j = 0; j < repeat; j++)
    {
    for (unsigned int i = 0; i < count; i++)
      {
      index = image->ComputeIndex (i);
      }
    }
  std::cout << "Last index: " << index << std::endl;
}

template <class TImage>
void ComputeFastIndex(TImage *image, unsigned int count, unsigned int repeat)
{
  typename TImage::IndexType index;
  const typename TImage::IndexType &bufferedRegionIndex = image->GetBufferedRegion().GetIndex();
  const typename TImage::OffsetValueType *offsetTable = image->GetOffsetTable();
  
  for (unsigned int j = 0; j < repeat; j++)
    {
    for (unsigned int i = 0; i < count; i++)
      {
      itk::ImageHelper<TImage::ImageDimension,TImage::ImageDimension>::ComputeIndex(bufferedRegionIndex,
                                                                                    i,
                                                                                    offsetTable,
                                                                                    index);
      }
    }
  std::cout << "Last index: " << index << std::endl;
}

template <class TImage>
void ComputeOffset(TImage *image, unsigned int count, unsigned int repeat)
{
  typename TImage::OffsetValueType offset = 0;
  typename TImage::OffsetValueType accum = 0;
  typename TImage::IndexType index;
  typename TImage::OffsetType indexIncr;
  indexIncr.Fill(1);

  for (unsigned j = 0; j < repeat; j++)
    {
    index.Fill(0);
    for (unsigned int i = 0; i < count; i++)
      {
      
      offset = image->ComputeOffset (index);
      accum += offset;
      index += indexIncr;
      }
    }<commit_msg>COMP: index is filled with 0 values (warning on gcc 4.4.4).<commit_after>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    itkImageComputeOffsetAndIndexTest.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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.

=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include <iostream>
#define ITK_LEAN_AND_MEAN

#include "itkImage.h"
#include "itkImageHelper.h"
#include "itkTimeProbesCollectorBase.h"

template <class TImage>
void ComputeIndex(TImage *image, unsigned int count, unsigned int repeat)
{
  typename TImage::IndexType index;
  for (unsigned j = 0; j < repeat; j++)
    {
    for (unsigned int i = 0; i < count; i++)
      {
      index = image->ComputeIndex (i);
      }
    }
  std::cout << "Last index: " << index << std::endl;
}

template <class TImage>
void ComputeFastIndex(TImage *image, unsigned int count, unsigned int repeat)
{
  typename TImage::IndexType index;
  index.Fill( 0 );
  const typename TImage::IndexType &bufferedRegionIndex = image->GetBufferedRegion().GetIndex();
  const typename TImage::OffsetValueType *offsetTable = image->GetOffsetTable();
  
  for (unsigned int j = 0; j < repeat; j++)
    {
    for (unsigned int i = 0; i < count; i++)
      {
      itk::ImageHelper<TImage::ImageDimension,TImage::ImageDimension>::ComputeIndex(bufferedRegionIndex,
        i,
        offsetTable,
        index);
      }
    }
  std::cout << "Last index: " << index << std::endl;
}

template <class TImage>
void ComputeOffset(TImage *image, unsigned int count, unsigned int repeat)
{
  typename TImage::OffsetValueType offset = 0;
  typename TImage::OffsetValueType accum = 0;
  typename TImage::IndexType index;
  typename TImage::OffsetType indexIncr;
  indexIncr.Fill(1);

  for (unsigned j = 0; j < repeat; j++)
    {
    index.Fill(0);
    for (unsigned int i = 0; i < count; i++)
      {
      
      offset = image->ComputeOffset (index);
      accum += offset;
      index += indexIncr;
      }
    }
{'fraction_non_alphanumeric': 0.15937803692905733, 'fraction_numerical': 0.00641399416909621, 'mean_word_length': 3.0712025316455698, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2888697', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1419, 'n_words': 434}