2016-01-20 22:40:54 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2016-01-20 22:40:54 +00:00
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtk_m_rendering_raytracing_Ray_h
|
|
|
|
#define vtk_m_rendering_raytracing_Ray_h
|
2017-06-17 21:28:45 +00:00
|
|
|
|
2016-01-20 22:40:54 +00:00
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
2017-06-17 21:28:45 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleCast.h>
|
2016-01-20 22:40:54 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleCompositeVector.h>
|
2017-06-17 21:28:45 +00:00
|
|
|
#include <vtkm/rendering/raytracing/ChannelBuffer.h>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#define RAY_ACTIVE 0
|
|
|
|
#define RAY_COMPLETE 1
|
|
|
|
#define RAY_TERMINATED 2
|
|
|
|
#define RAY_EXITED_MESH 3
|
|
|
|
#define RAY_EXITED_DOMAIN 4
|
|
|
|
#define RAY_LOST 5
|
|
|
|
#define RAY_ABANDONED 6
|
|
|
|
#define RAY_TUG_EPSILON 0.001
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace rendering
|
|
|
|
{
|
|
|
|
namespace raytracing
|
|
|
|
{
|
2016-01-20 22:40:54 +00:00
|
|
|
|
2017-06-17 21:28:45 +00:00
|
|
|
template <typename Precision>
|
|
|
|
class Ray
|
2016-05-18 05:13:36 +00:00
|
|
|
{
|
2017-06-17 21:28:45 +00:00
|
|
|
protected:
|
|
|
|
bool IntersectionDataEnabled;
|
2016-05-18 05:13:36 +00:00
|
|
|
|
2016-01-20 22:40:54 +00:00
|
|
|
public:
|
|
|
|
// composite vectors to hold array handles
|
2017-06-17 21:28:45 +00:00
|
|
|
typename //tell the compiler we have a dependent type
|
2018-05-10 17:06:08 +00:00
|
|
|
vtkm::cont::ArrayHandleCompositeVector<vtkm::cont::ArrayHandle<Precision>,
|
|
|
|
vtkm::cont::ArrayHandle<Precision>,
|
|
|
|
vtkm::cont::ArrayHandle<Precision>>
|
2017-06-17 21:28:45 +00:00
|
|
|
Intersection;
|
2016-05-19 23:15:06 +00:00
|
|
|
|
2017-06-17 21:28:45 +00:00
|
|
|
typename //tell the compiler we have a dependent type
|
2018-05-10 17:06:08 +00:00
|
|
|
vtkm::cont::ArrayHandleCompositeVector<vtkm::cont::ArrayHandle<Precision>,
|
|
|
|
vtkm::cont::ArrayHandle<Precision>,
|
|
|
|
vtkm::cont::ArrayHandle<Precision>>
|
|
|
|
Normal;
|
2016-05-19 23:15:06 +00:00
|
|
|
|
2017-06-17 21:28:45 +00:00
|
|
|
typename //tell the compiler we have a dependent type
|
2018-05-10 17:06:08 +00:00
|
|
|
vtkm::cont::ArrayHandleCompositeVector<vtkm::cont::ArrayHandle<Precision>,
|
|
|
|
vtkm::cont::ArrayHandle<Precision>,
|
|
|
|
vtkm::cont::ArrayHandle<Precision>>
|
|
|
|
Origin;
|
2016-01-20 22:40:54 +00:00
|
|
|
|
2017-06-17 21:28:45 +00:00
|
|
|
typename //tell the compiler we have a dependent type
|
2018-05-10 17:06:08 +00:00
|
|
|
vtkm::cont::ArrayHandleCompositeVector<vtkm::cont::ArrayHandle<Precision>,
|
|
|
|
vtkm::cont::ArrayHandle<Precision>,
|
|
|
|
vtkm::cont::ArrayHandle<Precision>>
|
|
|
|
Dir;
|
2016-01-20 22:40:54 +00:00
|
|
|
|
2017-06-17 21:28:45 +00:00
|
|
|
vtkm::cont::ArrayHandle<Precision> IntersectionX; //ray Intersection
|
|
|
|
vtkm::cont::ArrayHandle<Precision> IntersectionY;
|
|
|
|
vtkm::cont::ArrayHandle<Precision> IntersectionZ;
|
2016-01-20 22:40:54 +00:00
|
|
|
|
2017-06-17 21:28:45 +00:00
|
|
|
vtkm::cont::ArrayHandle<Precision> OriginX; //ray Origin
|
|
|
|
vtkm::cont::ArrayHandle<Precision> OriginY;
|
|
|
|
vtkm::cont::ArrayHandle<Precision> OriginZ;
|
2016-01-20 22:40:54 +00:00
|
|
|
|
2017-06-17 21:28:45 +00:00
|
|
|
vtkm::cont::ArrayHandle<Precision> DirX; //ray Dir
|
|
|
|
vtkm::cont::ArrayHandle<Precision> DirY;
|
|
|
|
vtkm::cont::ArrayHandle<Precision> DirZ;
|
2016-01-20 22:40:54 +00:00
|
|
|
|
2017-06-17 21:28:45 +00:00
|
|
|
vtkm::cont::ArrayHandle<Precision> U; //barycentric coordinates
|
|
|
|
vtkm::cont::ArrayHandle<Precision> V;
|
|
|
|
vtkm::cont::ArrayHandle<Precision> NormalX; //ray Normal
|
|
|
|
vtkm::cont::ArrayHandle<Precision> NormalY;
|
|
|
|
vtkm::cont::ArrayHandle<Precision> NormalZ;
|
|
|
|
vtkm::cont::ArrayHandle<Precision> Scalar; //scalar
|
2016-01-20 22:40:54 +00:00
|
|
|
|
2017-06-17 21:28:45 +00:00
|
|
|
vtkm::cont::ArrayHandle<Precision> Distance; //distance to hit
|
2016-01-20 22:40:54 +00:00
|
|
|
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> HitIdx;
|
2017-06-17 21:28:45 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> PixelIdx;
|
|
|
|
|
|
|
|
vtkm::cont::ArrayHandle<Precision> MinDistance; // distance to hit
|
|
|
|
vtkm::cont::ArrayHandle<Precision> MaxDistance; // distance to hit
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::UInt8> Status; // 0 = active 1 = miss 2 = lost
|
|
|
|
|
|
|
|
std::vector<ChannelBuffer<Precision>> Buffers;
|
|
|
|
vtkm::Id DebugWidth;
|
|
|
|
vtkm::Id DebugHeight;
|
|
|
|
vtkm::Id NumRays;
|
2016-01-20 22:40:54 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2016-01-20 22:40:54 +00:00
|
|
|
Ray()
|
2016-05-19 23:15:06 +00:00
|
|
|
{
|
2017-06-17 21:28:45 +00:00
|
|
|
IntersectionDataEnabled = false;
|
2016-01-20 22:40:54 +00:00
|
|
|
NumRays = 0;
|
2018-05-10 17:06:08 +00:00
|
|
|
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);
|
2017-06-17 21:28:45 +00:00
|
|
|
|
|
|
|
ChannelBuffer<Precision> buffer;
|
|
|
|
buffer.Resize(NumRays);
|
|
|
|
Buffers.push_back(buffer);
|
|
|
|
DebugWidth = -1;
|
|
|
|
DebugHeight = -1;
|
2016-01-20 22:40:54 +00:00
|
|
|
}
|
2017-06-17 21:28:45 +00:00
|
|
|
|
2023-05-18 20:45:16 +00:00
|
|
|
void EnableIntersectionData()
|
2017-06-17 21:28:45 +00:00
|
|
|
{
|
|
|
|
if (IntersectionDataEnabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntersectionDataEnabled = true;
|
2023-05-18 20:45:16 +00:00
|
|
|
|
|
|
|
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);
|
2017-06-17 21:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisableIntersectionData()
|
|
|
|
{
|
|
|
|
if (!IntersectionDataEnabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntersectionDataEnabled = false;
|
|
|
|
IntersectionX.ReleaseResources();
|
|
|
|
IntersectionY.ReleaseResources();
|
|
|
|
IntersectionZ.ReleaseResources();
|
|
|
|
U.ReleaseResources();
|
|
|
|
V.ReleaseResources();
|
|
|
|
Scalar.ReleaseResources();
|
|
|
|
|
|
|
|
NormalX.ReleaseResources();
|
|
|
|
NormalY.ReleaseResources();
|
|
|
|
NormalZ.ReleaseResources();
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-06-17 21:28:45 +00:00
|
|
|
void AddBuffer(const vtkm::Int32 numChannels, const std::string name)
|
2016-01-20 22:40:54 +00:00
|
|
|
{
|
2017-06-17 21:28:45 +00:00
|
|
|
ChannelBuffer<Precision> buffer(numChannels, this->NumRays);
|
|
|
|
buffer.SetName(name);
|
|
|
|
this->Buffers.push_back(buffer);
|
2016-01-20 22:40:54 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 14:30:42 +00:00
|
|
|
VTKM_CONT
|
|
|
|
bool HasBuffer(const std::string name)
|
|
|
|
{
|
2023-05-18 20:45:16 +00:00
|
|
|
for (const auto& buffer : this->Buffers)
|
2017-07-20 14:30:42 +00:00
|
|
|
{
|
2023-05-18 20:45:16 +00:00
|
|
|
if (buffer.GetName() == name)
|
|
|
|
return true;
|
2017-07-20 14:30:42 +00:00
|
|
|
}
|
2023-05-18 20:45:16 +00:00
|
|
|
return false;
|
2017-07-20 14:30:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT
|
|
|
|
ChannelBuffer<Precision>& GetBuffer(const std::string name)
|
|
|
|
{
|
2023-05-18 20:45:16 +00:00
|
|
|
for (auto&& buffer : this->Buffers)
|
2017-07-20 14:30:42 +00:00
|
|
|
{
|
2023-05-18 20:45:16 +00:00
|
|
|
if (buffer.GetName() == name)
|
|
|
|
return buffer;
|
2017-07-20 14:30:42 +00:00
|
|
|
}
|
2023-05-18 20:45:16 +00:00
|
|
|
|
|
|
|
throw vtkm::cont::ErrorBadValue("No channel buffer with requested name: " + name);
|
2017-07-20 14:30:42 +00:00
|
|
|
}
|
|
|
|
|
2017-09-04 15:17:01 +00:00
|
|
|
void PrintRay(vtkm::Id pixelId)
|
|
|
|
{
|
|
|
|
for (vtkm::Id i = 0; i < NumRays; ++i)
|
|
|
|
{
|
2020-01-28 19:14:32 +00:00
|
|
|
if (PixelIdx.WritePortal().Get(i) == pixelId)
|
2017-09-04 15:17:01 +00:00
|
|
|
{
|
|
|
|
std::cout << "Ray " << pixelId << "\n";
|
|
|
|
std::cout << "Origin "
|
2020-01-28 19:14:32 +00:00
|
|
|
<< "[" << OriginX.WritePortal().Get(i) << "," << OriginY.WritePortal().Get(i)
|
|
|
|
<< "," << OriginZ.WritePortal().Get(i) << "]\n";
|
2017-09-04 15:17:01 +00:00
|
|
|
std::cout << "Dir "
|
2020-01-28 19:14:32 +00:00
|
|
|
<< "[" << DirX.WritePortal().Get(i) << "," << DirY.WritePortal().Get(i) << ","
|
|
|
|
<< DirZ.WritePortal().Get(i) << "]\n";
|
2017-09-04 15:17:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-17 21:28:45 +00:00
|
|
|
friend class RayOperations;
|
2017-05-18 14:29:41 +00:00
|
|
|
}; // class ray
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} //namespace vtkm::rendering::raytracing
|
2016-05-18 05:13:36 +00:00
|
|
|
#endif //vtk_m_rendering_raytracing_Ray_h
|