This repository has been archived by the owner on Jul 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding point transform * add a way to disable color bars
- Loading branch information
Showing
10 changed files
with
276 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |