Add Slice filter and tests

This commit is contained in:
Sujin Philip 2021-05-28 10:55:13 -04:00
parent 0a401c2ace
commit d1b22046eb
10 changed files with 378 additions and 0 deletions

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:715c1e6092793106c9bb02945ea9a02275860eecc95e1a400e1efef80895efa1
size 48999

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:cae74d6c92a6bb469b646eb6e0239fac2340206e3fd1544901e39b7730e27f39
size 59702

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d9f6b4d118390b93e28caf9f452aa6030cef6b6f7cf585b46d41e94db384ed6f
size 57338

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:715c1e6092793106c9bb02945ea9a02275860eecc95e1a400e1efef80895efa1
size 48999

@ -179,6 +179,7 @@ set(contour_headers
ContourTreeUniformAugmented.h
ContourTreeUniformDistributed.h
ContourTreeUniform.h
Slice.h
)
set(contour_header_template_sources
@ -186,12 +187,14 @@ set(contour_header_template_sources
ContourTreeUniformAugmented.hxx
ContourTreeUniformDistributed.hxx
ContourTreeUniform.hxx
Slice.hxx
)
set(contour_sources_device
Contour.cxx
ContourInteger.cxx
ContourScalar.cxx
Slice.cxx
)
set(gradient_headers

31
vtkm/filter/Slice.cxx Normal file

@ -0,0 +1,31 @@
//============================================================================
// 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_Slice_cxx
#define vtk_m_filter_Slice_cxx
#include <vtkm/filter/Contour.h>
#include <vtkm/filter/Contour.hxx>
#include <vtkm/filter/Slice.h>
#include <vtkm/filter/Slice.hxx>
namespace vtkm
{
namespace filter
{
template VTKM_FILTER_CONTOUR_EXPORT vtkm::cont::DataSet Slice::DoExecute(
const vtkm::cont::DataSet&,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
}
} // vtkm::filter
#endif // vtk_m_filter_Slice_cxx

133
vtkm/filter/Slice.h Normal file

@ -0,0 +1,133 @@
//============================================================================
// 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_Slice_h
#define vtk_m_filter_Slice_h
#include <vtkm/filter/vtkm_filter_contour_export.h>
#include <vtkm/filter/Contour.h>
#include <vtkm/filter/FilterDataSet.h>
#include <vtkm/ImplicitFunction.h>
namespace vtkm
{
namespace filter
{
class VTKM_FILTER_CONTOUR_EXPORT Slice : public vtkm::filter::FilterDataSet<Slice>
{
public:
/// Set/Get the implicit function that is used to perform the slicing.
///
VTKM_CONT
void SetImplicitFunction(const vtkm::ImplicitFunctionGeneral& func) { this->Function = func; }
VTKM_CONT
const vtkm::ImplicitFunctionGeneral& GetImplicitFunction() const { return this->Function; }
/// Set/Get whether the points generated should be unique for every triangle
/// or will duplicate points be merged together. Duplicate points are identified
/// by the unique edge it was generated from.
///
VTKM_CONT
void SetMergeDuplicatePoints(bool on) { this->ContourFilter.SetMergeDuplicatePoints(on); }
VTKM_CONT
bool GetMergeDuplicatePoints() const { return this->ContourFilter.GetMergeDuplicatePoints(); }
/// Set/Get whether normals should be generated. Off by default. If enabled,
/// the default behaviour is to generate high quality normals for structured
/// datasets, using gradients, and generate fast normals for unstructured
/// datasets based on the result triangle mesh.
///
VTKM_CONT
void SetGenerateNormals(bool on) { this->ContourFilter.SetGenerateNormals(on); }
VTKM_CONT
bool GetGenerateNormals() const { return this->ContourFilter.GetGenerateNormals(); }
/// Set/Get whether to append the ids of the intersected edges to the vertices of the isosurface
/// triangles. Off by default.
VTKM_CONT
void SetAddInterpolationEdgeIds(bool on) { this->ContourFilter.SetAddInterpolationEdgeIds(on); }
VTKM_CONT
bool GetAddInterpolationEdgeIds() const
{
return this->ContourFilter.GetAddInterpolationEdgeIds();
}
/// Set/Get whether the fast path should be used for normals computation for
/// structured datasets. Off by default.
VTKM_CONT
void SetComputeFastNormalsForStructured(bool on)
{
this->ContourFilter.SetComputeFastNormalsForStructured(on);
}
VTKM_CONT
bool GetComputeFastNormalsForStructured() const
{
return this->ContourFilter.GetComputeFastNormalsForStructured();
}
/// Set/Get whether the fast path should be used for normals computation for
/// unstructured datasets. On by default.
VTKM_CONT
void SetComputeFastNormalsForUnstructured(bool on)
{
this->ContourFilter.SetComputeFastNormalsForUnstructured(on);
}
VTKM_CONT
bool GetComputeFastNormalsForUnstructured() const
{
return this->ContourFilter.GetComputeFastNormalsForUnstructured();
}
VTKM_CONT
void SetNormalArrayName(const std::string& name) { this->ContourFilter.SetNormalArrayName(name); }
VTKM_CONT
const std::string& GetNormalArrayName() const { return this->ContourFilter.GetNormalArrayName(); }
template <typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy);
template <typename DerivedPolicy>
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
{
return this->ContourFilter.MapFieldOntoOutput(result, field, policy);
}
//Map a new field onto the resulting dataset after running the filter
//this call is only valid
template <typename T, typename StorageType, typename DerivedPolicy>
VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
{
return this->ContourFilter.DoMapField(result, input, fieldMeta, policy);
}
private:
vtkm::ImplicitFunctionGeneral Function;
vtkm::filter::Contour ContourFilter;
};
#ifndef vtk_m_filter_Slice_cxx
extern template VTKM_FILTER_CONTOUR_TEMPLATE_EXPORT vtkm::cont::DataSet Slice::DoExecute(
const vtkm::cont::DataSet&,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
#endif
}
} // vtkm::filter
#endif // vtk_m_filter_Slice_h

43
vtkm/filter/Slice.hxx Normal file

@ -0,0 +1,43 @@
//============================================================================
// 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_Slice_hxx
#define vtk_m_filter_Slice_hxx
#include <vtkm/cont/ArrayHandleTransform.h>
namespace vtkm
{
namespace filter
{
template <typename DerivedPolicy>
vtkm::cont::DataSet Slice::DoExecute(const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
{
const auto& coords = input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex());
vtkm::cont::DataSet result;
auto impFuncEval =
vtkm::ImplicitFunctionValueFunctor<vtkm::ImplicitFunctionGeneral>(this->Function);
auto sliceScalars =
vtkm::cont::make_ArrayHandleTransform(coords.GetDataAsMultiplexer(), impFuncEval);
auto field = vtkm::cont::make_FieldPoint("sliceScalars", sliceScalars);
this->ContourFilter.SetIsoValue(0.0);
result =
this->ContourFilter.DoExecute(input, sliceScalars, vtkm::filter::FieldMetadata(field), policy);
return result;
}
}
} // vtkm::filter
#endif // vtk_m_filter_Slice_hxx

@ -88,6 +88,7 @@ if (VTKm_ENABLE_RENDERING)
list(APPEND unit_tests
RegressionTestContourFilter.cxx
RegressionTestPointTransform.cxx
RegressionTestSliceFilter.cxx
RegressionTestSplitSharpEdges.cxx
RegressionTestStreamline.cxx
RegressionTestSurfaceNormals.cxx

@ -0,0 +1,155 @@
//============================================================================
// 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/filter/Slice.h>
#include <vtkm/ImplicitFunction.h>
#include <vtkm/filter/Tetrahedralize.h>
#include <vtkm/source/Wavelet.h>
#include <vtkm/rendering/CanvasRayTracer.h>
#include <vtkm/rendering/MapperRayTracer.h>
#include <vtkm/rendering/View3D.h>
#include <vtkm/rendering/testing/RenderTest.h>
#include <vtkm/rendering/testing/Testing.h>
namespace
{
void TestSliceStructuredPointsPlane()
{
std::cout << "Generate Image for Slice by plane on structured points" << std::endl;
vtkm::cont::ColorTable colorTable;
using M = vtkm::rendering::MapperRayTracer;
using C = vtkm::rendering::CanvasRayTracer;
using V3 = vtkm::rendering::View3D;
vtkm::source::Wavelet wavelet(vtkm::Id3(-8), vtkm::Id3(8));
auto ds = wavelet.Execute();
vtkm::Plane plane(vtkm::Plane::Vector{ 1, 1, 1 });
vtkm::filter::Slice slice;
slice.SetImplicitFunction(plane);
auto result = slice.Execute(ds);
result.PrintSummary(std::cout);
vtkm::rendering::testing::RenderAndRegressionTest<M, C, V3>(
result,
"scalars",
colorTable,
"filter/slice-structured-points-plane.png",
false,
static_cast<vtkm::FloatDefault>(0.08));
}
void TestSliceStructuredPointsSphere()
{
std::cout << "Generate Image for Slice by sphere on structured points" << std::endl;
vtkm::cont::ColorTable colorTable;
using M = vtkm::rendering::MapperRayTracer;
using C = vtkm::rendering::CanvasRayTracer;
using V3 = vtkm::rendering::View3D;
vtkm::source::Wavelet wavelet(vtkm::Id3(-8), vtkm::Id3(8));
auto ds = wavelet.Execute();
vtkm::Sphere sphere(8.5f);
vtkm::filter::Slice slice;
slice.SetImplicitFunction(sphere);
auto result = slice.Execute(ds);
result.PrintSummary(std::cout);
vtkm::rendering::testing::RenderAndRegressionTest<M, C, V3>(
result,
"scalars",
colorTable,
"filter/slice-structured-points-sphere.png",
false,
static_cast<vtkm::FloatDefault>(0.08));
}
void TestSliceUnstructuredGridPlane()
{
std::cout << "Generate Image for Slice by plane on unstructured grid" << std::endl;
vtkm::cont::ColorTable colorTable;
using M = vtkm::rendering::MapperRayTracer;
using C = vtkm::rendering::CanvasRayTracer;
using V3 = vtkm::rendering::View3D;
vtkm::source::Wavelet wavelet(vtkm::Id3(-8), vtkm::Id3(8));
auto ds = wavelet.Execute();
vtkm::filter::Tetrahedralize tetrahedralize;
ds = tetrahedralize.Execute(ds);
vtkm::Plane plane(vtkm::Plane::Vector{ 1 });
vtkm::filter::Slice slice;
slice.SetImplicitFunction(plane);
auto result = slice.Execute(ds);
result.PrintSummary(std::cout);
vtkm::rendering::testing::RenderAndRegressionTest<M, C, V3>(
result,
"scalars",
colorTable,
"filter/slice-unstructured-grid-plane.png",
false,
static_cast<vtkm::FloatDefault>(0.08));
}
void TestSliceUnstructuredGridCylinder()
{
std::cout << "Generate Image for Slice by cylinder on unstructured grid" << std::endl;
vtkm::cont::ColorTable colorTable;
using M = vtkm::rendering::MapperRayTracer;
using C = vtkm::rendering::CanvasRayTracer;
using V3 = vtkm::rendering::View3D;
vtkm::source::Wavelet wavelet(vtkm::Id3(-8), vtkm::Id3(8));
auto ds = wavelet.Execute();
vtkm::filter::Tetrahedralize tetrahedralize;
ds = tetrahedralize.Execute(ds);
vtkm::Cylinder cylinder(vtkm::Cylinder::Vector{ 0, 1, 0 }, 8.5f);
vtkm::filter::Slice slice;
slice.SetImplicitFunction(cylinder);
auto result = slice.Execute(ds);
result.PrintSummary(std::cout);
vtkm::rendering::testing::RenderAndRegressionTest<M, C, V3>(
result,
"scalars",
colorTable,
"filter/slice-unstructured-grid-cylinder.png",
false,
static_cast<vtkm::FloatDefault>(0.08));
}
void TestSliceFilter()
{
TestSliceStructuredPointsPlane();
TestSliceStructuredPointsSphere();
TestSliceUnstructuredGridPlane();
TestSliceUnstructuredGridCylinder();
}
} // namespace
int RegressionTestSliceFilter(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestSliceFilter, argc, argv);
}