A patch update will be applied today - June 21st between 1pm - 1:45pm EDT (UTC-0400). GitLab will go down a few minutes within that time.

Commit 68ef0f4a authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

ENH: Fixed BUG #3722. Added new "Edit | Find Data" dialog which allows the user

to create a selection using a query dialog.

ENH: Added support for extract threshold selection using a multicomponent array
(we can pick the component or magnitude) or ids or global ids.

ENH: Added new vtkQuerySelectionSource which allows creation of selection from a
"query".
parent 69c2e512
......@@ -26,7 +26,7 @@
#include "vtkProp.h"
#include "vtkSmartPointer.h"
vtkCxxRevisionMacro(vtkSelectionNode, "1.6");
vtkCxxRevisionMacro(vtkSelectionNode, "1.7");
vtkStandardNewMacro(vtkSelectionNode);
vtkCxxSetObjectMacro(vtkSelectionNode, SelectionData, vtkDataSetAttributes);
......@@ -45,6 +45,7 @@ vtkInformationKeyMacro(vtkSelectionNode,CONTAINING_CELLS,Integer);
vtkInformationKeyMacro(vtkSelectionNode,PIXEL_COUNT,Integer);
vtkInformationKeyMacro(vtkSelectionNode,INVERSE,Integer);
vtkInformationKeyMacro(vtkSelectionNode,INDEXED_VERTICES,Integer);
vtkInformationKeyMacro(vtkSelectionNode,COMPONENT_NUMBER,Integer);
//----------------------------------------------------------------------------
vtkSelectionNode::vtkSelectionNode()
......
......@@ -172,6 +172,14 @@ public:
// it should also extract the cells that contain any of the extracted points.
static vtkInformationIntegerKey* CONTAINING_CELLS();
// Description:
// When ContentType==THRESHOLDS or ContentType==VALUES
// i.e. threshold and value based selections, it is
// possible pick the component number using this key. If none is specified,
// the 0th component is used. If any number less than 0 is specified, then
// the magnitude is used.
static vtkInformationIntegerKey* COMPONENT_NUMBER();
// Description:
// This flag tells the extraction filter to exclude the selection.
static vtkInformationIntegerKey* INVERSE();
......
......@@ -25,7 +25,7 @@
#include <vtkstd/set>
vtkStandardNewMacro(vtkExtractSelectedBlock);
vtkCxxRevisionMacro(vtkExtractSelectedBlock, "1.4");
vtkCxxRevisionMacro(vtkExtractSelectedBlock, "1.5");
//----------------------------------------------------------------------------
vtkExtractSelectedBlock::vtkExtractSelectedBlock()
{
......@@ -125,33 +125,36 @@ int vtkExtractSelectedBlock::RequestData(
node->GetProperties()->Get(vtkSelectionNode::INVERSE()) == 1);
output->CopyStructure(cd);
vtkUnsignedIntArray* selectionList = vtkUnsignedIntArray::SafeDownCast(
vtkDataArray* selectionList = vtkDataArray::SafeDownCast(
node->GetSelectionList());
vtkstd::set<unsigned int> blocks;
if (selectionList)
{
vtkstd::set<unsigned int> blocks;
vtkIdType numValues = selectionList->GetNumberOfTuples();
for (vtkIdType cc=0; cc < numValues; cc++)
void * dataPtr = selectionList->GetVoidPointer(0);
switch (selectionList->GetDataType())
{
blocks.insert(selectionList->GetValue(cc));
vtkTemplateMacro(
for (vtkIdType cc=0; cc < numValues; cc++)
{
blocks.insert(
static_cast<unsigned int>(static_cast<VTK_TT*>(dataPtr)[cc]));
});
}
}
if (numValues > 0)
vtkCompositeDataIterator* citer = cd->NewIterator();
for (citer->InitTraversal(); !citer->IsDoneWithTraversal();
citer->GoToNextItem())
{
vtkstd::set<unsigned int>::iterator fiter =
blocks.find(citer->GetCurrentFlatIndex());
if ((inverse && fiter == blocks.end()) || (!inverse && fiter != blocks.end()))
{
vtkCompositeDataIterator* citer = cd->NewIterator();
for (citer->InitTraversal(); !citer->IsDoneWithTraversal();
citer->GoToNextItem())
{
vtkstd::set<unsigned int>::iterator fiter =
blocks.find(citer->GetCurrentFlatIndex());
if ((inverse && fiter == blocks.end()) || (!inverse && fiter != blocks.end()))
{
output->SetDataSet(citer, citer->GetCurrentDataObject());
}
}
citer->Delete();
output->SetDataSet(citer, citer->GetCurrentDataObject());
}
}
citer->Delete();
return 1;
}
......
......@@ -31,7 +31,7 @@
#include "vtkDoubleArray.h"
#include "vtkSignedCharArray.h"
vtkCxxRevisionMacro(vtkExtractSelectedThresholds, "1.16");
vtkCxxRevisionMacro(vtkExtractSelectedThresholds, "1.17");
vtkStandardNewMacro(vtkExtractSelectedThresholds);
//----------------------------------------------------------------------------
......@@ -131,7 +131,7 @@ int vtkExtractSelectedThresholds::ExtractCells(
int usePointScalars)
{
//find the values to threshold within
vtkDoubleArray *lims = vtkDoubleArray::SafeDownCast(sel->GetSelectionList());
vtkDataArray *lims = vtkDataArray::SafeDownCast(sel->GetSelectionList());
if (lims == NULL)
{
vtkErrorMacro(<<"No values to threshold with");
......@@ -140,12 +140,24 @@ int vtkExtractSelectedThresholds::ExtractCells(
//find out what array we are suppose to threshold in
vtkDataArray *inScalars = NULL;
bool use_ids = false;
if (usePointScalars)
{
if (sel->GetSelectionList()->GetName())
{
inScalars = input->GetPointData()->GetArray(
sel->GetSelectionList()->GetName());
if (strcmp(sel->GetSelectionList()->GetName(), "vtkGlobalIds") == 0)
{
inScalars = input->GetPointData()->GetGlobalIds();
}
else if (strcmp(sel->GetSelectionList()->GetName(), "vtkIndices") == 0)
{
use_ids = true;
}
else
{
inScalars = input->GetPointData()->GetArray(
sel->GetSelectionList()->GetName());
}
}
else
{
......@@ -156,15 +168,26 @@ int vtkExtractSelectedThresholds::ExtractCells(
{
if (sel->GetSelectionList()->GetName())
{
inScalars = input->GetCellData()->GetArray(
sel->GetSelectionList()->GetName());
if (strcmp(sel->GetSelectionList()->GetName(), "vtkGlobalIds") == 0)
{
inScalars = input->GetCellData()->GetGlobalIds();
}
else if (strcmp(sel->GetSelectionList()->GetName(), "vtkIndices") == 0)
{
use_ids = true;
}
else
{
inScalars = input->GetCellData()->GetArray(
sel->GetSelectionList()->GetName());
}
}
else
{
inScalars = input->GetCellData()->GetScalars();
}
}
if (inScalars == NULL)
if (inScalars == NULL && !use_ids)
{
vtkErrorMacro("Could not figure out what array to threshold in.");
return 1;
......@@ -182,6 +205,12 @@ int vtkExtractSelectedThresholds::ExtractCells(
passThrough = 1;
}
int comp_no = 0;
if (sel->GetProperties()->Has(vtkSelectionNode::COMPONENT_NUMBER()))
{
comp_no = sel->GetProperties()->Get(vtkSelectionNode::COMPONENT_NUMBER());
}
vtkIdType cellId, newCellId;
vtkIdList *cellPts, *pointMap = NULL;
vtkIdList *newCellPts = NULL;
......@@ -293,7 +322,8 @@ int vtkExtractSelectedThresholds::ExtractCells(
int above = 0;
int below = 0;
ptId = cellPts->GetId(i);
int inside = this->EvaluateValue( inScalars, ptId, lims, &above, &below, NULL );
int inside = this->EvaluateValue(
inScalars, comp_no, ptId, lims, &above, &below, NULL);
totalAbove += above;
totalBelow += below;
// Have we detected a cell that straddles the threshold?
......@@ -311,7 +341,7 @@ int vtkExtractSelectedThresholds::ExtractCells(
}
else //use cell scalars
{
keepCell = this->EvaluateValue( inScalars, cellId, lims );
keepCell = this->EvaluateValue(inScalars, comp_no, cellId, lims);
if (passThrough && (keepCell ^ inverse))
{
cellInArray->SetValue(cellId, flag);
......@@ -371,7 +401,7 @@ int vtkExtractSelectedThresholds::ExtractPoints(
vtkDataSet *output)
{
//find the values to threshold within
vtkDoubleArray *lims = vtkDoubleArray::SafeDownCast(sel->GetSelectionList());
vtkDataArray *lims = vtkDataArray::SafeDownCast(sel->GetSelectionList());
if (lims == NULL)
{
vtkErrorMacro(<<"No values to threshold with");
......@@ -380,16 +410,28 @@ int vtkExtractSelectedThresholds::ExtractPoints(
//find out what array we are suppose to threshold in
vtkDataArray *inScalars = NULL;
bool use_ids = false;
if (sel->GetSelectionList()->GetName())
{
inScalars = input->GetPointData()->GetArray(
sel->GetSelectionList()->GetName());
if (strcmp(sel->GetSelectionList()->GetName(), "vtkGlobalIds") == 0)
{
inScalars = input->GetPointData()->GetGlobalIds();
}
else if (strcmp(sel->GetSelectionList()->GetName(), "vtkIndices") == 0)
{
use_ids = true;
}
else
{
inScalars = input->GetPointData()->GetArray(
sel->GetSelectionList()->GetName());
}
}
else
{
inScalars = input->GetPointData()->GetScalars();
}
if (inScalars == NULL)
if (inScalars == NULL && !use_ids)
{
vtkErrorMacro("Could not figure out what array to threshold in.");
return 1;
......@@ -407,6 +449,12 @@ int vtkExtractSelectedThresholds::ExtractPoints(
passThrough = 1;
}
int comp_no = 0;
if (sel->GetProperties()->Has(vtkSelectionNode::COMPONENT_NUMBER()))
{
comp_no = sel->GetProperties()->Get(vtkSelectionNode::COMPONENT_NUMBER());
}
vtkIdType numPts = input->GetNumberOfPoints();
vtkPointData *inputPD = input->GetPointData();
vtkPointData *outPD = output->GetPointData();
......@@ -459,7 +507,7 @@ int vtkExtractSelectedThresholds::ExtractPoints(
vtkIdType outPtCnt = 0;
for (vtkIdType ptId = 0; ptId < numPts; ptId++)
{
int keepPoint = this->EvaluateValue( inScalars, ptId, lims );
int keepPoint = this->EvaluateValue( inScalars, comp_no, ptId, lims );
if (keepPoint ^ inverse)
{
if (passThrough)
......@@ -495,20 +543,80 @@ void vtkExtractSelectedThresholds::PrintSelf(ostream& os, vtkIndent indent)
}
namespace
{
template <class daT>
bool TestItem(vtkIdType numLims, daT* limsPtr, double value)
{
for (int i = 0; i < numLims; i+=2)
{
if (value >= limsPtr[i] && value <= limsPtr[i+1])
{
return true;
}
}
return false;
}
template <class daT>
bool TestItem(vtkIdType numLims, daT* limsPtr, double value,
int &above, int &below, int& inside)
{
bool keepCell = false;
for (vtkIdType i = 0; i < numLims; i+=2)
{
daT low = limsPtr[i];
daT high = limsPtr[i+1];
if (value >= low && value <= high)
{
keepCell = true;
++inside;
}
else if (value < low)
{
++below;
}
else if (value > high)
{
++above;
}
}
return keepCell;
}
};
//----------------------------------------------------------------------------
int vtkExtractSelectedThresholds::EvaluateValue(
vtkDataArray *scalars, vtkIdType id, vtkDoubleArray *lims)
vtkDataArray *scalars, int comp_no, vtkIdType id, vtkDataArray *lims)
{
int keepCell = 0;
//check the value in the array against all of the thresholds in lims
//if it is inside any, return true
for (int i = 0; i < lims->GetNumberOfTuples(); i+=2)
double value = 0.0;
if (comp_no < 0 && scalars)
{
double value = scalars->GetComponent(id, 0);
if (value >= lims->GetValue(i) && value <= lims->GetValue(i+1))
// use magnitude.
int numComps = scalars->GetNumberOfComponents();
const double *tuple = scalars->GetTuple(id);
for (int cc=0; cc < numComps; cc++)
{
keepCell = 1;
value += tuple[cc]*tuple[cc];
}
value = sqrt(value);
}
else
{
value = scalars? scalars->GetComponent(id, comp_no) :
static_cast<double>(id); /// <=== precision loss when using id.
}
void* rawLimsPtr = lims->GetVoidPointer(0);
vtkIdType numLims = lims->GetNumberOfComponents() * lims->GetNumberOfTuples();
switch (lims->GetDataType())
{
vtkTemplateMacro(
keepCell = TestItem<VTK_TT>(numLims,
static_cast<VTK_TT*>(rawLimsPtr),
value));
}
return keepCell;
}
......@@ -516,34 +624,45 @@ int vtkExtractSelectedThresholds::EvaluateValue(
//----------------------------------------------------------------------------
int vtkExtractSelectedThresholds::EvaluateValue(
vtkDataArray *scalars, vtkIdType id, vtkDoubleArray *lims,
vtkDataArray *scalars, int comp_no, vtkIdType id, vtkDataArray *lims,
int *AboveCount, int *BelowCount, int *InsideCount)
{
double value = 0.0;
if (comp_no < 0 && scalars)
{
// use magnitude.
int numComps = scalars->GetNumberOfComponents();
const double *tuple = scalars->GetTuple(id);
for (int cc=0; cc < numComps; cc++)
{
value += tuple[cc]*tuple[cc];
}
value = sqrt(value);
}
else
{
value = scalars? scalars->GetComponent(id, comp_no) :
static_cast<double>(id); /// <=== precision loss when using id.
}
int keepCell = 0;
//check the value in the array against all of the thresholds in lims
//if it is inside any, return true
int above = 0;
int below = 0;
int inside = 0;
for (int i = 0; i < lims->GetNumberOfTuples(); i+=2)
void* rawLimsPtr = lims->GetVoidPointer(0);
vtkIdType numLims = lims->GetNumberOfComponents() * lims->GetNumberOfTuples();
switch (lims->GetDataType())
{
double value = scalars->GetComponent(id, 0);
double low = lims->GetValue(i);
double high = lims->GetValue(i+1);
if (value >= low && value <= high)
{
keepCell = 1;
++inside;
}
else if (value < low)
{
++below;
}
else if (value > high)
{
++above;
}
vtkTemplateMacro(
keepCell = TestItem<VTK_TT>(numLims,
static_cast<VTK_TT*>(rawLimsPtr),
value,
above, below, inside));
}
if (AboveCount) *AboveCount = above;
if (BelowCount) *BelowCount = below;
if (InsideCount) *InsideCount = inside;
......
......@@ -34,7 +34,6 @@
#include "vtkExtractSelectionBase.h"
class vtkDataArray;
class vtkDoubleArray;
class vtkSelection;
class vtkSelectionNode;
......@@ -52,7 +51,20 @@ public:
// Function for determining whether a value in a data array passes
// the threshold test(s) provided in lims. Returns 1 if the value
// passes at least one of the threshold tests.
static int EvaluateValue(vtkDataArray *scalars, vtkIdType id, vtkDoubleArray *lims);
// If \c scalars is NULL, then the id itself is used as the scalar value.
static int EvaluateValue(vtkDataArray *scalars,
vtkIdType id, vtkDataArray *lims)
{
return vtkExtractSelectedThresholds::EvaluateValue(scalars, 0, id, lims);
}
// Description:
// Same as the other EvaluateValue except that the component to be compared
// can be picked using array_component_no (use -1 for magnitude).
// If \c scalars is NULL, then the id itself is used as the scalar value.
static int EvaluateValue(vtkDataArray *array,
int array_component_no,
vtkIdType id, vtkDataArray *lims);
// Description:
// Function for determining whether a value in a data array passes
......@@ -60,7 +72,22 @@ public:
// passes at least one of the threshold tests. Also returns in
// AboveCount, BelowCount and InsideCount the number of tests where
// the value was above, below or inside the interval.
static int EvaluateValue(vtkDataArray *scalars, vtkIdType id, vtkDoubleArray *lims, int *AboveCount, int *BelowCount, int *InsideCount);
// If \c scalars is NULL, then the id itself is used as the scalar value.
static int EvaluateValue(vtkDataArray *scalars, vtkIdType id,
vtkDataArray *lims, int *AboveCount, int *BelowCount, int *InsideCount)
{
return vtkExtractSelectedThresholds::EvaluateValue(scalars, 0,
id, lims, AboveCount, BelowCount, InsideCount);
}
// Description:
// Same as the other EvaluateValue except that the component to be compared
// can be picked using array_component_no (use -1 for magnitude).
// If \c scalars is NULL, then the id itself is used as the scalar value.
static int EvaluateValue(vtkDataArray *scalars,
int array_component_no,
vtkIdType id,
vtkDataArray *lims, int *AboveCount, int *BelowCount, int *InsideCount);
protected:
vtkExtractSelectedThresholds();
......
......@@ -31,7 +31,7 @@
#include "vtkstd/vector"
#include "vtkstd/set"
vtkCxxRevisionMacro(vtkSelectionSource, "1.26");
vtkCxxRevisionMacro(vtkSelectionSource, "1.27");
vtkStandardNewMacro(vtkSelectionSource);
class vtkSelectionSourceInternals
......@@ -62,6 +62,7 @@ vtkSelectionSource::vtkSelectionSource()
this->ContainingCells = 1;
this->Inverse = 0;
this->ArrayName = NULL;
this->ArrayComponent = 0;
for (int cc=0; cc < 32; cc++)
{
this->Internal->Frustum[cc] = 0;
......@@ -250,6 +251,7 @@ void vtkSelectionSource::PrintSelf(ostream& os, vtkIndent indent)
os << (this->ContainingCells?"CELLS":"POINTS") << endl;
os << indent << "Inverse: " << this->Inverse << endl;
os << indent << "ArrayName: " << (this->ArrayName?this->ArrayName:"NULL") << endl;
os << indent << "ArrayComponent: " << this->ArrayComponent << endl;
os << indent << "CompositeIndex: " << this->CompositeIndex << endl;
os << indent << "HierarchicalLevel: " << this->HierarchicalLevel << endl;
os << indent << "HierarchicalIndex: " << this->HierarchicalIndex << endl;
......@@ -450,6 +452,8 @@ int vtkSelectionSource::RequestData(
this->ContentType);
oProperties->Set(vtkSelectionNode::FIELD_TYPE(),
this->FieldType);
oProperties->Set(vtkSelectionNode::COMPONENT_NUMBER(),
this->ArrayComponent);
// Create the selection list
vtkDoubleArray* selectionList = vtkDoubleArray::New();
selectionList->SetNumberOfComponents(1);
......
......@@ -103,6 +103,12 @@ public:
// Access to the name of the selection's subset description array.
vtkSetStringMacro(ArrayName);
vtkGetStringMacro(ArrayName);
// Description:
// Access to the component number for the array specified by ArrayName.
// Default is component 0. Use -1 for magnitude.
vtkSetMacro(ArrayComponent, int);
vtkGetMacro(ArrayComponent, int);
// Description:
// If CompositeIndex < 0 then COMPOSITE_INDEX() is not added to the output.
......@@ -139,6 +145,7 @@ protected:
int HierarchicalLevel;
int HierarchicalIndex;
char *ArrayName;
int ArrayComponent;
private:
vtkSelectionSource(const vtkSelectionSource&); // Not implemented.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment