Mesh_object.h

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 
00021 /*
00022 ** Mesh_object.h
00023 ** 
00024 ** Made by damien
00025 ** Login   <damien@ortie>
00026 ** 
00027 ** Started on  Fri Jun  6 19:26:06 2008 damien
00028 ** Last update Fri Jun  6 19:26:06 2008 damien
00029 */
00030 
00031 #ifndef         MESH_OBJECT_H_
00032 # define        MESH_OBJECT_H_
00033 
00034 
00035 #include <stdlib.h>
00036 #include <time.h>
00037 #include <iostream>
00038 #include <cmath>
00039 #include <string>
00040 #include <errno.h>
00041 #include <stdio.h>
00042 
00043 #include <int_vector.h>
00044 #include <tinyXml/tinyxml.h>
00045 #include <tinyXml/tinystr.h>
00046 
00047 #include <Connectivity.h>
00048 #include <Point_set.h>
00049 #include <Vector_parameter.h>
00050 #include <Polygon.h>
00051 #include <Curve_3D.h>
00052 
00053 
00054 
00056 
00058 class Mesh_object
00059 {
00060 
00061 public:
00062 
00063   //************************************************//
00064   //************************************************//
00065   //CONSTRUCTORS
00066   //************************************************//
00067   //************************************************//
00068 
00070   Mesh_object();
00072   Mesh_object(const Mesh_object& );
00074   ~Mesh_object();
00075 
00076 
00078   int destroy();
00079 
00080 
00081 
00082 
00083 
00084 
00085   //************************************************//
00086   //************************************************//
00087   //Geometry
00088   //************************************************//
00089   //************************************************//
00090 
00091 
00092   //Get
00093   //************************************************//
00094 
00096 
00097   int get_vertex_number() const;
00098 
00100   double& get_vertex(int k_vertex,int k_dim);
00102   double& get_vertex(int k_polygon,int k_vertex,int k_dim);
00104   double  get_vertex(int k_vertex,int k_dim) const;
00106   double  get_vertex(int k_polygon,int k_vertex,int k_dim) const;
00108   const double* get_vertex_p(int k_vertex);
00110   const double* get_vertex_p(int k_polygon,int k_vertex);
00112   V_3D get_vertex_v3d(int k_vertex) const;
00114   V_3D get_vertex_v3d(int k_polygon,int k_vertex) const;
00115 
00116 
00117   //Set
00118   //************************************************//
00119 
00121   int set_vertex(int k_vertex,double x,double y,double z);
00123   int set_vertex(int k_vertex,int k_dim,double value);
00125   int set_vertex(int k_vertex,V_3D v);
00127   int set_vertex(int k_vertex,double* v);
00129   int set_vertex(int k_vertex,int dim,double *v);
00131   int set_vertex(const Point_set& p);
00132 
00133   //ADD 
00134   //************************************************//
00135 
00137   int add_vertex(double x,double y,double z);
00139   int add_vertex(const V_3D& v);
00141   int add_vertex(const std::vector <double>& to_add);
00143   int add_vertex(const std::vector <V_3D>& to_add);
00145   int add_vertex(const double* v);
00147   int add_vertex(int dim,double *v);
00149   int add_vertex(const Point_set& p);
00150 
00151 
00152 
00153   //ADD/DELETE UNIQUE
00154   //************************************************//
00155 
00157   int add_unique(double x,double y,double z,double epsilon);
00159   int add_unique(const V_3D& v,double epsilon);
00161   int add_unique(const double* v,double epsilon);
00162 
00164   int exist(const V_3D& v) const;
00166   int exist(const V_3D& v,double epsilon) const;
00168   int exist(double x,double y,double z) const;
00170   int exist(double x,double y,double z,double epsilon) const;
00171 
00172 
00174   int eliminate(int k_index);
00176   int eliminate(const std::vector <int>& k_index);
00178   int eliminate(const std::vector <double>& k_index);
00180   int eliminate(double x,double y,double z);
00182   int eliminate(double x,double y,double z,double epsilon);
00184   int eliminate(const V_3D& x,double epsilon);
00186   int eliminate(const V_3D& x);
00188   int eliminate(const double* x,double epsilon);
00190   int eliminate(const double* x);
00191 
00192 
00193 
00194 
00195 
00196   //TRANSFORMATIONS
00197   //************************************************//
00198 
00200   int matrix_transform(const Matrix& M);
00201 
00203   int rotate(const V_3D& n,double angle);
00205   int rotate(double n_x,double n_y,double n_z,double angle);
00207   int rotate(const double *n,double angle);
00208 
00210   int rotate_centered(const V_3D& n,double angle);
00212   int rotate_centered(double n_x,double n_y,double n_z,double angle);
00214   int rotate_centered(const double *n,double angle);
00215 
00217   int rotate(const V_3D& n,double angle,const V_3D& center);
00219   int rotate(double n_x,double n_y,double n_z,double angle,const V_3D& center);
00221   int rotate(const double *n,double angle,const V_3D& center);
00222 
00223 
00224 
00226   int translate(double t_x,double t_y,double t_z);
00228   int translate(const double *t);
00230   int translate(const V_3D& t);
00231 
00232 
00234   int scale(double s_x,double s_y,double s_z);
00236   int scale(const double *s);
00238   int scale(const V_3D& s);
00240   int scale(double s);
00241 
00242 
00244   int scale_centered(double s_x,double s_y,double s_z);
00246   int scale_centered(const double *s);
00248   int scale_centered(const V_3D& s);
00250   int scale_centered(double s);
00251 
00252 
00253 
00254   //SIZE
00255   //************************************************//
00256 
00257 
00259   V_3D get_middle_point() const;
00261   V_3D get_min_point() const;
00263   V_3D get_max_point() const;
00265   V_3D get_size_mesh() const;
00266 
00267   //center the point set
00268   int center_mesh();
00269   //set max size to 1
00270   int unitize_size();
00271 
00272   
00273 
00274   //FURTHER
00275   //************************************************//
00276 
00278 
00279   double get_closest_distance(double x,double y,double z,int *index) const;
00281 
00282   double get_closest_distance(const double* x,int *index) const;
00284 
00285   double get_closest_distance(const V_3D& x,int *index) const;
00286 
00287 
00289 
00290   double get_further_distance(double x,double y,double z,int *index) const;
00292 
00293   double get_further_distance(const double* x,int *index) const;
00295 
00296   double get_further_distance(const V_3D& x,int *index) const;
00297 
00299   double distance_to_index(double x,double y,double z,int index) const;
00301   double distance_to_index(const double* x,int index) const;
00303   double distance_to_index(const V_3D& x,int index) const;
00304 
00305 
00307   std::vector <int> N_closest(const V_3D& center,int N_closest) const;
00309   std::vector <int> N_closest(double x,double y,double z,int N_closest) const;
00311   std::vector <int> N_closest(double *x,int N_closest) const;
00312 
00314   V_3D get_closest_vertex(const V_3D& center) const;
00316   V_3D get_closest_vertex(double x,double y,double z) const;
00318   V_3D get_closest_vertex(const double *x) const;
00319 
00320 
00321 
00322   
00323 
00324 
00325 
00326 
00327   //************************************************//
00328   //************************************************//
00329   //Connectivity
00330   //************************************************//
00331   //************************************************//
00332 
00333 
00334   //Get
00335   //************************************************//
00336 
00338   int get_index(int k_index) const;
00340   int& get_index(int k_index);
00342   int get_index(int k_polygon,int k_index) const;
00344   int& get_index(int k_polygon,int k_index);
00346   std::vector <int> get_index_of_polygon(int k_polygon) const;
00348   const int* get_index() const;
00349 
00351   Connectivity& get_connectivity();
00353   const Connectivity& get_connectivity() const;
00354 
00356   int size_index() const;
00358   int polygon_number() const;
00360   int polygon_size(int k_polygon) const;
00362   int vertex_number() const;
00363 
00364 
00366   int get_index_triangulated(int k_index) const;
00368   int& get_index_triangulated(int k_index);
00370   int get_index_triangulated(int k_triangle,int k_index) const;
00372   int& get_index_triangulated(int k_triangle,int k_index);
00374   const int* get_index_triangulated() const;
00376   int get_triangle_number() const;
00377 
00379   int find_polygon(const std::vector <int>& polygon) const;
00380 
00382 
00383   int build_connectivity_index();
00384 
00386   int triangulate();
00387 
00389 
00394   int get_polygon_access(int k_polygon) const;
00395 
00396   
00397   //Add/Delete polygon
00398   //************************************************//
00399 
00401   int add_polygon(const std::vector <int>& polygon);
00403   int add_polygon(int index_0,int index_1,int index_2,int index_3);
00405   int add_polygon(int index_0,int index_1,int index_2);
00407 
00408   int add_index(int index);
00410 
00412   int set_polygon(int k_polygon,const std::vector <int>& polygon);
00414 
00416   int set_index(int k_polygon,int k_index,int index);
00418 
00420   int delete_polygon(int k_polygon);
00422   int delete_given_polygon(const std::vector <int> polygon);
00423 
00425 
00426   int flip_polygon(int k_polygon);
00428   int flip_polygon();
00429 
00430 
00431 
00432   //One Ring
00433   //************************************************//
00434 
00436   int_vector get_one_ring(int k_polygon,int k_vertex) const;
00438   int_vector get_one_ring(int k_vertex) const;
00440   int_vector get_polygon_ring(int k_polygon,int k_vertex) const;
00442   int_vector get_polygon_ring(int k_vertex) const;
00443 
00444 
00445 
00446 
00447   //Edges and Manifold
00448   //************************************************//
00449 
00451 
00453   int build_manifold();
00454 
00456 
00457   int build_edges();
00458 
00459 
00460   //************************************************//
00461   //************************************************//
00462   //Normal
00463   //************************************************//
00464   //************************************************//
00465 
00467   int build_normal_per_polygon();
00469 
00470   int build_normal_intermediate(double angle_threshold);
00472   int build_normal_per_vertex();
00474   int normal_type() const;
00476   V_3D get_polygon_normal(int k_polygon) const;
00478   V_3D get_polygon_and_vertex_normal(int k_polygon,int k_vertex) const;
00480   V_3D get_vertex_normal(int k_vertex) const;
00482   int set_vertex_normal(int k_vertex,const V_3D& n);
00484   V_3D get_vertex_normal(int k_polygon,int k_vertex) const;
00486   int set_vertex_normal(int k_polygon,int k_vertex,const V_3D& n);
00487 
00488 
00489   //************************************************//
00490   //************************************************//
00491   //Color
00492   //************************************************//
00493   //************************************************//
00494 
00496   int set_per_vertex_color();
00498   int set_per_polygon_color();
00500   int set_per_polygon_and_vertex_color();
00501 
00502 
00504 
00509   int color_type() const;
00510 
00512 
00513   int fill_color(double r,double g,double b,double t);
00514 
00516   int set_per_polygon_color(int k_polygon,double r,double g,double b,double t);
00518   int get_per_polygon_color(int k_polygon,double *r,double *g,double *b,double *t) const;
00519 
00521   int set_per_vertex_color(int k_vertex,double r,double g,double b,double t);
00523   int get_per_vertex_color(int k_vertex,double *r,double *g,double *b,double *t) const;
00525   int set_per_vertex_color(int k_polygon,int k_vertex,double r,double g,double b,double t);
00527   int get_per_vertex_color(int k_polygon,int k_vertex,double *r,double *g,double *b,double *t) const;
00528 
00529 
00530 
00532   int set_per_polygon_and_vertex_color(int k_polygon,int k_vertex,double r,double g,double b,double t);
00534   int get_per_polygon_and_vertex_color(int k_polygon,int k_vertex,double *r,double *g,double *b,double *t) const;
00535 
00536 
00538   int increase_alpha(double d_alpha);
00540   int decrease_alpha(double d_alpha);
00541 
00542 
00543   //************************************************//
00544   //************************************************//
00545   //Texture
00546   //************************************************//
00547   //************************************************//
00548 
00549 
00551   int set_intermediate_texture();
00553 
00556   int texture_type() const;
00558   int get_intermediate_texture(int k_polygon,int k_vertex,double* t0,double* t1) const;
00560   int set_intermediate_texture(int k_polygon,int k_vertex,double t0,double t1);
00562   int add_intermediate_texture(double t0,double t1);
00564   int add_polygon_texture(const std::vector <int>& index);
00565 
00567   int set_texture_number(int k_texture);
00569   int get_texture_number() const;
00570 
00572   int get_texture_polygon_number() const;
00573 
00575   int check_texture() const;
00576 
00577 
00578   //************************************************//
00579   //************************************************//
00580   //Polygon Geometry
00581   //************************************************//
00582   //************************************************//
00583 
00585 
00588   std::vector <int> add_unique_polygon(const Polygon &polygon);
00589 
00590 
00592   Polygon get_polygon(int k_polygon) const;
00593   
00595 
00596   V_3D closest_mesh_point(const V_3D& x) const;
00597 
00599 
00605   std::vector <Curve_3D> plane_intersection(const V_3D& n,const V_3D& x0) const;
00606   
00607 
00609 
00613   Mesh_object half_space_intersection(const V_3D& n,const V_3D& x0,int *type);
00614 
00616 
00617   Mesh_object half_space_intersection(const V_3D& n,const V_3D& x0);
00618 
00619 
00620 
00622   /* x = x-lambda*x where v is the vertex going to the one ring barycenter */
00623   int Laplacien_smooth(double lambda);
00624 
00625   //************************************************//
00626   //************************************************//
00627   //Specific Meshes
00628   //************************************************//
00629   //************************************************//
00630 
00632   int build_cube();
00633 
00634 
00635 
00636 
00637 
00638   //************************************************//
00639   //************************************************//
00640   //Subdivision process
00641   //************************************************//
00642   //************************************************//
00643 
00645   int subdivide_mid_edge();
00647   int subdivide_barycenter_mid_edge();
00649   int subdivide_mixed_mid_edge();
00650 
00652 
00653   int fast_subdivide_mid_edge();
00655 
00656   int fast_subdivide_barycenter_mid_edge();
00658 
00662   int fast_subdivide_mixed_mid_edge();
00663 
00664 
00665   //************************************************//
00666   //************************************************//
00667   //INPUT/OUTPUT
00668   //************************************************//
00669   //************************************************//
00670 
00672   int load_off_file(const char* filename);
00674   int load_off_file(const std::string& filename);
00676   int save_off_file(const char* filename) const;
00678   int save_off_file(const std::string& filename) const;
00679 
00681   int load_obj_file(const char* filename);
00683   int load_obj_file(const std::string& filename);
00685   int save_obj_file(const char* filename);
00687   int save_obj_file(const std::string& filename);
00688 
00690 
00691   int load_collada_file(const char* filename);
00693 
00694   int load_collada_file(const std::string& filename);
00695 
00697 
00698   int load_collada_file(const char* filename,const char* geometry_name);
00700 
00701   int load_collada_file(const std::string& filename,const std::string& geometry_name);
00702 
00703 
00705   int load_g_file(const char* filename);
00707   int load_g_file(const std::string& filename);
00709   int save_g_file(const char* filename) const;
00711   int save_g_file(const std::string& filename) const;
00712 
00713   //************************************************//
00714   //************************************************//
00715   //NAME
00716   //************************************************//
00717   //************************************************//
00718 
00720   int set_name(const char* name);
00722   int set_name(const std::string& name);
00724   std::string get_name() const;
00726   std::string& get_name();
00727   
00728 
00729 
00730 private:
00731 
00733   Connectivity connectivity;
00735   Point_set point_set;
00736 
00738 
00742   std::vector <Vector_parameter> parameters;
00750 
00751   std::string name;
00752 
00753 };
00754 
00755 
00756 
00757 #endif      /* !MESH_OBJECT_H_ */

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