MC_v3d.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
00084
00085
00086
00088 void set_zero();
00089
00090
00091
00092
00093
00094
00095
00096
00098 MC_v3d& operator=(const MC_matrix& M);
00099
00100
00101
00102
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
00255
00256
00257
00258 std::pair <MC_v3d,MC_v3d_vector> normalized_with_gradient() const;
00259
00260
00261
00262
00263
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
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