mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
cleanup C++ usage, use unique_ptr for PIMPL
This commit is contained in:
parent
48393aa495
commit
61c002072f
@ -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,30 +28,21 @@ 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() = default;
|
||||
|
||||
void ScalarRenderer::SetWidth(const vtkm::Int32 width)
|
||||
{
|
||||
@ -90,16 +79,16 @@ 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::unique_ptr<raytracing::ShapeIntersector>{
|
||||
static_cast<raytracing::ShapeIntersector*>(triIntersector.release()) });
|
||||
}
|
||||
}
|
||||
|
||||
ScalarRenderer::Result ScalarRenderer::Render(const vtkm::rendering::Camera& camera)
|
||||
{
|
||||
|
||||
if (!Internals->ValidDataSet)
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("ScalarRenderer: input never set");
|
||||
@ -182,7 +171,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,6 +25,11 @@ class VTKM_RENDERING_EXPORT ScalarRenderer
|
||||
public:
|
||||
ScalarRenderer();
|
||||
|
||||
// Note: since we are using std::unique_ptr<T> for PIMPL, the compiler does
|
||||
// not know the real size of std::unique_ptr<T> at this point. Thus, we
|
||||
// can not have the definition of the destructor here. We need to declare it
|
||||
// here and have an implementation in .cxx. The implementation could just
|
||||
// be = default.
|
||||
~ScalarRenderer();
|
||||
|
||||
void SetInput(vtkm::cont::DataSet& dataSet);
|
||||
@ -47,10 +52,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,15 @@ 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;
|
||||
Intersector = std::move(intersector);
|
||||
IntersectorValid = true;
|
||||
}
|
||||
|
||||
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");
|
||||
@ -316,8 +286,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 +293,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 +318,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,13 @@ 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;
|
||||
bool IntersectorValid = false;
|
||||
|
||||
template <typename Precision>
|
||||
void RenderOnDevice(Ray<Precision>& rays,
|
||||
@ -37,19 +41,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 +67,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