29 const std::string &imageName,
40 unsigned short *image =
readFile(fileName, imageName);
68#ifdef TESTLASEREMISSION
77 gsl_histogram2d_pdf_free(
pdf_m);
83 const std::string &imageName) {
84 namespace fs = std::filesystem;
85 if (!fs::exists(fileName)) {
87 "given file '" + fileName +
"' does not exist");
90 size_t npos = fileName.find_last_of(
'.');
91 std::string ext = fileName.substr(npos + 1);
93 unsigned short *image;
110 unsigned int idx = 0;
111 for (
unsigned int i = 0; i <
sizeX_m; ++ i) {
112 for (
unsigned int j = 0; j <
sizeY_m; ++ j, ++ idx) {
121 const std::string &imageName) {
123 hid_t h5 = H5Fopen(fileName.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
124 hid_t group = H5Gopen2 (h5, imageName.c_str(), H5P_DEFAULT);
128 "given image name '" + imageName +
"' does not exist");
132 hid_t dataSet = H5Dopen2 (group,
"CameraData", H5P_DEFAULT);
136 "data set 'CameraData' does not exist");
139 hid_t dataSetSpace = H5Dget_space(dataSet);
140 H5Sget_simple_extent_dims(dataSetSpace, dim,
nullptr);
141 hid_t filespace = H5Screate_simple(2, dim,
nullptr);
146 hsize_t startHyperslab[] = {0, 0};
149 H5Sselect_hyperslab(filespace, H5S_SELECT_SET, startHyperslab,
nullptr, blockCount,
nullptr);
152 hid_t mem = H5Screate_simple(2, blockCount,
nullptr);
154 H5Dread(dataSet, H5T_NATIVE_USHORT, mem, filespace, H5P_DEFAULT, image);
158 H5Dclose(dataSetSpace);
167 unsigned int col2 =
sizeX_m - 1;
168 for (
unsigned int col1 = 0; col1 < col2; ++ col1, -- col2) {
170 unsigned int pixel1 = col1 *
sizeY_m;
171 unsigned int pixel2 = col2 *
sizeY_m;
172 for (
unsigned int row = 0; row <
sizeY_m; ++ row) {
173 std::swap(image[pixel1 ++], image[pixel2 ++]);
179 for (
unsigned int col = 0; col <
sizeX_m; ++ col) {
181 unsigned int pixel1 = col *
sizeY_m;
182 unsigned int pixel2 = (col + 1) *
sizeY_m - 1;
184 unsigned int row2 =
sizeY_m - 1;
185 for (
unsigned int row1 = 0; row1 < row2; ++ row1, -- row2) {
186 std::swap(image[pixel1 ++], image[pixel2 --]);
193 for (
unsigned int col = 0; col <
sizeX_m; ++ col) {
194 for (
unsigned int row = 0; row <
sizeY_m; ++ row) {
195 unsigned int pixel1 = col *
sizeY_m + row;
196 unsigned int pixel2 = row *
sizeX_m + col;
198 copy[pixel2] = image[pixel1];
202 for (
unsigned int pixel = 0; pixel <
sizeX_m *
sizeY_m; ++ pixel) {
203 image[pixel] = copy[pixel];
214 hsize_t idxNW = idxN - 1, idxNE = idxN + 1;
215 hsize_t idxW = idx - 1, idxE = idx + 1;
217 hsize_t idxSW = idxS - 1, idxSE = idxS + 1;
219 for (hsize_t i = 1; i <
sizeX_m - 1; ++ i) {
220 for (hsize_t j = 1; j <
sizeY_m - 1; ++ j) {
222 if (image[idx] > 0) {
223 if (image[idxNW] == 0 &&
236 ++ idxNW; ++ idxN; ++ idxNE;
237 ++ idxW; ++ idx; ++ idxE;
238 ++ idxSW; ++ idxS; ++ idxSE;
246 unsigned int pixel = 0;
247 for (
unsigned int col = 0; col <
sizeX_m; ++ col) {
248 for(
unsigned int row = 0; row <
sizeY_m; ++ row, ++ pixel) {
249 double val = (double(image[pixel]) / profileMax - intensityCut) / (1.0 - intensityCut);
251 val = std::max(0.0, val);
252 image[pixel] = std::round(val * profileMax);
258 double totalMass = 0.0;
262 unsigned int pixel = 0;
263 for(
unsigned int col = 0; col <
sizeX_m; ++ col) {
264 for(
unsigned int row = 0; row <
sizeY_m; ++ row, ++ pixel) {
265 double val = image[pixel];
283 unsigned int histSizeX =
sizeX_m;
284 unsigned int histSizeY =
sizeY_m;
290 hist2d_m = gsl_histogram2d_alloc(histSizeX, histSizeY);
291 gsl_histogram2d_set_ranges_uniform(
hist2d_m,
292 -histRangeX, histRangeX,
293 -histRangeY, histRangeY);
296 unsigned int pixel = 0;
297 for (
unsigned int col = 0; col <
sizeX_m; ++ col) {
299 x = x + 0.5 * binSizeX;
302 for (
unsigned int row = 0; row <
sizeY_m; ++ row, ++ pixel) {
303 double val = image[pixel];
305 y = y + 0.5 * binSizeY;
309 gsl_histogram2d_accumulate(
hist2d_m, x, y, val);
320 const gsl_rng_type *T = gsl_rng_default;
321 rng_m = gsl_rng_alloc(T);
323 pdf_m = gsl_histogram2d_pdf_alloc(histSizeX, histSizeY);
328 INFOMSG(
level3 <<
"* **********************************************************************************\n");
333 INFOMSG(
"* **********************************************************************************" <<
endl);
343 out <<
"P2" << std::endl;
347 for (
unsigned int j = 0; j <
sizeY_m; ++ j) {
348 for (
unsigned int i = 0; i <
sizeX_m; ++ i) {
349 out << image[i *
sizeY_m + j] <<
" ";
360 FILE *fh = std::fopen(fname.c_str(),
"w");
361 gsl_histogram2d_fprintf(fh,
hist2d_m,
"%g",
"%g");
368 "LaserEmissionSampled.dat"
371 std::ofstream fh(fname);
374 for(
int i = 0; i < 1000000; i++) {
376 fh << x <<
"\t" << y <<
"\n";
383 double u = gsl_rng_uniform(
rng_m);
384 double v = gsl_rng_uniform(
rng_m);
385 gsl_histogram2d_pdf_sample(
pdf_m, u, v, &x, &y);
391 unsigned short maxIntensity = 0;
393 for(
unsigned int i = 0; i < numberPixels; i++) {
394 if(image[i] > maxIntensity)
395 maxIntensity = image[i];
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