<commit_before>#include "ImageStackView.h"
#include <util/Logger.h>

static logger::LogChannel imagestackviewlog("imagestackviewlog", "[ImageStackView] ");

ImageStackView::ImageStackView(unsigned int numImages) :
	_painter(boost::make_shared<ImageStackPainter>(numImages)),
	_section(0) {

	registerInput(_stack, "imagestack");
	registerOutput(_painter, "painter");
	registerOutput(_currentImage, "current image");

	_painter.registerForwardSlot(_sizeChanged);
	_painter.registerForwardSlot(_contentChanged);
	_painter.registerForwardCallback(&ImageStackView::onKeyDown, this);
}

void
ImageStackView::updateOutputs() {

	util::rect<double> oldSize = _painter->getSize();

	_painter->setImageStack(_stack);
	_painter->setCurrentSection(_section);

	util::rect<double> newSize = _painter->getSize();

	if (oldSize == newSize) {

		LOG_ALL(imagestackviewlog) << "image size did not change -- sending ContentChanged" << std::endl;

		_contentChanged();

	} else {

		LOG_ALL(imagestackviewlog) << "image size did change -- sending SizeChanged" << std::endl;

		_sizeChanged();
	}

	// prepare current image data
	_currentImageData.reshape(vigra::MultiArray<2, float>::size_type(_stack->width(), _stack->height()));

	// copy current image data
	_currentImageData = *(*_stack)[_section];

	// set content of output
	*_currentImage = _currentImageData;
}

void
ImageStackView::onKeyDown(gui::KeyDown& signal) {

	LOG_ALL(imagestackviewlog) << "got a key down event" << std::endl;

	if (signal.key == gui::keys::A) {

		_section = std::max(0, _section - 1);

		LOG_ALL(imagestackviewlog) << "setting current section to " << _section << std::endl;

		setDirty(_painter);
		setDirty(_currentImage);
	}

	if (signal.key == gui::keys::D) {

		_section = std::min((int)_stack->size() - 1, _section + 1);

		LOG_ALL(imagestackviewlog) << "setting current section to " << _section << std::endl;<commit_msg>bugfix: ImageStackView tried to access empty image stack<commit_after>#include "ImageStackView.h"
#include <util/Logger.h>

static logger::LogChannel imagestackviewlog("imagestackviewlog", "[ImageStackView] ");

ImageStackView::ImageStackView(unsigned int numImages) :
	_painter(boost::make_shared<ImageStackPainter>(numImages)),
	_section(0) {

	registerInput(_stack, "imagestack");
	registerOutput(_painter, "painter");
	registerOutput(_currentImage, "current image");

	_painter.registerForwardSlot(_sizeChanged);
	_painter.registerForwardSlot(_contentChanged);
	_painter.registerForwardCallback(&ImageStackView::onKeyDown, this);
}

void
ImageStackView::updateOutputs() {

	util::rect<double> oldSize = _painter->getSize();

	_painter->setImageStack(_stack);
	_painter->setCurrentSection(_section);

	util::rect<double> newSize = _painter->getSize();

	if (oldSize == newSize) {

		LOG_ALL(imagestackviewlog) << "image size did not change -- sending ContentChanged" << std::endl;

		_contentChanged();

	} else {

		LOG_ALL(imagestackviewlog) << "image size did change -- sending SizeChanged" << std::endl;

		_sizeChanged();
	}

	if (_stack->size() == 0)
		return;

	// prepare current image data
	_currentImageData.reshape(vigra::MultiArray<2, float>::size_type(_stack->width(), _stack->height()));

	// copy current image data
	_currentImageData = *(*_stack)[_section];

	// set content of output
	*_currentImage = _currentImageData;
}

void
ImageStackView::onKeyDown(gui::KeyDown& signal) {

	LOG_ALL(imagestackviewlog) << "got a key down event" << std::endl;

	if (signal.key == gui::keys::A) {

		_section = std::max(0, _section - 1);

		LOG_ALL(imagestackviewlog) << "setting current section to " << _section << std::endl;

		setDirty(_painter);
		setDirty(_currentImage);
	}

	if (signal.key == gui::keys::D) {

		_section = std::min((int)_stack->size() - 1, _section + 1);

		LOG_ALL(imagestackviewlog) << "setting current section to " << _section << std::endl;
{'fraction_non_alphanumeric': 0.15046535677352638, 'fraction_numerical': 0.003360910031023785, 'mean_word_length': 6.191449814126394, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 28, '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': '3356860', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1257, 'n_words': 244}