MC_v4d.hpp

Go to the documentation of this file.
00001 /*
00002 **    Mesh Converter
00003 **    Copyright (C) 2008 Damien Rohmer
00004 **
00005 **    This program is free software: you can redistribute it and/or modify
00006 **    it under the terms of the GNU General Public License as published by
00007 **    the Free Software Foundation, either version 3 of the License, or
00008 **    (at your option) any later version.
00009 **
00010 **   This program is distributed in the hope that it will be useful,
00011 **    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 **    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 **    GNU General Public License for more details.
00014 **
00015 **    You should have received a copy of the GNU General Public License
00016 **    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 
00020 
00021 #ifndef MC_V4D_HPP
00022 #define MC_V4D_HPP
00023 
00024 #include <iostream>
00025 #include <cmath>
00026 
00027 
00028 
00029 
00030 
00031 namespace mesh_conv
00032 {
00033 
00034     class MC_v3d;
00035     class MC_matrix;
00036 
00038 
00040 class MC_v4d
00041 {
00042 public:
00043 
00044     //*********************************************//
00045     //*********************************************//
00046     // CONSTRUCTORS
00047     //*********************************************//
00048     //*********************************************//
00049 
00051     MC_v4d();
00053     MC_v4d(const double& x,const double& y,const double& z,const double& w);
00055     MC_v4d(const MC_v4d& _v);
00059     MC_v4d(const double* _v);
00064     MC_v4d(const std::string& s);
00065 
00067     MC_v4d(const MC_matrix& M);
00068 
00070     MC_v4d(const MC_v3d& vec);
00071 
00073     ~MC_v4d();
00074 
00075 
00076 
00077 
00078     //*********************************************//
00079     //*********************************************//
00080     // Math Operator
00081     //*********************************************//
00082     //*********************************************//
00083 
00087     MC_v4d operator-() const;
00088 
00092     friend MC_v4d operator+(const MC_v4d& vec,const double& to_add);
00096     friend MC_v4d operator-(const MC_v4d& vec,const double& to_sub);
00100     friend MC_v4d operator*(const MC_v4d& vec,const double& to_mult);
00104     friend MC_v4d operator*(const double& to_mult,const MC_v4d& vec);
00108     friend MC_v4d operator/(const MC_v4d& vec,const double& to_subdiv);
00109 
00110 
00114     friend MC_v4d operator+(const MC_v4d& vec,const MC_v4d& to_add);
00118     friend MC_v4d operator-(const MC_v4d& vec,const MC_v4d& to_sub);
00119 
00120 
00122     MC_v4d& operator+=(const double& to_add);
00124     MC_v4d& operator-=(const double& to_sub);
00126     MC_v4d& operator*=(const double& to_mult);
00128     MC_v4d& operator/=(const double& to_subdiv);
00129 
00131     MC_v4d& operator+=(const MC_v4d& to_add);
00133     MC_v4d& operator-=(const MC_v4d& to_sub);
00134 
00138     MC_v4d& scale(const double& sx,const double& sy,const double& sz,const double& sw);
00142     MC_v4d& scale(const MC_v4d& scaling);
00146     MC_v4d& scale(const double& scaling);
00147 
00151     MC_v4d mask(const double& sx,const double& sy,const double& sz,const double& sw) const;
00155     MC_v4d mask(const MC_v4d& scaling) const;
00159     MC_v4d scale(const double& scaling) const;
00160 
00162     double dot(const MC_v4d& vec) const;
00164     double norm() const;
00168     MC_v4d normalized() const;
00169 
00170 
00172     MC_v4d& operator*=(const MC_matrix& M);
00173 
00174 
00176     MC_v4d& set_v3d(const MC_v3d& vec);
00177 
00178 
00179     //*********************************************//
00180     //*********************************************//
00181     // GET
00182     //*********************************************//
00183     //*********************************************//
00184 
00186     const double& operator()(const int& k_dim) const;
00188     double& operator()(const int& k_dim);
00190     const double& operator[](const int& k_dim) const;
00192     double& operator[](const int& k_dim);
00193 
00197     const double* pointer() const;
00198 
00199     //*********************************************//
00200     //*********************************************//
00201     // OUTPUT
00202     //*********************************************//
00203     //*********************************************//
00204 
00206     friend std::ostream& operator<<(std::ostream& stream,const MC_v4d& v);
00207 
00209     friend MC_v4d& operator>>(std::istream& stream,MC_v4d& v);
00210 
00211 private:
00212 
00214     double v[4];
00215 };
00216 
00217 
00219 class MC_v4d_less
00220 {
00221  public:
00222   bool operator ()(const MC_v4d& v0,const MC_v4d& v1) const
00223   {
00224 
00225     double epsilon=0.000001;
00226     if( fabs(v0[0]-v1[0])<epsilon && fabs(v0[1]-v1[1])<epsilon && fabs(v0[2]-v1[2])<epsilon )
00227       return false;
00228 
00229 
00230     if(v0[0]<v1[0])
00231       return true;
00232     else if ( !(v1[0]<v0[0]) && v0[1]<v1[1] )
00233       return true;
00234     else if ( !(v1[0]<v0[0]) && !(v1[1]<v0[1]) && v0[2]<v1[2] )
00235       return true;
00236     else if ( !(v1[0]<v0[0]) && !(v1[1]<v0[1]) && v0[2]<v1[2] && v0[3]<v1[3] )
00237       return true;
00238 
00239     return false;
00240   }
00241 };
00242 
00243 }
00244 
00245 #endif // MC_v4d_HPP

Generated on Fri Sep 25 13:31:35 2009 by  doxygen 1.5.8