Pose.hh
00001 /*
00002  * Copyright 2011 Nate Koenig & Andrew Howard
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *
00016 */
00017 /* Desc: External interfaces for Gazebo
00018  * Author: Nate Koenig
00019  * Date: 03 Apr 2007
00020  */
00021 
00022 #ifndef POSE_HH
00023 #define POSE_HH
00024 
00025 #include <iostream>
00026 
00027 #include "math/Vector3.hh"
00028 #include "math/Quaternion.hh"
00029 
00030 namespace gazebo
00031 {
00032     namespace math
00033   {
00036     
00038     class Pose
00039     {
00041       public: Pose();
00042     
00046       public: Pose(const Vector3 &pos, const Quaternion &rot);
00047     
00050       public: Pose( const Pose &pose );
00051     
00053       public: virtual ~Pose();
00054 
00055       public: void Set(const Vector3 &_pos, const Quaternion &_rot);
00056 
00058       public: bool IsFinite() const;
00059     
00061       public: inline void Correct()
00062               {  this->pos.Correct(); this->rot.Correct(); }
00063 
00064     
00066       public: Pose GetInverse() const;
00067     
00071       public: Pose operator+(const Pose &pose) const;
00072     
00076       public: const Pose &operator+=(const Pose &pose);
00077     
00081       public: inline Pose operator-(const Pose &_pose) const
00082               {
00083                 return Pose(this->CoordPositionSub(_pose), 
00084                             this->CoordRotationSub(_pose.rot));
00085               }
00086 
00090       public: const Pose &operator-=(const Pose &_pose);
00091 
00095       public: bool operator==(const Pose &_pose) const;
00096 
00100       public: bool operator!=(const Pose &_pose) const;
00101     
00103       public: Pose operator*(const Pose &pose);
00104               
00108       public: Vector3 CoordPositionAdd(const Vector3 &pos) const;
00109     
00113       public: Vector3 CoordPositionAdd(const Pose &pose) const;
00114     
00118       public: inline Vector3 CoordPositionSub(const Pose &_pose) const
00119               {
00120                 Quaternion tmp( 0.0,
00121                     this->pos.x - _pose.pos.x,
00122                     this->pos.y - _pose.pos.y,
00123                     this->pos.z - _pose.pos.z);
00124 
00125                 tmp = _pose.rot.GetInverse() * (tmp * _pose.rot);
00126                 return Vector3(tmp.x, tmp.y, tmp.z);
00127               }
00128     
00132       public: Quaternion CoordRotationAdd(const Quaternion &rot) const;
00133     
00137       public: inline Quaternion CoordRotationSub(const Quaternion &rot) const
00138               {
00139                 Quaternion result(rot.GetInverse() * this->rot);
00140                 result.Normalize();
00141                 return result;
00142               }
00143 
00144     
00147       public: Pose CoordPoseSolve(const Pose &b) const;
00148     
00150       public: void Reset();
00151     
00153       public: Pose RotatePositionAboutOrigin(const Quaternion &rot) const;
00154 
00156       public: void Round(int _precision);
00157     
00159       public: Vector3 pos;
00160     
00162       public: Quaternion rot;
00163     
00168       public: friend std::ostream &operator<<(std::ostream &out, 
00169                                               const gazebo::math::Pose &pose)
00170               {
00171                 out << pose.pos << " " << pose.rot;
00172                 return out;
00173               }
00174 
00175     public: friend std::istream &operator>>( std::istream &in, 
00176                 gazebo::math::Pose &pose )
00177             {
00178               // Skip white spaces
00179               in.setf( std::ios_base::skipws );
00180               in >> pose.pos >> pose.rot;
00181               return in;
00182             }
00183     };
00184     
00186   }
00187 
00188 }
00189 #endif
00190