Salome HOME
Regression of XSMESH_TEST/SMESHCOMMON/SMESH_TEST/Grids/smesh/bugs12/M6
[modules/smesh.git] / src / SMESHUtils / SMESH_TypeDefs.hxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File      : SMESH_TypeDefs.hxx
23 // Created   : Thu Jan 27 18:38:33 2011
24 // Author    : Edward AGAPOV (eap)
25
26
27 #ifndef __SMESH_TypeDefs_HXX__
28 #define __SMESH_TypeDefs_HXX__
29
30 #include "SMESH_Utils.hxx"
31
32 #include <SMDS_MeshNode.hxx>
33
34 #include <gp_XYZ.hxx>
35
36 #include <map>
37 #include <list>
38 #include <set>
39 #include <cassert>
40
41 typedef std::map<const SMDS_MeshElement*,
42                  std::list<const SMDS_MeshElement*>, TIDCompare > TElemOfElemListMap;
43 typedef std::map<const SMDS_MeshElement*,
44                  std::list<const SMDS_MeshNode*>,    TIDCompare > TElemOfNodeListMap;
45 typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*> TNodeNodeMap;
46
47 //!< Set of elements sorted by ID, to be used to assure predictability of edition
48 typedef std::set< const SMDS_MeshElement*, TIDCompare >      TIDSortedElemSet;
49 typedef std::set< const SMDS_MeshNode*,    TIDCompare >      TIDSortedNodeSet;
50
51 typedef std::pair< const SMDS_MeshNode*, const SMDS_MeshNode* >   NLink;
52
53 struct faceQuadStruct; // defined in StdMeshers_Quadrangle_2D.hxx
54 typedef boost::shared_ptr<faceQuadStruct> TFaceQuadStructPtr;
55
56
57 namespace SMESHUtils
58 {
59   /*!
60    * \brief Enforce freeing memory allocated by std::vector
61    */
62   template <class TVECTOR>
63   void FreeVector(TVECTOR& vec)
64   {
65     TVECTOR v2;
66     vec.swap( v2 );
67   }
68   template <class TVECTOR>
69   void CompactVector(TVECTOR& vec)
70   {
71     TVECTOR v2( vec );
72     vec.swap( v2 );
73   }
74 }
75
76 //=======================================================================
77 /*!
78  * \brief A sorted pair of nodes
79  */
80 //=======================================================================
81
82 struct SMESH_TLink: public NLink
83 {
84   SMESH_TLink(const SMDS_MeshNode* n1, const SMDS_MeshNode* n2 ):NLink( n1, n2 )
85   { if ( n1->GetID() < n2->GetID() ) std::swap( first, second ); }
86   SMESH_TLink(const NLink& link ):NLink( link )
87   { if ( first->GetID() < second->GetID() ) std::swap( first, second ); }
88   const SMDS_MeshNode* node1() const { return first; }
89   const SMDS_MeshNode* node2() const { return second; }
90 };
91
92 //=======================================================================
93 /*!
94  * \brief SMESH_TLink knowing its orientation
95  */
96 //=======================================================================
97
98 struct SMESH_OrientedLink: public SMESH_TLink
99 {
100   bool _reversed;
101   SMESH_OrientedLink(const SMDS_MeshNode* n1, const SMDS_MeshNode* n2 )
102     : SMESH_TLink( n1, n2 ), _reversed( n1 != node1() ) {}
103 };
104
105 //------------------------------------------
106 /*!
107  * \brief SMDS_MeshNode -> gp_XYZ convertor
108  */
109 //------------------------------------------
110 struct SMESH_TNodeXYZ : public gp_XYZ
111 {
112   const SMDS_MeshNode* _node;
113   double               _xyz[3];
114   SMESH_TNodeXYZ( const SMDS_MeshElement* e=0):gp_XYZ(0,0,0),_node(0) {
115     if (e) {
116       assert( e->GetType() == SMDSAbs_Node );
117       _node = static_cast<const SMDS_MeshNode*>(e);
118       _node->GetXYZ(_xyz); // - thread safe getting coords
119       SetCoord( _xyz[0], _xyz[1], _xyz[2] );
120     }
121   }
122   double Distance(const SMDS_MeshNode* n)       const { return (SMESH_TNodeXYZ( n )-*this).Modulus(); }
123   double SquareDistance(const SMDS_MeshNode* n) const { return (SMESH_TNodeXYZ( n )-*this).SquareModulus(); }
124   bool operator==(const SMESH_TNodeXYZ& other) const { return _node == other._node; }
125 };
126
127 //--------------------------------------------------
128 /*!
129  * \brief Data of a node generated on FACE boundary
130  */
131 //--------------------------------------------------
132 typedef struct uvPtStruct
133 {
134   double param;
135   double normParam;
136   double u, v; // original 2d parameter
137   double x, y; // 2d parameter, normalized [0,1]
138   const SMDS_MeshNode * node;
139
140   struct NodeAccessor // accessor to iterate on nodes in UVPtStructVec
141   {
142     static const SMDS_MeshNode* value(std::vector< uvPtStruct >::const_iterator it)
143     { return it->node; }
144   };
145 } UVPtStruct;
146
147 typedef std::vector< UVPtStruct > UVPtStructVec;
148
149 // --------------------------------------------------------------------------------
150 // class SMESH_SequenceOfElemPtr
151 #include <NCollection_DefineSequence.hxx>
152
153 class SMDS_MeshElement;
154
155 typedef const SMDS_MeshElement* SMDS_MeshElementPtr;
156
157 DEFINE_BASECOLLECTION (SMESH_BaseCollectionElemPtr, SMDS_MeshElementPtr)
158 DEFINE_SEQUENCE (SMESH_SequenceOfElemPtr, SMESH_BaseCollectionElemPtr, SMDS_MeshElementPtr)
159
160
161 // --------------------------------------------------------------------------------
162 // class SMESH_SequenceOfNode
163 typedef const SMDS_MeshNode* SMDS_MeshNodePtr;
164
165 DEFINE_BASECOLLECTION (SMESH_BaseCollectionNodePtr, SMDS_MeshNodePtr)
166 DEFINE_SEQUENCE(SMESH_SequenceOfNode,
167                 SMESH_BaseCollectionNodePtr, SMDS_MeshNodePtr)
168
169 // --------------------------------------------------------------------------------
170 // #include "SMESHDS_DataMapOfShape.hxx"
171
172 // #include <NCollection_DefineIndexedMap.hxx>
173
174 // #include <TopoDS_Shape.hxx>
175
176 ///  Class SMESH_IndexedMapOfShape
177
178 // DEFINE_BASECOLLECTION (SMESH_BaseCollectionShape, TopoDS_Shape)
179 // DEFINE_INDEXEDMAP (SMESH_IndexedMapOfShape, SMESH_BaseCollectionShape, TopoDS_Shape)
180
181 ///  Class SMESH_IndexedDataMapOfShapeIndexedMapOfShape
182
183 // DEFINE_BASECOLLECTION (SMESH_BaseCollectionIndexedMapOfShape, SMESH_IndexedMapOfShape)
184 // DEFINE_INDEXEDDATAMAP (SMESH_IndexedDataMapOfShapeIndexedMapOfShape,
185 //                        SMESH_BaseCollectionIndexedMapOfShape, TopoDS_Shape,
186 //                        SMESH_IndexedMapOfShape)
187
188 // --------------------------------------------------------------------------------
189 // class SMESH_DataMapOfElemPtrSequenceOfElemPtr
190
191 // SMESHUtils_EXPORT 
192 // inline Standard_Integer HashCode(SMDS_MeshElementPtr theElem,
193 //                                  const Standard_Integer theUpper)
194 // {
195 //   void* anElem = (void*) theElem;
196 //   return HashCode(anElem,theUpper);
197 // }
198
199 // SMESHUtils_EXPORT 
200 // inline Standard_Boolean IsEqual(SMDS_MeshElementPtr theOne,
201 //                                 SMDS_MeshElementPtr theTwo)
202 // {
203 //   return theOne == theTwo;
204 // }
205
206 // DEFINE_BASECOLLECTION (SMESH_BaseCollectionSequenceOfElemPtr, SMESH_SequenceOfElemPtr)
207 // DEFINE_DATAMAP (SMESH_DataMapOfElemPtrSequenceOfElemPtr,
208 //                 SMESH_BaseCollectionSequenceOfElemPtr,
209 //                 SMDS_MeshElementPtr, SMESH_SequenceOfElemPtr)
210
211 #endif