1 //============================================================================
2 //  Copyright (c) Kitware, Inc.
3 //  All rights reserved.
4 //  See LICENSE.txt for details.
5 //  This software is distributed WITHOUT ANY WARRANTY; without even
6 //  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7 //  PURPOSE.  See the above copyright notice for more information.
8 //
9 //  Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 //  Copyright 2015 UT-Battelle, LLC.
11 //  Copyright 2015 Los Alamos National Security.
12 //
13 //  Under the terms of Contract DE-NA0003525 with NTESS,
14 //  the U.S. Government retains certain rights in this software.
15 //
16 //  Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
17 //  Laboratory (LANL), the U.S. Government retains certain rights in
18 //  this software.
19 //============================================================================
20 #ifndef vtk_m_worklet_BoundingVolumeHierachy_h
21 #define vtk_m_worklet_BoundingVolumeHierachy_h
22 
23 #include <vtkm/cont/ArrayHandle.h>
24 #include <vtkm/cont/DataSet.h>
25 #include <vtkm/rendering/vtkm_rendering_export.h>
26 
27 namespace vtkm
28 {
29 namespace rendering
30 {
31 namespace raytracing
32 {
33 
34 struct AABBs
35 {
36   vtkm::cont::ArrayHandle<vtkm::Float32> xmins;
37   vtkm::cont::ArrayHandle<vtkm::Float32> ymins;
38   vtkm::cont::ArrayHandle<vtkm::Float32> zmins;
39   vtkm::cont::ArrayHandle<vtkm::Float32> xmaxs;
40   vtkm::cont::ArrayHandle<vtkm::Float32> ymaxs;
41   vtkm::cont::ArrayHandle<vtkm::Float32> zmaxs;
42 };
43 
44 //
45 // This is the data structure that is passed to the ray tracer.
46 //
47 class VTKM_RENDERING_EXPORT LinearBVH
48 {
49 public:
50   using InnerNodesHandle = vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32, 4>>;
51   using LeafNodesHandle = vtkm::cont::ArrayHandle<Id>;
52   AABBs AABB;
53   InnerNodesHandle FlatBVH;
54   LeafNodesHandle Leafs;
55   vtkm::Bounds TotalBounds;
56   struct ConstructFunctor;
57   vtkm::Id LeafCount;
58 
59 protected:
60   bool IsConstructed;
61   bool CanConstruct;
62 
63 public:
64   LinearBVH();
65 
66   VTKM_CONT
67   LinearBVH(AABBs& aabbs);
68 
69   VTKM_CONT
70   LinearBVH(const LinearBVH& other);
71 
72   template <typename DeviceAdapter>
73   VTKM_CONT void Allocate(const vtkm::Id& leafCount, DeviceAdapter deviceAdapter);
74 
75   VTKM_CONT
76   void Construct();
77 
78   VTKM_CONT
79   void SetData(AABBs& aabbs);
80 
81   VTKM_CONT
82   AABBs& GetAABBs();
83 
84   template <typename Device>
85   VTKM_CONT void ConstructOnDevice(Device device);
86 
87   VTKM_CONT
88   bool GetIsConstructed() const;
89 
90   vtkm::Id GetNumberOfAABBs() const;
91 }; // class LinearBVH
92 }
93 }
94 } // namespace vtkm::rendering::raytracing
95 #endif //vtk_m_worklet_BoundingVolumeHierachy_h
96