MC_v3d.hpp

Go to the documentation of this file.
00001 /*
00002 **    Mesh Converter
00003 **    Copyright (C) 2009 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_V3D_HPP
00022 #define MC_V3D_HPP
00023 
00024 #include <iostream>
00025 #include <cmath>
00026 
00027 
00028 
00029 
00030 
00031 namespace mesh_conv
00032 {
00033     class MC_double_vector;
00034     class MC_v3d_vector;
00035     class MC_matrix;
00036     class MC_quaternion;
00037     class MC_segment;
00038 
00040 
00042 class MC_v3d
00043 {
00044 public:
00045 
00046     //*********************************************//
00047     //*********************************************//
00048     // CONSTRUCTORS
00049     //*********************************************//
00050     //*********************************************//
00051 
00053     MC_v3d();
00055     MC_v3d(const double& x,const double& y,const double& z);
00057     MC_v3d(const MC_v3d& _v);
00061     MC_v3d(const double* _v);
00066     MC_v3d(const std::string& s);
00067 
00069     MC_v3d(const MC_matrix& M);
00070 
00072     MC_v3d(const MC_v3d_vector& vec);
00073 
00075     MC_v3d(const MC_double_vector& vec);
00076 
00078     ~MC_v3d();
00079 
00080 
00081     // ********************************************* //
00082     // ********************************************* //
00083     //  Math Operator
00084     // ********************************************* //
00085     // ********************************************* //
00086 
00088     void set_zero();
00089 
00090 
00091     //*********************************************//
00092     //*********************************************//
00093     // Equality
00094     //*********************************************//
00095     //*********************************************//
00096 
00098     MC_v3d& operator=(const MC_matrix& M);
00099 
00100     //*********************************************//
00101     //*********************************************//
00102     // Math Operator
00103     //*********************************************//
00104     //*********************************************//
00105 
00109     MC_v3d operator-() const;
00110 
00114     friend MC_v3d operator+(const MC_v3d& vec,const double& to_add);
00118     friend MC_v3d operator-(const MC_v3d& vec,const double& to_sub);
00122     friend MC_v3d operator*(const MC_v3d& vec,const double& to_mult);
00126     friend MC_v3d operator*(const double& to_mult,const MC_v3d& vec);
00130     friend MC_v3d operator/(const MC_v3d& vec,const double& to_subdiv);
00131 
00132 
00136     friend MC_v3d operator+(const MC_v3d& vec,const MC_v3d& to_add);
00140     friend MC_v3d operator-(const MC_v3d& vec,const MC_v3d& to_sub);
00141 
00142 
00144     MC_v3d& operator+=(const double& to_add);
00146     MC_v3d& operator-=(const double& to_sub);
00148     MC_v3d& operator*=(const double& to_mult);
00150     MC_v3d& operator/=(const double& to_subdiv);
00151 
00153     MC_v3d& operator+=(const MC_v3d& to_add);
00155     MC_v3d& operator-=(const MC_v3d& to_sub);
00156 
00160     MC_v3d& scale(const double& sx,const double& sy,const double& sz);
00164     MC_v3d& scale(const MC_v3d& scaling);
00168     MC_v3d& scale(const double& scaling);
00169 
00173     MC_v3d scaled(const MC_v3d& scaling) const;
00177     MC_v3d scaled(const double& scaling) const;
00178 
00179 
00183     MC_v3d mask(const double& sx,const double& sy,const double& sz) const;
00187     MC_v3d mask(const MC_v3d& scaling) const;
00191     MC_v3d scale(const double& scaling) const;
00192 
00194     double dot(const MC_v3d& vec) const;
00196     MC_v3d cross(const MC_v3d& vec) const;
00198     double norm() const;
00202     MC_v3d normalized() const;
00203 
00204 
00206     MC_v3d& operator*=(const MC_matrix& M);
00207 
00210     friend MC_v3d operator*(const MC_quaternion& q,const MC_v3d& vec);
00213     MC_v3d& operator*=(const MC_quaternion& q);
00214 
00215 
00217     friend bool operator==(const MC_v3d& a1,const MC_v3d& a2);
00219     friend bool operator!=(const MC_v3d& a1,const MC_v3d& a2);
00220 
00221 
00225     static double area(const MC_v3d& v0,const MC_v3d& v1);
00226 
00230     static double cotan(const MC_v3d& u0,const MC_v3d& u1);
00231 
00235     static double angle(const MC_v3d& u0,const MC_v3d& u1);
00236 
00241     MC_v3d project_on_plane(const MC_v3d& normal) const;
00242 
00246     MC_v3d project_on_line(const MC_v3d& dir) const;
00250     MC_v3d project_on_line(const MC_segment& seg) const;
00251 
00252     //*********************************************//
00253     //*********************************************//
00254     // Operator with gradient
00255     //*********************************************//
00256     //*********************************************//
00257 
00258     std::pair <MC_v3d,MC_v3d_vector> normalized_with_gradient() const;
00259 
00260 
00261     //*********************************************//
00262     //*********************************************//
00263     // GET
00264     //*********************************************//
00265     //*********************************************//
00266 
00268     const double& operator()(const int& k_dim) const;
00270     double& operator()(const int& k_dim);
00272     const double& operator[](const int& k_dim) const;
00274     double& operator[](const int& k_dim);
00275 
00277     const double* pointer() const;
00281     double* pointer_unprotected();
00282 
00283     //*********************************************//
00284     //*********************************************//
00285     // OUTPUT
00286     //*********************************************//
00287     //*********************************************//
00288 
00290     friend std::ostream& operator<<(std::ostream& stream,const MC_v3d& v);
00291 
00293     std::string to_string() const;
00294 
00296     friend bool operator>>(std::istream& stream,MC_v3d& v);
00297 
00298 private:
00299 
00301     double v[3];
00302 };
00303 
00304 
00306 class MC_v3d_less
00307 {
00308  public:
00309   bool operator ()(const MC_v3d& v0,const MC_v3d& v1) const
00310   {
00311 
00312     double epsilon=1e-5;
00313     if( std::fabs(v0[0]-v1[0])<epsilon && std::fabs(v0[1]-v1[1])<epsilon && std::fabs(v0[2]-v1[2])<epsilon )
00314       return false;
00315 
00316 
00317     if(v0[0]+epsilon<v1[0])
00318       return true;
00319     else if ( !(v1[0]+epsilon<v0[0]) && v0[1]+epsilon<v1[1] )
00320       return true;
00321     else if ( !(v1[0]+epsilon<v0[0]) && !(v1[1]+epsilon<v0[1]) && v0[2]+epsilon<v1[2] )
00322       return true;
00323 
00324 
00325     return false;
00326   }
00327 };
00328 
00329 }
00330 
00331 #endif // MC_V3D_HPP

Generated on Sun Apr 18 20:24:47 2010 by  doxygen 1.6.1