mesh.hpp

Go to the documentation of this file.
00001 /*
00002 **    TP 5ETI CPE Lyon
00003 **    Copyright (C) 2011 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 #ifndef _MESH_HPP_
00020 #define _MESH_HPP_
00021 
00022 #include <v3.hpp>
00023 
00024 #include <iostream>
00025 #include <vector>
00026 #include <map>
00027 #include <list>
00028 
00030 namespace cpe
00031 {
00032 class matrix3;
00033 }
00034 
00035 namespace cpe
00036 {
00037 
00042     class mesh
00043     {
00044 
00045     public:
00046 
00047         // ********************************************* //
00048         // ********************************************* //
00049         //  CONSTRUCTORS
00050         // ********************************************* //
00051         // ********************************************* //
00052 
00054         mesh();
00056         mesh(const std::pair <std::vector<double>,std::vector<unsigned int> >& input);
00057 
00058 
00059         // ********************************************* //
00060         // ********************************************* //
00061         //  Get value
00062         // ********************************************* //
00063         // ********************************************* //
00064 
00066         v3 get_vertex(const unsigned int& k_vertex) const;
00068         v3 get_vertex(const unsigned int& k_tri,const unsigned int& k_v) const;
00070         std::vector<unsigned int> get_connectivity(const unsigned int& k_polygon) const;
00071 
00073         void set_vertex(const unsigned int& k_vertex,const v3& new_vertex);
00075         void set_connectivity(const unsigned int& k_polygon,const std::vector<unsigned int>& new_triangle);
00076 
00077 
00078 
00080         void set_texture(const unsigned int& k_vertex,const double& tx,const double& ty);
00082         double get_texture_tx(const unsigned int& k_vertex) const;
00084         double get_texture_ty(const unsigned int& k_vertex) const;
00085 
00086 
00087         // ********************************************* //
00088         // ********************************************* //
00089         //  Build shape
00090         // ********************************************* //
00091         // ********************************************* //
00092 
00094         void add_vertex(const v3& x);
00096         void add_vertex(const double& x,const double& y,const double& z);
00098         void add_triangle(const unsigned int& u0,const unsigned int& u1,const unsigned int& u2);
00099 
00100 
00101         // ********************************************* //
00102         // ********************************************* //
00103         //  Size
00104         // ********************************************* //
00105         // ********************************************* //
00106 
00108         unsigned int vertex_number() const;
00110         unsigned int triangle_number() const;
00111 
00112         // ********************************************* //
00113         // ********************************************* //
00114         //  Connectivity information
00115         // ********************************************* //
00116         // ********************************************* //
00117 
00119         std::map<int,std::list<int> > ring() const;
00121         std::map<int,std::list<int> > star() const;
00122 
00123 
00124         // ********************************************* //
00125         // ********************************************* //
00126         //  Normal
00127         // ********************************************* //
00128         // ********************************************* //
00129 
00131         std::vector <double> normal_vertex() const;
00133         std::vector <double> normal_polygon() const;
00134 
00135 
00137         void inverse_triangle_order();
00138 
00139 
00140         // ********************************************* //
00141         // ********************************************* //
00142         //  INTERNAL ACCESS
00143         // ********************************************* //
00144         // ********************************************* //
00145 
00147         const std::vector<double>& get_vertex() const;
00149         std::vector<double>& get_vertex();
00150 
00152         const std::vector <unsigned int>& get_connectivity() const;
00154         std::vector <unsigned int>& get_connectivity();
00155 
00157         const std::vector<double>& get_texture() const;
00159         std::vector<double>& get_texture();
00160 
00161         // ********************************************* //
00162         // ********************************************* //
00163         //  Assert
00164         // ********************************************* //
00165         // ********************************************* //
00166 
00168         void assert_vertex(const unsigned int& k_vertex) const;
00169 
00171         void assert_connectivity(const unsigned int& k_connectivity) const;
00172 
00173 
00174         // ********************************************* //
00175         // ********************************************* //
00176         //  IN/OUT
00177         // ********************************************* //
00178         // ********************************************* //
00179 
00181         static mesh load_off_file(const std::string& filename);
00183         void save_off_file(const std::string& filename) const;
00184 
00185 
00186         // ********************************************* //
00187         // ********************************************* //
00188         //  Deformation
00189         // ********************************************* //
00190         // ********************************************* //
00191 
00193         void scale_unity();
00194 
00196         void scale(const double& value);
00198         void apply(const matrix3& M);
00200         void translate(const v3& tr);
00201 
00202     private:
00203 
00205         std::vector <double> vertex;
00207         std::vector <unsigned int> connectivity;
00208 
00212         std::vector <double> texture;
00213 
00214     };
00215 }
00216 
00217 #endif
Generated on Fri Aug 19 14:45:24 2011 by  doxygen 1.6.3