Commit 2daba821 authored by Matt Larsen's avatar Matt Larsen
Browse files

adding the ability to invert clips

parent 7fd9950c
......@@ -43,6 +43,9 @@ public:
VTKM_CONT
void SetClipValue(vtkm::Float64 value) { this->ClipValue = value; }
VTKM_CONT
void SetInvertClip(bool invert) { this->Invert = invert; }
VTKM_CONT
vtkm::Float64 GetClipValue() const { return this->ClipValue; }
......@@ -65,6 +68,7 @@ public:
private:
vtkm::Float64 ClipValue;
vtkm::worklet::Clip Worklet;
bool Invert;
};
template <>
......
......@@ -60,6 +60,7 @@ inline VTKM_CONT ClipWithField::ClipWithField()
: vtkm::filter::FilterDataSetWithField<ClipWithField>()
, ClipValue(0)
, Worklet()
, Invert(false)
{
}
......@@ -87,8 +88,8 @@ inline VTKM_CONT vtkm::filter::Result ClipWithField::DoExecute(
const vtkm::cont::CoordinateSystem& inputCoords =
input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex());
vtkm::cont::CellSetExplicit<> outputCellSet =
this->Worklet.Run(vtkm::filter::ApplyPolicy(cells, policy), field, this->ClipValue, device);
vtkm::cont::CellSetExplicit<> outputCellSet = this->Worklet.Run(
vtkm::filter::ApplyPolicy(cells, policy), field, this->ClipValue, this->Invert, device);
//create the output data
vtkm::cont::DataSet output;
......
......@@ -38,11 +38,15 @@ namespace filter
class ClipWithImplicitFunction : public vtkm::filter::FilterDataSet<ClipWithImplicitFunction>
{
public:
ClipWithImplicitFunction();
void SetImplicitFunction(const vtkm::cont::ImplicitFunctionHandle& func)
{
this->Function = func;
}
void SetInvertClip(bool invert) { this->Invert = invert; }
const vtkm::cont::ImplicitFunctionHandle& GetImplicitFunction() const { return this->Function; }
template <typename DerivedPolicy, typename DeviceAdapter>
......@@ -62,6 +66,7 @@ public:
private:
vtkm::cont::ImplicitFunctionHandle Function;
vtkm::worklet::Clip Worklet;
bool Invert;
};
}
} // namespace vtkm::filter
......
......@@ -54,6 +54,12 @@ struct PointMapHelper
} // end namespace clipwithimplicitfunction
//-----------------------------------------------------------------------------
ClipWithImplicitFunction::ClipWithImplicitFunction()
: Invert(false)
{
}
template <typename DerivedPolicy, typename DeviceAdapter>
inline vtkm::filter::Result ClipWithImplicitFunction::DoExecute(
const vtkm::cont::DataSet& input,
......@@ -69,7 +75,7 @@ inline vtkm::filter::Result ClipWithImplicitFunction::DoExecute(
input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex());
vtkm::cont::CellSetExplicit<> outputCellSet = this->Worklet.Run(
vtkm::filter::ApplyPolicy(cells, policy), this->Function, inputCoords, device);
vtkm::filter::ApplyPolicy(cells, policy), this->Function, inputCoords, this->Invert, device);
// compute output coordinates
auto outputCoordsArray = this->Worklet.ProcessPointField(inputCoords.GetData(), device);
......
......@@ -196,9 +196,10 @@ public:
typedef void ExecutionSignature(_2, CellShape, PointCount, _3, _4);
VTKM_CONT
ComputeStats(vtkm::Float64 value, const ClipTablesPortal& clipTables)
ComputeStats(vtkm::Float64 value, const ClipTablesPortal& clipTables, bool invert)
: Value(value)
, ClipTables(clipTables)
, Invert(invert)
{
}
......@@ -215,7 +216,14 @@ public:
vtkm::Id caseId = 0;
for (vtkm::IdComponent i = 0; i < count; ++i)
{
caseId |= (static_cast<vtkm::Float64>(scalars[i]) > this->Value) ? mask[i] : 0;
if (this->Invert)
{
caseId |= (static_cast<vtkm::Float64>(scalars[i]) <= this->Value) ? mask[i] : 0;
}
else
{
caseId |= (static_cast<vtkm::Float64>(scalars[i]) > this->Value) ? mask[i] : 0;
}
}
vtkm::Id idx = this->ClipTables.GetCaseIndex(shape.Id, caseId);
......@@ -244,6 +252,7 @@ public:
private:
vtkm::Float64 Value;
ClipTablesPortal ClipTables;
bool Invert;
};
template <typename DeviceAdapter>
......@@ -432,6 +441,7 @@ public:
vtkm::cont::CellSetExplicit<> Run(const vtkm::cont::DynamicCellSetBase<CellSetList>& cellSet,
const ScalarsArrayHandle& scalars,
vtkm::Float64 value,
bool invert,
DeviceAdapter device)
{
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
......@@ -443,7 +453,7 @@ public:
vtkm::cont::ArrayHandle<vtkm::Id> clipTableIdxs;
vtkm::cont::ArrayHandle<ClipStats> stats;
ComputeStats<DeviceAdapter> computeStats(value, clipTablesDevicePortal);
ComputeStats<DeviceAdapter> computeStats(value, clipTablesDevicePortal, invert);
DispatcherMapTopology<ComputeStats<DeviceAdapter>, DeviceAdapter>(computeStats)
.Invoke(cellSet, scalars, clipTableIdxs, stats);
......@@ -521,10 +531,12 @@ public:
ClipWithImplicitFunction(Clip* clipper,
const DynamicCellSet& cellSet,
const vtkm::ImplicitFunction* function,
const bool invert,
vtkm::cont::CellSetExplicit<>* result)
: Clipper(clipper)
, CellSet(&cellSet)
, Function(function)
, Invert(invert)
, Result(result)
{
}
......@@ -538,13 +550,15 @@ public:
handle, this->Function);
// Clip at locations where the implicit function evaluates to 0
*this->Result = this->Clipper->Run(*this->CellSet, clipScalars, 0.0, DeviceAdapter());
*this->Result =
this->Clipper->Run(*this->CellSet, clipScalars, 0.0, this->Invert, DeviceAdapter());
}
private:
Clip* Clipper;
const DynamicCellSet* CellSet;
vtkm::ImplicitFunctionValue Function;
bool Invert;
vtkm::cont::CellSetExplicit<>* Result;
};
......@@ -552,12 +566,13 @@ public:
vtkm::cont::CellSetExplicit<> Run(const vtkm::cont::DynamicCellSetBase<CellSetList>& cellSet,
const vtkm::cont::ImplicitFunctionHandle& clipFunction,
const vtkm::cont::CoordinateSystem& coords,
const bool invert,
DeviceAdapter device)
{
vtkm::cont::CellSetExplicit<> output;
ClipWithImplicitFunction<vtkm::cont::DynamicCellSetBase<CellSetList>, DeviceAdapter> clip(
this, cellSet, clipFunction.PrepareForExecution(device), &output);
this, cellSet, clipFunction.PrepareForExecution(device), invert, &output);
CastAndCall(coords, clip);
return output;
......
......@@ -129,8 +129,9 @@ void TestClippingExplicit()
vtkm::cont::DataSet ds = MakeTestDatasetExplicit();
vtkm::worklet::Clip clip;
vtkm::cont::CellSetExplicit<> outputCellSet =
clip.Run(ds.GetCellSet(0), ds.GetField("scalars").GetData(), clipValue, DeviceAdapter());
bool invertClip = false;
vtkm::cont::CellSetExplicit<> outputCellSet = clip.Run(
ds.GetCellSet(0), ds.GetField("scalars").GetData(), clipValue, invertClip, DeviceAdapter());
auto coordsIn = ds.GetCoordinateSystem("coords").GetData();
vtkm::cont::ArrayHandle<Coord3D> coords = clip.ProcessPointField(coordsIn, DeviceAdapter());
......@@ -183,9 +184,10 @@ void TestClippingStrucutred()
vtkm::cont::DataSet ds = MakeTestDatasetStructured();
bool invertClip = false;
vtkm::worklet::Clip clip;
vtkm::cont::CellSetExplicit<> outputCellSet =
clip.Run(ds.GetCellSet(0), ds.GetField("scalars").GetData(), clipValue, DeviceAdapter());
vtkm::cont::CellSetExplicit<> outputCellSet = clip.Run(
ds.GetCellSet(0), ds.GetField("scalars").GetData(), clipValue, invertClip, DeviceAdapter());
auto coordsIn = ds.GetCoordinateSystem("coords").GetData();
CoordsOutType coords = clip.ProcessPointField(coordsIn, DeviceAdapter());
......@@ -243,12 +245,13 @@ void TestClippingWithImplicitFunction()
vtkm::FloatDefault radius(0.5);
vtkm::cont::DataSet ds = MakeTestDatasetStructured();
bool invertClip = false;
vtkm::worklet::Clip clip;
vtkm::cont::CellSetExplicit<> outputCellSet =
clip.Run(ds.GetCellSet(0),
vtkm::cont::make_ImplicitFunctionHandle<vtkm::Sphere>(center, radius),
ds.GetCoordinateSystem("coords"),
invertClip,
DeviceAdapter());
auto coordsIn = ds.GetCoordinateSystem("coords").GetData();
......
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