Salome HOME
Update copyrights 2014.
[modules/smesh.git] / src / SMESHUtils / SMESH_TypeDefs.hxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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 #include <gp_XY.hxx>
36
37 #include <map>
38 #include <list>
39 #include <set>
40 #include <cassert>
41
42 typedef std::map<const SMDS_MeshElement*,
43                  std::list<const SMDS_MeshElement*>, TIDCompare > TElemOfElemListMap;
44 typedef std::map<const SMDS_MeshElement*,
45                  std::list<const SMDS_MeshNode*>,    TIDCompare > TElemOfNodeListMap;
46 typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*>      TNodeNodeMap;
47
48 //!< Set of elements sorted by ID, to be used to assure predictability of edition
49 typedef std::set< const SMDS_MeshElement*, TIDCompare >      TIDSortedElemSet;
50 typedef std::set< const SMDS_MeshNode*,    TIDCompare >      TIDSortedNodeSet;
51
52 typedef std::pair< const SMDS_MeshNode*, const SMDS_MeshNode* >   NLink;
53
54 struct FaceQuadStruct; // defined in StdMeshers_Quadrangle_2D.hxx
55 typedef boost::shared_ptr<FaceQuadStruct> TFaceQuadStructPtr;
56
57
58 namespace SMESHUtils
59 {
60   /*!
61    * \brief Enforce freeing memory allocated by std::vector
62    */
63   template <class TVECTOR>
64   void FreeVector(TVECTOR& vec)
65   {
66     TVECTOR v2;
67     vec.swap( v2 );
68   }
69   template <class TVECTOR>
70   void CompactVector(TVECTOR& vec)
71   {
72     TVECTOR v2( vec );
73     vec.swap( v2 );
74   }
75 }
76
77 //=======================================================================
78 /*!
79  * \brief A sorted pair of nodes
80  */
81 //=======================================================================
82
83 struct SMESH_TLink: public NLink
84 {
85   SMESH_TLink(const SMDS_MeshNode* n1, const SMDS_MeshNode* n2 ):NLink( n1, n2 )
86   { if ( n1->GetID() < n2->GetID() ) std::swap( first, second ); }
87   SMESH_TLink(const NLink& link ):NLink( link )
88   { if ( first->GetID() < second->GetID() ) std::swap( first, second ); }
89   const SMDS_MeshNode* node1() const { return first; }
90   const SMDS_MeshNode* node2() const { return second; }
91 };
92
93 //=======================================================================
94 /*!
95  * \brief SMESH_TLink knowing its orientation
96  */
97 //=======================================================================
98
99 struct SMESH_OrientedLink: public SMESH_TLink
100 {
101   bool _reversed;
102   SMESH_OrientedLink(const SMDS_MeshNode* n1, const SMDS_MeshNode* n2 )
103     : SMESH_TLink( n1, n2 ), _reversed( n1 != node1() ) {}
104 };
105
106 //------------------------------------------
107 /*!
108  * \brief SMDS_MeshNode -> gp_XYZ convertor
109  */
110 //------------------------------------------
111 struct SMESH_TNodeXYZ : public gp_XYZ
112 {
113   const SMDS_MeshNode* _node;
114   double               _xyz[3];
115   SMESH_TNodeXYZ( const SMDS_MeshElement* e=0):gp_XYZ(0,0,0),_node(0) {
116     if (e) {
117       assert( e->GetType() == SMDSAbs_Node );
118       _node = static_cast<const SMDS_MeshNode*>(e);
119       _node->GetXYZ(_xyz); // - thread safe getting coords
120       SetCoord( _xyz[0], _xyz[1], _xyz[2] );
121     }
122   }
123   double Distance(const SMDS_MeshNode* n)       const { return (SMESH_TNodeXYZ( n )-*this).Modulus(); }
124   double SquareDistance(const SMDS_MeshNode* n) const { return (SMESH_TNodeXYZ( n )-*this).SquareModulus(); }
125   bool operator==(const SMESH_TNodeXYZ& other) const { return _node == other._node; }
126 };
127
128 //--------------------------------------------------
129 /*!
130  * \brief Data of a node generated on FACE boundary
131  */
132 //--------------------------------------------------
133 typedef struct uvPtStruct
134 {
135   double param;
136   double normParam;
137   double u, v; // original 2d parameter
138   double x, y; // 2d parameter, normalized [0,1]
139   const SMDS_MeshNode * node;
140
141   uvPtStruct(): node(NULL) {}
142
143   inline gp_XY UV() const { return gp_XY( u, v ); }
144
145   struct NodeAccessor // accessor to iterate on nodes in UVPtStructVec
146   {
147     static const SMDS_MeshNode* value(std::vector< uvPtStruct >::const_iterator it)
148     { return it->node; }
149   };
150 } UVPtStruct;
151
152 typedef std::vector< UVPtStruct > UVPtStructVec;
153
154 // --------------------------------------------------------------------------------
155 // class SMESH_SequenceOfElemPtr
156 #include <NCollection_DefineSequence.hxx>
157
158 class SMDS_MeshElement;
159
160 typedef const SMDS_MeshElement* SMDS_MeshElementPtr;
161
162 DEFINE_BASECOLLECTION (SMESH_BaseCollectionElemPtr, SMDS_MeshElementPtr)
163 DEFINE_SEQUENCE (SMESH_SequenceOfElemPtr, SMESH_BaseCollectionElemPtr, SMDS_MeshElementPtr)
164
165
166 // --------------------------------------------------------------------------------
167 // class SMESH_SequenceOfNode
168 typedef const SMDS_MeshNode* SMDS_MeshNodePtr;
169
170 DEFINE_BASECOLLECTION (SMESH_BaseCollectionNodePtr, SMDS_MeshNodePtr)
171 DEFINE_SEQUENCE(SMESH_SequenceOfNode,
172                 SMESH_BaseCollectionNodePtr, SMDS_MeshNodePtr)
173
174 // --------------------------------------------------------------------------------
175 // #include "SMESHDS_DataMapOfShape.hxx"
176
177 // #include <NCollection_DefineIndexedMap.hxx>
178
179 // #include <TopoDS_Shape.hxx>
180
181 ///  Class SMESH_IndexedMapOfShape
182
183 // DEFINE_BASECOLLECTION (SMESH_BaseCollectionShape, TopoDS_Shape)
184 // DEFINE_INDEXEDMAP (SMESH_IndexedMapOfShape, SMESH_BaseCollectionShape, TopoDS_Shape)
185
186 ///  Class SMESH_IndexedDataMapOfShapeIndexedMapOfShape
187
188 // DEFINE_BASECOLLECTION (SMESH_BaseCollectionIndexedMapOfShape, SMESH_IndexedMapOfShape)
189 // DEFINE_INDEXEDDATAMAP (SMESH_IndexedDataMapOfShapeIndexedMapOfShape,
190 //                        SMESH_BaseCollectionIndexedMapOfShape, TopoDS_Shape,
191 //                        SMESH_IndexedMapOfShape)
192
193 // --------------------------------------------------------------------------------
194 // class SMESH_DataMapOfElemPtrSequenceOfElemPtr
195
196 // SMESHUtils_EXPORT 
197 // inline Standard_Integer HashCode(SMDS_MeshElementPtr theElem,
198 //                                  const Standard_Integer theUpper)
199 // {
200 //   void* anElem = (void*) theElem;
201 //   return HashCode(anElem,theUpper);
202 // }
203
204 // SMESHUtils_EXPORT 
205 // inline Standard_Boolean IsEqual(SMDS_MeshElementPtr theOne,
206 //                                 SMDS_MeshElementPtr theTwo)
207 // {
208 //   return theOne == theTwo;
209 // }
210
211 // DEFINE_BASECOLLECTION (SMESH_BaseCollectionSequenceOfElemPtr, SMESH_SequenceOfElemPtr)
212 // DEFINE_DATAMAP (SMESH_DataMapOfElemPtrSequenceOfElemPtr,
213 //                 SMESH_BaseCollectionSequenceOfElemPtr,
214 //                 SMDS_MeshElementPtr, SMESH_SequenceOfElemPtr)
215
216 #endif