<commit_before>#ifndef IMAGEPROCESSING_EXPLICIT_VOLUME_H__
#define IMAGEPROCESSING_EXPLICIT_VOLUME_H__

#include <vigra/multi_array.hxx>
#include "DiscreteVolume.h"
#include "ImageStack.h"

/**
 * Explicit representation of a discrete volume as a vigra multi-array.
 */
template <typename ValueType>
class ExplicitVolume : public DiscreteVolume {

public:

	typedef ValueType                       value_type;
	typedef vigra::MultiArray<3, ValueType> data_type;

	/**
	 * Create an empty volume.
	 */
	ExplicitVolume() {}

	/**
	 * Create a volume from another (type compatible) volume.
	 */
	template <typename T>
	ExplicitVolume(const ExplicitVolume<T>& other) :
		DiscreteVolume(other),
		_data(other.data()) {}

	/**
	 * Create a volume from an image stack.
	 */
	ExplicitVolume(const ImageStack& stack) :
		DiscreteVolume(stack),
		_data(vigra::Shape3(stack.width(), stack.height(), stack.size())) {

		// fill volume image by image
		for (unsigned int i = 0; i < stack.size(); i++)
			vigra::copyMultiArray(
					*stack[i],
					_data.template bind<2>(i));
	}

	/**
	 * Create a new explicit volume of the given size.
	 */
	ExplicitVolume(
			unsigned int width,
			unsigned int height,
			unsigned int depth) :
		_data(vigra::Shape3(width, height, depth)) {}

	/**
	 * Create a new explicit volume of the given size. Initialize all voxels 
	 * with the given value.
	 */
	ExplicitVolume(
			unsigned int width,
			unsigned int height,
			unsigned int depth,
			const ValueType& value) :
		_data(vigra::Shape3(width, height, depth), value) {}

	/**
	 * Pixel access.
	 */
	ValueType&       operator[](vigra::Shape3 pos)       { return _data[pos]; }
	const ValueType& operator[](vigra::Shape3 pos) const { return _data[pos]; }
	ValueType&       operator()(unsigned int x, unsigned int y, unsigned int z)       { return _data(x, y, z); }
	const ValueType& operator()(unsigned int x, unsigned int y, unsigned int z) const { return _data(x, y, z); }

	/**
	 * Get access to the vigra multi-array that contains the data of this 
	 * volume.
	 */
	data_type&       data()       { return _data; }
	const data_type& data() const { return _data; }

	unsigned int width()  const { return _data.shape()[0]; }
	unsigned int height() const { return _data.shape()[1]; }
	unsigned int depth()  const { return _data.shape()[2]; }

private:

	data_type _data;
};

#endif // IMAGEPROCESSING_EXPLICIT_VOLUME_H__

<commit_msg>added ExplicitVolume::slice() to get image from stack<commit_after>#ifndef IMAGEPROCESSING_EXPLICIT_VOLUME_H__
#define IMAGEPROCESSING_EXPLICIT_VOLUME_H__

#include <vigra/multi_array.hxx>
#include "DiscreteVolume.h"
#include "ImageStack.h"

/**
 * Explicit representation of a discrete volume as a vigra multi-array.
 */
template <typename ValueType>
class ExplicitVolume : public DiscreteVolume {

public:

	typedef ValueType                       value_type;
	typedef vigra::MultiArray<3, ValueType> data_type;

	/**
	 * Create an empty volume.
	 */
	ExplicitVolume() {}

	/**
	 * Create a volume from another (type compatible) volume.
	 */
	template <typename T>
	ExplicitVolume(const ExplicitVolume<T>& other) :
		DiscreteVolume(other),
		_data(other.data()) {}

	/**
	 * Create a volume from an image stack.
	 */
	ExplicitVolume(const ImageStack& stack) :
		DiscreteVolume(stack),
		_data(vigra::Shape3(stack.width(), stack.height(), stack.size())) {

		// fill volume image by image
		for (unsigned int i = 0; i < stack.size(); i++)
			vigra::copyMultiArray(
					*stack[i],
					_data.template bind<2>(i));
	}

	/**
	 * Create a new explicit volume of the given size.
	 */
	ExplicitVolume(
			unsigned int width,
			unsigned int height,
			unsigned int depth) :
		_data(vigra::Shape3(width, height, depth)) {}

	/**
	 * Create a new explicit volume of the given size. Initialize all voxels 
	 * with the given value.
	 */
	ExplicitVolume(
			unsigned int width,
			unsigned int height,
			unsigned int depth,
			const ValueType& value) :
		_data(vigra::Shape3(width, height, depth), value) {}

	/**
	 * Pixel access.
	 */
	ValueType&       operator[](vigra::Shape3 pos)       { return _data[pos]; }
	const ValueType& operator[](vigra::Shape3 pos) const { return _data[pos]; }
	ValueType&       operator()(unsigned int x, unsigned int y, unsigned int z)       { return _data(x, y, z); }
	const ValueType& operator()(unsigned int x, unsigned int y, unsigned int z) const { return _data(x, y, z); }

	/**
	 * 2D z-slice access.
	 */
	Image slice(int z) {

		vigra::MultiArrayView<2, ValueType> slice = _data.template bind<2>(z);

		Image image;
		image = slice;
		image.setResolution(
				getResolutionX(),
				getResolutionY(),
				getResolutionZ());
		image.setBoundingBox(
				BoundingBox(
						getBoundingBox().getMinX(),
						getBoundingBox().getMinY(),
						getBoundingBox().getMinZ() + z*getResolutionZ(),
						getBoundingBox().getMaxX(),
						getBoundingBox().getMaxY(),
						getBoundingBox().getMinZ() + (z+1)*getResolutionZ()));

		return image;
	}

	/**
	 * Get access to the vigra multi-array that contains the data of this 
	 * volume.
	 */
	data_type&       data()       { return _data; }
	const data_type& data() const { return _data; }

	unsigned int width()  const { return _data.shape()[0]; }
	unsigned int height() const { return _data.shape()[1]; }
	unsigned int depth()  const { return _data.shape()[2]; }

private:

	data_type _data;
};

#endif // IMAGEPROCESSING_EXPLICIT_VOLUME_H__


{'fraction_non_alphanumeric': 0.1289134438305709, 'fraction_numerical': 0.004788213627992633, 'mean_word_length': 3.5754001684919965, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, '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': '2078841', 'n_tokens_mistral': 1949, 'n_tokens_neox': 1754, 'n_words': 501}