<commit_before>// __BEGIN_LICENSE__
// Copyright (C) 2006-2010 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__


// IntegralImage.h
//
// Provides support for algorithms that evaluate with Integral Images
// such as SURF
#ifndef __VW_INTERESTPOINT_INTEGRALIMAGE_H__
#define __VW_INTERESTPOINT_INTEGRALIMAGE_H__

#include <boost/utility/enable_if.hpp>
#include <vw/Core/FundamentalTypes.h>
#include <vw/Image/ImageView.h>

namespace vw {
namespace ip {

  /// Creates Integral Image
  template <class ViewT>
  inline ImageView<typename PixelChannelType<typename ViewT::pixel_type>::type>
  IntegralImage( ImageViewBase<ViewT> const& source ) {

    typedef typename PixelChannelType<typename ViewT::pixel_type>::type channel_type;

    // Allocating space
    ImageView<channel_type> integral( source.impl().cols()+1, source.impl().rows()+1 );

    typedef typename ImageView<channel_type>::pixel_accessor dst_accessor;
    typedef typename ViewT::pixel_accessor src_accessor;

    // Zero-ing the first row and col
    dst_accessor dest_row = integral.origin();
    *dest_row = 0;
    for ( int i = 1; i < integral.cols(); i++ ) {
      dest_row.next_col();
      *dest_row = 0;
    }
    dest_row = integral.origin();
    for ( int i = 1; i < integral.rows(); i++ ) {
      dest_row.next_row();
      *dest_row = 0;
    }

    // Pointer and pointer offset
    int offset = integral.cols();
    channel_type* p;

    // Now filling in integral image
    dest_row = integral.origin();
    dest_row.advance(1,1);
    src_accessor src_row = source.impl().origin();
    for ( int iy = 0; iy < source.impl().rows(); iy++ ) {
      dst_accessor dest_col = dest_row;
      src_accessor src_col = src_row;
      for ( int ix = 0; ix < source.impl().cols(); ix++ ) {
        p = &(*dest_col);

        // Summing
        *dest_col = pixel_cast<PixelGray<channel_type> >(*src_col).v() + *(p-1) + *(p-offset) - *(p-offset-1);

        dest_col.next_col();
      src_col.next_col();
      }
      dest_row.next_row();
      src_row.next_row();
    }

    return integral;
  }

  /// Integral Block Evaluation
  ///
  /// This is for summing an area of pixels described by integral
  template <class PixelT>
  inline PixelT
  IntegralBlock( ImageView<PixelT> const& integral,
                 Vector2i const& top_left,
                 Vector2i const& bottom_right ) {
    VW_DEBUG_ASSERT(top_left.x() > bottom_right.x() && top_left.y() > bottom_right.y(),
                    vw::ArgumentErr() << "Incorrect input for IntegralBlock.\n");
    VW_DEBUG_ASSERT(top_left.x() < integral.cols(),
                    vw::ArgumentErr() << "x0 out of bounds. "<< integral.cols() <<" : "
                    << top_left << bottom_right << "\n");
    VW_DEBUG_ASSERT(bottom_right.x() < integral.cols(),
                    vw::ArgumentErr() << "x1 out of bounds. "<< integral.cols() <<" : "
                    << top_left << bottom_right << "\n");
    VW_DEBUG_ASSERT(top_left.y() < integral.rows(),
                    vw::ArgumentErr() << "y0 out of bounds. "<< integral.rows() <<" : "
                    << top_left << bottom_right << "\n");
    VW_DEBUG_ASSERT(bottom_right.y() < integral.rows(),
                    vw::ArgumentErr() << "y1 out of bounds. "<< integral.rows() <<" : "
                    << top_left << bottom_right << "\n");

    PixelT result;
    result = integral( top_left.x(), top_left.y() );
    result += integral( bottom_right.x(), bottom_right.y() );
    result -= integral( top_left.x(), bottom_right.y() );
    result -= integral( bottom_right.x(), top_left.y() );

    return result;
  }
<commit_msg>IntergralImage excessive on input requirements<commit_after>// __BEGIN_LICENSE__
// Copyright (C) 2006-2010 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__


// IntegralImage.h
//
// Provides support for algorithms that evaluate with Integral Images
// such as SURF
#ifndef __VW_INTERESTPOINT_INTEGRALIMAGE_H__
#define __VW_INTERESTPOINT_INTEGRALIMAGE_H__

#include <boost/utility/enable_if.hpp>
#include <vw/Core/FundamentalTypes.h>
#include <vw/Image/ImageView.h>

namespace vw {
namespace ip {

