Salome HOME
0da39e0a04141683cfabcc261f792fa0e0720364
[tools/medcoupling.git] / src / INTERP_KERNEL / MeshElement.txx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D
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, or (at your option) any later version.
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 #ifndef __MESHELEMENT_TXX__
20 #define __MESHELEMENT_TXX__
21
22 #include "MeshElement.hxx"
23
24 #include "TetraAffineTransform.hxx"
25 #include "TransformedTriangle.hxx"
26 #include "MeshUtils.hxx"
27 #include "BoundingBox.hxx"
28 #include <assert.h>
29
30 namespace INTERP_KERNEL
31 {
32
33   /**
34    * Constructor
35    *
36    * @param index   global number of element in the mesh in C mode.
37    * @param mesh    mesh that the element belongs to
38    */
39   template<class ConnType>
40   template<class MyMeshType>
41   MeshElement<ConnType>::MeshElement(const ConnType index, const MyMeshType& mesh)
42     : _index(index), _number(mesh.getNumberOfNodesOfElement(OTT<typename MyMeshType::MyConnType,MyMeshType::My_numPol>::indFC(index))), _box(0)
43   {
44     const double**vertices = new const double*[_number];
45
46     for(unsigned char i = 0 ; i < _number ; ++i)
47       vertices[i] = getCoordsOfNode(i , OTT<typename MyMeshType::MyConnType,MyMeshType::My_numPol>::indFC(index), mesh);
48
49     // create bounding box
50     _box = new BoundingBox(vertices,_number);
51     delete [] vertices;
52   }
53     
54   /**
55    * Destructor
56    *
57    */
58   template<class ConnType>
59   MeshElement<ConnType>::~MeshElement()
60   {
61     delete _box;
62   }
63
64   
65
66   /////////////////////////////////////////////////////////////////////
67   /// ElementBBoxOrder                                    /////////////
68   /////////////////////////////////////////////////////////////////////
69
70   /**
71    * Comparison operator based on the bounding boxes of the elements
72    *
73    * @return true if the coordinate _coord of the bounding box of elem1 is 
74    *          strictly smaller than that of the bounding box of elem2
75    */
76   template<class ConnType>
77   bool ElementBBoxOrder::operator()( MeshElement<ConnType>* elem1, MeshElement<ConnType>* elem2)
78   {
79     const BoundingBox* box1 = elem1->getBoundingBox();
80     const BoundingBox* box2 = elem2->getBoundingBox();
81
82     assert(elem1 != 0);
83     assert(elem2 != 0);
84     assert(box1 != 0);
85     assert(box2 != 0);
86     
87     const double coord1 = box1->getCoordinate(_coord);
88     const double coord2 = box2->getCoordinate(_coord);
89     
90     return coord1 < coord2;
91   }
92
93 }
94
95 #endif