vector4.cpp
Go to the documentation of this file.
00001 // HOG-Man - Hierarchical Optimization for Pose Graphs on Manifolds
00002 // Copyright (C) 2010 G. Grisetti, R. Kümmerle, C. Stachniss
00003 //
00004 // This file is part of HOG-Man.
00005 // 
00006 // HOG-Man is free software: you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation, either version 3 of the License, or
00009 // (at your option) any later version.
00010 // 
00011 // HOG-Man is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 // 
00016 // You should have received a copy of the GNU General Public License
00017 // along with HOG-Man.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 #include "vector4.h"
00020 
00021 #include <cmath>
00022 #include <cstdlib>
00023 #include <cstring>
00024 using namespace std;
00025 
00026 namespace vrml {
00027 
00028 Vector4::Vector4()
00029 {
00030   memset(_data, 0, 4*sizeof(double));
00031 }
00032 
00033 Vector4::~Vector4()
00034 {
00035 }
00036 
00037 Vector4::Vector4(const Vector4& other)
00038 {
00039   copy(other);
00040 }
00041 
00042 void Vector4::copy(const Vector4& other)
00043 {
00044   memcpy(_data, other._data, 4*sizeof(double));
00045 }
00046 
00047 Vector4::Vector4(const double* data)
00048 {
00049   memcpy(_data, data, 4*sizeof(double));
00050 }
00051 
00052 Vector4& Vector4::operator=(const Vector4& other)
00053 {
00054   if (this != &other) {
00055     copy(other);
00056   }
00057   return *this;
00058 }
00059 
00060 bool Vector4::operator== (const Vector4& other) const
00061 {
00062   if ((fabs(_data[0] - other[0]) < 1e-12) &&
00063       (fabs(_data[1] - other[1]) < 1e-12) &&
00064       (fabs(_data[2] - other[2]) < 1e-12) &&
00065       (fabs(_data[3] - other[3]) < 1e-12))
00066     return true;
00067   return false;
00068 }
00069 
00070 bool Vector4::operator!= (const Vector4& other) const
00071 {
00072   return !(*this == other);
00073 }
00074 
00075 Vector4 Vector4::operator+ (const Vector4& other) const
00076 {
00077   Vector4 sum(other);
00078   for (unsigned int i = 0; i < 4; ++i)
00079     sum[i] += _data[i];
00080   return sum;
00081 }
00082 
00083 Vector4 Vector4::operator- (const Vector4& other) const
00084 {
00085   Vector4 diff(*this);
00086   for (unsigned int i = 0; i < 4; ++i)
00087     diff[i] -= other[i];
00088   return diff;
00089 }
00090 
00091 Vector4 Vector4::operator* (double x) const
00092 {
00093   Vector4 prod(*this);
00094   for (unsigned int i = 0; i < 4; ++i)
00095     prod[i] *= x;
00096   return prod;
00097 }
00098 
00099 Vector4 Vector4::operator/ (double x) const
00100 {
00101   Vector4 quot(*this);
00102   for (unsigned int i = 0; i < 4; ++i)
00103     quot[i] /= x;
00104   return quot;
00105 }
00106 
00107 Vector4 Vector4::operator- () const
00108 {
00109   Vector4 minus(*this);
00110   for (unsigned int i = 0; i < 4; ++i)
00111     minus[i] *= -1.0;
00112   return minus;
00113 }
00114 
00115 Vector4& Vector4::operator+= (const Vector4& other)
00116 {
00117   *this = *this + other;
00118   return *this;
00119 }
00120 
00121 Vector4& Vector4::operator-= (const Vector4& other)
00122 {
00123   *this = *this - other;
00124   return *this;
00125 }
00126 
00127 Vector4& Vector4::operator*= (double x)
00128 {
00129   *this = *this * x;
00130   return *this;
00131 }
00132 
00133 Vector4& Vector4::operator/= (double x)
00134 {
00135   *this = *this / x;
00136   return *this;
00137 }
00138 
00139 Vector4 operator* (double x, const Vector4& v)
00140 {
00141   return v * x;
00142 }
00143 
00144 Vector4 operator/ (double x, const Vector4& v)
00145 {
00146   Vector4 out;
00147   for (unsigned int i = 0; i < 4; ++i)
00148     out[i] = x / v[i];
00149   return out;
00150 }
00151 
00152 std::ostream& operator<<(std::ostream& os, const Vector4& v)
00153 {
00154   os << v[0] << " " << v[1] << " " << v[2] << " " << v[3];
00155   return os;
00156 }
00157 
00158 Vector4::Vector4(double d1, double d2, double d3, double d4)
00159 {
00160   _data[0] = d1;
00161   _data[1] = d2;
00162   _data[2] = d3;
00163   _data[3] = d4;
00164 }
00165 
00166 }


hogman_minimal
Author(s): Maintained by Juergen Sturm
autogenerated on Mon Oct 6 2014 00:06:59