MC_v3d_vector.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 #ifndef MC_V3D_VECTOR_HPP_
00021 #define MC_V3D_VECTOR_HPP_
00022 
00023 
00024 
00025 #include <MC_v3d.hpp>
00026 #include <vector>
00027 #include <set>
00028 #include <map>
00029 #include <list>
00030 #include <algorithm>
00031 
00032 
00033 
00034 namespace mesh_conv
00035 {
00036     class MC_double_vector;
00037     class MC_int_vector;
00038     class MC_matrix;
00039     class MC_connectivity_index;
00040     class MC_mesh_index_vector;
00041     class MC_segment;
00042 
00044 
00045     class MC_v3d_vector
00046     {
00047 
00048 
00049     protected:
00050 
00052         std::vector <MC_v3d> v;
00053 
00054 
00055     public:
00056 
00057 
00058         //*********************************************//
00059         //*********************************************//
00060         // CONSTRUCTORS
00061         //*********************************************//
00062         //*********************************************//
00063 
00065         MC_v3d_vector();
00067         MC_v3d_vector(const int& new_size);
00069         MC_v3d_vector(const MC_v3d& v0);
00071         MC_v3d_vector(const MC_v3d& v0,const MC_v3d& v1);
00073         MC_v3d_vector(const MC_v3d& v0,const MC_v3d& v1,const MC_v3d& v2);
00075         MC_v3d_vector(const MC_v3d& v0,const MC_v3d& v1,const MC_v3d& v2,const MC_v3d& v3);
00077         MC_v3d_vector(const MC_v3d& v0,const MC_v3d& v1,const MC_v3d& v2,const MC_v3d& v3,const MC_v3d& v4);
00079         MC_v3d_vector(const MC_v3d_vector& vec);
00081         MC_v3d_vector(const std::vector <MC_v3d>& vec);
00083         MC_v3d_vector(const std::set <MC_v3d,MC_v3d_less> set);
00085         MC_v3d_vector(const std::map <MC_v3d,int,MC_v3d_less> map);
00087         MC_v3d_vector(const MC_double_vector& x_vector,const MC_double_vector& y_vector,const MC_double_vector& z_vector);
00089         static MC_v3d_vector build_from_concatenated_vector(const MC_double_vector& X);
00090 
00092         virtual ~MC_v3d_vector(){}
00093 
00094         //************************************************//
00095         //************************************************//
00096         //Asserts
00097         //************************************************//
00098         //************************************************//
00099 
00103         void assert_bounds(const int& u) const;
00104 
00105 
00106 
00107         //*********************************************//
00108         //*********************************************//
00109         // Attribute
00110         //*********************************************//
00111         //*********************************************//
00112 
00114         int size() const;
00115 
00116         //*********************************************//
00117         //*********************************************//
00118         // Manipulate
00119         //*********************************************//
00120         //*********************************************//
00121 
00123         void clear();
00124 
00128         MC_v3d_vector& resize(const int& new_size);
00129 
00133         MC_v3d_vector& add(const MC_v3d& x);
00137         MC_v3d_vector& add(const MC_v3d_vector& v_x);
00141         friend MC_v3d_vector operator<<(const MC_v3d_vector& vec,const MC_v3d& value);
00145         friend MC_v3d_vector operator<<(const MC_v3d_vector& vec,const MC_v3d_vector& value);
00146 
00147 
00151         MC_v3d_vector& set(const int& k_index,const MC_v3d& x);
00157         MC_v3d_vector& set(const mesh_conv::MC_int_vector& k_index,const MC_v3d_vector& x);
00158 
00159 
00161         const MC_v3d& first() const;
00163         MC_v3d& first();
00164 
00166         const MC_v3d& last() const;
00168         MC_v3d& last();
00169 
00171         MC_double_vector component(const int& k_dim) const;
00172 
00173 
00177         MC_v3d_vector removed(const MC_int_vector& index_to_remove) const;
00178 
00179         //************************************************//
00180         //************************************************//
00181         //Initialize value
00182         //************************************************//
00183         //************************************************//
00184 
00185 
00187         static MC_v3d_vector zeros(const int& new_size);
00188 
00190         static MC_v3d_vector build_duplicate(const unsigned int& N,const MC_v3d& value_to_duplicate);
00191 
00192 
00193         //************************************************//
00194         //************************************************//
00195         //Math operator
00196         //************************************************//
00197         //************************************************//
00198 
00199 
00200 
00201 
00205         MC_v3d_vector operator-() const;
00206 
00207 
00211         friend MC_v3d_vector operator+(const MC_v3d_vector& vec,const MC_v3d& to_add);
00215         friend MC_v3d_vector operator+(const MC_v3d& to_add,const MC_v3d_vector& vec);
00219         friend MC_v3d_vector operator-(const MC_v3d_vector& vec,const MC_v3d& to_sub);
00220 
00224         friend MC_v3d_vector operator*(const MC_v3d_vector& vec,const double& to_mult);
00228         friend MC_v3d_vector operator*(const double& to_mult,const MC_v3d_vector& vec);
00232         friend MC_v3d_vector operator/(const MC_v3d_vector& vec,const double& to_subdiv);
00233 
00234 
00235 
00241         friend MC_v3d_vector operator+(const MC_v3d_vector& vec,const MC_v3d_vector& to_add);
00247         friend MC_v3d_vector operator-(const MC_v3d_vector& vec,const MC_v3d_vector& to_sub);
00248 
00249 
00250 
00252         MC_v3d_vector& operator+=(const MC_v3d& to_add);
00254         MC_v3d_vector& operator-=(const MC_v3d& to_sub);
00256         MC_v3d_vector& operator*=(const double& to_mult);
00258         MC_v3d_vector& operator/=(const double& to_subdiv);
00259 
00264         MC_v3d_vector& operator+=(const MC_v3d_vector& to_add);
00269         MC_v3d_vector& operator-=(const MC_v3d_vector& to_sub);
00270 
00272         static MC_v3d sum(const MC_v3d_vector& vec);
00273 
00275         friend MC_v3d_vector operator*(const MC_matrix& M,const MC_v3d_vector& vec);
00277         MC_v3d_vector& operator*=(const MC_matrix& M);
00278 
00281         friend MC_v3d_vector operator*(const MC_double_vector w,const MC_v3d_vector& vec);
00284         friend MC_v3d_vector operator*(const MC_v3d_vector& vec,const MC_double_vector& w);
00287         MC_v3d_vector& operator*=(const MC_double_vector& w);
00288 
00290         static MC_double_vector norm(const MC_v3d_vector& vec);
00291 
00293         MC_v3d_vector normalized() const;
00294 
00296         MC_v3d_vector& scale(const MC_v3d_vector& s);
00297 
00301         std::pair <MC_v3d_vector,double> scaled_to_unit() const;
00302 
00304         MC_v3d barycenter() const;
00305 
00307         std::pair<MC_v3d_vector,MC_matrix> scaled_to_unit_and_center() const;
00308 
00309 
00310         //*********************************************//
00311         //*********************************************//
00312         // get Operators
00313         //*********************************************//
00314         //*********************************************//
00315 
00317         const MC_v3d& operator()(const int& k_index) const ;
00319         MC_v3d& operator()(const int& k_index) ;
00321         const MC_v3d& operator[](const int& k_index) const ;
00323         MC_v3d& operator[](const int& k_index) ;
00324         
00326         MC_v3d_vector operator()(const MC_int_vector& index) const; 
00328         MC_v3d_vector operator[](const MC_int_vector& index) const;
00329 
00331         const MC_v3d* pointer() const;
00335         MC_v3d* pointer_unprotected();
00336 
00337         //************************************************//
00338         //************************************************//
00339         //change type
00340         //************************************************//
00341         //************************************************//
00342 
00344         std::map <MC_v3d,int,MC_v3d_less> to_map() const;
00346         std::set <MC_v3d,MC_v3d_less> to_set() const;
00348         std::list <MC_v3d> to_list() const;
00349 
00350 
00351         //*********************************************//
00352         //*********************************************//
00353         // Bounding box
00354         //*********************************************//
00355         //*********************************************//
00356 
00361         std::pair <MC_v3d,MC_v3d> bounding_box_elements() const;
00362 
00364         MC_v3d bounding_box_length() const;
00365 
00369         std::vector <MC_segment> bounding_box_segment(const double& length_ratio=0.1) const;
00370 
00371         //*********************************************//
00372         //*********************************************//
00373         // Laplacian
00374         //*********************************************//
00375         //*********************************************//
00376 
00389         static MC_v3d_vector laplacian_deformation(const MC_v3d_vector& vertex_input,const std::map<int,std::pair<MC_int_vector,MC_double_vector> >& laplacian_mean_value,const std::pair<MC_int_vector,MC_v3d_vector>& constraints);
00390 
00391 
00392 
00393         
00394         //*********************************************//
00395         //*********************************************//
00396         // INPUT OUTPUT
00397         //*********************************************//
00398         //*********************************************//
00399 
00401         friend std::ostream& operator<<(std::ostream& output,const MC_v3d_vector& in);
00402 
00404         std::ostream& export_stream(std::ostream& output) const;
00406         MC_v3d_vector& read_stream(std::istream& input);
00407 
00408 
00409 
00410 //        //*********************************************//
00411 //        //*********************************************//
00412 //        // Points contained in volume
00413 //        //*********************************************//
00414 //        //*********************************************//
00415 //
00416 //        /** \brief Points contained in a given box */
00417 //        MC_int_vector contained_in_box(const MC_v3d& x0,const MC_v3d& x1);
00418 
00419 
00420         //************************************************//
00421         //************************************************//
00422         //Closest
00423         //************************************************//
00424         //************************************************//
00425 
00427         std::pair<MC_v3d,int> closest(const MC_v3d& x) const;
00428 
00429 
00430         //************************************************//
00431         //************************************************//
00432         //Change position
00433         //************************************************//
00434         //************************************************//
00435 
00437         MC_v3d_vector inverted_position() const;
00438 
00439     private:
00440     };
00441 
00442 
00444     class MC_v3d_vector_less
00445     {
00446     public:
00447         bool operator()(const MC_v3d_vector& v0,const MC_v3d_vector& v1) const
00448         {
00449             MC_v3d_less L;
00450             if(v0.size()<v1.size())
00451                 return true;
00452             else if(v0.size()>v1.size())
00453                 return false;
00454             else //equal size compare by values
00455             {
00456                 int N=v0.size();
00457                 for(int k=0;k<N;++k)
00458                 {
00459                     if(L(v0[k],v1[k])==true)
00460                         return true;
00461                     else if(L(v1[k],v0[k])==true)
00462                         return false;
00463                 }
00464                 //complete equality
00465                 return false;
00466             }
00467         }
00468     };
00469 
00470 }
00471 
00472 #endif

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