KiCad PCB EDA Suite
bvh_pbrt.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 2015-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
70 #ifndef _BVH_PBRT_H_
71 #define _BVH_PBRT_H_
72 
73 #include "accelerator_3d.h"
74 #include <cstdint>
75 #include <list>
76 
77 // Forward Declarations
78 struct BVHBuildNode;
79 struct BVHPrimitiveInfo;
80 struct MortonPrimitive;
81 
83 {
84  // 24 bytes
86 
87  // 4 bytes
88  union
89  {
92  };
93 
94  // 4 bytes
95  uint16_t nPrimitives;
96  uint8_t axis;
97  uint8_t pad[1];
98 };
99 
100 
101 enum class SPLITMETHOD
102 {
103  MIDDLE,
104  EQUALCOUNTS,
105  SAH,
106  HLBVH
107 };
108 
109 
110 class BVH_PBRT : public ACCELERATOR_3D
111 {
112 public:
113  BVH_PBRT( const CONTAINER_3D_BASE& aObjectContainer, int aMaxPrimsInNode = 4,
114  SPLITMETHOD aSplitMethod = SPLITMETHOD::SAH );
115 
116  ~BVH_PBRT();
117 
118  bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const override;
119  bool Intersect( const RAY& aRay, HITINFO& aHitInfo, unsigned int aAccNodeInfo ) const override;
120  bool Intersect( const RAYPACKET& aRayPacket, HITINFO_PACKET* aHitInfoPacket ) const override;
121  bool IntersectP( const RAY& aRay, float aMaxDistance ) const override;
122 
123 private:
124  BVHBuildNode* recursiveBuild( std::vector<BVHPrimitiveInfo>& primitiveInfo, int start,
125  int end, int* totalNodes, CONST_VECTOR_OBJECT& orderedPrims );
126 
127  BVHBuildNode* HLBVHBuild( const std::vector<BVHPrimitiveInfo>& primitiveInfo,
128  int* totalNodes, CONST_VECTOR_OBJECT& orderedPrims );
129 
131  BVHBuildNode* emitLBVH( BVHBuildNode* &buildNodes,
132  const std::vector<BVHPrimitiveInfo>& primitiveInfo,
133  MortonPrimitive* mortonPrims, int nPrimitives, int* totalNodes,
134  CONST_VECTOR_OBJECT& orderedPrims, int* orderedPrimsOffset, int bit );
135 
136  BVHBuildNode* buildUpperSAH( std::vector<BVHBuildNode*>& treeletRoots, int start, int end,
137  int* totalNodes );
138 
139  int flattenBVHTree( BVHBuildNode* node, uint32_t* offset );
140 
141  // BVH Private Data
142  const int m_maxPrimsInNode;
146 
147  std::list<void*> m_nodesToFree;
148 
149  // Partition traversal
151 };
152 
153 #endif // _BVH_PBRT_H_
int primitivesOffset
leaf
Definition: bvh_pbrt.h:90
CONST_VECTOR_OBJECT m_primitives
Definition: bvh_pbrt.h:144
SPLITMETHOD m_splitMethod
Definition: bvh_pbrt.h:143
uint16_t nPrimitives
0 -> interior node
Definition: bvh_pbrt.h:95
BVHBuildNode * recursiveBuild(std::vector< BVHPrimitiveInfo > &primitiveInfo, int start, int end, int *totalNodes, CONST_VECTOR_OBJECT &orderedPrims)
Definition: bvh_pbrt.cpp:426
Manage a bounding box defined by two SFVEC3F min max points.
Definition: bbox_3d.h:41
uint8_t axis
interior node: xyz
Definition: bvh_pbrt.h:96
BVHBuildNode * HLBVHBuild(const std::vector< BVHPrimitiveInfo > &primitiveInfo, int *totalNodes, CONST_VECTOR_OBJECT &orderedPrims)
Definition: bvh_pbrt.cpp:678
std::vector< const OBJECT_3D * > CONST_VECTOR_OBJECT
Definition: container_3d.h:38
Definition: ray.h:67
SPLITMETHOD
Definition: bvh_pbrt.h:101
BVHBuildNode * emitLBVH(BVHBuildNode *&buildNodes, const std::vector< BVHPrimitiveInfo > &primitiveInfo, MortonPrimitive *mortonPrims, int nPrimitives, int *totalNodes, CONST_VECTOR_OBJECT &orderedPrims, int *orderedPrimsOffset, int bit)
TODO: after implement memory arena, put const back to this functions.
Definition: bvh_pbrt.cpp:795
uint8_t pad[1]
ensure 32 byte total size
Definition: bvh_pbrt.h:97
BVHBuildNode * buildUpperSAH(std::vector< BVHBuildNode * > &treeletRoots, int start, int end, int *totalNodes)
Definition: bvh_pbrt.cpp:894
const int m_maxPrimsInNode
Definition: bvh_pbrt.h:142
bool IntersectP(const RAY &aRay, float aMaxDistance) const override
Definition: bvh_pbrt.cpp:1195
std::list< void * > m_nodesToFree
Definition: bvh_pbrt.h:147
Stores the hit information of a ray with a point on the surface of a object.
Definition: hitinfo.h:40
#define RAYPACKET_RAYS_PER_PACKET
Definition: raypacket.h:40
bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const override
Definition: bvh_pbrt.cpp:1066
int flattenBVHTree(BVHBuildNode *node, uint32_t *offset)
Definition: bvh_pbrt.cpp:1034
int secondChildOffset
interior
Definition: bvh_pbrt.h:91
BVH_PBRT(const CONTAINER_3D_BASE &aObjectContainer, int aMaxPrimsInNode=4, SPLITMETHOD aSplitMethod=SPLITMETHOD::SAH)
Definition: bvh_pbrt.cpp:235
unsigned int m_I[RAYPACKET_RAYS_PER_PACKET]
Definition: bvh_pbrt.h:150
LinearBVHNode * m_nodes
Definition: bvh_pbrt.h:145
BBOX_3D bounds
Definition: bvh_pbrt.h:85