Box.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef IGNITION_MATH_BOX_HH_
18 #define IGNITION_MATH_BOX_HH_
19 
20 #include <iostream>
21 #include <tuple>
22 #include <ignition/math/Helpers.hh>
23 #include <ignition/math/Vector3.hh>
24 #include <ignition/math/Line3.hh>
25 #include <ignition/math/config.hh>
26 
27 namespace ignition
28 {
29  namespace math
30  {
31  inline namespace IGNITION_MATH_VERSION_NAMESPACE
32  {
33  // Forward declaration of private data
34  class BoxPrivate;
35 
38  class IGNITION_MATH_VISIBLE Box
39  {
46  public: Box();
47 
52  public: Box(const Vector3d &_vec1, const Vector3d &_vec2);
53 
62  public: Box(double _vec1X, double _vec1Y, double _vec1Z,
63  double _vec2X, double _vec2Y, double _vec2Z);
64 
67  public: Box(const Box &_b);
68 
70  public: virtual ~Box();
71 
74  public: double XLength() const;
75 
78  public: double YLength() const;
79 
82  public: double ZLength() const;
83 
86  public: math::Vector3d Size() const;
87 
90  public: math::Vector3d Center() const;
91 
94  public: void Merge(const Box &_box);
95 
99  public: Box &operator=(const Box &_b);
100 
104  public: Box operator+(const Box &_b) const;
105 
109  public: const Box &operator+=(const Box &_b);
110 
114  public: bool operator==(const Box &_b) const;
115 
119  public: bool operator!=(const Box &_b) const;
120 
124  public: Box operator-(const Vector3d &_v);
125 
130  public: friend std::ostream &operator<<(std::ostream &_out,
131  const ignition::math::Box &_b)
132  {
133  _out << "Min[" << _b.Min() << "] Max[" << _b.Max() << "]";
134  return _out;
135  }
136 
139  public: const Vector3d &Min() const;
140 
143  public: const Vector3d &Max() const;
144 
147  public: Vector3d &Min();
148 
151  public: Vector3d &Max();
152 
158  public: bool Intersects(const Box &_box) const;
159 
163  public: bool Contains(const Vector3d &_p) const;
164 
171  public: bool IntersectCheck(const Vector3d &_origin, const Vector3d &_dir,
172  const double _min, const double _max) const;
173 
189  public: std::tuple<bool, double> IntersectDist(
190  const Vector3d &_origin, const Vector3d &_dir,
191  const double _min, const double _max) const;
192 
210  public: std::tuple<bool, double, Vector3d> Intersect(
211  const Vector3d &_origin, const Vector3d &_dir,
212  const double _min, const double _max) const;
213 
222  public: std::tuple<bool, double, Vector3d> Intersect(
223  const Line3d &_line) const;
224 
231  private: bool ClipLine(const int _d, const Line3d &_line,
232  double &_low, double &_high) const;
233 
235  private: BoxPrivate *dataPtr;
236  };
237  }
238  }
239 }
240 #endif
Helpers.hh
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::Center
math::Vector3d Center() const
Get the box center.
Line3.hh
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::IntersectCheck
bool IntersectCheck(const Vector3d &_origin, const Vector3d &_dir, const double _min, const double _max) const
Check if a ray (origin, direction) intersects the box.
ignition
Definition: Angle.hh:40
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::Merge
void Merge(const Box &_box)
Merge a box with this box.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::operator==
bool operator==(const Box &_b) const
Equality test operator.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::ZLength
double ZLength() const
Get the length along the z dimension.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::operator!=
bool operator!=(const Box &_b) const
Inequality test operator.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::IntersectDist
std::tuple< bool, double > IntersectDist(const Vector3d &_origin, const Vector3d &_dir, const double _min, const double _max) const
Check if a ray (origin, direction) intersects the box.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::YLength
double YLength() const
Get the length along the y dimension.
Vector3.hh
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::Size
math::Vector3d Size() const
Get the size of the box.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::operator-
Box operator-(const Vector3d &_v)
Subtract a vector from the min and max values.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::operator<<
friend std::ostream & operator<<(std::ostream &_out, const ignition::math::Box &_b)
Output operator.
Definition: Box.hh:130
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::Intersect
std::tuple< bool, double, Vector3d > Intersect(const Vector3d &_origin, const Vector3d &_dir, const double _min, const double _max) const
Check if a ray (origin, direction) intersects the box.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::operator=
Box & operator=(const Box &_b)
Assignment operator.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::Box
Box()
Default constructor.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::Contains
bool Contains(const Vector3d &_p) const
Check if a point lies inside the box.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Vector3
The Vector3 class represents the generic vector containing 3 elements. Since it's commonly used to ke...
Definition: Vector3.hh:40
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::Intersect
std::tuple< bool, double, Vector3d > Intersect(const Line3d &_line) const
Check if a line intersects the box.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::XLength
double XLength() const
Get the length along the x dimension.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::Min
const Vector3d & Min() const
Get the minimum corner.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::Box
Box(double _vec1X, double _vec1Y, double _vec1Z, double _vec2X, double _vec2Y, double _vec2Z)
Constructor.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::Box
Box(const Box &_b)
Copy Constructor.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::operator+
Box operator+(const Box &_b) const
Addition operator.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::Max
const Vector3d & Max() const
Get the maximum corner.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box
Mathematical representation of a box and related functions.
Definition: Box.hh:39
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::Intersects
bool Intersects(const Box &_box) const
Test box intersection.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Line3
A three dimensional line segment. The line is defined by a start and end point.
Definition: Line3.hh:35
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::Max
Vector3d & Max()
Get a mutable version of the maximum corner.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::operator+=
const Box & operator+=(const Box &_b)
Addition set operator.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::~Box
virtual ~Box()
Destructor.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::Min
Vector3d & Min()
Get a mutable version of the minimum corner.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::Box::Box
Box(const Vector3d &_vec1, const Vector3d &_vec2)
Constructor.