Example #1
0
void multi_img::setBand(unsigned int band, const Band &data,
						const Mask &mask)
{
	assert(band < size());
	assert(data.rows == height && data.cols == width);
	Band &b = bands[band];
	BandConstIt bit = b.begin();
	MaskConstIt dit = dirty.begin();
	/* we use opencv to copy the band data. afterwards, we update the pixels
	   cache. we do this only for pixels, which are not dirty yet (and would
	   need a complete rebuild anyways. As we instantly fix the other pixels,
	   those do not get marked as dirty by us. */
	if (!mask.empty()) {
		assert(mask.rows == height && mask.cols == width);
		MaskConstIt mit = mask.begin();
		data.copyTo(b, mask);
		for (int i = 0; bit != b.end(); ++bit, ++dit, ++mit, ++i)
			if ((*mit > 0)&&(*dit == 0))
				pixels[i][band] = *bit;
	} else {
		data.copyTo(b);
		for (int i = 0; bit != b.end(); ++bit, ++dit, ++i) {
			if ((*dit == 0))
				pixels[i][band] = *bit;
		}
	}
}
Example #2
0
	void move(const FUNC& func) const
	{
		static_assert(std::is_convertible<FUNC, std::function<void(const State&)>>::value, "func must be callable with a 'const State&' parameter.");
		const Mask mask = toMask();
		
		for(int i = 0; i < kBlocks; ++i)
		{
			Block b = blocks_[i];
			
			if(b.top > 0 && mask.empty(b.top - 1, b.left) && mask.empty(b.top - 1, b.right()))
			{
				State next = *this;
				next.step++;
				next.blocks_[i].top--;
				func(next);
			}
			
			if(b.bottom() < kRows - 1 && mask.empty(b.bottom() + 1, b.left) && mask.empty(b.bottom() + 1, b.right()))
			{
				State next = *this;
				next.step++;
				next.blocks_[i].top++;
				func(next);
			}
			
			if(b.left > 0 && mask.empty(b.top, b.left - 1) && mask.empty(b.bottom(), b.left - 1))
			{
				State next = *this;
				next.step++;
				next.blocks_[i].left--;
				func(next);
			}
			
			if(b.right() < kColumns - 1 && mask.empty(b.top, b.right() + 1) && mask.empty(b.bottom(), b.right() + 1))
			{
				State next = *this;
				next.step++;
				next.blocks_[i].left++;
				func(next);
			}
		}
	}