Commit 98eecaa950c3e4b2d2b71f2a145c5c67379dab46

Authored by David Mayerich
1 parent 6f99700e

VS and win32 updates

stim/cuda/cuda_texture.cuh
... ... @@ -7,7 +7,7 @@
7 7 #include <cuda_runtime.h>
8 8 #include <cublas_v2.h>
9 9 #include <stdio.h>
10   -#include <GL/glew.h>
  10 +//#include <GL/glew.h>
11 11 #include <GL/glut.h>
12 12 #include <sstream>
13 13 #include <stim/visualization/colormap.h>
... ...
stim/cuda/cudatools/glbind.h
1 1 #ifndef RTS_GL_BIND_H
2 2 #define RTS_GL_BIND_H
3 3  
4   -#include <GL/glew.h>
5   -#include <GL/gl.h>
  4 +//#include <GL/glew.h>
  5 +#include <GL/GL.h>
  6 +#include <GL/GLU.h>
6 7  
7 8 #include <stdio.h>
8 9 #include <cstring>
... ... @@ -18,12 +19,12 @@ static void InitGLEW()
18 19 {
19 20 //Initialize the GLEW toolkit
20 21  
21   - GLenum err = glewInit();
  22 + /*GLenum err = glewInit();
22 23 if(GLEW_OK != err)
23 24 {
24 25 printf("Error starting GLEW.");
25 26 }
26   - fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
  27 + fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));*/
27 28 }
28 29  
29 30 static void cudaSetDevice(int major = 1, int minor = 3)
... ...
stim/gl/gl_spider.h
1 1 #ifndef STIM_GL_SPIDER_H
2 2 #define STIM_GL_SPIDER_H
3 3  
4   -#include <GL/glew.h>
  4 +//#include <GL/glew.h>
5 5 #include <GL/glut.h>
6 6 #include <cuda.h>
7 7 #include <cuda_gl_interop.h>
... ... @@ -55,13 +55,13 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
55 55 private:
56 56  
57 57 #ifdef TIMING
58   - double branch_time = 0;
59   - double direction_time = 0;
60   - double position_time = 0;
61   - double size_time = 0;
62   - double cost_time = 0;
63   - double network_time = 0;
64   - double hit_time = 0;
  58 + double branch_time;// = 0;
  59 + double direction_time;// = 0;
  60 + double position_time;// = 0;
  61 + double size_time;// = 0;
  62 + double cost_time;// = 0;
  63 + double network_time;// = 0;
  64 + double hit_time;// = 0;
65 65 #endif
66 66  
67 67 //
... ... @@ -99,7 +99,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
99 99 int numSamplesPos;
100 100 int numSamplesMag;
101 101  
102   - float stepsize = 5.0; //Step size.
  102 + float stepsize;// = 5.0; //Step size.
103 103 // float stepsize = 3.0; //Step size.
104 104 int current_cost; //variable to store the cost of the current step.
105 105  
... ... @@ -121,8 +121,8 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
121 121 stim::vec3<float> ups;
122 122 stim::vec3<float> ds;
123 123  
124   - static const float t_length = 16.0;
125   -
  124 + //static const float t_length = 16.0;
  125 + float t_length;
126 126  
127 127 //cuda texture variables that keep track of the binding.
128 128 stim::cuda::cuda_texture t_dir;
... ... @@ -929,6 +929,18 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
929 929 void
930 930 attachSpider(GLuint id)
931 931 {
  932 +#ifdef TIMING
  933 + branch_time = 0;
  934 + direction_time = 0;
  935 + position_time = 0;
  936 + size_time = 0;
  937 + cost_time = 0;
  938 + network_time = 0;
  939 + hit_time = 0;
  940 +#endif
  941 + stepsize = 3.0;
  942 + t_length = 16.0;
  943 +
932 944 srand(100);
933 945 texID = id;
934 946 //GenerateFBO(16, numSamples*8);
... ...
stim/math/circle.h
... ... @@ -5,6 +5,7 @@
5 5 #include <stim/math/plane.h>
6 6 #include <stim/math/vector.h>
7 7 #include <stim/math/triangle.h>
  8 +#include <stim/math/constants.h>
8 9 #include <assert.h>
9 10 #include <algorithm>
10 11 #include <iostream>
... ... @@ -153,8 +154,8 @@ public:
153 154 float step = 360.0/(float) n;
154 155 for(float j = 0; j <= 360.0; j += step)
155 156 {
156   - y = 0.5*cos(j*2.0*M_PI/360.0)+0.5;
157   - x = 0.5*sin(j*2.0*M_PI/360.0)+0.5;
  157 + y = 0.5*cos(j*stim::TAU/360.0)+0.5;
  158 + x = 0.5*sin(j*stim::TAU/360.0)+0.5;
158 159 result.push_back(p(x,y));
159 160 }
160 161 return result;
... ... @@ -167,8 +168,8 @@ public:
167 168 p(T theta)
168 169 {
169 170 T x,y;
170   - y = 0.5*cos(theta*2.0*M_PI/360.0)+0.5;
171   - x = 0.5*sin(theta*2.0*M_PI/360.0)+0.5;
  171 + y = 0.5*cos(theta*stim::TAU/360.0)+0.5;
  172 + x = 0.5*sin(theta*stim::TAU/360.0)+0.5;
172 173 return p(x,y);
173 174 }
174 175  
... ...
stim/math/complex.h
... ... @@ -11,7 +11,7 @@
11 11  
12 12 namespace stim
13 13 {
14   - enum complexComponentType {complexReal, complexImaginary, complexMag};
  14 + enum complexComponentType {complexReal, complexImaginary, complexMag, complexIntensity};
15 15  
16 16 template <class T>
17 17 struct complex
... ... @@ -346,6 +346,13 @@ static void abs(T* m, complex&lt;T&gt;* c, size_t n){
346 346 m[i] = c[i].abs();
347 347 }
348 348  
  349 +/// Calculate the intensity of an array of complex values
  350 +template<typename T>
  351 +static void intensity(T* m, complex<T>* c, size_t n){
  352 + for(size_t i = 0; i < n; i++)
  353 + m[i] = pow(c[i].abs(), 2);
  354 +}
  355 +
349 356 } //end RTS namespace
350 357  
351 358 //addition
... ...
stim/optics/scalarfield.h
... ... @@ -291,6 +291,8 @@ public:
291 291  
292 292 /// Propagate the field along its orthogonal direction by a distance d
293 293 void propagate(T d, T k){
  294 + //X[2] += d; //move the plane position along the propagation direction
  295 + //Y[2] += d;
294 296 cpu_scalar_propagate(E, E, X.len(), Y.len(), d, k, R[0], R[1]);
295 297 }
296 298  
... ... @@ -299,6 +301,35 @@ public:
299 301 cpu_scalar_lowpass(E, E, X.len(), Y.len(), highest, R[0], R[1]);
300 302 }
301 303  
  304 + /// Crop an image based on a given padding parameter (crop out the center)
  305 + void crop(size_t padding, stim::scalarfield<T>& cropped){
  306 + size_t Cx = R[0] / (2 * padding + 1); //calculate the size of the cropped image based on the padding value
  307 + size_t Cy = R[1] / (2 * padding + 1);
  308 +
  309 + if(cropped.R[0] != Cx || cropped.R[1] != Cy){
  310 + std::cout<<"Error: cropped field resolution ("<<cropped.R[0]<<" x "<<cropped.R[1]<<") does not match the required resolution ("<<Cx<<" x "<<Cy<<")."<<std::endl;
  311 + exit(1);
  312 + }
  313 +
  314 + if(loc == CPUmem){
  315 + size_t x, y;
  316 + size_t sx, sy, si, di;
  317 + for(y = 0; y < Cy; y++){
  318 + sy = y + Cy * padding; //calculate the y-index into the source image
  319 + for(x = 0; x < Cx; x++){
  320 + sx = x + Cx * padding; //calculate the x-index into the source image
  321 + si = sy * R[0] + sx; //calculate the 1D index into the source image
  322 + di = y * Cx + x;
  323 + cropped.E[di] = E[si];
  324 + }
  325 + }
  326 + }
  327 + else{
  328 + std::cout<<"Error: cropping not supported for GPU memory yet."<<std::endl;
  329 + exit(1);
  330 + }
  331 + }
  332 +
