ray tracing now using shared pointers for intersectors

This commit is contained in:
mclarsen 2019-02-22 08:06:04 -08:00
parent 6b4a4267dc
commit 4cd4637c18
7 changed files with 27 additions and 27 deletions

@ -50,21 +50,17 @@ namespace benchmarking
template <typename Precision>
struct BenchRayTracing
{
vtkm::rendering::raytracing::RayTracer Tracer;
vtkm::rendering::raytracing::Camera RayCamera;
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Id, 4>> Indices;
vtkm::rendering::raytracing::Ray<Precision> Rays;
vtkm::cont::CoordinateSystem Coords;
vtkm::cont::DataSet Data;
VTKM_CONT ~BenchRayTracing() {}
VTKM_CONT BenchRayTracing() {}
VTKM_CONT
vtkm::Float64 operator()()
VTKM_CONT BenchRayTracing()
{
vtkm::rendering::raytracing::RayTracer Tracer;
vtkm::rendering::raytracing::Camera RayCamera;
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Id, 4>> Indices;
vtkm::rendering::raytracing::Ray<Precision> Rays;
vtkm::cont::CoordinateSystem Coords;
vtkm::cont::DataSet Data;
vtkm::Id3 dims(128, 128, 128);
vtkm::cont::testing::MakeTestDataSet maker;
Data = maker.Make3DUniformDataSet3(dims);
@ -79,8 +75,8 @@ struct BenchRayTracing
vtkm::rendering::raytracing::TriangleExtractor triExtractor;
triExtractor.ExtractCells(cellset);
vtkm::rendering::raytracing::TriangleIntersector* triIntersector =
new vtkm::rendering::raytracing::TriangleIntersector();
auto triIntersector = std::make_shared<vtkm::rendering::raytracing::TriangleIntersector>(
vtkm::rendering::raytracing::TriangleIntersector());
triIntersector->SetData(Coords, triExtractor.GetTriangles());
Tracer.AddShapeIntersector(triIntersector);
@ -117,6 +113,12 @@ struct BenchRayTracing
Tracer.SetColorMap(colors);
Tracer.Render(Rays);
}
VTKM_CONT
vtkm::Float64 operator()()
{
vtkm::cont::Timer timer;
timer.Start();
@ -125,7 +127,6 @@ struct BenchRayTracing
try
{
Tracer.Render(Rays);
Tracer.Render(Rays);
}
catch (vtkm::cont::ErrorBadValue& e)
{

@ -184,7 +184,8 @@ void MapperCylinder::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
if (cylExtractor.GetNumberOfCylinders() > 0)
{
raytracing::CylinderIntersector* cylIntersector = new raytracing::CylinderIntersector();
auto cylIntersector =
std::make_shared<raytracing::CylinderIntersector>(raytracing::CylinderIntersector());
cylIntersector->SetData(coords, cylExtractor.GetCylIds(), cylExtractor.GetRadii());
this->Internals->Tracer.AddShapeIntersector(cylIntersector);
shapeBounds.Include(cylIntersector->GetShapeBounds());

@ -182,7 +182,8 @@ void MapperPoint::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
if (sphereExtractor.GetNumberOfSpheres() > 0)
{
raytracing::SphereIntersector* sphereIntersector = new raytracing::SphereIntersector();
auto sphereIntersector =
std::make_shared<raytracing::SphereIntersector>(raytracing::SphereIntersector());
sphereIntersector->SetData(coords, sphereExtractor.GetPointIds(), sphereExtractor.GetRadii());
this->Internals->Tracer.AddShapeIntersector(sphereIntersector);
shapeBounds.Include(sphereIntersector->GetShapeBounds());

@ -104,7 +104,8 @@ void MapperQuad::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
quadExtractor.ExtractCells(cellset);
if (quadExtractor.GetNumberOfQuads() > 0)
{
raytracing::QuadIntersector* quadIntersector = new raytracing::QuadIntersector();
auto quadIntersector =
std::make_shared<raytracing::QuadIntersector>(raytracing::QuadIntersector());
quadIntersector->SetData(coords, quadExtractor.GetQuadIds());
this->Internals->Tracer.AddShapeIntersector(quadIntersector);
shapeBounds.Include(quadIntersector->GetShapeBounds());

@ -108,7 +108,8 @@ void MapperRayTracer::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
triExtractor.ExtractCells(cellset);
if (triExtractor.GetNumberOfTriangles() > 0)
{
raytracing::TriangleIntersector* triIntersector = new raytracing::TriangleIntersector();
auto triIntersector =
std::make_shared<raytracing::TriangleIntersector>(raytracing::TriangleIntersector());
triIntersector->SetData(coords, triExtractor.GetTriangles());
this->Internals->Tracer.AddShapeIntersector(triIntersector);
shapeBounds.Include(triIntersector->GetShapeBounds());

@ -230,7 +230,7 @@ Camera& RayTracer::GetCamera()
}
void RayTracer::AddShapeIntersector(ShapeIntersector* intersector)
void RayTracer::AddShapeIntersector(std::shared_ptr<ShapeIntersector> intersector)
{
NumberOfShapes += intersector->GetNumberOfShapes();
Intersectors.push_back(intersector);
@ -269,12 +269,6 @@ vtkm::Id RayTracer::GetNumberOfShapes() const
void RayTracer::Clear()
{
size_t numShapes = Intersectors.size();
for (size_t i = 0; i < numShapes; ++i)
{
delete Intersectors[i];
}
Intersectors.clear();
}

@ -20,6 +20,7 @@
#ifndef vtk_m_rendering_raytracing_RayTracer_h
#define vtk_m_rendering_raytracing_RayTracer_h
#include <memory>
#include <vector>
#include <vtkm/cont/DataSet.h>
@ -36,7 +37,7 @@ namespace raytracing
class VTKM_RENDERING_EXPORT RayTracer
{
protected:
std::vector<ShapeIntersector*> Intersectors;
std::vector<std::shared_ptr<ShapeIntersector>> Intersectors;
Camera camera;
const vtkm::cont::Field* ScalarField;
vtkm::cont::ArrayHandle<vtkm::Float32> Scalars;
@ -58,7 +59,7 @@ public:
Camera& GetCamera();
VTKM_CONT
void AddShapeIntersector(ShapeIntersector* intersector);
void AddShapeIntersector(std::shared_ptr<ShapeIntersector> intersector);
VTKM_CONT
void SetField(const vtkm::cont::Field& scalarField, const vtkm::Range& scalarRange);