Commit 43a744f1 authored by Cory Quammen's avatar Cory Quammen
Browse files

Add Invert option to vtkThreshold

The Invert option simply inverts which cells are kept in the output of
the vtkThreshold. In other words, if a cell would be included in the
filter output normally, it will not be included when the Invert option
is on, and vice versa. Also, updated the test to check that inversion
produces a reasonable result.
parent 9d84d7f4
......@@ -21,6 +21,7 @@
#include "vtkImageData.h"
#include "vtkPointData.h"
#include "vtkFloatArray.h"
int TestThreshold(int, char *[])
{
//---------------------------------------------------
......@@ -64,5 +65,19 @@ int TestThreshold(int, char *[])
return EXIT_FAILURE;
}
// Get the total number of cells
int totalCellCount = source->GetOutput()->GetNumberOfCells();
int thresholdedCellCount = filter->GetOutput()->GetNumberOfCells();
// Now invert the threshold and test the number of cells
filter->InvertOn();
filter->Update();
int invertedCellCount = filter->GetOutput()->GetNumberOfCells();
if (invertedCellCount + thresholdedCellCount != totalCellCount)
{
std::cerr << "Cell count and inverted cell count inconsistent" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
......@@ -47,6 +47,7 @@ vtkThreshold::vtkThreshold()
vtkDataSetAttributes::SCALARS);
this->UseContinuousCellRange = 0;
this->Invert = false;
}
vtkThreshold::~vtkThreshold() = default;
......@@ -218,7 +219,10 @@ int vtkThreshold::RequestData(
keepCell = this->EvaluateComponents( inScalars, cellId );
}
if ( numCellPts > 0 && keepCell )
// Invert the keep flag if the Invert option is enabled.
keepCell = this->Invert ? (1 - keepCell) : keepCell;
if ( numCellPts > 0 && keepCell)
{
// satisfied thresholding (also non-empty cell, i.e. not VTK_EMPTY_CELL)
for (i=0; i < numCellPts; i++)
......
......@@ -173,6 +173,17 @@ public:
int GetPointsDataType();
//@}
//@{
/**
* Invert the threshold results. That is, cells that would have been in the output with this
* option off are excluded, while cells that would have been excluded from the output are
* included.
*/
vtkSetMacro(Invert, bool);
vtkGetMacro(Invert, bool);
vtkBooleanMacro(Invert, bool);
//@}
//@{
/**
* Set/get the desired precision for the output types. See the documentation
......@@ -201,6 +212,7 @@ protected:
int SelectedComponent;
int OutputPointsPrecision;
vtkTypeBool UseContinuousCellRange;
bool Invert;
int (vtkThreshold::*ThresholdFunction)(double s);
......
Supports Markdown
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