Skip to content

Commit

Permalink
Merge pull request #57 from prism-em/topic/formatting
Browse files Browse the repository at this point in the history
Improve formatting
  • Loading branch information
lerandc authored Jul 2, 2019
2 parents 6c25c29 + f3bb258 commit 6c1a2da
Show file tree
Hide file tree
Showing 37 changed files with 6,447 additions and 5,745 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ cmake-build-debug/
*.mexa*
*.txt
*.mrc

**/.vscode/
2 changes: 1 addition & 1 deletion Qt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ int main(int argc, char *argv[])
a.setFont(font);
PRISMMainWindow w;
w.show();
w.setGeometry(100,100,850,700);
w.setGeometry(100, 100, 850, 700);
return a.exec();
}
109 changes: 58 additions & 51 deletions Qt/prism_colormapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,72 @@
#include <cmath>
#include <iostream>
#include <map>
namespace Prismatic{
namespace Prismatic
{

void Colormapper::setColormap(const Colormap& cmap){this->colormap = cmap;}
void Colormapper::setColormap(const Colormap &cmap) { this->colormap = cmap; }

QRgb Colormapper::getColor(const double value, const double contrastMin, const double contrastMax) {
QRgb Colormapper::getColor(const double value, const double contrastMin, const double contrastMax)
{

Color<double> color_fraction;
Color<unsigned char> c;
// std::cout << "value " << value << std::endl;
// std::cout << "contrastMax " << contrastMax << std::endl;
// std::cout << "contrastMin " << contrastMin << std::endl;
if (value <= contrastMin){
// use first color in colormap
color_fraction = this->colormap[0];
Color<double> color_fraction;
Color<unsigned char> c;
// std::cout << "value " << value << std::endl;
// std::cout << "contrastMax " << contrastMax << std::endl;
// std::cout << "contrastMin " << contrastMin << std::endl;
if (value <= contrastMin)
{
// use first color in colormap
color_fraction = this->colormap[0];

// convert to uint8
c = Color<unsigned char>{(unsigned char)(color_fraction.r * 255.0),
(unsigned char)(color_fraction.g * 255.0),
(unsigned char)(color_fraction.b * 255.0)};
} else if (value >= contrastMax){
// use last color in colormap
color_fraction = this->colormap[this->colormap.size() - 1];
// convert to uint8
c = Color<unsigned char>{(unsigned char)(color_fraction.r * 255.0),
(unsigned char)(color_fraction.g * 255.0),
(unsigned char)(color_fraction.b * 255.0)};
}
else if (value >= contrastMax)
{
// use last color in colormap
color_fraction = this->colormap[this->colormap.size() - 1];

// convert to uint8
c = Color<unsigned char>{(unsigned char)(color_fraction.r * 255.0),
(unsigned char)(color_fraction.g * 255.0),
(unsigned char)(color_fraction.b * 255.0)};
} else{
// linearly interpolate the color value based upon the two nearest positional neighbors
// convert to uint8
c = Color<unsigned char>{(unsigned char)(color_fraction.r * 255.0),
(unsigned char)(color_fraction.g * 255.0),
(unsigned char)(color_fraction.b * 255.0)};
}
else
{
// linearly interpolate the color value based upon the two nearest positional neighbors

// determine what fraction of max value the value is
float fractional_pos = (value - contrastMin) / (contrastMax - contrastMin);
// determine what fraction of max value the value is
float fractional_pos = (value - contrastMin) / (contrastMax - contrastMin);

// map this fraction to a color (or decimal index between two colors)
float colorIndex = fractional_pos * (this->colormap.size() - 1);
// map this fraction to a color (or decimal index between two colors)
float colorIndex = fractional_pos * (this->colormap.size() - 1);

// determine the two relevant colors
int lowerColorIndex = (int)std::floor(colorIndex);
int upperColorIndex = (int)std::ceil(colorIndex);
Color<double> cLow, cHigh;
cLow = this->colormap[lowerColorIndex];
cHigh = this->colormap[upperColorIndex];
// determine the two relevant colors
int lowerColorIndex = (int)std::floor(colorIndex);
int upperColorIndex = (int)std::ceil(colorIndex);
Color<double> cLow, cHigh;
cLow = this->colormap[lowerColorIndex];
cHigh = this->colormap[upperColorIndex];

// determine the weights
double weight1, weight2;
weight2 = colorIndex - (float)lowerColorIndex;
weight1 = 1-weight2;
// std::cout << "weight1 = " << weight1 << std::endl;
// std::cout << "weight2 = " << weight2 << std::endl;
// std::cout << "lowerColorIndex = " << lowerColorIndex << std::endl;
// std::cout << "upperColorIndex = " << upperColorIndex << std::endl;
// determine the weights
double weight1, weight2;
weight2 = colorIndex - (float)lowerColorIndex;
weight1 = 1 - weight2;
// std::cout << "weight1 = " << weight1 << std::endl;
// std::cout << "weight2 = " << weight2 << std::endl;
// std::cout << "lowerColorIndex = " << lowerColorIndex << std::endl;
// std::cout << "upperColorIndex = " << upperColorIndex << std::endl;

// make the interpolated color
c = Color<unsigned char>{(unsigned char)( (weight1*cLow.r + weight2*cHigh.r) * 255.0),
(unsigned char)( (weight1*cLow.g + weight2*cHigh.g) * 255.0),
(unsigned char)( (weight1*cLow.b + weight2*cHigh.b) * 255.0)};
}
return qRgba(c.r, c.g, c.b, 255);
// return qRgba(0, 0, 0, 255);
}

// make the interpolated color
c = Color<unsigned char>{(unsigned char)((weight1 * cLow.r + weight2 * cHigh.r) * 255.0),
(unsigned char)((weight1 * cLow.g + weight2 * cHigh.g) * 255.0),
(unsigned char)((weight1 * cLow.b + weight2 * cHigh.b) * 255.0)};
}
return qRgba(c.r, c.g, c.b, 255);
// return qRgba(0, 0, 0, 255);
}

} // namespace Prismatic
104 changes: 56 additions & 48 deletions Qt/prism_progressbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,106 +14,114 @@
#include "prism_progressbar.h"
#include "ui_prism_progressbar.h"
#include <algorithm>
prism_progressbar::prism_progressbar(PRISMMainWindow *_parent) :
parent(_parent),
ui(new Ui::prism_progressbar),
potentialCurrentSlice(-1),
potentialTotalSlices(0),
SMatrixCurrentBeam(-1),
SMatrixTotalBeams(0),
currentProbe(0),
totalProbes(0)
prism_progressbar::prism_progressbar(PRISMMainWindow *_parent) : parent(_parent),
ui(new Ui::prism_progressbar),
potentialCurrentSlice(-1),
potentialTotalSlices(0),
SMatrixCurrentBeam(-1),
SMatrixTotalBeams(0),
currentProbe(0),
totalProbes(0)
{
ui->setupUi(this);
ui->progressBar->setValue(0);
connect(this, SIGNAL(updateDescriptionMessage(QString)), this, SLOT(updateDescription(QString)));
connect(this, SIGNAL(updateCalcStatus(QString)), this, SLOT(updateCalcStatusMessage(QString)));
connect(this, SIGNAL(updateProgressBar(int)), ui->progressBar, SLOT(setValue(int)));

connect(this, SIGNAL(updateProgressBar(int)), ui->progressBar, SLOT(setValue(int)));
}

void prism_progressbar::setStepPotential(){
void prism_progressbar::setStepPotential()
{
ui->lbl_Description->setText(QString("Computing Projected Potential Slices"));
}

void prism_progressbar::setTitle(const QString str){
void prism_progressbar::setTitle(const QString str)
{
ui->lbl_Algorithm->setText(str);
}


//void prism_progressbar::setAlgorithmPRISM(){
// ui->lbl_calcStatus->setText("Computing Projected Potential Slices");
//}

void prism_progressbar::update_calculatingPotential(long current, long total){
void prism_progressbar::update_calculatingPotential(long current, long total)
{
potentialCurrentSlice = std::max(potentialCurrentSlice, current);
ui->lbl_calcStatus->setText(QString("Slice ") +
QString::number(current + 1) +
QString("/") +
QString::number(total));
QString::number(current + 1) +
QString("/") +
QString::number(total));
}

void prism_progressbar::updateDescription(const QString str){
void prism_progressbar::updateDescription(const QString str)
{
ui->lbl_Description->setText(str);
}
//void prism_progressbar::setText(const QString str){
// ui->lbl_Description->setText(str);
//}
void prism_progressbar::setProgress(int val){
emit updateProgressBar(val);
void prism_progressbar::setProgress(int val)
{
emit updateProgressBar(val);
}
void prism_progressbar::updateCalcStatusMessage(const QString str){
void prism_progressbar::updateCalcStatusMessage(const QString str)
{
ui->lbl_calcStatus->setText(str);
}
void prism_progressbar::signalCalcStatusMessage(const QString str){
void prism_progressbar::signalCalcStatusMessage(const QString str)
{
emit updateCalcStatus(str);
}
void prism_progressbar::signalDescriptionMessage(const QString str){
void prism_progressbar::signalDescriptionMessage(const QString str)
{
emit updateDescriptionMessage(str);
}

void prism_progressbar::signalPotentialUpdate(const long current, const long total){
// std::lock_guard<std::mutex> gatekeeper(this->parent->potentialLock);
potentialCurrentSlice = std::max(potentialCurrentSlice, current);
emit updateCalcStatus(QString("Slice ") +
QString::number(potentialCurrentSlice + 1) +
QString("/") +
QString::number(total));
emit updateProgressBar(100*(current+1)/total);
void prism_progressbar::signalPotentialUpdate(const long current, const long total)
{
// std::lock_guard<std::mutex> gatekeeper(this->parent->potentialLock);
potentialCurrentSlice = std::max(potentialCurrentSlice, current);
emit updateCalcStatus(QString("Slice ") +
QString::number(potentialCurrentSlice + 1) +
QString("/") +
QString::number(total));
emit updateProgressBar(100 * (current + 1) / total);
}
void prism_progressbar::signalScompactUpdate(const long current, const long total){
// std::lock_guard<std::mutex> gatekeeper(this->parent->sMatrixLock);
void prism_progressbar::signalScompactUpdate(const long current, const long total)
{
// std::lock_guard<std::mutex> gatekeeper(this->parent->sMatrixLock);
SMatrixCurrentBeam = std::max(SMatrixCurrentBeam, current);
// std::cout << "SMatrixCurrentBeam + 1 = " << SMatrixCurrentBeam + 1 << std::endl;
// std::cout << "SMatrixCurrentBeam + 1 = " << SMatrixCurrentBeam + 1 << std::endl;
emit updateCalcStatus(QString("Plane Wave ") +
QString::number(SMatrixCurrentBeam + 1) +
QString("/") +
QString::number(total));
emit updateProgressBar(100*(SMatrixCurrentBeam+1)/total);
emit updateProgressBar(100 * (SMatrixCurrentBeam + 1) / total);
}

void prism_progressbar::resetOutputs(){
void prism_progressbar::resetOutputs()
{
currentProbe = 0;
SMatrixCurrentBeam = 0;
potentialCurrentSlice = 0;
// std::cout << "SMatrixCurrentBeam + 1 = " << SMatrixCurrentBeam + 1 << std::endl;
// emit updateCalcStatus(QString("Probe Position ") +
// QString::number(currentProbe + 1) +
// QString("/") +
// QString::number(total));
// emit updateProgressBar(100*(currentProbe+1)/total);
// std::cout << "SMatrixCurrentBeam + 1 = " << SMatrixCurrentBeam + 1 << std::endl;
// emit updateCalcStatus(QString("Probe Position ") +
// QString::number(currentProbe + 1) +
// QString("/") +
// QString::number(total));
// emit updateProgressBar(100*(currentProbe+1)/total);
emit updateProgressBar(0);

}
void prism_progressbar::signalOutputUpdate(const long current, const long total){
// std::lock_guard<std::mutex> gatekeeper(this->parent->outputLock);
void prism_progressbar::signalOutputUpdate(const long current, const long total)
{
// std::lock_guard<std::mutex> gatekeeper(this->parent->outputLock);
currentProbe = std::max(currentProbe, current);
// std::cout << "SMatrixCurrentBeam + 1 = " << SMatrixCurrentBeam + 1 << std::endl;
// std::cout << "SMatrixCurrentBeam + 1 = " << SMatrixCurrentBeam + 1 << std::endl;
emit updateCalcStatus(QString("Probe Position ") +
QString::number(currentProbe + 1) +
QString("/") +
QString::number(total));
emit updateProgressBar(100*(currentProbe+1)/total);
emit updateProgressBar(100 * (currentProbe + 1) / total);
}

prism_progressbar::~prism_progressbar()
Expand Down
Loading

0 comments on commit 6c1a2da

Please sign in to comment.