Commit 7057a5a3 authored by kbensema's avatar kbensema

Added normalization and cumulative distribution options to the Histogram Plot

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@22363 18c085ea-50e0-402c-830e-de6fd14e8384
parent 8e5f3950
......@@ -90,6 +90,12 @@
<Field name="binScale" label="Bin Scale" type="enum" subtype="DataScale">
Linear
</Field>
<Field name="normalizeHistogram" label="Normalize the Histogram" type="bool">
false
</Field>
<Field name="computeAsCDF" label="Compute CDF" type="bool">
false
</Field>
<Function name="ChangesRequireRecalculation" user="true" member="true">
</Function>
<Function name="VarChangeRequiresReset" user="true" member="true">
......
......@@ -259,6 +259,8 @@ void HistogramAttributes::Init()
lineWidth = 0;
dataScale = Linear;
binScale = Linear;
normalizeHistogram = false;
computeAsCDF = false;
HistogramAttributes::SelectAll();
}
......@@ -298,6 +300,8 @@ void HistogramAttributes::Copy(const HistogramAttributes &obj)
color = obj.color;
dataScale = obj.dataScale;
binScale = obj.binScale;
normalizeHistogram = obj.normalizeHistogram;
computeAsCDF = obj.computeAsCDF;
HistogramAttributes::SelectAll();
}
......@@ -474,7 +478,9 @@ HistogramAttributes::operator == (const HistogramAttributes &obj) const
(lineWidth == obj.lineWidth) &&
(color == obj.color) &&
(dataScale == obj.dataScale) &&
(binScale == obj.binScale));
(binScale == obj.binScale) &&
(normalizeHistogram == obj.normalizeHistogram) &&
(computeAsCDF == obj.computeAsCDF));
}
// ****************************************************************************
......@@ -615,24 +621,26 @@ HistogramAttributes::NewInstance(bool copy) const
void
HistogramAttributes::SelectAll()
{
Select(ID_basedOn, (void *)&basedOn);
Select(ID_histogramType, (void *)&histogramType);
Select(ID_weightVariable, (void *)&weightVariable);
Select(ID_limitsMode, (void *)&limitsMode);
Select(ID_minFlag, (void *)&minFlag);
Select(ID_maxFlag, (void *)&maxFlag);
Select(ID_min, (void *)&min);
Select(ID_max, (void *)&max);
Select(ID_numBins, (void *)&numBins);
Select(ID_domain, (void *)&domain);
Select(ID_zone, (void *)&zone);
Select(ID_useBinWidths, (void *)&useBinWidths);
Select(ID_outputType, (void *)&outputType);
Select(ID_lineStyle, (void *)&lineStyle);
Select(ID_lineWidth, (void *)&lineWidth);
Select(ID_color, (void *)&color);
Select(ID_dataScale, (void *)&dataScale);
Select(ID_binScale, (void *)&binScale);
Select(ID_basedOn, (void *)&basedOn);
Select(ID_histogramType, (void *)&histogramType);
Select(ID_weightVariable, (void *)&weightVariable);
Select(ID_limitsMode, (void *)&limitsMode);
Select(ID_minFlag, (void *)&minFlag);
Select(ID_maxFlag, (void *)&maxFlag);
Select(ID_min, (void *)&min);
Select(ID_max, (void *)&max);
Select(ID_numBins, (void *)&numBins);
Select(ID_domain, (void *)&domain);
Select(ID_zone, (void *)&zone);
Select(ID_useBinWidths, (void *)&useBinWidths);
Select(ID_outputType, (void *)&outputType);
Select(ID_lineStyle, (void *)&lineStyle);
Select(ID_lineWidth, (void *)&lineWidth);
Select(ID_color, (void *)&color);
Select(ID_dataScale, (void *)&dataScale);
Select(ID_binScale, (void *)&binScale);
Select(ID_normalizeHistogram, (void *)&normalizeHistogram);
Select(ID_computeAsCDF, (void *)&computeAsCDF);
}
///////////////////////////////////////////////////////////////////////////////
......@@ -775,6 +783,18 @@ HistogramAttributes::CreateNode(DataNode *parentNode, bool completeSave, bool fo
node->AddNode(new DataNode("binScale", DataScale_ToString(binScale)));
}
if(completeSave || !FieldsEqual(ID_normalizeHistogram, &defaultObject))
{
addToParent = true;
node->AddNode(new DataNode("normalizeHistogram", normalizeHistogram));
}
if(completeSave || !FieldsEqual(ID_computeAsCDF, &defaultObject))
{
addToParent = true;
node->AddNode(new DataNode("computeAsCDF", computeAsCDF));
}
// Add the node to the parent node.
if(addToParent || forceAdd)
......@@ -931,6 +951,10 @@ HistogramAttributes::SetFromNode(DataNode *parentNode)
SetBinScale(value);
}
}
if((node = searchNode->GetNode("normalizeHistogram")) != 0)
SetNormalizeHistogram(node->AsBool());
if((node = searchNode->GetNode("computeAsCDF")) != 0)
SetComputeAsCDF(node->AsBool());
}
///////////////////////////////////////////////////////////////////////////////
......@@ -1063,6 +1087,20 @@ HistogramAttributes::SetBinScale(HistogramAttributes::DataScale binScale_)
Select(ID_binScale, (void *)&binScale);
}
void
HistogramAttributes::SetNormalizeHistogram(bool normalizeHistogram_)
{
normalizeHistogram = normalizeHistogram_;
Select(ID_normalizeHistogram, (void *)&normalizeHistogram);
}
void
HistogramAttributes::SetComputeAsCDF(bool computeAsCDF_)
{
computeAsCDF = computeAsCDF_;
Select(ID_computeAsCDF, (void *)&computeAsCDF);
}
///////////////////////////////////////////////////////////////////////////////
// Get property methods
///////////////////////////////////////////////////////////////////////////////
......@@ -1187,6 +1225,18 @@ HistogramAttributes::GetBinScale() const
return DataScale(binScale);
}
bool
HistogramAttributes::GetNormalizeHistogram() const
{
return normalizeHistogram;
}
bool
HistogramAttributes::GetComputeAsCDF() const
{
return computeAsCDF;
}
///////////////////////////////////////////////////////////////////////////////
// Select property methods
///////////////////////////////////////////////////////////////////////////////
......@@ -1227,24 +1277,26 @@ HistogramAttributes::GetFieldName(int index) const
{
switch (index)
{
case ID_basedOn: return "basedOn";
case ID_histogramType: return "histogramType";
case ID_weightVariable: return "weightVariable";
case ID_limitsMode: return "limitsMode";
case ID_minFlag: return "minFlag";
case ID_maxFlag: return "maxFlag";
case ID_min: return "min";
case ID_max: return "max";
case ID_numBins: return "numBins";
case ID_domain: return "domain";
case ID_zone: return "zone";
case ID_useBinWidths: return "useBinWidths";
case ID_outputType: return "outputType";
case ID_lineStyle: return "lineStyle";
case ID_lineWidth: return "lineWidth";
case ID_color: return "color";
case ID_dataScale: return "dataScale";
case ID_binScale: return "binScale";
case ID_basedOn: return "basedOn";
case ID_histogramType: return "histogramType";
case ID_weightVariable: return "weightVariable";
case ID_limitsMode: return "limitsMode";
case ID_minFlag: return "minFlag";
case ID_maxFlag: return "maxFlag";
case ID_min: return "min";
case ID_max: return "max";
case ID_numBins: return "numBins";
case ID_domain: return "domain";
case ID_zone: return "zone";
case ID_useBinWidths: return "useBinWidths";
case ID_outputType: return "outputType";
case ID_lineStyle: return "lineStyle";
case ID_lineWidth: return "lineWidth";
case ID_color: return "color";
case ID_dataScale: return "dataScale";
case ID_binScale: return "binScale";
case ID_normalizeHistogram: return "normalizeHistogram";
case ID_computeAsCDF: return "computeAsCDF";
default: return "invalid index";
}
}
......@@ -1269,24 +1321,26 @@ HistogramAttributes::GetFieldType(int index) const
{
switch (index)
{
case ID_basedOn: return FieldType_enum;
case ID_histogramType: return FieldType_enum;
case ID_weightVariable: return FieldType_variablename;
case ID_limitsMode: return FieldType_enum;
case ID_minFlag: return FieldType_bool;
case ID_maxFlag: return FieldType_bool;
case ID_min: return FieldType_double;
case ID_max: return FieldType_double;
case ID_numBins: return FieldType_int;
case ID_domain: return FieldType_int;
case ID_zone: return FieldType_int;
case ID_useBinWidths: return FieldType_bool;
case ID_outputType: return FieldType_enum;
case ID_lineStyle: return FieldType_linestyle;
case ID_lineWidth: return FieldType_linewidth;
case ID_color: return FieldType_color;
case ID_dataScale: return FieldType_enum;
case ID_binScale: return FieldType_enum;
case ID_basedOn: return FieldType_enum;
case ID_histogramType: return FieldType_enum;
case ID_weightVariable: return FieldType_variablename;
case ID_limitsMode: return FieldType_enum;
case ID_minFlag: return FieldType_bool;
case ID_maxFlag: return FieldType_bool;
case ID_min: return FieldType_double;
case ID_max: return FieldType_double;
case ID_numBins: return FieldType_int;
case ID_domain: return FieldType_int;
case ID_zone: return FieldType_int;
case ID_useBinWidths: return FieldType_bool;
case ID_outputType: return FieldType_enum;
case ID_lineStyle: return FieldType_linestyle;
case ID_lineWidth: return FieldType_linewidth;
case ID_color: return FieldType_color;
case ID_dataScale: return FieldType_enum;
case ID_binScale: return FieldType_enum;
case ID_normalizeHistogram: return FieldType_bool;
case ID_computeAsCDF: return FieldType_bool;
default: return FieldType_unknown;
}
}
......@@ -1311,24 +1365,26 @@ HistogramAttributes::GetFieldTypeName(int index) const
{
switch (index)
{
case ID_basedOn: return "enum";
case ID_histogramType: return "enum";
case ID_weightVariable: return "variablename";
case ID_limitsMode: return "enum";
case ID_minFlag: return "bool";
case ID_maxFlag: return "bool";
case ID_min: return "double";
case ID_max: return "double";
case ID_numBins: return "int";
case ID_domain: return "int";
case ID_zone: return "int";
case ID_useBinWidths: return "bool";
case ID_outputType: return "enum";
case ID_lineStyle: return "linestyle";
case ID_lineWidth: return "linewidth";
case ID_color: return "color";
case ID_dataScale: return "enum";
case ID_binScale: return "enum";
case ID_basedOn: return "enum";
case ID_histogramType: return "enum";
case ID_weightVariable: return "variablename";
case ID_limitsMode: return "enum";
case ID_minFlag: return "bool";
case ID_maxFlag: return "bool";
case ID_min: return "double";
case ID_max: return "double";
case ID_numBins: return "int";
case ID_domain: return "int";
case ID_zone: return "int";
case ID_useBinWidths: return "bool";
case ID_outputType: return "enum";
case ID_lineStyle: return "linestyle";
case ID_lineWidth: return "linewidth";
case ID_color: return "color";
case ID_dataScale: return "enum";
case ID_binScale: return "enum";
case ID_normalizeHistogram: return "bool";
case ID_computeAsCDF: return "bool";
default: return "invalid index";
}
}
......@@ -1445,6 +1501,16 @@ HistogramAttributes::FieldsEqual(int index_, const AttributeGroup *rhs) const
retval = (binScale == obj.binScale);
}
break;
case ID_normalizeHistogram:
{ // new scope
retval = (normalizeHistogram == obj.normalizeHistogram);
}
break;
case ID_computeAsCDF:
{ // new scope
retval = (computeAsCDF == obj.computeAsCDF);
}
break;
default: retval = false;
}
......
......@@ -202,3 +202,4 @@ HistogramViewerPluginInfo::ProvidesLegend() const
{
return false;
}
......@@ -137,6 +137,8 @@ public:
void SetColor(const ColorAttribute &color_);
void SetDataScale(DataScale dataScale_);
void SetBinScale(DataScale binScale_);
void SetNormalizeHistogram(bool normalizeHistogram_);
void SetComputeAsCDF(bool computeAsCDF_);
// Property getting methods
BasedOn GetBasedOn() const;
......@@ -159,6 +161,8 @@ public:
ColorAttribute &GetColor();
DataScale GetDataScale() const;
DataScale GetBinScale() const;
bool GetNormalizeHistogram() const;
bool GetComputeAsCDF() const;
// Persistence methods
virtual bool CreateNode(DataNode *node, bool completeSave, bool forceAdd);
......@@ -221,6 +225,8 @@ public:
ID_color,
ID_dataScale,
ID_binScale,
ID_normalizeHistogram,
ID_computeAsCDF,
ID__LAST
};
......@@ -243,11 +249,13 @@ private:
ColorAttribute color;
int dataScale;
int binScale;
bool normalizeHistogram;
bool computeAsCDF;
// Static class format string for type map.
static const char *TypeMapFormatString;
static const private_tmfs_t TmfsStruct;
};
#define HISTOGRAMATTRIBUTES_TMFS "iisibbddiiibiiiaii"
#define HISTOGRAMATTRIBUTES_TMFS "iisibbddiiibiiiaiibb"
#endif
......@@ -60,7 +60,7 @@ import llnl.visit.ColorAttribute;
public class HistogramAttributes extends AttributeSubject implements Plugin
{
private static int HistogramAttributes_numAdditionalAtts = 18;
private static int HistogramAttributes_numAdditionalAtts = 20;
// Enum values
public final static int OUTPUTTYPE_CURVE = 0;
......@@ -103,6 +103,8 @@ public class HistogramAttributes extends AttributeSubject implements Plugin
color = new ColorAttribute(200, 80, 40);
dataScale = DATASCALE_LINEAR;
binScale = DATASCALE_LINEAR;
normalizeHistogram = false;
computeAsCDF = false;
}
public HistogramAttributes(int nMoreFields)
......@@ -127,6 +129,8 @@ public class HistogramAttributes extends AttributeSubject implements Plugin
color = new ColorAttribute(200, 80, 40);
dataScale = DATASCALE_LINEAR;
binScale = DATASCALE_LINEAR;
normalizeHistogram = false;
computeAsCDF = false;
}
public HistogramAttributes(HistogramAttributes obj)
......@@ -151,6 +155,8 @@ public class HistogramAttributes extends AttributeSubject implements Plugin
color = new ColorAttribute(obj.color);
dataScale = obj.dataScale;
binScale = obj.binScale;
normalizeHistogram = obj.normalizeHistogram;
computeAsCDF = obj.computeAsCDF;
SelectAll();
}
......@@ -185,7 +191,9 @@ public class HistogramAttributes extends AttributeSubject implements Plugin
(lineWidth == obj.lineWidth) &&
(color == obj.color) &&
(dataScale == obj.dataScale) &&
(binScale == obj.binScale));
(binScale == obj.binScale) &&
(normalizeHistogram == obj.normalizeHistogram) &&
(computeAsCDF == obj.computeAsCDF));
}
public String GetName() { return "Histogram"; }
......@@ -300,6 +308,18 @@ public class HistogramAttributes extends AttributeSubject implements Plugin
Select(17);
}
public void SetNormalizeHistogram(boolean normalizeHistogram_)
{
normalizeHistogram = normalizeHistogram_;
Select(18);
}
public void SetComputeAsCDF(boolean computeAsCDF_)
{
computeAsCDF = computeAsCDF_;
Select(19);
}
// Property getting methods
public int GetBasedOn() { return basedOn; }
public int GetHistogramType() { return histogramType; }
......@@ -319,6 +339,8 @@ public class HistogramAttributes extends AttributeSubject implements Plugin
public ColorAttribute GetColor() { return color; }
public int GetDataScale() { return dataScale; }
public int GetBinScale() { return binScale; }
public boolean GetNormalizeHistogram() { return normalizeHistogram; }
public boolean GetComputeAsCDF() { return computeAsCDF; }
// Write and read methods.
public void WriteAtts(CommunicationBuffer buf)
......@@ -359,6 +381,10 @@ public class HistogramAttributes extends AttributeSubject implements Plugin
buf.WriteInt(dataScale);
if(WriteSelect(17, buf))
buf.WriteInt(binScale);
if(WriteSelect(18, buf))
buf.WriteBool(normalizeHistogram);
if(WriteSelect(19, buf))
buf.WriteBool(computeAsCDF);
}
public void ReadAtts(int index, CommunicationBuffer buf)
......@@ -420,6 +446,12 @@ public class HistogramAttributes extends AttributeSubject implements Plugin
case 17:
SetBinScale(buf.ReadInt());
break;
case 18:
SetNormalizeHistogram(buf.ReadBool());
break;
case 19:
SetComputeAsCDF(buf.ReadBool());
break;
}
}
......@@ -480,6 +512,8 @@ public class HistogramAttributes extends AttributeSubject implements Plugin
if(binScale == DATASCALE_SQUAREROOT)
str = str + "DATASCALE_SQUAREROOT";
str = str + "\n";
str = str + boolToString("normalizeHistogram", normalizeHistogram, indent) + "\n";
str = str + boolToString("computeAsCDF", computeAsCDF, indent) + "\n";
return str;
}
......@@ -503,5 +537,7 @@ public class HistogramAttributes extends AttributeSubject implements Plugin
private ColorAttribute color;
private int dataScale;
private int binScale;
private boolean normalizeHistogram;
private boolean computeAsCDF;
}
......@@ -214,6 +214,16 @@ PyHistogramAttributes_ToString(const HistogramAttributes *atts, const char *pref
break;
}
if(atts->GetNormalizeHistogram())
SNPRINTF(tmpStr, 1000, "%snormalizeHistogram = 1\n", prefix);
else
SNPRINTF(tmpStr, 1000, "%snormalizeHistogram = 0\n", prefix);
str += tmpStr;
if(atts->GetComputeAsCDF())
SNPRINTF(tmpStr, 1000, "%scomputeAsCDF = 1\n", prefix);
else
SNPRINTF(tmpStr, 1000, "%scomputeAsCDF = 0\n", prefix);
str += tmpStr;
return str;
}
......@@ -774,6 +784,54 @@ HistogramAttributes_GetBinScale(PyObject *self, PyObject *args)
return retval;
}
/*static*/ PyObject *
HistogramAttributes_SetNormalizeHistogram(PyObject *self, PyObject *args)
{
HistogramAttributesObject *obj = (HistogramAttributesObject *)self;
int ival;
if(!PyArg_ParseTuple(args, "i", &ival))
return NULL;
// Set the normalizeHistogram in the object.
obj->data->SetNormalizeHistogram(ival != 0);
Py_INCREF(Py_None);
return Py_None;
}
/*static*/ PyObject *
HistogramAttributes_GetNormalizeHistogram(PyObject *self, PyObject *args)
{
HistogramAttributesObject *obj = (HistogramAttributesObject *)self;
PyObject *retval = PyInt_FromLong(obj->data->GetNormalizeHistogram()?1L:0L);
return retval;
}
/*static*/ PyObject *
HistogramAttributes_SetComputeAsCDF(PyObject *self, PyObject *args)
{
HistogramAttributesObject *obj = (HistogramAttributesObject *)self;
int ival;
if(!PyArg_ParseTuple(args, "i", &ival))
return NULL;
// Set the computeAsCDF in the object.
obj->data->SetComputeAsCDF(ival != 0);
Py_INCREF(Py_None);
return Py_None;
}
/*static*/ PyObject *
HistogramAttributes_GetComputeAsCDF(PyObject *self, PyObject *args)
{
HistogramAttributesObject *obj = (HistogramAttributesObject *)self;
PyObject *retval = PyInt_FromLong(obj->data->GetComputeAsCDF()?1L:0L);
return retval;
}
PyMethodDef PyHistogramAttributes_methods[HISTOGRAMATTRIBUTES_NMETH] = {
......@@ -814,6 +872,10 @@ PyMethodDef PyHistogramAttributes_methods[HISTOGRAMATTRIBUTES_NMETH] = {
{"GetDataScale", HistogramAttributes_GetDataScale, METH_VARARGS},
{"SetBinScale", HistogramAttributes_SetBinScale, METH_VARARGS},
{"GetBinScale", HistogramAttributes_GetBinScale, METH_VARARGS},
{"SetNormalizeHistogram", HistogramAttributes_SetNormalizeHistogram, METH_VARARGS},
{"GetNormalizeHistogram", HistogramAttributes_GetNormalizeHistogram, METH_VARARGS},
{"SetComputeAsCDF", HistogramAttributes_SetComputeAsCDF, METH_VARARGS},
{"GetComputeAsCDF", HistogramAttributes_GetComputeAsCDF, METH_VARARGS},
{NULL, NULL}
};
......@@ -923,6 +985,10 @@ PyHistogramAttributes_getattr(PyObject *self, char *name)
if(strcmp(name, "SquareRoot") == 0)
return PyInt_FromLong(long(HistogramAttributes::SquareRoot));
if(strcmp(name, "normalizeHistogram") == 0)
return HistogramAttributes_GetNormalizeHistogram(self, NULL);
if(strcmp(name, "computeAsCDF") == 0)
return HistogramAttributes_GetComputeAsCDF(self, NULL);
return Py_FindMethod(PyHistogramAttributes_methods, self, name);
}
......@@ -973,6 +1039,10 @@ PyHistogramAttributes_setattr(PyObject *self, char *name, PyObject *args)
obj = HistogramAttributes_SetDataScale(self, tuple);
else if(strcmp(name, "binScale") == 0)
obj = HistogramAttributes_SetBinScale(self, tuple);
else if(strcmp(name, "normalizeHistogram") == 0)
obj = HistogramAttributes_SetNormalizeHistogram(self, tuple);
else if(strcmp(name, "computeAsCDF") == 0)
obj = HistogramAttributes_SetComputeAsCDF(self, tuple);
if(obj != NULL)
Py_DECREF(obj);
......
......@@ -44,7 +44,7 @@
//
// Functions exposed to the VisIt module.
//
#define HISTOGRAMATTRIBUTES_NMETH 38
#define HISTOGRAMATTRIBUTES_NMETH 42
void PyHistogramAttributes_StartUp(HistogramAttributes *subj, void *data);
void PyHistogramAttributes_CloseDown();
PyMethodDef * PyHistogramAttributes_GetMethodTable(int *nMethods);
......
......@@ -132,6 +132,9 @@ QvisHistogramPlotWindow::~QvisHistogramPlotWindow()
// Dave Pugmire, Wed Oct 29 16:00:48 EDT 2008
// Swap the min/max in the gui.
//
// Kevin Bensema, Mon Nov 11, 12:54 2013 PST
// Normalize/ComputeAsCDF checkboxes added.
//
// ****************************************************************************
void
......@@ -178,7 +181,6 @@ QvisHistogramPlotWindow::CreateWindowContents()
hgTopLayout->addLayout(hgLayout);
hgLayout->setColumnStretch(1,10);
// Number of bins
numBinsLabel = new QLabel(tr("Number of Bins"), histGroupBox);
hgLayout->addWidget(numBinsLabel, 0, 0);
......@@ -287,6 +289,31 @@ QvisHistogramPlotWindow::CreateWindowContents()
this, SLOT(weightVariableChanged(const QString&)));
weightingLayout->addWidget(weightVariable, 2,1);
//
// Statistics options
//
QGroupBox* statisticsGroupBox = new QGroupBox(histGroupBox);
statisticsGroupBox->setTitle(tr("Statistical Options"));
hgTopLayout->addWidget(statisticsGroupBox);
QHBoxLayout* statsLayout = new QHBoxLayout(statisticsGroupBox);
statisticsGroupBox->setLayout(statsLayout);