59 static_assert(
sizeof(
Node) == 64,
"Node should be 64 bytes");
73 ioBufferSize +=
sizeof(
Node);
85 return ioBuffer.
size();
88 size_t node_start = ioBuffer.
size();
93 for (
size_t i = 0; i < 4; ++i)
95 if (i < ioChildren.
size())
111 outError =
"NodeCodecQuadTreeHalfFloat: Too many triangles";
133 outChildBoundsMin[i] = inNodeBoundsMin;
134 outChildBoundsMax[i] = inNodeBoundsMax;
147 for (
uint i = 0; i < inNumChildren; ++i)
153 offset = inChildrenTrianglesStart[i];
156 mHighestTriangleBlock = max(mHighestTriangleBlock, offset);
161 offset = inChildrenNodeStart[i];
167 outError =
"NodeCodecQuadTreeHalfFloat: Internal Error: Offset has non-significant bits set";
173 outError =
"NodeCodecQuadTreeHalfFloat: Offset too large. Too much data.";
186 size_t offset = inRoot->
HasChildren()? inRootNodeStart : inRootTrianglesStart;
189 outError =
"NodeCodecQuadTreeHalfFloat: Internal Error: Offset has non-significant bits set";
195 outError =
"NodeCodecQuadTreeHalfFloat: Offset too large. Too much data.";
200 size_t highest_triangle_block = inRootTrianglesStart != size_t(-1)? inRootTrianglesStart : mHighestTriangleBlock;
209 outError =
"NodeCodecQuadTreeHalfFloat: Too many triangles";
217 size_t mHighestTriangleBlock = 0;
244 template <
class TriangleContext,
class Visitor>
245 JPH_INLINE
void WalkTree(
const uint8 *inBufferStart,
const TriangleContext &inTriangleContext, Visitor &ioVisitor)
250 uint32 node_properties = mNodeStack[mTop];
257 #ifdef JPH_CPU_BIG_ENDIAN
283 int num_results = ioVisitor.VisitNodes(bounds_minx, bounds_miny, bounds_minz, bounds_maxx, bounds_maxy, bounds_maxz, properties, mTop);
296 ioVisitor.VisitTriangles(inTriangleContext, triangles, tri_count, triangle_block_id);
300 if (ioVisitor.ShouldAbort())
306 while (mTop >= 0 && !ioVisitor.ShouldVisitNode(mTop));
std::uint8_t uint8
Definition Core.h:482
std::uint64_t uint64
Definition Core.h:485
unsigned int uint
Definition Core.h:481
#define JPH_NAMESPACE_END
Definition Core.h:414
std::uint32_t uint32
Definition Core.h:484
#define JPH_NAMESPACE_BEGIN
Definition Core.h:408
uint16 HalfFloat
Definition HalfFloat.h:12
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
uint CountLeadingZeros(uint32 inValue)
Compute the number of leading zero bits (how many high bits are zero)
Definition Math.h:134
@ SWIZZLE_Z
Use the Z component.
Definition Swizzle.h:14
@ SWIZZLE_W
Use the W component.
Definition Swizzle.h:15
@ SWIZZLE_UNUSED
We always use the Z component when we don't specifically want to initialize a value,...
Definition Swizzle.h:16
A node in the tree, contains the AABox for the tree and any child nodes or triangles.
Definition AABBTreeBuilder.h:40
AABox mBounds
Bounding box.
Definition AABBTreeBuilder.h:78
uint GetTriangleCount() const
Get number of triangles in this node.
Definition AABBTreeBuilder.h:48
bool HasChildren() const
Check if this node has any children.
Definition AABBTreeBuilder.h:51
Vec3 mMin
Bounding box min and max.
Definition AABox.h:309
Vec3 mMax
Definition AABox.h:310
size_type size() const
Returns amount of elements in the array.
Definition Array.h:320
Simple byte buffer, aligned to a cache line.
Definition ByteBuffer.h:16
Type * Allocate(size_t inSize=1)
Allocate block of data of inSize elements and return the pointer.
Definition ByteBuffer.h:33
const Type * Get(size_t inPosition) const
Get object at inPosition (an offset in bytes)
Definition ByteBuffer.h:61
Class that holds 3 floats. Used as a storage class. Convert to Vec3 for calculations.
Definition Float3.h:13
This class decodes and decompresses quad tree nodes.
Definition NodeCodecQuadTreeHalfFloat.h:222
bool IsDoneWalking() const
This can be used to have the visitor early out (ioVisitor.ShouldAbort() returns true) and later conti...
Definition NodeCodecQuadTreeHalfFloat.h:312
static uint sTriangleBlockIDBits(const Header *inHeader)
Get the amount of bits needed to store an ID to a triangle block.
Definition NodeCodecQuadTreeHalfFloat.h:225
JPH_INLINE DecodingContext(const Header *inHeader)
Constructor.
Definition NodeCodecQuadTreeHalfFloat.h:237
static const void * sGetTriangleBlockStart(const uint8 *inBufferStart, uint inTriangleBlockID)
Convert a triangle block ID to the start of the triangle buffer.
Definition NodeCodecQuadTreeHalfFloat.h:231
JPH_INLINE void WalkTree(const uint8 *inBufferStart, const TriangleContext &inTriangleContext, Visitor &ioVisitor)
Walk the node tree calling the Visitor::VisitNodes for each node encountered and Visitor::VisitTriang...
Definition NodeCodecQuadTreeHalfFloat.h:245
This class encodes and compresses quad tree nodes.
Definition NodeCodecQuadTreeHalfFloat.h:63
bool NodeFinalize(const AABBTreeBuilder::Node *inNode, size_t inNodeStart, uint inNumChildren, const size_t *inChildrenNodeStart, const size_t *inChildrenTrianglesStart, ByteBuffer &ioBuffer, const char *&outError)
Once all nodes have been added, this call finalizes all nodes by patching in the offsets of the child...
Definition NodeCodecQuadTreeHalfFloat.h:141
size_t NodeAllocate(const AABBTreeBuilder::Node *inNode, Vec3Arg inNodeBoundsMin, Vec3Arg inNodeBoundsMax, Array< const AABBTreeBuilder::Node * > &ioChildren, Vec3 outChildBoundsMin[NumChildrenPerNode], Vec3 outChildBoundsMax[NumChildrenPerNode], ByteBuffer &ioBuffer, const char *&outError) const
Definition NodeCodecQuadTreeHalfFloat.h:81
bool Finalize(Header *outHeader, const AABBTreeBuilder::Node *inRoot, size_t inRootNodeStart, size_t inRootTrianglesStart, const char *&outError) const
Once all nodes have been finalized, this will finalize the header of the nodes.
Definition NodeCodecQuadTreeHalfFloat.h:183
void PrepareNodeAllocate(const AABBTreeBuilder::Node *inNode, uint64 &ioBufferSize) const
Mimics the size a call to NodeAllocate() would add to the buffer.
Definition NodeCodecQuadTreeHalfFloat.h:66
Definition NodeCodecQuadTreeHalfFloat.h:14
static constexpr int StackSize
Stack size to use during DecodingContext::sWalkTree.
Definition NodeCodecQuadTreeHalfFloat.h:33
static constexpr int HeaderSize
Size of the header (an empty struct is always > 0 bytes so this needs a separate variable)
Definition NodeCodecQuadTreeHalfFloat.h:30
static constexpr int NumChildrenPerNode
Number of child nodes of this node.
Definition NodeCodecQuadTreeHalfFloat.h:17
@ OFFSET_BITS
Definition NodeCodecQuadTreeHalfFloat.h:41
@ OFFSET_MASK
Definition NodeCodecQuadTreeHalfFloat.h:42
@ TRIANGLE_COUNT_MASK
Definition NodeCodecQuadTreeHalfFloat.h:40
@ OFFSET_NON_SIGNIFICANT_MASK
Definition NodeCodecQuadTreeHalfFloat.h:44
@ OFFSET_NON_SIGNIFICANT_BITS
Definition NodeCodecQuadTreeHalfFloat.h:43
@ TRIANGLE_COUNT_SHIFT
Definition NodeCodecQuadTreeHalfFloat.h:39
@ TRIANGLE_COUNT_BITS
Definition NodeCodecQuadTreeHalfFloat.h:38
JPH_INLINE UVec4 Swizzle() const
Swizzle the elements in inV.
JPH_INLINE void StoreInt4(uint32 *outV) const
Store 4 ints to memory.
Definition UVec4.inl:351
static JPH_INLINE UVec4 sLoadInt4(const uint32 *inV)
Load 4 ints from memory.
Definition UVec4.inl:78
JPH_INLINE float GetX() const
Get individual components.
Definition Vec3.h:124
JPH_INLINE float GetY() const
Definition Vec3.h:125
JPH_INLINE void StoreFloat3(Float3 *outV) const
Store 3 floats to memory.
Definition Vec3.inl:767
JPH_INLINE float GetZ() const
Definition Vec3.h:126
JPH_INLINE Vec4 ToFloat(UVec4Arg inValue)
Convert 4 half floats (lower 64 bits) to floats.
Definition HalfFloat.h:195
JPH_INLINE HalfFloat FromFloat(float inV)
Convert a float (32-bits) to a half float (16-bits)
Definition HalfFloat.h:133
Node structure.
Definition NodeCodecQuadTreeHalfFloat.h:49
HalfFloat mBoundsMaxY[4]
Definition NodeCodecQuadTreeHalfFloat.h:54
HalfFloat mBoundsMinY[4]
Definition NodeCodecQuadTreeHalfFloat.h:51
HalfFloat mBoundsMaxX[4]
Definition NodeCodecQuadTreeHalfFloat.h:53
HalfFloat mBoundsMaxZ[4]
Definition NodeCodecQuadTreeHalfFloat.h:55
HalfFloat mBoundsMinZ[4]
Definition NodeCodecQuadTreeHalfFloat.h:52
uint32 mNodeProperties[4]
4 child node properties
Definition NodeCodecQuadTreeHalfFloat.h:56
HalfFloat mBoundsMinX[4]
4 child bounding boxes
Definition NodeCodecQuadTreeHalfFloat.h:50