Back to index

salome-med  6.5.0
PolygonAlgorithms.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #ifndef __POLYGONALGORITHMS_HXX__
00021 #define __POLYGONALGORITHMS_HXX__
00022 
00023 #include <vector>
00024 #include <deque>
00025 #include <map>
00026 
00027 namespace INTERP_KERNEL
00028 {
00029   template<int DIM>
00030   class VertexLess
00031   {
00032   public:
00033     bool operator()(const double * P_1, const double * P_2) 
00034     {
00035       for(int idim=0; idim<DIM; idim++)
00036         {        
00037           if(P_1[idim] < P_2[idim] )  return true;
00038           else if( P_1[idim] > P_2[idim]) return false;
00039         }
00040       return false;
00041     }
00042   };
00043   
00044   template<int DIM>
00045   class PolygonAlgorithms
00046   {
00047   public:
00048     PolygonAlgorithms(double epsilon, double precision);
00049     std::deque<double> intersectConvexPolygons(const double* P_1,const double* P_2, int N1, int N2);
00050 
00051     //Not yet tested
00052     int convexDecomposition(const double * P, int N, std::vector< std::map< int,int > >& components,
00053                             std::vector< int >& components_index, const double epsilon);
00054   private:
00055     void defineIndices(int& i_loc, int& i_next, int& i_prev, 
00056                        const double *& Poly1, const double *& Poly2,
00057                        int& j1, int& j1_glob, int& j2, int& j2_glob,
00058                        int& j3, int& j3_glob, int& j4, int& j4_glob, 
00059                        int& i_glob, int& i_next_glob, int& i_prev_glob, 
00060                        const double * P_1, const double * P_2, 
00061                        int N1, int N2, int sign);
00062     void addCrossings( const double * A, const double * B, int i , int i_next,
00063                        const double * C, const double * D, int j1, int j2,
00064                        const double * E, const double * F, int j3, int j4,
00065                        const double * G);
00066     void addCrossing0(const double * A, const double * B, int i, int i_next,
00067                       const double * C, const double * D, int j, int j_next);
00068     void addCrossing( double * ABCD, std::pair< int,int > i_i_next, std::pair< int,int > j_j_next);
00069     void addNewVertex( int i, int i_glob, int i_next_glob, int i_prev_glob, const double * P);
00070     bool intersectSegmentSegment(const double * A,  const double * B, const double * C,
00071                                  const double * D,  const double * E, double * V);
00072 
00073 
00074     //Not yet tested
00075     void convexDecomposition(const double* P, int N, double* n,  std::vector< int > subP, int NsubP, 
00076                              std::vector< std::map< int,int > >& components, std::vector< int >& components_index,
00077                              int& Ncomp, int sign, const double epsilon);
00078     void convHull(const double *P, int N, double * n,  std::map< int,int >& subP,
00079                   std::map< int,int >& not_in_hull, int& NsubP, const double epsilon);
00080   private:
00081     std::deque< double > _Inter;/* vertices of the intersection  P1^P2 */
00082     std::vector< std::pair< int,int > > _End_segments; /* segments containing inter final edges */   
00083     /* status list of segments (ending point, starting point) intersected by the sweeping line */
00084     /* and a boolean true if the ending point is in the intersection */
00085     std::multimap< int, std::pair< int,bool> > _Status;
00086     bool _is_in_intersection;
00087     bool _terminus;
00088     double _vdouble[DIM];
00089     double _epsilon;
00090     double _precision;
00091   };
00092 }
00093 
00094 #endif