/* * image.h * * Handle images and image features * * Copyright © 2012-2017 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: * 2009-2017 Thomas White * 2014 Valerio Mariani * * * This file is part of CrystFEL. * * CrystFEL is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * CrystFEL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with CrystFEL. If not, see . * */ #ifdef HAVE_CONFIG_H #include #endif #ifndef IMAGE_H #define IMAGE_H struct detector; #include #include #include struct imagefeature; struct sample; struct image; struct imagefile; struct imagefile_field_list; #include "utils.h" #include "cell.h" #include "detector.h" #include "reflist.h" #include "crystal.h" #include "index.h" #include "events.h" /** * SpectrumType: * @SPECTRUM_TOPHAT: A top hat distribution of wavelengths * @SPECTRUM_SASE: A simulated SASE spectrum * @SPECTRUM_TWOCOLOUR: A spectrum containing two peaks * * A %SpectrumType represents a type of X-ray energy spectrum to use for * generating simulated data. **/ typedef enum { SPECTRUM_TOPHAT, SPECTRUM_SASE, SPECTRUM_TWOCOLOUR } SpectrumType; /* Structure describing a feature in an image */ struct imagefeature { struct image *parent; double fs; double ss; struct panel *p; double intensity; /* Reciprocal space coordinates (m^-1 of course) of this feature */ double rx; double ry; double rz; /* Internal use only */ int valid; const char *name; }; /* An enum representing the image file formats we can handle */ enum imagefile_type { IMAGEFILE_HDF5, IMAGEFILE_CBF }; /* An opaque type representing a list of image features */ typedef struct _imagefeaturelist ImageFeatureList; /* Structure describing a wavelength sample from a spectrum */ struct sample { double k; double weight; }; struct beam_params { double photon_energy; /* eV per photon */ char *photon_energy_from; /* HDF5 dataset name */ double photon_energy_scale; /* Scale factor for photon energy, if the * energy is to be from the HDF5 file */ }; /** * image: * * * struct image * { * Crystal **crystals; * int n_crystals; * IndexingMethod indexed_by; * * struct detector *det; * struct beam_params *beam; * char *filename; * const struct imagefile_field_list *copyme; * * int id; * * double lambda; * double div; * double bw; * * int width; * int height; * * long long int num_peaks; * long long int num_saturated_peaks; * ImageFeatureList *features; * }; * * * The field data contains the raw image data, if it * is currently available. The data might be available throughout the * processing of an experimental pattern, but it might not be available when * simulating, scaling or merging patterns. Similarly, * flags contains an array of the same dimensions * as data to contain the bad pixel flags. * twotheta likewise contains an array of 2*theta * (scattering angle) values in radians, since these values are generated as a * by-product of the scattering vector calculation and can be used later for * calculating intensities from differential scattering cross sections. * * crystals is an array of %Crystal directly * returned by the low-level indexing system. n_crystals * is the number of crystals which were found in the image. * * copyme represents a list of fields in the image * file (e.g. HDF5 fields or CBF headers) to copy to the output stream. **/ struct image; struct image { float **dp; /* Data in panel */ int **bad; /* Bad pixels by panel */ float **sat; /* Per-pixel saturation values */ Crystal **crystals; int n_crystals; IndexingMethod indexed_by; struct detector *det; struct beam_params *beam; /* The nominal beam parameters */ char *filename; struct event *event; const struct imagefile_field_list *copyme; struct stuff_from_stream *stuff_from_stream; double avg_clen; /* Average camera length extracted * from stuff_from_stream */ int id; /* ID number of the thread * handling this image */ int serial; /* Monotonically ascending serial * number for this image */ struct sample *spectrum; int nsamples; /* Number of wavelengths */ int spectrum_size; /* Size of "spectrum" */ /* Per-shot radiation values */ double lambda; /* Wavelength in m */ double div; /* Divergence in radians */ double bw; /* Bandwidth as a fraction */ /* Detected peaks */ long long int num_peaks; long long int num_saturated_peaks; ImageFeatureList *features; }; #ifdef __cplusplus extern "C" { #endif /* Feature lists */ extern ImageFeatureList *image_feature_list_new(void); extern void image_feature_list_free(ImageFeatureList *flist); extern void image_add_feature(ImageFeatureList *flist, double x, double y, struct panel *p, struct image *parent, double intensity, const char *name); extern void image_remove_feature(ImageFeatureList *flist, int idx); extern struct imagefeature *image_feature_closest(ImageFeatureList *flist, double fs, double ss, struct panel *p, double *d, int *idx); extern Reflection *image_reflection_closest(RefList *rlist, double fs, double ss, struct panel *p, struct detector *det, double *d); extern int image_feature_count(ImageFeatureList *flist); extern struct imagefeature *image_get_feature(ImageFeatureList *flist, int idx); extern ImageFeatureList *sort_peaks(ImageFeatureList *flist); extern void image_add_crystal(struct image *image, Crystal *cryst); extern void remove_flagged_crystals(struct image *image); extern void free_all_crystals(struct image *image); /* Image files */ extern struct imagefile *imagefile_open(const char *filename); extern int imagefile_read(struct imagefile *f, struct image *image, struct event *event); extern int imagefile_read_simple(struct imagefile *f, struct image *image); extern struct hdfile *imagefile_get_hdfile(struct imagefile *f); extern enum imagefile_type imagefile_get_type(struct imagefile *f); extern void imagefile_copy_fields(struct imagefile *f, const struct imagefile_field_list *copyme, FILE *fh, struct event *ev); extern void imagefile_close(struct imagefile *f); /* Field lists */ extern struct imagefile_field_list *new_imagefile_field_list(void); extern void free_imagefile_field_list(struct imagefile_field_list *f); extern void add_imagefile_field(struct imagefile_field_list *copyme, const char *name); #ifdef __cplusplus } #endif #endif /* IMAGE_H */