Commit 59bfb4bb authored by hrchilds's avatar hrchilds

Add DataBinning operator. Rename DDF to DataBinning.


git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@12277 18c085ea-50e0-402c-830e-de6fd14e8384
parent bb5641ff
......@@ -40,16 +40,17 @@
#
#****************************************************************************/
SET(AVTDDF_SOURCES
SET(AVTDBIN_SOURCES
avtBinningScheme.C
avtDDF.C
avtDDFConstructor.C
avtDDFFunctionInfo.C
avtDataBinning.C
avtDataBinningConstructor.C
avtDataBinningFunctionInfo.C
avtR2Faverage.C
avtR2Fcount.C
avtR2Fmaximum.C
avtR2Fminimum.C
avtR2Foperator.C
avtR2Fpdf.C
avtR2Frms.C
avtR2Fstddev.C
avtR2Fsum.C
......@@ -77,13 +78,13 @@ ${VTK_INCLUDE_DIRS}
LINK_DIRECTORIES(${LIBRARY_OUTPUT_DIRECTORY} ${VTK_LIBRARY_DIRS})
#********************************* SERIAL ************************************
ADD_LIBRARY(avtddf_ser ${AVTDDF_SOURCES})
TARGET_LINK_LIBRARIES(avtddf_ser visitcommon avtdbatts avtmath avtpipeline_ser)
VISIT_INSTALL_TARGETS(avtddf_ser)
ADD_LIBRARY(avtdbin_ser ${AVTDBIN_SOURCES})
TARGET_LINK_LIBRARIES(avtdbin_ser visitcommon avtdbatts avtmath avtpipeline_ser)
VISIT_INSTALL_TARGETS(avtdbin_ser)
#********************************* PARALLEL **********************************
IF(VISIT_PARALLEL)
ADD_PARALLEL_LIBRARY(avtddf_par ${AVTDDF_SOURCES})
TARGET_LINK_LIBRARIES(avtddf_par visitcommon avtdbatts avtmath avtpipeline_par)
VISIT_INSTALL_TARGETS(avtddf_par)
ADD_PARALLEL_LIBRARY(avtdbin_par ${AVTDBIN_SOURCES})
TARGET_LINK_LIBRARIES(avtdbin_par visitcommon avtdbatts avtmath avtpipeline_par)
VISIT_INSTALL_TARGETS(avtdbin_par)
ENDIF(VISIT_PARALLEL)
......@@ -53,11 +53,16 @@
// Programmer: Hank Childs
// Creation: February 12, 2006
//
// Modifications:
//
// Hank Childs, Sat Aug 21 14:05:14 PDT 2010
// Initialize oobb (out-of-bounds behavior).
//
// ****************************************************************************
avtBinningScheme::avtBinningScheme()
{
;
oobb = ConstructDataBinningAttributes::Clamp;
}
// ****************************************************************************
......
......@@ -43,7 +43,9 @@
#ifndef AVT_BINNING_SCHEME_H
#define AVT_BINNING_SCHEME_H
#include <ddf_exports.h>
#include <dbin_exports.h>
#include <ConstructDataBinningAttributes.h>
class vtkDataSet;
......@@ -53,14 +55,19 @@ class vtkDataSet;
//
// Purpose:
// This module creates a binning that can be used for neighborhood
// information when constructing a DDR or a DDF.
// information when constructing a data binning.
//
// Programmer: Hank Childs
// Creation: February 12, 2006
//
// Modifications:
//
// Hank Childs, Sat Aug 21 14:05:14 PDT 2010
// Added the concept of out-of-bounds behavior.
//
// ****************************************************************************
class AVTDDF_API avtBinningScheme
class AVTDBIN_API avtBinningScheme
{
public:
avtBinningScheme();
......@@ -68,8 +75,15 @@ class AVTDDF_API avtBinningScheme
virtual int GetBinId(const float *) const = 0;
virtual int GetNumberOfBins(void) const = 0;
virtual int GetNumberOfDimensions(void) const = 0;
void SetOutOfBoundsBehavior(ConstructDataBinningAttributes::OutOfBoundsBehavior o)
{ oobb = o; };
virtual vtkDataSet *CreateGrid(void) const = 0;
protected:
ConstructDataBinningAttributes::OutOfBoundsBehavior oobb;
};
......
......@@ -37,10 +37,10 @@
*****************************************************************************/
// ************************************************************************* //
// avtDDF.C //
// avtDataBinning.C //
// ************************************************************************* //
#include <avtDDF.h>
#include <avtDataBinning.h>
#include <vtkCell.h>
#include <vtkCellData.h>
......@@ -51,7 +51,7 @@
#include <vtkDataSetWriter.h>
#include <avtBinningScheme.h>
#include <avtDDFFunctionInfo.h>
#include <avtDataBinningFunctionInfo.h>
#include <avtParallel.h>
#include <BadIndexException.h>
......@@ -63,14 +63,14 @@ using std::vector;
// ****************************************************************************
// Method: avtDDF constructor
// Method: avtDataBinning constructor
//
// Programmer: Hank Childs
// Creation: February 12, 2006
//
// ****************************************************************************
avtDDF::avtDDF(avtDDFFunctionInfo *info, float *v)
avtDataBinning::avtDataBinning(avtDataBinningFunctionInfo *info, float *v)
{
functionInfo = info;
vals = v;
......@@ -78,14 +78,14 @@ avtDDF::avtDDF(avtDDFFunctionInfo *info, float *v)
// ****************************************************************************
// Method: avtDDF destructor
// Method: avtDataBinning destructor
//
// Programmer: Hank Childs
// Creation: February 12, 2006
//
// ****************************************************************************
avtDDF::~avtDDF()
avtDataBinning::~avtDataBinning()
{
delete [] vals;
delete functionInfo;
......@@ -93,44 +93,73 @@ avtDDF::~avtDDF()
// ****************************************************************************
// Method: avtDDF::CreateGrid
// Method: avtDataBinning::CreateGrid
//
// Purpose:
// Creates a grid so the DDF can be visualized.
// Creates a grid so the DataBinning can be visualized.
//
// Programmer: Hank Childs
// Creation: February 12, 2006
//
// Modifications:
//
// Hank Childs, Sat Aug 21 14:05:14 PDT 2010
// Changes to setup 1D curves and also to work well inside an operator.
//
// ****************************************************************************
vtkDataSet *
avtDDF::CreateGrid(void)
avtDataBinning::CreateGrid(void)
{
avtBinningScheme *bs = functionInfo->GetBinningScheme();
vtkDataSet *rv = bs->CreateGrid();
int nCells = rv->GetNumberOfCells();
int nPts = rv->GetNumberOfPoints();
int nvals = (bs->GetNumberOfDimensions() == 1 ? nPts : nCells);
vtkFloatArray *arr = vtkFloatArray::New();
arr->SetName(functionInfo->GetCodomainName().c_str());
arr->SetNumberOfTuples(nCells);
for (int i = 0 ; i < nCells ; i++)
arr->SetNumberOfTuples(nvals);
for (int i = 0 ; i < nvals ; i++)
{
vtkCell *cell = rv->GetCell(i);
double bbox[6];
cell->GetBounds(bbox);
// Note the assumption here that the X-axis corresponds to tuple 0,
// the Y-axis to tuple 1, etc.
float center[3];
center[0] = (bbox[0] + bbox[1]) / 2.;
center[1] = (bbox[2] + bbox[3]) / 2.;
center[2] = (bbox[4] + bbox[5]) / 2.;
int binId = bs->GetBinId(center);
float loc[3];
if (bs->GetNumberOfDimensions() == 1)
{
double *pt = rv->GetPoint(i);
loc[0] = pt[0];
loc[1] = pt[1];
loc[2] = pt[2];
}
else
{
vtkCell *cell = rv->GetCell(i);
double bbox[6];
cell->GetBounds(bbox);
// Note the assumption here that the X-axis corresponds to tuple 0,
// the Y-axis to tuple 1, etc.
float center[3];
loc[0] = (bbox[0] + bbox[1]) / 2.;
loc[1] = (bbox[2] + bbox[3]) / 2.;
loc[2] = (bbox[4] + bbox[5]) / 2.;
}
int binId = bs->GetBinId(loc);
arr->SetValue(i, vals[binId]);
}
rv->GetCellData()->AddArray(arr);
// We set up curve data as point data, 2D and 3D as cell data.
if (bs->GetNumberOfDimensions() == 1)
{
rv->GetPointData()->AddArray(arr);
rv->GetPointData()->SetActiveScalars(functionInfo->GetCodomainName().c_str());
}
else
{
rv->GetCellData()->AddArray(arr);
rv->GetCellData()->SetActiveScalars(functionInfo->GetCodomainName().c_str());
}
arr->Delete();
return rv;
......@@ -138,10 +167,10 @@ avtDDF::CreateGrid(void)
// ****************************************************************************
// Method: avtDDF::ApplyFunction
// Method: avtDataBinning::ApplyFunction
//
// Purpose:
// Applies the DDF to a data set.
// Applies the DataBinning to a data set.
//
// Programmer: Hank Childs
// Creation: February 12, 2006
......@@ -154,7 +183,7 @@ avtDDF::CreateGrid(void)
// ****************************************************************************
vtkDataArray *
avtDDF::ApplyFunction(vtkDataSet *ds)
avtDataBinning::ApplyFunction(vtkDataSet *ds)
{
int i, j, k;
int nvars = functionInfo->GetDomainNumberOfTuples();
......@@ -215,10 +244,10 @@ avtDDF::ApplyFunction(vtkDataSet *ds)
// ****************************************************************************
// Method: avtDDF::OutputDDF
// Method: avtDataBinning::OutputDataBinning
//
// Purpose:
// Outputs a DDF.
// Outputs a DataBinning.
//
// Programmer: Hank Childs
// Creation: March 30, 2006
......@@ -229,15 +258,18 @@ avtDDF::ApplyFunction(vtkDataSet *ds)
// Only have the root processor write out the file (wowsa! -- how did this
// not get noticed for 3 years!).
//
// Hank Childs, Sat Aug 21 14:05:14 PDT 2010
// Set up curve with point data.
//
// ****************************************************************************
void
avtDDF::OutputDDF(const std::string &ddfname)
avtDataBinning::OutputDataBinning(const std::string &ddfname)
{
if (PAR_Rank() != 0)
return;
avtDDFFunctionInfo *i = GetFunctionInfo();
avtDataBinningFunctionInfo *i = GetFunctionInfo();
int numDims = i->GetDomainNumberOfTuples();
vtkDataSet *g = CreateGrid();
if (numDims > 1)
......@@ -255,12 +287,12 @@ avtDDF::OutputDDF(const std::string &ddfname)
vtkRectilinearGrid *r = (vtkRectilinearGrid *) g;
int dims[3];
r->GetDimensions(dims);
vtkDataArray *s = r->GetCellData()->GetArray(0);
vtkDataArray *s = r->GetPointData()->GetArray(0);
vtkDataArray *x = r->GetXCoordinates();
char str[1024];
sprintf(str, "%s.ultra", ddfname.c_str());
ofstream ofile(str);
ofile << "# DDF " << ddfname << endl;
ofile << "# DataBinning " << ddfname << endl;
for (int j = 0 ; j < dims[0]-1 ; j++)
{
ofile << (x->GetTuple1(j) + x->GetTuple1(j+1)) / 2. << " "
......
......@@ -37,13 +37,13 @@
*****************************************************************************/
// ************************************************************************* //
// avtDDF.h //
// avtDataBinning.h //
// ************************************************************************* //
#ifndef AVT_DDF_H
#define AVT_DDF_H
#ifndef AVT_DATA_BINNING_H
#define AVT_DATA_BINNING_H
#include <ddf_exports.h>
#include <dbin_exports.h>
#include <vector>
#include <string>
......@@ -53,16 +53,15 @@ class vtkDataArray;
class vtkDataSet;
class avtBinningScheme;
class avtDDFFunctionInfo;
class avtDataBinningFunctionInfo;
// ****************************************************************************
// Class: avtDDF
// Class: avtDataBinning
//
// Purpose:
// This class represents a derived data function, which allows for data
// to be represented on new sampling spaces. Further documentation about
// DDFs can be found in the document: ...
// This class represents a data binning, which allows for data
// to be represented on new sampling spaces.
//
// Programmer: Hank Childs
// Creation: February 12, 2006
......@@ -72,22 +71,25 @@ class avtDDFFunctionInfo;
// Hank Childs, Thu Mar 30 12:43:24 PST 2006
// Add method OutputDDF.
//
// Hank Childs, Sat Aug 21 14:05:14 PDT 2010
// Renamed from DDF to DataBinning.
//
// ****************************************************************************
class AVTDDF_API avtDDF
class AVTDBIN_API avtDataBinning
{
public:
avtDDF(avtDDFFunctionInfo *, float *);
virtual ~avtDDF();
avtDataBinning(avtDataBinningFunctionInfo *, float *);
virtual ~avtDataBinning();
avtDDFFunctionInfo *GetFunctionInfo(void) { return functionInfo; };
vtkDataArray *ApplyFunction(vtkDataSet *);
vtkDataSet *CreateGrid(void);
void OutputDDF(const std::string &);
avtDataBinningFunctionInfo *GetFunctionInfo(void) { return functionInfo; };
vtkDataArray *ApplyFunction(vtkDataSet *);
vtkDataSet *CreateGrid(void);
void OutputDataBinning(const std::string &);
protected:
avtDDFFunctionInfo *functionInfo;
float *vals;
avtDataBinningFunctionInfo *functionInfo;
float *vals;
};
......
......@@ -37,10 +37,10 @@
*****************************************************************************/
// ************************************************************************* //
// avtDDFConstructor.C //
// avtDataBinningConstructor.C //
// ************************************************************************* //
#include <avtDDFConstructor.h>
#include <avtDataBinningConstructor.h>
#include <vtkCell.h>
#include <vtkCellData.h>
......@@ -48,16 +48,17 @@
#include <vtkDataSet.h>
#include <vtkPointData.h>
#include <ConstructDDFAttributes.h>
#include <ConstructDataBinningAttributes.h>
#include <avtCallback.h>
#include <avtDDF.h>
#include <avtDDFFunctionInfo.h>
#include <avtDataBinning.h>
#include <avtDataBinningFunctionInfo.h>
#include <avtParallel.h>
#include <avtR2Faverage.h>
#include <avtR2Fminimum.h>
#include <avtR2Fmaximum.h>
#include <avtR2Fcount.h>
#include <avtR2Fpdf.h>
#include <avtR2Fstddev.h>
#include <avtR2Fsum.h>
#include <avtR2Fvariance.h>
......@@ -77,7 +78,7 @@ using std::vector;
// ****************************************************************************
// Method: avtDDFConstructor constructor
// Method: avtDataBinningConstructor constructor
//
// Purpose:
// Defines the destructor. Note: this should not be inlined in the header
......@@ -88,14 +89,14 @@ using std::vector;
//
// ****************************************************************************
avtDDFConstructor::avtDDFConstructor()
avtDataBinningConstructor::avtDataBinningConstructor()
{
;
}
// ****************************************************************************
// Method: avtDDFConstructor destructor
// Method: avtDataBinningConstructor destructor
//
// Purpose:
// Defines the destructor. Note: this should not be inlined in the header
......@@ -106,17 +107,17 @@ avtDDFConstructor::avtDDFConstructor()
//
// ****************************************************************************
avtDDFConstructor::~avtDDFConstructor()
avtDataBinningConstructor::~avtDataBinningConstructor()
{
;
}
// ****************************************************************************
// Method: avtDDFConstructor::ConstructDDF
// Method: avtDataBinningConstructor::ConstructDataBinning
//
// Purpose:
// Constructs the actual DDF.
// Constructs the actual data binning.
//
// Programmer: Hank Childs
// Creation: February 12, 2006
......@@ -146,27 +147,31 @@ avtDDFConstructor::~avtDDFConstructor()
// Cyrus Harrison, Tue Aug 10 10:48:17 PDT 2010
// Added a "rms" operator.
//
// Hank Childs, Sat Aug 21 14:05:14 PDT 2010
// Better support for mixed centering, r2f's that don't require a variable.
//
// ****************************************************************************
avtDDF *
avtDDFConstructor::ConstructDDF(ConstructDDFAttributes *atts,
avtContract_p spec)
avtDataBinning *
avtDataBinningConstructor::ConstructDataBinning(
ConstructDataBinningAttributes *atts,
avtContract_p spec, bool mustReExecute)
{
int i, j, k, l;
//
// Certify the attributes.
//
if (atts->GetBinningScheme() != ConstructDDFAttributes::Uniform)
if (atts->GetBinningScheme() != ConstructDataBinningAttributes::Uniform)
{
debug1 << "Only uniform binning is supported" << endl;
EXCEPTION1(ImproperUseException, "Only uniform binning is supported");
return NULL;
}
if (atts->GetCodomainName() == "")
if (atts->ReductionRequiresVariable() && atts->GetVarForReductionOperator() == "")
{
debug1 << "The codomain name is not valid." << endl;
EXCEPTION1(ImproperUseException, "The codomain name is not valid.");
debug1 << "The reduction operator requires a variable." << endl;
EXCEPTION1(ImproperUseException, "The reduction operator requires a variable.");
return NULL;
}
for (i = 0 ; i < atts->GetVarnames().size() ; i++)
......@@ -179,7 +184,7 @@ avtDDFConstructor::ConstructDDF(ConstructDDFAttributes *atts,
return NULL;
}
}
if (atts->GetNumSamples().size() != atts->GetVarnames().size())
if (atts->GetNumBins().size() != atts->GetVarnames().size())
{
debug1 << "There must be the same number of samples "
"as there are variable names." << endl;
......@@ -188,7 +193,7 @@ avtDDFConstructor::ConstructDDF(ConstructDDFAttributes *atts,
"as there are variable names.");
return NULL;
}
if (atts->GetRanges().size() != 2*atts->GetVarnames().size())
if (atts->GetBinBoundaries().size() != 2*atts->GetVarnames().size())
{
debug1 << "There must be a minimum and a maximum for "
"every variable. The range is the wrong size." << endl;
......@@ -199,7 +204,7 @@ avtDDFConstructor::ConstructDDF(ConstructDDFAttributes *atts,
}
for (i = 0 ; i < atts->GetVarnames().size() ; i++)
{
if (atts->GetRanges()[2*i] >= atts->GetRanges()[2*i+1])
if (atts->GetBinBoundaries()[2*i] >= atts->GetBinBoundaries()[2*i+1])
{
debug1 << "The minimum for the range of a variable"
"must be less than the maximum" << endl;
......@@ -211,7 +216,7 @@ avtDDFConstructor::ConstructDDF(ConstructDDFAttributes *atts,
}
for (i = 0 ; i < atts->GetVarnames().size() ; i++)
{
if (atts->GetNumSamples()[i] <= 0)
if (atts->GetNumBins()[i] <= 0)
{
debug1 << "Each variable must have at least one bin" << endl;
EXCEPTION1(ImproperUseException,
......@@ -228,44 +233,48 @@ avtDDFConstructor::ConstructDDF(ConstructDDFAttributes *atts,
int nvars = atts->GetVarnames().size();
float *minmax = new float[2*nvars];
for (i = 0 ; i < 2*nvars ; i++)
minmax[i] = atts->GetRanges()[i];
minmax[i] = atts->GetBinBoundaries()[i];
int *nvals = new int[nvars];
for (i = 0 ; i < nvars ; i++)
nvals[i] = atts->GetNumSamples()[i];
nvals[i] = atts->GetNumBins()[i];
avtBinningScheme *bs = new avtUniformBinningScheme(nvars, minmax, nvals);
std::vector<std::string> varnames = atts->GetVarnames();
avtDDFFunctionInfo *info = new avtDDFFunctionInfo(bs, varnames,
atts->GetCodomainName());
avtDataBinningFunctionInfo *info = new avtDataBinningFunctionInfo(bs, varnames,
atts->GetVarForReductionOperator());
//
// Now create the "relation-to-function operator".
//
int nBins = bs->GetNumberOfBins();
bs->SetOutOfBoundsBehavior(atts->GetOutOfBoundsBehavior());
avtR2Foperator *R2Foperator = NULL;
switch (atts->GetStatisticalOperator())
switch (atts->GetReductionOperator())
{
case ConstructDDFAttributes::Average:
case ConstructDataBinningAttributes::Average:
R2Foperator = new avtR2Faverage(nBins, atts->GetUndefinedValue());
break;
case ConstructDDFAttributes::Minimum:
case ConstructDataBinningAttributes::Minimum:
R2Foperator = new avtR2Fminimum(nBins, atts->GetUndefinedValue());
break;
case ConstructDDFAttributes::Maximum:
case ConstructDataBinningAttributes::Maximum:
R2Foperator = new avtR2Fmaximum(nBins, atts->GetUndefinedValue());
break;
case ConstructDDFAttributes::Count:
case ConstructDataBinningAttributes::Count:
R2Foperator = new avtR2Fcount(nBins);
break;
case ConstructDDFAttributes::StandardDeviation:
case ConstructDataBinningAttributes::PDF:
R2Foperator = new avtR2Fpdf(nBins);
break;
case ConstructDataBinningAttributes::StandardDeviation: