Path: blob/master/thirdparty/embree/kernels/builders/primref_mb.h
9912 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include "../common/default.h"67#define MBLUR_BIN_LBBOX 189namespace embree10{11#if MBLUR_BIN_LBBOX1213/*! A primitive reference stores the bounds of the primitive and its ID. */14struct PrimRefMB15{16typedef LBBox3fa BBox;1718__forceinline PrimRefMB () {}1920__forceinline PrimRefMB (const LBBox3fa& lbounds_i, unsigned int activeTimeSegments, BBox1f time_range, unsigned int totalTimeSegments, unsigned int geomID, unsigned int primID)21: lbounds((LBBox3fx)lbounds_i), time_range(time_range)22{23assert(activeTimeSegments > 0);24lbounds.bounds0.lower.a = geomID;25lbounds.bounds0.upper.a = primID;26lbounds.bounds1.lower.a = activeTimeSegments;27lbounds.bounds1.upper.a = totalTimeSegments;28}2930__forceinline PrimRefMB (EmptyTy empty, const LBBox3fa& lbounds_i, unsigned int activeTimeSegments, BBox1f time_range, unsigned int totalTimeSegments, size_t id)31: lbounds((LBBox3fx)lbounds_i), time_range(time_range)32{33assert(activeTimeSegments > 0);34#if defined(__64BIT__)35lbounds.bounds0.lower.a = id & 0xFFFFFFFF;36lbounds.bounds0.upper.a = (id >> 32) & 0xFFFFFFFF;37#else38lbounds.bounds0.lower.a = id;39lbounds.bounds0.upper.a = 0;40#endif41lbounds.bounds1.lower.a = activeTimeSegments;42lbounds.bounds1.upper.a = totalTimeSegments;43}4445__forceinline PrimRefMB (const LBBox3fa& lbounds_i, unsigned int activeTimeSegments, BBox1f time_range, unsigned int totalTimeSegments, size_t id)46: lbounds((LBBox3fx)lbounds_i), time_range(time_range)47{48assert(activeTimeSegments > 0);49#if defined(__64BIT__)50lbounds.bounds0.lower.u = id & 0xFFFFFFFF;51lbounds.bounds0.upper.u = (id >> 32) & 0xFFFFFFFF;52#else53lbounds.bounds0.lower.u = id;54lbounds.bounds0.upper.u = 0;55#endif56lbounds.bounds1.lower.a = activeTimeSegments;57lbounds.bounds1.upper.a = totalTimeSegments;58}5960/*! returns bounds for binning */61__forceinline LBBox3fa bounds() const {62return lbounds;63}6465/*! returns the number of time segments of this primref */66__forceinline unsigned size() const {67return lbounds.bounds1.lower.a;68}6970__forceinline unsigned totalTimeSegments() const {71return lbounds.bounds1.upper.a;72}7374/* calculate overlapping time segment range */75__forceinline range<int> timeSegmentRange(const BBox1f& range) const {76return getTimeSegmentRange(range,time_range,float(totalTimeSegments()));77}7879/* returns time that corresponds to time step */80__forceinline float timeStep(const int i) const {81assert(i>=0 && i<=(int)totalTimeSegments());82return time_range.lower + time_range.size()*float(i)/float(totalTimeSegments());83}8485/*! checks if time range overlaps */86__forceinline bool time_range_overlap(const BBox1f& range) const87{88if (0.9999f*time_range.upper <= range.lower) return false;89if (1.0001f*time_range.lower >= range.upper) return false;90return true;91}9293/*! returns center for binning */94__forceinline Vec3fa binCenter() const {95return center2(lbounds.interpolate(0.5f));96}9798/*! returns bounds and centroid used for binning */99__forceinline void binBoundsAndCenter(LBBox3fa& bounds_o, Vec3fa& center_o) const100{101bounds_o = bounds();102center_o = binCenter();103}104105/*! returns the geometry ID */106__forceinline unsigned geomID() const {107return lbounds.bounds0.lower.a;108}109110/*! returns the primitive ID */111__forceinline unsigned primID() const {112return lbounds.bounds0.upper.a;113}114115/*! returns an size_t sized ID */116__forceinline size_t ID() const {117#if defined(__64BIT__)118return size_t(lbounds.bounds0.lower.u) + (size_t(lbounds.bounds0.upper.u) << 32);119#else120return size_t(lbounds.bounds0.lower.u);121#endif122}123124/*! special function for operator< */125__forceinline uint64_t ID64() const {126return (((uint64_t)primID()) << 32) + (uint64_t)geomID();127}128129/*! allows sorting the primrefs by ID */130friend __forceinline bool operator<(const PrimRefMB& p0, const PrimRefMB& p1) {131return p0.ID64() < p1.ID64();132}133134/*! Outputs primitive reference to a stream. */135friend __forceinline embree_ostream operator<<(embree_ostream cout, const PrimRefMB& ref) {136return cout << "{ time_range = " << ref.time_range << ", bounds = " << ref.bounds() << ", geomID = " << ref.geomID() << ", primID = " << ref.primID() << ", active_segments = " << ref.size() << ", total_segments = " << ref.totalTimeSegments() << " }";137}138139public:140LBBox3fx lbounds;141BBox1f time_range; // entire geometry time range142};143144#else145146/*! A primitive reference stores the bounds of the primitive and its ID. */147struct __aligned(16) PrimRefMB148{149typedef BBox3fa BBox;150151__forceinline PrimRefMB () {}152153__forceinline PrimRefMB (const LBBox3fa& bounds, unsigned int activeTimeSegments, BBox1f time_range, unsigned int totalTimeSegments, unsigned int geomID, unsigned int primID)154: bbox(bounds.interpolate(0.5f)), _activeTimeSegments(activeTimeSegments), _totalTimeSegments(totalTimeSegments), time_range(time_range)155{156assert(activeTimeSegments > 0);157bbox.lower.a = geomID;158bbox.upper.a = primID;159}160161__forceinline PrimRefMB (EmptyTy empty, const LBBox3fa& bounds, unsigned int activeTimeSegments, BBox1f time_range, unsigned int totalTimeSegments, size_t id)162: bbox(bounds.interpolate(0.5f)), _activeTimeSegments(activeTimeSegments), _totalTimeSegments(totalTimeSegments), time_range(time_range)163{164assert(activeTimeSegments > 0);165#if defined(__64BIT__)166bbox.lower.u = id & 0xFFFFFFFF;167bbox.upper.u = (id >> 32) & 0xFFFFFFFF;168#else169bbox.lower.u = id;170bbox.upper.u = 0;171#endif172}173174/*! returns bounds for binning */175__forceinline BBox3fa bounds() const {176return bbox;177}178179/*! returns the number of time segments of this primref */180__forceinline unsigned int size() const {181return _activeTimeSegments;182}183184__forceinline unsigned int totalTimeSegments() const {185return _totalTimeSegments;186}187188/* calculate overlapping time segment range */189__forceinline range<int> timeSegmentRange(const BBox1f& range) const {190return getTimeSegmentRange(range,time_range,float(_totalTimeSegments));191}192193/* returns time that corresponds to time step */194__forceinline float timeStep(const int i) const {195assert(i>=0 && i<=(int)_totalTimeSegments);196return time_range.lower + time_range.size()*float(i)/float(_totalTimeSegments);197}198199/*! checks if time range overlaps */200__forceinline bool time_range_overlap(const BBox1f& range) const201{202if (0.9999f*time_range.upper <= range.lower) return false;203if (1.0001f*time_range.lower >= range.upper) return false;204return true;205}206207/*! returns center for binning */208__forceinline Vec3fa binCenter() const {209return center2(bounds());210}211212/*! returns bounds and centroid used for binning */213__forceinline void binBoundsAndCenter(BBox3fa& bounds_o, Vec3fa& center_o) const214{215bounds_o = bounds();216center_o = center2(bounds());217}218219/*! returns the geometry ID */220__forceinline unsigned int geomID() const {221return bbox.lower.a;222}223224/*! returns the primitive ID */225__forceinline unsigned int primID() const {226return bbox.upper.a;227}228229/*! returns an size_t sized ID */230__forceinline size_t ID() const {231#if defined(__64BIT__)232return size_t(bbox.lower.u) + (size_t(bbox.upper.u) << 32);233#else234return size_t(bbox.lower.u);235#endif236}237238/*! special function for operator< */239__forceinline uint64_t ID64() const {240return (((uint64_t)primID()) << 32) + (uint64_t)geomID();241}242243/*! allows sorting the primrefs by ID */244friend __forceinline bool operator<(const PrimRefMB& p0, const PrimRefMB& p1) {245return p0.ID64() < p1.ID64();246}247248/*! Outputs primitive reference to a stream. */249friend __forceinline embree_ostream operator<<(embree_ostream cout, const PrimRefMB& ref) {250return cout << "{ bounds = " << ref.bounds() << ", geomID = " << ref.geomID() << ", primID = " << ref.primID() << ", active_segments = " << ref.size() << ", total_segments = " << ref.totalTimeSegments() << " }";251}252253public:254BBox3fa bbox; // bounds, geomID, primID255unsigned int _activeTimeSegments;256unsigned int _totalTimeSegments;257BBox1f time_range; // entire geometry time range258};259260#endif261}262263264