clean up Ray and RayOperator

This commit is contained in:
Li-Ta Lo 2023-05-18 14:45:16 -06:00
parent 9ed11540f1
commit d660a53b8d
2 changed files with 24 additions and 136 deletions

@ -69,7 +69,6 @@ public:
vtkm::cont::ArrayHandle<Precision> IntersectionY; vtkm::cont::ArrayHandle<Precision> IntersectionY;
vtkm::cont::ArrayHandle<Precision> IntersectionZ; vtkm::cont::ArrayHandle<Precision> IntersectionZ;
vtkm::cont::ArrayHandle<Precision> OriginX; //ray Origin vtkm::cont::ArrayHandle<Precision> OriginX; //ray Origin
vtkm::cont::ArrayHandle<Precision> OriginY; vtkm::cont::ArrayHandle<Precision> OriginY;
vtkm::cont::ArrayHandle<Precision> OriginZ; vtkm::cont::ArrayHandle<Precision> OriginZ;
@ -117,40 +116,26 @@ public:
DebugHeight = -1; DebugHeight = -1;
} }
void EnableIntersectionData()
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)
{ {
if (IntersectionDataEnabled) if (IntersectionDataEnabled)
{ {
return; return;
} }
vtkm::cont::Token token;
IntersectionDataEnabled = true; 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); IntersectionX.Allocate(NumRays);
NormalY.PrepareForOutput(NumRays, Device(), token); IntersectionY.Allocate(NumRays);
NormalZ.PrepareForOutput(NumRays, Device(), token); IntersectionZ.Allocate(NumRays);
U.Allocate(NumRays);
V.Allocate(NumRays);
Scalar.Allocate(NumRays);
NormalX.Allocate(NumRays);
NormalY.Allocate(NumRays);
NormalZ.Allocate(NumRays);
} }
void DisableIntersectionData() void DisableIntersectionData()
@ -173,90 +158,9 @@ public:
NormalZ.ReleaseResources(); 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 VTKM_CONT
void AddBuffer(const vtkm::Int32 numChannels, const std::string name) void AddBuffer(const vtkm::Int32 numChannels, const std::string name)
{ {
ChannelBuffer<Precision> buffer(numChannels, this->NumRays); ChannelBuffer<Precision> buffer(numChannels, this->NumRays);
buffer.SetName(name); buffer.SetName(name);
this->Buffers.push_back(buffer); this->Buffers.push_back(buffer);
@ -265,41 +169,24 @@ public:
VTKM_CONT VTKM_CONT
bool HasBuffer(const std::string name) bool HasBuffer(const std::string name)
{ {
size_t numBuffers = this->Buffers.size(); for (const auto& buffer : this->Buffers)
bool found = false;
for (size_t i = 0; i < numBuffers; ++i)
{ {
if (this->Buffers[i].GetName() == name) if (buffer.GetName() == name)
{ return true;
found = true;
break;
}
} }
return found; return false;
} }
VTKM_CONT VTKM_CONT
ChannelBuffer<Precision>& GetBuffer(const std::string name) ChannelBuffer<Precision>& GetBuffer(const std::string name)
{ {
const size_t numBuffers = this->Buffers.size(); for (auto&& buffer : this->Buffers)
bool found = false;
size_t index = 0;
for (size_t i = 0; i < numBuffers; ++i)
{ {
if (this->Buffers[i].GetName() == name) if (buffer.GetName() == name)
{ return buffer;
found = true;
index = i;
}
}
if (found)
{
return this->Buffers.at(index);
}
else
{
throw vtkm::cont::ErrorBadValue("No channel buffer with requested name: " + name);
} }
throw vtkm::cont::ErrorBadValue("No channel buffer with requested name: " + name);
} }
void PrintRay(vtkm::Id pixelId) void PrintRay(vtkm::Id pixelId)

@ -277,7 +277,7 @@ public:
rays.NumRays = rays.Status.ReadPortal().GetNumberOfValues(); 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) for (size_t i = 0; i < bufferCount; ++i)
{ {
ChannelBufferOperations::Compact(rays.Buffers[i], masks, rays.NumRays); ChannelBufferOperations::Compact(rays.Buffers[i], masks, rays.NumRays);
@ -298,6 +298,7 @@ public:
rays.IntersectionX.Allocate(rays.NumRays); rays.IntersectionX.Allocate(rays.NumRays);
rays.IntersectionY.Allocate(rays.NumRays); rays.IntersectionY.Allocate(rays.NumRays);
rays.IntersectionZ.Allocate(rays.NumRays); rays.IntersectionZ.Allocate(rays.NumRays);
rays.U.Allocate(rays.NumRays); rays.U.Allocate(rays.NumRays);
rays.V.Allocate(rays.NumRays); rays.V.Allocate(rays.NumRays);
rays.Scalar.Allocate(rays.NumRays); rays.Scalar.Allocate(rays.NumRays);
@ -322,7 +323,7 @@ public:
rays.HitIdx.Allocate(rays.NumRays); rays.HitIdx.Allocate(rays.NumRays);
rays.PixelIdx.Allocate(rays.NumRays); rays.PixelIdx.Allocate(rays.NumRays);
for (auto& buffer : rays.Buffers) for (auto&& buffer : rays.Buffers)
{ {
buffer.Resize(rays.NumRays); buffer.Resize(rays.NumRays);
} }