]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
addition for triangulation of polygons
authorvbd <vbd>
Tue, 12 Feb 2008 13:02:09 +0000 (13:02 +0000)
committervbd <vbd>
Tue, 12 Feb 2008 13:02:09 +0000 (13:02 +0000)
src/INTERP_KERNEL/InterpolationUtils.hxx

index 57b8589c9f7988019698db90cc5d6ca65cc4ce67..7a79b962b9f57de4aa07c9322923ac7a8122af19 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "NormalizedUnstructuredMesh.hxx"
 
+#include <deque>
 #include <map>
 #include <cmath>
 #include <string>
@@ -517,6 +518,58 @@ namespace INTERP_KERNEL
     
     return determinant(AB,AC,n)>0;
   }
+
+  /*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _*/  
+  /*      calcul l'intersection de deux polygones COPLANAIRES */
+  /* en dimension DIM (2 ou 3). Si DIM=3 l'algorithme ne considère*/
+  /* que les deux premières coordonnées de chaque point */
+  /*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _*/ 
+  template<int DIM> inline void intersec_de_polygone(const double * Coords_A, const double * Coords_B, 
+                                                                                                                                                                                                                int nb_NodesA, int nb_NodesB,
+                                                                                                                                                                                                                std::vector<double>& inter, double dim_caracteristic, double precision)
+       {
+    for(int i_A = 1; i_A<nb_NodesA-1; i_A++)
+      {
+                               for(int i_B = 1; i_B<nb_NodesB-1; i_B++)
+                                       {
+                                               INTERP_KERNEL::intersec_de_triangle(&Coords_A[0],&Coords_A[DIM*i_A],&Coords_A[DIM*(i_A+1)],
+                                                                                                                                                                                        &Coords_B[0],&Coords_B[DIM*i_B],&Coords_B[DIM*(i_B+1)],
+                                                                                                                                                                                        inter, dim_caracteristic, precision);
+                                       }
+                       }
+               int nb_inter=((int)inter.size())/DIM;
+               if(nb_inter >3) inter=INTERP_KERNEL::reconstruct_polygon(inter);
+       }
+
+  /*_ _ _ _ _ _ _ _ _
+  /*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ */
+  /*  fonctions qui calcule l'aire d'un polygone en dimension 2 ou 3    */
+  /*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ */
+       template<int DIM> inline double polygon_area(std::vector<double>& inter)
+       {
+    double result=0.;
+               double area[DIM];
+               
+               for(int i = 1; i<(int)inter.size()/DIM-1; i++)
+                       {
+                               INTERP_KERNEL::crossprod<DIM>(&inter[0],&inter[DIM*i],&inter[DIM*(i+1)],area);
+                               result +=0.5*norm<DIM>(area);
+                       }
+               return result;
+       }
+       
+       template<int DIM> inline double polygon_area(std::deque<double>& inter)
+       {
+    double result=0.;
+               double area[DIM];
+               
+               for(int i = 1; i<(int)inter.size()/DIM-1; i++)
+                       {
+                               INTERP_KERNEL::crossprod<DIM>(&inter[0],&inter[DIM*i],&inter[DIM*(i+1)],area);
+                               result +=0.5*norm<DIM>(area);
+                       }
+               return result;
+       }
 }
 
 #endif