Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AmrPicture.H
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class AmrPicture {
void CreateImage(const amrex::FArrayBox &fab, unsigned char *imagedata,
int datasizeh, int datasizev,
Real globalMin, Real globalMax, Palette *palptr,
const amrex::FArrayBox *vfracFab, const Real vfeps);
const amrex::FArrayBox *vfracFab, const Real vfeps,
bool logScale = false);
void CreateScaledImage(XImage **ximage, int scale,
unsigned char *imagedata,
unsigned char *scaledimagedata,
Expand Down
50 changes: 37 additions & 13 deletions AmrPicture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ void AmrPicture::APChangeContour(Amrvis::ContourType prevCType) {
CreateImage(*(sliceFab[iLevel]), imageData[iLevel],
dataSizeH[iLevel], dataSizeV[iLevel],
minUsing, maxUsing, palPtr,
vffp, vfeps);
vffp, vfeps, pltAppStatePtr->GetLogScale());
bool bCreateMask(iLevel == minDrawnLevel);
CreateScaledImage(&(xImageArray[iLevel]), pltAppStatePtr->CurrentScale() *
amrex::CRRBetweenLevels(iLevel, maxAllowableLevel,
Expand Down Expand Up @@ -880,7 +880,7 @@ void AmrPicture::APMakeImages(Palette *palptr) {
}
CreateImage(*(sliceFab[iLevel]), imageData[iLevel],
dataSizeH[iLevel], dataSizeV[iLevel],
minUsing, maxUsing, palPtr, vffp, vfeps);
minUsing, maxUsing, palPtr, vffp, vfeps, pltAppStatePtr->GetLogScale());
bool bCreateMask(iLevel == minDrawnLevel);
CreateScaledImage(&(xImageArray[iLevel]), pltAppStatePtr->CurrentScale() *
amrex::CRRBetweenLevels(iLevel, maxAllowableLevel,
Expand All @@ -904,15 +904,29 @@ void AmrPicture::APMakeImages(Palette *palptr) {
void AmrPicture::CreateImage(const FArrayBox &fab, unsigned char *imagedata,
int datasizeh, int datasizev,
Real globalMin, Real globalMax, Palette *palptr,
const FArrayBox *vfracFab, const Real vfeps)
const FArrayBox *vfracFab, const Real vfeps,
bool logScale)
{
int jdsh, jtmp1;
int dIndex, iIndex;
Real oneOverGDiff;
if((globalMax - globalMin) < FLT_MIN) {
oneOverGDiff = 0.0;
Real logGlobalMin, logGlobalMax;
bool useLogScale = logScale && globalMin > 0.0 && globalMax > 0.0;

if(useLogScale) {
logGlobalMin = std::log10(globalMin);
logGlobalMax = std::log10(globalMax);
if((logGlobalMax - logGlobalMin) < FLT_MIN) {
oneOverGDiff = 0.0;
} else {
oneOverGDiff = 1.0 / (logGlobalMax - logGlobalMin);
}
} else {
oneOverGDiff = 1.0 / (globalMax - globalMin);
if((globalMax - globalMin) < FLT_MIN) {
oneOverGDiff = 0.0;
} else {
oneOverGDiff = 1.0 / (globalMax - globalMin);
}
}
const Real *dataPoint = fab.dataPtr();
bool bCartGrid(dataServicesPtr->AmrDataRef().CartGrid());
Expand Down Expand Up @@ -943,9 +957,14 @@ void AmrPicture::CreateImage(const FArrayBox &fab, unsigned char *imagedata,
} else if(dPoint < globalMin) { // clip
imagedata[iIndex] = paletteStart;
} else {
imagedata[iIndex] = (unsigned char)
((((dPoint - globalMin) * oneOverGDiff) * csm1) );
// ^^^^^^^^^^^^^^^^^^ Real data
if(useLogScale && dPoint > 0.0) {
Real logDPoint = std::log10(dPoint);
imagedata[iIndex] = (unsigned char)
((((logDPoint - logGlobalMin) * oneOverGDiff) * csm1) );
} else {
imagedata[iIndex] = (unsigned char)
((((dPoint - globalMin) * oneOverGDiff) * csm1) );
}
imagedata[iIndex] += paletteStart;
}
}
Expand All @@ -966,9 +985,14 @@ void AmrPicture::CreateImage(const FArrayBox &fab, unsigned char *imagedata,
} else if(dPoint < globalMin) { // clip
imagedata[iIndex] = paletteStart;
} else {
imagedata[iIndex] = (unsigned char)
((((dPoint - globalMin) * oneOverGDiff) * csm1) );
// ^^^^^^^^^^^^^^^^^^ Real data
if(useLogScale && dPoint > 0.0) {
Real logDPoint = std::log10(dPoint);
imagedata[iIndex] = (unsigned char)
((((logDPoint - logGlobalMin) * oneOverGDiff) * csm1) );
} else {
imagedata[iIndex] = (unsigned char)
((((dPoint - globalMin) * oneOverGDiff) * csm1) );
}
imagedata[iIndex] += paletteStart;
}
if(dVFPoint < vfeps) { // set to body color
Expand Down Expand Up @@ -1686,7 +1710,7 @@ void AmrPicture::CreateFrames(Amrvis::AnimDirection direction) {
}
CreateImage(imageFab, frameImageData,
dataSizeH[maxDrawnLevel], dataSizeV[maxDrawnLevel],
minUsing, maxUsing, palPtr, vffp, vfeps);
minUsing, maxUsing, palPtr, vffp, vfeps, pltAppStatePtr->GetLogScale());

// this cannot be deleted because it belongs to the XImage
unsigned char *frameScaledImageData;
Expand Down
19 changes: 15 additions & 4 deletions Docs/Amrvis.tex
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation update could be split into a separate PR.

Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ \subsubsection{Interface Windows and Regions}
drawn around the corresponding data point in the Data Image Area
(the color data image).

\item[XY Plot Window] This window displays 1D line plots of data values
and is created when holding shift while using the middle or right mouse buttons
to draw lines across the data view. The plot shows the variation of the selected
quantity along the line. Multiple line plots can be overlaid in the same
window for comparison. The window includes controls for animation through
time steps, displaying the plots from multiple files at the same position.

\item[Animation Control Area] This area contains controls for animating
through data files and through planes in 3D. It is in the lower right
part of the Data View Window below the Palette Area. It also shows
Expand Down Expand Up @@ -316,11 +323,15 @@ \subsubsection{Mouse Controls}
in the isometric view, translating the image in the isometric view (with the
shift button pressed), and clicking a point for its data value.

\item [Middle Button] Placing horizontal planar cutting lines in the
orthogonal image views and rotating around the eye point in the isometric view.
\item [Middle Button] Creating horizontal 1D line plots by holding shift while clicking
and dragging to draw a horizontal line across the data view. When the button is released,
a separate XY plot window opens showing the data values along that line (X-direction plot
at the selected Y position). In 3D, this also rotates around the eye point in the isometric view.

\item [Right Button] Placing vertical planar cutting lines in the
orthogonal image views and zooming the isometric view (pull or push the mouse).
\item [Right Button] Creating vertical 1D line plots by holding shift while clicking
and dragging to draw a vertical line across the data view. When the button is released,
a separate XY plot window opens showing the data values along that line (Y-direction plot
at the selected X position). In 3D, this also zooms the isometric view (pull or push the mouse).

\end{description}

Expand Down
3 changes: 2 additions & 1 deletion Palette.H
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ class Palette {
PaletteType GetPaletteType() { return paletteType; }
amrex::Vector<float> GetTransferArray() { return transferArray; }
int ReadSeqPalette(const string &fileName, bool bRedraw = true);
void DrawPalette(Real palMin, Real palMax, const string &numberFormat);
void DrawPalette(Real palMin, Real palMax, const string &numberFormat, bool logScale = false);
void SetWindow(Window drawPaletteHere);
void SetWindowPalette(const string &palName, Window newPalWindow,
bool bRedraw = true);
void ChangeWindowPalette(const string &palName, Window newPalWindow);
void ExposePalette();
void RedrawPalette();
void RedrawPalette(bool logScale);
void SetReserveSystemColors(int reservesystemcolors);
void SetFormat(const string &newFormat);
Colormap GetColormap() const { return colmap; }
Expand Down
29 changes: 24 additions & 5 deletions Palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <cassert>
#include <cstdio>
#include <cmath>
using std::cout;
using std::cerr;
using std::endl;
Expand Down Expand Up @@ -173,9 +174,14 @@ void Palette::RedrawPalette() {
DrawPalette(pmin, pmax, defaultFormat); // use defaults
}

// -------------------------------------------------------------------
void Palette::RedrawPalette(bool logScale) {
DrawPalette(pmin, pmax, defaultFormat, logScale); // use defaults with log scale
}


// -------------------------------------------------------------------
void Palette::DrawPalette(Real palMin, Real palMax, const string &numberFormat) {
void Palette::DrawPalette(Real palMin, Real palMax, const string &numberFormat, bool logScale) {
int i, cy, palOffsetY(14);
XWindowAttributes winAttribs;
Display *display(gaPtr->PDisplay());
Expand Down Expand Up @@ -329,10 +335,23 @@ void Palette::DrawPalette(Real palMin, Real palMax, const string &numberFormat)
char palString[128];
for(i = 0; i < dataList.size(); ++i) {
XSetForeground(display, gc, AVWhitePixel());
dataList[i] = palMin + (dataList.size() - 1 - i) *
(palMax - palMin) / (dataList.size() - 1);
if(i == 0) {
dataList[i] = palMax; // to avoid roundoff
if(logScale && palMin > 0.0 && palMax > 0.0) {
// Log scale: interpolate in log space
Real logMin = std::log10(palMin);
Real logMax = std::log10(palMax);
Real logVal = logMin + (dataList.size() - 1 - i) *
(logMax - logMin) / (dataList.size() - 1);
dataList[i] = std::pow(10.0, logVal);
if(i == 0) {
dataList[i] = palMax; // to avoid roundoff
}
} else {
// Linear scale (original behavior)
dataList[i] = palMin + (dataList.size() - 1 - i) *
(palMax - palMin) / (dataList.size() - 1);
if(i == 0) {
dataList[i] = palMax; // to avoid roundoff
}
}
sprintf(palString, numberFormat.c_str(), dataList[i]);
XDrawString(display, palPixmap, gc, palWidth + 4,
Expand Down
3 changes: 2 additions & 1 deletion PltApp.H
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ private:
void DirtyFrames();
void DoRubberBanding(Widget, XtPointer, XtPointer);
void DoBoxesButton(Widget, XtPointer, XtPointer);
void DoLogScaleButton(Widget, XtPointer, XtPointer);
void DoCGSmoothing(Widget, XtPointer, XtPointer);
void DoCGShowBody(Widget, XtPointer, XtPointer);
void DoAnimBackStep();
Expand Down Expand Up @@ -348,7 +349,7 @@ class AVXGrab {
public:
AVXGrab(Display *display) : bIsGrabbed(true), cachedDisplay(display) {
XSync(cachedDisplay, False);
XGrabServer(display);
//XGrabServer(display);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to refactor this out into a separate PR. This could be controlled by an ifdef so Amrvis will work with x11vnc or xpra.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the grab even necessary with modern hardware? As I understand it, the main reasons for grabbing the server are to prevent other windows from trying to redraw themselves while drawing over them (which shouldn't be needed here, since the rectangle is only drawn over our own widgets), and to prevent other apps from congesting the server while doing something interactive (like rubber-banding). I couldn't see any performance differences when I commented out the grab call (running on a local Xorg server). If anything, it was slightly less flickery.

XSync(cachedDisplay, False);
}

Expand Down
27 changes: 27 additions & 0 deletions PltApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <Xm/CascadeB.h>

#include <X11/cursorfont.h>
#include <X11/keysym.h>


#include <PltApp.H>
Expand Down Expand Up @@ -1060,6 +1061,18 @@ void PltApp::PltAppInit(bool bSubVolume) {
XmStringFree(label_str);
AddStaticCallback(wid, XmNvalueChangedCallback, &PltApp::DoBoxesButton);

// Toggle log scale colorbar
label_str = XmStringCreateSimple(const_cast<char *>("l"));
wid = XtVaCreateManagedWidget("Log Scale",
xmToggleButtonGadgetClass, wMenuPulldown,
XmNmnemonic, 'L',
XmNset, pltAppState->GetLogScale(),
XmNaccelerator, "<Key>L",
XmNacceleratorText, label_str,
NULL);
XmStringFree(label_str);
AddStaticCallback(wid, XmNvalueChangedCallback, &PltApp::DoLogScaleButton);

if(amrData.CartGrid()) {
// cart grid smoothing
label_str = XmStringCreateSimple(const_cast<char *>("s"));
Expand Down Expand Up @@ -3370,6 +3383,20 @@ void PltApp::DoBoxesButton(Widget, XtPointer, XtPointer) {
}


// -------------------------------------------------------------------
void PltApp::DoLogScaleButton(Widget, XtPointer, XtPointer) {
if(animating2d) {
ResetAnimation();
DirtyFrames();
}
pltAppState->SetLogScale( ! pltAppState->GetLogScale());
pltPaletteptr->RedrawPalette(pltAppState->GetLogScale());
for(int np(0); np < Amrvis::NPLANES; ++np) {
amrPicturePtrArray[np]->APMakeImages(pltPaletteptr);
}
}


// -------------------------------------------------------------------
void PltApp::DoCGSmoothing(Widget, XtPointer, XtPointer) {
if(animating2d) {
Expand Down
5 changes: 5 additions & 0 deletions PltAppState.H
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public:
bool GetCGSmoothing() const { return cgSmoothing; }
void SetCGSmoothing(bool smoothing) { cgSmoothing = smoothing; }

// ------------------------ log scale
bool GetLogScale() const { return logScale; }
void SetLogScale(bool useLogScale) { logScale = useLogScale; }

// ------------------------ number format
string GetFormatString() const { return formatString; }
void SetFormatString(const string &newformat) { formatString = newformat; }
Expand Down Expand Up @@ -139,6 +143,7 @@ private:
int currentDerivedNumber;
bool showBoxes;
bool cgSmoothing;
bool logScale;
amrex::Amrvis::ContourType currentContourType;
int nContours;
amrex::Amrvis::MinMaxRangeType currentMinMaxType;
Expand Down
2 changes: 2 additions & 0 deletions PltAppState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ PltAppState::PltAppState(int numFrames, int numDerived)
}
}
cgSmoothing = false;
logScale = false;
}


Expand All @@ -88,6 +89,7 @@ PltAppState &PltAppState::operator=(const PltAppState &rhs) {
currentDerivedNumber = rhs.currentDerivedNumber;
showBoxes = rhs.showBoxes;
cgSmoothing = rhs.cgSmoothing;
logScale = rhs.logScale;
currentContourType = rhs.currentContourType;
nContours = rhs.nContours;
currentMinMaxType = rhs.currentMinMaxType;
Expand Down
Loading