Commit 6b1a1f2c authored by Yuanxin Liu's avatar Yuanxin Liu Committed by Code Review
Browse files

Merge topic 'add-crinkle-like-option-to-vtkThreshold' into master

052a9ef1 vtkThreshold: Add continuous range option
parents 441a6725 052a9ef1
......@@ -12,6 +12,7 @@ create_test_sourcelist(Tests ${vtk-module}CxxTests.cxx
TestGlyph3D.cxx
TestImplicitPolyDataDistance.cxx
TestCutter.cxx
TestThreshold.cxx
EXTRA_INCLUDE vtkTestDriver.h)
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestThreshold.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkSmartPointer.h"
#include "vtkNew.h"
#include "vtkThreshold.h"
#include "vtkRTAnalyticSource.h"
#include "vtkDataObject.h"
#include "vtkUnstructuredGrid.h"
#include "vtkImageData.h"
#include "vtkPointData.h"
#include "vtkFloatArray.h"
int TestThreshold(int, char *[])
{
//---------------------------------------------------
// Test using different thresholding methods
//---------------------------------------------------
vtkNew<vtkRTAnalyticSource> source;
vtkNew<vtkThreshold> filter;
filter->SetInputConnection(source->GetOutputPort());
double L=100;
double U=200;
filter->ThresholdBetween(L,U);
filter->SetAllScalars(0);
filter->Update();
int n1 = filter->GetOutput()->GetNumberOfCells();
filter->UseContinuousCellRangeOn();
filter->Update();
int n2 = filter->GetOutput()->GetNumberOfCells();
//we we are using a large query range,
//whether to use continuous range or not should not matter
if(n1!=n2)
{
return EXIT_FAILURE;
}
filter->UseContinuousCellRangeOff();
filter->ThresholdBetween(L,L);
filter->Update();
//since we are not using continuous cell range
//no cell points should fall in the empty interval
if(filter->GetOutput()->GetNumberOfCells()>0)
{
return EXIT_FAILURE;
}
filter->UseContinuousCellRangeOn();
filter->Update();
if(filter->GetOutput()->GetNumberOfCells()==0)
{
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
......@@ -23,6 +23,7 @@
#include "vtkPointData.h"
#include "vtkUnstructuredGrid.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkMath.h"
vtkStandardNewMacro(vtkThreshold);
......@@ -45,6 +46,7 @@ vtkThreshold::vtkThreshold()
this->GetInformation()->Set(vtkAlgorithm::PRESERVES_RANGES(), 1);
this->GetInformation()->Set(vtkAlgorithm::PRESERVES_BOUNDS(), 1);
this->UseContinuousCellRange = 0;
}
vtkThreshold::~vtkThreshold()
......@@ -193,11 +195,18 @@ int vtkThreshold::RequestData(
}
else
{
keepCell = 0;
for ( i=0; (!keepCell) && (i < numCellPts); i++)
if(!this->UseContinuousCellRange)
{
ptId = cellPts->GetId(i);
keepCell = this->EvaluateComponents( inScalars, ptId );
keepCell = 0;
for ( i=0; (!keepCell) && (i < numCellPts); i++)
{
ptId = cellPts->GetId(i);
keepCell = this->EvaluateComponents( inScalars, ptId );
}
}
else
{
keepCell = this->EvaluateCell(inScalars, cellPts, numCellPts);
}
}
}
......@@ -252,6 +261,49 @@ int vtkThreshold::RequestData(
return 1;
}
int vtkThreshold::EvaluateCell( vtkDataArray *scalars,vtkIdList* cellPts, int numCellPts )
{
int c(0);
int numComp = scalars->GetNumberOfComponents();
int keepCell(0);
switch (this->ComponentMode)
{
case VTK_COMPONENT_MODE_USE_SELECTED:
c = (this->SelectedComponent < numComp)?(this->SelectedComponent):(0);
keepCell = EvaluateCell(scalars,c,cellPts,numCellPts);
case VTK_COMPONENT_MODE_USE_ANY:
keepCell = 0;
for ( c = 0; (!keepCell) && (c < numComp); c++ )
{
keepCell =EvaluateCell(scalars,c,cellPts,numCellPts);
}
break;
case VTK_COMPONENT_MODE_USE_ALL:
keepCell = 1;
for ( c = 0; keepCell && (c < numComp); c++ )
{
keepCell =EvaluateCell(scalars,c,cellPts,numCellPts);
}
break;
}
return keepCell;
}
int vtkThreshold::EvaluateCell( vtkDataArray *scalars, int c, vtkIdList* cellPts, int numCellPts )
{
double minScalar=DBL_MAX, maxScalar=DBL_MIN;
for (int i=0; i < numCellPts; i++)
{
int ptId = cellPts->GetId(i);
double s = scalars->GetComponent(ptId,c);
minScalar = std::min(s,minScalar);
maxScalar = std::max(s,maxScalar);
}
int keepCell = !(this->LowerThreshold > maxScalar || this->UpperThreshold < minScalar);
return keepCell;
}
int vtkThreshold::EvaluateComponents( vtkDataArray *scalars, vtkIdType id )
{
int keepCell = 0;
......@@ -285,6 +337,7 @@ int vtkThreshold::EvaluateComponents( vtkDataArray *scalars, vtkIdType id )
return keepCell;
}
// Return the method for manipulating scalar data as a string.
const char *vtkThreshold::GetAttributeModeAsString(void)
{
......@@ -390,6 +443,7 @@ void vtkThreshold::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "Upper Threshold: " << this->UpperThreshold << "\n";
os << indent << "Precision of the output points: "
<< this->OutputPointsPrecision << "\n";
os << indent << "Use Continuous Cell Range: "<<this->UseContinuousCellRange<<endl;
}
//----------------------------------------------------------------------------
......
......@@ -47,6 +47,7 @@
#define VTK_COMPONENT_MODE_USE_ANY 2
class vtkDataArray;
class vtkIdList;
class VTKFILTERSCORE_EXPORT vtkThreshold : public vtkUnstructuredGridAlgorithm
{
......@@ -123,6 +124,17 @@ public:
vtkGetMacro(AllScalars,int);
vtkBooleanMacro(AllScalars,int);
// Description:
// If this is on (default is off), we will use the continuous interval
// [minimum cell scalar, maxmimum cell scalar] to intersect the threshold bound
//, rather than the set of discrete scalar values from the vertices
// *WARNING*: For higher order cells, the scalar range of the cell is
// not the same as the vertex scalar interval used here, so the
// result will not be accurate.
vtkSetMacro(UseContinuousCellRange,int);
vtkGetMacro(UseContinuousCellRange,int);
vtkBooleanMacro(UseContinuousCellRange,int);
// Description:
// Set the data type of the output points (See the data types defined in
// vtkType.h). The default data type is float.
......@@ -160,6 +172,7 @@ protected:
int ComponentMode;
int SelectedComponent;
int OutputPointsPrecision;
int UseContinuousCellRange;
//BTX
int (vtkThreshold::*ThresholdFunction)(double s);
......@@ -171,7 +184,8 @@ protected:
( s <= this->UpperThreshold ? 1 : 0 ) : 0 );};
int EvaluateComponents( vtkDataArray *scalars, vtkIdType id );
int EvaluateCell( vtkDataArray *scalars, vtkIdList* cellPts, int numCellPts );
int EvaluateCell( vtkDataArray *scalars, int c, vtkIdList* cellPts, int numCellPts );
private:
vtkThreshold(const vtkThreshold&); // Not implemented.
void operator=(const vtkThreshold&); // 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