mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-19 18:47:13 +02:00
Merge branch 'developer' into feature/remove-factories
This commit is contained in:
@ -5,6 +5,9 @@
|
||||
|
||||
namespace aare {
|
||||
|
||||
/**
|
||||
* @brief enum class to define the endianess of the system
|
||||
*/
|
||||
enum class endian {
|
||||
#ifdef _WIN32
|
||||
little = 0,
|
||||
@ -17,6 +20,10 @@ enum class endian {
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief class to define the data type of the pixels
|
||||
* @note only native endianess is supported
|
||||
*/
|
||||
class DType {
|
||||
// TODO! support for non native endianess?
|
||||
static_assert(sizeof(long) == sizeof(int64_t), "long should be 64bits");
|
||||
|
@ -7,14 +7,13 @@
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
|
||||
namespace aare {
|
||||
|
||||
/**
|
||||
* @brief Frame class to represent a single frame of data
|
||||
* model class
|
||||
* should be able to work with streams coming from files or network
|
||||
*/
|
||||
|
||||
namespace aare {
|
||||
|
||||
class Frame {
|
||||
ssize_t m_rows;
|
||||
ssize_t m_cols;
|
||||
|
@ -11,6 +11,9 @@
|
||||
|
||||
namespace aare {
|
||||
|
||||
/**
|
||||
* @brief header contained in parts of frames
|
||||
*/
|
||||
struct sls_detector_header {
|
||||
uint64_t frameNumber;
|
||||
uint32_t expLength;
|
||||
@ -35,7 +38,6 @@ struct xy {
|
||||
bool operator!=(const xy &other) const { return !(*this == other); }
|
||||
};
|
||||
|
||||
// using image_shape = std::array<ssize_t, 2>;
|
||||
using dynamic_shape = std::vector<ssize_t>;
|
||||
|
||||
enum class DetectorType { Jungfrau, Eiger, Mythen3, Moench, ChipTestBoard };
|
||||
|
@ -6,6 +6,13 @@
|
||||
|
||||
namespace aare {
|
||||
|
||||
/**
|
||||
* @brief Construct a DType object from a type_info object
|
||||
* @param t type_info object
|
||||
* @throw runtime_error if the type is not supported
|
||||
* @note supported types are: int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t, float, double
|
||||
* @note the type_info object is obtained using typeid (e.g. typeid(int))
|
||||
*/
|
||||
DType::DType(const std::type_info &t) {
|
||||
if (t == typeid(int8_t))
|
||||
m_type = TypeIndex::INT8;
|
||||
@ -33,6 +40,10 @@ DType::DType(const std::type_info &t) {
|
||||
throw std::runtime_error("Could not construct data type. Type not supported.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the bitdepth of the data type
|
||||
* @return bitdepth
|
||||
*/
|
||||
uint8_t DType::bitdepth() const {
|
||||
switch (m_type) {
|
||||
case TypeIndex::INT8:
|
||||
@ -58,8 +69,20 @@ uint8_t DType::bitdepth() const {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Construct a DType object from a TypeIndex
|
||||
* @param ti TypeIndex
|
||||
*
|
||||
*/
|
||||
DType::DType(DType::TypeIndex ti) : m_type(ti) {}
|
||||
|
||||
/**
|
||||
* @brief Construct a DType object from a string
|
||||
* @param sv string_view
|
||||
* @throw runtime_error if the type is not supported
|
||||
* @note example strings: "<i4", "u8", "f4"
|
||||
* @note the endianess is checked and only native endianess is supported
|
||||
*/
|
||||
DType::DType(std::string_view sv) {
|
||||
|
||||
// Check if the file is using our native endianess
|
||||
@ -101,6 +124,10 @@ DType::DType(std::string_view sv) {
|
||||
throw std::runtime_error("Could not construct data type. Type no supported.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the string representation of the data type
|
||||
* @return string representation
|
||||
*/
|
||||
std::string DType::str() const {
|
||||
|
||||
char ec;
|
||||
|
@ -5,17 +5,38 @@
|
||||
|
||||
namespace aare {
|
||||
|
||||
/**
|
||||
* @brief Construct a new Frame
|
||||
* @param bytes pointer to the data to be copied into the frame
|
||||
* @param rows number of rows
|
||||
* @param cols number of columns
|
||||
* @param bitdepth bitdepth of the pixels
|
||||
*/
|
||||
Frame::Frame(std::byte *bytes, ssize_t rows, ssize_t cols, ssize_t bitdepth)
|
||||
: m_rows(rows), m_cols(cols), m_bitdepth(bitdepth) {
|
||||
m_data = new std::byte[rows * cols * bitdepth / 8];
|
||||
std::memcpy(m_data, bytes, rows * cols * bitdepth / 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Construct a new Frame
|
||||
* @param rows number of rows
|
||||
* @param cols number of columns
|
||||
* @param bitdepth bitdepth of the pixels
|
||||
* @note the data is initialized to zero
|
||||
*/
|
||||
Frame::Frame(ssize_t rows, ssize_t cols, ssize_t bitdepth) : m_rows(rows), m_cols(cols), m_bitdepth(bitdepth) {
|
||||
m_data = new std::byte[rows * cols * bitdepth / 8];
|
||||
std::memset(m_data, 0, rows * cols * bitdepth / 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the pointer to the pixel at the given row and column
|
||||
* @param row row index
|
||||
* @param col column index
|
||||
* @return pointer to the pixel
|
||||
* @note the user should cast the pointer to the appropriate type
|
||||
*/
|
||||
std::byte *Frame::get(int row, int col) {
|
||||
if (row < 0 || row >= m_rows || col < 0 || col >= m_cols) {
|
||||
std::cerr << "Invalid row or column index" << std::endl;
|
||||
|
@ -2,6 +2,11 @@
|
||||
|
||||
namespace aare {
|
||||
|
||||
/**
|
||||
* @brief Convert a DetectorType to a string
|
||||
* @param type DetectorType
|
||||
* @return string representation of the DetectorType
|
||||
*/
|
||||
template <> std::string toString(DetectorType type) {
|
||||
switch (type) {
|
||||
case DetectorType::Jungfrau:
|
||||
@ -19,6 +24,12 @@ template <> std::string toString(DetectorType type) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert a string to a DetectorType
|
||||
* @param name string representation of the DetectorType
|
||||
* @return DetectorType
|
||||
* @throw runtime_error if the string does not match any DetectorType
|
||||
*/
|
||||
template <> DetectorType StringTo(std::string name) {
|
||||
if (name == "Jungfrau")
|
||||
return DetectorType::Jungfrau;
|
||||
@ -35,6 +46,12 @@ template <> DetectorType StringTo(std::string name) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert a string to a TimingMode
|
||||
* @param mode string representation of the TimingMode
|
||||
* @return TimingMode
|
||||
* @throw runtime_error if the string does not match any TimingMode
|
||||
*/
|
||||
template <> TimingMode StringTo(std::string mode) {
|
||||
if (mode == "auto")
|
||||
return TimingMode::Auto;
|
||||
|
Reference in New Issue
Block a user