<commit_before>#include "ImageCropper.hpp"
#include "FAST/Data/Image.hpp"

namespace fast {


void ImageCropper::setOffset(VectorXi offset) {
    mOffset.x() = offset.x();
    mOffset.y() = offset.y();
    if(offset.size() > 2) {
        mOffset.z() = offset.z();
    } else {
        mOffset.z() = 0;
    }
}

void ImageCropper::setSize(VectorXi size) {
    mSize.x() = size.x();
    mSize.y() = size.y();
    if(size.size() > 2) {
        mSize.z() = size.z();
    } else {
        mSize.z() = 1;
    }
}

ImageCropper::ImageCropper() {
    createInputPort<Image>(0);
    createOutputPort<Image>(0);

    mSize = Vector3i::Zero();
    mOffset = Vector3i::Zero();
    mAllowOutOfBoundsCropping = false;
    mCropBottom = 0;
    mCropTop = 0;
}

void ImageCropper::execute() {
    Image::pointer input = getInputData<Image>();
    Vector3i size = mSize;
    Vector3i offset = mOffset;
    if(size == Vector3i::Zero()) {
        if(mCropTop > 0) {
            size = input->getSize().cast<int>();
            size.y() = (int)std::floor(size.y()*mCropTop);
        } else if(mCropBottom > 0) {
            size = input->getSize().cast<int>();
            offset.y() = (int)std::floor(size.y()*(1.0f - mCropBottom));
            size.y() = (int)std::floor(size.y()*mCropBottom);
        }
    }

    Image::pointer output = input->crop(offset, size, mAllowOutOfBoundsCropping);
    addOutputData(0, output);
}
<commit_msg>Added 3D support to crop top/bottom in ImageCropper<commit_after>#include "ImageCropper.hpp"
#include "FAST/Data/Image.hpp"

namespace fast {


void ImageCropper::setOffset(VectorXi offset) {
    mOffset.x() = offset.x();
    mOffset.y() = offset.y();
    if(offset.size() > 2) {
        mOffset.z() = offset.z();
    } else {
        mOffset.z() = 0;
    }
}

void ImageCropper::setSize(VectorXi size) {
    mSize.x() = size.x();
    mSize.y() = size.y();
    if(size.size() > 2) {
        mSize.z() = size.z();
    } else {
        mSize.z() = 1;
    }
}

ImageCropper::ImageCropper() {
    createInputPort<Image>(0);
    createOutputPort<Image>(0);

    mSize = Vector3i::Zero();
    mOffset = Vector3i::Zero();
    mAllowOutOfBoundsCropping = false;
    mCropBottom = 0;
    mCropTop = 0;
}

void ImageCropper::execute() {
    Image::pointer input = getInputData<Image>();
    Vector3i size = mSize;
    Vector3i offset = mOffset;
    if(size == Vector3i::Zero()) {
        if(mCropTop > 0) {
            size = input->getSize().cast<int>();
            if(input->getDimensions() == 2) {
                size.y() = (int) std::floor(size.y() * mCropTop);
            } else {
                size.z() = (int) std::floor(size.z() * mCropTop);
            }
        } else if(mCropBottom > 0) {
            size = input->getSize().cast<int>();
            if(input->getDimensions() == 2) {
                offset.y() = (int) std::floor(size.y() * (1.0f - mCropBottom));
                size.y() = (int) std::floor(size.y() * mCropBottom);
            } else {
                offset.z() = (int) std::floor(size.z() * (1.0f - mCropBottom));
                size.z() = (int) std::floor(size.z() * mCropBottom);
            }
        }
    }

    Image::pointer output = input->crop(offset, size, mAllowOutOfBoundsCropping);
    addOutputData(0, output);
}

{'fraction_non_alphanumeric': 0.18204031765424558, 'fraction_numerical': 0.012522907758094075, 'mean_word_length': 2.3762886597938144, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 29, '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': '3744500', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1163, 'n_words': 198}