Salome HOME
066a0a45ba8b02ce1509c957f852ab4033484feb
[modules/med.git] / src / MEDMEM / MEDMEM_Extractor.hxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File      : MEDMEM_Extractor.hxx
21 // Created   : Thu Dec 18 10:52:01 2008
22 // Author    : Edward AGAPOV (eap)
23 //
24 #ifndef __MEDMEM_EXTRACTOR_HXX__
25 #define __MEDMEM_EXTRACTOR_HXX__
26
27 #include "MEDMEM_Exception.hxx"
28 #include "MEDMEM_Mesh.hxx"
29 #include "MEDMEM_Field.hxx"
30
31 #include <map>
32 #include <vector>
33 #include <set>
34
35 namespace MEDMEM
36 {
37   /*!
38    * \brief Tool taking an input field and making a field of lower dimension
39    * by cutting the given field by a plane or a line.
40    *
41    * The following extractions are possible: <ul>
42    *<li>  3D -> 2D (3D mesh cut by plane)</li>
43    *<li>  3D -> 1D (3D mesh cut by line)</li>
44    *<li>  2D -> 1D (2D mesh cut by line in 2D space or by plane in 3D space)</li></ul>
45    */
46   class MEDMEM_EXPORT Extractor
47   {
48   /*!
49    * \brief Creates a tool
50    *  \param inputField - input field
51    *
52    * The input field is supposed to comply with following conditions <ul>
53    *<li>  it is constant by element (i.e. has 1 gauss point),</li>
54    *<li>  it's support mesh does not contain poly elements,</li>
55    *<li>  volumic elements have planar faces,</li>
56    *<li>  surfasic elements have linear edges.</li></ul>
57    */
58   public:
59     Extractor(const FIELD<double>& inputField) throw (MEDEXCEPTION);
60     ~Extractor();
61     /*!
62      * \brief Creates a field by cutting inputField by a plane
63      *  \param coords - give a point to pass through by the plane
64      *  \param normal - gives the plane normal
65      *  \retval FIELD<double>* - resulting field holding ownership of its support,
66      *                           which in its turn holds ownership of its mesh
67      */
68     FIELD<double>* extractPlane(const double* coords, const double* normal) throw (MEDEXCEPTION);
69
70     /*!
71      * \brief Creates a field by cutting inputField by a line
72      *  \param coords - give a point to pass through by the line
73      *  \param direction - gives a vector collinear to the line
74      *  \retval FIELD<double>* - resulting field holding ownership of its support,
75      *                           which in its turn holds ownership of its mesh
76      */
77     FIELD<double>* extractLine(const double* coords, const double* direction) throw (MEDEXCEPTION);
78
79   private:
80
81     MESH* divideEdges(const double*       coords,
82                       const double*       normal,
83                       std::map<int,std::set<int> >& new2oldCells);
84                      
85     MESH* transfixFaces( const double*       coords,
86                          const double*       direction,
87                          std::map<int,std::set<int> >& new2oldCells);
88
89     FIELD<double>* makeField( const std::map<int,std::set<int> >& new2oldCells,
90                               MESH*                               mesh) const;
91
92     void computeDistanceOfNodes(const double* point, const double* normal);
93
94     void sortNodes( std::map< int, std::vector< int > >& connByNbNodes,
95                     const double* nodeCoords,
96                     const double* point,
97                     const double* normal,
98                     const std::list<int> & nbNodesPerPolygon);
99
100
101     const FIELD<double>* _myInputField; //!<  input field
102     const MESH*          _myInputMesh;  //!<  unstructured field support mesh
103     std::vector<double>  _myNodeDistance; //!< distance of input nodes to cutting tool
104   };
105 }
106
107 #endif