20#include <boost/filesystem.hpp>
30 const std::string &imageName,
39 standardDeviation_m(0.0){
41 unsigned short *image =
readFile(fileName, imageName);
69#ifdef TESTLASEREMISSION
78 gsl_histogram2d_pdf_free(
pdf_m);
84 const std::string &imageName) {
85 namespace fs = boost::filesystem;
86 if (!fs::exists(fileName)) {
88 "given file '" + fileName +
"' does not exist");
91 size_t npos = fileName.find_last_of(
'.');
92 std::string ext = fileName.substr(npos + 1);
94 unsigned short *image;
111 unsigned int idx = 0;
112 for (
unsigned int i = 0; i <
sizeX_m; ++ i) {
113 for (
unsigned int j = 0; j <
sizeY_m; ++ j, ++ idx) {
122 const std::string &imageName) {
124 hid_t h5 = H5Fopen(fileName.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
125 hid_t group = H5Gopen2 (h5, imageName.c_str(), H5P_DEFAULT);
129 "given image name '" + imageName +
"' does not exist");
133 hid_t dataSet = H5Dopen2 (group,
"CameraData", H5P_DEFAULT);
137 "data set 'CameraData' does not exist");
140 hid_t dataSetSpace = H5Dget_space(dataSet);
141 H5Sget_simple_extent_dims(dataSetSpace, dim,
nullptr);
142 hid_t filespace = H5Screate_simple(2, dim,
nullptr);
147 hsize_t startHyperslab[] = {0, 0};
150 H5Sselect_hyperslab(filespace, H5S_SELECT_SET, startHyperslab,
nullptr, blockCount,
nullptr);
153 hid_t mem = H5Screate_simple(2, blockCount,
nullptr);
155 H5Dread(dataSet, H5T_NATIVE_USHORT, mem, filespace, H5P_DEFAULT, image);
159 H5Dclose(dataSetSpace);
168 unsigned int col2 =
sizeX_m - 1;
169 for (
unsigned int col1 = 0; col1 < col2; ++ col1, -- col2) {
171 unsigned int pixel1 = col1 *
sizeY_m;
172 unsigned int pixel2 = col2 *
sizeY_m;
173 for (
unsigned int row = 0; row <
sizeY_m; ++ row) {
174 std::swap(image[pixel1 ++], image[pixel2 ++]);
180 for (
unsigned int col = 0; col <
sizeX_m; ++ col) {
182 unsigned int pixel1 = col *
sizeY_m;
183 unsigned int pixel2 = (col + 1) *
sizeY_m - 1;
185 unsigned int row2 =
sizeY_m - 1;
186 for (
unsigned int row1 = 0; row1 < row2; ++ row1, -- row2) {
187 std::swap(image[pixel1 ++], image[pixel2 --]);
194 for (
unsigned int col = 0; col <
sizeX_m; ++ col) {
195 for (
unsigned int row = 0; row <
sizeY_m; ++ row) {
196 unsigned int pixel1 = col *
sizeY_m + row;
197 unsigned int pixel2 = row *
sizeX_m + col;
199 copy[pixel2] = image[pixel1];
203 for (
unsigned int pixel = 0; pixel <
sizeX_m *
sizeY_m; ++ pixel) {
204 image[pixel] = copy[pixel];
215 hsize_t idxNW = idxN - 1, idxNE = idxN + 1;
216 hsize_t idxW = idx - 1, idxE = idx + 1;
218 hsize_t idxSW = idxS - 1, idxSE = idxS + 1;
220 for (hsize_t i = 1; i <
sizeX_m - 1; ++ i) {
221 for (hsize_t j = 1; j <
sizeY_m - 1; ++ j) {
223 if (image[idx] > 0) {
224 if (image[idxNW] == 0 &&
237 ++ idxNW; ++ idxN; ++ idxNE;
238 ++ idxW; ++ idx; ++ idxE;
239 ++ idxSW; ++ idxS; ++ idxSE;
247 unsigned int pixel = 0;
248 for (
unsigned int col = 0; col <
sizeX_m; ++ col) {
249 for(
unsigned int row = 0; row <
sizeY_m; ++ row, ++ pixel) {
250 double val = (double(image[pixel]) / profileMax - intensityCut) / (1.0 - intensityCut);
253 image[pixel] = std::round(val * profileMax);
259 double totalMass = 0.0;
263 unsigned int pixel = 0;
264 for(
unsigned int col = 0; col <
sizeX_m; ++ col) {
265 for(
unsigned int row = 0; row <
sizeY_m; ++ row, ++ pixel) {
266 double val = image[pixel];
284 unsigned int histSizeX =
sizeX_m;
285 unsigned int histSizeY =
sizeY_m;
291 hist2d_m = gsl_histogram2d_alloc(histSizeX, histSizeY);
292 gsl_histogram2d_set_ranges_uniform(
hist2d_m,
293 -histRangeX, histRangeX,
294 -histRangeY, histRangeY);
297 unsigned int pixel = 0;
298 for (
unsigned int col = 0; col <
sizeX_m; ++ col) {
300 x = x + 0.5 * binSizeX;
303 for (
unsigned int row = 0; row <
sizeY_m; ++ row, ++ pixel) {
304 double val = image[pixel];
306 y = y + 0.5 * binSizeY;
310 gsl_histogram2d_accumulate(
hist2d_m, x, y, val);
321 const gsl_rng_type *
T = gsl_rng_default;
324 pdf_m = gsl_histogram2d_pdf_alloc(histSizeX, histSizeY);
329 INFOMSG(
level3 <<
"* **********************************************************************************\n");
334 INFOMSG(
"* **********************************************************************************" <<
endl);
348 for (
unsigned int j = 0; j <
sizeY_m; ++ j) {
349 for (
unsigned int i = 0; i <
sizeX_m; ++ i) {
350 out << image[i *
sizeY_m + j] <<
" ";
361 FILE *fh = std::fopen(fname.c_str(),
"w");
362 gsl_histogram2d_fprintf(fh,
hist2d_m,
"%g",
"%g");
369 "LaserEmissionSampled.dat"
372 std::ofstream fh(fname);
375 for(
int i = 0; i < 1000000; i++) {
377 fh << x <<
"\t" << y <<
"\n";
384 double u = gsl_rng_uniform(
rng_m);
385 double v = gsl_rng_uniform(
rng_m);
386 gsl_histogram2d_pdf_sample(
pdf_m, u, v, &x, &y);
392 unsigned short maxIntensity = 0;
394 for(
unsigned int i = 0; i < numberPixels; i++) {
395 if(image[i] > maxIntensity)
396 maxIntensity = image[i];
Tps< T > sqrt(const Tps< T > &x)
Square root.
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Inform & endl(Inform &inf)
Inform & level3(Inform &inf)
std::string combineFilePath(std::initializer_list< std::string > ilist)
static OpalData * getInstance()
std::string getAuxiliaryOutputDirectory() const
get the name of the the additional data directory
unsigned int getWidth() const
unsigned int getHeight() const
unsigned short getPixel(unsigned int i, unsigned int j) const
void normalizeProfileData(double intensityCut, unsigned short *image)
void getXY(double &x, double &y)
void saveData(const std::string &fname, unsigned short *image)
void fillHistrogram(unsigned short *image)
void flipY(unsigned short *image)
LaserProfile(const std::string &fileName, const std::string &imageName, double intensityCut, short flags)
void flipX(unsigned short *image)
gsl_histogram2d * hist2d_m
unsigned short * readPGMFile(const std::string &fileName)
unsigned short * readFile(const std::string &fileName, const std::string &imageName)
void swapXY(unsigned short *image)
unsigned short getProfileMax(unsigned short *image)
unsigned short * readHDF5File(const std::string &fileName, const std::string &imageName)
Vector_t standardDeviation_m
void computeProfileStatistics(unsigned short *image)
gsl_histogram2d_pdf * pdf_m
void filterSpikes(unsigned short *image)
The base class for all OPAL exceptions.
Vektor< double, 3 > Vector_t