<commit_before>/*
 *  qikfilter.cpp
 *
 *  Copyright (c) 2015 <NAME>.
 *
 *  This Source Code Form is subject to the terms of the Mozilla Public
 *  License, v. 2.0. If a copy of the MPL was not distributed with this
 *  file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 */

#include <memory>
#include <getopt.h>
#include <iostream>
#include <sstream>
#include "Eigen/Dense"

#include "itkImageSource.h"
#include "itkConstNeighborhoodIterator.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "itkMultiplyImageFilter.h"
#include "itkDivideImageFilter.h"
#include "itkComplexToComplexFFTImageFilter.h"
#include "itkInverseFFTImageFilter.h"
#include "itkFFTShiftImageFilter.h"
#include "itkComplexToModulusImageFilter.h"
#include "itkFFTPadImageFilter.h"
#include "itkConstantPadImageFilter.h"
#include "itkExtractImageFilter.h"
#include "itkPasteImageFilter.h"
#include "itkCastImageFilter.h"

#include "QI/Types.h"
#include "QI/Util.h"
#include "QI/Kernels.h"
#include "QI/IO.h"

using namespace std;
using namespace Eigen;

namespace itk {

template<typename TImage>
class KernelSource : public ImageSource<TImage> {
public:
    typedef TImage                 ImageType;
    typedef KernelSource           Self;
    typedef ImageSource<ImageType> Superclass;
    typedef SmartPointer<Self>     Pointer;
    typedef typename ImageType::RegionType     RegionType;
    typedef typename ImageType::IndexType      IndexType;
    typedef typename ImageType::SizeType       SizeType;
    typedef typename ImageType::SpacingType    SpacingType;
    typedef typename ImageType::DirectionType  DirectionType;
    typedef typename ImageType::PointType      PointType;

protected:
    KernelSource(){}
    ~KernelSource(){}
    RegionType    m_Region;
    SpacingType   m_Spacing;
    DirectionType m_Direction;
    PointType     m_Origin;
    std::vector<std::shared_ptr<QI::FilterKernel>> m_kernels;

public:
    itkNewMacro(Self);
    itkTypeMacro(Self, ImageSource);
    void SetKernels(const std::vector<std::shared_ptr<QI::FilterKernel>> &k) { m_kernels = k; }
    itkSetMacro(Region, RegionType);
    itkSetMacro(Spacing, SpacingType);
    itkSetMacro(Direction, DirectionType);
    itkSetMacro(Origin, PointType);

protected:
    virtual void GenerateOutputInformation() ITK_OVERRIDE {
        auto output = this->GetOutput(0);
        output->SetLargestPossibleRegion(m_Region);
        output->SetSpacing(m_Spacing);
        output->SetDirection(m_Direction);
        output->SetOrigin(m_Origin);
    }

