Skip to content

Commit d9d128d

Browse files
authored
Add a checkbox for toggling opacity in 3d redering (#35)
By default, regions with higher density region have higher opacity. In the current implementation, there is no option to change this behavior. At least, I cannot find it. So I added a checkbox for inverting the opacity mapping. This is useful when the high-density region is outside the main volume.
1 parent 6ebba97 commit d9d128d

File tree

6 files changed

+32
-2
lines changed

6 files changed

+32
-2
lines changed

Docs/Amrvis.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ \subsubsection{Interface Controls}
294294
to draw.
295295
\item [Autodraw] Automatically render the image while rotating.
296296
As with {\bf Draw}, the first image takes longer.
297+
\item [Invert Opacity] Useful when high-density regions are outside the volume.
297298
\item [Trans] Reread the transfer functions.
298299
\item [Lights] Allows the user to set the rendering lighting parameters.
299300
\item[Light/Value] This menu shows the volume rendering

PltApp.H

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ private:
162162
Widget wAttach, wDetachTopLevel;
163163
#if defined(BL_VOLUMERENDER) || defined(BL_PARALLELVOLUMERENDER)
164164
Widget wAutoDraw;
165+
Widget wInvertOpacity;
165166
Widget wLWambient, wLWdiffuse, wLWspecular, wLWshiny;
166167
Widget wLWminOpacity, wLWmaxOpacity;
167168
Widget wCurrentRenderMode, wCurrentClassify;
@@ -229,7 +230,7 @@ private:
229230
ProjectionPicture *projPicturePtr;
230231
ViewTransform viewTrans;
231232
bool lightingModel, showing3dRender, preClassify, lightingWindowExists;
232-
233+
bool invert_opacity = false;
233234
#endif
234235

235236
void PltAppInit(bool bSubVolume = false); // called by constructors
@@ -308,6 +309,7 @@ private:
308309
void DoRenderModeMenu(Widget, XtPointer, XtPointer);
309310
void DoClassifyMenu(Widget, XtPointer, XtPointer);
310311
void DoAutoDraw(Widget, XtPointer, XtPointer);
312+
void SetInvertOpacity(Widget, XtPointer, XtPointer);
311313
void DoCreateLightingWindow(Widget, XtPointer, XtPointer);
312314
void DoDoneLightingWindow(Widget, XtPointer, XtPointer);
313315
void DoApplyLightingWindow(Widget, XtPointer, XtPointer);

PltApp.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,11 @@ void PltApp::PltAppInit(bool bSubVolume) {
11331133
XtVaCreateManagedWidget("Autodraw", xmToggleButtonGadgetClass, wMenuPulldown,
11341134
XmNmnemonic, 'A', XmNset, false, NULL);
11351135
AddStaticCallback(wAutoDraw, XmNvalueChangedCallback, &PltApp::DoAutoDraw);
1136+
1137+
wInvertOpacity =
1138+
XtVaCreateManagedWidget("Invert Opacity", xmToggleButtonGadgetClass, wMenuPulldown,
1139+
XmNmnemonic, 'I', XmNset, false, NULL);
1140+
AddStaticCallback(wInvertOpacity, XmNvalueChangedCallback, &PltApp::SetInvertOpacity);
11361141

11371142
wid = XtVaCreateManagedWidget("Lighting...",
11381143
xmPushButtonGadgetClass, wMenuPulldown,

PltApp3D.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,20 @@ void PltApp::DoAutoDraw(Widget, XtPointer, XtPointer) {
782782
DoExposeTransDA();
783783
}
784784

785+
// -------------------------------------------------------------------
786+
void PltApp::SetInvertOpacity(Widget, XtPointer, XtPointer) {
787+
if(XmToggleButtonGetState(wInvertOpacity)) {
788+
invert_opacity = true;
789+
} else {
790+
invert_opacity = false;
791+
}
792+
VolRender *volRenderPtr = projPicturePtr->GetVolRenderPtr();
793+
if (volRenderPtr && volRenderPtr->GetInvertOpacity() != invert_opacity) {
794+
volRenderPtr->SetInvertOpacity(invert_opacity);
795+
volRenderPtr->SetTransferProperties();
796+
volRenderPtr->InvalidateVPData();
797+
}
798+
}
785799

786800
// -------------------------------------------------------------------
787801
void PltApp::DoRenderModeMenu(Widget w, XtPointer item_no, XtPointer /*client_data*/) {

VolRender.H

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class VolRender {
9292
void SetTransferProperties();
9393
void SetLighting(Real ambient, Real diffuse, Real specular, Real shiny,
9494
Real minRay, Real maxRay);
95+
void SetInvertOpacity(bool a_invert_opacity) { invert_opacity = a_invert_opacity; }
96+
bool GetInvertOpacity() { return invert_opacity; }
9597
Real GetDiffuse() { return diffuseMat; }
9698
Real GetAmbient() { return ambientMat; }
9799
Real GetSpecular() { return specularMat; }
@@ -102,6 +104,7 @@ class VolRender {
102104
private:
103105
Real diffuseMat, shinyMat, specularMat, ambientMat;
104106
Real vpLen, vpAspect;
107+
bool invert_opacity = false;
105108
bool lightingModel, preClassify;
106109
bool bDrawAllBoxes;
107110
int voxelFields;

VolRender.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ void VolRender::MakeSWFData(amrex::DataServices *dataServicesPtr,
273273
int grows = gbox.length(Amrvis::XDIR);
274274
int gcols = gbox.length(Amrvis::YDIR);
275275
//int gplanes = gbox.length(Amrvis::ZDIR);
276-
276+
277277
int gcolsgrowstmp(gcols * grows);
278278
int gpgcgrtmp, gcgrowstmp;
279279
for(int gp(gostartp); gp <= goendp; ++gp) {
@@ -999,6 +999,11 @@ void VolRender::MakeDefaultTransProperties() {
999999
void VolRender::SetTransferProperties() {
10001000
BL_ASSERT(palettePtr != NULL);
10011001
density_ramp = palettePtr->GetTransferArray();
1002+
if (invert_opacity) {
1003+
for (auto& op : density_ramp) {
1004+
op = float(1) - op;
1005+
}
1006+
}
10021007
//density_ramp[palettePtr->BodyIndex()] = 0.08;
10031008
density_ramp[palettePtr->BodyIndex()] = (float) AVGlobals::GetBodyOpacity();
10041009
vpSetClassifierTable(vpc, DENSITY_PARAM, densityField,

0 commit comments

Comments
 (0)