Commit f1827cdd authored by Yaroslav Gevorkov's avatar Yaroslav Gevorkov
Browse files

hiding things behind the pinkIndexer namespace

parent a6547fce
#pragma once
#include <Eigen/Dense>
#include "ExperimentSettings.h"
#include <Eigen/Dense>
class Backprojection
namespace pinkIndexer
{
public:
Backprojection(const ExperimentSettings& experimentSettings);
void backProject(const Eigen::Matrix2Xf& detectorPeaks_m, Eigen::Matrix3Xf& ucsDirections, Eigen::Array2Xf& ucsBorderNorms ) const;
class Backprojection
{
public:
Backprojection(const ExperimentSettings& experimentSettings);
void backProject(const Eigen::Matrix2Xf& detectorPeaks_m, Eigen::Matrix3Xf& ucsDirections, Eigen::Array2Xf& ucsBorderNorms) const;
private:
ExperimentSettings experimentSettings;
};
private:
ExperimentSettings experimentSettings;
};
\ No newline at end of file
} // namespace pinkIndexer
\ No newline at end of file
......@@ -10,20 +10,19 @@
#include <CustomException.h>
//! A specialization of MyException.
/*!
* This exception is thrown whenever the input to a method/function is not as expected
*/
class BadInputException: public CustomException {
public:
BadInputException(const std::string& msg) :
CustomException(msg)
{
}
namespace pinkIndexer
{
virtual ~BadInputException() throw ()
class BadInputException : public CustomException
{
}
};
public:
BadInputException(const std::string& msg)
: CustomException(msg)
{
}
virtual ~BadInputException() throw() {}
};
} // namespace pinkIndexer
#endif /* BADINPUTEXCEPTION_H_ */
......@@ -4,23 +4,26 @@
#include <cstdint>
#include <string>
class Chronometer
namespace pinkIndexer
{
public:
/**
* @brief Chronometer constructor - saves the current time
* @param key the key for the debug protocol value
*/
Chronometer(const std::string& key);
/**
* @brief Chronometer destructor - gets the current time, calculates the
* difference to the saved time (in milliseconds) and logs it via the Debug class
*/
~Chronometer();
class Chronometer
{
public:
/**
* @brief Chronometer constructor - saves the current time
* @param key the key for the debug protocol value
*/
Chronometer(const std::string& key);
/**
* @brief Chronometer destructor - gets the current time, calculates the
* difference to the saved time (in milliseconds) and logs it via the Debug class
*/
~Chronometer();
private:
/// the key for the time value
const std::string key_;
/// the timestamp at object construction
std::chrono::time_point<std::chrono::system_clock> startTime_;
};
private:
/// the key for the time value
const std::string key_;
/// the timestamp at object construction
std::chrono::time_point<std::chrono::system_clock> startTime_;
};
} // namespace pinkIndexer
\ No newline at end of file
......@@ -11,40 +11,43 @@
#include <exception>
#include <string>
//! The Exception class from which every exception type in this project inherits from.
/*!
* This is the superclass for all the custom exception types used in this project.
* This class itself inherits from std::exception.
*/
class CustomException: public std::exception {
public:
namespace pinkIndexer
{
//! The Exception class from which every exception type in this project inherits from.
/*!
* The constructor taking a message as parameter.
* @param msg The message of the exception.
* This is the superclass for all the custom exception types used in this project.
* This class itself inherits from std::exception.
*/
CustomException(const std::string& msg) :
msg(msg)
class CustomException : public std::exception
{
}
public:
/*!
* The constructor taking a message as parameter.
* @param msg The message of the exception.
*/
CustomException(const std::string& msg)
: msg(msg)
{
}
/*!
* The virtual destructor.
*/
virtual ~CustomException() throw ()
{
}
/*!
* The virtual destructor.
*/
virtual ~CustomException() throw() {}
/*!
* Returns the message of the exception.
* @return
*/
virtual const char* what() const throw ()
{
return msg.c_str();
}
/*!
* Returns the message of the exception.
* @return
*/
virtual const char* what() const throw()
{
return msg.c_str();
}
private:
std::string msg;
};
private:
std::string msg;
};
} // namespace pinkIndexer
#endif /* CUSTOMEXCEPTION_H_ */
......@@ -11,102 +11,105 @@
#include "Lattice.h"
#include "WrongUsageException.h"
class ExperimentSettings
namespace pinkIndexer
{
public:
ExperimentSettings(float coffset_m, float clen_mm, float beamEenergy_eV, float divergenceAngle_deg, float nonMonochromaticity, float pixelLength_m,
float detectorRadius_pixel, float minRealLatticeVectorLength_A, float maxRealLatticeVectorLength_A, float reflectionRadius_1_per_A);
ExperimentSettings(float beamEenergy_eV, float detectorDistance_m, float detectorRadius_m, float divergenceAngle_deg, float nonMonochromaticity,
float minRealLatticeVectorLength_A, float maxRealLatticeVectorLength_A, float reflectionRadius_1_per_A);
ExperimentSettings(float coffset_m, float clen_mm, float beamEenergy_eV, float divergenceAngle_deg, float nonMonochromaticity, float pixelLength_m,
float detectorRadius_pixel, const Lattice& sampleReciprocalLattice_1A, float tolerance, float reflectionRadius_1_per_A);
ExperimentSettings(float beamEenergy_eV, float detectorDistance_m, float detectorRadius_m, float divergenceAngle_deg, float nonMonochromaticity,
const Lattice& sampleReciprocalLattice_1A, float tolerance, float reflectionRadius_1_per_A);
float getDetectorDistance_m() const;
float getDetectorRadius_m() const;
float getLambda_A() const;
float getLambdaLong_A() const;
float getLambdaShort_A() const;
float getReciprocalLambda_1A() const;
float getReciprocalLambdaLong_1A() const;
float getReciprocalLambdaShort_1A() const;
float getNonMonochromaticity() const;
float getDivergenceAngle_rad() const;
float getMaxResolutionAngle_rad() const;
float getReflectionRadius() const;
bool isLatticeParametersKnown() const;
const Lattice& getSampleRealLattice_A() const;
const Lattice& getSampleReciprocalLattice_1A() const;
const Eigen::Array3f& getRealLatticeVectorLengths_A() const;
const Eigen::Array3f& getRealLatticeVectorAngles_deg() const;
const Eigen::Array3f& getRealLatticeVectorAnglesNormalized_deg() const;
float getRealLatticeDeterminant_A3() const;
const Eigen::Array3f& getReciprocalLatticeVectorLengths_1A() const;
const Eigen::Array3f& getReciprocalLatticeVectorAngles_deg() const;
const Eigen::Array3f& getReciprocalLatticeVectorAnglesNormalized_deg() const;
float getReciprocalLatticeDeterminant_1A3() const;
float getTolerance() const;
float getMaxRealLatticeDeterminant_A3() const;
float getMaxRealLatticeVectorLength_A() const;
float getMaxReciprocalLatticeDeterminant_1A3() const;
float getMaxReciprocalLatticeVectorLength_1A() const;
float getMinRealLatticeDeterminant_A3() const;
float getMinRealLatticeVectorLength_A() const;
float getMinReciprocalLatticeDeterminant_1A3() const;
float getMinReciprocalLatticeVectorLength_1A() const;
const Eigen::ArrayXf& getDifferentRealLatticeVectorLengths_A() const;
private:
void constructFromGeometryFileValues(float coffset_m, float clen_mm, float beamEenergy_eV, float divergenceAngle_deg, float nonMonochromaticity,
float pixelLength_m, float detectorRadius_pixel);
void constructFromPrecomputedValues(float beamEenergy_eV, float detectorDistance_m, float detectorRadius_m, float divergenceAngle_deg,
float nonMonochromaticity);
void deduceValuesFromSampleReciprocalLattice();
float detectorDistance_m;
float detectorRadius_m;
float lambda_A, lambdaShort_A, lambdaLong_A;
float reciprocal_lambda_1A, reciprocal_lambdaShort_1A, reciprocal_lambdaLong_1A;
float nonMonochromaticity;
float divergenceAngle_rad;
float maxResolutionAngle_rad;
float reflectionRadius_1_per_A;
bool latticeParametersKnown;
float minRealLatticeVectorLength_A;
float maxRealLatticeVectorLength_A;
float minRealLatticeDeterminant_A3;
float maxRealLatticeDeterminant_A3;
float minReciprocalLatticeVectorLength_1A;
float maxReciprocalLatticeVectorLength_1A;
float minReciprocalLatticeDeterminant_1A3;
float maxReciprocalLatticeDeterminant_1A3;
// if latticeParametersKnown
Lattice sampleRealLattice_A;
Lattice sampleReciprocalLattice_1A;
Eigen::Array3f realLatticeVectorLengths_A;
Eigen::Array3f realLatticeVectorAngles_deg;
Eigen::Array3f realLatticeVectorAnglesNormalized_deg;
float realLatticeDeterminant_A3;
Eigen::Array3f reciprocalLatticeVectorLengths_1A;
Eigen::Array3f reciprocalLatticeVectorAngles_deg;
Eigen::Array3f reciprocalLatticeVectorAnglesNormalized_deg;
float reciprocalLatticeDeterminant_1A3;
float latticeParametersTolerance;
// if latticeParametersKnown, trivial. if not, set to min and max vector length
Eigen::ArrayXf differentRealLatticeVectorLengths_A;
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
class ExperimentSettings
{
public:
ExperimentSettings(float coffset_m, float clen_mm, float beamEenergy_eV, float divergenceAngle_deg, float nonMonochromaticity, float pixelLength_m,
float detectorRadius_pixel, float minRealLatticeVectorLength_A, float maxRealLatticeVectorLength_A, float reflectionRadius_1_per_A);
ExperimentSettings(float beamEenergy_eV, float detectorDistance_m, float detectorRadius_m, float divergenceAngle_deg, float nonMonochromaticity,
float minRealLatticeVectorLength_A, float maxRealLatticeVectorLength_A, float reflectionRadius_1_per_A);
ExperimentSettings(float coffset_m, float clen_mm, float beamEenergy_eV, float divergenceAngle_deg, float nonMonochromaticity, float pixelLength_m,
float detectorRadius_pixel, const Lattice& sampleReciprocalLattice_1A, float tolerance, float reflectionRadius_1_per_A);
ExperimentSettings(float beamEenergy_eV, float detectorDistance_m, float detectorRadius_m, float divergenceAngle_deg, float nonMonochromaticity,
const Lattice& sampleReciprocalLattice_1A, float tolerance, float reflectionRadius_1_per_A);
float getDetectorDistance_m() const;
float getDetectorRadius_m() const;
float getLambda_A() const;
float getLambdaLong_A() const;
float getLambdaShort_A() const;
float getReciprocalLambda_1A() const;
float getReciprocalLambdaLong_1A() const;
float getReciprocalLambdaShort_1A() const;
float getNonMonochromaticity() const;
float getDivergenceAngle_rad() const;
float getMaxResolutionAngle_rad() const;
float getReflectionRadius() const;
bool isLatticeParametersKnown() const;
const Lattice& getSampleRealLattice_A() const;
const Lattice& getSampleReciprocalLattice_1A() const;
const Eigen::Array3f& getRealLatticeVectorLengths_A() const;
const Eigen::Array3f& getRealLatticeVectorAngles_deg() const;
const Eigen::Array3f& getRealLatticeVectorAnglesNormalized_deg() const;
float getRealLatticeDeterminant_A3() const;
const Eigen::Array3f& getReciprocalLatticeVectorLengths_1A() const;
const Eigen::Array3f& getReciprocalLatticeVectorAngles_deg() const;
const Eigen::Array3f& getReciprocalLatticeVectorAnglesNormalized_deg() const;
float getReciprocalLatticeDeterminant_1A3() const;
float getTolerance() const;
float getMaxRealLatticeDeterminant_A3() const;
float getMaxRealLatticeVectorLength_A() const;
float getMaxReciprocalLatticeDeterminant_1A3() const;
float getMaxReciprocalLatticeVectorLength_1A() const;
float getMinRealLatticeDeterminant_A3() const;
float getMinRealLatticeVectorLength_A() const;
float getMinReciprocalLatticeDeterminant_1A3() const;
float getMinReciprocalLatticeVectorLength_1A() const;
const Eigen::ArrayXf& getDifferentRealLatticeVectorLengths_A() const;
private:
void constructFromGeometryFileValues(float coffset_m, float clen_mm, float beamEenergy_eV, float divergenceAngle_deg, float nonMonochromaticity,
float pixelLength_m, float detectorRadius_pixel);
void constructFromPrecomputedValues(float beamEenergy_eV, float detectorDistance_m, float detectorRadius_m, float divergenceAngle_deg,
float nonMonochromaticity);
void deduceValuesFromSampleReciprocalLattice();
float detectorDistance_m;
float detectorRadius_m;
float lambda_A, lambdaShort_A, lambdaLong_A;
float reciprocal_lambda_1A, reciprocal_lambdaShort_1A, reciprocal_lambdaLong_1A;
float nonMonochromaticity;
float divergenceAngle_rad;
float maxResolutionAngle_rad;
float reflectionRadius_1_per_A;
bool latticeParametersKnown;
float minRealLatticeVectorLength_A;
float maxRealLatticeVectorLength_A;
float minRealLatticeDeterminant_A3;
float maxRealLatticeDeterminant_A3;
float minReciprocalLatticeVectorLength_1A;
float maxReciprocalLatticeVectorLength_1A;
float minReciprocalLatticeDeterminant_1A3;
float maxReciprocalLatticeDeterminant_1A3;
// if latticeParametersKnown
Lattice sampleRealLattice_A;
Lattice sampleReciprocalLattice_1A;
Eigen::Array3f realLatticeVectorLengths_A;
Eigen::Array3f realLatticeVectorAngles_deg;
Eigen::Array3f realLatticeVectorAnglesNormalized_deg;
float realLatticeDeterminant_A3;
Eigen::Array3f reciprocalLatticeVectorLengths_1A;
Eigen::Array3f reciprocalLatticeVectorAngles_deg;
Eigen::Array3f reciprocalLatticeVectorAnglesNormalized_deg;
float reciprocalLatticeDeterminant_1A3;
float latticeParametersTolerance;
// if latticeParametersKnown, trivial. if not, set to min and max vector length
Eigen::ArrayXf differentRealLatticeVectorLengths_A;
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
} // namespace pinkIndexer
#endif /* EXPERIMENTSETTINGS_H_ */
......@@ -11,49 +11,52 @@
#include <Eigen/Dense>
#include <iostream>
class Lattice
namespace pinkIndexer
{
public:
Lattice();
Lattice(const Eigen::Matrix3f& basis);
Lattice(const Eigen::Vector3f& a, const Eigen::Vector3f& b, const Eigen::Vector3f& c);
Lattice& minimize();
inline float det() const
class Lattice
{
return basis.determinant();
}
public:
Lattice();
Lattice(const Eigen::Matrix3f& basis);
Lattice(const Eigen::Vector3f& a, const Eigen::Vector3f& b, const Eigen::Vector3f& c);
inline const Eigen::Matrix3f& getBasis() const
{
return basis;
}
Lattice& minimize();
inline Eigen::Vector3f getBasisVectorNorms() const
{
return basis.colwise().norm();
}
inline float det() const
{
return basis.determinant();
}
Eigen::Vector3f getBasisVectorAngles_deg() const;
Eigen::Vector3f getBasisVectorAnglesNormalized_deg() const;
inline const Eigen::Matrix3f& getBasis() const
{
return basis;
}
inline Lattice getReciprocalLattice() const
{
return Lattice(basis.transpose().inverse().eval());
}
inline Eigen::Vector3f getBasisVectorNorms() const
{
return basis.colwise().norm();
}
Eigen::Vector3f getBasisVectorAngles_deg() const;
Eigen::Vector3f getBasisVectorAnglesNormalized_deg() const;
friend std::ostream& operator<<(std::ostream& os, const Lattice& lattice);
inline Lattice getReciprocalLattice() const
{
return Lattice(basis.transpose().inverse().eval());
}
void reorder(const Eigen::Vector3f prototypeNorms, const Eigen::Vector3f prototypeAngles_deg);
void reorder(const Lattice prototypeLattice);
void normalizeAngles();
friend std::ostream& operator<<(std::ostream& os, const Lattice& lattice);
private:
Eigen::Matrix3f basis;
void reorder(const Eigen::Vector3f prototypeNorms, const Eigen::Vector3f prototypeAngles_deg);
void reorder(const Lattice prototypeLattice);
void normalizeAngles();
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
private:
Eigen::Matrix3f basis;
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
} // namespace pinkIndexer
#endif /* LATTICE_H_ */
......@@ -11,65 +11,68 @@
#include <Eigen/Dense>
#include <stdint.h>
class PinkIndexer
namespace pinkIndexer
{
public:
enum class ConsideredPeaksCount
{
veryFew,
few,
standard,
many,
manyMany
};
enum class AngleResolution
class PinkIndexer
{
extremelyLoose,
loose,
standard,
dense,
extremelyDense
};
public:
enum class ConsideredPeaksCount
{
veryFew,
few,
standard,
many,
manyMany
};
enum class RefinementType
{
none,
fixedLatticeParameters,
variableLatticeParameters,
firstFixedThenVariableLatticeParameters,
firstFixedThenVariableLatticeParametersMultiSeedLengths,
firstFixedThenVariableLatticeParametersMultiSeed,
firstFixedThenVariableLatticeParametersCenterAdjustmentMultiSeed
};
enum class AngleResolution
{
extremelyLoose,
loose,
standard,
dense,
extremelyDense
};
PinkIndexer(const ExperimentSettings& experimentSettings, ConsideredPeaksCount consideredPeaksCount, AngleResolution angleResolution,
RefinementType refinementType, float maxResolutionForIndexing_1_per_A);
enum class RefinementType
{
none,
fixedLatticeParameters,
variableLatticeParameters,
firstFixedThenVariableLatticeParameters,
firstFixedThenVariableLatticeParametersMultiSeedLengths,
firstFixedThenVariableLatticeParametersMultiSeed,
firstFixedThenVariableLatticeParametersCenterAdjustmentMultiSeed
};
int indexPattern(Lattice& indexedLattice, Eigen::Vector2f& centerShift, Eigen::Array<bool, Eigen::Dynamic, 1>& fittedPeaks, Eigen::RowVectorXf& intensities,
const Eigen::Matrix2Xf& detectorPeaks_m, int threadCount);
int indexPattern(Lattice& indexedLattice, Eigen::Vector2f& centerShift, Eigen::Array<bool, Eigen::Dynamic, 1>& fittedPeaks, Eigen::RowVectorXf& intensities,
const Eigen::Matrix3Xf& meanReciprocalPeaks_1_per_A, int threadCount);
PinkIndexer(const ExperimentSettings& experimentSettings, ConsideredPeaksCount consideredPeaksCount, AngleResolution angleResolution,
RefinementType refinementType, float maxResolutionForIndexing_1_per_A);
private:
void reducePeakCount(Eigen::Matrix3Xf& ucsDirections, Eigen::Array2Xf& ucsBorderNorms, Eigen::RowVectorXf& intensities,
const Eigen::Matrix2Xf& detectorPeaks_m);
void refine(Lattice& indexedLattice, Eigen::Vector2f& centerShift, const Eigen::Matrix3Xf& ucsDirections, const Eigen::Array2Xf& ucsBorderNorms,
const Eigen::Matrix2Xf& detectorPeaks_m);
int indexPattern(Lattice& indexedLattice, Eigen::Vector2f& centerShift, Eigen::Array<bool, Eigen::Dynamic, 1>& fittedPeaks,
Eigen::RowVectorXf& intensities, const Eigen::Matrix2Xf& detectorPeaks_m, int threadCount);
int indexPattern(Lattice& indexedLattice, Eigen::Vector2f& centerShift, Eigen::Array<bool, Eigen::Dynamic, 1>& fittedPeaks,
Eigen::RowVectorXf& intensities, const Eigen::Matrix3Xf& meanReciprocalPeaks_1_per_A, int threadCount);
float getAngleResolution();
int getConsideredPeaksCount();
private:
void reducePeakCount(Eigen::Matrix3Xf& ucsDirections, Eigen::Array2Xf& ucsBorderNorms, Eigen::RowVectorXf& intensities,
const Eigen::Matrix2Xf& detectorPeaks_m);
void refine(Lattice& indexedLattice, Eigen::Vector2f& centerShift, const Eigen::Matrix3Xf& ucsDirections, const Eigen::Array2Xf& ucsBorderNorms,
const Eigen::Matrix2Xf& detectorPeaks_m);
SimpleProjection reciprocalToRealProjection;
Backprojection backprojection;
Sinogram sinogram;
Refinement refinement;
Lattice sampleLattice;
float getAngleResolution();
int getConsideredPeaksCount();
ConsideredPeaksCount consideredPeaksCount;
AngleResolution angleResolution;
RefinementType refinementType;
float maxResolutionForIndexing_1_per_A;
float finalRefinementTolerance;
};
\ No newline at end of file
SimpleProjection reciprocalToRealProjection;
Backprojection backprojection;
Sinogram sinogram;
Refinement refinement;
Lattice sampleLattice;
ConsideredPeaksCount consideredPeaksCount;
AngleResolution angleResolution;
RefinementType refinementType;
float maxResolutionForIndexing_1_per_A;
float finalRefinementTolerance;
};
} // namespace pinkIndexer
\ No newline at end of file
......@@ -3,15 +3,17 @@
#include "ExperimentSettings.h"
#include <Eigen/Dense>
class ReciprocalToRealProjection
namespace pinkIndexer
{
public:
ReciprocalToRealProjection(const ExperimentSettings& experimentSettings);
virtual ~ReciprocalToRealProjection() = default;
class ReciprocalToRealProjection
{
public:
ReciprocalToRealProjection(const ExperimentSettings& experimentSettings);
virtual ~ReciprocalToRealProjection() = default;
virtual void project(Eigen::Matrix2Xf& projectedPoints, const Eigen::Matrix3Xf& reciprocalPoints) const = 0;
virtual void project(Eigen::Matrix2Xf& projectedPoints, const Eigen::Matrix3Xf& reciprocalPoints) const = 0;