CGI/exercise4/include/Box.h

80 lines
2.5 KiB
C
Raw Normal View History

2019-01-24 14:38:18 +00:00
// This source code is property of the Computer Graphics and Visualization
// chair of the TU Dresden. Do not distribute!
2018-09-06 12:35:43 +00:00
// Copyright (C) CGV TU Dresden - All Rights Reserved
#pragma once
#include <Eigen/Core>
class Box
{
//internal storage for lower and upper corner points of the box
std::pair<Eigen::Vector3f, Eigen::Vector3f> bounds;
2019-01-24 14:38:18 +00:00
public:
2018-09-06 12:35:43 +00:00
//creates an empty box like the method Clear
Box();
//construct a box with the gven lower and upper corner points
2019-01-24 14:38:18 +00:00
Box(const Eigen::Vector3f &lbound, const Eigen::Vector3f &ubound);
2018-09-06 12:35:43 +00:00
//returns the corner point which is the lower bound of the box in all dimensions
2019-01-24 14:38:18 +00:00
Eigen::Vector3f &LowerBound();
2018-09-06 12:35:43 +00:00
//returns the corner point which is the lower bound of the box in all dimensions
2019-01-24 14:38:18 +00:00
const Eigen::Vector3f &LowerBound() const;
2018-09-06 12:35:43 +00:00
//returns the corner point which is the upper bound of the box in all dimensions
2019-01-24 14:38:18 +00:00
Eigen::Vector3f &UpperBound();
2018-09-06 12:35:43 +00:00
//returns the corner point which is the upper bound of the box in all dimensions
2019-01-24 14:38:18 +00:00
const Eigen::Vector3f &UpperBound() const;
2018-09-06 12:35:43 +00:00
//returns a vector containing the extents of the box in all dimensions
Eigen::Vector3f Extents() const;
//returns a vector containing the extents of the box in all dimensions divided by 2
Eigen::Vector3f HalfExtents() const;
//returns the center of the box
Eigen::Vector3f Center() const;
//returns the surface area of the box
float SurfaceArea() const;
//returns the volume of the box
float Volume() const;
2019-01-24 14:38:18 +00:00
//returns the box radius for a given direction vector a
//if the box is centered at the origin
2018-09-06 12:35:43 +00:00
//then the projection of the box on direction a is contained within the Interval [-r,r]
2019-01-24 14:38:18 +00:00
float Radius(const Eigen::Vector3f &a) const;
2018-09-06 12:35:43 +00:00
//returns true if the box b overlaps with the current one
2019-01-24 14:38:18 +00:00
bool Overlaps(const Box &b) const;
2018-09-06 12:35:43 +00:00
//returns true if the point p is inside this box
2019-01-24 14:38:18 +00:00
bool IsInside(const Eigen::Vector3f &p) const;
2018-09-06 12:35:43 +00:00
//returns true if box b is inside this box
2019-01-24 14:38:18 +00:00
bool IsInside(const Box &b) const;
2018-09-06 12:35:43 +00:00
//creates a box which goes from [+infinity,- infinity] in al dimensions
void Clear();
2019-01-24 14:38:18 +00:00
2018-09-06 12:35:43 +00:00
//enlarges the box such that the point p is inside afterwards
2019-01-24 14:38:18 +00:00
void Insert(const Eigen::Vector3f &p);
2018-09-06 12:35:43 +00:00
//enlarges the box such that box b is inside afterwards
2019-01-24 14:38:18 +00:00
void Insert(const Box &b);
2018-09-06 12:35:43 +00:00
2019-01-24 14:38:18 +00:00
//returns the point on or inside the box with the smallest distance to p
Eigen::Vector3f ClosestPoint(const Eigen::Vector3f &p) const;
2018-09-06 12:35:43 +00:00
2019-01-24 14:38:18 +00:00
//returns the squared distance between p and the box
float SqrDistance(const Eigen::Vector3f &p) const;
2018-09-06 12:35:43 +00:00
2019-01-24 14:38:18 +00:00
//returns the euclidean distance between p and the box
float Distance(const Eigen::Vector3f &p) const;
2018-09-06 12:35:43 +00:00
};