From 6f9afc9c085843556e86b22f9941e35d022ea0d6 Mon Sep 17 00:00:00 2001 From: Matt Larsen Date: Thu, 5 Nov 2020 13:15:32 -0800 Subject: [PATCH] adding point transform (#185) * adding point transform * add a way to disable color bars --- src/tests/vtkh/CMakeLists.txt | 1 + src/tests/vtkh/t_vtk-h_point_transform.cpp | 99 ++++++++++++++++++++ src/vtkh/filters/CMakeLists.txt | 4 +- src/vtkh/filters/PointTransform.cpp | 87 +++++++++++++++++ src/vtkh/filters/PointTransform.hpp | 36 +++++++ src/vtkh/rendering/Renderer.cpp | 7 ++ src/vtkh/rendering/Renderer.hpp | 1 + src/vtkh/vtkm_filters/CMakeLists.txt | 2 + src/vtkh/vtkm_filters/vtkmPointTransform.cpp | 21 +++++ src/vtkh/vtkm_filters/vtkmPointTransform.hpp | 19 ++++ 10 files changed, 276 insertions(+), 1 deletion(-) create mode 100644 src/tests/vtkh/t_vtk-h_point_transform.cpp create mode 100644 src/vtkh/filters/PointTransform.cpp create mode 100644 src/vtkh/filters/PointTransform.hpp create mode 100644 src/vtkh/vtkm_filters/vtkmPointTransform.cpp create mode 100644 src/vtkh/vtkm_filters/vtkmPointTransform.hpp diff --git a/src/tests/vtkh/CMakeLists.txt b/src/tests/vtkh/CMakeLists.txt index 57a65202..5385f4e5 100644 --- a/src/tests/vtkh/CMakeLists.txt +++ b/src/tests/vtkh/CMakeLists.txt @@ -76,6 +76,7 @@ set(BASIC_TESTS t_vtk-h_smoke t_vtk-h_lagrangian t_vtk-h_log t_vtk-h_threshold + t_vtk-h_point_transform t_vtk-h_mesh_renderer t_vtk-h_multi_render t_vtk-h_point_renderer diff --git a/src/tests/vtkh/t_vtk-h_point_transform.cpp b/src/tests/vtkh/t_vtk-h_point_transform.cpp new file mode 100644 index 00000000..84e5a838 --- /dev/null +++ b/src/tests/vtkh/t_vtk-h_point_transform.cpp @@ -0,0 +1,99 @@ +//----------------------------------------------------------------------------- +/// +/// file: t_vtk-h_dataset.cpp +/// +//----------------------------------------------------------------------------- + +#include "gtest/gtest.h" + +#include +#include +#include +#include +#include +#include "t_test_utils.hpp" + +#include + + + +//---------------------------------------------------------------------------- +TEST(vtkh_point_transform, vtkh_translate) +{ + vtkh::DataSet data_set; + + const int base_size = 32; + const int num_blocks = 2; + + for(int i = 0; i < num_blocks; ++i) + { + data_set.AddDomain(CreateTestData(i, num_blocks, base_size), i); + } + + vtkh::PointTransform transformer; + transformer.SetTranslation(100.0, 0.0, 0.0); + transformer.SetInput(&data_set); + + transformer.Update(); + vtkh::DataSet *output = transformer.GetOutput(); + vtkm::Bounds bounds = output->GetGlobalBounds(); + + vtkm::rendering::Camera camera; + camera.SetPosition(vtkm::Vec(-16, -16, -16)); + camera.ResetToBounds(bounds); + vtkh::Render render = vtkh::MakeRender(512, + 512, + camera, + *output, + "translate"); + vtkh::RayTracer tracer; + tracer.SetInput(output); + tracer.SetField("point_data_Float64"); + + vtkh::Scene scene; + scene.AddRender(render); + scene.AddRenderer(&tracer); + scene.Render(); + + delete output; +} + +TEST(vtkh_point_transform, vtkh_scale) +{ + vtkh::DataSet data_set; + + const int base_size = 32; + const int num_blocks = 2; + + for(int i = 0; i < num_blocks; ++i) + { + data_set.AddDomain(CreateTestData(i, num_blocks, base_size), i); + } + + vtkh::PointTransform transformer; + transformer.SetScale(1.0, 1.0, 0.5); + transformer.SetInput(&data_set); + + transformer.Update(); + vtkh::DataSet *output = transformer.GetOutput(); + vtkm::Bounds bounds = output->GetGlobalBounds(); + + vtkm::rendering::Camera camera; + camera.SetPosition(vtkm::Vec(-16, -16, -16)); + camera.ResetToBounds(bounds); + vtkh::Render render = vtkh::MakeRender(512, + 512, + camera, + *output, + "scale"); + vtkh::RayTracer tracer; + tracer.SetInput(output); + tracer.SetField("point_data_Float64"); + + vtkh::Scene scene; + scene.AddRender(render); + scene.AddRenderer(&tracer); + scene.Render(); + + delete output; +} diff --git a/src/vtkh/filters/CMakeLists.txt b/src/vtkh/filters/CMakeLists.txt index f7f85fc7..1b438a8c 100644 --- a/src/vtkh/filters/CMakeLists.txt +++ b/src/vtkh/filters/CMakeLists.txt @@ -22,6 +22,7 @@ set(vtkh_filters_headers ParticleAdvection.hpp Integrator.hpp PointAverage.hpp + PointTransform.hpp Recenter.hpp Threshold.hpp Statistics.hpp @@ -32,7 +33,7 @@ set(vtkh_filters_headers communication/Communicator.hpp communication/MemStream.h ) - + if(ENABLE_FILTER_CONTOUR_TREE) list(APPEND vtkh_filters_headers ContourTree.hpp) endif() @@ -61,6 +62,7 @@ set(vtkh_filters_sources MarchingCubes.cpp ParticleAdvection.cpp PointAverage.cpp + PointTransform.cpp Recenter.cpp Threshold.cpp Slice.cpp diff --git a/src/vtkh/filters/PointTransform.cpp b/src/vtkh/filters/PointTransform.cpp new file mode 100644 index 00000000..fa9668a1 --- /dev/null +++ b/src/vtkh/filters/PointTransform.cpp @@ -0,0 +1,87 @@ +#include +#include +#include + +namespace vtkh +{ + +PointTransform::PointTransform() +{ + ResetTransform(); +} + +PointTransform::~PointTransform() +{ + +} + +void PointTransform::ResetTransform() +{ + vtkm::MatrixIdentity(m_transform); +} + +void +PointTransform::SetTranslation(const double& tx, + const double& ty, + const double& tz) +{ + vtkm::Matrix matrix = vtkm::Transform3DTranslate(tx, ty, tz); + m_transform = vtkm::MatrixMultiply(m_transform, matrix); +} + +void PointTransform::SetRotation(const double& angleDegrees, + const vtkm::Vec& axis) +{ + vtkm::Matrix matrix = vtkm::Transform3DRotate(angleDegrees, axis); + m_transform = vtkm::MatrixMultiply(m_transform, matrix); +} + +void PointTransform::SetTransform(const vtkm::Matrix& mtx) +{ + m_transform = mtx; +} + +void PointTransform::SetScale(const double& sx, + const double& sy, + const double& sz) +{ + vtkm::Matrix matrix = vtkm::Transform3DScale(sx, sy, sz); + m_transform = vtkm::MatrixMultiply(m_transform, matrix); +} + +void PointTransform::PreExecute() +{ + Filter::PreExecute(); +} + +void PointTransform::PostExecute() +{ + Filter::PostExecute(); +} + +void PointTransform::DoExecute() +{ + this->m_output = new DataSet(); + const int num_domains = this->m_input->GetNumberOfDomains(); + + for(int i = 0; i < num_domains; ++i) + { + vtkm::Id domain_id; + vtkm::cont::DataSet dom; + this->m_input->GetDomain(i, dom, domain_id); + vtkmPointTransform transformer; + auto dataset = transformer.Run(dom, + m_transform, + this->GetFieldSelection()); + // insert interesting stuff + m_output->AddDomain(dataset, domain_id); + } +} + +std::string +PointTransform::GetName() const +{ + return "vtkh::PointTransform"; +} + +} // namespace vtkh diff --git a/src/vtkh/filters/PointTransform.hpp b/src/vtkh/filters/PointTransform.hpp new file mode 100644 index 00000000..e7735361 --- /dev/null +++ b/src/vtkh/filters/PointTransform.hpp @@ -0,0 +1,36 @@ +#ifndef VTK_H_POINT_TRANSFORM_HPP +#define VTK_H_POINT_TRANSFORM_HPP + +#include +#include +#include +#include +#include + +namespace vtkh +{ + +class VTKH_API PointTransform : public Filter +{ +public: + PointTransform(); + virtual ~PointTransform(); + std::string GetName() const override; + + void ResetTransform(); + + void SetTranslation(const double& tx, const double& ty, const double& tz); + void SetRotation(const double& angleDegrees, const vtkm::Vec& axis); + void SetScale(const double& sx, const double& sy, const double& sz); + void SetTransform(const vtkm::Matrix& mtx); + +protected: + void PreExecute() override; + void PostExecute() override; + void DoExecute() override; + std::string m_field_name; + vtkm::Matrix m_transform; +}; + +} //namespace vtkh +#endif diff --git a/src/vtkh/rendering/Renderer.cpp b/src/vtkh/rendering/Renderer.cpp index b361f6be..f4d2e4c9 100644 --- a/src/vtkh/rendering/Renderer.cpp +++ b/src/vtkh/rendering/Renderer.cpp @@ -30,6 +30,13 @@ Renderer::SetShadingOn(bool on) // do nothing by default; } +void Renderer::DisableColorBar() +{ + // not all plots have color bars, so + // we only give the option to turn it off + m_has_color_table = false; +} + void Renderer::SetField(const std::string field_name) { diff --git a/src/vtkh/rendering/Renderer.hpp b/src/vtkh/rendering/Renderer.hpp index bb334883..43e14c9a 100644 --- a/src/vtkh/rendering/Renderer.hpp +++ b/src/vtkh/rendering/Renderer.hpp @@ -36,6 +36,7 @@ class VTKH_API Renderer : public Filter void SetDoComposite(bool do_composite); void SetRenders(const std::vector &renders); void SetRange(const vtkm::Range &range); + void DisableColorBar(); vtkm::cont::ColorTable GetColorTable() const; std::string GetFieldName() const; diff --git a/src/vtkh/vtkm_filters/CMakeLists.txt b/src/vtkh/vtkm_filters/CMakeLists.txt index 5cafb91d..a65d1319 100644 --- a/src/vtkh/vtkm_filters/CMakeLists.txt +++ b/src/vtkh/vtkm_filters/CMakeLists.txt @@ -12,6 +12,7 @@ set(vtkm_filters_headers vtkmLagrangian.hpp vtkmMarchingCubes.hpp vtkmPointAverage.hpp + vtkmPointTransform.hpp vtkmThreshold.hpp vtkmVectorMagnitude.hpp GradientParameters.hpp @@ -27,6 +28,7 @@ set(vtkm_filters_sources vtkmLagrangian.cpp vtkmMarchingCubes.cpp vtkmPointAverage.cpp + vtkmPointTransform.cpp vtkmThreshold.cpp vtkmVectorMagnitude.cpp ) diff --git a/src/vtkh/vtkm_filters/vtkmPointTransform.cpp b/src/vtkh/vtkm_filters/vtkmPointTransform.cpp new file mode 100644 index 00000000..dadf0c01 --- /dev/null +++ b/src/vtkh/vtkm_filters/vtkmPointTransform.cpp @@ -0,0 +1,21 @@ +#include "vtkmPointTransform.hpp" +#include + +namespace vtkh +{ +vtkm::cont::DataSet +vtkmPointTransform::Run(vtkm::cont::DataSet &input, + vtkm::Matrix &transform, + vtkm::filter::FieldSelection map_fields) +{ + vtkm::filter::PointTransform trans; + + trans.SetChangeCoordinateSystem(true); + trans.SetFieldsToPass(map_fields); + trans.SetTransform(transform); + + auto output = trans.Execute(input); + return output; +} + +} // namespace vtkh diff --git a/src/vtkh/vtkm_filters/vtkmPointTransform.hpp b/src/vtkh/vtkm_filters/vtkmPointTransform.hpp new file mode 100644 index 00000000..05e47a0e --- /dev/null +++ b/src/vtkh/vtkm_filters/vtkmPointTransform.hpp @@ -0,0 +1,19 @@ +#ifndef VTK_H_VTKM_POINT_TRANSFORM_HPP +#define VTK_H_VTKM_POINT_TRANSFORM_HPP + +#include +#include +#include + +namespace vtkh +{ + +class vtkmPointTransform +{ +public: + vtkm::cont::DataSet Run(vtkm::cont::DataSet &input, + vtkm::Matrix &transform, + vtkm::filter::FieldSelection map_fields); +}; +} +#endif