From d660a53b8d66a9fcf41efb154a5b1ce02f0d2169 Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Thu, 18 May 2023 14:45:16 -0600 Subject: [PATCH] clean up Ray and RayOperator --- vtkm/rendering/raytracing/Ray.h | 155 +++------------------- vtkm/rendering/raytracing/RayOperations.h | 5 +- 2 files changed, 24 insertions(+), 136 deletions(-) diff --git a/vtkm/rendering/raytracing/Ray.h b/vtkm/rendering/raytracing/Ray.h index 82b627ee8..c1de3225e 100644 --- a/vtkm/rendering/raytracing/Ray.h +++ b/vtkm/rendering/raytracing/Ray.h @@ -69,7 +69,6 @@ public: vtkm::cont::ArrayHandle IntersectionY; vtkm::cont::ArrayHandle IntersectionZ; - vtkm::cont::ArrayHandle OriginX; //ray Origin vtkm::cont::ArrayHandle OriginY; vtkm::cont::ArrayHandle OriginZ; @@ -117,40 +116,26 @@ public: DebugHeight = -1; } - - struct EnableIntersectionDataFunctor - { - template - VTKM_CONT bool operator()(Device, Ray* self) - { - VTKM_IS_DEVICE_ADAPTER_TAG(Device); - self->EnableIntersectionData(Device()); - return true; - } - }; - - void EnableIntersectionData() { vtkm::cont::TryExecute(EnableIntersectionDataFunctor(), this); } - - template - 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 - VTKM_CONT Ray(const vtkm::Int32 size, Device, bool enableIntersectionData = false) - { - NumRays = size; - IntersectionDataEnabled = enableIntersectionData; - - ChannelBuffer buffer; - this->Buffers.push_back(buffer); - - DebugWidth = -1; - DebugHeight = -1; - - this->Resize(size, Device()); - } - - struct ResizeFunctor - { - template - VTKM_CONT bool operator()(Device, Ray* 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 - 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 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& 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) diff --git a/vtkm/rendering/raytracing/RayOperations.h b/vtkm/rendering/raytracing/RayOperations.h index 0435e28a8..9464ed97e 100644 --- a/vtkm/rendering/raytracing/RayOperations.h +++ b/vtkm/rendering/raytracing/RayOperations.h @@ -277,7 +277,7 @@ public: rays.NumRays = rays.Status.ReadPortal().GetNumberOfValues(); - const size_t bufferCount = static_cast(rays.Buffers.size()); + const auto bufferCount = static_cast(rays.Buffers.size()); for (size_t i = 0; i < bufferCount; ++i) { ChannelBufferOperations::Compact(rays.Buffers[i], masks, rays.NumRays); @@ -298,6 +298,7 @@ public: rays.IntersectionX.Allocate(rays.NumRays); rays.IntersectionY.Allocate(rays.NumRays); rays.IntersectionZ.Allocate(rays.NumRays); + rays.U.Allocate(rays.NumRays); rays.V.Allocate(rays.NumRays); rays.Scalar.Allocate(rays.NumRays); @@ -322,7 +323,7 @@ public: rays.HitIdx.Allocate(rays.NumRays); rays.PixelIdx.Allocate(rays.NumRays); - for (auto& buffer : rays.Buffers) + for (auto&& buffer : rays.Buffers) { buffer.Resize(rays.NumRays); }