  /// Creates Integral Image
  template <class ViewT>
  inline ImageView<typename PixelChannelType<typename ViewT::pixel_type>::type>
  IntegralImage( ImageViewBase<ViewT> const& source ) {

    typedef typename PixelChannelType<typename ViewT::pixel_type>::type channel_type;

    // Allocating space
    ImageView<channel_type> integral( source.impl().cols()+1, source.impl().rows()+1 );

    typedef typename ImageView<channel_type>::pixel_accessor dst_accessor;
    typedef typename ViewT::pixel_accessor src_accessor;

    // Zero-ing the first row and col
    dst_accessor dest_row = integral.origin();
    *dest_row = 0;
    for ( int i = 1; i < integral.cols(); i++ ) {
      dest_row.next_col();
      *dest_row = 0;
    }
    dest_row = integral.origin();
    for ( int i = 1; i < integral.rows(); i++ ) {
      dest_row.next_row();
      *dest_row = 0;
    }

    // Pointer and pointer offset
    int offset = integral.cols();
    channel_type* p;

    // Now filling in integral image
    dest_row = integral.origin();
    dest_row.advance(1,1);
    src_accessor src_row = source.impl().origin();
    for ( int iy = 0; iy < source.impl().rows(); iy++ ) {
      dst_accessor dest_col = dest_row;
      src_accessor src_col = src_row;
      for ( int ix = 0; ix < source.impl().cols(); ix++ ) {
        p = &(*dest_col);

        // Summing
        *dest_col = pixel_cast<PixelGray<channel_type> >(*src_col).v() + *(p-1) + *(p-offset) - *(p-offset-1);

        dest_col.next_col();
      src_col.next_col();
      }
      dest_row.next_row();
      src_row.next_row();
    }

    return integral;
  }

  /// Integral Block Evaluation
  ///
  /// This is for summing an area of pixels described by integral
  template <class PixelT>
  inline PixelT
  IntegralBlock( ImageView<PixelT> const& integral,
                 Vector2i const& top_left,
                 Vector2i const& bottom_right ) {
    VW_DEBUG_ASSERT(top_left.x() < integral.cols(),
                    vw::ArgumentErr() << "x0 out of bounds. "<< integral.cols() <<" : "
                    << top_left << bottom_right << "\n");
    VW_DEBUG_ASSERT(bottom_right.x() < integral.cols(),
                    vw::ArgumentErr() << "x1 out of bounds. "<< integral.cols() <<" : "
                    << top_left << bottom_right << "\n");
    VW_DEBUG_ASSERT(top_left.y() < integral.rows(),
                    vw::ArgumentErr() << "y0 out of bounds. "<< integral.rows() <<" : "
                    << top_left << bottom_right << "\n");
    VW_DEBUG_ASSERT(bottom_right.y() < integral.rows(),
                    vw::ArgumentErr() << "y1 out of bounds. "<< integral.rows() <<" : "
                    << top_left << bottom_right << "\n");

    PixelT result;
    result = integral( top_left.x(), top_left.y() );
    result += integral( bottom_right.x(), bottom_right.y() );
    result -= integral( top_left.x(), bottom_right.y() );
    result -= integral( bottom_right.x(), top_left.y() );

    return result;
  }

{'fraction_non_alphanumeric': 0.14295476288096215, 'fraction_numerical': 0.007380073800738007, 'mean_word_length': 2.7489754098360657, 'pattern_counts': {'":': 0, '<': 145, '<?xml version=': 0, '>': 33, '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': '6871239', 'n_tokens_mistral': 2407, 'n_tokens_neox': 2295, 'n_words': 543}