    virtual void ThreadedGenerateData(const RegionType &region, ThreadIdType threadId) ITK_OVERRIDE {
        const auto startIndex = m_Region.GetIndex();
        const Eigen::Array3d sz{m_Region.GetSize()[0], m_Region.GetSize()[1], m_Region.GetSize()[2]};
        const Eigen::Array3d hsz = sz / 2;
        const Eigen::Array3d sp{m_Spacing[0], m_Spacing[1], m_Spacing[2]};
        itk::ImageRegionIterator<ImageType> outIt(this->GetOutput(), m_Region);
        outIt.GoToBegin();
        while(!outIt.IsAtEnd()) {
            const auto I = outIt.GetIndex() - startIndex; // Might be padded to a negative start
            const double x = fmod(static_cast<double>(I[0]) + hsz[0], sz[0]) - hsz[0];
            const double y = fmod(static_cast<double>(I[1]) + hsz[1], sz[1]) - hsz[1];
            const double z = fmod(static_cast<double>(I[2]) + hsz[2], sz[2]) - hsz[2];
            const Eigen::Array3d p{x, y, z};
            typename ImageType::PixelType val = 1;<commit_msg>BUG: Fixed narrowing warning.<commit_after>/*
 *  qikfilter.cpp
 *
 *  Copyright (c) 2015 <NAME>.
 *
 *  This Source Code Form is subject to the terms of the Mozilla Public
 *  License, v. 2.0. If a copy of the MPL was not distributed with this
 *  file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 */

#include <memory>
#include <getopt.h>
#include <iostream>
#include <sstream>
#include "Eigen/Dense"

#include "itkImageSource.h"
#include "itkConstNeighborhoodIterator.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "itkMultiplyImageFilter.h"
#include "itkDivideImageFilter.h"
#include "itkComplexToComplexFFTImageFilter.h"
#include "itkInverseFFTImageFilter.h"
#include "itkFFTShiftImageFilter.h"
#include "itkComplexToModulusImageFilter.h"
#include "itkFFTPadImageFilter.h"
#include "itkConstantPadImageFilter.h"
#include "itkExtractImageFilter.h"
#include "itkPasteImageFilter.h"
#include "itkCastImageFilter.h"

#include "QI/Types.h"
#include "QI/Util.h"
#include "QI/Kernels.h"
#include "QI/IO.h"

using namespace std;
using namespace Eigen;

namespace itk {

template<typename TImage>
class KernelSource : public ImageSource<TImage> {
public:
    typedef TImage                 ImageType;
    typedef KernelSource           Self;
    typedef ImageSource<ImageType> Superclass;
    typedef SmartPointer<Self>     Pointer;
    typedef typename ImageType::RegionType     RegionType;
    typedef typename ImageType::IndexType      IndexType;
    typedef typename ImageType::SizeType       SizeType;
    typedef typename ImageType::SpacingType    SpacingType;
    typedef typename ImageType::DirectionType  DirectionType;
    typedef typename ImageType::PointType      PointType;

protected:
    KernelSource(){}
    ~KernelSource(){}
    RegionType    m_Region;
    SpacingType   m_Spacing;
    DirectionType m_Direction;
    PointType     m_Origin;
    std::vector<std::shared_ptr<QI::FilterKernel>> m_kernels;

public:
    itkNewMacro(Self);
    itkTypeMacro(Self, ImageSource);
    void SetKernels(const std::vector<std::shared_ptr<QI::FilterKernel>> &k) { m_kernels = k; }
    itkSetMacro(Region, RegionType);
    itkSetMacro(Spacing, SpacingType);
    itkSetMacro(Direction, DirectionType);
    itkSetMacro(Origin, PointType);

protected:
    virtual void GenerateOutputInformation() ITK_OVERRIDE {
        auto output = this->GetOutput(0);
        output->SetLargestPossibleRegion(m_Region);
        output->SetSpacing(m_Spacing);
        output->SetDirection(m_Direction);
        output->SetOrigin(m_Origin);
    }

    virtual void ThreadedGenerateData(const RegionType &region, ThreadIdType threadId) ITK_OVERRIDE {
        const auto startIndex = m_Region.GetIndex();
        const Eigen::Array3d sz{static_cast<double>(m_Region.GetSize()[0]),
                                static_cast<double>(m_Region.GetSize()[1]),
                                static_cast<double>(m_Region.GetSize()[2])};
        const Eigen::Array3d hsz = sz / 2;
        const Eigen::Array3d sp{m_Spacing[0], m_Spacing[1], m_Spacing[2]};
        itk::ImageRegionIterator<ImageType> outIt(this->GetOutput(), m_Region);
        outIt.GoToBegin();
        while(!outIt.IsAtEnd()) {
            const auto I = outIt.GetIndex() - startIndex; // Might be padded to a negative start
            const double x = fmod(static_cast<double>(I[0]) + hsz[0], sz[0]) - hsz[0];
            const double y = fmod(static_cast<double>(I[1]) + hsz[1], sz[1]) - hsz[1];
            const double z = fmod(static_cast<double>(I[2]) + hsz[2], sz[2]) - hsz[2];
            const Eigen::Array3d p{x, y, z};
            typename ImageType::PixelType val = 1;
{'fraction_non_alphanumeric': 0.11669231845529593, 'fraction_numerical': 0.00923464390653421, 'mean_word_length': 3.7940979208584844, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 52, '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': '1263140', 'n_tokens_mistral': 2391, 'n_tokens_neox': 2308, 'n_words': 510}