Path: blob/master/thirdparty/embree/kernels/common/point_query.h
9905 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include "default.h"67namespace embree8{9/* Point query structure for closest point query */10template<int K>11struct RTC_ALIGN(16) PointQueryK12{13/* Default construction does nothing */14__forceinline PointQueryK() {}1516/* Constructs a ray from origin, direction, and ray segment. Near17* has to be smaller than far */18__forceinline PointQueryK(const Vec3vf<K>& p, const vfloat<K>& radius = inf, const vfloat<K>& time = zero)19: p(p), time(time), radius(radius) {}2021/* Returns the size of the ray */22static __forceinline size_t size() { return K; }2324/* Calculates if this is a valid ray that does not cause issues during traversal */25__forceinline vbool<K> valid() const26{27const vbool<K> vx = (abs(p.x) <= vfloat<K>(FLT_LARGE));28const vbool<K> vy = (abs(p.y) <= vfloat<K>(FLT_LARGE));29const vbool<K> vz = (abs(p.z) <= vfloat<K>(FLT_LARGE));30const vbool<K> vn = radius >= vfloat<K>(0);31const vbool<K> vf = abs(time) < vfloat<K>(inf);32return vx & vy & vz & vn & vf;33}3435__forceinline void get(PointQueryK<1>* ray) const;36__forceinline void get(size_t i, PointQueryK<1>& ray) const;37__forceinline void set(const PointQueryK<1>* ray);38__forceinline void set(size_t i, const PointQueryK<1>& ray);3940Vec3vf<K> p; // location of the query point41vfloat<K> time; // time for motion blur42vfloat<K> radius; // radius for the point query43};4445/* Specialization for a single point query */46template<>47struct RTC_ALIGN(16) PointQueryK<1>48{49/* Default construction does nothing */50__forceinline PointQueryK() {}5152/* Constructs a ray from origin, direction, and ray segment. Near53* has to be smaller than far */54__forceinline PointQueryK(const Vec3fa& p, float radius = inf, float time = zero)55: p(p), time(time), radius(radius) {}5657/* Calculates if this is a valid ray that does not cause issues during traversal */58__forceinline bool valid() const {59return all(le_mask(abs(Vec3fa(p)), Vec3fa(FLT_LARGE)) & le_mask(Vec3fa(0.f), Vec3fa(radius))) && abs(time) < float(inf);60}6162Vec3f p;63float time;64float radius;65};6667/* Converts point query packet to single point query */68template<int K>69__forceinline void PointQueryK<K>::get(PointQueryK<1>* query) const70{71for (size_t i = 0; i < K; i++) // FIXME: use SIMD transpose72{73query[i].p.x = p.x[i];74query[i].p.y = p.y[i];75query[i].p.z = p.z[i];76query[i].time = time[i];77query[i].radius = radius[i];78}79}8081/* Extracts a single point query out of a point query packet*/82template<int K>83__forceinline void PointQueryK<K>::get(size_t i, PointQueryK<1>& query) const84{85query.p.x = p.x[i];86query.p.y = p.y[i];87query.p.z = p.z[i];88query.radius = radius[i];89query.time = time[i];90}9192/* Converts single point query to point query packet */93template<int K>94__forceinline void PointQueryK<K>::set(const PointQueryK<1>* query)95{96for (size_t i = 0; i < K; i++)97{98p.x[i] = query[i].p.x;99p.y[i] = query[i].p.y;100p.z[i] = query[i].p.z;101radius[i] = query[i].radius;102time[i] = query[i].time;103}104}105106/* inserts a single point query into a point query packet element */107template<int K>108__forceinline void PointQueryK<K>::set(size_t i, const PointQueryK<1>& query)109{110p.x[i] = query.p.x;111p.y[i] = query.p.y;112p.z[i] = query.p.z;113radius[i] = query.radius;114time[i] = query.time;115}116117/* Shortcuts */118typedef PointQueryK<1> PointQuery;119typedef PointQueryK<4> PointQuery4;120typedef PointQueryK<8> PointQuery8;121typedef PointQueryK<16> PointQuery16;122typedef PointQueryK<VSIZEX> PointQueryx;123struct PointQueryN;124125/* Outputs point query to stream */126template<int K>127__forceinline embree_ostream operator <<(embree_ostream cout, const PointQueryK<K>& query)128{129cout << "{ " << embree_endl130<< " p = " << query.p << embree_endl131<< " r = " << query.radius << embree_endl132<< " time = " << query.time << embree_endl133<< "}";134return cout;135}136}137138139