mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 21:33:55 +00:00
Migrate ExtractStructured
DoMapField add back deprecated ExtractStructured.h
This commit is contained in:
parent
e3703b09cf
commit
7e08f4fb1b
@ -48,7 +48,6 @@ set(common_headers
|
||||
set(common_header_template_sources
|
||||
CellAverage.hxx
|
||||
CellMeasures.hxx
|
||||
ExtractStructured.hxx
|
||||
FilterDataSet.hxx
|
||||
FilterDataSetWithField.hxx
|
||||
FilterField.hxx
|
||||
@ -61,7 +60,6 @@ set(common_header_template_sources
|
||||
|
||||
set(common_sources_device
|
||||
CellAverage.cxx
|
||||
ExtractStructured.cxx
|
||||
PointAverage.cxx
|
||||
Threshold.cxx
|
||||
)
|
||||
|
@ -1,68 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt 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.
|
||||
//============================================================================
|
||||
#define vtkm_filter_ExtractStructured_cxx
|
||||
#include <vtkm/filter/ExtractStructured.h>
|
||||
#include <vtkm/filter/ExtractStructured.hxx>
|
||||
|
||||
#include <vtkm/filter/MapFieldPermutation.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
ExtractStructured::ExtractStructured()
|
||||
: vtkm::filter::FilterDataSet<ExtractStructured>()
|
||||
, VOI(vtkm::RangeId3(0, -1, 0, -1, 0, -1))
|
||||
, SampleRate(vtkm::Id3(1, 1, 1))
|
||||
, IncludeBoundary(false)
|
||||
, IncludeOffset(false)
|
||||
, Worklet()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ExtractStructured::MapFieldOntoOutput(vtkm::cont::DataSet& result,
|
||||
const vtkm::cont::Field& field)
|
||||
{
|
||||
if (field.IsFieldPoint())
|
||||
{
|
||||
return vtkm::filter::MapFieldPermutation(field, this->PointFieldMap, result);
|
||||
}
|
||||
else if (field.IsFieldCell())
|
||||
{
|
||||
return vtkm::filter::MapFieldPermutation(field, this->CellFieldMap, result);
|
||||
}
|
||||
else if (field.IsFieldGlobal())
|
||||
{
|
||||
result.AddField(field);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void ExtractStructured::PostExecute(const vtkm::cont::PartitionedDataSet&,
|
||||
vtkm::cont::PartitionedDataSet&)
|
||||
{
|
||||
this->CellFieldMap.ReleaseResources();
|
||||
this->PointFieldMap.ReleaseResources();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template VTKM_FILTER_COMMON_TEMPLATE_EXPORT vtkm::cont::DataSet ExtractStructured::DoExecute(
|
||||
const vtkm::cont::DataSet& inData,
|
||||
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault> policy);
|
||||
}
|
||||
}
|
@ -7,126 +7,35 @@
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#ifndef vtk_m_filter_ExtractStructured_h
|
||||
#define vtk_m_filter_ExtractStructured_h
|
||||
|
||||
#include <vtkm/filter/vtkm_filter_common_export.h>
|
||||
|
||||
#include <vtkm/filter/FilterDataSet.h>
|
||||
#include <vtkm/worklet/ExtractStructured.h>
|
||||
#include <vtkm/Deprecated.h>
|
||||
#include <vtkm/filter/entity_extraction/ExtractStructured.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
/// \brief Select piece (e.g., volume of interest) and/or subsample structured points dataset
|
||||
///
|
||||
/// Select or subsample a portion of an input structured dataset. The selected
|
||||
/// portion of interested is referred to as the Volume Of Interest, or VOI.
|
||||
/// The output of this filter is a structured dataset. The filter treats input
|
||||
/// data of any topological dimension (i.e., point, line, plane, or volume) and
|
||||
/// can generate output data of any topological dimension.
|
||||
///
|
||||
/// To use this filter set the VOI ivar which are i-j-k min/max indices that
|
||||
/// specify a rectangular region in the data. (Note that these are 0-offset.)
|
||||
/// You can also specify a sampling rate to subsample the data.
|
||||
///
|
||||
/// Typical applications of this filter are to extract a slice from a volume
|
||||
/// for image processing, subsampling large volumes to reduce data size, or
|
||||
/// extracting regions of a volume with interesting data.
|
||||
///
|
||||
class VTKM_FILTER_COMMON_EXPORT ExtractStructured
|
||||
: public vtkm::filter::FilterDataSet<ExtractStructured>
|
||||
|
||||
VTKM_DEPRECATED(1.8,
|
||||
"Use vtkm/filter/entity_extraction/ExtractStructured.h instead of "
|
||||
"vtkm/filter/ExtractStructured.h.")
|
||||
inline void ExtractStructured_deprecated() {}
|
||||
|
||||
inline void ExtractStructured_deprecated_warning()
|
||||
{
|
||||
public:
|
||||
ExtractStructured();
|
||||
ExtractStructured_deprecated();
|
||||
}
|
||||
|
||||
// Set the bounding box for the volume of interest
|
||||
VTKM_CONT
|
||||
vtkm::RangeId3 GetVOI() const { return this->VOI; }
|
||||
|
||||
VTKM_CONT
|
||||
void SetVOI(vtkm::Id i0, vtkm::Id i1, vtkm::Id j0, vtkm::Id j1, vtkm::Id k0, vtkm::Id k1)
|
||||
{
|
||||
this->VOI = vtkm::RangeId3(i0, i1, j0, j1, k0, k1);
|
||||
}
|
||||
VTKM_CONT
|
||||
void SetVOI(vtkm::Id extents[6]) { this->VOI = vtkm::RangeId3(extents); }
|
||||
VTKM_CONT
|
||||
void SetVOI(vtkm::Id3 minPoint, vtkm::Id3 maxPoint)
|
||||
{
|
||||
this->VOI = vtkm::RangeId3(minPoint, maxPoint);
|
||||
}
|
||||
VTKM_CONT
|
||||
void SetVOI(const vtkm::RangeId3& voi) { this->VOI = voi; }
|
||||
|
||||
/// Get the Sampling rate
|
||||
VTKM_CONT
|
||||
vtkm::Id3 GetSampleRate() const { return this->SampleRate; }
|
||||
|
||||
/// Set the Sampling rate
|
||||
VTKM_CONT
|
||||
void SetSampleRate(vtkm::Id i, vtkm::Id j, vtkm::Id k) { this->SampleRate = vtkm::Id3(i, j, k); }
|
||||
|
||||
/// Set the Sampling rate
|
||||
VTKM_CONT
|
||||
void SetSampleRate(vtkm::Id3 sampleRate) { this->SampleRate = sampleRate; }
|
||||
|
||||
/// Get if we should include the outer boundary on a subsample
|
||||
VTKM_CONT
|
||||
bool GetIncludeBoundary() { return this->IncludeBoundary; }
|
||||
/// Set if we should include the outer boundary on a subsample
|
||||
VTKM_CONT
|
||||
void SetIncludeBoundary(bool value) { this->IncludeBoundary = value; }
|
||||
|
||||
VTKM_CONT
|
||||
void SetIncludeOffset(bool value) { this->IncludeOffset = value; }
|
||||
|
||||
template <typename DerivedPolicy>
|
||||
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
|
||||
vtkm::filter::PolicyBase<DerivedPolicy> policy);
|
||||
|
||||
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field);
|
||||
|
||||
template <typename DerivedPolicy>
|
||||
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result,
|
||||
const vtkm::cont::Field& field,
|
||||
vtkm::filter::PolicyBase<DerivedPolicy>)
|
||||
{
|
||||
return this->MapFieldOntoOutput(result, field);
|
||||
}
|
||||
|
||||
|
||||
VTKM_CONT void PostExecute(const vtkm::cont::PartitionedDataSet&,
|
||||
vtkm::cont::PartitionedDataSet&);
|
||||
|
||||
template <typename DerivedPolicy>
|
||||
VTKM_CONT void PostExecute(const vtkm::cont::PartitionedDataSet& input,
|
||||
vtkm::cont::PartitionedDataSet& output,
|
||||
const vtkm::filter::PolicyBase<DerivedPolicy>&)
|
||||
{
|
||||
this->PostExecute(input, output);
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::RangeId3 VOI;
|
||||
vtkm::Id3 SampleRate = { 1, 1, 1 };
|
||||
bool IncludeBoundary;
|
||||
bool IncludeOffset;
|
||||
vtkm::worklet::ExtractStructured Worklet;
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> CellFieldMap;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> PointFieldMap;
|
||||
class VTKM_DEPRECATED(1.8,
|
||||
"Use vtkm::filter::entity_extraction::ExtractStructured.") ExtractStructured
|
||||
: public vtkm::filter::entity_extraction::ExtractStructured
|
||||
{
|
||||
using entity_extraction::ExtractStructured::ExtractStructured;
|
||||
};
|
||||
|
||||
#ifndef vtkm_filter_ExtractStructured_cxx
|
||||
extern template VTKM_FILTER_COMMON_TEMPLATE_EXPORT vtkm::cont::DataSet ExtractStructured::DoExecute(
|
||||
const vtkm::cont::DataSet&,
|
||||
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
|
||||
#endif
|
||||
}
|
||||
} // namespace vtkm::filter
|
||||
|
||||
|
||||
#endif // vtk_m_filter_ExtractStructured_h
|
||||
#endif //vtk_m_filter_ExtractStructured_h
|
||||
|
@ -1,52 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt 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.
|
||||
//============================================================================
|
||||
|
||||
#ifndef vtk_m_filter_ExtractStructured_hxx
|
||||
#define vtk_m_filter_ExtractStructured_hxx
|
||||
#include <vtkm/filter/ExtractStructured.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename DerivedPolicy>
|
||||
vtkm::cont::DataSet ExtractStructured::DoExecute(const vtkm::cont::DataSet& input,
|
||||
vtkm::filter::PolicyBase<DerivedPolicy> policy)
|
||||
{
|
||||
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
|
||||
const vtkm::cont::CoordinateSystem& coordinates = input.GetCoordinateSystem();
|
||||
|
||||
auto cellset = this->Worklet.Run(vtkm::filter::ApplyPolicyCellSetStructured(cells, policy, *this),
|
||||
this->VOI,
|
||||
this->SampleRate,
|
||||
this->IncludeBoundary,
|
||||
this->IncludeOffset);
|
||||
|
||||
auto coords = this->Worklet.MapCoordinates(coordinates);
|
||||
vtkm::cont::CoordinateSystem outputCoordinates(coordinates.GetName(), coords);
|
||||
|
||||
vtkm::cont::DataSet output;
|
||||
output.SetCellSet(vtkm::cont::UnknownCellSet(cellset));
|
||||
output.AddCoordinateSystem(outputCoordinates);
|
||||
|
||||
// Create map arrays for mapping fields. Could potentially save some time to first check to see
|
||||
// if these arrays would be used.
|
||||
this->CellFieldMap =
|
||||
this->Worklet.ProcessCellField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfCells()));
|
||||
this->PointFieldMap =
|
||||
this->Worklet.ProcessPointField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfPoints()));
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -18,8 +18,8 @@
|
||||
#include <vtkm/cont/UnknownCellSet.h>
|
||||
|
||||
#include <vtkm/RangeId3.h>
|
||||
#include <vtkm/filter/ExtractStructured.h>
|
||||
#include <vtkm/filter/MapFieldPermutation.h>
|
||||
#include <vtkm/filter/entity_extraction/ExtractStructured.h>
|
||||
#include <vtkm/worklet/CellDeepCopy.h>
|
||||
|
||||
namespace
|
||||
@ -318,7 +318,7 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(
|
||||
if (CanDoStructuredStrip(
|
||||
cells, field, this->Invoke, this->GetRemoveAllGhost(), this->GetRemoveType(), range))
|
||||
{
|
||||
vtkm::filter::ExtractStructured extract;
|
||||
vtkm::filter::entity_extraction::ExtractStructured extract;
|
||||
extract.SetInvoker(this->Invoke);
|
||||
vtkm::RangeId3 erange(
|
||||
range.X.Min, range.X.Max + 2, range.Y.Min, range.Y.Max + 2, range.Z.Min, range.Z.Max + 2);
|
||||
|
@ -11,6 +11,7 @@ set(entity_extraction_headers
|
||||
ExternalFaces.h
|
||||
ExtractGeometry.h
|
||||
ExtractPoints.h
|
||||
ExtractStructured.h
|
||||
MaskPoints.h
|
||||
ThresholdPoints.h
|
||||
)
|
||||
@ -18,6 +19,7 @@ set(entity_extraction_sources_device
|
||||
ExternalFaces.cxx
|
||||
ExtractGeometry.cxx
|
||||
ExtractPoints.cxx
|
||||
ExtractStructured.cxx
|
||||
MaskPoints.cxx
|
||||
ThresholdPoints.cxx
|
||||
)
|
||||
|
@ -15,6 +15,15 @@
|
||||
#include <vtkm/filter/entity_extraction/ExtractGeometry.h>
|
||||
#include <vtkm/filter/entity_extraction/worklet/ExtractGeometry.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
} // end anon namespace
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
namespace
|
||||
{
|
||||
struct CallWorker
|
||||
@ -55,12 +64,33 @@ struct CallWorker
|
||||
this->ExtractOnlyBoundaryCells);
|
||||
}
|
||||
};
|
||||
} // end anon namespace
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
bool DoMapField(vtkm::cont::DataSet& result,
|
||||
const vtkm::cont::Field& field,
|
||||
const vtkm::worklet::ExtractGeometry& Worklet)
|
||||
{
|
||||
if (field.IsFieldPoint())
|
||||
{
|
||||
result.AddField(field);
|
||||
return true;
|
||||
}
|
||||
else if (field.IsFieldCell())
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> permutation = Worklet.GetValidCellIds();
|
||||
return vtkm::filter::MapFieldPermutation(field, permutation, result);
|
||||
}
|
||||
else if (field.IsFieldGlobal())
|
||||
{
|
||||
result.AddField(field);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
namespace entity_extraction
|
||||
{
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -87,38 +117,12 @@ vtkm::cont::DataSet ExtractGeometry::DoExecute(const vtkm::cont::DataSet& input)
|
||||
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
|
||||
output.SetCellSet(outCells);
|
||||
|
||||
auto mapper = [&, this](auto& result, const auto& f) {
|
||||
this->MapFieldOntoOutput(result, f, Worklet);
|
||||
};
|
||||
auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f, Worklet); };
|
||||
MapFieldsOntoOutput(input, output, mapper);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
bool ExtractGeometry::MapFieldOntoOutput(vtkm::cont::DataSet& result,
|
||||
const vtkm::cont::Field& field,
|
||||
const vtkm::worklet::ExtractGeometry& Worklet)
|
||||
{
|
||||
if (field.IsFieldPoint())
|
||||
{
|
||||
result.AddField(field);
|
||||
return true;
|
||||
}
|
||||
else if (field.IsFieldCell())
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> permutation = Worklet.GetValidCellIds();
|
||||
return vtkm::filter::MapFieldPermutation(field, permutation, result);
|
||||
}
|
||||
else if (field.IsFieldGlobal())
|
||||
{
|
||||
result.AddField(field);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // namespace entity_extraction
|
||||
} // namespace filter
|
||||
} // namespace vtkm
|
||||
|
@ -81,10 +81,6 @@ private:
|
||||
VTKM_CONT
|
||||
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
|
||||
|
||||
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result,
|
||||
const vtkm::cont::Field& field,
|
||||
const vtkm::worklet::ExtractGeometry&);
|
||||
|
||||
bool ExtractInside = true;
|
||||
bool ExtractBoundaryCells = false;
|
||||
bool ExtractOnlyBoundaryCells = false;
|
||||
|
@ -17,6 +17,28 @@ namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
namespace
|
||||
{
|
||||
bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field)
|
||||
{
|
||||
// point data is copied as is because it was not collapsed
|
||||
if (field.IsFieldPoint())
|
||||
{
|
||||
result.AddField(field);
|
||||
return true;
|
||||
}
|
||||
else if (field.IsFieldGlobal())
|
||||
{
|
||||
result.AddField(field);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// cell data does not apply
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace entity_extraction
|
||||
{
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -40,7 +62,7 @@ vtkm::cont::DataSet ExtractPoints::DoExecute(const vtkm::cont::DataSet& input)
|
||||
output.SetCellSet(outCellSet);
|
||||
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
|
||||
|
||||
auto mapper = [&, this](auto& result, const auto& f) { this->MapFieldOntoOutput(result, f); };
|
||||
auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f); };
|
||||
this->MapFieldsOntoOutput(input, output, mapper);
|
||||
|
||||
// compact the unused points in the output dataset
|
||||
@ -57,27 +79,6 @@ vtkm::cont::DataSet ExtractPoints::DoExecute(const vtkm::cont::DataSet& input)
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
VTKM_CONT bool ExtractPoints::MapFieldOntoOutput(vtkm::cont::DataSet& result,
|
||||
const vtkm::cont::Field& field)
|
||||
{
|
||||
// point data is copied as is because it was not collapsed
|
||||
if (field.IsFieldPoint())
|
||||
{
|
||||
result.AddField(field);
|
||||
return true;
|
||||
}
|
||||
else if (field.IsFieldGlobal())
|
||||
{
|
||||
result.AddField(field);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// cell data does not apply
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // namespace entity_extraction
|
||||
} // namespace filter
|
||||
} // namespace vtkm
|
||||
|
@ -63,9 +63,6 @@ private:
|
||||
VTKM_CONT
|
||||
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
|
||||
|
||||
//Map a new field onto the resulting dataset after running the filter
|
||||
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field);
|
||||
|
||||
bool ExtractInside = true;
|
||||
vtkm::ImplicitFunctionGeneral Function;
|
||||
|
||||
|
88
vtkm/filter/entity_extraction/ExtractStructured.cxx
Normal file
88
vtkm/filter/entity_extraction/ExtractStructured.cxx
Normal file
@ -0,0 +1,88 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt 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 <vtkm/cont/ArrayHandleIndex.h>
|
||||
|
||||
#include <vtkm/filter/MapFieldPermutation.h>
|
||||
#include <vtkm/filter/entity_extraction/ExtractStructured.h>
|
||||
|
||||
#include <vtkm/filter/entity_extraction/worklet/ExtractStructured.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
namespace
|
||||
{
|
||||
VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result,
|
||||
const vtkm::cont::Field& field,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id>& CellFieldMap,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id>& PointFieldMap)
|
||||
{
|
||||
if (field.IsFieldPoint())
|
||||
{
|
||||
return vtkm::filter::MapFieldPermutation(field, PointFieldMap, result);
|
||||
}
|
||||
else if (field.IsFieldCell())
|
||||
{
|
||||
return vtkm::filter::MapFieldPermutation(field, CellFieldMap, result);
|
||||
}
|
||||
else if (field.IsFieldGlobal())
|
||||
{
|
||||
result.AddField(field);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace entity_extraction
|
||||
{
|
||||
//-----------------------------------------------------------------------------
|
||||
vtkm::cont::DataSet ExtractStructured::DoExecute(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
|
||||
const vtkm::cont::CoordinateSystem& coordinates = input.GetCoordinateSystem();
|
||||
|
||||
vtkm::worklet::ExtractStructured Worklet;
|
||||
auto cellset = Worklet.Run(cells.ResetCellSetList<VTKM_DEFAULT_CELL_SET_LIST_STRUCTURED>(),
|
||||
this->VOI,
|
||||
this->SampleRate,
|
||||
this->IncludeBoundary,
|
||||
this->IncludeOffset);
|
||||
|
||||
auto coords = Worklet.MapCoordinates(coordinates);
|
||||
vtkm::cont::CoordinateSystem outputCoordinates(coordinates.GetName(), coords);
|
||||
|
||||
vtkm::cont::DataSet output;
|
||||
output.SetCellSet(vtkm::cont::UnknownCellSet(cellset));
|
||||
output.AddCoordinateSystem(outputCoordinates);
|
||||
|
||||
// Create map arrays for mapping fields. Could potentially save some time to first check to see
|
||||
// if these arrays would be used.
|
||||
auto CellFieldMap =
|
||||
Worklet.ProcessCellField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfCells()));
|
||||
auto PointFieldMap =
|
||||
Worklet.ProcessPointField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfPoints()));
|
||||
|
||||
auto mapper = [&, this](auto& result, const auto& f) {
|
||||
DoMapField(result, f, CellFieldMap, PointFieldMap);
|
||||
};
|
||||
MapFieldsOntoOutput(input, output, mapper);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
} // namespace entity_extraction
|
||||
} // namespace filter
|
||||
} // namespace vtkm
|
98
vtkm/filter/entity_extraction/ExtractStructured.h
Normal file
98
vtkm/filter/entity_extraction/ExtractStructured.h
Normal file
@ -0,0 +1,98 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt 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.
|
||||
//============================================================================
|
||||
|
||||
#ifndef vtk_m_filter_entity_extraction_ExtractStructured_h
|
||||
#define vtk_m_filter_entity_extraction_ExtractStructured_h
|
||||
|
||||
#include <vtkm/RangeId3.h>
|
||||
#include <vtkm/filter/NewFilterField.h>
|
||||
#include <vtkm/filter/entity_extraction/vtkm_filter_entity_extraction_export.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
namespace entity_extraction
|
||||
{
|
||||
/// \brief Select piece (e.g., volume of interest) and/or subsample structured points dataset
|
||||
///
|
||||
/// Select or subsample a portion of an input structured dataset. The selected
|
||||
/// portion of interested is referred to as the Volume Of Interest, or VOI.
|
||||
/// The output of this filter is a structured dataset. The filter treats input
|
||||
/// data of any topological dimension (i.e., point, line, plane, or volume) and
|
||||
/// can generate output data of any topological dimension.
|
||||
///
|
||||
/// To use this filter set the VOI ivar which are i-j-k min/max indices that
|
||||
/// specify a rectangular region in the data. (Note that these are 0-offset.)
|
||||
/// You can also specify a sampling rate to subsample the data.
|
||||
///
|
||||
/// Typical applications of this filter are to extract a slice from a volume
|
||||
/// for image processing, subsampling large volumes to reduce data size, or
|
||||
/// extracting regions of a volume with interesting data.
|
||||
///
|
||||
class VTKM_FILTER_ENTITY_EXTRACTION_EXPORT ExtractStructured : public vtkm::filter::NewFilterField
|
||||
{
|
||||
public:
|
||||
// Set the bounding box for the volume of interest
|
||||
VTKM_CONT
|
||||
vtkm::RangeId3 GetVOI() const { return this->VOI; }
|
||||
|
||||
VTKM_CONT
|
||||
void SetVOI(vtkm::Id i0, vtkm::Id i1, vtkm::Id j0, vtkm::Id j1, vtkm::Id k0, vtkm::Id k1)
|
||||
{
|
||||
this->VOI = vtkm::RangeId3(i0, i1, j0, j1, k0, k1);
|
||||
}
|
||||
VTKM_CONT
|
||||
void SetVOI(vtkm::Id extents[6]) { this->VOI = vtkm::RangeId3(extents); }
|
||||
VTKM_CONT
|
||||
void SetVOI(vtkm::Id3 minPoint, vtkm::Id3 maxPoint)
|
||||
{
|
||||
this->VOI = vtkm::RangeId3(minPoint, maxPoint);
|
||||
}
|
||||
VTKM_CONT
|
||||
void SetVOI(const vtkm::RangeId3& voi) { this->VOI = voi; }
|
||||
|
||||
/// Get the Sampling rate
|
||||
VTKM_CONT
|
||||
vtkm::Id3 GetSampleRate() const { return this->SampleRate; }
|
||||
|
||||
/// Set the Sampling rate
|
||||
VTKM_CONT
|
||||
void SetSampleRate(vtkm::Id i, vtkm::Id j, vtkm::Id k) { this->SampleRate = vtkm::Id3(i, j, k); }
|
||||
|
||||
/// Set the Sampling rate
|
||||
VTKM_CONT
|
||||
void SetSampleRate(vtkm::Id3 sampleRate) { this->SampleRate = sampleRate; }
|
||||
|
||||
/// Get if we should include the outer boundary on a subsample
|
||||
VTKM_CONT
|
||||
bool GetIncludeBoundary() { return this->IncludeBoundary; }
|
||||
/// Set if we should include the outer boundary on a subsample
|
||||
VTKM_CONT
|
||||
void SetIncludeBoundary(bool value) { this->IncludeBoundary = value; }
|
||||
|
||||
VTKM_CONT
|
||||
void SetIncludeOffset(bool value) { this->IncludeOffset = value; }
|
||||
|
||||
private:
|
||||
VTKM_CONT
|
||||
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
|
||||
|
||||
vtkm::RangeId3 VOI = vtkm::RangeId3(0, -1, 0, -1, 0, -1);
|
||||
vtkm::Id3 SampleRate = { 1, 1, 1 };
|
||||
bool IncludeBoundary = false;
|
||||
bool IncludeOffset = false;
|
||||
};
|
||||
|
||||
} // namespace entity_extraction
|
||||
} // namespace filter
|
||||
} // namespace vtkm
|
||||
|
||||
#endif // vtk_m_filter_entity_extraction_ExtractStructured_h
|
@ -12,49 +12,9 @@
|
||||
#include <vtkm/filter/entity_extraction/MaskPoints.h>
|
||||
#include <vtkm/filter/entity_extraction/worklet/MaskPoints.h>
|
||||
|
||||
namespace vtkm
|
||||
namespace
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
namespace entity_extraction
|
||||
{
|
||||
//-----------------------------------------------------------------------------
|
||||
VTKM_CONT vtkm::cont::DataSet MaskPoints::DoExecute(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
// extract the input cell set
|
||||
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
|
||||
|
||||
// run the worklet on the cell set and input field
|
||||
vtkm::cont::CellSetSingleType<> outCellSet;
|
||||
vtkm::worklet::MaskPoints worklet;
|
||||
|
||||
outCellSet = worklet.Run(cells, this->Stride);
|
||||
|
||||
// create the output dataset
|
||||
vtkm::cont::DataSet output;
|
||||
output.SetCellSet(outCellSet);
|
||||
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
|
||||
|
||||
auto mapper = [&, this](auto& result, const auto& f) { this->MapFieldOntoOutput(result, f); };
|
||||
this->MapFieldsOntoOutput(input, output, mapper);
|
||||
|
||||
// compact the unused points in the output dataset
|
||||
if (this->CompactPoints)
|
||||
{
|
||||
vtkm::filter::clean_grid::CleanGrid compactor;
|
||||
compactor.SetCompactPointFields(true);
|
||||
compactor.SetMergePoints(false);
|
||||
return compactor.Execute(output);
|
||||
}
|
||||
else
|
||||
{
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
VTKM_CONT bool MaskPoints::MapFieldOntoOutput(vtkm::cont::DataSet& result,
|
||||
const vtkm::cont::Field& field)
|
||||
bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field)
|
||||
{
|
||||
// point data is copied as is because it was not collapsed
|
||||
if (field.IsFieldPoint())
|
||||
@ -73,6 +33,49 @@ VTKM_CONT bool MaskPoints::MapFieldOntoOutput(vtkm::cont::DataSet& result,
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
namespace entity_extraction
|
||||
{
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
VTKM_CONT vtkm::cont::DataSet MaskPoints::DoExecute(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
// extract the input cell set
|
||||
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
|
||||
|
||||
// run the worklet on the cell set and input field
|
||||
vtkm::cont::CellSetSingleType<> outCellSet;
|
||||
vtkm::worklet::MaskPoints worklet;
|
||||
|
||||
outCellSet = worklet.Run(cells, this->Stride);
|
||||
|
||||
// create the output dataset
|
||||
vtkm::cont::DataSet output;
|
||||
output.SetCellSet(outCellSet);
|
||||
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
|
||||
|
||||
auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f); };
|
||||
this->MapFieldsOntoOutput(input, output, mapper);
|
||||
|
||||
// compact the unused points in the output dataset
|
||||
if (this->CompactPoints)
|
||||
{
|
||||
vtkm::filter::clean_grid::CleanGrid compactor;
|
||||
compactor.SetCompactPointFields(true);
|
||||
compactor.SetMergePoints(false);
|
||||
return compactor.Execute(output);
|
||||
}
|
||||
else
|
||||
{
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace entity_extraction
|
||||
} // namespace filter
|
||||
} // namespace vtkm
|
||||
|
@ -42,8 +42,6 @@ private:
|
||||
VTKM_CONT
|
||||
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
|
||||
|
||||
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field);
|
||||
|
||||
vtkm::Id Stride = 1;
|
||||
bool CompactPoints = true;
|
||||
};
|
||||
|
@ -77,12 +77,34 @@ private:
|
||||
vtkm::Float64 Lower;
|
||||
vtkm::Float64 Upper;
|
||||
};
|
||||
|
||||
bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field)
|
||||
{
|
||||
// point data is copied as is because it was not collapsed
|
||||
if (field.IsFieldPoint())
|
||||
{
|
||||
result.AddField(field);
|
||||
return true;
|
||||
}
|
||||
else if (field.IsFieldGlobal())
|
||||
{
|
||||
result.AddField(field);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// cell data does not apply
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
|
||||
namespace entity_extraction
|
||||
{
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -156,7 +178,7 @@ VTKM_CONT vtkm::cont::DataSet ThresholdPoints::DoExecute(const vtkm::cont::DataS
|
||||
output.SetCellSet(outCellSet);
|
||||
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
|
||||
|
||||
auto mapper = [&, this](auto& result, const auto& f) { this->MapFieldOntoOutput(result, f); };
|
||||
auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f); };
|
||||
this->MapFieldsOntoOutput(input, output, mapper);
|
||||
|
||||
// compact the unused points in the output dataset
|
||||
@ -173,27 +195,6 @@ VTKM_CONT vtkm::cont::DataSet ThresholdPoints::DoExecute(const vtkm::cont::DataS
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
VTKM_CONT bool ThresholdPoints::MapFieldOntoOutput(vtkm::cont::DataSet& result,
|
||||
const vtkm::cont::Field& field)
|
||||
{
|
||||
// point data is copied as is because it was not collapsed
|
||||
if (field.IsFieldPoint())
|
||||
{
|
||||
result.AddField(field);
|
||||
return true;
|
||||
}
|
||||
else if (field.IsFieldGlobal())
|
||||
{
|
||||
result.AddField(field);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// cell data does not apply
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // namespace entity_extraction
|
||||
} // namespace filter
|
||||
} // namespace vtkm
|
||||
|
@ -51,8 +51,6 @@ private:
|
||||
VTKM_CONT
|
||||
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
|
||||
|
||||
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field);
|
||||
|
||||
constexpr static int THRESHOLD_BELOW = 0;
|
||||
constexpr static int THRESHOLD_ABOVE = 1;
|
||||
constexpr static int THRESHOLD_BETWEEN = 2;
|
||||
|
@ -12,6 +12,7 @@ set(unit_tests
|
||||
UnitTestExternalFacesFilter.cxx
|
||||
UnitTestExtractGeometryFilter.cxx
|
||||
UnitTestExtractPointsFilter.cxx
|
||||
UnitTestExtractStructuredFilter.cxx
|
||||
UnitTestMaskPointsFilter.cxx
|
||||
UnitTestThresholdPointsFilter.cxx
|
||||
)
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <vtkm/filter/ExtractStructured.h>
|
||||
#include <vtkm/filter/entity_extraction/ExtractStructured.h>
|
||||
|
||||
using vtkm::cont::testing::MakeTestDataSet;
|
||||
|
||||
@ -29,7 +29,7 @@ public:
|
||||
vtkm::RangeId3 range(1, 4, 1, 4, 0, 1);
|
||||
vtkm::Id3 sample(1, 1, 1);
|
||||
|
||||
vtkm::filter::ExtractStructured extract;
|
||||
vtkm::filter::entity_extraction::ExtractStructured extract;
|
||||
extract.SetVOI(range);
|
||||
extract.SetSampleRate(sample);
|
||||
|
||||
@ -63,7 +63,7 @@ public:
|
||||
std::cout << "Testing extract structured uniform" << std::endl;
|
||||
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
|
||||
|
||||
vtkm::filter::ExtractStructured extract;
|
||||
vtkm::filter::entity_extraction::ExtractStructured extract;
|
||||
|
||||
// VOI within dataset
|
||||
extract.SetVOI(1, 4, 1, 4, 1, 4);
|
||||
@ -99,7 +99,7 @@ public:
|
||||
std::cout << "Testing extract structured uniform" << std::endl;
|
||||
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
|
||||
|
||||
vtkm::filter::ExtractStructured extract;
|
||||
vtkm::filter::entity_extraction::ExtractStructured extract;
|
||||
|
||||
// VOI surrounds dataset
|
||||
vtkm::Id3 minPoint(-1, -1, -1);
|
||||
@ -136,7 +136,7 @@ public:
|
||||
{
|
||||
std::cout << "Testing extract structured uniform" << std::endl;
|
||||
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
|
||||
vtkm::filter::ExtractStructured extract;
|
||||
vtkm::filter::entity_extraction::ExtractStructured extract;
|
||||
|
||||
// VOI surrounds dataset
|
||||
vtkm::RangeId3 range(-1, 3, -1, 3, -1, 3);
|
||||
@ -173,7 +173,7 @@ public:
|
||||
{
|
||||
std::cout << "Testing extract structured uniform" << std::endl;
|
||||
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
|
||||
vtkm::filter::ExtractStructured extract;
|
||||
vtkm::filter::entity_extraction::ExtractStructured extract;
|
||||
|
||||
// RangeId3 intersects dataset on far boundary
|
||||
vtkm::RangeId3 range(1, 8, 1, 8, 1, 8);
|
||||
@ -211,7 +211,7 @@ public:
|
||||
std::cout << "Testing extract structured uniform" << std::endl;
|
||||
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
|
||||
|
||||
vtkm::filter::ExtractStructured extract;
|
||||
vtkm::filter::entity_extraction::ExtractStructured extract;
|
||||
|
||||
// RangeId3 intersects dataset without corner
|
||||
vtkm::RangeId3 range(2, 8, 1, 4, 1, 4);
|
||||
@ -249,7 +249,7 @@ public:
|
||||
std::cout << "Testing extract structured uniform" << std::endl;
|
||||
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
|
||||
|
||||
vtkm::filter::ExtractStructured extract;
|
||||
vtkm::filter::entity_extraction::ExtractStructured extract;
|
||||
|
||||
// RangeId3 intersects dataset with plane
|
||||
vtkm::RangeId3 range(2, 8, 1, 2, 1, 4);
|
||||
@ -287,7 +287,7 @@ public:
|
||||
std::cout << "Testing extract structured uniform" << std::endl;
|
||||
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
|
||||
|
||||
vtkm::filter::ExtractStructured extract;
|
||||
vtkm::filter::entity_extraction::ExtractStructured extract;
|
||||
|
||||
// RangeId3 within data set with sampling
|
||||
vtkm::RangeId3 range(0, 5, 0, 5, 1, 4);
|
||||
@ -325,7 +325,7 @@ public:
|
||||
std::cout << "Testing extract structured uniform" << std::endl;
|
||||
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
|
||||
|
||||
vtkm::filter::ExtractStructured extract;
|
||||
vtkm::filter::entity_extraction::ExtractStructured extract;
|
||||
|
||||
// RangeId3 within data set with sampling
|
||||
vtkm::RangeId3 range(0, 5, 0, 5, 1, 4);
|
||||
@ -361,7 +361,7 @@ public:
|
||||
{
|
||||
std::cout << "Testing extract structured uniform" << std::endl;
|
||||
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
|
||||
vtkm::filter::ExtractStructured extract;
|
||||
vtkm::filter::entity_extraction::ExtractStructured extract;
|
||||
|
||||
// RangeId3 within data set with sampling
|
||||
vtkm::RangeId3 range(0, 5, 0, 5, 1, 4);
|
||||
@ -401,7 +401,7 @@ public:
|
||||
std::cout << "Testing extract structured rectilinear" << std::endl;
|
||||
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DRectilinearDataSet0();
|
||||
|
||||
vtkm::filter::ExtractStructured extract;
|
||||
vtkm::filter::entity_extraction::ExtractStructured extract;
|
||||
|
||||
// RangeId3
|
||||
vtkm::RangeId3 range(0, 2, 0, 2, 0, 1);
|
||||
@ -438,7 +438,7 @@ public:
|
||||
std::cout << "Testing extract structured rectilinear" << std::endl;
|
||||
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DRectilinearDataSet0();
|
||||
|
||||
vtkm::filter::ExtractStructured extract;
|
||||
vtkm::filter::entity_extraction::ExtractStructured extract;
|
||||
|
||||
// RangeId3 and subsample
|
||||
vtkm::RangeId3 range(0, 2, 0, 2, 0, 2);
|
@ -11,6 +11,7 @@
|
||||
set(headers
|
||||
ExternalFaces.h
|
||||
ExtractGeometry.h
|
||||
ExtractStructured.h
|
||||
ExtractPoints.h
|
||||
MaskPoints.h
|
||||
ThresholdPoints.h
|
||||
|
@ -26,7 +26,6 @@ set(unit_tests
|
||||
UnitTestCoordinateSystemTransform.cxx
|
||||
UnitTestCrossProductFilter.cxx
|
||||
UnitTestEntropyFilter.cxx
|
||||
UnitTestExtractStructuredFilter.cxx
|
||||
UnitTestFieldMetadata.cxx
|
||||
UnitTestFieldSelection.cxx
|
||||
UnitTestFieldToColors.cxx
|
||||
|
@ -27,7 +27,6 @@ set(headers
|
||||
DispatcherPointNeighborhood.h
|
||||
DispatcherReduceByKey.h
|
||||
DotProduct.h
|
||||
ExtractStructured.h
|
||||
FieldEntropy.h
|
||||
FieldHistogram.h
|
||||
FieldStatistics.h
|
||||
|
@ -32,7 +32,6 @@ set(unit_tests
|
||||
UnitTestCrossProduct.cxx
|
||||
UnitTestDescriptiveStatistics.cxx
|
||||
UnitTestDotProduct.cxx
|
||||
UnitTestExtractStructured.cxx
|
||||
UnitTestFieldHistogram.cxx
|
||||
UnitTestFieldStatistics.cxx
|
||||
UnitTestGraphConnectivity.cxx
|
||||
|
@ -1,339 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt 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 <vtkm/worklet/ExtractStructured.h>
|
||||
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
using vtkm::cont::testing::MakeTestDataSet;
|
||||
|
||||
class TestingExtractStructured
|
||||
{
|
||||
public:
|
||||
void TestUniform2D() const
|
||||
{
|
||||
std::cout << "Testing extract structured uniform 2D" << std::endl;
|
||||
using CellSetType = vtkm::cont::CellSetStructured<2>;
|
||||
|
||||
// Create the input uniform cell set
|
||||
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make2DUniformDataSet1();
|
||||
CellSetType cellSet;
|
||||
dataSet.GetCellSet().AsCellSet(cellSet);
|
||||
|
||||
// RangeId3 and subsample
|
||||
vtkm::RangeId3 range(1, 4, 1, 4, 0, 1);
|
||||
vtkm::Id3 sample(1, 1, 1);
|
||||
bool includeBoundary = false;
|
||||
bool includeOffset = false;
|
||||
|
||||
vtkm::worklet::ExtractStructured worklet;
|
||||
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 9),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 4),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
}
|
||||
|
||||
void TestUniform3D() const
|
||||
{
|
||||
std::cout << "Testing extract structured uniform 3D" << std::endl;
|
||||
using CellSetType = vtkm::cont::CellSetStructured<3>;
|
||||
|
||||
// Create the input uniform cell set
|
||||
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DUniformDataSet1();
|
||||
CellSetType cellSet;
|
||||
dataSet.GetCellSet().AsCellSet(cellSet);
|
||||
|
||||
vtkm::worklet::ExtractStructured worklet;
|
||||
vtkm::worklet::ExtractStructured::UncertainCellSetStructured outCellSet;
|
||||
|
||||
// RangeId3 within dataset
|
||||
vtkm::RangeId3 range0(1, 4, 1, 4, 1, 4);
|
||||
vtkm::Id3 sample(1, 1, 1);
|
||||
bool includeBoundary = false;
|
||||
bool includeOffset = false;
|
||||
|
||||
outCellSet = worklet.Run(cellSet, range0, sample, includeBoundary, includeOffset);
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 27),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
|
||||
// RangeId3 surrounds dataset
|
||||
vtkm::RangeId3 range1(-1, 8, -1, 8, -1, 8);
|
||||
outCellSet = worklet.Run(cellSet, range1, sample, includeBoundary, includeOffset);
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 125),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 64),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
|
||||
// RangeId3 intersects dataset on near boundary
|
||||
vtkm::RangeId3 range2(-1, 3, -1, 3, -1, 3);
|
||||
outCellSet = worklet.Run(cellSet, range2, sample, includeBoundary, includeOffset);
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 27),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
|
||||
// RangeId3 intersects dataset on far boundary
|
||||
vtkm::RangeId3 range3(1, 8, 1, 8, 1, 8);
|
||||
outCellSet = worklet.Run(cellSet, range3, sample, includeBoundary, includeOffset);
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 64),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 27),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
|
||||
// RangeId3 intersects dataset without corner
|
||||
vtkm::RangeId3 range4(2, 8, 1, 4, 1, 4);
|
||||
outCellSet = worklet.Run(cellSet, range4, sample, includeBoundary, includeOffset);
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 27),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
|
||||
// RangeId3 intersects dataset with plane
|
||||
vtkm::RangeId3 range5(2, 8, 1, 2, 1, 4);
|
||||
outCellSet = worklet.Run(cellSet, range5, sample, includeBoundary, includeOffset);
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 9),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 4),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
}
|
||||
|
||||
void TestUniform3D1() const
|
||||
{
|
||||
std::cout << "Testing extract structured uniform with sampling" << std::endl;
|
||||
using CellSetType = vtkm::cont::CellSetStructured<3>;
|
||||
|
||||
// Create the input uniform cell set
|
||||
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DUniformDataSet1();
|
||||
CellSetType cellSet;
|
||||
dataSet.GetCellSet().AsCellSet(cellSet);
|
||||
|
||||
vtkm::worklet::ExtractStructured worklet;
|
||||
vtkm::worklet::ExtractStructured::UncertainCellSetStructured outCellSet;
|
||||
|
||||
// RangeId3 within data set with sampling
|
||||
vtkm::RangeId3 range0(0, 5, 0, 5, 1, 4);
|
||||
vtkm::Id3 sample0(2, 2, 1);
|
||||
bool includeBoundary0 = false;
|
||||
bool includeOffset = false;
|
||||
|
||||
outCellSet = worklet.Run(cellSet, range0, sample0, includeBoundary0, includeOffset);
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 27),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
|
||||
// RangeId3 and subsample
|
||||
vtkm::RangeId3 range1(0, 5, 0, 5, 1, 4);
|
||||
vtkm::Id3 sample1(3, 3, 2);
|
||||
bool includeBoundary1 = false;
|
||||
|
||||
outCellSet = worklet.Run(cellSet, range1, sample1, includeBoundary1, includeOffset);
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 8),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 1),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
|
||||
// RangeId3 and subsample
|
||||
vtkm::RangeId3 range2(0, 5, 0, 5, 1, 4);
|
||||
vtkm::Id3 sample2(3, 3, 2);
|
||||
bool includeBoundary2 = true;
|
||||
|
||||
outCellSet = worklet.Run(cellSet, range2, sample2, includeBoundary2, includeOffset);
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 18),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 4),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
}
|
||||
|
||||
void TestRectilinear2D() const
|
||||
{
|
||||
std::cout << "Testing extract structured rectilinear" << std::endl;
|
||||
using CellSetType = vtkm::cont::CellSetStructured<2>;
|
||||
|
||||
// Create the input uniform cell set
|
||||
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make2DRectilinearDataSet0();
|
||||
CellSetType cellSet;
|
||||
dataSet.GetCellSet().AsCellSet(cellSet);
|
||||
|
||||
// RangeId3 and subsample
|
||||
vtkm::RangeId3 range(0, 2, 0, 2, 0, 1);
|
||||
vtkm::Id3 sample(1, 1, 1);
|
||||
bool includeBoundary = false;
|
||||
bool includeOffset = false;
|
||||
|
||||
// Extract subset
|
||||
vtkm::worklet::ExtractStructured worklet;
|
||||
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 4),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 1),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
}
|
||||
|
||||
void TestRectilinear3D() const
|
||||
{
|
||||
std::cout << "Testing extract structured rectilinear" << std::endl;
|
||||
using CellSetType = vtkm::cont::CellSetStructured<3>;
|
||||
|
||||
// Create the input uniform cell set
|
||||
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DRectilinearDataSet0();
|
||||
CellSetType cellSet;
|
||||
dataSet.GetCellSet().AsCellSet(cellSet);
|
||||
|
||||
// RangeId3 and subsample
|
||||
vtkm::RangeId3 range(0, 2, 0, 2, 0, 2);
|
||||
vtkm::Id3 sample(1, 1, 1);
|
||||
bool includeBoundary = false;
|
||||
bool includeOffset = false;
|
||||
|
||||
// Extract subset
|
||||
vtkm::worklet::ExtractStructured worklet;
|
||||
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 8),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 1),
|
||||
"Wrong result for ExtractStructured worklet");
|
||||
}
|
||||
|
||||
void TestOffset3D1() const
|
||||
{
|
||||
std::cout << "Testing offset 3D-1" << std::endl;
|
||||
using CellSetType = vtkm::cont::CellSetStructured<3>;
|
||||
|
||||
CellSetType cellSet;
|
||||
|
||||
// RangeID3 and subsample
|
||||
vtkm::RangeId3 range(5, 15, 0, 10, 0, 10);
|
||||
vtkm::Id3 sample(1, 1, 1);
|
||||
vtkm::Id3 test_offset(10, 0, 0);
|
||||
vtkm::Id3 no_offset(0, 0, 0);
|
||||
vtkm::Id3 new_dims(5, 10, 10);
|
||||
bool includeBoundary = false;
|
||||
bool includeOffset = false;
|
||||
cellSet.SetPointDimensions(vtkm::make_Vec(10, 10, 10));
|
||||
|
||||
vtkm::worklet::ExtractStructured worklet;
|
||||
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), no_offset));
|
||||
vtkm::Id3 cellDims =
|
||||
outCellSet.AsCellSet<CellSetType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
|
||||
|
||||
includeOffset = true;
|
||||
cellSet.SetGlobalPointIndexStart(test_offset);
|
||||
outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
|
||||
cellDims =
|
||||
outCellSet.AsCellSet<CellSetType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
|
||||
CellSetType cs = outCellSet.AsCellSet<CellSetType>();
|
||||
cellDims = cs.GetPointDimensions();
|
||||
VTKM_TEST_ASSERT(test_equal(cellDims, new_dims));
|
||||
VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), test_offset));
|
||||
}
|
||||
|
||||
void TestOffset3D2() const
|
||||
{
|
||||
std::cout << "Testing Offset 3D-2" << std::endl;
|
||||
using CellSetType = vtkm::cont::CellSetStructured<3>;
|
||||
CellSetType cellSet;
|
||||
vtkm::RangeId3 range(15, 20, 0, 10, 0, 10);
|
||||
vtkm::Id3 sample(1, 1, 1);
|
||||
vtkm::Id3 test_dims(5, 10, 10);
|
||||
vtkm::Id3 gpis(10, 0, 0);
|
||||
vtkm::Id3 test_offset(15, 0, 0);
|
||||
bool includeBoundary = false;
|
||||
bool includeOffset = true;
|
||||
cellSet.SetPointDimensions(vtkm::make_Vec(10, 10, 10));
|
||||
cellSet.SetGlobalPointIndexStart(gpis);
|
||||
vtkm::worklet::ExtractStructured worklet;
|
||||
|
||||
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
|
||||
CellSetType cs = outCellSet.AsCellSet<CellSetType>();
|
||||
vtkm::Id3 cellDims = cs.GetPointDimensions();
|
||||
VTKM_TEST_ASSERT(test_equal(cellDims, test_dims));
|
||||
VTKM_TEST_ASSERT(test_equal(cs.GetGlobalPointIndexStart(), test_offset));
|
||||
}
|
||||
|
||||
void TestOffset3D3() const
|
||||
{
|
||||
std::cout << "Testing Offset 3D-3" << std::endl;
|
||||
using CellSetType = vtkm::cont::CellSetStructured<3>;
|
||||
CellSetType cellSet;
|
||||
vtkm::RangeId3 range(100, 110, 0, 10, 0, 10);
|
||||
vtkm::Id3 sample(1, 1, 1);
|
||||
vtkm::Id3 test_dims(0, 0, 0);
|
||||
bool includeBoundary = false;
|
||||
bool includeOffset = true;
|
||||
cellSet.SetPointDimensions(vtkm::make_Vec(10, 10, 10));
|
||||
vtkm::worklet::ExtractStructured worklet;
|
||||
|
||||
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
|
||||
CellSetType cs = outCellSet.AsCellSet<CellSetType>();
|
||||
VTKM_TEST_ASSERT(test_equal(cs.GetPointDimensions(), test_dims));
|
||||
}
|
||||
void TestOffset2D() const
|
||||
{
|
||||
std::cout << "Testing offset 2D" << std::endl;
|
||||
using CellSetType = vtkm::cont::CellSetStructured<2>;
|
||||
CellSetType cellSet;
|
||||
// RangeID3 and subsample
|
||||
vtkm::RangeId3 range(5, 15, 0, 10, 0, 1);
|
||||
vtkm::Id3 sample(1, 1, 1);
|
||||
vtkm::Id2 test_offset(10, 0);
|
||||
vtkm::Id2 no_offset(0, 0);
|
||||
vtkm::Id2 new_dims(5, 10);
|
||||
bool includeBoundary = false;
|
||||
bool includeOffset = false;
|
||||
cellSet.SetPointDimensions(vtkm::make_Vec(10, 10));
|
||||
vtkm::worklet::ExtractStructured worklet;
|
||||
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
|
||||
VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), no_offset));
|
||||
vtkm::Id2 cellDims =
|
||||
outCellSet.AsCellSet<CellSetType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
|
||||
// Test with offset now
|
||||
includeOffset = true;
|
||||
cellSet.SetGlobalPointIndexStart(test_offset);
|
||||
outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
|
||||
cellDims =
|
||||
outCellSet.AsCellSet<CellSetType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
|
||||
CellSetType cs = outCellSet.AsCellSet<CellSetType>();
|
||||
cellDims = cs.GetPointDimensions();
|
||||
VTKM_TEST_ASSERT(test_equal(cellDims, new_dims));
|
||||
VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), test_offset));
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
TestUniform2D();
|
||||
TestUniform3D();
|
||||
TestUniform3D1();
|
||||
TestRectilinear2D();
|
||||
TestRectilinear3D();
|
||||
TestOffset3D1();
|
||||
TestOffset3D2();
|
||||
TestOffset3D3();
|
||||
TestOffset2D();
|
||||
}
|
||||
};
|
||||
|
||||
int UnitTestExtractStructured(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestingExtractStructured(), argc, argv);
|
||||
}
|
Loading…
Reference in New Issue
Block a user