Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate scalar quantity along a stream or path line #2893 #2914

Merged
merged 8 commits into from
Jan 10, 2022
Merged
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
2 changes: 2 additions & 0 deletions apps/vaporgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ set (SRCS
PButton.h
PFlowRakeRegionSelector.cpp
PFlowRakeRegionSelector.h
PFlowIntegrationRegionSelector.cpp
PFlowIntegrationRegionSelector.h
PMultiVarSelector.cpp
PMultiVarSelector.h
AppSettingsMenu.cpp
Expand Down
18 changes: 17 additions & 1 deletion apps/vaporgui/FlowEventRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "vapor/FlowParams.h"
#include "PWidgets.h"
#include "PFlowRakeRegionSelector.h"
#include "PFlowIntegrationRegionSelector.h"
#include "PMultiVarSelector.h"
#include "PConstantColorWidget.h"

Expand All @@ -10,6 +11,7 @@ typedef FlowParams FP;

static RenderEventRouterRegistrar<FlowEventRouter> registrar(FlowEventRouter::GetClassType());
const string FlowEventRouter::SeedingTabName = "Seeding";
const string FlowEventRouter::IntegrationTabName = "Integration";

FlowEventRouter::FlowEventRouter(QWidget *parent, ControlExec *ce) : RenderEventRouterGUI(ce, FlowParams::GetClassType())
{
Expand Down Expand Up @@ -88,7 +90,7 @@ FlowEventRouter::FlowEventRouter(QWidget *parent, ControlExec *ce) : RenderEvent
}));

AddAppearanceSubtab(new PGroup({
(new PTFEditor(RenderParams::_colorMapVariableNameTag))->ShowOpacityBasedOnParam("NULL", 1),
(new PTFEditor(RenderParams::_colorMapVariableNameTag)),
new PSection("Appearance", {
new PConstantColorWidget,
new PEnumDropdown(FP::RenderTypeTag, {"Tubes", "Samples", "KLGWTH"}, {FP::RenderTypeStream, FP::RenderTypeSamples, FP::RenderTypeDensity}, "Render Type"),
Expand Down Expand Up @@ -127,6 +129,20 @@ FlowEventRouter::FlowEventRouter(QWidget *parent, ControlExec *ce) : RenderEvent
}))->SetTooltip("Only accessible in debug build."),
#endif
}));

AddSubtab(IntegrationTabName, new PGroup({
new PSection("Integration Settings", {
new PCheckbox(FP::_doIntegrationTag, "Integrate particle values along trajectory"),
new PCheckbox(FP::_integrationSetAllToFinalValueTag, "Set entire stream value to integrated total"),
(new PVariableSelector(RenderParams::_colorMapVariableNameTag, "Scalar to Integrate"))->EnableBasedOnParam(FP::_doIntegrationTag),
(new PDoubleInput(FP::_integrationScalarTag, "Integration distance scale"))->EnableBasedOnParam(FP::_doIntegrationTag),
}),
(new PSection("Integration Region", {
new PFlowIntegrationRegionSelector1D(0),
new PFlowIntegrationRegionSelector1D(1),
new PFlowIntegrationRegionSelector1D(2),
}))->EnableBasedOnParam(FP::_doIntegrationTag),
}));

AddGeometrySubtab(new PGeometrySubtab);
AddAnnotationSubtab(new PAnnotationColorbarWidget);
Expand Down
1 change: 1 addition & 0 deletions apps/vaporgui/FlowEventRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class FlowEventRouter : public RenderEventRouterGUI {

public:
static const std::string SeedingTabName;
static const std::string IntegrationTabName;

FlowEventRouter(QWidget *parent, VAPoR::ControlExec *ce);
static string GetClassType() { return VAPoR::FlowRenderer::GetClassType(); }
Expand Down
14 changes: 12 additions & 2 deletions apps/vaporgui/Histo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ void Histo::reset(int newNumBins)
if (_above) delete[] _above;
_below = nullptr;
_above = nullptr;
_nBinsBelow = 0;
_nBinsAbove = 0;
}
for (int i = 0; i < _numBins; i++) _binArray[i] = 0;
if (_below) memset(_below, 0, _nBinsBelow * sizeof(*_below));
Expand All @@ -78,6 +80,12 @@ void Histo::reset(int newNumBins, float mnData, float mxData)
_range = _maxMapData - _minMapData;
}

void Histo::setBins(const vector<long> &bins)
{
VAssert(bins.size() == _numBins);
for (int i = 0; i < _numBins; i++) _binArray[i] = bins[i];
}

