Skip to content

Commit

Permalink
Add egs_view vacuum color control
Browse files Browse the repository at this point in the history
Add control of the vacuum color and transparency in egs_view. Previously
the vacuum regions were always transparent, but now it can be displayed.
  • Loading branch information
rtownson committed May 1, 2018
1 parent 357346d commit df15944
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 28 deletions.
33 changes: 29 additions & 4 deletions HEN_HOUSE/egs++/view/egs_visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,15 @@ void EGS_PrivateVisualizer::getRegions(const EGS_Vector &x, EGS_BaseGeometry *g,
t -= tclip;
if (ireg >= 0) {
imed = g->medium(ireg);
if(imed < 0) {
imed = g->nMedia();
}
if (imed >= 0) {
c = mat[imed].d*mat[imed].alpha;
if(!allowRegionSelection || showReg[ireg]) {
c = mat[imed].d*mat[imed].alpha;
} else {
c = displayColors[0];
}
}
// save region
regions[regcount]=ireg;
Expand Down Expand Up @@ -383,8 +390,13 @@ void EGS_PrivateVisualizer::getRegions(const EGS_Vector &x, EGS_BaseGeometry *g,
if (ireg >= 0) {
tleft -= t;
xs += u*t;
if(imed < 0) {
imed = g->nMedia();
}
if (imed >= 0) {
c = mat[imed].d*mat[imed].alpha;
if(!allowRegionSelection || showReg[ireg]) {
c = mat[imed].d*mat[imed].alpha;
}
}
regions[regcount]=ireg;
colors[regcount]=c;
Expand Down Expand Up @@ -486,6 +498,9 @@ EGS_Vector EGS_PrivateVisualizer::getColor(const EGS_Vector &x,
// ray hits a region
if (ireg >= 0) {
imed = g->medium(ireg);
if(imed < 0) {
imed = g->nMedia();
}
if (imed >= 0) {
if(!allowRegionSelection || showReg[ireg]) {
a1 = mat[imed].alpha;
Expand Down Expand Up @@ -538,6 +553,9 @@ EGS_Vector EGS_PrivateVisualizer::getColor(const EGS_Vector &x,
// hitting a surface
if (inew >= 0) {
xs += u*t;
if(imed < 0) {
imed = g->nMedia();
}
if (imed >= 0) {
if(!allowRegionSelection || showReg[inew]) {
a1 = mat[imed].alpha;
Expand Down Expand Up @@ -597,6 +615,10 @@ EGS_Vector EGS_PrivateVisualizer::getColor(const EGS_Vector &x,
EGS_Vector c1;
xs += u*t;

if(imed_new < 0) {
imed_new = g->nMedia();
}

// new region is not outside, new material is not vacuum, and there is a change in material
if (inew >= 0 && imed_new >= 0 && (imed_new != imed || (allowRegionSelection && !showReg[ireg]))) {
if(!allowRegionSelection || showReg[inew]) {
Expand Down Expand Up @@ -661,8 +683,7 @@ bool EGS_PrivateVisualizer::renderImage(EGS_BaseGeometry *g, int nx, int ny, EGS
EGS_Float xx = -sx/2 + dx*(i+0.5);
EGS_Vector xp(xy + v1_screen*xx);

// Set the axis color
EGS_Vector bCol(displayColors[2].x,displayColors[2].y,displayColors[2].z);
EGS_Vector bCol(0,0,0);

ttrack = -1;
if (image) {
Expand Down Expand Up @@ -690,6 +711,10 @@ bool EGS_PrivateVisualizer::renderImage(EGS_BaseGeometry *g, int nx, int ny, EGS
if (image[idx].x == 3.0) {
bCol = displayColors[5];
}
// Axis
if (image[idx].x == 100.0) {
bCol = displayColors[2];
}
}
image[idx] = EGS_Vector(0,0,0);
}
Expand Down
78 changes: 54 additions & 24 deletions HEN_HOUSE/egs++/view/viewcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,11 @@ void GeometryViewControl::saveConfig() {
out << ":start material colors:" << endl;
for (size_t i=0; i<rp.material_colors.size(); ++i) {
out << " :start material:" << endl;
out << " material = " << g->getMediumName(i) << endl;
if(i==nmed) {
out << " material = vacuum" << endl;
} else {
out << " material = " << g->getMediumName(i) << endl;
}
out << " rgb = " << qRed(m_colors[i]) << " "
<< qGreen(m_colors[i]) << " "
<< qBlue(m_colors[i]) << endl;
Expand Down Expand Up @@ -678,9 +682,13 @@ void GeometryViewControl::loadConfig(QString configFilename) {

// Find the index of the material by the same name
int imed;
for(imed = 0; imed<nmed; ++imed) {
if(g->getMediumName(imed) == material) {
break;
if(material == "vacuum") {
imed = nmed;
} else {
for(imed = 0; imed<nmed; ++imed) {
if(g->getMediumName(imed) == material) {
break;
}
}
}

Expand All @@ -704,7 +712,7 @@ void GeometryViewControl::loadConfig(QString configFilename) {

// Update swatches in the combo box
QPixmap pixmap(10,10);
for (int j=0; j<nmed; j++) {
for (int j=0; j<=nmed; j++) {
pixmap.fill(m_colors[j]);
materialCB->setItemIcon(j,pixmap);
}
Expand Down Expand Up @@ -1348,31 +1356,38 @@ int GeometryViewControl::setGeometry(

// set up material combo box items
materialCB->clear();
m_colors = new QRgb [nmed];
m_colors = new QRgb [nmed+1]; // nmed+1 for vacuum
for (int j=0; j<nmed; j++) {
materialCB->insertItem(j,g->getMediumName(j));
}

// Always insert vacuum since it is not in the medium list
// The only way to check if it was in geometry would be to loop through
// every region and check if g->medium(ireg)==-1
materialCB->insertItem(nmed,"vacuum");

int nstandard = sizeof(standard_red)/sizeof(unsigned char);
int js = 0;
{
for (int j=0; j<nmed; j++) {
string med_name = g->getMediumName(j);
unsigned int i;
for (i=0; i<ucolors.size(); ++i) if (med_name == ucolors[i].medname) {
break;
}
if (i < ucolors.size()) {
m_colors[j] = qRgba(ucolors[i].red,ucolors[i].green,ucolors[i].blue,ucolors[i].alpha);
for (int j=0; j<nmed; j++) {
string med_name = g->getMediumName(j);
unsigned int i;
for (i=0; i<ucolors.size(); ++i) if (med_name == ucolors[i].medname) {
break;
}
else {
m_colors[j] = qRgba(standard_red[js], standard_green[js], standard_blue[js], 255);
if ((++js) >= nstandard) {
js = 0;
}
if (i < ucolors.size()) {
m_colors[j] = qRgba(ucolors[i].red,ucolors[i].green,ucolors[i].blue,ucolors[i].alpha);
}
else {
m_colors[j] = qRgba(standard_red[js], standard_green[js], standard_blue[js], 255);
if ((++js) >= nstandard) {
js = 0;
}
}
}

// Vacuum defaults to black, transparent
m_colors[nmed] = qRgba(0,0,0,0);

/*
if( nmed <= nstandard ) {
for(int j=0; j<nmed; j++) m_colors[j] = qRgba(standard_red[j], standard_green[j], standard_blue[j], 255);
Expand Down Expand Up @@ -1404,7 +1419,7 @@ int GeometryViewControl::setGeometry(
// add swatches in the combo box
QPixmap pixmap(10,10);
{
for (int j=0; j<nmed; j++) {
for (int j=0; j<=nmed; j++) {
pixmap.fill(m_colors[j]);
materialCB->setItemIcon(j,pixmap);
}
Expand Down Expand Up @@ -1635,7 +1650,7 @@ void GeometryViewControl::updateView(bool transform) {
rp.lights.push_back(EGS_Light(p_light, EGS_Vector(1,1,1)));

rp.material_colors = vector<EGS_MaterialColor>();
for (int j=0; j<nmed; j++) {
for (int j=0; j<=nmed; j++) {
EGS_Float r = ((EGS_Float) qRed(m_colors[j]))/255.;
EGS_Float gr = ((EGS_Float) qGreen(m_colors[j]))/255.;
EGS_Float b = ((EGS_Float) qBlue(m_colors[j]))/255.;
Expand Down Expand Up @@ -1925,7 +1940,11 @@ void GeometryViewControl::updateRegionTable() {
colorItem = new QTableWidgetItem();
regionTable->setItem(i,1,colorItem);
}
colorItem->setBackground(QBrush(QColor(m_colors[imed])));
if(imed < 0) {
colorItem->setBackground(QBrush(QColor(m_colors[nmed])));
} else {
colorItem->setBackground(QBrush(QColor(m_colors[imed])));
}
colorItem->setFlags(colorItem->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsSelectable);

// Set the material name
Expand All @@ -1934,7 +1953,11 @@ void GeometryViewControl::updateRegionTable() {
matItem = new QTableWidgetItem();
regionTable->setItem(i,2,matItem);
}
matItem->setText(QString(g->getMediumName(imed)));
if(imed < 0) {
matItem->setText(QString("vacuum"));
} else {
matItem->setText(QString(g->getMediumName(imed)));
}
matItem->setFlags(matItem->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsSelectable);

// Set the show/hide checkbox
Expand Down Expand Up @@ -1965,6 +1988,9 @@ void GeometryViewControl::updateRegionTable(int imedToChange) {
if(g->isRealRegion(ireg)) {
int imed = g->medium(ireg);

if(imed < 0) {
imed = nmed;
}
if(imed != imedToChange) {
++i;
continue;
Expand Down Expand Up @@ -2011,6 +2037,10 @@ void GeometryViewControl::toggleRegion(int i, int j) {
if(j == 0) {
int imed = g->medium(ireg);

if(imed < 0) {
imed = nmed;
}

// Set the material color
QTableWidgetItem *colorItem = regionTable->item(i,1);
if(!colorItem) {
Expand Down

0 comments on commit df15944

Please sign in to comment.