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
{
class Backprojection
{
public:
Backprojection(const ExperimentSettings& experimentSettings);
void backProject(const Eigen::Matrix2Xf& detectorPeaks_m, Eigen::Matrix3Xf& ucsDirections, Eigen::Array2Xf& ucsBorderNorms ) const;
void backProject(const Eigen::Matrix2Xf& detectorPeaks_m, Eigen::Matrix3Xf& ucsDirections, Eigen::Array2Xf& ucsBorderNorms) const;
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,9 +4,11 @@
#include <cstdint>
#include <string>
class Chronometer
namespace pinkIndexer
{
public:
class Chronometer
{
public:
/**
* @brief Chronometer constructor - saves the current time
* @param key the key for the debug protocol value
......@@ -18,9 +20,10 @@ public:
*/
~Chronometer();
private:
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.
/*!
namespace pinkIndexer
{
//! 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:
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)
CustomException(const std::string& msg)
: msg(msg)
{
}
/*!
* The virtual destructor.
*/
virtual ~CustomException() throw ()
{
}
virtual ~CustomException() throw() {}
/*!
* Returns the message of the exception.
* @return
*/
virtual const char* what() const throw ()
virtual const char* what() const throw()
{
return msg.c_str();
}
private:
private:
std::string msg;
};
};
} // namespace pinkIndexer
#endif /* CUSTOMEXCEPTION_H_ */
......@@ -11,8 +11,11 @@
#include "Lattice.h"
#include "WrongUsageException.h"
class ExperimentSettings
namespace pinkIndexer
{
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);
......@@ -107,6 +110,6 @@ class ExperimentSettings
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
};
} // namespace pinkIndexer
#endif /* EXPERIMENTSETTINGS_H_ */
......@@ -11,8 +11,11 @@
#include <Eigen/Dense>
#include <iostream>
class Lattice
namespace pinkIndexer
{
class Lattice
{
public:
Lattice();
Lattice(const Eigen::Matrix3f& basis);
......@@ -54,6 +57,6 @@ class Lattice
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
};
} // namespace pinkIndexer
#endif /* LATTICE_H_ */
......@@ -11,9 +11,11 @@
#include <Eigen/Dense>
#include <stdint.h>
class PinkIndexer
namespace pinkIndexer
{
class PinkIndexer
{
public:
enum class ConsideredPeaksCount
{
......@@ -47,10 +49,10 @@ class PinkIndexer
PinkIndexer(const ExperimentSettings& experimentSettings, ConsideredPeaksCount consideredPeaksCount, AngleResolution angleResolution,
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::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);
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);
private:
void reducePeakCount(Eigen::Matrix3Xf& ucsDirections, Eigen::Array2Xf& ucsBorderNorms, Eigen::RowVectorXf& intensities,
......@@ -72,4 +74,5 @@ class PinkIndexer
RefinementType refinementType;
float maxResolutionForIndexing_1_per_A;
float finalRefinementTolerance;
};
\ No newline at end of file
};
} // namespace pinkIndexer
\ No newline at end of file
......@@ -3,9 +3,10 @@
#include "ExperimentSettings.h"
#include <Eigen/Dense>
class ReciprocalToRealProjection
namespace pinkIndexer
{
class ReciprocalToRealProjection
{
public:
ReciprocalToRealProjection(const ExperimentSettings& experimentSettings);
virtual ~ReciprocalToRealProjection() = default;
......@@ -14,4 +15,5 @@ class ReciprocalToRealProjection
protected:
ExperimentSettings experimentSettings;
};
};
} // namespace pinkIndexer
\ No newline at end of file
......@@ -7,8 +7,10 @@
#include <Eigen/Dense>
#include <vector>
class Refinement
namespace pinkIndexer
{
class Refinement
{
public:
Refinement(float tolerance);
Refinement(float tolerance, const Backprojection& backprojection);
......@@ -63,4 +65,5 @@ class Refinement
Eigen::Matrix2Xf detectorPeaks_m_shifted;
Eigen::Matrix3Xf ucsDirections;
Eigen::Array2Xf ucsBorderNorms;
};
};
} // namespace pinkIndexer
\ No newline at end of file
#pragma once
#include "BadInputException.h"
#include "ExperimentSettings.h"
#include "eigenSTLContainers.h"
#include "BadInputException.h"
class ReflectionsInRangeFinder
namespace pinkIndexer
{
class ReflectionsInRangeFinder
{
public:
ReflectionsInRangeFinder(const Lattice& lattice);
......@@ -15,4 +17,5 @@ class ReflectionsInRangeFinder
Eigen::Matrix3Xf reflectionsDirections_sorted;
std::vector<float> norms_sorted;
float maxRadius;
};
\ No newline at end of file
};
} // namespace pinkIndexer
\ No newline at end of file
......@@ -4,8 +4,10 @@
#include "SimpleProjection.h"
#include <Eigen/Dense>
class SimpleDiffractionPatternPrediction
namespace pinkIndexer
{
class SimpleDiffractionPatternPrediction
{
public:
SimpleDiffractionPatternPrediction(const ExperimentSettings& experimentSettings);
......@@ -20,4 +22,5 @@ class SimpleDiffractionPatternPrediction
float reciprocalLambdaShort, reciprocalLambdaLong;
float reciprocalLambdaShort_extended_squared, reciprocalLambdaLong_extended_squared;
float detectorDistance;
};
};
} // namespace pinkIndexer
\ No newline at end of file
......@@ -3,10 +3,13 @@
#include "ReciprocalToRealProjection.h"
#include <Eigen/Dense>
class SimpleProjection : public ReciprocalToRealProjection
namespace pinkIndexer
{
class SimpleProjection : public ReciprocalToRealProjection
{
public:
SimpleProjection(const ExperimentSettings& experimentSettings);
void project(Eigen::Matrix2Xf& projectedPeaks, const Eigen::Matrix3Xf& reciprocalPeaks) const;
};
};
} // namespace pinkIndexer
\ No newline at end of file
......@@ -9,8 +9,10 @@
#include <string>
#include <vector>
class Sinogram
namespace pinkIndexer
{
class Sinogram
{
public:
Sinogram(const Lattice& lattice);
......@@ -42,4 +44,5 @@ class Sinogram
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
\ No newline at end of file
};
} // namespace pinkIndexer
\ No newline at end of file
......@@ -10,20 +10,18 @@
#include <CustomException.h>
//! A specialization of MyException.
/*!
* This exception is thrown whenever a function/method is used in a wrong way
*/
class WrongUsageException: public CustomException {
public:
WrongUsageException(const std::string& msg) :
CustomException(msg)
{
}
namespace pinkIndexer
{
virtual ~WrongUsageException() throw ()
class WrongUsageException : public CustomException
{
public:
WrongUsageException(const std::string& msg)
: CustomException(msg)
{
}
};
virtual ~WrongUsageException() throw() {}
};
} // namespace pinkIndexer
#endif /* WRONGUSAGEEXCEPTION_H_ */
......@@ -4,22 +4,25 @@
#include "Lattice.h"
#ifdef __cplusplus
extern "C" {
namespace pinkIndexer
{
extern "C" {
#endif
typedef struct ExperimentSettings ExperimentSettings;
typedef struct ExperimentSettings ExperimentSettings;
ExperimentSettings* ExperimentSettings_new_nolatt(float beamEenergy_eV, float detectorDistance_m, float detectorRadius_m, float divergenceAngle_deg,
ExperimentSettings* ExperimentSettings_new_nolatt(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* ExperimentSettings_new(float beamEenergy_eV, float detectorDistance_m, float detectorRadius_m, float divergenceAngle_deg,
ExperimentSettings* ExperimentSettings_new(float beamEenergy_eV, float detectorDistance_m, float detectorRadius_m, float divergenceAngle_deg,
float nonMonochromaticity, const Lattice_t sampleReciprocalLattice_1A, float tolerance,
float reflectionRadius_1_per_A);
void ExperimentSettings_delete(ExperimentSettings* experimentSettings);
void ExperimentSettings_delete(ExperimentSettings* experimentSettings);
#ifdef __cplusplus
}
}
#endif
......
......@@ -30,14 +30,17 @@ typedef struct
} LatticeTransform_t;
#ifdef __cplusplus
extern "C" {
namespace pinkIndexer
{
extern "C" {
#endif
void reorderLattice(const Lattice_t* prototype, Lattice_t* lattice);
void reduceLattice(Lattice_t* lattice, LatticeTransform_t* appliedReductionTransform);
void restoreLattice(Lattice_t* lattice, LatticeTransform_t* appliedReductionTransform);
void reorderLattice(const Lattice_t* prototype, Lattice_t* lattice);
void reduceLattice(Lattice_t* lattice, LatticeTransform_t* appliedReductionTransform);
void restoreLattice(Lattice_t* lattice, LatticeTransform_t* appliedReductionTransform);
#ifdef __cplusplus
}
}
#endif
......
......@@ -6,11 +6,13 @@
#include "indexerData.h"
#ifdef __cplusplus
extern "C" {
namespace pinkIndexer
{
extern "C" {
#endif
typedef enum
{
typedef enum
{
CONSIDERED_PEAKS_COUNT_veryFew = 0,
CONSIDERED_PEAKS_COUNT_few = 1,
CONSIDERED_PEAKS_COUNT_standard = 2,
......@@ -18,10 +20,10 @@ typedef enum
CONSIDERED_PEAKS_COUNT_manyMany = 4,
CONSIDERED_PEAKS_COUNT_lastEnum
} consideredPeaksCount_t;
} consideredPeaksCount_t;
typedef enum
{
typedef enum
{
ANGLE_RESOLUTION_extremelyLoose = 0,
ANGLE_RESOLUTION_loose = 1,
ANGLE_RESOLUTION_standard = 2,
......@@ -29,10 +31,10 @@ typedef enum
ANGLE_RESOLUTION_extremelyDense = 4,
ANGLE_RESOLUTION_lastEnum
} angleResolution_t;
} angleResolution_t;
typedef enum
{
typedef enum
{
REFINEMENT_TYPE_none = 0,
REFINEMENT_TYPE_fixedLatticeParameters = 1,
REFINEMENT_TYPE_variableLatticeParameters = 2,
......@@ -40,19 +42,21 @@ typedef enum
REFINEMENT_TYPE_firstFixedThenVariableLatticeParametersMultiSeed = 4,
REFINEMENT_TYPE_firstFixedThenVariableLatticeParametersCenterAdjustmentMultiSeed = 5,
REFINEMENT_TYPE_lastEnum
} refinementType_t;
} refinementType_t;
typedef struct PinkIndexer PinkIndexer;
typedef struct PinkIndexer PinkIndexer;
PinkIndexer* PinkIndexer_new(ExperimentSettings* experimentSettings, consideredPeaksCount_t consideredPeaksCount, angleResolution_t angleResolution,
PinkIndexer* PinkIndexer_new(ExperimentSettings* experimentSettings, consideredPeaksCount_t consideredPeaksCount, angleResolution_t angleResolution,
refinementType_t refinementType, float maxResolutionForIndexing_1_per_A);
void PinkIndexer_delete(PinkIndexer* pinkIndexer);
void PinkIndexer_delete(PinkIndexer* pinkIndexer);
int PinkIndexer_indexPattern(PinkIndexer* pinkIndexer, Lattice_t* indexedLattice, float centerShift[2], reciprocalPeaks_1_per_A_t* meanReciprocalPeaks_1_per_A,
const float* intensities, float maxRefinementDisbalance, int threadCount);
int PinkIndexer_indexPattern(PinkIndexer* pinkIndexer, Lattice_t* indexedLattice, float centerShift[2],
reciprocalPeaks_1_per_A_t* meanReciprocalPeaks_1_per_A, const float* intensities, float maxRefinementDisbalance,
int threadCount);
#ifdef __cplusplus
}
}
#endif
......
......@@ -6,20 +6,23 @@
#include "projectionData.h"
#ifdef __cplusplus
extern "C" {
namespace pinkIndexer
{
extern "C" {
#endif
typedef struct SimpleDiffractionPatternPrediction SimpleDiffractionPatternPrediction;
typedef struct SimpleDiffractionPatternPrediction SimpleDiffractionPatternPrediction;
SimpleDiffractionPatternPrediction* SimpleDiffractionPrediction_new(ExperimentSettings* experimentSettings);
void SimpleDiffractionPatternPrediction_delete(SimpleDiffractionPatternPrediction* simpleDiffractionPatternPrediction);
SimpleDiffractionPatternPrediction* SimpleDiffractionPrediction_new(ExperimentSettings* experimentSettings);
void SimpleDiffractionPatternPrediction_delete(SimpleDiffractionPatternPrediction* simpleDiffractionPatternPrediction);
void SDPP_getPeaksOnEwaldSphere(SimpleDiffractionPatternPrediction* simpleDiffractionPatternPrediction, reciprocalPeaks_1_per_A_t* reciprocalPeaks_1_per_A,
void SDPP_getPeaksOnEwaldSphere(SimpleDiffractionPatternPrediction* simpleDiffractionPatternPrediction, reciprocalPeaks_1_per_A_t* reciprocalPeaks_1_per_A,
Lattice_t lattice);
void SDPP_predictPattern(SimpleDiffractionPatternPrediction* simpleDiffractionPatternPrediction, millerIndices_t* millerIndices,
void SDPP_predictPattern(SimpleDiffractionPatternPrediction* simpleDiffractionPatternPrediction, millerIndices_t* millerIndices,
projectionDirections_t* projectionDirections, Lattice_t lattice);
#ifdef __cplusplus
}
}
#endif
......
......@@ -6,17 +6,20 @@
#include "projectionData.h"
#ifdef __cplusplus
extern "C" {
namespace pinkIndexer
{
extern "C" {
#endif
typedef struct SimpleProjection SimpleProjection;
typedef struct SimpleProjection SimpleProjection;
SimpleProjection* SimpleProjection_new(ExperimentSettings* experimentSettings);
void SimpleProjection_delete(SimpleProjection* simpleProjection);
SimpleProjection* SimpleProjection_new(ExperimentSettings* experimentSettings);
void SimpleProjection_delete(SimpleProjection* simpleProjection);
void project(SimpleProjection* simpleProjection, detectorPeaks_m_t* projectedPeaks_m, const reciprocalPeaks_1_per_A_t* reciprocalPeaks_1_per_A);
void project(SimpleProjection* simpleProjection, detectorPeaks_m_t* projectedPeaks_m, const reciprocalPeaks_1_per_A_t* reciprocalPeaks_1_per_A);
#ifdef __cplusplus
}
}
#endif
......
......@@ -8,44 +8,48 @@
#ifndef EIGENDISKIMPORT_H_
#define EIGENDISKIMPORT_H_
#include "BadInputException.h"
#include <Eigen/Dense>
#include <iterator>
#include <fstream>
#include <vector>
#include <algorithm>
#include "BadInputException.h"
#include <fstream>
#include <iterator>
#include <string.h>
#include <vector>
//matrix must be whitespace separated
template< typename T >
void loadEigenMatrixFromDisk(Eigen::DenseBase< T >& matrix, std::string path)
namespace pinkIndexer
{
// matrix must be whitespace separated
template <typename T>
void loadEigenMatrixFromDisk(Eigen::DenseBase<T>& matrix, std::string path)
{
std::ifstream file(path);
if (!file.is_open()) {
if (!file.is_open())
{
std::stringstream errStream;
errStream << "File " << path << " not found.";
throw BadInputException(errStream.str());
}
std::istream_iterator< typename T::RealScalar > startFile(file), end;
std::vector< typename T::RealScalar > numbers(startFile, end);
std::istream_iterator<typename T::RealScalar> startFile(file), end;
std::vector<typename T::RealScalar> numbers(startFile, end);
file.clear();
file.seekg(std::ios::beg);
std::string firstLine;
getline(file, firstLine);
std::istringstream iss(firstLine);
std::vector< typename T::RealScalar > firstLineNumbers(std::istream_iterator< typename T::RealScalar >(iss), end);
std::vector<typename T::RealScalar> firstLineNumbers(std::istream_iterator<typename T::RealScalar>(iss), end);
int cols = (int) firstLineNumbers.size();
int rows = (int) numbers.size() / cols;
int cols = (int)firstLineNumbers.size();
int rows = (int)numbers.size() / cols;
bool constexpr checkDynamicRows = T::RowsAtCompileTime != Eigen::Dynamic;
bool constexpr checkDynamicCols = T::ColsAtCompileTime != Eigen::Dynamic;
if (checkDynamicRows)
{
if (T::RowsAtCompileTime != rows) {
if (T::RowsAtCompileTime != rows)
{
std::stringstream errStream;