Skip to content

Commit

Permalink
Merge pull request #180 from NREL/contour-nonfinite-masking
Browse files Browse the repository at this point in the history
Change mask color for nan/inf values to light grey for contour plots

Merging to go out in the beta release!
  • Loading branch information
sjanzou authored Nov 21, 2024
2 parents a6795da + f468a77 commit 824c11c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions include/wex/plot/plcolourmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "wex/plot/plplot.h"

#define wxCONTOUR_BG wxStockGDI::GetColour(wxStockGDI::COLOUR_LIGHTGREY)

class wxPLColourMap : public wxPLSideWidgetBase {
public:
wxPLColourMap(double min = 0, double max = 1);
Expand Down
2 changes: 1 addition & 1 deletion src/plot/plcolourmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void wxPLColourMap::Render(wxPLOutputDevice &dc, const wxPLRealRect &geom) {
}

wxColour wxPLColourMap::ColourForValue(double val) {
if (m_colourList.size() == 0 || !(wxFinite(val))) return *wxBLACK;
if (m_colourList.size() == 0 || !(wxFinite(val))) return *wxCONTOUR_BG;

int position =
(int) (((double) m_colourList.size()) * (
Expand Down
22 changes: 17 additions & 5 deletions src/plot/plcontourplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,20 @@ void wxPLContourPlot::RebuildContours() {
}
}
} else {
for (size_t k = 0; k < m_levels.size() - 1; k++) {
double zlow = m_levels[k];
double zhigh = m_levels[k + 1];
for (size_t k = 0; k < m_levels.size(); k++) {
double zlow = 0;
double zhigh = 0;
if (k == 0) {
zlow = m_levels[k] - (m_levels[1] - m_levels[0]);
zhigh = m_levels[k];
}
else {
zlow = m_levels[k-1];
zhigh = m_levels[k];
}

//double zlow = m_levels[k];
//double zhigh = m_levels[k + 1];

std::vector<QuadContourGenerator::VertexCodes *> list;
qcg.create_filled_contour(zlow, zhigh, list);
Expand Down Expand Up @@ -250,16 +261,17 @@ void wxPLContourPlot::Draw(wxPLOutputDevice &dc, const wxPLDeviceMapping &map) {
dc.NoPen();
// background set to min
// assume RebuildMask has been called
wxColor bgc(m_cmap->ColourForValue(m_zMin));
//wxColor bgc(m_cmap->ColourForValue(m_zMin));
wxColor bgc(*wxCONTOUR_BG);
dc.Brush(bgc);
wxRealPoint pos, size;
map.GetDeviceExtents(&pos, &size);
dc.Rect(pos.x, pos.y, size.x, size.y);
// end background

// int ipoly = 0;
for (size_t i = 0; i < m_cPolys.size(); i++) {
double zmid = 0.5 * (m_cPolys[i].z + m_cPolys[i].zmax);
//double zmid = m_cPolys[i].z;
wxColour color(m_cmap->ColourForValue(zmid));
dc.Pen(color, 2);
dc.Brush(color);
Expand Down

0 comments on commit 824c11c

Please sign in to comment.