From df1594423cca0fbcb5820d43cdba5f9f6798e45e Mon Sep 17 00:00:00 2001 From: Reid Townson Date: Tue, 1 May 2018 09:22:33 -0400 Subject: [PATCH] Add egs_view vacuum color control Add control of the vacuum color and transparency in egs_view. Previously the vacuum regions were always transparent, but now it can be displayed. --- HEN_HOUSE/egs++/view/egs_visualizer.cpp | 33 +++++++++-- HEN_HOUSE/egs++/view/viewcontrol.cpp | 78 +++++++++++++++++-------- 2 files changed, 83 insertions(+), 28 deletions(-) diff --git a/HEN_HOUSE/egs++/view/egs_visualizer.cpp b/HEN_HOUSE/egs++/view/egs_visualizer.cpp index 88a663923..015099852 100644 --- a/HEN_HOUSE/egs++/view/egs_visualizer.cpp +++ b/HEN_HOUSE/egs++/view/egs_visualizer.cpp @@ -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; @@ -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; @@ -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; @@ -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; @@ -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]) { @@ -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) { @@ -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); } diff --git a/HEN_HOUSE/egs++/view/viewcontrol.cpp b/HEN_HOUSE/egs++/view/viewcontrol.cpp index 0682bf111..4aa761881 100644 --- a/HEN_HOUSE/egs++/view/viewcontrol.cpp +++ b/HEN_HOUSE/egs++/view/viewcontrol.cpp @@ -405,7 +405,11 @@ void GeometryViewControl::saveConfig() { out << ":start material colors:" << endl; for (size_t i=0; igetMediumName(imed) == material) { - break; + if(material == "vacuum") { + imed = nmed; + } else { + for(imed = 0; imedgetMediumName(imed) == material) { + break; + } } } @@ -704,7 +712,7 @@ void GeometryViewControl::loadConfig(QString configFilename) { // Update swatches in the combo box QPixmap pixmap(10,10); - for (int j=0; jsetItemIcon(j,pixmap); } @@ -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; jinsertItem(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; jgetMediumName(j); - unsigned int i; - for (i=0; igetMediumName(j); + unsigned int i; + for (i=0; i= 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; jsetItemIcon(j,pixmap); } @@ -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(); - for (int j=0; jsetItem(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 @@ -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 @@ -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; @@ -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) {