Connectivity.h

Go to the documentation of this file.
00001 
00002 /*
00003 **    Mesh Converter
00004 **    Copyright (C) 2008 Damien Rohmer
00005 **
00006 **    This program is free software: you can redistribute it and/or modify
00007 **    it under the terms of the GNU General Public License as published by
00008 **    the Free Software Foundation, either version 3 of the License, or
00009 **    (at your option) any later version.
00010 **
00011 **   This program is distributed in the hope that it will be useful,
00012 **    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 **    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 **    GNU General Public License for more details.
00015 **
00016 **    You should have received a copy of the GNU General Public License
00017 **    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 
00021 
00022 
00023 /*
00024 ** Connectivity.h
00025 ** 
00026 ** Made by damien
00027 ** Login   <damien@ortie>
00028 ** 
00029 ** Started on  Tue May  6 21:17:55 2008 damien
00030 ** Last update Tue May  6 21:17:55 2008 damien
00031 */
00032 
00033 #ifndef         CONNECTIVITY_H_
00034 # define        CONNECTIVITY_H_
00035 
00036 #include <stdlib.h>
00037 #include <iostream>
00038 #include <cmath>
00039 #include <string>
00040 #include <errno.h>
00041 #include <stdio.h>
00042 #include <int_vector.h>
00043 
00044 #include <tinyXml/tinyxml.h>
00045 #include <tinyXml/tinystr.h>
00046 
00047 #include <vector>
00048 
00049 #include <Point_set.h>
00050 #include <Edge.h>
00051 
00052 
00054 
00069 class Connectivity
00070 {
00071  public:
00072   
00073   //************************************************//
00074   //************************************************//
00075   //CONSTRUCTORS
00076   //************************************************//
00077   //************************************************//
00078 
00080   Connectivity();
00082   Connectivity(const Connectivity& );
00084   ~Connectivity();
00086   int destroy();
00087 
00088 
00089 
00090 
00091 
00092   //************************************************//
00093   //************************************************//
00094   //Access/Size
00095   //************************************************//
00096   //************************************************//
00097 
00099   int get_index(int k_index) const;
00101   int& get_index(int k_index);
00103   int get_index(int k_polygon,int k_index) const;
00105   int& get_index(int k_polygon,int k_index);
00107   std::vector <int> get_index_of_polygon(int k_polygon) const;
00109   const int* get_index() const;
00110 
00111 
00113   int size_index() const;
00115   int polygon_number() const;
00117   int polygon_size(int k_polygon) const;
00119   int vertex_number() const;
00120 
00121 
00123   int get_index_triangulated(int k_index) const;
00125   int& get_index_triangulated(int k_index);
00127   int get_index_triangulated(int k_triangle,int k_index) const;
00129   int& get_index_triangulated(int k_triangle,int k_index);
00131   const int* get_index_triangulated() const;
00133   int get_triangle_number() const;
00134 
00136 
00137   int triangulate();
00138 
00140   int find_polygon(const std::vector <int>& polygon) const;
00141 
00142 
00144 
00147   int get_polygon_access(int k_polygon) const;
00148 
00149 
00150   //************************************************//
00151   //************************************************//
00152   //Build access
00153   //************************************************//
00154   //************************************************//
00155 
00157   int build_size_and_polygon_access();
00159 
00160   int build_triangulated_index();
00162   int find_max_index();
00164 
00166   int build_all_index();
00167   
00168 
00169 
00170 
00171 
00172 
00173 
00174 
00175 
00176   //************************************************//
00177   //************************************************//
00178   //Add/Delete polygon
00179   //************************************************//
00180   //************************************************//
00181 
00183   int add_polygon(const std::vector <int>& polygon);
00185   int add_polygon(int index_0,int index_1,int index_2,int index_3);
00187   int add_polygon(int index_0,int index_1,int index_2);
00189 
00190   int add_index(int index);
00192 
00194   int set_polygon(int k_polygon,const std::vector <int>& polygon);
00196 
00198   int set_index(int k_polygon,int k_index,int index);
00200 
00202   int delete_polygon(int k_polygon);
00204   int delete_given_polygon(const std::vector <int> polygon);
00205 
00206   
00208 
00209   int flip_polygon(int k_polygon);
00211   int flip_polygon();
00212 
00213   //************************************************//
00214   //************************************************//
00215   //Edges
00216   //************************************************//
00217   //************************************************//
00218 
00220   Edge  get_edge(int k_index) const;
00222   int set_edge(int k_index,const Edge& e);
00224   Edge  get_edge(int k_polygon,int k_edge) const;
00226   int  set_edge(int k_polygon,int k_edge,const Edge& e);
00228   Edge get_edge_segment(int index_vertex_0,int index_vertex_1) const;
00229 
00231   int edge_number() const;
00232   
00234 
00235   int build_edges();
00236 
00238 
00240   int build_manifold();
00241 
00242 
00243   //************************************************//
00244   //************************************************//
00245   //One Ring
00246   //************************************************//
00247   //************************************************//
00248 
00250 
00251   int build_one_ring();
00252 
00254   int_vector get_one_ring(int k_polygon,int k_edge) const;
00256   int_vector get_one_ring(int k_vertex) const;
00257 
00259   int_vector get_polygon_ring(int k_polygon,int k_edge) const;
00261   int_vector get_polygon_ring(int k_vertex) const;
00262 
00263 
00264 
00265   //************************************************//
00266   //************************************************//
00267   //INPUT/OUTPUT
00268   //************************************************//
00269   //************************************************//
00270 
00271 
00273   int load_off_file(const char* filename);
00275   int load_off_file(const std::string& filename);
00277   int load_obj_file(const char* filename);
00279   int load_obj_file(const std::string& filename);
00280 
00282 
00283   int load_collada_file(const std::string& filename);
00285 
00286   int load_collada_file(const char* filename);
00288 
00289   int load_collada_file(const std::string& filename,const std::string& name);
00291 
00292   int load_collada_file(const char* filename,const char* name);
00293   
00295   int load_g_file(const char* filename);
00297   int load_g_file(const std::string& filename);
00299   int write_g_type(const char* filename) const;
00301   int write_g_type(const std::string& filename) const;
00302 
00303 
00304 
00306   int write_off_type(const char* filename) const;
00308   int write_off_type(const std::string& filename) const;
00310   int write_obj_type(const char* filename) const;
00312   int write_obj_type(const std::string& filename) const;
00313 
00314 
00315 
00317   int export_visible_off(const char* filename,const Point_set& set) const;
00318   int export_visible_off(const std::string& filename,const Point_set& set) const;
00319 
00320 
00321 
00322 
00323   //************************************************//
00324   //************************************************//
00325   //OPERATORS
00326   //************************************************//
00327   //************************************************//
00328 
00330   int operator()(int k_index) const;
00332   int operator[](int k_index) const;
00334   int& operator()(int k_index);
00336   int& operator[](int k_index);
00338   int operator()(int k_polygon,int k_index) const;
00340   int& operator()(int k_polygon,int k_index);
00341 
00342   //affectation operator
00343   const Connectivity& operator=(const Connectivity&);
00344 
00346 
00347   friend Connectivity operator+(const Connectivity&,const Connectivity&);
00349   friend Connectivity operator+(const Connectivity&,const std::vector<int> &);
00351   friend Connectivity operator+(const std::vector<int> &,const Connectivity&);
00353   friend Connectivity operator-(const Connectivity&,const Connectivity&);
00355   friend Connectivity operator-(const Connectivity&,const std::vector<int>&);
00357   friend bool operator==(const Connectivity&,const Connectivity&);
00359   friend bool operator!=(const Connectivity&,const Connectivity&);
00361   friend ostream& operator << (ostream& flux,const Connectivity& );
00362 
00363 
00364 
00365 
00366 
00367  private:
00368 
00369 
00372 
00373   int find_current_edge_slow(int vertex_index_0,int vertex_index_1);
00376 
00377   std::vector <int> find_all_current_edge_slow(int vertex_index_0,int vertex_index_1);
00378 
00380 
00381   int reccursive_connect_manifold_polygons(int current_polygon,std::vector <int>* correct_polygon);
00382 
00383 
00385 
00386   int load_collada_mesh_connectivity(TiXmlNode* geometry_node,const std::string& filename);
00388 
00389   int load_triangles_connectivity(TiXmlNode* triangles,const std::string& filename);
00391 
00392   int load_polylist_connectivity(TiXmlNode* polylist,const std::string& filename);
00394 
00395   std::vector <int> load_collada_int_entry(TiXmlNode* node);
00396 
00397 
00399 
00401   std::vector <int> index_polygon;
00402 
00404   /*** could be better using an indirection. Just give the max index
00405        through all the index*/
00406   int max_index;
00407 
00409   std::vector <int> size_polygon;
00410 
00412   std::vector <int> polygon_access;
00413 
00415   std::vector <int> triangulated_index;
00416 
00418   std::vector <int_vector> one_ring;
00419 
00421   std::vector <int_vector> polygon_ring;
00422 
00424   std::vector <Edge> edges;
00425   
00427   std::vector <int> index_edges;
00428 
00430   std::vector <int_vector> edges_access;
00431 
00432 };
00433 
00434 #endif      /* !CONNECTIVITY_H_ */

Generated on Mon Mar 30 16:55:54 2009 by  doxygen 1.5.6