MC_polygon.hpp

Go to the documentation of this file.
00001 /*
00002 **    Mesh Converter
00003 **    Copyright (C) 2009 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 MC_POLYGON_HPP_
00020 #define MC_POLYGON_HPP_
00021 
00022 #include <MC_v3d.hpp>
00023 #include <MC_v3d_vector.hpp>
00024 #include <MC_int_vector.hpp>
00025 
00026 #include <stdlib.h>
00027 #include <iostream>
00028 
00029 
00030 
00031 namespace mesh_conv
00032 {
00033     class MC_segment;
00034     class MC_mesh_index_vector;
00035 
00037 
00038     class MC_polygon : public MC_v3d_vector
00039     {
00040     public:
00041 
00042         //************************************************//
00043         //************************************************//
00044         //Constructor
00045         //************************************************//
00046         //************************************************//
00047 
00049         MC_polygon();
00051         MC_polygon(const MC_v3d& v0,const MC_v3d& v1,const MC_v3d& v2);
00053         MC_polygon(const MC_v3d& v0,const MC_v3d& v1,const MC_v3d& v2,const MC_v3d& v3);
00055         MC_polygon(const MC_v3d& v0,const MC_v3d& v1,const MC_v3d& v2,const MC_v3d& v3,const MC_v3d& v4);
00057         MC_polygon(const MC_v3d_vector& vec);
00059         MC_polygon(const std::vector <MC_v3d>& vec);
00061         MC_polygon(const MC_polygon& p);
00062 
00063 
00064         //************************************************//
00065         //************************************************//
00066         //Informations
00067         //************************************************//
00068         //************************************************//
00069 
00073         bool is_planar() const;
00074 
00078         MC_v3d normal() const;
00079 
00081         MC_v3d barycenter() const;
00082 
00085         bool is_inside(const MC_v3d& _x) const;
00088         bool is_outside(const MC_v3d& _x) const;
00089 
00090 
00104         MC_v3d closest_point(const MC_v3d& x,int *type=0) const;
00105 
00106 
00112         MC_double_vector barycentric_coordinates(const MC_v3d& x) const;
00113 
00114 
00118         MC_int_vector position(const MC_v3d& x) const;
00119 
00120 
00121 
00122 
00123 
00124         //************************************************//
00125         //************************************************//
00126         //Geometry transform (intersection, ...)
00127         //************************************************//
00128         //************************************************//
00129 
00130 
00150         MC_v3d_vector plane_intersection(const MC_v3d& n,const MC_v3d& x0,int *type=0,MC_int_vector *type_edge=0) const;
00151 
00166         MC_polygon half_space_intersection(const MC_v3d& n,const MC_v3d& x0,int *type=0) const;
00167 
00180         MC_v3d segment_intersection(const MC_segment& s,int *type=0) const;
00181 
00182 
00191         std::pair <MC_v3d,std::pair<int,std::pair<int,double> > > projected_direction(const MC_v3d& x0,const MC_v3d& d,const MC_int_vector& forbidden_edge=MC_int_vector(-1)) const;
00192 
00193 
00194 
00196         bool is_degenerated() const;
00204         std::pair<MC_polygon,std::pair<bool,bool> > undegenerated() const;
00205 
00206 
00207 
00213         std::pair <MC_polygon,MC_matrix> rotate_to_plane(const MC_v3d& normal) const;
00214 
00215 
00216         //************************************************//
00217         //************************************************//
00218         //Subdivision
00219         //************************************************//
00220         //************************************************//.
00221 
00231         std::pair<std::vector <MC_polygon>,std::pair<MC_mesh_index_vector,std::pair<MC_int_vector,MC_int_vector> > >  subdivide_mid_edge(const MC_int_vector& constraint_edges=MC_int_vector()) const;
00232 
00233 
00234 
00245         std::pair<std::vector <MC_polygon>,std::pair<MC_mesh_index_vector,std::pair<MC_int_vector,MC_int_vector> > > subdivide_barycenter_mid_edge(const MC_int_vector& constraint_edges=MC_int_vector()) const;
00246 
00251         std::pair<std::vector <MC_polygon>,std::pair<MC_mesh_index_vector,std::pair<MC_int_vector,MC_int_vector> > > subdivide_mixed_mid_edge(const MC_int_vector& constraint_edges=MC_int_vector()) const;
00252 
00253 
00254         //************************************************//
00255         //************************************************//
00256         //Get
00257         //************************************************//
00258         //************************************************//
00259 
00261          MC_segment segment(const int& edge_number) const;
00262 
00263 
00264     private:
00265 
00273         std::vector <MC_polygon> subdivide_mid_edge_no_constraint() const;
00281         std::vector <MC_polygon> subdivide_barycenter_mid_edge_no_constraint() const;
00282 
00283 
00284     };
00285 
00286 
00287     class MC_polygon_less
00288     {
00289     public:
00290         bool operator()(const MC_polygon& p0,const MC_polygon& p1) const
00291         {
00292             MC_v3d_less L;
00293             if(p0.size()<p1.size())
00294                 return true;
00295             else if(p0.size()>p1.size())
00296                 return false;
00297             else //equal size compare by values
00298             {
00299                 int N=p0.size();
00300                 for(int k=0;k<N;k++)
00301                 {
00302                     if(L(p0[k],p1[k])==true)
00303                         return true;
00304                     else if(L(p1[k],p0[k])==true)
00305                         return false;
00306                 }
00307                 //complete equality
00308                 return false;
00309             }
00310         }
00311     };
00312 
00313 }
00314 
00315 
00316 
00317 
00318 #endif

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