Path: blob/master/thirdparty/embree/kernels/builders/priminfo.h
9912 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include "primref.h"67namespace embree8{9// FIXME: maybe there's a better place for this util fct10__forceinline float areaProjectedTriangle(const Vec3fa& v0, const Vec3fa& v1, const Vec3fa& v2)11{12const Vec3fa e0 = v1-v0;13const Vec3fa e1 = v2-v0;14const Vec3fa d = cross(e0,e1);15return fabs(d.x) + fabs(d.y) + fabs(d.z);16}1718//namespace isa19//{20template<typename BBox>21class CentGeom22{23public:24__forceinline CentGeom () {}2526__forceinline CentGeom (EmptyTy)27: geomBounds(empty), centBounds(empty) {}2829__forceinline CentGeom (const BBox& geomBounds, const BBox3fa& centBounds)30: geomBounds(geomBounds), centBounds(centBounds) {}3132template<typename PrimRef>33__forceinline void extend_primref(const PrimRef& prim)34{35BBox bounds; Vec3fa center;36prim.binBoundsAndCenter(bounds,center);37geomBounds.extend(bounds);38centBounds.extend(center);39}4041static void extend_ref (CentGeom& pinfo, const PrimRef& ref) {42pinfo.extend_primref(ref);43};4445template<typename PrimRef>46__forceinline void extend_center2(const PrimRef& prim)47{48BBox3fa bounds = prim.bounds();49geomBounds.extend(bounds);50centBounds.extend(bounds.center2());51}5253__forceinline void extend(const BBox& geomBounds_) {54geomBounds.extend(geomBounds_);55centBounds.extend(center2(geomBounds_));56}5758__forceinline void merge(const CentGeom& other)59{60geomBounds.extend(other.geomBounds);61centBounds.extend(other.centBounds);62}6364static __forceinline const CentGeom merge2(const CentGeom& a, const CentGeom& b) {65CentGeom r = a; r.merge(b); return r;66}6768public:69BBox geomBounds; //!< geometry bounds of primitives70BBox3fa centBounds; //!< centroid bounds of primitives71};7273typedef CentGeom<BBox3fa> CentGeomBBox3fa;7475/*! stores bounding information for a set of primitives */76template<typename BBox>77class PrimInfoT : public CentGeom<BBox>78{79public:80using CentGeom<BBox>::geomBounds;81using CentGeom<BBox>::centBounds;8283__forceinline PrimInfoT () {}8485__forceinline PrimInfoT (EmptyTy)86: CentGeom<BBox>(empty), begin(0), end(0) {}8788__forceinline PrimInfoT (size_t N)89: CentGeom<BBox>(empty), begin(0), end(N) {}9091__forceinline PrimInfoT (size_t begin, size_t end, const CentGeomBBox3fa& centGeomBounds)92: CentGeom<BBox>(centGeomBounds), begin(begin), end(end) {}9394template<typename PrimRef>95__forceinline void add_primref(const PrimRef& prim)96{97CentGeom<BBox>::extend_primref(prim);98end++;99}100101template<typename PrimRef>102__forceinline void add_center2(const PrimRef& prim) {103CentGeom<BBox>::extend_center2(prim);104end++;105}106107template<typename PrimRef>108__forceinline void add_center2(const PrimRef& prim, const size_t i) {109CentGeom<BBox>::extend_center2(prim);110end+=i;111}112113/*__forceinline void add(const BBox& geomBounds_) {114CentGeom<BBox>::extend(geomBounds_);115end++;116}117118__forceinline void add(const BBox& geomBounds_, const size_t i) {119CentGeom<BBox>::extend(geomBounds_);120end+=i;121}*/122123__forceinline void merge(const PrimInfoT& other)124{125CentGeom<BBox>::merge(other);126begin += other.begin;127end += other.end;128}129130static __forceinline const PrimInfoT merge(const PrimInfoT& a, const PrimInfoT& b) {131PrimInfoT r = a; r.merge(b); return r;132}133134/*! returns the number of primitives */135__forceinline size_t size() const {136return end-begin;137}138139__forceinline float halfArea() {140return expectedApproxHalfArea(geomBounds);141}142143__forceinline float leafSAH() const {144return expectedApproxHalfArea(geomBounds)*float(size());145//return halfArea(geomBounds)*blocks(num);146}147148__forceinline float leafSAH(size_t block_shift) const {149return expectedApproxHalfArea(geomBounds)*float((size()+(size_t(1)<<block_shift)-1) >> block_shift);150//return halfArea(geomBounds)*float((num+3) >> 2);151//return halfArea(geomBounds)*blocks(num);152}153154/*! stream output */155friend embree_ostream operator<<(embree_ostream cout, const PrimInfoT& pinfo) {156return cout << "PrimInfo { begin = " << pinfo.begin << ", end = " << pinfo.end << ", geomBounds = " << pinfo.geomBounds << ", centBounds = " << pinfo.centBounds << "}";157}158159public:160size_t begin,end; //!< number of primitives161};162163typedef PrimInfoT<BBox3fa> PrimInfo;164//typedef PrimInfoT<LBBox3fa> PrimInfoMB;165//}166}167168169