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

hiding things behind the pinkIndexer namespace

parent a6547fce
#pragma once #pragma once
#include <Eigen/Dense>
#include "ExperimentSettings.h" #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: } // namespace pinkIndexer
ExperimentSettings experimentSettings; \ No newline at end of file
};
\ No newline at end of file
...@@ -10,20 +10,19 @@ ...@@ -10,20 +10,19 @@
#include <CustomException.h> #include <CustomException.h>
//! A specialization of MyException. namespace pinkIndexer
/*! {
* 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)
{
}
virtual ~BadInputException() throw () class BadInputException : public CustomException
{ {
} public:
}; BadInputException(const std::string& msg)
: CustomException(msg)
{
}
virtual ~BadInputException() throw() {}
};
} // namespace pinkIndexer
#endif /* BADINPUTEXCEPTION_H_ */ #endif /* BADINPUTEXCEPTION_H_ */
...@@ -4,23 +4,26 @@ ...@@ -4,23 +4,26 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
class Chronometer namespace pinkIndexer
{ {
public: class Chronometer
/** {
* @brief Chronometer constructor - saves the current time public:
* @param key the key for the debug protocol value /**
*/ * @brief Chronometer constructor - saves the current time
Chronometer(const std::string& key); * @param key the key for the debug protocol value
/** */
* @brief Chronometer destructor - gets the current time, calculates the Chronometer(const std::string& key);
* difference to the saved time (in milliseconds) and logs it via the Debug class /**
*/ * @brief Chronometer destructor - gets the current time, calculates the
~Chronometer(); * difference to the saved time (in milliseconds) and logs it via the Debug class
*/
~Chronometer();
private: private:
/// the key for the time value /// the key for the time value
const std::string key_; const std::string key_;
/// the timestamp at object construction /// the timestamp at object construction
std::chrono::time_point<std::chrono::system_clock> startTime_; std::chrono::time_point<std::chrono::system_clock> startTime_;
}; };
} // namespace pinkIndexer
\ No newline at end of file
...@@ -11,40 +11,43 @@ ...@@ -11,40 +11,43 @@
#include <exception> #include <exception>
#include <string> #include <string>
//! The Exception class from which every exception type in this project inherits from. namespace pinkIndexer
/*! {
* This is the superclass for all the custom exception types used in this project. //! The Exception class from which every exception type in this project inherits from.
* This class itself inherits from std::exception.
*/
class CustomException: public std::exception {
public:
/*! /*!
* The constructor taking a message as parameter. * This is the superclass for all the custom exception types used in this project.
* @param msg The message of the exception. * This class itself inherits from std::exception.
*/ */
CustomException(const std::string& msg) : class CustomException : public std::exception
msg(msg)
{ {
} 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. * The virtual destructor.
*/ */
virtual ~CustomException() throw () virtual ~CustomException() throw() {}
{
}
/*! /*!
* Returns the message of the exception. * Returns the message of the exception.
* @return * @return
*/ */
virtual const char* what() const throw () virtual const char* what() const throw()
{ {
return msg.c_str(); return msg.c_str();
} }
private:
std::string msg;
};
private: } // namespace pinkIndexer
std::string msg;
};
#endif /* CUSTOMEXCEPTION_H_ */ #endif /* CUSTOMEXCEPTION_H_ */
...@@ -11,102 +11,105 @@ ...@@ -11,102 +11,105 @@
#include "Lattice.h" #include "Lattice.h"
#include "WrongUsageException.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_ */ #endif /* EXPERIMENTSETTINGS_H_ */
...@@ -11,49 +11,52 @@ ...@@ -11,49 +11,52 @@
#include <Eigen/Dense> #include <Eigen/Dense>
#include <iostream> #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(); class Lattice
inline float det() const
{ {
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 Lattice& minimize();
{
return basis;
}
inline Eigen::Vector3f getBasisVectorNorms() const inline float det() const
{ {
return basis.colwise().norm(); return basis.determinant();
} }
Eigen::Vector3f getBasisVectorAngles_deg() const; inline const Eigen::Matrix3f& getBasis() const
Eigen::Vector3f getBasisVectorAnglesNormalized_deg() const; {
return basis;
}
inline Lattice getReciprocalLattice() const inline Eigen::Vector3f getBasisVectorNorms() const
{ {
return Lattice(basis.transpose().inverse().eval()); 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); friend std::ostream& operator<<(std::ostream& os, const Lattice& lattice);
void reorder(const Lattice prototypeLattice);
void normalizeAngles();
private: void reorder(const Eigen::Vector3f prototypeNorms, const Eigen::Vector3f prototypeAngles_deg);
Eigen::Matrix3f basis; void reorder(const Lattice prototypeLattice);
void normalizeAngles();
public: private:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Matrix3f basis;
};
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
} // namespace pinkIndexer
#endif /* LATTICE_H_ */ #endif /* LATTICE_H_ */
...@@ -11,65 +11,68 @@ ...@@ -11,65 +11,68 @@
#include <Eigen/Dense> #include <Eigen/Dense>
#include <stdint.h> #include <stdint.h>
namespace pinkIndexer
class PinkIndexer
{ {
public:
enum class ConsideredPeaksCount
{
veryFew,
few,
standard,
many,
manyMany
};
enum class AngleResolution class PinkIndexer
{ {
extremelyLoose, public:
loose, enum class ConsideredPeaksCount
standard, {
dense, veryFew,
extremelyDense few,
}; standard,
many,
manyMany
};
enum class RefinementType enum class AngleResolution
{ {
none, extremelyLoose,
fixedLatticeParameters, loose,
variableLatticeParameters, standard,
firstFixedThenVariableLatticeParameters, dense,
firstFixedThenVariableLatticeParametersMultiSeedLengths, extremelyDense
firstFixedThenVariableLatticeParametersMultiSeed, };
firstFixedThenVariableLatticeParametersCenterAdjustmentMultiSeed
};
PinkIndexer(const ExperimentSettings& experimentSettings, ConsideredPeaksCount consideredPeaksCount, AngleResolution angleResolution, enum class RefinementType
RefinementType refinementType, float maxResolutionForIndexing_1_per_A); {
none,
fixedLatticeParameters,
variableLatticeParameters,
firstFixedThenVariableLatticeParameters,
firstFixedThenVariableLatticeParametersMultiSeedLengths,
firstFixedThenVariableLatticeParametersMultiSeed,
firstFixedThenVariableLatticeParametersCenterAdjustmentMultiSeed
};
int indexPattern(Lattice& indexedLattice, Eigen::Vector2f& centerShift, Eigen::Array<bool, Eigen::Dynamic, 1>& fittedPeaks, Eigen::RowVectorXf& intensities, PinkIndexer(const ExperimentSettings& experimentSettings, ConsideredPeaksCount consideredPeaksCount, AngleResolution angleResolution,
const Eigen::Matrix2Xf& detectorPeaks_m, int threadCount); RefinementType refinementType, float maxResolutionForIndexing_1_per_A);
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);
private: int indexPattern(Lattice& indexedLattice, Eigen::Vector2f& centerShift, Eigen::Array<bool, Eigen::Dynamic, 1>& fittedPeaks,
void reducePeakCount(Eigen::Matrix3Xf& ucsDirections, Eigen::Array2Xf& ucsBorderNorms, Eigen::RowVectorXf& intensities, Eigen::RowVectorXf& intensities, const Eigen::Matrix2Xf& detectorPeaks_m, int threadCount);
const Eigen::Matrix2Xf& detectorPeaks_m); int indexPattern(Lattice& indexedLattice, Eigen::Vector2f& centerShift, Eigen::Array<bool, Eigen::Dynamic, 1>& fittedPeaks,
void refine(Lattice& indexedLattice, Eigen::Vector2f& centerShift, const Eigen::Matrix3Xf& ucsDirections, const Eigen::Array2Xf& ucsBorderNorms, Eigen::RowVectorXf& intensities, const Eigen::Matrix3Xf& meanReciprocalPeaks_1_per_A, int threadCount);
const Eigen::Matrix2Xf& detectorPeaks_m);
float getAngleResolution(); private:
int getConsideredPeaksCount(); 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; float getAngleResolution();
Backprojection backprojection; int getConsideredPeaksCount();
Sinogram sinogram;
Refinement refinement;
Lattice sampleLattice;
ConsideredPeaksCount consideredPeaksCount; SimpleProjection reciprocalToRealProjection;
AngleResolution angleResolution; Backprojection backprojection;
RefinementType refinementType; Sinogram sinogram;
float maxResolutionForIndexing_1_per_A; Refinement refinement;
float finalRefinementTolerance; Lattice sampleLattice;
};
\ No newline at end of file ConsideredPeaksCount consideredPeaksCount;
AngleResolution angleResolution;