Skip to content

Commit

Permalink
Merge pull request #48 from aglowacki/master
Browse files Browse the repository at this point in the history
Templated classes merge
  • Loading branch information
Arthur Glowacki authored May 17, 2022
2 parents b46f69a + a458a2e commit c08655e
Show file tree
Hide file tree
Showing 35 changed files with 348 additions and 337 deletions.
22 changes: 15 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,20 @@ project(uProbeX)
#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/" ${PROJECT_SOURCE_DIR}/cmake "c:/Qt/5.15.0/msvc2019_64/lib/cmake/Qt5" "c:/Qt/5.11.1/msvc2017_64/lib/cmake/Qt5" ${PROJECT_SOURCE_DIR}/../XRF-Maps/build)
#set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${PROJECT_SOURCE_DIR}/../XRF-Maps/build )

option(BUILD_WITH_TIRPC "Build tripc library for libxrpc (RedHat 8)" OFF)

IF(UNIX)
IF(BUILD_WITH_TIRPC)
set(GCC_INCLUDE_DIR "/usr/include/tirpc/" CACHE PATH "include folder for xrpc (red hat)")
include_directories(${GCC_INCLUDE_DIR})
ENDIF()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake/linux)
ENDIF()

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(PREC _REAL_FLOAT)

# If compiled on some intel mahcines this causes crashes so let user set it for compile
option(AVX2 "Compule with arch AVX2 on MSVC" OFF)
Expand All @@ -72,7 +81,7 @@ find_package(Threads)
find_package(hdf5 CONFIG REQUIRED)
find_package(netCDF CONFIG REQUIRED)
find_package(yaml-cpp CONFIG REQUIRED)
find_package(ZeroMQ REQUIRED libzmq-static)
find_package(ZeroMQ CONFIG REQUIRED)
find_package(XRF_Maps CONFIG REQUIRED COMPONENTS libxrf_io libxrf_fit)

if (libxrf_fit_FOUND)
Expand Down Expand Up @@ -117,8 +126,8 @@ include(CheckCXXCompilerFlag)

IF (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
# Enable C++11 mode on C++ / Clang
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -D__Unix__ -D${PREC} -fPIC -g -fopenmp")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__Unix__ -D${PREC} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -D__Unix__ -fPIC -g -fopenmp")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__Unix__ -fPIC")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
Expand Down Expand Up @@ -147,7 +156,7 @@ IF(MSVC)
ELSE()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
ENDIF()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DHDF5CPP_USEDLL /D_USE_MATH_DEFINES /DH5_BUILT_AS_DYNAMIC_LIB /D_HDF5USEDLL_ /DBUILDING_DLL /DXDR_HACK /DXDR_LE /D${PREC} /DNOMINMAX /openmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DHDF5CPP_USEDLL /D_USE_MATH_DEFINES /DH5_BUILT_AS_DYNAMIC_LIB /D_HDF5USEDLL_ /DBUILDING_DLL /DXDR_HACK /DXDR_LE /DNOMINMAX /openmp")
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -Waddress -Warray-bounds=1 -Wbool-compare -Wbool-operation -Wc++11-compat -Wc++14-compat -Wcatch-value -Wchar-subscripts -Wcomment -Wduplicate-decl-specifier -Wenum-compare -Wformat -Wimplicit -Wimplicit-int -Wimplicit-function-declaration -Winit-self -Wlogical-not-parentheses -Wmain -Wmaybe-uninitialized -Wmemset-elt-size -Wmemset-transposed-args -Wmisleading-indentation -Wmissing-attributes -Wmissing-braces -Wmultistatement-macros -Wnarrowing -Wnonnull -Wnonnull-compare -Wopenmp-simd -Wparentheses -Wpointer-sign -Wreorder -Wrestrict -Wreturn-type -Wsequence-point -Wsign-compare -Wsizeof-pointer-div -Wsizeof-pointer-memaccess -Wstrict-aliasing -Wstrict-overflow=1 -Wswitch -Wtautological-compare -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wunused-function -Wunused-label -Wunused-value -Wunused-variable -Wvolatile-register-var")
Expand Down Expand Up @@ -208,12 +217,11 @@ ELSEIF (UNIX)
set_target_properties(uProbeX PROPERTIES COMPILE_FLAGS "-O3")

