Ignition Math

API Reference

4.0.0
OrientedBox.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 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_ORIENTEDBOX_HH_
18 #define IGNITION_MATH_ORIENTEDBOX_HH_
19 
20 #include <iostream>
21 #include <ignition/math/Helpers.hh>
22 #include <ignition/math/Matrix4.hh>
23 #include <ignition/math/Pose3.hh>
24 #include <ignition/math/Vector3.hh>
25 #include <ignition/math/config.hh>
26 
27 namespace ignition
28 {
29  namespace math
30  {
31  // Inline bracket to help doxygen filtering.
32  inline namespace IGNITION_MATH_VERSION_NAMESPACE {
33  //
36  template<typename T>
38  {
40  public: OrientedBox() : size(Vector3<T>::Zero), pose(Pose3<T>::Zero)
41  {
42  }
43 
48  public: OrientedBox(const Vector3<T> &_size, const Pose3<T> &_pose)
49  : size(_size), pose(_pose)
50  {
51  // Enforce non-negative size
52  this->size = this->size.Abs();
53  }
54 
58  public: explicit OrientedBox(const Vector3<T> &_size)
59  : size(_size), pose(Pose3<T>::Zero)
60  {
61  // Enforce non-negative size
62  this->size = this->size.Abs();
63  }
64 
67  public: OrientedBox(const OrientedBox<T> &_b)
68  : size(_b.size), pose(_b.pose)
69  {
70  }
71 
73  public: virtual ~OrientedBox()
74  {
75  }
76 
79  public: T XLength() const
80  {
81  return this->size.X();
82  }
83 
86  public: T YLength() const
87  {
88  return this->size.Y();
89  }
90 
93  public: T ZLength() const
94  {
95  return this->size.Z();
96  }
97 
100  public: const Vector3<T> &Size() const
101  {
102  return this->size;
103  }
104 
107  public: const Pose3<T> &Pose() const
108  {
109  return this->pose;
110  }
111 
115  public: void Size(Vector3<T> &_size)
116  {
117  // Enforce non-negative size
118  this->size = _size.Abs();
119  }
120 
123  public: void Pose(Pose3<T> &_pose)
124  {
125  this->pose = _pose;
126  }
127 
132  {
133  this->size = _b.size;
134  this->pose = _b.pose;
135  return *this;
136  }
137 
141  public: bool operator==(const OrientedBox<T> &_b) const
142  {
143  return this->size == _b.size && this->pose == _b.pose;
144  }
145 
149  public: bool operator!=(const OrientedBox<T> &_b) const
150  {
151  return this->size != _b.size || this->pose != _b.pose;
152  }
153 
158  public: friend std::ostream &operator<<(std::ostream &_out,
159  const OrientedBox<T> &_b)
160  {
161  _out << "Size[" << _b.Size() << "] Pose[" << _b.Pose() << "]";
162  return _out;
163  }
164 
168  public: bool Contains(const Vector3d &_p) const
169  {
170  // Move point to box frame
171  auto t = Matrix4<T>(this->pose).Inverse();
172  auto p = t *_p;
173 
174  return p.X() >= -this->size.X()*0.5 && p.X() <= this->size.X()*0.5 &&
175  p.Y() >= -this->size.Y()*0.5 && p.Y() <= this->size.Y()*0.5 &&
176  p.Z() >= -this->size.Z()*0.5 && p.Z() <= this->size.Z()*0.5;
177  }
178 
180  private: Vector3<T> size;
181 
183  private: Pose3<T> pose;
184  };
185 
189  }
190  }
191 }
192 #endif
OrientedBox< float > OrientedBoxf
Definition: OrientedBox.hh:188
OrientedBox(const Vector3< T > &_size, const Pose3< T > &_pose)
Constructor which takes size and pose.
Definition: OrientedBox.hh:48
OrientedBox & operator=(const OrientedBox< T > &_b)
Assignment operator. Set this box to the parameter.
Definition: OrientedBox.hh:131
const Pose3< T > & Pose() const
Get the box pose, which is the pose of its center.
Definition: OrientedBox.hh:107
OrientedBox< double > OrientedBoxd
Definition: OrientedBox.hh:187
bool Contains(const Vector3d &_p) const
Check if a point lies inside the box.
Definition: OrientedBox.hh:168
Encapsulates a position and rotation in three space.
Definition: Pose3.hh:34
A 4x4 matrix class.
Definition: Matrix4.hh:37
bool operator==(const OrientedBox< T > &_b) const
Equality test operator.
Definition: OrientedBox.hh:141
T X() const
Get the x value.
Definition: Vector3.hh:648
OrientedBox(const Vector3< T > &_size)
Constructor which takes only the size.
Definition: OrientedBox.hh:58
void Size(Vector3< T > &_size)
Set the box size.
Definition: OrientedBox.hh:115
Vector3 Abs() const
Get the absolute value of the vector.
Definition: Vector3.hh:223
OrientedBox(const OrientedBox< T > &_b)
Copy constructor.
Definition: OrientedBox.hh:67
T YLength() const
Get the length along the y dimension.
Definition: OrientedBox.hh:86
friend std::ostream & operator<<(std::ostream &_out, const OrientedBox< T > &_b)
Output operator.
Definition: OrientedBox.hh:158
void Pose(Pose3< T > &_pose)
Set the box pose.
Definition: OrientedBox.hh:123
The Vector3 class represents the generic vector containing 3 elements. Since it&#39;s commonly used to ke...
Definition: Vector3.hh:40
bool operator!=(const OrientedBox< T > &_b) const
Inequality test operator.
Definition: OrientedBox.hh:149
Mathematical representation of a box which can be arbitrarily positioned and rotated.
Definition: OrientedBox.hh:37
OrientedBox()
Default constructor.
Definition: OrientedBox.hh:40
Definition: Angle.hh:39
OrientedBox< int > OrientedBoxi
Definition: OrientedBox.hh:186
STL class.
const Vector3< T > & Size() const
Get the size of the box.
Definition: OrientedBox.hh:100
T ZLength() const
Get the length along the z dimension.
Definition: OrientedBox.hh:93
virtual ~OrientedBox()
Destructor.
Definition: OrientedBox.hh:73
T XLength() const
Get the length along the x dimension.
Definition: OrientedBox.hh:79