mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Merge topic 'rendering_cpp_cleanup'
ee9c78ca9 Merge branch 'master' into rendering_cpp_cleanup d05025ce8 simplify comment 066e6a696 I think this is the proper way doing PIMPL 6e75be33e unique_ptr know if itself is valid 50a9efc2f use rvalue ref for parameter 61c002072 cleanup C++ usage, use unique_ptr for PIMPL Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Kenneth Moreland <morelandkd@ornl.gov> Merge-request: !3057
This commit is contained in:
commit
fdf7aaece7
@ -13,7 +13,6 @@
|
||||
#include <vtkm/cont/Timer.h>
|
||||
#include <vtkm/cont/TryExecute.h>
|
||||
|
||||
#include <vtkm/rendering/CanvasRayTracer.h>
|
||||
#include <vtkm/rendering/raytracing/Camera.h>
|
||||
#include <vtkm/rendering/raytracing/Logger.h>
|
||||
#include <vtkm/rendering/raytracing/RayOperations.h>
|
||||
@ -22,7 +21,6 @@
|
||||
#include <vtkm/rendering/raytracing/SphereIntersector.h>
|
||||
#include <vtkm/rendering/raytracing/TriangleExtractor.h>
|
||||
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
@ -30,32 +28,25 @@ namespace rendering
|
||||
|
||||
struct ScalarRenderer::InternalsType
|
||||
{
|
||||
bool ValidDataSet;
|
||||
vtkm::Int32 Width;
|
||||
vtkm::Int32 Height;
|
||||
vtkm::Float32 DefaultValue;
|
||||
bool ValidDataSet = false;
|
||||
vtkm::Int32 Width = 1024;
|
||||
vtkm::Int32 Height = 1024;
|
||||
vtkm::Float32 DefaultValue = vtkm::Nan32();
|
||||
vtkm::cont::DataSet DataSet;
|
||||
vtkm::rendering::raytracing::ScalarRenderer Tracer;
|
||||
vtkm::Bounds ShapeBounds;
|
||||
|
||||
VTKM_CONT
|
||||
InternalsType()
|
||||
: ValidDataSet(false)
|
||||
, Width(1024)
|
||||
, Height(1024)
|
||||
, DefaultValue(vtkm::Nan32())
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
ScalarRenderer::ScalarRenderer()
|
||||
: Internals(new InternalsType)
|
||||
: Internals(std::make_unique<InternalsType>())
|
||||
{
|
||||
}
|
||||
|
||||
ScalarRenderer::~ScalarRenderer() {}
|
||||
ScalarRenderer::ScalarRenderer(ScalarRenderer&&) noexcept = default;
|
||||
ScalarRenderer& ScalarRenderer::operator=(ScalarRenderer&&) noexcept = default;
|
||||
ScalarRenderer::~ScalarRenderer() = default;
|
||||
|
||||
void ScalarRenderer::SetWidth(const vtkm::Int32 width)
|
||||
void ScalarRenderer::SetWidth(vtkm::Int32 width)
|
||||
{
|
||||
if (width < 1)
|
||||
{
|
||||
@ -64,12 +55,12 @@ void ScalarRenderer::SetWidth(const vtkm::Int32 width)
|
||||
Internals->Width = width;
|
||||
}
|
||||
|
||||
void ScalarRenderer::SetDefaultValue(const vtkm::Float32 value)
|
||||
void ScalarRenderer::SetDefaultValue(vtkm::Float32 value)
|
||||
{
|
||||
Internals->DefaultValue = value;
|
||||
}
|
||||
|
||||
void ScalarRenderer::SetHeight(const vtkm::Int32 height)
|
||||
void ScalarRenderer::SetHeight(vtkm::Int32 height)
|
||||
{
|
||||
if (height < 1)
|
||||
{
|
||||
@ -90,16 +81,15 @@ void ScalarRenderer::SetInput(vtkm::cont::DataSet& dataSet)
|
||||
|
||||
if (triExtractor.GetNumberOfTriangles() > 0)
|
||||
{
|
||||
auto triIntersector = std::make_shared<raytracing::TriangleIntersector>();
|
||||
auto triIntersector = std::make_unique<raytracing::TriangleIntersector>();
|
||||
triIntersector->SetData(coords, triExtractor.GetTriangles());
|
||||
this->Internals->Tracer.SetShapeIntersector(triIntersector);
|
||||
this->Internals->ShapeBounds = triIntersector->GetShapeBounds();
|
||||
this->Internals->Tracer.SetShapeIntersector(std::move(triIntersector));
|
||||
}
|
||||
}
|
||||
|
||||
ScalarRenderer::Result ScalarRenderer::Render(const vtkm::rendering::Camera& camera)
|
||||
{
|
||||
|
||||
if (!Internals->ValidDataSet)
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("ScalarRenderer: input never set");
|
||||
@ -182,7 +172,7 @@ ScalarRenderer::Result ScalarRenderer::Render(const vtkm::rendering::Camera& cam
|
||||
|
||||
vtkm::cont::DataSet ScalarRenderer::Result::ToDataSet()
|
||||
{
|
||||
if (Scalars.size() == 0)
|
||||
if (Scalars.empty())
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("ScalarRenderer: result empty");
|
||||
}
|
||||
|
@ -25,12 +25,19 @@ class VTKM_RENDERING_EXPORT ScalarRenderer
|
||||
public:
|
||||
ScalarRenderer();
|
||||
|
||||
// Disable copying due to unique_ptr;
|
||||
ScalarRenderer(const ScalarRenderer&) = delete;
|
||||
ScalarRenderer& operator=(const ScalarRenderer&) = delete;
|
||||
|
||||
ScalarRenderer(ScalarRenderer&&) noexcept;
|
||||
ScalarRenderer& operator=(ScalarRenderer&&) noexcept;
|
||||
// Default destructor implemented in source file to support PIMPL idiom.
|
||||
~ScalarRenderer();
|
||||
|
||||
void SetInput(vtkm::cont::DataSet& dataSet);
|
||||
|
||||
void SetWidth(const vtkm::Int32 width);
|
||||
void SetHeight(const vtkm::Int32 height);
|
||||
void SetWidth(vtkm::Int32 width);
|
||||
void SetHeight(vtkm::Int32 height);
|
||||
void SetDefaultValue(vtkm::Float32 value);
|
||||
|
||||
struct VTKM_RENDERING_EXPORT Result
|
||||
@ -47,10 +54,9 @@ public:
|
||||
|
||||
ScalarRenderer::Result Render(const vtkm::rendering::Camera& camera);
|
||||
|
||||
|
||||
private:
|
||||
struct InternalsType;
|
||||
std::shared_ptr<InternalsType> Internals;
|
||||
std::unique_ptr<InternalsType> Internals;
|
||||
};
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
@ -10,15 +10,11 @@
|
||||
#include <vtkm/rendering/raytracing/ScalarRenderer.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
|
||||
#include <vtkm/cont/ColorTable.h>
|
||||
#include <vtkm/cont/Timer.h>
|
||||
|
||||
#include <vtkm/rendering/raytracing/Logger.h>
|
||||
#include <vtkm/rendering/raytracing/RayTracingTypeDefs.h>
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
namespace vtkm
|
||||
@ -39,10 +35,10 @@ public:
|
||||
{
|
||||
private:
|
||||
vtkm::Vec3f_32 LightPosition;
|
||||
vtkm::Vec3f_32 LightAmbient;
|
||||
vtkm::Vec3f_32 LightDiffuse;
|
||||
vtkm::Vec3f_32 LightSpecular;
|
||||
vtkm::Float32 SpecularExponent;
|
||||
vtkm::Vec3f_32 LightAmbient{ .5f, .5f, .5f };
|
||||
vtkm::Vec3f_32 LightDiffuse{ .7f, .7f, .7f };
|
||||
vtkm::Vec3f_32 LightSpecular{ .7f, .7f, .7f };
|
||||
vtkm::Float32 SpecularExponent = 20.f;
|
||||
vtkm::Vec3f_32 CameraPosition;
|
||||
vtkm::Vec3f_32 LookAt;
|
||||
Precision MissScalar;
|
||||
@ -58,31 +54,16 @@ public:
|
||||
, LookAt(lookAt)
|
||||
, MissScalar(missScalar)
|
||||
{
|
||||
//Set up some default lighting parameters for now
|
||||
LightAmbient[0] = .5f;
|
||||
LightAmbient[1] = .5f;
|
||||
LightAmbient[2] = .5f;
|
||||
LightDiffuse[0] = .7f;
|
||||
LightDiffuse[1] = .7f;
|
||||
LightDiffuse[2] = .7f;
|
||||
LightSpecular[0] = .7f;
|
||||
LightSpecular[1] = .7f;
|
||||
LightSpecular[2] = .7f;
|
||||
SpecularExponent = 20.f;
|
||||
}
|
||||
|
||||
using ControlSignature = void(FieldIn, FieldIn, FieldIn, FieldOut);
|
||||
using ExecutionSignature = void(_1, _2, _3, _4);
|
||||
//using ExecutionSignature = void(_1, _2, _3, _4, WorkIndex);
|
||||
|
||||
//template <typename ShadePortalType, typename Precision>
|
||||
VTKM_EXEC void operator()(const vtkm::Id& hitIdx,
|
||||
const vtkm::Vec<Precision, 3>& normal,
|
||||
const vtkm::Vec<Precision, 3>& intersection,
|
||||
Precision& output) const //,
|
||||
// const vtkm::Id& idx) const
|
||||
Precision& output) const
|
||||
{
|
||||
|
||||
if (hitIdx < 0)
|
||||
{
|
||||
output = MissScalar;
|
||||
@ -145,7 +126,6 @@ public:
|
||||
|
||||
}; //class Shade
|
||||
|
||||
//template <typename Precision>
|
||||
VTKM_CONT void run(Ray<Precision>& rays,
|
||||
const vtkm::rendering::raytracing::Camera& camera,
|
||||
const Precision missScalar,
|
||||
@ -173,7 +153,7 @@ private:
|
||||
|
||||
public:
|
||||
VTKM_CONT
|
||||
FilterDepth(const Precision missScalar)
|
||||
explicit FilterDepth(const Precision missScalar)
|
||||
: MissScalar(missScalar)
|
||||
{
|
||||
}
|
||||
@ -201,7 +181,7 @@ private:
|
||||
|
||||
public:
|
||||
VTKM_CONT
|
||||
WriteBuffer(const Precision missScalar)
|
||||
explicit WriteBuffer(const Precision missScalar)
|
||||
: MissScalar(missScalar)
|
||||
{
|
||||
}
|
||||
@ -227,9 +207,6 @@ template <typename Precision>
|
||||
class WriteDepthBuffer : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
VTKM_CONT
|
||||
WriteDepthBuffer() {}
|
||||
|
||||
typedef void ControlSignature(FieldIn, FieldOut);
|
||||
|
||||
typedef void ExecutionSignature(_1, _2);
|
||||
@ -237,22 +214,14 @@ public:
|
||||
}; //class WriteDepthBuffer
|
||||
} // namespace detail
|
||||
|
||||
ScalarRenderer::ScalarRenderer()
|
||||
: IntersectorValid(false)
|
||||
void ScalarRenderer::SetShapeIntersector(std::unique_ptr<ShapeIntersector>&& intersector)
|
||||
{
|
||||
}
|
||||
|
||||
ScalarRenderer::~ScalarRenderer() {}
|
||||
|
||||
void ScalarRenderer::SetShapeIntersector(std::shared_ptr<ShapeIntersector> intersector)
|
||||
{
|
||||
Intersector = intersector;
|
||||
IntersectorValid = true;
|
||||
Intersector = std::move(intersector);
|
||||
}
|
||||
|
||||
void ScalarRenderer::AddField(const vtkm::cont::Field& scalarField)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Range> ranges = scalarField.GetRange();
|
||||
const auto& ranges = scalarField.GetRange();
|
||||
if (ranges.GetNumberOfValues() != 1)
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("ScalarRenderer(AddField): field must be a scalar");
|
||||
@ -295,7 +264,7 @@ void ScalarRenderer::RenderOnDevice(Ray<Precision>& rays,
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("ScalarRenderer: no fields added");
|
||||
}
|
||||
if (!IntersectorValid)
|
||||
if (!Intersector)
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("ScalarRenderer: intersector never set");
|
||||
}
|
||||
@ -316,8 +285,6 @@ void ScalarRenderer::RenderOnDevice(Ray<Precision>& rays,
|
||||
AddBuffer(rays, missScalar, Fields[f].GetName());
|
||||
}
|
||||
|
||||
|
||||
|
||||
const vtkm::Int32 numChannels = 1;
|
||||
ChannelBuffer<Precision> buffer(numChannels, rays.NumRays);
|
||||
detail::SurfaceShade<Precision> surfaceShade;
|
||||
@ -325,24 +292,20 @@ void ScalarRenderer::RenderOnDevice(Ray<Precision>& rays,
|
||||
buffer.SetName("shading");
|
||||
rays.Buffers.push_back(buffer);
|
||||
|
||||
|
||||
vtkm::worklet::DispatcherMapField<detail::FilterDepth<Precision>>(
|
||||
detail::FilterDepth<Precision>(missScalar))
|
||||
.Invoke(rays.HitIdx, rays.Distance);
|
||||
this->Invoke(detail::FilterDepth<Precision>{ missScalar }, rays.HitIdx, rays.Distance);
|
||||
|
||||
time = renderTimer.GetElapsedTime();
|
||||
logger->CloseLogEntry(time);
|
||||
} // RenderOnDevice
|
||||
|
||||
template <typename Precision>
|
||||
void ScalarRenderer::AddBuffer(Ray<Precision>& rays, Precision missScalar, const std::string name)
|
||||
void ScalarRenderer::AddBuffer(Ray<Precision>& rays, Precision missScalar, const std::string& name)
|
||||
{
|
||||
const vtkm::Int32 numChannels = 1;
|
||||
ChannelBuffer<Precision> buffer(numChannels, rays.NumRays);
|
||||
|
||||
vtkm::worklet::DispatcherMapField<detail::WriteBuffer<Precision>>(
|
||||
detail::WriteBuffer<Precision>(missScalar))
|
||||
.Invoke(rays.HitIdx, rays.Scalar, buffer.Buffer);
|
||||
this->Invoke(
|
||||
detail::WriteBuffer<Precision>{ missScalar }, rays.HitIdx, rays.Scalar, buffer.Buffer);
|
||||
|
||||
buffer.SetName(name);
|
||||
rays.Buffers.push_back(buffer);
|
||||
@ -354,9 +317,7 @@ void ScalarRenderer::AddDepthBuffer(Ray<Precision>& rays)
|
||||
const vtkm::Int32 numChannels = 1;
|
||||
ChannelBuffer<Precision> buffer(numChannels, rays.NumRays);
|
||||
|
||||
vtkm::worklet::DispatcherMapField<detail::WriteDepthBuffer<Precision>>(
|
||||
detail::WriteDepthBuffer<Precision>())
|
||||
.Invoke(rays.Depth, buffer.Buffer);
|
||||
this->Invoke(detail::WriteDepthBuffer<Precision>{}, rays.Depth, buffer.Buffer);
|
||||
|
||||
buffer.SetName("depth");
|
||||
rays.Buffers.push_back(buffer);
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include <vtkm/rendering/raytracing/Camera.h>
|
||||
#include <vtkm/rendering/raytracing/TriangleIntersector.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
@ -26,10 +27,12 @@ namespace raytracing
|
||||
|
||||
class VTKM_RENDERING_EXPORT ScalarRenderer
|
||||
{
|
||||
private:
|
||||
vtkm::cont::Invoker Invoke;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ShapeIntersector> Intersector;
|
||||
std::unique_ptr<ShapeIntersector> Intersector;
|
||||
std::vector<vtkm::cont::Field> Fields;
|
||||
bool IntersectorValid;
|
||||
|
||||
template <typename Precision>
|
||||
void RenderOnDevice(Ray<Precision>& rays,
|
||||
@ -37,19 +40,14 @@ protected:
|
||||
vtkm::rendering::raytracing::Camera& cam);
|
||||
|
||||
template <typename Precision>
|
||||
void AddBuffer(Ray<Precision>& rays, Precision missScalar, const std::string name);
|
||||
void AddBuffer(Ray<Precision>& rays, Precision missScalar, const std::string& name);
|
||||
|
||||
template <typename Precision>
|
||||
void AddDepthBuffer(Ray<Precision>& rays);
|
||||
|
||||
public:
|
||||
VTKM_CONT
|
||||
ScalarRenderer();
|
||||
VTKM_CONT
|
||||
~ScalarRenderer();
|
||||
|
||||
VTKM_CONT
|
||||
void SetShapeIntersector(std::shared_ptr<ShapeIntersector> intersector);
|
||||
void SetShapeIntersector(std::unique_ptr<ShapeIntersector>&& intersector);
|
||||
|
||||
VTKM_CONT
|
||||
void AddField(const vtkm::cont::Field& scalarField);
|
||||
@ -68,4 +66,4 @@ public:
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering::raytracing
|
||||
#endif //vtk_m_rendering_raytracing_RayTracer_h
|
||||
#endif //vtk_m_rendering_raytracing_ScalarRenderer_h
|
||||
|
Loading…
Reference in New Issue
Block a user