302 333 std::string str(){
303 334 std::stringstream ss;
304 335 ss<<rect<T>::str()<<std::endl;
... ... @@ -367,11 +398,49 @@ public:
367 398 break;
368 399 case complexImaginary:
369 400 stim::imag(image, E, size());
  401 + break;
  402 + case complexIntensity:
  403 + stim::intensity(image, E, size());
  404 + break;
370 405 }
371 406 stim::cpu2image(image, filename, R[0], R[1], cmap); //save the resulting image
372 407 free(image); //free the real image
373 408 }
374 409  
  410 + void image(T* img, stim::complexComponentType type = complexMag){
  411 + if(loc == GPUmem) to_cpu(); //if the field is in the GPU, move it to the CPU
  412 +
  413 + switch(type){ //get the specified component from the complex value
  414 + case complexMag:
  415 + stim::abs(img, E, size());
  416 + break;
  417 + case complexReal:
  418 + stim::real(img, E, size());
  419 + break;
  420 + case complexImaginary:
  421 + stim::imag(img, E, size());
  422 + break;
  423 + case complexIntensity:
  424 + stim::intensity(img, E, size());
  425 + break;
  426 + }
  427 + //stim::cpu2image(image, filename, R[0], R[1], cmap); //save the resulting image
  428 + //free(image); //free the real image
  429 + }
  430 +
  431 + //adds the field intensity to the output array (useful for calculating detector response to incoherent fields)
  432 + void intensity(T* out){
  433 + if(loc == GPUmem) to_cpu(); //if the field is in the GPU, move it to the CPU
  434 + T* image = (T*) malloc( sizeof(T) * size() ); //allocate space for the real image
  435 + stim::intensity(image, E, size()); //calculate the intensity
  436 +
  437 + size_t N = size(); //calculate the number of elements in the field
  438 + for(size_t n = 0; n < N; n++) //for each point in the field
  439 + out[n] += image[n]; //add the field intensity to the output image
  440 +
  441 + free(image); //free the temporary intensity image
  442 + }
  443 +
375 444 }; //end class scalarfield
376 445 }
377 446  
... ...
stim/visualization/cylinder.h
... ... @@ -203,8 +203,10 @@ class cylinder
203 203 T
204 204 r(T pvalue)
205 205 {
206   - if(pvalue < 0.0 || pvalue > 1.0)
207   - return;
  206 + if(pvalue < 0.0 || pvalue > 1.0){
  207 + std::cerr<<"Error, value "<<pvalue<<" is outside of [0 1]."<<std::endl;
  208 + exit(1);
  209 + }
208 210 T l = pvalue*L[L.size()-1];
209 211 int idx = findIdx(l);
210 212 return (e[idx].U.len() + (e[idx+1].U.len() - e[idx].U.len())*((l-L[idx])/(L[idx+1]- L[idx])));
... ...
stim/visualization/glObj.h
1 1 #ifndef STIM_GLOBJ_H
2 2 #define STIM_GLOBJ_H
3 3  
4   -#include <GL/glew.h>
  4 +//#include <GL/glew.h>
5 5 #include <GL/glut.h>
6 6 #include <stim/math/vector.h>
7 7 #include <stim/visualization/obj.h>
... ...