KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
5 * Copyright The 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, see <https://www.gnu.org/licenses/>.
19 */
20
64
65
66#ifndef _BVH_PBRT_H_
67#define _BVH_PBRT_H_
68
69#include "accelerator_3d.h"
70#include <cstdint>
71#include <list>
72
73// Forward Declarations
74struct BVHBuildNode;
75struct BVHPrimitiveInfo;
76struct MortonPrimitive;
77
79{
80 // 24 bytes
82
83 // 4 bytes
84 union
85 {
88 };
89
90 // 4 bytes
91 uint16_t nPrimitives;
92 uint8_t axis;
93 uint8_t pad[1];
94};
95
96
104
105
107{
108public:
109 BVH_PBRT( const CONTAINER_3D_BASE& aObjectContainer, int aMaxPrimsInNode = 4,
110 SPLITMETHOD aSplitMethod = SPLITMETHOD::SAH );
111
112 ~BVH_PBRT();
113
114 // We own at least one list of raw pointers. Don't let the compiler fill in copy c'tors that
115 // will only land us in trouble.
116 BVH_PBRT( const BVH_PBRT& ) = delete;
117 BVH_PBRT& operator=( const BVH_PBRT& ) = delete;
118
119 bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const override;
120 bool Intersect( const RAY& aRay, HITINFO& aHitInfo, unsigned int aAccNodeInfo ) const override;
121 bool Intersect( const RAYPACKET& aRayPacket, HITINFO_PACKET* aHitInfoPacket ) const override;
122 bool IntersectP( const RAY& aRay, float aMaxDistance ) const override;
123
124private:
125 BVHBuildNode* recursiveBuild( std::vector<BVHPrimitiveInfo>& primitiveInfo, int start, int end, int* totalNodes,
126 std::vector<const OBJECT_3D*>& orderedPrims );
127
128 BVHBuildNode* HLBVHBuild( const std::vector<BVHPrimitiveInfo>& primitiveInfo, int* totalNodes,
129 std::vector<const OBJECT_3D*>& orderedPrims );
130
132 BVHBuildNode* emitLBVH( BVHBuildNode* &buildNodes, const std::vector<BVHPrimitiveInfo>& primitiveInfo,
133 MortonPrimitive* mortonPrims, int nPrimitives, int* totalNodes,
134 std::vector<const OBJECT_3D*>& orderedPrims, int* orderedPrimsOffset, int bit );
135
136 BVHBuildNode* buildUpperSAH( std::vector<BVHBuildNode*>& treeletRoots, int start, int end, int* totalNodes );
137
138 int flattenBVHTree( BVHBuildNode* node, uint32_t* offset );
139
140 // BVH Private Data
143 std::vector<const OBJECT_3D*> m_primitives;
145
146 std::list<void*> m_nodesToFree;
147
148 // Partition traversal
150};
151
152#endif // _BVH_PBRT_H_
SPLITMETHOD
Definition bvh_pbrt.h:98
BVH_PBRT & operator=(const BVH_PBRT &)=delete
std::list< void * > m_nodesToFree
Definition bvh_pbrt.h:146
int flattenBVHTree(BVHBuildNode *node, uint32_t *offset)
BVH_PBRT(const BVH_PBRT &)=delete
LinearBVHNode * m_nodes
Definition bvh_pbrt.h:144
BVHBuildNode * HLBVHBuild(const std::vector< BVHPrimitiveInfo > &primitiveInfo, int *totalNodes, std::vector< const OBJECT_3D * > &orderedPrims)
Definition bvh_pbrt.cpp:674
BVHBuildNode * recursiveBuild(std::vector< BVHPrimitiveInfo > &primitiveInfo, int start, int end, int *totalNodes, std::vector< const OBJECT_3D * > &orderedPrims)
Definition bvh_pbrt.cpp:422
unsigned int m_I[RAYPACKET_RAYS_PER_PACKET]
Definition bvh_pbrt.h:149
BVH_PBRT(const CONTAINER_3D_BASE &aObjectContainer, int aMaxPrimsInNode=4, SPLITMETHOD aSplitMethod=SPLITMETHOD::SAH)
Definition bvh_pbrt.cpp:231
std::vector< const OBJECT_3D * > m_primitives
Definition bvh_pbrt.h:143
BVHBuildNode * buildUpperSAH(std::vector< BVHBuildNode * > &treeletRoots, int start, int end, int *totalNodes)
Definition bvh_pbrt.cpp:888
const int m_maxPrimsInNode
Definition bvh_pbrt.h:141
bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const override
bool IntersectP(const RAY &aRay, float aMaxDistance) const override
BVHBuildNode * emitLBVH(BVHBuildNode *&buildNodes, const std::vector< BVHPrimitiveInfo > &primitiveInfo, MortonPrimitive *mortonPrims, int nPrimitives, int *totalNodes, std::vector< const OBJECT_3D * > &orderedPrims, int *orderedPrimsOffset, int bit)
TODO: after implement memory arena, put const back to this functions.
Definition bvh_pbrt.cpp:791
SPLITMETHOD m_splitMethod
Definition bvh_pbrt.h:142
#define RAYPACKET_RAYS_PER_PACKET
Definition raypacket.h:31
Manage a bounding box defined by two SFVEC3F min max points.
Definition bbox_3d.h:39
Stores the hit information of a ray with a point on the surface of a object.
Definition hitinfo.h:32
int secondChildOffset
interior
Definition bvh_pbrt.h:87
uint8_t axis
interior node: xyz
Definition bvh_pbrt.h:92
BBOX_3D bounds
Definition bvh_pbrt.h:81
uint16_t nPrimitives
0 -> interior node
Definition bvh_pbrt.h:91
uint8_t pad[1]
ensure 32 byte total size
Definition bvh_pbrt.h:93
int primitivesOffset
leaf
Definition bvh_pbrt.h:86
Definition ray.h:59
VECTOR2I end