target_link_libraries (uProbeX PRIVATE
libzmq-static
libzmq
yaml-cpp
${Qt5Core_LIBRARIES}
${Qt5Charts_LIBRARIES}
netCDF::netcdf
hdf5::hdf5-shared
libxrf_fit
libxrf_io
${CMAKE_THREAD_LIBS_INIT} )
Expand Down
13 changes: 6 additions & 7 deletions src/core/uProbeX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ uProbeX::uProbeX(QWidget* parent, Qt::WindowFlags flags) : QMainWindow(parent, f
// Update preferences; also creates solver
processPreferencesUpdate();

if (false == io::load_scalers_lookup(scaler_lookup_yaml))
if (false == io::file::load_scalers_lookup(scaler_lookup_yaml))
{
logE << " Could not load " << scaler_lookup_yaml << ". Won't be able to translate from PV to Label for scalers!\n";
}


if (false == io::load_element_info(element_henke_filename, element_csv_filename ) )
if (false == io::file::load_element_info<double>(element_henke_filename, element_csv_filename ) )
{
QString msg = QString("Error loading ");
msg += QString(element_henke_filename.c_str());
Expand All @@ -94,7 +94,6 @@ uProbeX::uProbeX(QWidget* parent, Qt::WindowFlags flags) : QMainWindow(parent, f
QMessageBox::critical(this, "Warning", msg);
}


// Creat MDI window
m_mdiArea = new QMdiArea();

Expand Down Expand Up @@ -524,11 +523,11 @@ void uProbeX::open_spectra_and_override_file()
"Override Params", ".",
"TXT (*.txt *.txt0 *.txt1 *.txt2 *.txt3)");

data_struct::Params_Override* po = nullptr;
data_struct::Params_Override<double>* po = nullptr;
if (false == (fileName.isNull() || fileName.isEmpty()))
{
po = new data_struct::Params_Override();
if (false == io::load_override_params(po_fileName.toStdString(), -1, po, false))
po = new data_struct::Params_Override<double>();
if (false == io::file::load_override_params(po_fileName.toStdString(), -1, po, false))
{
delete po;
po = nullptr;
Expand All @@ -539,7 +538,7 @@ void uProbeX::open_spectra_and_override_file()

/*---------------------------------------------------------------------------*/

void uProbeX::make_spectra_window(QString path, data_struct::Params_Override* po)
void uProbeX::make_spectra_window(QString path, data_struct::Params_Override<double>* po)
{
RAW_Model* model = new RAW_Model();
if (model->load(path))
Expand Down
2 changes: 1 addition & 1 deletion src/core/uProbeX.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private slots:

void open_spectra_and_override_file();

void make_spectra_window(QString path, data_struct::Params_Override* po);
void make_spectra_window(QString path, data_struct::Params_Override<double>* po);

void open_VLM_File();

Expand Down
4 changes: 2 additions & 2 deletions src/gstar/ContrastDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ ContrastDialog::~ContrastDialog()

}

void ContrastDialog::set_array(const data_struct::ArrayXXr* arr)
void ContrastDialog::set_array(const data_struct::ArrayXXr<float>* arr)
{
if (arr != nullptr)
{
_arr = arr;
_min_max_slider->setMinMax(_arr->minCoeff(), _arr->maxCoeff());

data_struct::ArrayXr pts;
data_struct::ArrayTr<float> pts;
int w = arr->rows();
int h = arr->cols();
pts.resize(w * h);
Expand Down
4 changes: 2 additions & 2 deletions src/gstar/ContrastDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace gstar

~ContrastDialog();

void set_array(const data_struct::ArrayXXr* arr);
void set_array(const data_struct::ArrayXXr<float>* arr);

signals:
void on_min_max_update(float min, float max);
Expand All @@ -53,7 +53,7 @@ public slots:

QPushButton* _btn_cancel;

const data_struct::ArrayXXr* _arr;
const data_struct::ArrayXXr<float>* _arr;

};

Expand Down
2 changes: 1 addition & 1 deletion src/gstar/CountsLookupTransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ QMap<QString, double> CountsLookupTransformer::getAllCoef()

/*---------------------------------------------------------------------------*/

void CountsLookupTransformer::setCounts(const data_struct::ArrayXXr& counts)
void CountsLookupTransformer::setCounts(const data_struct::ArrayXXr<float>& counts)
{
_counts_arr = counts;
_min_counts = _counts_arr.minCoeff();
Expand Down
6 changes: 3 additions & 3 deletions src/gstar/CountsLookupTransformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CountsLookupTransformer : public ITransformer
*/
virtual bool setVariable(QString name, double val);

void setCounts(const data_struct::ArrayXXr &counts);
void setCounts(const data_struct::ArrayXXr<float> &counts);

/**
* @brief transformCommand
Expand All @@ -81,7 +81,7 @@ class CountsLookupTransformer : public ITransformer
double *outY,
double *outZ);

const data_struct::ArrayXXr* get_count_array() { return &_counts_arr; }
const data_struct::ArrayXXr<float>* get_count_array() { return &_counts_arr; }

protected:

Expand All @@ -95,7 +95,7 @@ class CountsLookupTransformer : public ITransformer

int _cols;

data_struct::ArrayXXr _counts_arr;
data_struct::ArrayXXr<float> _counts_arr;
};

}
Expand Down
4 changes: 2 additions & 2 deletions src/gstar/HistogramPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ qreal HistogramPlot::ymap(const qreal& value)

/*---------------------------------------------------------------------------*/

void HistogramPlot::updatePoints(const data_struct::ArrayXr& pts)
void HistogramPlot::updatePoints(const data_struct::ArrayTr<float>& pts)
{

_minCoef = pts.minCoeff();
Expand All @@ -149,7 +149,7 @@ void HistogramPlot::updatePoints(const data_struct::ArrayXr& pts)
_min_line = _minCoef;
_max_line = _maxCoef;

_bin_width = (_maxCoef - _minCoef) / (real_t)(_n_bins-1);
_bin_width = (_maxCoef - _minCoef) / (_n_bins-1);
for (int i = 0; i < pts.size(); i++)
{
int bin = std::floor( (pts(i) - _minCoef) / _bin_width);
Expand Down
8 changes: 4 additions & 4 deletions src/gstar/HistogramPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public slots:
/**
* Update points
*/
void updatePoints(const data_struct::ArrayXr& pts);
void updatePoints(const data_struct::ArrayTr<float>& pts);

private:
/**
Expand Down Expand Up @@ -77,11 +77,11 @@ public slots:

QPen _max_pen;

real_t _minCoef;
float _minCoef;

real_t _maxCoef;
float _maxCoef;

real_t _bin_width;
float _bin_width;
};

}
Expand Down
38 changes: 19 additions & 19 deletions src/mvc/FitElementsTableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,41 +70,41 @@ void FitElementsTableModel::update_counts_log10(bool is_log10)

/*---------------------------------------------------------------------------*/

data_struct::Fit_Element_Map_Dict FitElementsTableModel::getElementsToFit()
data_struct::Fit_Element_Map_Dict<double> FitElementsTableModel::getElementsToFit()
{
data_struct::Fit_Element_Map_Dict elements_to_fit;
data_struct::Fit_Element_Map_Dict<double> elements_to_fit;
for (auto& itr : _nodes)
{
TreeItem* node = itr.second;
data_struct::Fit_Element_Map *element = node->element_data;
data_struct::Fit_Element_Map<double>*element = node->element_data;
elements_to_fit[element->full_name()] = element;
}
return elements_to_fit;
}

/*---------------------------------------------------------------------------*/

data_struct::Fit_Parameters FitElementsTableModel::getAsFitParams()
data_struct::Fit_Parameters<double> FitElementsTableModel::getAsFitParams()
{
data_struct::Fit_Parameters fit_params;
data_struct::Fit_Parameters<double> fit_params;
for(auto& itr : _nodes)
{
TreeItem* node = itr.second;
data_struct::Fit_Element_Map *element = node->element_data;
fit_params.add_parameter(data_struct::Fit_Param(element->full_name(), node->itemData[1].toFloat(), data_struct::E_Bound_Type::FIT));
data_struct::Fit_Element_Map<double>* element = node->element_data;
fit_params.add_parameter(data_struct::Fit_Param<double>(element->full_name(), node->itemData[1].toDouble(), data_struct::E_Bound_Type::FIT));
}
return fit_params;
}

/*---------------------------------------------------------------------------*/

void FitElementsTableModel::updateElementValues(data_struct::Fit_Parameters *fit_params)
void FitElementsTableModel::updateElementValues(data_struct::Fit_Parameters<double>*fit_params)
{

for(auto& itr : _nodes)
{
TreeItem* node = itr.second;
data_struct::Fit_Element_Map *element = node->element_data;
data_struct::Fit_Element_Map<double>* element = node->element_data;
if(fit_params->contains(element->full_name()))
{
node->itemData[1] = QVariant(fit_params->at(element->full_name()).value);
Expand All @@ -127,7 +127,7 @@ int FitElementsTableModel::columnCount(const QModelIndex &parent) const

/*---------------------------------------------------------------------------*/

void FitElementsTableModel::updateFitElements(data_struct::Fit_Element_Map_Dict * elements_to_fit)
void FitElementsTableModel::updateFitElements(data_struct::Fit_Element_Map_Dict<double>* elements_to_fit)
{
if(elements_to_fit != nullptr)
{
Expand All @@ -139,14 +139,14 @@ void FitElementsTableModel::updateFitElements(data_struct::Fit_Element_Map_Dict
_nodes.clear();
for(auto& itr : *elements_to_fit)
{
data_struct::Fit_Element_Map* element = itr.second;
if(data_struct::Element_Info_Map::inst()->contains(element->symbol()))
data_struct::Fit_Element_Map<double>* element = itr.second;
if(data_struct::Element_Info_Map<double>::inst()->contains(element->symbol()))
{
int idx = element->Z();
const std::string el_name = element->full_name();
int found_L = el_name.find("_L");
int found_M = el_name.find("_M");
const data_struct::Element_Info* pileup = element->pileup_element();
const data_struct::Element_Info<double>* pileup = element->pileup_element();
if(found_L > 0)
{
idx += 1000;
Expand Down Expand Up @@ -193,15 +193,15 @@ QString FitElementsTableModel::element_at_row(int row)

/*---------------------------------------------------------------------------*/

void FitElementsTableModel::appendElement(data_struct::Fit_Element_Map* element)
void FitElementsTableModel::appendElement(data_struct::Fit_Element_Map<double>* element)
{
if(data_struct::Element_Info_Map::inst()->contains(element->symbol()))
if(data_struct::Element_Info_Map<double>::inst()->contains(element->symbol()))
{
int idx = element->Z();
const std::string el_name = element->full_name();
int found_L = el_name.find("_L");
int found_M = el_name.find("_M");
const data_struct::Element_Info* pileup = element->pileup_element();
const data_struct::Element_Info<double>* pileup = element->pileup_element();
if(found_L > 0)
{
idx += 1000;
Expand Down Expand Up @@ -444,7 +444,7 @@ QModelIndex FitElementsTableModel::index(int row, int column, const QModelIndex

/*---------------------------------------------------------------------------*/

data_struct::Fit_Element_Map* FitElementsTableModel::getElementByIndex(QModelIndex index) const
data_struct::Fit_Element_Map<double>* FitElementsTableModel::getElementByIndex(QModelIndex index) const
{
if (index.isValid())
{
Expand Down Expand Up @@ -532,8 +532,8 @@ bool FitElementsTableModel::setData(const QModelIndex &index,
{
if (node->parentItem->element_data != nullptr)
{
node->parentItem->element_data->set_custom_multiply_ratio(index.row(), value.toFloat());
node->parentItem->element_data->init_energy_ratio_for_detector_element(data_struct::Element_Info_Map::inst()->get_element(_detector_element));
node->parentItem->element_data->set_custom_multiply_ratio(index.row(), value.toDouble());
node->parentItem->element_data->init_energy_ratio_for_detector_element(data_struct::Element_Info_Map<double>::inst()->get_element(_detector_element));
auto ratio_vec = node->parentItem->element_data->energy_ratios();
if (index.row() > 0 && index.row() < ratio_vec.size())
{
Expand Down
Loading

0 comments on commit c08655e

Please sign in to comment.