aabb3.h 1.19 KB
#ifndef STIM_AABB3_H
#define STIM_AABB3_H

#include <stim/cuda/cudatools/callable.h>

namespace stim{

/// Structure for a 3D axis aligned bounding box
template<typename T>
struct aabb3{


	T low[3];						//top left corner position
	T high[3];							//dimensions along x and y and z


	CUDA_CALLABLE aabb3(T x, T y, T z){					//initialize an axis aligned bounding box of size 0 at the given position
		low[0] = high[0] = x;					//set the position to the user specified coordinates
		low[1] = high[1] = y;
		low[2] = high[2] = z;

	//insert a point into the bounding box, growing the box appropriately
	CUDA_CALLABLE void insert(T x, T y, T z){
		if(x < low[0]) low[0] = x;
		if(y < low[1]) low[1] = y;
		if(z < low[2]) low[2] = z;

		if(x > high[0]) high[0] = x;		
		if(y > high[1]) high[1] = y;
		if(z > high[2]) high[2] = z;

	//trim the bounding box so that the lower bounds are (x, y, z)
	CUDA_CALLABLE void trim_low(T x, T y, T z){
		if(low[0] < x) low[0] = x;
		if(low[1] < y) low[1] = y;
		if(low[2] < z) low[2] = z;

	CUDA_CALLABLE void trim_high(T x, T y, T z){
		if(high[0] > x) high[0] = x;
		if(high[1] > y) high[1] = y;
		if(high[2] > z) high[2] = z;