Blame view

fileout.cu 5.13 KB
3f56f1f9   dmayerich   initial commit
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
  #include "fileout.h"
  //#include "scalarfield.h"

  

  

  /*void fileoutStruct::saveMag(fieldslice* U, std::string filename, rts::colormap::colormapType cmap)

  {
      int Rx = U->R[0];
      int Ry = U->R[1];
  

  	//allocate space for a scalar field on the GPU

  	ptype* gpuScalar;

  	int memsize = sizeof(ptype) * Rx * Ry;

  	HANDLE_ERROR(cudaMalloc((void**) &gpuScalar, memsize));
  	HANDLE_ERROR(cudaMemset(gpuScalar, 0, memsize));

  	U->Mag(gpuScalar);

  
  

  	rts::colormap::gpu2image<ptype>(gpuScalar, filename, Rx, Ry, 0, colorMax, cmap);

  

  	HANDLE_ERROR(cudaFree(gpuScalar));

  }
  
  void fileoutStruct::saveReal_scalar(fieldslice* U, std::string filename, rts::colormap::colormapType cmap)

  {

  	//returns the real component

  	scalarslice sf = U->Real();

  	sf.toImage(filename, false, cmap);

  

  }
  
  void fileoutStruct::saveImag_scalar(fieldslice* U, std::string filename, rts::colormap::colormapType cmap)

  {

  	//returns the imaginary component of a field (assumed scalar)

  	scalarslice sf = U->Imag();

  	sf.toImage(filename, false, cmap);

  }
  
  void fileoutStruct::saveIntensity(fieldslice* U, std::string filename, rts::colormap::colormapType cmap)
  {
  	//get the intensity of the field
      scalarslice sf = U->Intensity();

  	sf.toImage(filename, true, cmap);
  }
  
  void fileoutStruct::saveAngularSpectrum(fieldslice* U, std::string filename, rts::colormap::colormapType cmap)
  {
      ptype* gpuScalar;
      int memsize = sizeof(ptype) * U->R[0] * U->R[1];

  	HANDLE_ERROR(cudaMalloc((void**) &gpuScalar, memsize));
  	HANDLE_ERROR(cudaMemset(gpuScalar, 0, memsize));
  
  	//convert the field slice to its angular spectrum
  	U->toAngularSpectrum();
  
  	//convert the angular spectrum to a scalar field
  	U->Mag(gpuScalar);
  
  	//save the color image
  	rts::colormap::gpu2image<ptype>(gpuScalar, filename, U->R[0], U->R[1], 0, colorMax, cmap);

  

  	HANDLE_ERROR(cudaFree(gpuScalar));
  
  }*/
  
  void fileoutStruct::saveNearField(nearfieldStruct* nf)
  {
      if(nearFile == "") return;
  
      if(field == fieldReal)
      {
          scalarslice S = nf->U.Real();
          S.toImage(nearFile, false, colormap);
      }
      if(field == fieldImag)
      {
          scalarslice S = nf->U.Imag();
          S.toImage(nearFile, false, colormap);
      }
      if(field == fieldMag)
      {
          scalarslice S = nf->U.Mag();
          S.toImage(nearFile, true, colormap);
      }
  }
  
  void fileoutStruct::saveFarField(microscopeStruct* scope)
  {
      if(farFile == "") return;
  
      if(field == fieldReal)
      {
          scalarslice S = scope->Ud.Real();
          S.toImage(farFile, false, colormap);
      }
      if(field == fieldImag)
      {
          scalarslice S = scope->Ud.Imag();
          S.toImage(farFile, false, colormap);
      }
      if(field == fieldMag)
      {
          scalarslice S = scope->Ud.Mag();
          S.toImage(farFile, true, colormap);
      }
  
  }
  
  void fileoutStruct::saveDetector(microscopeStruct* scope)
  {
  	//intensity
      if(intFile != "")
      {
          scalarslice I = scope->getIntensity();
  
          if(is_binary(intFile))
b6179de6   dmayerich   added scripts for...
116
117
118
119
120
121
  		{
  			if(wavenumber)
  				I.toEnvi(intFile, 10000.0f/scope->nf.lambda, append);
  			else
  				I.toEnvi(intFile, scope->nf.lambda, append);
  		}
967e46a1   dmayerich   added spectral sc...
122
123
  		else
  			I.toImage(intFile);
3f56f1f9   dmayerich   initial commit
124
125
126
127
128
129
130
      }
      //absorbance
      if(absFile != "")
      {
          scalarslice I = scope->getAbsorbance();
  
          if(is_binary(absFile))
b6179de6   dmayerich   added scripts for...
131
132
133
134
135
136
          {
  			if(wavenumber)
  				I.toEnvi(absFile, 10000.0f/scope->nf.lambda, append);
  			else
  				I.toEnvi(absFile, scope->nf.lambda, append);
  		}
3f56f1f9   dmayerich   initial commit
137
138
139
140
141
142
143
144
145
          else
              I.toImage(absFile);
      }
      //transmittance
      if(transFile != "")
      {
          scalarslice I = scope->getTransmittance();
  
          if(is_binary(transFile))
b6179de6   dmayerich   added scripts for...
146
147
148
149
150
151
          {
  			if(wavenumber)
  				I.toEnvi(transFile, 10000.0f/scope->nf.lambda, append);
  			else
  				I.toEnvi(transFile, scope->nf.lambda, append);
  		}
3f56f1f9   dmayerich   initial commit
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
          else
              I.toImage(transFile);
      }
  
  }
  
  bool fileoutStruct::is_binary(std::string filename)
  {
      //this function guesses if a file name is binary or a standard image
      //  do this by just testing extensions
  
      //get the extension
      size_t i = filename.find_last_of('.');
  
      //if there is no extension, return true
      if( i == std::string::npos )
          return true;
  
      //otherwise grab the extension
      std::string ext = filename.substr(i+1);
      if(ext == "bmp" ||
         ext == "jpg" ||
         ext == "tif" ||
         ext == "gif" ||
         ext == "png")
         return false;
      else
          return true;
  }
  
  

  

  void fileoutStruct::Save(microscopeStruct* scope)

  {
  	//save images of the fields in the microscope
  
  	//if the user specifies an extended source
51b6469a   dmayerich   added look-up tables
189
  	if(scope->focalPoints.size() > 0)
3f56f1f9   dmayerich   initial commit
190
191
192
193
  	{
  		//simulate the extended source and output the detector image
  		scope->SimulateExtendedSource();
  
51b6469a   dmayerich   added look-up tables
194
195
196
197
198
199
200
201
202
203
  		//saveNearField(&scope->nf);
  		saveFarField(scope);
  
  		//save the detector images
  		saveDetector(scope);
  
  		//simulate scattering for the last point (so that you have a near field image)
  		scope->SimulateScattering();
          saveNearField(&scope->nf);
  
3f56f1f9   dmayerich   initial commit
204
205
206
207
208
209
210
211
212
213
214
215
  	}
  	else
  	{
  		//run the near-field simulation
  		scope->SimulateScattering();
  
  		//output the near field image
  		saveNearField(&scope->nf);
  
  		//run the far-field simulation
  		scope->SimulateImaging();
  
51b6469a   dmayerich   added look-up tables
216
  		//saveNearField(&scope->nf);
3f56f1f9   dmayerich   initial commit
217
218
  		saveFarField(scope);
  
51b6469a   dmayerich   added look-up tables
219
220
221
  		//save the detector images
  		saveDetector(scope);
  
3f56f1f9   dmayerich   initial commit
222
223
  	}
  
51b6469a   dmayerich   added look-up tables
224
  	
3f56f1f9   dmayerich   initial commit
225
226
227
228
229
  
  

  }