#pragma once
#include "../common/default.h"
#define MBLUR_BIN_LBBOX …
namespace embree
{
#if MBLUR_BIN_LBBOX
struct PrimRefMB
{ … };
#else
struct __aligned(16) PrimRefMB
{
typedef BBox3fa BBox;
__forceinline PrimRefMB () {}
__forceinline PrimRefMB (const LBBox3fa& bounds, unsigned int activeTimeSegments, BBox1f time_range, unsigned int totalTimeSegments, unsigned int geomID, unsigned int primID)
: bbox(bounds.interpolate(0.5f)), _activeTimeSegments(activeTimeSegments), _totalTimeSegments(totalTimeSegments), time_range(time_range)
{
assert(activeTimeSegments > 0);
bbox.lower.a = geomID;
bbox.upper.a = primID;
}
__forceinline PrimRefMB (EmptyTy empty, const LBBox3fa& bounds, unsigned int activeTimeSegments, BBox1f time_range, unsigned int totalTimeSegments, size_t id)
: bbox(bounds.interpolate(0.5f)), _activeTimeSegments(activeTimeSegments), _totalTimeSegments(totalTimeSegments), time_range(time_range)
{
assert(activeTimeSegments > 0);
#if defined(__64BIT__)
bbox.lower.u = id & 0xFFFFFFFF;
bbox.upper.u = (id >> 32) & 0xFFFFFFFF;
#else
bbox.lower.u = id;
bbox.upper.u = 0;
#endif
}
__forceinline BBox3fa bounds() const {
return bbox;
}
__forceinline unsigned int size() const {
return _activeTimeSegments;
}
__forceinline unsigned int totalTimeSegments() const {
return _totalTimeSegments;
}
__forceinline range<int> timeSegmentRange(const BBox1f& range) const {
return getTimeSegmentRange(range,time_range,float(_totalTimeSegments));
}
__forceinline float timeStep(const int i) const {
assert(i>=0 && i<=(int)_totalTimeSegments);
return time_range.lower + time_range.size()*float(i)/float(_totalTimeSegments);
}
__forceinline bool time_range_overlap(const BBox1f& range) const
{
if (0.9999f*time_range.upper <= range.lower) return false;
if (1.0001f*time_range.lower >= range.upper) return false;
return true;
}
__forceinline Vec3fa binCenter() const {
return center2(bounds());
}
__forceinline void binBoundsAndCenter(BBox3fa& bounds_o, Vec3fa& center_o) const
{
bounds_o = bounds();
center_o = center2(bounds());
}
__forceinline unsigned int geomID() const {
return bbox.lower.a;
}
__forceinline unsigned int primID() const {
return bbox.upper.a;
}
__forceinline size_t ID() const {
#if defined(__64BIT__)
return size_t(bbox.lower.u) + (size_t(bbox.upper.u) << 32);
#else
return size_t(bbox.lower.u);
#endif
}
__forceinline uint64_t ID64() const {
return (((uint64_t)primID()) << 32) + (uint64_t)geomID();
}
friend __forceinline bool operator<(const PrimRefMB& p0, const PrimRefMB& p1) {
return p0.ID64() < p1.ID64();
}
friend __forceinline embree_ostream operator<<(embree_ostream cout, const PrimRefMB& ref) {
return cout << "{ bounds = " << ref.bounds() << ", geomID = " << ref.geomID() << ", primID = " << ref.primID() << ", active_segments = " << ref.size() << ", total_segments = " << ref.totalTimeSegments() << " }";
}
public:
BBox3fa bbox;
unsigned int _activeTimeSegments;
unsigned int _totalTimeSegments;
BBox1f time_range;
};
#endif
}