Salome HOME
Last checks of the new option for 3D surf
[tools/medcoupling.git] / src / INTERP_KERNEL / SplitterTetra.txx
index 38aab3c233bce06edbf49a475325afa7f9460575..9700e9ab643d64ef0c0b98b3bbdac89f1d48c9cb 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2014  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -84,6 +84,32 @@ namespace INTERP_KERNEL
     // create the affine transform
     _t=new TetraAffineTransform(_coords);
   }
+
+  /**
+   * SplitterTetra class computes for a list of cell ids of a given mesh \a srcMesh (badly named) the intersection with a 
+   * single TETRA4 cell given by \a tetraCorners (of length 4) and \a nodesId (of length 4 too). \a nodedIds is given only to establish
+   * if a partial computation of a triangle has already been performed (to increase performance).
+   *
+   * The \a srcMesh can contain polyhedron cells.
+   * 
+   * 
+   * Constructor creating object from the four corners of the tetrahedron.
+   *
+   * \param [in] srcMesh       mesh containing the source elements
+   * \param [in] tetraCorners  array 4*3 doubles containing corners of input tetrahedron (P0X,P0Y,P0Y,P1X,P1Y,P1Z,P2X,P2Y,P2Z,P3X,P3Y,P3Z).
+   */
+  template<class MyMeshType>
+  SplitterTetra<MyMeshType>::SplitterTetra(const MyMeshType& srcMesh, const double tetraCorners[12], const int *conn): _t(0),_src_mesh(srcMesh)
+  {
+    if(!conn)
+      { _conn[0]=0; _conn[1]=1; _conn[2]=2; _conn[3]=3; }
+    else
+      { _conn[0]=conn[0]; _conn[1]=conn[1]; _conn[2]=conn[2]; _conn[3]=conn[3]; }
+    _coords[0]=tetraCorners[0]; _coords[1]=tetraCorners[1]; _coords[2]=tetraCorners[2]; _coords[3]=tetraCorners[3]; _coords[4]=tetraCorners[4]; _coords[5]=tetraCorners[5];
+    _coords[6]=tetraCorners[6]; _coords[7]=tetraCorners[7]; _coords[8]=tetraCorners[8]; _coords[9]=tetraCorners[9]; _coords[10]=tetraCorners[10]; _coords[11]=tetraCorners[11];
+    // create the affine transform
+    _t=new TetraAffineTransform(_coords);
+  }
   
   /**
    * Destructor
@@ -184,8 +210,7 @@ namespace INTERP_KERNEL
             //std::cout << std::endl << "*** " << globalNodeNum << std::endl;
             calculateNode(globalNodeNum);
           }
-
-        checkIsOutside(_nodes[globalNodeNum], isOutside);       
+        CheckIsOutside(_nodes[globalNodeNum], isOutside);       
       }
 
     // halfspace filtering check
@@ -599,8 +624,8 @@ namespace INTERP_KERNEL
             calculateNode2(globalNodeNum, polyCoords[i]);
           }
 
-        checkIsStrictlyOutside(_nodes[globalNodeNum], isStrictlyOutside, precision);
-        checkIsOutside(_nodes[globalNodeNum], isOutside, precision);
+        CheckIsStrictlyOutside(_nodes[globalNodeNum], isStrictlyOutside, precision);
+        CheckIsOutside(_nodes[globalNodeNum], isOutside, precision);
       }
 
     // halfspace filtering check
@@ -825,7 +850,7 @@ namespace INTERP_KERNEL
     for(int i = 0;i<(int)nbOfNodes4Type;++i)
     {
       _t->apply(nodes[i], tetraCorners[i]);
-      checkIsOutside(nodes[i], isOutside);
+      CheckIsOutside(nodes[i], isOutside);
     }
 
     // halfspace filtering check
@@ -898,6 +923,46 @@ namespace INTERP_KERNEL
       }
     _nodes.clear();
   }
+  
+  /*!
+   * \param [in] targetCell in C mode.
+   * \param [out] tetra is the output result tetra containers.
+   */
+  template<class MyMeshTypeT, class MyMeshTypeS>
+  void SplitterTetra2<MyMeshTypeT, MyMeshTypeS>::splitTargetCell2(typename MyMeshTypeT::MyConnType targetCell, typename std::vector< SplitterTetra<MyMeshTypeS>* >& tetra)
+  {
+    const int *refConn(_target_mesh.getConnectivityPtr());
+    const int *cellConn(refConn+_target_mesh.getConnectivityIndexPtr()[targetCell]);
+    INTERP_KERNEL::NormalizedCellType gt(_target_mesh.getTypeOfElement(targetCell));
+    std::vector<int> tetrasNodalConn;
+    std::vector<double> addCoords;
+    const double *coords(_target_mesh.getCoordinatesPtr());
+    SplitIntoTetras(_splitting_pol,gt,cellConn,refConn+_target_mesh.getConnectivityIndexPtr()[targetCell+1],coords,tetrasNodalConn,addCoords);
+    std::size_t nbTetras(tetrasNodalConn.size()/4); tetra.resize(nbTetras);
+    double tmp[12];
+    int tmp2[4];
+    for(std::size_t i=0;i<nbTetras;i++)
+      {
+        for(int j=0;j<4;j++)
+          {
+            int cellId(tetrasNodalConn[4*i+j]);
+            tmp2[j]=cellId;
+            if(cellId>=0)
+              {
+                tmp[j*3+0]=coords[3*cellId+0];
+                tmp[j*3+1]=coords[3*cellId+1];
+                tmp[j*3+2]=coords[3*cellId+2];
+              }
+            else
+              {
+                tmp[j*3+0]=addCoords[3*(-cellId-1)+0];
+                tmp[j*3+1]=addCoords[3*(-cellId-1)+1];
+                tmp[j*3+2]=addCoords[3*(-cellId-1)+2];
+              }
+          }
+        tetra[i]=new SplitterTetra<MyMeshTypeS>(_src_mesh,tmp,tmp2);
+      }
+  }
 
   /*!
    * @param targetCell in C mode.