void Histo::addToBin(float val)
{
// The additional checks below are because
Expand Down Expand Up @@ -134,12 +142,12 @@ int Histo::getMaxBinSizeBetweenIndices(const int start, const int end) const
{
int maxBin = 0;

if (start < 0)
if (start < 0 && _below)
for (int i = max(0, start + _nBinsBelow); i < min(end + _nBinsBelow, _nBinsBelow); i++) maxBin = maxBin < _below[i] ? _below[i] : maxBin;

for (int i = max(start, 0); i < min(end, _numBins); i++) maxBin = maxBin < _binArray[i] ? _binArray[i] : maxBin;

if (end >= _numBins)
if (end >= _numBins && _above)
for (int i = max(start - _numBins, 0); i < min(end - _numBins, _nBinsAbove); i++) maxBin = maxBin < _above[i] ? _above[i] : maxBin;

if (maxBin == 0)
Expand Down Expand Up @@ -221,10 +229,12 @@ int Histo::Populate(const std::string &varName, VAPoR::DataMgr *dm, VAPoR::Rende
if (_below) {
delete[] _below;
_below = nullptr;
_nBinsBelow = 0;
}
if (_above) {
delete[] _above;
_above = nullptr;
_nBinsAbove = 0;
}

_getDataRange(varName, dm, rp, &_minData, &_maxData);
Expand Down
1 change: 1 addition & 0 deletions apps/vaporgui/Histo.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Histo {
void reset(int newNumBins = -1);
void reset(int newNumBins, float mnData, float mxData);
void addToBin(float val);
void setBins(const vector<long> &bins);
int getMaxBinSize();
int getMaxBinSizeBetweenIndices(const int start, const int end) const;
int getNumBins() const;
Expand Down
6 changes: 6 additions & 0 deletions apps/vaporgui/PFlowIntegrationRegionSelector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "PFlowIntegrationRegionSelector.h"
#include <vapor/FlowParams.h>

using VAPoR::FlowParams;

VAPoR::Box *PFlowIntegrationRegionSelector1D::getBox() const { return getParams<FlowParams>()->GetIntegrationBox(); }
11 changes: 11 additions & 0 deletions apps/vaporgui/PFlowIntegrationRegionSelector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "PRegionSelector.h"

class PFlowIntegrationRegionSelector1D : public PRegionSelector1D {
public:
using PRegionSelector1D::PRegionSelector1D;

protected:
VAPoR::Box *getBox() const override;
};
15 changes: 12 additions & 3 deletions apps/vaporgui/TFHistogramWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,18 @@ void TFHistogramMap::PopulateSettingsMenu(QMenu *menu) const

void TFHistogramMap::paramsUpdate()
{
int numBins = width() ? width() : 256;
if (_histo.getNumBins() != numBins) _histo.reset(numBins); // This can be called before it is resized
if (_histo.PopulateIfNeeded(getVariableName(), getDataMgr(), getRenderParams()) < 0) MSG_ERR("Failed to populate histogram");
RenderParams *rp = getRenderParams();
if (rp->GetValueDoubleVec(RenderParams::CustomHistogramRangeTag).size()) {
auto range = rp->GetValueDoubleVec(RenderParams::CustomHistogramRangeTag);
auto bins = rp->GetValueLongVec(RenderParams::CustomHistogramDataTag);
int numBins = bins.size();
_histo.reset(numBins, range[0], range[1]);
_histo.setBins(bins);
} else {
int numBins = width() ? width() : 256;
if (_histo.getNumBins() != numBins) _histo.reset(numBins); // This can be called before it is resized
if (_histo.PopulateIfNeeded(getVariableName(), getDataMgr(), getRenderParams()) < 0) MSG_ERR("Failed to populate histogram");
}

_scalingMenu->Update(getRenderParams());
update();
Expand Down
2 changes: 0 additions & 2 deletions apps/vaporgui/TFHistogramWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class TFHistogramMap : public TFMap {
// void mouseDoubleClickEvent(QMouseEvent *event);

private:
VAPoR::DataMgr * _dataMgr = nullptr;
VAPoR::RenderParams * _renderParams = nullptr;
Histo _histo;
ParamsDropdownMenuItem *_scalingMenu;
bool _dynamicScaling = true;
Expand Down
15 changes: 14 additions & 1 deletion apps/vaporgui/TFMappingRangeSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <vapor/ParamsMgr.h>
#include <vapor/DataMgrUtils.h>

using VAPoR::RenderParams;

TFMappingRangeSelector::TFMappingRangeSelector(const std::string &variableNameTag) : _variableNameTag(variableNameTag)
{
AllowCustomRange();
Expand All @@ -27,14 +29,25 @@ void TFMappingRangeSelector::Update(VAPoR::DataMgr *dataMgr, VAPoR::ParamsMgr *p
min = range[0];
max = range[1];
} else {
_getDataRange(dataMgr, rParams, &min, &max);
_getDefaultRange(dataMgr, rParams, &min, &max);
}
SetRange(min, max);

vector<double> mapperRange = rParams->GetMapperFunc(_getVariableName())->getMinMaxMapValue();
SetValue(mapperRange[0], mapperRange[1]);
}

void TFMappingRangeSelector::_getDefaultRange(VAPoR::DataMgr *d, VAPoR::RenderParams *r, float *min, float *max) const
{
if (r->GetValueDoubleVec(RenderParams::CustomHistogramRangeTag).size() == 2) {
auto range = r->GetValueDoubleVec(RenderParams::CustomHistogramRangeTag);
*min = range[0];
*max = range[1];
} else {
_getDataRange(d, r, min, max);
}
}

void TFMappingRangeSelector::_getDataRange(VAPoR::DataMgr *d, VAPoR::RenderParams *r, float *min, float *max) const
{
vector<double> minExt, maxExt;
Expand Down
1 change: 1 addition & 0 deletions apps/vaporgui/TFMappingRangeSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TFMappingRangeSelector : public QRangeSliderTextCombo {
VAPoR::ParamsMgr * _paramsMgr = nullptr;
const std::string & _variableNameTag;

void _getDefaultRange(VAPoR::DataMgr *dataMgr, VAPoR::RenderParams *rParams, float *min, float *max) const;
void _getDataRange(VAPoR::DataMgr *dataMgr, VAPoR::RenderParams *rParams, float *min, float *max) const;
std::string _getVariableName() const;
VAPoR::MapperFunction *_getTF() const;
Expand Down
12 changes: 11 additions & 1 deletion apps/vaporgui/VizWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ string VizWin::_getCurrentMouseMode() const
GUIStateParams *guiP = (GUIStateParams *)paramsMgr->GetParams(GUIStateParams::GetClassType());

string activeTab = guiP->ActiveTab();
if (activeTab == RenderEventRouterGUI::GeometryTabName || activeTab == FlowEventRouter::SeedingTabName)
if (activeTab == RenderEventRouterGUI::GeometryTabName || activeTab == FlowEventRouter::SeedingTabName || activeTab == FlowEventRouter::IntegrationTabName)
return MouseModeParams::GetRegionModeName();
else
return MouseModeParams::GetNavigateModeName();
Expand Down Expand Up @@ -585,6 +585,10 @@ void VizWin::_setNewExtents()
fp->SetRake(b);
}
}
} else if (_manipFlowIntegrationFlag) {
FlowParams *fp = dynamic_cast<FlowParams *>(rParams);
VAssert(fp);
fp->GetIntegrationBox()->SetExtents(llc, urc);
} else {
box->SetExtents(llc, urc);
}
Expand Down Expand Up @@ -814,10 +818,12 @@ void VizWin::updateManip(bool initialize)
urc = maxExts;
} else {
_manipFlowSeedFlag = false;
_manipFlowIntegrationFlag = false;
GUIStateParams *gp = (GUIStateParams *)_controlExec->GetParamsMgr()->GetParams(GUIStateParams::GetClassType());

if (rParams->GetName() == FlowParams::GetClassType()) {
if (gp->ActiveTab() == FlowEventRouter::SeedingTabName) _manipFlowSeedFlag = true;
if (gp->ActiveTab() == FlowEventRouter::IntegrationTabName) _manipFlowIntegrationFlag = true;
}
if (_manipFlowSeedFlag) {
FlowParams *fp = dynamic_cast<FlowParams *>(rParams);
Expand Down Expand Up @@ -853,6 +859,10 @@ void VizWin::updateManip(bool initialize)
urc[1] = b[3];
llc[2] = b[4];
urc[2] = b[5];
} else if (_manipFlowIntegrationFlag) {
FlowParams *fp = dynamic_cast<FlowParams *>(rParams);
VAssert(fp);
fp->GetIntegrationBox()->GetExtents(llc, urc);
} else {
VAPoR::Box *box = rParams->GetBox();
box->GetExtents(llc, urc);
Expand Down
1 change: 1 addition & 0 deletions apps/vaporgui/VizWin.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public slots:
bool _navigateFlag;
bool _manipFlag;
bool _manipFlowSeedFlag = false;
bool _manipFlowIntegrationFlag = false;
Trackball *_trackBall;

std::vector<double> _getScreenCoords(QMouseEvent *e) const;
Expand Down
9 changes: 9 additions & 0 deletions include/vapor/Advection.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ class FLOW_API Advection final {
// If "skipNonZero" is true, then this function only overwrites zeros.
// Otherwise, it will overwrite values anyway.
int CalculateParticleValues(Field *scalarField, bool skipNonZero);
int CalculateParticleIntegratedValues(Field *scalarField, const bool skipNonZero, const float distScale = 1.f, const std::vector<double> &integrateWithinVolumeMin = {-FLT_MAX, -FLT_MAX, -FLT_MAX},
const std::vector<double> &integrateWithinVolumeMax = {FLT_MAX, FLT_MAX, FLT_MAX});
void SetAllStreamValuesToFinalValue(int realNSamples);
int CalculateParticleProperties(Field *scalarField);

void CalculateParticleHistogram(std::vector<double> &bounds, std::vector<long> &bins);

// Reset all particle values to zero
void ResetParticleValues();
// Clear all existing properties of a particle
Expand Down Expand Up @@ -100,6 +105,10 @@ class FLOW_API Advection final {
// Adjust input "val" according to the bound specified by min and max.
// Returns the value after adjustment.
float _applyPeriodic(float val, float min, float max) const;

void _calculateParticleIntegratedValue(Particle &p, const Particle &prev, const Field *scalarField, const bool skipNonZero, const float distScale,
const std::vector<double> &integrateWithinVolumeMin, const std::vector<double> &integrateWithinVolumeMax) const;
static bool _isParticleInsideVolume(const Particle &p, const std::vector<double> &min, const std::vector<double> &max);
};
}; // namespace flow

Expand Down
12 changes: 12 additions & 0 deletions include/vapor/FlowParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@ enum class FlowDir : int { FORWARD = 0, BACKWARD = 1, BI_DIR = 2 };

class FlowParams;
class PARAMS_API FakeRakeBox : public Box {
string _tag;

public:
using Box::Box;
FlowParams *parent = nullptr;

void Initialize(string tag);
void SetExtents(const vector<double> &minExt, const vector<double> &maxExt) override;
};

class PARAMS_API FlowParams : public RenderParams {
StateSave _fakeRakeStateSave;
FakeRakeBox *_fakeRakeBox = nullptr;
FakeRakeBox *_fakeIntegrationBox = nullptr;
bool _initialized = false;

public:
Expand Down Expand Up @@ -86,6 +91,9 @@ class PARAMS_API FlowParams : public RenderParams {
std::vector<float> GetRake() const;
void SetRake(const std::vector<float> &);

Box *GetIntegrationBox();
void SetIntegrationVolume(const std::vector<float> &);

/*
*This result vector could be of size 2 or 3.
*/
Expand Down Expand Up @@ -170,6 +178,10 @@ class PARAMS_API FlowParams : public RenderParams {
static const std::string _yPeriodicTag;
static const std::string _zPeriodicTag;
static const std::string _rakeTag;
static const std::string _doIntegrationTag;
static const std::string _integrationScalarTag;
static const std::string _integrationSetAllToFinalValueTag;
static const std::string _integrationBoxTag;
static const std::string _rakeBiasVariable;
static const std::string _rakeBiasStrength;
static const std::string _pastNumOfTimeSteps;
Expand Down
4 changes: 4 additions & 0 deletions include/vapor/FlowRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class RENDER_API FlowRenderer final : public Renderer {
FlowStatus _renderStatus = FlowStatus::SIMPLE_OUTOFDATE;
std::string _cache_rakeBiasVariable;
std::string _cache_seedInputFilename;
bool _cache_doIntegration;
bool _cache_integrationSetAllToFinalValue;
float _cache_integrationDistScalar;
std::vector<double> _cache_integrationVolume;

// This Advection class is only used in bi-directional advection mode
std::unique_ptr<flow::Advection> _2ndAdvection;
Expand Down
2 changes: 2 additions & 0 deletions include/vapor/RenderParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ class PARAMS_API RenderParams : public ParamsBase {
static const string _yFieldVariableNameTag;
static const string _zFieldVariableNameTag;
static const string _constantOpacityTag;
static const string CustomHistogramDataTag;
static const string CustomHistogramRangeTag;

//! If a renderer supports rotation about a point of origin,
//! this string identifies the parameter for the origin's
Expand Down
Loading