Merge topic 'parallel_projection'

6508d47cb Remove 3DPara
c39ff5f86 add include CanvasRayTracer.h
ca1fe424c cleanup Camera
d660a53b8 clean up Ray and RayOperator
9ed11540f cleanup Camera

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Kenneth Moreland <morelandkd@ornl.gov>
Merge-request: !3072
This commit is contained in:
Li-Ta Lo 2023-06-01 16:05:02 +00:00 committed by Kitware Robot
commit c5ddf1e543
9 changed files with 155 additions and 342 deletions

@ -13,20 +13,17 @@
#include <vtkm/TypeTraits.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/Initialize.h>
#include <vtkm/cont/Timer.h>
#include <vtkm/source/Tangle.h>
#include <vtkm/rendering/Camera.h>
#include <vtkm/rendering/CanvasRayTracer.h>
#include <vtkm/rendering/raytracing/Ray.h>
#include <vtkm/rendering/raytracing/RayTracer.h>
#include <vtkm/rendering/raytracing/SphereIntersector.h>
#include <vtkm/rendering/raytracing/TriangleExtractor.h>
#include <vtkm/exec/FunctorBase.h>
#include <sstream>
#include <string>
#include <vector>

@ -153,7 +153,6 @@ void Camera::GetRealViewport(vtkm::Id screenWidth,
vtkm::Float32 daspect =
(this->Camera2D.Right - this->Camera2D.Left) / (this->Camera2D.Top - this->Camera2D.Bottom);
daspect *= this->Camera2D.XScale;
//cerr << "waspect="<<waspect << " \tdaspect="<<daspect<<endl;
//needed as center is a constant value
#if defined(VTKM_MSVC)

@ -98,13 +98,11 @@ void MapperVolume::RenderCells(const vtkm::cont::UnknownCellSet& cellset,
vtkm::rendering::raytracing::VolumeRendererStructured tracer;
vtkm::rendering::raytracing::Camera rayCamera;
vtkm::rendering::raytracing::Ray<vtkm::Float32> rays;
vtkm::Int32 width = (vtkm::Int32)this->Internals->Canvas->GetWidth();
vtkm::Int32 height = (vtkm::Int32)this->Internals->Canvas->GetHeight();
rayCamera.SetParameters(camera, width, height);
vtkm::rendering::raytracing::Ray<vtkm::Float32> rays;
rayCamera.CreateRays(rays, coords.GetBounds());
rays.Buffers.at(0).InitConst(0.f);
raytracing::RayOperations::MapCanvasToRays(rays, camera, *this->Internals->Canvas);

@ -102,12 +102,12 @@ ScalarRenderer::Result ScalarRenderer::Render(const vtkm::rendering::Camera& cam
vtkm::cont::Timer timer;
timer.Start();
//
// Create rays
//
vtkm::rendering::raytracing::Camera cam;
cam.SetParameters(camera, this->Internals->Width, this->Internals->Height);
// FIXME: rays are created with an unused Buffers.at(0), that ChannelBuffer
// also has wrong number of channels, thus allocates memory that is wasted.
vtkm::rendering::raytracing::Ray<vtkm::Float32> rays;
cam.CreateRays(rays, this->Internals->ShapeBounds);
rays.Buffers.at(0).InitConst(0.f);
@ -117,12 +117,10 @@ ScalarRenderer::Result ScalarRenderer::Render(const vtkm::rendering::Camera& cam
std::map<std::string, vtkm::Range> rangeMap;
for (vtkm::Id i = 0; i < numFields; ++i)
{
vtkm::cont::Field field = this->Internals->DataSet.GetField(i);
vtkm::cont::ArrayHandle<vtkm::Range> ranges;
ranges = field.GetRange();
vtkm::Id comps = ranges.GetNumberOfValues();
if (comps == 1)
const auto& field = this->Internals->DataSet.GetField(i);
if (field.GetData().GetNumberOfComponents() == 1)
{
auto ranges = field.GetRange();
rangeMap[field.GetName()] = ranges.ReadPortal().Get(0);
this->Internals->Tracer.AddField(field);
}
@ -153,7 +151,6 @@ ScalarRenderer::Result ScalarRenderer::Render(const vtkm::rendering::Camera& cam
raytracing::ChannelBuffer<vtkm::Float32> depthExpanded =
depthChannel.ExpandBuffer(rays.PixelIdx, expandSize, Internals->DefaultValue);
Result result;
result.Width = Internals->Width;
result.Height = Internals->Height;

@ -13,20 +13,16 @@
#include <vtkm/cont/Algorithm.h>
#include <vtkm/cont/ErrorBadValue.h>
#include <vtkm/cont/Timer.h>
#include <vtkm/cont/TryExecute.h>
#include <vtkm/rendering/raytracing/Camera.h>
#include <vtkm/rendering/raytracing/Logger.h>
#include <vtkm/rendering/raytracing/RayOperations.h>
#include <vtkm/rendering/raytracing/RayTracingTypeDefs.h>
#include <vtkm/rendering/raytracing/Sampler.h>
#include <vtkm/rendering/raytracing/Worklets.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <limits>
namespace vtkm
{
namespace rendering
@ -91,9 +87,9 @@ public:
vtkm::Normalize(nlook);
}
VTKM_EXEC inline vtkm::Float32 rcp(vtkm::Float32 f) const { return 1.0f / f; }
VTKM_EXEC static inline vtkm::Float32 rcp(vtkm::Float32 f) { return 1.0f / f; }
VTKM_EXEC inline vtkm::Float32 rcp_safe(vtkm::Float32 f) const
VTKM_EXEC static inline vtkm::Float32 rcp_safe(vtkm::Float32 f)
{
return rcp((fabs(f) < 1e-8f) ? 1e-8f : f);
}
@ -229,7 +225,7 @@ public:
}; // class perspective ray gen jitter
class Camera::Ortho2DRayGen : public vtkm::worklet::WorkletMapField
class Ortho2DRayGen : public vtkm::worklet::WorkletMapField
{
public:
vtkm::Int32 w;
@ -263,15 +259,18 @@ public:
vtkm::Float32 _h = static_cast<vtkm::Float32>(height) * (vt - vb) / 2.f;
vtkm::Vec2f_32 minPoint(left, bottom);
vtkm::Vec2f_32 maxPoint(right, top);
// pixel size in world coordinate
vtkm::Vec2f_32 delta = maxPoint - minPoint;
//delta[0] /= vtkm::Float32(width);
//delta[1] /= vtkm::Float32(height);
delta[0] /= vtkm::Float32(_w);
delta[1] /= vtkm::Float32(_h);
PixelDelta[0] = delta[0];
PixelDelta[1] = delta[1];
PixelDelta[2] = 0.f;
// "first" ray starts at the bottom-lower corner, with half pixel offset. All other
// pixels will be one pixel size (i.e. PixelData) apart.
vtkm::Vec2f_32 startOffset = minPoint + delta / 2.f;
StartOffset[0] = startOffset[0];
StartOffset[1] = startOffset[1];
@ -297,6 +296,7 @@ public:
rayDirX = 0.f;
rayDirY = 0.f;
rayDirZ = 1.f;
//
// Pixel subset is the pixels in the 2d viewport
// not where the rays might intersect data like
@ -305,14 +305,13 @@ public:
int i = vtkm::Int32(idx) % SubsetWidth;
int j = vtkm::Int32(idx) / SubsetWidth;
vtkm::Vec3f_32 pos;
pos[0] = vtkm::Float32(i);
pos[1] = vtkm::Float32(j);
pos[2] = 0.f;
vtkm::Vec3f_32 pos{ vtkm::Float32(i), vtkm::Float32(j), 0.f };
vtkm::Vec3f_32 origin = StartOffset + pos * PixelDelta;
rayOriginX = origin[0];
rayOriginY = origin[1];
rayOriginZ = origin[2];
i += Minx;
j += Miny;
pixelIndex = static_cast<vtkm::Id>(j * w + i);
@ -320,7 +319,7 @@ public:
}; // class perspective ray gen
class Camera::PerspectiveRayGen : public vtkm::worklet::WorkletMapField
class PerspectiveRayGen : public vtkm::worklet::WorkletMapField
{
public:
vtkm::Int32 w;
@ -350,11 +349,13 @@ public:
{
vtkm::Float32 thx = tanf((fovX * vtkm::Pi_180f()) * .5f);
vtkm::Float32 thy = tanf((fovY * vtkm::Pi_180f()) * .5f);
vtkm::Vec3f_32 ru = vtkm::Cross(look, up);
vtkm::Normalize(ru);
vtkm::Vec3f_32 rv = vtkm::Cross(ru, look);
vtkm::Normalize(rv);
delta_x = ru * (2 * thx / (float)w);
delta_y = rv * (2 * thy / (float)h);
@ -367,6 +368,7 @@ public:
delta_y[1] = delta_y[1] / _zoom;
delta_y[2] = delta_y[2] / _zoom;
}
nlook = look;
vtkm::Normalize(nlook);
}
@ -381,14 +383,15 @@ public:
Precision& rayDirZ,
vtkm::Id& pixelIndex) const
{
vtkm::Vec<Precision, 3> ray_dir(rayDirX, rayDirY, rayDirZ);
int i = vtkm::Int32(idx) % SubsetWidth;
int j = vtkm::Int32(idx) / SubsetWidth;
auto i = vtkm::Int32(idx) % SubsetWidth;
auto j = vtkm::Int32(idx) / SubsetWidth;
i += Minx;
j += Miny;
// Write out the global pixelId
pixelIndex = static_cast<vtkm::Id>(j * w + i);
ray_dir = nlook + delta_x * ((2.f * Precision(i) - Precision(w)) / 2.0f) +
vtkm::Vec<Precision, 3> ray_dir = nlook +
delta_x * ((2.f * Precision(i) - Precision(w)) / 2.0f) +
delta_y * ((2.f * Precision(j) - Precision(h)) / 2.0f);
// avoid some numerical issues
for (vtkm::Int32 d = 0; d < 3; ++d)
@ -396,19 +399,16 @@ public:
if (ray_dir[d] == 0.f)
ray_dir[d] += 0.0000001f;
}
Precision dot = vtkm::Dot(ray_dir, ray_dir);
Precision sq_mag = vtkm::Sqrt(dot);
rayDirX = ray_dir[0] / sq_mag;
rayDirY = ray_dir[1] / sq_mag;
rayDirZ = ray_dir[2] / sq_mag;
vtkm::Normalize(ray_dir);
rayDirX = ray_dir[0];
rayDirY = ray_dir[1];
rayDirZ = ray_dir[2];
}
}; // class perspective ray gen
bool Camera::operator==(const Camera& other) const
{
if (this->Height != other.Height)
return false;
if (this->Width != other.Width)
@ -427,68 +427,21 @@ bool Camera::operator==(const Camera& other) const
return false;
if (this->Zoom != other.Zoom)
return false;
if (this->Look[0] != other.Look[0])
if (this->Look != other.Look)
return false;
if (this->Look[1] != other.Look[1])
if (this->LookAt != other.LookAt)
return false;
if (this->Look[2] != other.Look[2])
if (this->Up != other.Up)
return false;
if (this->LookAt[0] != other.LookAt[0])
return false;
if (this->LookAt[1] != other.LookAt[1])
return false;
if (this->LookAt[2] != other.LookAt[2])
return false;
if (this->Up[0] != other.Up[0])
return false;
if (this->Up[1] != other.Up[1])
return false;
if (this->Up[2] != other.Up[2])
return false;
if (this->Position[0] != other.Position[0])
return false;
if (this->Position[1] != other.Position[1])
return false;
if (this->Position[2] != other.Position[2])
if (this->Position != other.Position)
return false;
return true;
}
VTKM_CONT
Camera::Camera()
{
this->Height = 500;
this->Width = 500;
this->SubsetWidth = 500;
this->SubsetHeight = 500;
this->SubsetMinX = 0;
this->SubsetMinY = 0;
this->FovY = 30.f;
this->FovX = 30.f;
this->Zoom = 1.f;
this->Look[0] = 0.f;
this->Look[1] = 0.f;
this->Look[2] = -1.f;
this->LookAt[0] = 0.f;
this->LookAt[1] = 0.f;
this->LookAt[2] = -1.f;
this->Up[0] = 0.f;
this->Up[1] = 1.f;
this->Up[2] = 0.f;
this->Position[0] = 0.f;
this->Position[1] = 0.f;
this->Position[2] = 0.f;
this->IsViewDirty = true;
}
VTKM_CONT
Camera::~Camera() {}
VTKM_CONT
void Camera::SetParameters(const vtkm::rendering::Camera& camera,
const vtkm::Int32 width,
const vtkm::Int32 height)
vtkm::Int32 width,
vtkm::Int32 height)
{
this->SetUp(camera.GetViewUp());
this->SetLookAt(camera.GetLookAt());
@ -500,7 +453,6 @@ void Camera::SetParameters(const vtkm::rendering::Camera& camera,
this->CameraView = camera;
}
VTKM_CONT
void Camera::SetHeight(const vtkm::Int32& height)
{
@ -726,19 +678,19 @@ void Camera::GetPixelData(const vtkm::cont::CoordinateSystem& coords,
}
VTKM_CONT
void Camera::CreateRays(Ray<vtkm::Float32>& rays, vtkm::Bounds bounds)
void Camera::CreateRays(Ray<vtkm::Float32>& rays, const vtkm::Bounds& bounds)
{
CreateRaysImpl(rays, bounds);
}
VTKM_CONT
void Camera::CreateRays(Ray<vtkm::Float64>& rays, vtkm::Bounds bounds)
void Camera::CreateRays(Ray<vtkm::Float64>& rays, const vtkm::Bounds& bounds)
{
CreateRaysImpl(rays, bounds);
}
template <typename Precision>
VTKM_CONT void Camera::CreateRaysImpl(Ray<Precision>& rays, const vtkm::Bounds boundingBox)
VTKM_CONT void Camera::CreateRaysImpl(Ray<Precision>& rays, const vtkm::Bounds& boundingBox)
{
Logger* logger = Logger::GetInstance();
vtkm::cont::Timer createTimer;
@ -748,9 +700,9 @@ VTKM_CONT void Camera::CreateRaysImpl(Ray<Precision>& rays, const vtkm::Bounds b
bool ortho = this->CameraView.GetMode() == vtkm::rendering::Camera::Mode::TwoD;
this->UpdateDimensions(rays, boundingBox, ortho);
this->WriteSettingsToLog();
vtkm::cont::Timer timer;
timer.Start();
//Set the origin of the ray back to the camera position
Precision infinity;
GetInfinity(infinity);
@ -772,40 +724,44 @@ VTKM_CONT void Camera::CreateRaysImpl(Ray<Precision>& rays, const vtkm::Bounds b
//Reset the camera look vector
this->Look = this->LookAt - this->Position;
vtkm::Normalize(this->Look);
vtkm::cont::Invoker invoke;
if (ortho)
{
vtkm::worklet::DispatcherMapField<Ortho2DRayGen> dispatcher(Ortho2DRayGen(this->Width,
this->Height,
this->Zoom,
this->SubsetWidth,
this->SubsetMinX,
this->SubsetMinY,
this->CameraView));
dispatcher.Invoke(rays.DirX,
rays.DirY,
rays.DirZ,
rays.OriginX,
rays.OriginY,
rays.OriginZ,
rays.PixelIdx); //X Y Z
invoke(Ortho2DRayGen{ this->Width,
this->Height,
this->Zoom,
this->SubsetWidth,
this->SubsetMinX,
this->SubsetMinY,
this->CameraView },
rays.DirX,
rays.DirY,
rays.DirZ,
rays.OriginX,
rays.OriginY,
rays.OriginZ,
rays.PixelIdx);
}
else
{
//Create the ray direction
vtkm::worklet::DispatcherMapField<PerspectiveRayGen> dispatcher(
PerspectiveRayGen(this->Width,
this->Height,
this->FovX,
this->FovY,
this->Look,
this->Up,
this->Zoom,
this->SubsetWidth,
this->SubsetMinX,
this->SubsetMinY));
dispatcher.Invoke(rays.DirX, rays.DirY, rays.DirZ, rays.PixelIdx); //X Y Z
invoke(PerspectiveRayGen{ this->Width,
this->Height,
this->FovX,
this->FovY,
this->Look,
this->Up,
this->Zoom,
this->SubsetWidth,
this->SubsetMinX,
this->SubsetMinY },
rays.DirX,
rays.DirY,
rays.DirZ,
rays.PixelIdx);
//Set the origin of the ray back to the camera position
vtkm::cont::ArrayHandleConstant<Precision> posX(this->Position[0], rays.NumRays);
vtkm::cont::Algorithm::Copy(posX, rays.OriginX);
@ -934,11 +890,10 @@ VTKM_CONT void Camera::UpdateDimensions(Ray<Precision>& rays,
if (imageSubsetModeOn && !ortho2D)
{
//Create a transform matrix using the rendering::camera class
vtkm::rendering::Camera camera = this->CameraView;
camera.SetFieldOfView(this->GetFieldOfView());
camera.SetLookAt(this->GetLookAt());
camera.SetPosition(this->GetPosition());
camera.SetViewUp(this->GetUp());
this->CameraView.SetFieldOfView(this->GetFieldOfView());
this->CameraView.SetLookAt(this->GetLookAt());
this->CameraView.SetPosition(this->GetPosition());
this->CameraView.SetViewUp(this->GetUp());
//
// Just create come clipping range, we ignore the zmax value in subsetting
//
@ -947,7 +902,8 @@ VTKM_CONT void Camera::UpdateDimensions(Ray<Precision>& rays,
vtkm::Max(boundingBox.Y.Max - boundingBox.Y.Min, boundingBox.Z.Max - boundingBox.Z.Min));
maxDim *= 100;
camera.SetClippingRange(.0001, maxDim);
this->CameraView.SetClippingRange(.0001, maxDim);
//Update our ViewProjection matrix
this->ViewProjectionMat =
vtkm::MatrixMultiply(this->CameraView.CreateProjectionMatrix(this->Width, this->Height),
@ -957,7 +913,7 @@ VTKM_CONT void Camera::UpdateDimensions(Ray<Precision>& rays,
else if (ortho2D)
{
// 2D rendering has a viewport that represents the area of the canvas where the image
// is drawn. Thus, we have to create rays cooresponding to that region of the
// is drawn. Thus, we have to create rays corresponding to that region of the
// canvas, so annotations are correctly rendered
vtkm::Float32 vl, vr, vb, vt;
this->CameraView.GetRealViewport(this->GetWidth(), this->GetHeight(), vl, vr, vb, vt);
@ -983,8 +939,7 @@ VTKM_CONT void Camera::UpdateDimensions(Ray<Precision>& rays,
// resize rays and buffers
if (rays.NumRays != SubsetWidth * SubsetHeight)
{
RayOperations::Resize(
rays, this->SubsetHeight * this->SubsetWidth, vtkm::cont::DeviceAdapterTagSerial());
RayOperations::Resize(rays, this->SubsetHeight * this->SubsetWidth);
}
}
@ -1001,7 +956,7 @@ void Camera::CreateDebugRay(vtkm::Vec2i_32 pixel, Ray<vtkm::Float32>& rays)
template <typename Precision>
void Camera::CreateDebugRayImp(vtkm::Vec2i_32 pixel, Ray<Precision>& rays)
{
RayOperations::Resize(rays, 1, vtkm::cont::DeviceAdapterTagSerial());
RayOperations::Resize(rays, 1);
vtkm::Int32 pixelIndex = this->Width * (this->Height - pixel[1]) + pixel[0];
rays.PixelIdx.WritePortal().Set(0, pixelIndex);
rays.OriginX.WritePortal().Set(0, this->Position[0]);

@ -12,7 +12,6 @@
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/rendering/Camera.h>
#include <vtkm/rendering/CanvasRayTracer.h>
#include <vtkm/rendering/raytracing/Ray.h>
namespace vtkm
@ -24,55 +23,35 @@ namespace raytracing
class VTKM_RENDERING_EXPORT Camera
{
private:
struct PixelDataFunctor;
vtkm::Int32 Height;
vtkm::Int32 Width;
vtkm::Int32 SubsetWidth;
vtkm::Int32 SubsetHeight;
vtkm::Int32 SubsetMinX;
vtkm::Int32 SubsetMinY;
vtkm::Float32 FovX;
vtkm::Float32 FovY;
vtkm::Float32 Zoom;
bool IsViewDirty;
vtkm::Int32 Height = 500;
vtkm::Int32 Width = 500;
vtkm::Int32 SubsetWidth = 500;
vtkm::Int32 SubsetHeight = 500;
vtkm::Int32 SubsetMinX = 0;
vtkm::Int32 SubsetMinY = 0;
vtkm::Float32 FovX = 30.f;
vtkm::Float32 FovY = 30.f;
vtkm::Float32 Zoom = 1.f;
bool IsViewDirty = true;
vtkm::Vec3f_32 Look;
vtkm::Vec3f_32 Up;
vtkm::Vec3f_32 LookAt;
vtkm::Vec3f_32 Position;
vtkm::Vec3f_32 Look{ 0.f, 0.f, -1.f };
vtkm::Vec3f_32 Up{ 0.f, 1.f, 0.f };
vtkm::Vec3f_32 LookAt{ 0.f, 0.f, -1.f };
vtkm::Vec3f_32 Position{ 0.f, 0.f, 0.f };
vtkm::rendering::Camera CameraView;
vtkm::Matrix<vtkm::Float32, 4, 4> ViewProjectionMat;
public:
VTKM_CONT
Camera();
VTKM_CONT
~Camera();
// cuda does not compile if this is private
class PerspectiveRayGen;
class Ortho2DRayGen;
std::string ToString();
VTKM_CONT
void SetParameters(const vtkm::rendering::Camera& camera,
const vtkm::Int32 width,
const vtkm::Int32 height);
VTKM_CONT
void SetParameters(const vtkm::rendering::Camera& camera,
vtkm::rendering::CanvasRayTracer& canvas);
void SetParameters(const vtkm::rendering::Camera& camera, vtkm::Int32 width, vtkm::Int32 height);
VTKM_CONT
void SetHeight(const vtkm::Int32& height);
VTKM_CONT
void WriteSettingsToLog();
VTKM_CONT
vtkm::Int32 GetHeight() const;
@ -125,10 +104,10 @@ public:
bool GetIsViewDirty() const;
VTKM_CONT
void CreateRays(Ray<vtkm::Float32>& rays, vtkm::Bounds bounds);
void CreateRays(Ray<vtkm::Float32>& rays, const vtkm::Bounds& bounds);
VTKM_CONT
void CreateRays(Ray<vtkm::Float64>& rays, vtkm::Bounds bounds);
void CreateRays(Ray<vtkm::Float64>& rays, const vtkm::Bounds& bounds);
VTKM_CONT
void GetPixelData(const vtkm::cont::CoordinateSystem& coords,
@ -136,7 +115,7 @@ public:
vtkm::Float32& aveRayDistance);
template <typename Precision>
VTKM_CONT void CreateRaysImpl(Ray<Precision>& rays, const vtkm::Bounds boundingBox);
VTKM_CONT void CreateRaysImpl(Ray<Precision>& rays, const vtkm::Bounds& boundingBox);
void CreateDebugRay(vtkm::Vec2i_32 pixel, Ray<vtkm::Float32>& rays);
@ -146,10 +125,14 @@ public:
private:
template <typename Precision>
void CreateDebugRayImp(vtkm::Vec2i_32 pixel, Ray<Precision>& rays);
VTKM_CONT void CreateDebugRayImp(vtkm::Vec2i_32 pixel, Ray<Precision>& rays);
VTKM_CONT
void FindSubset(const vtkm::Bounds& bounds);
VTKM_CONT
void WriteSettingsToLog();
template <typename Precision>
VTKM_CONT void UpdateDimensions(Ray<Precision>& rays,
const vtkm::Bounds& boundingBox,

@ -69,7 +69,6 @@ public:
vtkm::cont::ArrayHandle<Precision> IntersectionY;
vtkm::cont::ArrayHandle<Precision> IntersectionZ;
vtkm::cont::ArrayHandle<Precision> OriginX; //ray Origin
vtkm::cont::ArrayHandle<Precision> OriginY;
vtkm::cont::ArrayHandle<Precision> OriginZ;
@ -117,40 +116,26 @@ public:
DebugHeight = -1;
}
struct EnableIntersectionDataFunctor
{
template <typename Device>
VTKM_CONT bool operator()(Device, Ray<Precision>* self)
{
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
self->EnableIntersectionData(Device());
return true;
}
};
void EnableIntersectionData() { vtkm::cont::TryExecute(EnableIntersectionDataFunctor(), this); }
template <typename Device>
void EnableIntersectionData(Device)
void EnableIntersectionData()
{
if (IntersectionDataEnabled)
{
return;
}
vtkm::cont::Token token;
IntersectionDataEnabled = true;
IntersectionX.PrepareForOutput(NumRays, Device(), token);
IntersectionY.PrepareForOutput(NumRays, Device(), token);
IntersectionZ.PrepareForOutput(NumRays, Device(), token);
U.PrepareForOutput(NumRays, Device(), token);
V.PrepareForOutput(NumRays, Device(), token);
Scalar.PrepareForOutput(NumRays, Device(), token);
NormalX.PrepareForOutput(NumRays, Device(), token);
NormalY.PrepareForOutput(NumRays, Device(), token);
NormalZ.PrepareForOutput(NumRays, Device(), token);
IntersectionX.Allocate(NumRays);
IntersectionY.Allocate(NumRays);
IntersectionZ.Allocate(NumRays);
U.Allocate(NumRays);
V.Allocate(NumRays);
Scalar.Allocate(NumRays);
NormalX.Allocate(NumRays);
NormalY.Allocate(NumRays);
NormalZ.Allocate(NumRays);
}
void DisableIntersectionData()
@ -173,90 +158,9 @@ public:
NormalZ.ReleaseResources();
}
template <typename Device>
VTKM_CONT Ray(const vtkm::Int32 size, Device, bool enableIntersectionData = false)
{
NumRays = size;
IntersectionDataEnabled = enableIntersectionData;
ChannelBuffer<Precision> buffer;
this->Buffers.push_back(buffer);
DebugWidth = -1;
DebugHeight = -1;
this->Resize(size, Device());
}
struct ResizeFunctor
{
template <typename Device>
VTKM_CONT bool operator()(Device, Ray<Precision>* self, const vtkm::Int32 size)
{
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
self->Resize(size, Device());
return true;
}
};
VTKM_CONT void Resize(const vtkm::Int32 size) { vtkm::cont::TryExecute(ResizeFunctor(), size); }
template <typename Device>
VTKM_CONT void Resize(const vtkm::Int32 size, Device)
{
NumRays = size;
vtkm::cont::Token token;
if (IntersectionDataEnabled)
{
IntersectionX.PrepareForOutput(NumRays, Device(), token);
IntersectionY.PrepareForOutput(NumRays, Device(), token);
IntersectionZ.PrepareForOutput(NumRays, Device(), token);
U.PrepareForOutput(NumRays, Device(), token);
V.PrepareForOutput(NumRays, Device(), token);
Scalar.PrepareForOutput(NumRays, Device(), token);
NormalX.PrepareForOutput(NumRays, Device(), token);
NormalY.PrepareForOutput(NumRays, Device(), token);
NormalZ.PrepareForOutput(NumRays, Device(), token);
}
OriginX.PrepareForOutput(NumRays, Device(), token);
OriginY.PrepareForOutput(NumRays, Device(), token);
OriginZ.PrepareForOutput(NumRays, Device(), token);
DirX.PrepareForOutput(NumRays, Device(), token);
DirY.PrepareForOutput(NumRays, Device(), token);
DirZ.PrepareForOutput(NumRays, Device(), token);
Distance.PrepareForOutput(NumRays, Device(), token);
MinDistance.PrepareForOutput(NumRays, Device(), token);
MaxDistance.PrepareForOutput(NumRays, Device(), token);
Status.PrepareForOutput(NumRays, Device(), token);
HitIdx.PrepareForOutput(NumRays, Device(), token);
PixelIdx.PrepareForOutput(NumRays, Device(), token);
Intersection =
vtkm::cont::make_ArrayHandleCompositeVector(IntersectionX, IntersectionY, IntersectionZ);
Normal = vtkm::cont::make_ArrayHandleCompositeVector(NormalX, NormalY, NormalZ);
Origin = vtkm::cont::make_ArrayHandleCompositeVector(OriginX, OriginY, OriginZ);
Dir = vtkm::cont::make_ArrayHandleCompositeVector(DirX, DirY, DirZ);
const size_t numBuffers = this->Buffers.size();
for (size_t i = 0; i < numBuffers; ++i)
{
this->Buffers[i].Resize(NumRays, Device());
}
}
VTKM_CONT
void AddBuffer(const vtkm::Int32 numChannels, const std::string name)
{
ChannelBuffer<Precision> buffer(numChannels, this->NumRays);
buffer.SetName(name);
this->Buffers.push_back(buffer);
@ -265,41 +169,24 @@ public:
VTKM_CONT
bool HasBuffer(const std::string name)
{
size_t numBuffers = this->Buffers.size();
bool found = false;
for (size_t i = 0; i < numBuffers; ++i)
for (const auto& buffer : this->Buffers)
{
if (this->Buffers[i].GetName() == name)
{
found = true;
break;
}
if (buffer.GetName() == name)
return true;
}
return found;
return false;
}
VTKM_CONT
ChannelBuffer<Precision>& GetBuffer(const std::string name)
{
const size_t numBuffers = this->Buffers.size();
bool found = false;
size_t index = 0;
for (size_t i = 0; i < numBuffers; ++i)
for (auto&& buffer : this->Buffers)
{
if (this->Buffers[i].GetName() == name)
{
found = true;
index = i;
}
}
if (found)
{
return this->Buffers.at(index);
}
else
{
throw vtkm::cont::ErrorBadValue("No channel buffer with requested name: " + name);
if (buffer.GetName() == name)
return buffer;
}
throw vtkm::cont::ErrorBadValue("No channel buffer with requested name: " + name);
}
void PrintRay(vtkm::Id pixelId)

@ -30,8 +30,6 @@ namespace detail
class RayStatusFilter : public vtkm::worklet::WorkletMapField
{
public:
VTKM_CONT
RayStatusFilter() {}
using ControlSignature = void(FieldIn, FieldInOut);
using ExecutionSignature = void(_1, _2);
VTKM_EXEC
@ -205,7 +203,7 @@ public:
{
vtkm::Vec<UInt8, 1> maskValues;
maskValues[0] = RAY_ACTIVE;
vtkm::UInt8 statusUInt8 = static_cast<vtkm::UInt8>(RAY_ACTIVE);
auto statusUInt8 = static_cast<vtkm::UInt8>(RAY_ACTIVE);
vtkm::cont::ArrayHandle<vtkm::UInt8> masks;
vtkm::worklet::DispatcherMapField<Mask<vtkm::UInt8>> dispatcher{ (
@ -277,7 +275,7 @@ public:
rays.NumRays = rays.Status.ReadPortal().GetNumberOfValues();
const size_t bufferCount = static_cast<size_t>(rays.Buffers.size());
const auto bufferCount = static_cast<size_t>(rays.Buffers.size());
for (size_t i = 0; i < bufferCount; ++i)
{
ChannelBufferOperations::Compact(rays.Buffers[i], masks, rays.NumRays);
@ -285,48 +283,47 @@ public:
return masks;
}
template <typename Device, typename T>
static void Resize(Ray<T>& rays, const vtkm::Int32 newSize, Device)
template <typename T>
static void Resize(Ray<T>& rays, const vtkm::Int32 newSize)
{
if (newSize == rays.NumRays)
return; //nothing to do
rays.NumRays = newSize;
vtkm::cont::Token token;
if (rays.IntersectionDataEnabled)
{
rays.IntersectionX.PrepareForOutput(rays.NumRays, Device(), token);
rays.IntersectionY.PrepareForOutput(rays.NumRays, Device(), token);
rays.IntersectionZ.PrepareForOutput(rays.NumRays, Device(), token);
rays.U.PrepareForOutput(rays.NumRays, Device(), token);
rays.V.PrepareForOutput(rays.NumRays, Device(), token);
rays.Scalar.PrepareForOutput(rays.NumRays, Device(), token);
rays.IntersectionX.Allocate(rays.NumRays);
rays.IntersectionY.Allocate(rays.NumRays);
rays.IntersectionZ.Allocate(rays.NumRays);
rays.NormalX.PrepareForOutput(rays.NumRays, Device(), token);
rays.NormalY.PrepareForOutput(rays.NumRays, Device(), token);
rays.NormalZ.PrepareForOutput(rays.NumRays, Device(), token);
rays.U.Allocate(rays.NumRays);
rays.V.Allocate(rays.NumRays);
rays.Scalar.Allocate(rays.NumRays);
rays.NormalX.Allocate(rays.NumRays);
rays.NormalY.Allocate(rays.NumRays);
rays.NormalZ.Allocate(rays.NumRays);
}
rays.OriginX.PrepareForOutput(rays.NumRays, Device(), token);
rays.OriginY.PrepareForOutput(rays.NumRays, Device(), token);
rays.OriginZ.PrepareForOutput(rays.NumRays, Device(), token);
rays.OriginX.Allocate(rays.NumRays);
rays.OriginY.Allocate(rays.NumRays);
rays.OriginZ.Allocate(rays.NumRays);
rays.DirX.PrepareForOutput(rays.NumRays, Device(), token);
rays.DirY.PrepareForOutput(rays.NumRays, Device(), token);
rays.DirZ.PrepareForOutput(rays.NumRays, Device(), token);
rays.DirX.Allocate(rays.NumRays);
rays.DirY.Allocate(rays.NumRays);
rays.DirZ.Allocate(rays.NumRays);
rays.Distance.PrepareForOutput(rays.NumRays, Device(), token);
rays.MinDistance.PrepareForOutput(rays.NumRays, Device(), token);
rays.MaxDistance.PrepareForOutput(rays.NumRays, Device(), token);
rays.Status.PrepareForOutput(rays.NumRays, Device(), token);
rays.HitIdx.PrepareForOutput(rays.NumRays, Device(), token);
rays.PixelIdx.PrepareForOutput(rays.NumRays, Device(), token);
rays.Distance.Allocate(rays.NumRays);
rays.MinDistance.Allocate(rays.NumRays);
rays.MaxDistance.Allocate(rays.NumRays);
rays.Status.Allocate(rays.NumRays);
rays.HitIdx.Allocate(rays.NumRays);
rays.PixelIdx.Allocate(rays.NumRays);
const size_t bufferCount = static_cast<size_t>(rays.Buffers.size());
for (size_t i = 0; i < bufferCount; ++i)
for (auto&& buffer : rays.Buffers)
{
rays.Buffers[i].Resize(rays.NumRays, Device());
buffer.Resize(rays.NumRays);
}
}

@ -98,7 +98,7 @@ struct RenderTestOptions
bool LogX = false;
bool LogY = false;
std::string Title = "";
std::string Title;
vtkm::Float32 TitleScale = 0.075f;
vtkm::Vec2f_32 TitlePosition = { -0.11f, 0.92f };
vtkm::Float32 TitleAngle = 0;