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;
};
......
......@@ -38,10 +38,12 @@
#include <avtNamedSelectionExtension.h>
#include <avtDataset.h>
#include <avtParallel.h>
#include <vtkCellData.h>
#include <vtkDataArray.h>
#include <vtkDataSet.h>
#include <vtkPointData.h>
#include <DebugStream.h>
......@@ -63,7 +65,7 @@ avtNamedSelectionExtension::~avtNamedSelectionExtension()
}
// ****************************************************************************
// Method: avtNamedSelectionExtension::GetContract
// Method: avtNamedSelectionExtension::ModifyContract
//
// Purpose:
// Return the contract that we'll use for pipeline execution.
......@@ -72,35 +74,72 @@ avtNamedSelectionExtension::~avtNamedSelectionExtension()
//
// Returns:
//
// Note: We turn on zone numbers in the returned contract. If the prior
// contract did not have zone numbers then we'll need to execute
// the pipeline.
// Note: We add different requests to the input contract and return a
// changed copy of it.
//
// Programmer: Brad Whitlock
// Creation: Tue Sep 6 15:44:42 PDT 2011
//
// Modifications:
//
// Brad Whitlock, Fri Oct 28 10:00:39 PDT 2011
// I added support for different id methods.
//
// ****************************************************************************
avtContract_p
avtNamedSelectionExtension::GetContract(avtDataObject_p dob, bool &needsUpdate)
avtNamedSelectionExtension::ModifyContract(avtContract_p c0,
const SelectionProperties &props, bool &needsUpdate) const
{
avtContract_p c1 = dob->GetContractFromPreviousExecution();
avtContract_p contract;
if (c1->GetDataRequest()->NeedZoneNumbers() == false)
if(props.GetIdVariableType() == SelectionProperties::UseZoneIDForID)
{
if (c0->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(c0);
contract->GetDataRequest()->TurnZoneNumbersOn();
needsUpdate = true;
}
else
{
contract = c0;
needsUpdate = false;
}
}
else if(props.GetIdVariableType() == SelectionProperties::UseGlobalZoneIDForID)
{
// 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();
needsUpdate = true;
if (c0->GetDataRequest()->NeedGlobalZoneNumbers() == false)
{
// If we don't have global zone numbers, then get them, even if we have
// to re-execute the whole darn pipeline.
contract = new avtContract(c0);
contract->GetDataRequest()->TurnGlobalZoneNumbersOn();
needsUpdate = true;
}
else
{
contract = c0;
needsUpdate = false;
}
}
else
else if(props.GetIdVariableType() == SelectionProperties::UseVariableForID)
{
contract = c1;
needsUpdate = false;
// Make sure that we request the id variable.
if(c0->GetDataRequest()->HasSecondaryVariable(props.GetIdVariable().c_str()))
{
contract = c0;
needsUpdate = false;
}
else
{
contract = new avtContract(c0);
contract->GetDataRequest()->AddSecondaryVariable(props.GetIdVariable().c_str());
needsUpdate = true;
}
}
return contract;
}
......@@ -126,18 +165,20 @@ avtNamedSelectionExtension::GetContract(avtDataObject_p dob, bool &needsUpdate)
// Creation: Tue Sep 6 16:02:40 PDT 2011
//
// Modifications:
//
// Brad Whitlock, Fri Oct 28 09:44:54 PDT 2011
// I changed the code so it creates an avtNamedSelection object.
//
// ****************************************************************************
void
avtNamedSelection *
avtNamedSelectionExtension::GetSelection(avtDataObject_p dob,
const SelectionProperties &/*props*/,
avtNamedSelectionCache &/*cache*/,
std::vector<int> &doms, std::vector<int> &zones)
const SelectionProperties &props,
avtNamedSelectionCache &/*cache*/)
{
const char *mName = "avtNamedSelectionExtension::GetSelection: ";
avtContract_p c0 = dob->GetContractFromPreviousExecution();
bool needsUpdate = false;
avtContract_p contract = GetContract(dob, needsUpdate);
avtContract_p contract = ModifyContract(c0, props, needsUpdate);
if (needsUpdate)
{
......@@ -146,9 +187,57 @@ avtNamedSelectionExtension::GetSelection(avtDataObject_p dob,
debug1 << mName << "Done re-executing pipeline to create named selection" << endl;
}
// Get this processor's contribution
avtDataset_p ds;
CopyTo(ds, dob);
GetSelectionFromDataset(ds, doms, zones);
avtNamedSelection *ns = GetSelectionFromDataset(ds, props);
TRY
{
// Make sure all processors have the same selection.
ns->Globalize();
}
CATCH(VisItException)
{
delete ns;
RETHROW;
}
ENDTRY
return ns;
}
// ****************************************************************************
// Method: avtNamedSelectionExtension::GetIdVariable
//
// Purpose:
// Return the name of the id variable that we'll use for the selection.
//
// Arguments:
// props : The selection properties.
//
// Returns: The name of the id variable that we'll use when accessing cell data.
//
// Note:
//
// Programmer: Brad Whitlock
// Creation: Fri Oct 28 13:28:51 PDT 2011
//
// Modifications:
//
// ****************************************************************************
std::string
avtNamedSelectionExtension::GetIdVariable(const SelectionProperties &props)
{
std::string idName;
if(props.GetIdVariableType() == SelectionProperties::UseZoneIDForID)
idName = "avtOriginalCellNumbers";
else if(props.GetIdVariableType() == SelectionProperties::UseGlobalZoneIDForID)
idName = "avtGlobalZoneNumbers";
else if(props.GetIdVariableType() == SelectionProperties::UseVariableForID)
idName = props.GetIdVariable();
return idName;
}
// ****************************************************************************
......@@ -174,23 +263,37 @@ avtNamedSelectionExtension::GetSelection(avtDataObject_p dob,
// I moved it from the named selection manager and changed it to a 2 pass
// scheme to remove successive calls to resize.
//
// Brad Whitlock, Fri Oct 28 10:48:34 PDT 2011
// I rewrote it.
//
// ****************************************************************************
void
avtNamedSelection *
avtNamedSelectionExtension::GetSelectionFromDataset(avtDataset_p ds,
std::vector<int> &doms, std::vector<int> &zones)
const SelectionProperties &props)
{
const char *mName = "avtNamedSelectionExtension::GetSelectionFromDataTree: ";
avtNamedSelection *ns = NULL;
std::string idName;
if(props.GetIdVariableType() == SelectionProperties::UseZoneIDForID)
ns = new avtZoneIdNamedSelection(props.GetName());
else if(props.GetIdVariableType() == SelectionProperties::UseGlobalZoneIDForID)
ns = new avtFloatingPointIdNamedSelection(props.GetName());
else if(props.GetIdVariableType() == SelectionProperties::UseVariableForID)
ns = new avtFloatingPointIdNamedSelection(props.GetName());
ns->SetIdVariable(GetIdVariable(props));
int nleaves = 0;
avtDataTree_p tree = ds->GetDataTree();