Version: 9.16.0
SMESH_TypeDefs.hxx
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF, 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 <Basics_OCCTVersion.hxx>
31
32#include "SMESH_Utils.hxx"
33
34#include "SMDS_SetIterator.hxx"
35#include "SMDS_MeshNode.hxx"
36
37#include <smIdType.hxx>
38
39#include <gp_XYZ.hxx>
40#include <gp_XY.hxx>
41#include <NCollection_Sequence.hxx>
42
43#include <map>
44#include <list>
45#include <set>
46#include <cassert>
47
48#include <boost/make_shared.hpp>
49
50typedef std::map<const SMDS_MeshElement*,
51 std::list<const SMDS_MeshElement*>, TIDCompare > TElemOfElemListMap;
52typedef std::map<const SMDS_MeshElement*,
53 std::list<const SMDS_MeshNode*>, TIDCompare > TElemOfNodeListMap;
54typedef std::map<const SMDS_MeshNode*,
56
58typedef std::set< const SMDS_MeshElement*, TIDCompare > TIDSortedElemSet;
59typedef std::set< const SMDS_MeshNode*, TIDCompare > TIDSortedNodeSet;
60
61typedef std::pair< const SMDS_MeshNode*, const SMDS_MeshNode* > NLink;
62
63struct FaceQuadStruct; // defined in StdMeshers_Quadrangle_2D.hxx
64typedef boost::shared_ptr<FaceQuadStruct> TFaceQuadStructPtr;
65
66
67namespace SMESHUtils
68{
72 template <class TVECTOR>
73 void FreeVector(TVECTOR& vec)
74 {
75 TVECTOR v2;
76 vec.swap( v2 );
77 }
78 template <class TVECTOR>
79 void CompactVector(TVECTOR& vec)
80 {
81 TVECTOR v2( vec );
82 vec.swap( v2 );
83 }
84
88 template <typename TOBJ>
89 struct Deleter
90 {
91 TOBJ* _obj;
92 explicit Deleter( TOBJ* obj = (TOBJ*)NULL ): _obj( obj ) {}
93 ~Deleter() { delete _obj; _obj = 0; }
94 TOBJ& operator*() const { return *_obj; }
95 TOBJ* operator->() const { return _obj; }
96 operator bool() const { return _obj; }
97 private:
98 Deleter( const Deleter& );
99 };
100
104 template <typename TOBJ>
106 {
107 TOBJ* _obj;
108 ArrayDeleter( TOBJ* obj ): _obj( obj ) {}
109 ~ArrayDeleter() { delete [] _obj; _obj = 0; }
110 operator TOBJ*() { return _obj; }
111 TOBJ* get() { return _obj; }
112 private:
114 };
115
119 template < class ELEM_SET >
120 SMDS_ElemIteratorPtr elemSetIterator( const ELEM_SET& elements )
121 {
122 typedef SMDS_SetIterator
123 < SMDS_pElement, typename ELEM_SET::const_iterator> TSetIterator;
124 return boost::make_shared< TSetIterator >( elements.begin(), elements.end() );
125 }
126
130 template < typename ENUM >
131 void Increment( ENUM& v, int delta=1 )
132 {
133 v = ENUM( int(v)+delta );
134 }
135
139 template < typename ENUM >
140 ENUM Add( ENUM v, int delta )
141 {
142 return ENUM( int(v)+delta );
143 }
144}
145
146//=======================================================================
150//=======================================================================
151
152struct SMESH_TLink: public NLink
153{
154 SMESH_TLink(const SMDS_MeshNode* n1, const SMDS_MeshNode* n2 ):NLink( n1, n2 )
155 { if ( n1->GetID() < n2->GetID() ) std::swap( first, second ); }
156 SMESH_TLink(const NLink& link ):NLink( link )
157 { if ( first->GetID() < second->GetID() ) std::swap( first, second ); }
158 const SMDS_MeshNode* node1() const { return first; }
159 const SMDS_MeshNode* node2() const { return second; }
160
161 // methods for usage of SMESH_TLink as a hasher in NCollection maps
162 //static int HashCode(const SMESH_TLink& link, int aLimit)
163 //{
164 // return smIdHasher::HashCode( link.node1()->GetID() + link.node2()->GetID(), aLimit );
165 //}
166 //static Standard_Boolean IsEqual(const SMESH_TLink& l1, const SMESH_TLink& l2)
167 //{
168 // return ( l1.node1() == l2.node1() && l1.node2() == l2.node2() );
169 //}
170};
171// a hasher in NCollection maps
173{
174#if OCC_VERSION_LARGE < 0x07080000
175 static int HashCode(const SMESH_TLink& link, int aLimit)
176 {
177 return smIdHasher::HashCode( link.node1()->GetID() + link.node2()->GetID(), aLimit );
178 }
179 static Standard_Boolean IsEqual(const SMESH_TLink& l1, const SMESH_TLink& l2)
180 {
181 return ( l1.node1() == l2.node1() && l1.node2() == l2.node2() );
182 }
183#else
184 size_t operator()(const SMESH_TLink& link) const
185 {
186 return smIdHasher()( link.node1()->GetID() + link.node2()->GetID() );
187 }
188 bool operator()(const SMESH_TLink& l1, const SMESH_TLink& l2) const
189 {
190 return ( l1.node1() == l2.node1() && l1.node2() == l2.node2() );
191 }
192#endif
193};
195
196//=======================================================================
200//=======================================================================
201
203{
206 : SMESH_TLink( n1, n2 ), _reversed( n1 != node1() ) {}
207};
208
209//------------------------------------------
213//------------------------------------------
214struct SMESH_TNodeXYZ : public gp_XYZ
215{
217 SMESH_TNodeXYZ( const SMDS_MeshElement* e=0):gp_XYZ(0,0,0),_node(0)
218 {
219 Set(e);
220 }
221 bool Set( const SMDS_MeshElement* e=0 )
222 {
223 if (e) {
224 assert( e->GetType() == SMDSAbs_Node );
225 _node = static_cast<const SMDS_MeshNode*>(e);
226 _node->GetXYZ( ChangeData() ); // - thread safe getting coords
227 return true;
228 }
229 return false;
230 }
231 void SetXYZ( const gp_XYZ& p ) { SetCoord( p.X(), p.Y(), p.Z() ); }
232 const SMDS_MeshNode* Node() const { return _node; }
233 double Distance(const SMDS_MeshNode* n) const { return (SMESH_TNodeXYZ( n )-*this).Modulus(); }
234 double SquareDistance(const SMDS_MeshNode* n) const { return (SMESH_TNodeXYZ( n )-*this).SquareModulus(); }
235 bool operator==(const SMESH_TNodeXYZ& other) const { return _node == other._node; }
236 bool operator!=(const SMESH_TNodeXYZ& other) const { return _node != other._node; }
237 bool operator!() const { return !_node; }
238 const SMDS_MeshNode* operator->() const { return _node; }
239};
241
242// --------------------------------------------------------------------------------
243// SMESH_Hasher provide methods needed to put mesh data to NCollection maps
244
246{
247#if OCC_VERSION_LARGE < 0x07080000
248 static Standard_Integer HashCode(const SMDS_MeshElement* e, const Standard_Integer upper)
249 {
250 return smIdHasher::HashCode( e->GetID(), upper );
251 }
252 static Standard_Boolean IsEqual( const SMDS_MeshElement* e1, const SMDS_MeshElement* e2 )
253 {
254 return ( e1 == e2 );
255 }
256#else
257 size_t operator()(const SMDS_MeshElement* e) const
258 {
259 return smIdHasher()( e->GetID() );
260 }
261
262 bool operator()(const SMDS_MeshElement* e1, const SMDS_MeshElement* e2) const
263 {
264 return ( e1 == e2 );
265 }
266#endif
267};
268
269//--------------------------------------------------
273//--------------------------------------------------
274typedef struct uvPtStruct
275{
276 double param;
277 double normParam;
278 double u, v; // original 2d parameter
279 double x, y; // 2d parameter, normalized [0,1]
281
282 uvPtStruct(const SMDS_MeshNode* n = 0): node(n) {}
283
284 inline gp_XY UV() const { return gp_XY( u, v ); }
285 inline void SetUV( const gp_XY& uv ) { u = uv.X(); v = uv.Y(); }
286
287 struct NodeAccessor // accessor to iterate on nodes in UVPtStructVec
288 {
289 static const SMDS_MeshNode* value(std::vector< uvPtStruct >::const_iterator it)
290 { return it->node; }
291 };
293
294typedef std::vector< UVPtStruct > UVPtStructVec;
295
296// --------------------------------------------------------------------------------
297// class SMESH_SequenceOfElemPtr
298
299typedef std::vector< const SMDS_MeshElement* > SMESH_SequenceOfElemPtr;
300
301// --------------------------------------------------------------------------------
302// class SMESH_SequenceOfNode
303
305typedef NCollection_Sequence< SMDS_MeshNodePtr > SMESH_SequenceOfNode;
306
307#endif
@ SMDSAbs_Node
Definition: SMDSAbs_ElementType.hxx:36
boost::shared_ptr< SMDS_Iterator< const SMDS_MeshElement * > > SMDS_ElemIteratorPtr
Definition: SMDS_ElemIterator.hxx:43
const SMDS_MeshElement * SMDS_pElement
Definition: SMDS_SetIterator.hxx:188
SMESH_TNodeXYZ SMESH_NodeXYZ
Definition: SMESH_TypeDefs.hxx:240
boost::shared_ptr< FaceQuadStruct > TFaceQuadStructPtr
Definition: SMESH_TypeDefs.hxx:64
NCollection_Sequence< SMDS_MeshNodePtr > SMESH_SequenceOfNode
Definition: SMESH_TypeDefs.hxx:305
std::map< const SMDS_MeshElement *, std::list< const SMDS_MeshNode * >, TIDCompare > TElemOfNodeListMap
Definition: SMESH_TypeDefs.hxx:53
SMESH_TLink SMESH_Link
Definition: SMESH_TypeDefs.hxx:194
std::map< const SMDS_MeshNode *, const SMDS_MeshNode *, TIDCompare > TNodeNodeMap
Set of elements sorted by ID, to be used to assure predictability of edition.
Definition: SMESH_TypeDefs.hxx:55
std::set< const SMDS_MeshNode *, TIDCompare > TIDSortedNodeSet
Definition: SMESH_TypeDefs.hxx:59
std::pair< const SMDS_MeshNode *, const SMDS_MeshNode * > NLink
Definition: SMESH_TypeDefs.hxx:61
std::map< const SMDS_MeshElement *, std::list< const SMDS_MeshElement * >, TIDCompare > TElemOfElemListMap
Definition: SMESH_TypeDefs.hxx:51
struct uvPtStruct UVPtStruct
Data of a node generated on FACE boundary.
const SMDS_MeshNode * SMDS_MeshNodePtr
Definition: SMESH_TypeDefs.hxx:304
std::set< const SMDS_MeshElement *, TIDCompare > TIDSortedElemSet
Definition: SMESH_TypeDefs.hxx:58
std::vector< UVPtStruct > UVPtStructVec
Definition: SMESH_TypeDefs.hxx:294
std::vector< const SMDS_MeshElement * > SMESH_SequenceOfElemPtr
Definition: SMESH_TypeDefs.hxx:299
Base class for elements.
Definition: SMDS_MeshElement.hxx:56
virtual smIdType GetID() const
Return ID of an element.
Definition: SMDS_MeshElement.cxx:108
Definition: SMDS_MeshNode.hxx:36
void GetXYZ(double xyz[3]) const
thread safe getting coords
Definition: SMDS_MeshNode.cxx:241
SMDS_Iterator iterating over abstract set of values like STL containers.
Definition: SMDS_SetIterator.hxx:88
Definition: SMESH_BoostTxtArchive.hxx:35
void FreeVector(TVECTOR &vec)
Enforce freeing memory allocated by std::vector.
Definition: SMESH_TypeDefs.hxx:73
SMDS_ElemIteratorPtr elemSetIterator(const ELEM_SET &elements)
Definition: SMESH_TypeDefs.hxx:120
ENUM Add(ENUM v, int delta)
Return incremented enum value.
Definition: SMESH_TypeDefs.hxx:140
void CompactVector(TVECTOR &vec)
Definition: SMESH_TypeDefs.hxx:79
void Increment(ENUM &v, int delta=1)
Increment enum value.
Definition: SMESH_TypeDefs.hxx:131
Definition: StdMeshers_Quadrangle_2D.hxx:50
Auto pointer to array.
Definition: SMESH_TypeDefs.hxx:106
ArrayDeleter(const ArrayDeleter &)
TOBJ * _obj
Definition: SMESH_TypeDefs.hxx:107
TOBJ * get()
Definition: SMESH_TypeDefs.hxx:111
ArrayDeleter(TOBJ *obj)
Definition: SMESH_TypeDefs.hxx:108
~ArrayDeleter()
Definition: SMESH_TypeDefs.hxx:109
Auto pointer.
Definition: SMESH_TypeDefs.hxx:90
TOBJ * _obj
Definition: SMESH_TypeDefs.hxx:91
~Deleter()
Definition: SMESH_TypeDefs.hxx:93
Deleter(const Deleter &)
TOBJ * operator->() const
Definition: SMESH_TypeDefs.hxx:95
Deleter(TOBJ *obj=(TOBJ *) NULL)
Definition: SMESH_TypeDefs.hxx:92
TOBJ & operator*() const
Definition: SMESH_TypeDefs.hxx:94
Definition: SMESH_TypeDefs.hxx:246
static Standard_Boolean IsEqual(const SMDS_MeshElement *e1, const SMDS_MeshElement *e2)
Definition: SMESH_TypeDefs.hxx:252
static Standard_Integer HashCode(const SMDS_MeshElement *e, const Standard_Integer upper)
Definition: SMESH_TypeDefs.hxx:248
Definition: SMESH_TypeDefs.hxx:173
static int HashCode(const SMESH_TLink &link, int aLimit)
Definition: SMESH_TypeDefs.hxx:175
static Standard_Boolean IsEqual(const SMESH_TLink &l1, const SMESH_TLink &l2)
Definition: SMESH_TypeDefs.hxx:179
SMDS_MeshNode -> gp_XYZ converter.
Definition: SMESH_TypeDefs.hxx:215
SMESH_TNodeXYZ(const SMDS_MeshElement *e=0)
Definition: SMESH_TypeDefs.hxx:217
const SMDS_MeshNode * Node() const
Definition: SMESH_TypeDefs.hxx:232
double Distance(const SMDS_MeshNode *n) const
Definition: SMESH_TypeDefs.hxx:233
bool operator!() const
Definition: SMESH_TypeDefs.hxx:237
double SquareDistance(const SMDS_MeshNode *n) const
Definition: SMESH_TypeDefs.hxx:234
const SMDS_MeshNode * operator->() const
Definition: SMESH_TypeDefs.hxx:238
bool operator!=(const SMESH_TNodeXYZ &other) const
Definition: SMESH_TypeDefs.hxx:236
bool Set(const SMDS_MeshElement *e=0)
Definition: SMESH_TypeDefs.hxx:221
void SetXYZ(const gp_XYZ &p)
Definition: SMESH_TypeDefs.hxx:231
const SMDS_MeshNode * _node
Definition: SMESH_TypeDefs.hxx:216
bool operator==(const SMESH_TNodeXYZ &other) const
Definition: SMESH_TypeDefs.hxx:235
Definition: SMDS_MeshElement.hxx:209
Definition: SMESH_TypeDefs.hxx:288
static const SMDS_MeshNode * value(std::vector< uvPtStruct >::const_iterator it)
Definition: SMESH_TypeDefs.hxx:289
Data of a node generated on FACE boundary.
Definition: SMESH_TypeDefs.hxx:275
uvPtStruct(const SMDS_MeshNode *n=0)
Definition: SMESH_TypeDefs.hxx:282
double param
Definition: SMESH_TypeDefs.hxx:276
double y
Definition: SMESH_TypeDefs.hxx:279
double normParam
Definition: SMESH_TypeDefs.hxx:277
double u
Definition: SMESH_TypeDefs.hxx:278
double x
Definition: SMESH_TypeDefs.hxx:279
const SMDS_MeshNode * node
Definition: SMESH_TypeDefs.hxx:280
gp_XY UV() const
Definition: SMESH_TypeDefs.hxx:284
double v
Definition: SMESH_TypeDefs.hxx:278
void SetUV(const gp_XY &uv)
Definition: SMESH_TypeDefs.hxx:285