1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESH_TypeDefs.hxx
23 // Created : Thu Jan 27 18:38:33 2011
24 // Author : Edward AGAPOV (eap)
27 #ifndef __SMESH_TypeDefs_HXX__
28 #define __SMESH_TypeDefs_HXX__
30 #include <Basics_OCCTVersion.hxx>
32 #include "SMESH_Utils.hxx"
34 #include "SMDS_SetIterator.hxx"
35 #include "SMDS_MeshNode.hxx"
37 #include <smIdType.hxx>
41 #include <NCollection_Sequence.hxx>
48 #include <boost/make_shared.hpp>
50 typedef std::map<const SMDS_MeshElement*,
51 std::list<const SMDS_MeshElement*>, TIDCompare > TElemOfElemListMap;
52 typedef std::map<const SMDS_MeshElement*,
53 std::list<const SMDS_MeshNode*>, TIDCompare > TElemOfNodeListMap;
54 typedef std::map<const SMDS_MeshNode*,
55 const SMDS_MeshNode*, TIDCompare> TNodeNodeMap;
57 //!< Set of elements sorted by ID, to be used to assure predictability of edition
58 typedef std::set< const SMDS_MeshElement*, TIDCompare > TIDSortedElemSet;
59 typedef std::set< const SMDS_MeshNode*, TIDCompare > TIDSortedNodeSet;
61 typedef std::pair< const SMDS_MeshNode*, const SMDS_MeshNode* > NLink;
63 struct FaceQuadStruct; // defined in StdMeshers_Quadrangle_2D.hxx
64 typedef boost::shared_ptr<FaceQuadStruct> TFaceQuadStructPtr;
70 * \brief Enforce freeing memory allocated by std::vector
72 template <class TVECTOR>
73 void FreeVector(TVECTOR& vec)
78 template <class TVECTOR>
79 void CompactVector(TVECTOR& vec)
88 template <typename TOBJ>
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; }
98 Deleter( const Deleter& );
102 * \brief Auto pointer to array
104 template <typename TOBJ>
108 ArrayDeleter( TOBJ* obj ): _obj( obj ) {}
109 ~ArrayDeleter() { delete [] _obj; _obj = 0; }
110 operator TOBJ*() { return _obj; }
111 TOBJ* get() { return _obj; }
113 ArrayDeleter( const ArrayDeleter& );
117 * \return SMDS_ElemIteratorPtr on an std container of SMDS_MeshElement's
119 template < class ELEM_SET >
120 SMDS_ElemIteratorPtr elemSetIterator( const ELEM_SET& elements )
122 typedef SMDS_SetIterator
123 < SMDS_pElement, typename ELEM_SET::const_iterator> TSetIterator;
124 return boost::make_shared< TSetIterator >( elements.begin(), elements.end() );
128 * \brief Increment enum value
130 template < typename ENUM >
131 void Increment( ENUM& v, int delta=1 )
133 v = ENUM( int(v)+delta );
137 * \brief Return incremented enum value
139 template < typename ENUM >
140 ENUM Add( ENUM v, int delta )
142 return ENUM( int(v)+delta );
146 //=======================================================================
148 * \brief A sorted pair of nodes
150 //=======================================================================
152 struct SMESH_TLink: public NLink
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; }
161 // methods for usage of SMESH_TLink as a hasher in NCollection maps
162 //static int HashCode(const SMESH_TLink& link, int aLimit)
164 // return smIdHasher::HashCode( link.node1()->GetID() + link.node2()->GetID(), aLimit );
166 //static Standard_Boolean IsEqual(const SMESH_TLink& l1, const SMESH_TLink& l2)
168 // return ( l1.node1() == l2.node1() && l1.node2() == l2.node2() );
171 // a hasher in NCollection maps
172 struct SMESH_TLinkHasher
174 #if OCC_VERSION_LARGE < 0x07080000
175 static int HashCode(const SMESH_TLink& link, int aLimit)
177 return smIdHasher::HashCode( link.node1()->GetID() + link.node2()->GetID(), aLimit );
179 static Standard_Boolean IsEqual(const SMESH_TLink& l1, const SMESH_TLink& l2)
181 return ( l1.node1() == l2.node1() && l1.node2() == l2.node2() );
184 size_t operator()(const SMESH_TLink& link) const
186 return smIdHasher()( link.node1()->GetID() + link.node2()->GetID() );
188 bool operator()(const SMESH_TLink& l1, const SMESH_TLink& l2) const
190 return ( l1.node1() == l2.node1() && l1.node2() == l2.node2() );
194 typedef SMESH_TLink SMESH_Link;
196 //=======================================================================
198 * \brief SMESH_TLink knowing its orientation
200 //=======================================================================
202 struct SMESH_OrientedLink: public SMESH_TLink
205 SMESH_OrientedLink(const SMDS_MeshNode* n1, const SMDS_MeshNode* n2 )
206 : SMESH_TLink( n1, n2 ), _reversed( n1 != node1() ) {}
209 //------------------------------------------
211 * \brief SMDS_MeshNode -> gp_XYZ converter
213 //------------------------------------------
214 struct SMESH_TNodeXYZ : public gp_XYZ
216 const SMDS_MeshNode* _node;
217 SMESH_TNodeXYZ( const SMDS_MeshElement* e=0):gp_XYZ(0,0,0),_node(0)
221 bool Set( const SMDS_MeshElement* e=0 )
224 assert( e->GetType() == SMDSAbs_Node );
225 _node = static_cast<const SMDS_MeshNode*>(e);
226 _node->GetXYZ( ChangeData() ); // - thread safe getting coords
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; }
240 typedef SMESH_TNodeXYZ SMESH_NodeXYZ;
242 // --------------------------------------------------------------------------------
243 // SMESH_Hasher provide methods needed to put mesh data to NCollection maps
247 #if OCC_VERSION_LARGE < 0x07080000
248 static Standard_Integer HashCode(const SMDS_MeshElement* e, const Standard_Integer upper)
250 return smIdHasher::HashCode( e->GetID(), upper );
252 static Standard_Boolean IsEqual( const SMDS_MeshElement* e1, const SMDS_MeshElement* e2 )
257 size_t operator()(const SMDS_MeshElement* e) const
259 return smIdHasher()( e->GetID() );
262 bool operator()(const SMDS_MeshElement* e1, const SMDS_MeshElement* e2) const
269 //--------------------------------------------------
271 * \brief Data of a node generated on FACE boundary
273 //--------------------------------------------------
274 typedef struct uvPtStruct
278 double u, v; // original 2d parameter
279 double x, y; // 2d parameter, normalized [0,1]
280 const SMDS_MeshNode * node;
282 uvPtStruct(const SMDS_MeshNode* n = 0): node(n) {}
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(); }
287 struct NodeAccessor // accessor to iterate on nodes in UVPtStructVec
289 static const SMDS_MeshNode* value(std::vector< uvPtStruct >::const_iterator it)
294 typedef std::vector< UVPtStruct > UVPtStructVec;
296 // --------------------------------------------------------------------------------
297 // class SMESH_SequenceOfElemPtr
299 typedef std::vector< const SMDS_MeshElement* > SMESH_SequenceOfElemPtr;
301 // --------------------------------------------------------------------------------
302 // class SMESH_SequenceOfNode
304 typedef const SMDS_MeshNode* SMDS_MeshNodePtr;
305 typedef NCollection_Sequence< SMDS_MeshNodePtr > SMESH_SequenceOfNode;