Blame view

sources.h 1.06 KB
8d8c3ebd   David Mayerich   initial commit tr...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  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;
  }