Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
adding point transform (#185)
Browse files Browse the repository at this point in the history
* adding point transform

* add a way to disable color bars
  • Loading branch information
mclarsen authored Nov 5, 2020
1 parent 95fee60 commit 6f9afc9
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/tests/vtkh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
99 changes: 99 additions & 0 deletions src/tests/vtkh/t_vtk-h_point_transform.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//-----------------------------------------------------------------------------
///
/// file: t_vtk-h_dataset.cpp
///
//-----------------------------------------------------------------------------

#include "gtest/gtest.h"

#include <vtkh/vtkh.hpp>
#include <vtkh/DataSet.hpp>
#include <vtkh/filters/PointTransform.hpp>
#include <vtkh/rendering/RayTracer.hpp>
#include <vtkh/rendering/Scene.hpp>
#include "t_test_utils.hpp"

#include <iostream>



//----------------------------------------------------------------------------
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<vtkm::Float64,3>(-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<vtkm::Float64,3>(-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;
}
4 changes: 3 additions & 1 deletion src/vtkh/filters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(vtkh_filters_headers
ParticleAdvection.hpp
Integrator.hpp
PointAverage.hpp
PointTransform.hpp
Recenter.hpp
Threshold.hpp
Statistics.hpp
Expand All @@ -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()
Expand Down Expand Up @@ -61,6 +62,7 @@ set(vtkh_filters_sources
MarchingCubes.cpp
ParticleAdvection.cpp
PointAverage.cpp
PointTransform.cpp
Recenter.cpp
Threshold.cpp
Slice.cpp
Expand Down
87 changes: 87 additions & 0 deletions src/vtkh/filters/PointTransform.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include <vtkh/filters/PointTransform.hpp>
#include <vtkm/Transform3D.h>
#include <vtkh/vtkm_filters/vtkmPointTransform.hpp>

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<double,4,4> matrix = vtkm::Transform3DTranslate(tx, ty, tz);
m_transform = vtkm::MatrixMultiply(m_transform, matrix);
}

void PointTransform::SetRotation(const double& angleDegrees,
const vtkm::Vec<double, 3>& axis)
{
vtkm::Matrix<double,4,4> matrix = vtkm::Transform3DRotate(angleDegrees, axis);
m_transform = vtkm::MatrixMultiply(m_transform, matrix);
}

void PointTransform::SetTransform(const vtkm::Matrix<double, 4, 4>& mtx)
{
m_transform = mtx;
}

void PointTransform::SetScale(const double& sx,
const double& sy,
const double& sz)
{
vtkm::Matrix<double,4,4> 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
36 changes: 36 additions & 0 deletions src/vtkh/filters/PointTransform.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef VTK_H_POINT_TRANSFORM_HPP
#define VTK_H_POINT_TRANSFORM_HPP

#include <vtkh/vtkh_exports.h>
#include <vtkh/vtkh.hpp>
#include <vtkh/filters/Filter.hpp>
#include <vtkh/DataSet.hpp>
#include <vtkm/Matrix.h>

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<double, 3>& axis);
void SetScale(const double& sx, const double& sy, const double& sz);
void SetTransform(const vtkm::Matrix<double, 4, 4>& mtx);

protected:
void PreExecute() override;
void PostExecute() override;
void DoExecute() override;
std::string m_field_name;
vtkm::Matrix<vtkm::Float64, 4,4> m_transform;
};

} //namespace vtkh
#endif
7 changes: 7 additions & 0 deletions src/vtkh/rendering/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/vtkh/rendering/Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class VTKH_API Renderer : public Filter
void SetDoComposite(bool do_composite);
void SetRenders(const std::vector<Render> &renders);
void SetRange(const vtkm::Range &range);
void DisableColorBar();

vtkm::cont::ColorTable GetColorTable() const;
std::string GetFieldName() const;
Expand Down
2 changes: 2 additions & 0 deletions src/vtkh/vtkm_filters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(vtkm_filters_headers
vtkmLagrangian.hpp
vtkmMarchingCubes.hpp
vtkmPointAverage.hpp
vtkmPointTransform.hpp
vtkmThreshold.hpp
vtkmVectorMagnitude.hpp
GradientParameters.hpp
Expand All @@ -27,6 +28,7 @@ set(vtkm_filters_sources
vtkmLagrangian.cpp
vtkmMarchingCubes.cpp
vtkmPointAverage.cpp
vtkmPointTransform.cpp
vtkmThreshold.cpp
vtkmVectorMagnitude.cpp
)
Expand Down
21 changes: 21 additions & 0 deletions src/vtkh/vtkm_filters/vtkmPointTransform.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "vtkmPointTransform.hpp"
#include <vtkm/filter/PointTransform.h>

namespace vtkh
{
vtkm::cont::DataSet
vtkmPointTransform::Run(vtkm::cont::DataSet &input,
vtkm::Matrix<double,4,4> &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
19 changes: 19 additions & 0 deletions src/vtkh/vtkm_filters/vtkmPointTransform.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef VTK_H_VTKM_POINT_TRANSFORM_HPP
#define VTK_H_VTKM_POINT_TRANSFORM_HPP

#include <vtkm/cont/DataSet.h>
#include <vtkm/Matrix.h>
#include <vtkm/filter/FieldSelection.h>

namespace vtkh
{

class vtkmPointTransform
{
public:
vtkm::cont::DataSet Run(vtkm::cont::DataSet &input,
vtkm::Matrix<double,4,4> &transform,
vtkm::filter::FieldSelection map_fields);
};
}
#endif

0 comments on commit 6f9afc9

Please sign in to comment.