sources.h 1.06 KB
template<typename T>
std::vector< stim::vec3<T> > simage(T size, std::string imagefile) {
	std::vector< stim::vec3<T> > sources;

	stim::image<unsigned char> src(imagefile);

	float xmin = -size / 2;
	float ymin = -size / 2;

	size_t xi, yi;
	float xa, ya;
	for (yi = 0; yi < src.height(); yi++) {
		for (xi = 0; xi < src.width(); xi++) {
			if (src(xi, yi)) {
				xa = (float)xi / (float)(src.width() - 1);
				ya = (float)yi / (float)(src.height() - 1);

				sources.push_back(stim::vec3<float>(xa * size + xmin, ya * size + ymin, 0));

			}
		}
	}

	return sources;
}

template<typename T>
std::vector< stim::vec3<T> > sgrid(T size, unsigned int n, unsigned int m = 0) {
	std::vector< stim::vec3<T> > sources;

	if (m == 0) m = n;

	float xmin = -size / 2 + size/(n + 1);
	float ymin = -size / 2 + size/(m + 1);

	size_t xi, yi;
	float xa, ya;
	for (yi = 0; yi < m; yi++) {
		for (xi = 0; xi < n; xi++) {
				xa = (float)xi / (float)(n + 1);
				ya = (float)yi / (float)(m + 1);

				sources.push_back(stim::vec3<float>(xa * size + xmin, ya * size + ymin, 0));
		}
	}

	return sources;
}