Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / INTERP_KERNEL / MeshElement.txx
1 //  Copyright (C) 2007-2008  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.
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), _box(0), _number(mesh.getNumberOfNodesOfElement(OTT<typename MyMeshType::MyConnType,MyMeshType::My_numPol>::indFC(index)))
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    * Constructor
71    *
72    * @param  coord   BoundingBox coordinate (XMIN, XMAX, etc) on which to base the ordering
73    */
74   ElementBBoxOrder::ElementBBoxOrder(BoundingBox::BoxCoord coord)
75     : _coord(coord)
76   {
77   }
78
79   /**
80    * Comparison operator based on the bounding boxes of the elements
81    *
82    * @return true if the coordinate _coord of the bounding box of elem1 is 
83    *          strictly smaller than that of the bounding box of elem2
84    */
85   template<class ConnType>
86   bool ElementBBoxOrder::operator()( MeshElement<ConnType>* elem1, MeshElement<ConnType>* elem2)
87   {
88     const BoundingBox* box1 = elem1->getBoundingBox();
89     const BoundingBox* box2 = elem2->getBoundingBox();
90
91     assert(elem1 != 0);
92     assert(elem2 != 0);
93     assert(box1 != 0);
94     assert(box2 != 0);
95     
96     const double coord1 = box1->getCoordinate(_coord);
97     const double coord2 = box2->getCoordinate(_coord);
98     
99     return coord1 < coord2;
100   }
101
102 }
103
104 #endif