Commit 0ecfed98 authored by whitlocb's avatar whitlocb

Enhance selections and CQ so they can use different variables to index cells in a mesh.



git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@16654 18c085ea-50e0-402c-830e-de6fd14e8384
parent f4f6446d
......@@ -45,6 +45,7 @@
#include <vtkCellData.h>
#include <vtkDataSet.h>
#include <vtkFloatArray.h>
#include <vtkPointData.h>
#include <vtkThreshold.h>
#include <vtkUnstructuredGrid.h>
......@@ -101,13 +102,14 @@ avtNamedSelectionFilter::~avtNamedSelectionFilter()
// Brad Whitlock, Mon Jun 20 17:06:33 PST 2011
// Delete the copied dataset so we don't leak memory.
//
// Brad Whitlock, Thu Oct 27 15:51:06 PDT 2011
// Extend to other selection types.
//
// ****************************************************************************
vtkDataSet *
avtNamedSelectionFilter::ExecuteData(vtkDataSet *in_ds, int dom, std::string)
{
int i;
//
// See if the input reader applied the named selection on read.
//
......@@ -115,58 +117,95 @@ avtNamedSelectionFilter::ExecuteData(vtkDataSet *in_ds, int dom, std::string)
if (GetInput()->GetInfo().GetAttributes().GetSelectionApplied(selectionId))
return in_ds;
vtkDataArray *ocn=in_ds->GetCellData()->GetArray("avtOriginalCellNumbers");
if (ocn == NULL)
vtkDataSet *rv = NULL;
avtNamedSelectionManager *nsm = avtNamedSelectionManager::GetInstance();
avtNamedSelection *ns = nsm->GetNamedSelection(selName);
const SelectionProperties *props = nsm->GetSelectionProperties(selName);
if (ns == NULL || props == NULL)
{
EXCEPTION0(ImproperUseException);
}
unsigned int *ptr = (unsigned int *) ocn->GetVoidPointer(0);
if (ptr == NULL)
else
{
EXCEPTION0(ImproperUseException);
std::string idName(ns->GetIdVariable());
vtkDataArray *idData = in_ds->GetCellData()->GetArray(idName.c_str());
if (idData == NULL)
{
if(in_ds->GetNumberOfCells() == in_ds->GetNumberOfPoints())
{
idData = in_ds->GetPointData()->GetArray(idName.c_str());
}
if(idData == NULL)
{
EXCEPTION0(ImproperUseException);
}
}
std::vector<vtkIdType> ids;
ns->GetMatchingIds(idData, ids);
rv = SelectedData(in_ds, ids);
}
avtNamedSelectionManager *nsm = avtNamedSelectionManager::GetInstance();
avtNamedSelection *ns = nsm->GetNamedSelection(selName);
if (ns == NULL || ns->GetType() != avtNamedSelection::ZONE_ID)
return rv;
}
// ****************************************************************************
// Method: avtNamedSelectionFilter::SelectedData
//
// Purpose:
// Isolate the specified cell ids from the input dataset.
//
// Arguments:
// in_ds The input dataset.
// ids The cell ids of the data we care about.
//
// Returns: The output dataset.
//
// Programmer: Hank Childs
// Creation: February 2, 2009
//
// Modifications:
// Brad Whitlock, Mon Jun 20 17:06:33 PST 2011
// I moved this code out from another function to make it more general.
//
// ****************************************************************************
vtkDataSet *
avtNamedSelectionFilter::SelectedData(vtkDataSet *in_ds,
const std::vector<vtkIdType> &ids)
{
vtkDataSet *rv = NULL;
if (!ids.empty())
{
EXCEPTION0(ImproperUseException);
vtkIdType ncells = in_ds->GetNumberOfCells();
vtkDataSet *ds = in_ds->NewInstance();
ds->ShallowCopy(in_ds);
vtkFloatArray *arr = vtkFloatArray::New();
arr->SetNumberOfTuples(ncells);
arr->SetName("_avt_thresh_var");
for (vtkIdType i = 0 ; i < ncells ; i++)
arr->SetValue(i, 0.);
for (vtkIdType i = 0 ; i < ids.size() ; i++)
arr->SetValue(ids[i], 1.);
ds->GetCellData()->AddArray(arr);
arr->Delete();
vtkThreshold *thres = vtkThreshold::New();
thres->SetInput(ds);
thres->ThresholdBetween(0.5, 1.5);
thres->SetInputArrayToProcess(0, 0, 0,
vtkDataObject::FIELD_ASSOCIATION_CELLS, "_avt_thresh_var");
rv = thres->GetOutput();
rv->Update();
ManageMemory(rv);
thres->Delete();
ds->Delete();
}
avtZoneIdNamedSelection *zins = (avtZoneIdNamedSelection *) ns;
std::vector<int> ids;
int ncells = in_ds->GetNumberOfCells();
zins->GetMatchingIds(ptr, ncells, ids);
if (ids.size() == 0)
return NULL;
vtkDataSet *ds = in_ds->NewInstance();
ds->ShallowCopy(in_ds);
vtkFloatArray *arr = vtkFloatArray::New();
arr->SetNumberOfTuples(ncells);
arr->SetName("_avt_thresh_var");
for (i = 0 ; i < ncells ; i++)
arr->SetValue(i, 0.);
for (i = 0 ; i < ids.size() ; i++)
arr->SetValue(ids[i], 1.);
ds->GetCellData()->AddArray(arr);
arr->Delete();
vtkThreshold *thres = vtkThreshold::New();
thres->SetInput(ds);
thres->ThresholdBetween(0.5, 1.5);
thres->SetInputArrayToProcess(0, 0, 0,
vtkDataObject::FIELD_ASSOCIATION_CELLS, "_avt_thresh_var");
vtkUnstructuredGrid *rv = thres->GetOutput();
rv->Update();
ManageMemory(rv);
thres->Delete();
ds->Delete();
return rv;
}
// ****************************************************************************
// Method: avtNamedSelectionFilter::ModifyContract
//
......@@ -177,14 +216,16 @@ avtNamedSelectionFilter::ExecuteData(vtkDataSet *in_ds, int dom, std::string)
// Programmer: Hank Childs
// Creation: February 2, 2009
//
// Modifications:
// Brad Whitlock, Mon Nov 7 13:36:54 PST 2011
// I moved some code into the named selections so they can modify the
// contract as needed.
//
// ****************************************************************************
avtContract_p
avtNamedSelectionFilter::ModifyContract(avtContract_p contract)
{
avtContract_p rv = new avtContract(contract);
rv->GetDataRequest()->TurnZoneNumbersOn();
avtNamedSelectionManager *nsm = avtNamedSelectionManager::GetInstance();
avtNamedSelection *ns = nsm->GetNamedSelection(selName);
if (ns == NULL)
......@@ -192,13 +233,10 @@ avtNamedSelectionFilter::ModifyContract(avtContract_p contract)
EXCEPTION1(VisItException, "The named selection was not valid");
}
std::vector<int> domains;
bool useList = ns->GetDomainList(domains);
if (useList)
{
rv->GetDataRequest()->GetRestriction()->RestrictDomains(domains);
}
// Let the named selection derived types modify the contract.
avtContract_p rv = ns->ModifyContract(contract);
// Try and apply a data selection based on the named selection.
avtDataSelection *ds = ns->CreateSelection();
selectionId = -1;
if (ds != NULL)
......
......@@ -47,8 +47,7 @@
#include <avtDataTreeIterator.h>
class vtkDataSet;
#include <vtkDataSet.h>
// ****************************************************************************
// Class: avtNamedSelectionFilter
......@@ -65,6 +64,9 @@ class vtkDataSet;
// Hank Childs, Mon Feb 23 21:27:00 PST 2009
// Added data member selectionId.
//
// Brad Whitlock, Thu Oct 27 16:26:30 PDT 2011
// I added SelectedData.
//
// ****************************************************************************
class AVTFILTERS_API avtNamedSelectionFilter : public avtDataTreeIterator
......@@ -86,6 +88,9 @@ class AVTFILTERS_API avtNamedSelectionFilter : public avtDataTreeIterator
virtual vtkDataSet *ExecuteData(vtkDataSet *, int, std::string);
virtual avtContract_p ModifyContract(avtContract_p);
vtkDataSet *SelectedData(vtkDataSet *in_ds,
const std::vector<vtkIdType> &ids);
};
......
......@@ -1106,6 +1106,9 @@ avtThresholdFilter::ModifyContract(avtContract_p in_spec)
// a fix Hank did on Mon Apr 6 17:13:58 PDT 2009 in
// avtParallelCoordinatesFilter::CreateDBAcceleratedNamedSelection
//
// Brad Whitlock, Fri Oct 28 11:00:26 PDT 2011
// Change named selection API.
//
// ****************************************************************************
avtNamedSelection *
......@@ -1139,7 +1142,12 @@ avtThresholdFilter::CreateNamedSelection(avtContract_p c, const std::string &s)
avtIdentifierSelection *ids = GetMetaData()->GetIdentifiers(drs);
avtNamedSelection *rv = NULL;
if (ids != NULL)
rv = new avtFloatingPointIdNamedSelection(s, ids->GetIdentifiers());
{
avtFloatingPointIdNamedSelection *fpns = new avtFloatingPointIdNamedSelection(s);
fpns->SetIdentifiers(ids->GetIdentifiers());
rv = fpns;
}
// Don't delete ids, since it is being cached at the DB level and we don't
// own this reference.
// delete ids;
......
This diff is collapsed.
......@@ -40,12 +40,15 @@
#define AVT_NAMED_SELECTION_H
#include <pipeline_exports.h>
#include <avtContract.h>
#include <set>
#include <vector>
#include <visitstream.h>
#include <vtkDataArray.h>
class avtDataSelection;
......@@ -83,6 +86,9 @@ class PairCompare {
// Hank Childs, Mon Jul 13 17:16:00 PDT 2009
// Added method for determining size of selection.
//
// Brad Whitlock, Mon Nov 7 13:27:09 PST 2011
// Lots of changes. Add Allocate, Append, Globalize, GetMatchingIds, etc.
//
// ****************************************************************************
class PIPELINE_API avtNamedSelection
......@@ -97,22 +103,31 @@ class PIPELINE_API avtNamedSelection
FLOAT_ID /* 1 */
} SELECTION_TYPE;
const std::string &GetName(void) { return name; };
virtual void Read(const std::string &) = 0;
virtual void Write(const std::string &) = 0;
virtual int GetSize(void) = 0;
virtual SELECTION_TYPE GetType(void) = 0;
virtual bool GetDomainList(std::vector<int> &) { return false; };
virtual avtContract_p ModifyContract(avtContract_p c0) const = 0;
virtual avtDataSelection *CreateSelection(void) { return NULL; };
virtual int GetSize(void) = 0;
void SetIdVariable(const std::string &id);
const std::string &GetIdVariable() const;
virtual SELECTION_TYPE GetType(void) = 0;
virtual std::string CreateConditionString(void) { return ""; };
const std::string &GetName(void) { return name; };
virtual const std::string CreateConditionString(void) { return ""; };
virtual void Allocate(size_t) = 0;
virtual void Append(vtkDataArray *arr) = 0;
virtual void Globalize() = 0;
virtual void GetMatchingIds(vtkDataArray *, std::vector<vtkIdType> &) = 0;
static int MaximumSelectionSize();
protected:
std::string name;
std::string idVar;
private:
// These methods are defined to prevent accidental use of bitwise copy
// implementations. If you want to re-define them to do something
......@@ -126,19 +141,25 @@ class PIPELINE_API avtZoneIdNamedSelection : public avtNamedSelection
{
public:
avtZoneIdNamedSelection(const std::string &);
avtZoneIdNamedSelection(const std::string &, int,
const int *, const int *);
virtual ~avtZoneIdNamedSelection();
virtual void Read(const std::string &);
virtual void Write(const std::string &);
virtual bool GetDomainList(std::vector<int> &);
virtual int GetSize(void) { return zoneId.size(); };
virtual SELECTION_TYPE GetType(void) { return ZONE_ID; };
void GetMatchingIds(unsigned int *, int, std::vector<int> &);
virtual avtContract_p ModifyContract(avtContract_p c0) const;
virtual void Allocate(size_t);
virtual void Append(vtkDataArray *arr);
virtual void Globalize();
virtual void GetMatchingIds(vtkDataArray *, std::vector<vtkIdType> &);
void SetIdentifiers(int nvals, const int *doms, const int *zones);
protected:
bool GetDomainList(std::vector<int> &) const;
std::vector<int> domId;
std::vector<int> zoneId;
......@@ -150,19 +171,24 @@ class PIPELINE_API avtFloatingPointIdNamedSelection : public avtNamedSelection
{
public:
avtFloatingPointIdNamedSelection(const std::string &);
avtFloatingPointIdNamedSelection(const std::string &,
const std::vector<double> &);
virtual ~avtFloatingPointIdNamedSelection();
virtual void Read(const std::string &);
virtual void Write(const std::string &);
virtual int GetSize(void) { return ids.size(); };
virtual SELECTION_TYPE GetType(void) { return FLOAT_ID; };
virtual avtContract_p ModifyContract(avtContract_p c0) const;
virtual avtDataSelection *CreateSelection(void);
virtual const std::string CreateConditionString(void);
virtual std::string CreateConditionString(void);
virtual void Allocate(size_t);
virtual void Append(vtkDataArray *arr);
virtual SELECTION_TYPE GetType(void) { return FLOAT_ID; };
virtual void Globalize();
virtual void GetMatchingIds(vtkDataArray *, std::vector<vtkIdType> &);
void SetIdentifiers(const std::vector<double> &);
protected:
std::vector<double> ids;
};
......
......@@ -39,11 +39,11 @@
#define AVT_NAMED_SELECTION_EXTENSION_H
#include <pipeline_exports.h>
#include <vector>
#include <avtContract.h>
#include <avtDataset.h>
#include <avtDataObject.h>
#include <avtNamedSelection.h>
#include <MRUCache.h>
#include <SelectionProperties.h>
......@@ -79,6 +79,9 @@ typedef MRUCache<std::string,
// Brad Whitlock, Tue Sep 6 14:47:35 PDT 2011
// I changed the API.
//
// Brad Whitlock, Thu Oct 27 16:56:42 PDT 2011
// I changed the API so we return a named selection from the extension.
//
// ****************************************************************************
class PIPELINE_API avtNamedSelectionExtension
......@@ -87,15 +90,14 @@ public:
avtNamedSelectionExtension();
virtual ~avtNamedSelectionExtension();
virtual void GetSelection(avtDataObject_p dob, const SelectionProperties &props,
avtNamedSelectionCache &cache,
std::vector<int> &doms, std::vector<int> &zones);
virtual avtNamedSelection *GetSelection(avtDataObject_p dob, const SelectionProperties &props,
avtNamedSelectionCache &cache);
protected:
avtContract_p GetContract(avtDataObject_p dob, bool &needsUpdate);
virtual avtContract_p ModifyContract(avtContract_p c0, const SelectionProperties &props,
bool &needsUpdate) const;
void GetSelectionFromDataset(avtDataset_p tree,
std::vector<int> &doms, std::vector<int> &zones);
static std::string GetIdVariable(const SelectionProperties &props);
static avtNamedSelection *GetSelectionFromDataset(avtDataset_p tree, const SelectionProperties &props);
};
#endif
......@@ -48,7 +48,6 @@
#include <avtDataObjectSource.h>
#include <avtDataset.h>
#include <avtNamedSelection.h>
#include <avtParallel.h>
#include <DebugStream.h>
#include <snprintf.h>
......@@ -112,27 +111,6 @@ avtNamedSelectionManager::GetInstance(void)
return instance;
}
// ****************************************************************************
// Method: avtNamedSelectionManager::MaximumSelectionSize
//
// Purpose:
// Returns the upper limit on the size of selections we're allowed to create.
//
// Returns: The upper limit on selections we're allowed to create.
//
// Programmer: Brad Whitlock
// Creation: Thu Jun 16 09:54:19 PDT 2011
//
// Modifications:
//
// ****************************************************************************
int
avtNamedSelectionManager::MaximumSelectionSize()
{
return 50000000;
}
// ****************************************************************************
// Method: avtNamedSelectionManager::CreateNamedSelection
//
......@@ -172,6 +150,9 @@ avtNamedSelectionManager::MaximumSelectionSize()
// Brad Whitlock, Tue Sep 6 16:01:52 PDT 2011
// I moved most of the code to do the selection into the extension.
//
// Brad Whitlock, Fri Oct 28 09:57:55 PDT 2011
// I changed avtNamedSelectionExtension and moved more code into it.
//
// ****************************************************************************
void
......@@ -190,19 +171,10 @@ avtNamedSelectionManager::CreateNamedSelection(avtDataObject_p dob,
// Save the selection properties.
AddSelectionProperties(selProps);
avtContract_p c1 = dob->GetContractFromPreviousExecution();
avtContract_p contract;
if (c1->GetDataRequest()->NeedZoneNumbers() == false)
{
// If we don't have zone numbers, then get them, even if we have
// to re-execute the whole darn pipeline.
contract = new avtContract(c1);
contract->GetDataRequest()->TurnZoneNumbersOn();
}
else
{
contract = c1;
}
// Augment the contract based on the selection properties.
avtContract_p c0 = dob->GetContractFromPreviousExecution();
bool needsUpdate = false;
avtContract_p contract = ext->ModifyContract(c0, selProps, needsUpdate);
//
// Let the input try to create the named selection ... some have special
......@@ -229,69 +201,28 @@ avtNamedSelectionManager::CreateNamedSelection(avtDataObject_p dob,
}
//
// Call into the extension to get the domains and zones that make up the selection.
// Call into the extension to get the per-processor named selection.
//
std::vector<int> doms, zones;
TimedCodeBlock("Creating selection in extension",
ext->GetSelection(dob, selProps, cache, doms, zones);
ns = ext->GetSelection(dob, selProps, cache);
);
// Note the poor use of MPI below, coded for expediency, as I believe all
// of the named selections will be small.
int *numPerProcIn = new int[PAR_Size()];
int *numPerProc = new int[PAR_Size()];
for (i = 0 ; i < PAR_Size() ; i++)
numPerProcIn[i] = 0;
numPerProcIn[PAR_Rank()] = doms.size();
SumIntArrayAcrossAllProcessors(numPerProcIn, numPerProc, PAR_Size());
int numTotal = 0;
for (i = 0 ; i < PAR_Size() ; i++)
numTotal += numPerProc[i];
if (numTotal > MaximumSelectionSize())
{
EXCEPTION1(VisItException, "You have selected too many zones in your "
"named selection. Disallowing ... no selection created");
}
int myStart = 0;
for (i = 0 ; i < PAR_Rank()-1 ; i++)
myStart += numPerProc[i];
int *selForDomsIn = new int[numTotal];
memset(selForDomsIn, 0, sizeof(int) * numTotal);
for (i = 0 ; i < doms.size() ; i++)
selForDomsIn[myStart+i] = doms[i];
int *selForDoms = new int[numTotal];
SumIntArrayAcrossAllProcessors(selForDomsIn, selForDoms, numTotal);
int *selForZonesIn = new int[numTotal];
memset(selForZonesIn, 0, sizeof(int) * numTotal);
for (i = 0 ; i < zones.size() ; i++)
selForZonesIn[myStart+i] = zones[i];
int *selForZones = new int[numTotal];
SumIntArrayAcrossAllProcessors(selForZonesIn, selForZones, numTotal);
//
// Now construct the actual named selection and add it to our internal
// data structure for tracking named selections.
// Save the selection
//
ns = new avtZoneIdNamedSelection(selName,numTotal,selForDoms,selForZones);
DeleteNamedSelection(selName, false); // Remove sel if it already exists.
int curSize = selList.size();
selList.resize(curSize+1);
selList[curSize] = ns;
delete [] numPerProcIn;
delete [] numPerProc;
delete [] selForDomsIn;
delete [] selForDoms;
delete [] selForZonesIn;
delete [] selForZones;
//
// Save out the named selection in case of engine crash /
// save/restore session, etc.
//
SaveNamedSelection(selName, true);
if(ns != NULL)
{
int curSize = selList.size();
selList.resize(curSize+1);
selList[curSize] = ns;
//
// Save out the named selection in case of engine crash /
// save/restore session, etc.
//
SaveNamedSelection(selName, true);
}
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -41,10 +41,6 @@
#include <avtNamedSelectionExtension.h>
#include <SelectionSummary.h>
class avtThresholdFilter;
class CQHistogramCalculationFilter;
class CQFilter;
// ****************************************************************************
// Class: CumulativeQueryNamedSelectionExtension
//
......@@ -64,6 +60,9 @@ class CQFilter;
// I changed the API so we could add caching support that lets setting
// query attributes sometimes bypass filter execution.
//
// Brad Whitlock, Fri Oct 28 11:48:05 PDT 2011
// Change the API.
//
// ****************************************************************************
class CumulativeQueryNamedSelectionExtension : public avtNamedSelectionExtension
......@@ -72,23 +71,13 @@ public:
CumulativeQueryNamedSelectionExtension();
virtual ~CumulativeQueryNamedSelectionExtension();
virtual void GetSelection(avtDataObject_p dob, const SelectionProperties &props,
avtNamedSelectionCache &cache,
std::vector<int> &doms, std::vector<int> &zones);
virtual avtNamedSelection *GetSelection(avtDataObject_p dob,
const SelectionProperties &props,
avtNamedSelectionCache &cache);
const SelectionSummary &GetSelectionSummary() const;
private:
std::string CreateSelectionKey(const SelectionProperties &props) const;
bool CheckProperties(const SelectionProperties &newProps,
const SelectionProperties &oldProps) const;
avtDataObject_p AddFilters(avtDataObject_p dob, const SelectionProperties &props);
SelectionSummary BuildSummary();
CQHistogramCalculationFilter *hist;
CQFilter *cqFilter;
avtThresholdFilter *threshold;
SelectionSummary summary;
int nts;
SelectionSummary summary;
};
#endif
......@@ -435,8 +435,6 @@ NetworkManager::ClearAllNetworks(void)
viswinMap.clear();
avtNamedSelectionManager::GetInstance()->ClearCache();
avtNamedSelectionManager::GetInstance()->ClearCache();
}
// ****************************************************************************
......
......@@ -226,7 +226,9 @@ QvisHistogram::drawOpacities()
// Creation: Wed Dec 29 13:55:27 PST 2010
//
// Modifications:
//
// Brad Whitlock, Mon Nov 7 15:51:00 PST 2011
// I added special case text.
//
// ****************************************************************************
void
......@@ -266,6 +268,58 @@ QvisHistogram::paintEvent(QPaintEvent *e)
Qt::AlignCenter | Qt::AlignVCenter,
tr("No data"));
}
else
{
// Examine the histogram texture and look for the case where there
// are just a few values.
float sum = 0.f;
for(int i = 0; i < histTextureSize; ++i)
sum += histTexture[i];
p.setPen(Qt::white);
if(sum == 0.f)
{
p.drawText(contentsRect().x(), contentsRect().y(),
contentsRect().width(), contentsRect().height(),
Qt::AlignCenter | Qt::AlignVCenter,
tr("No data"));
}
else if(sum == histTexture[0])
{
QString minstr(tr("minimum"));
if(totalRangeValid)
minstr = QString().setNum(totalRange[0]);
p.drawText(contentsRect().x(), contentsRect().y(),
contentsRect().width(), contentsRect().height(),
Qt::AlignCenter | Qt::AlignVCenter,
tr("All values are %1").arg(minstr));
}
else if(sum == histTexture[histTextureSize-1])
{
QString maxstr(tr("maximum"));
if(totalRangeValid)
maxstr = QString().setNum(totalRange[1]);
p.drawText(contentsRect().x(), contentsRect().y(),
contentsRect().width(), contentsRect().height(),
Qt::AlignCenter | Qt::AlignVCenter,
tr("All values are %1").arg(maxstr));
}
else if(sum == (histTexture[0] + histTexture[histTextureSize-1]))
{
QString minstr(tr("minimum"));
if(totalRangeValid)
minstr = QString().setNum(totalRange[0]);
QString maxstr(tr("maximum"));
if(totalRangeValid)
maxstr = QString().setNum(totalRange[1]);
p.drawText(contentsRect().x(), contentsRect().y(),
contentsRect().width(), contentsRect().height(),
Qt::AlignCenter | Qt::AlignVCenter,