| 1 |
// Copyright (C) 2007-2015 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 : [email protected] |
| 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*, |
| 47 |
const SMDS_MeshNode*, TIDCompare> TNodeNodeMap; |
| 48 |
|
| 49 |
//!< Set of elements sorted by ID, to be used to assure predictability of edition |
| 50 |
typedef std::set< const SMDS_MeshElement*, TIDCompare > TIDSortedElemSet; |
| 51 |
typedef std::set< const SMDS_MeshNode*, TIDCompare > TIDSortedNodeSet; |
| 52 |
|
| 53 |
typedef std::pair< const SMDS_MeshNode*, const SMDS_MeshNode* > NLink; |
| 54 |
|
| 55 |
struct FaceQuadStruct; // defined in StdMeshers_Quadrangle_2D.hxx |
| 56 |
typedef boost::shared_ptr<FaceQuadStruct> TFaceQuadStructPtr; |
| 57 |
|
| 58 |
|
| 59 |
namespace SMESHUtils |
| 60 |
{ |
| 61 |
/*! |
| 62 |
* \brief Enforce freeing memory allocated by std::vector |
| 63 |
*/ |
| 64 |
template <class TVECTOR> |
| 65 |
void FreeVector(TVECTOR& vec) |
| 66 |
{ |
| 67 |
TVECTOR v2; |
| 68 |
vec.swap( v2 ); |
| 69 |
} |
| 70 |
template <class TVECTOR> |
| 71 |
void CompactVector(TVECTOR& vec) |
| 72 |
{ |
| 73 |
TVECTOR v2( vec ); |
| 74 |
vec.swap( v2 ); |
| 75 |
} |
| 76 |
/*! |
| 77 |
* \brief Auto pointer |
| 78 |
*/ |
| 79 |
template <typename TOBJ> |
| 80 |
struct Deleter |
| 81 |
{ |
| 82 |
TOBJ* _obj; |
| 83 |
Deleter( TOBJ* obj = (TOBJ*)NULL ): _obj( obj ) {} |
| 84 |
~Deleter() { delete _obj; _obj = 0; } |
| 85 |
private: |
| 86 |
Deleter( const Deleter& ); |
| 87 |
}; |
| 88 |
/*! |
| 89 |
* \brief Auto pointer to array |
| 90 |
*/ |
| 91 |
template <typename TOBJ> |
| 92 |
struct ArrayDeleter |
| 93 |
{ |
| 94 |
TOBJ* _obj; |
| 95 |
ArrayDeleter( TOBJ* obj ): _obj( obj ) {} |
| 96 |
~ArrayDeleter() { delete [] _obj; _obj = 0; } |
| 97 |
private: |
| 98 |
ArrayDeleter( const ArrayDeleter& ); |
| 99 |
}; |
| 100 |
} |
| 101 |
|
| 102 |
//======================================================================= |
| 103 |
/*! |
| 104 |
* \brief A sorted pair of nodes |
| 105 |
*/ |
| 106 |
//======================================================================= |
| 107 |
|
| 108 |
struct SMESH_TLink: public NLink |
| 109 |
{ |
| 110 |
SMESH_TLink(const SMDS_MeshNode* n1, const SMDS_MeshNode* n2 ):NLink( n1, n2 ) |
| 111 |
{ if ( n1->GetID() < n2->GetID() ) std::swap( first, second ); } |
| 112 |
SMESH_TLink(const NLink& link ):NLink( link ) |
| 113 |
{ if ( first->GetID() < second->GetID() ) std::swap( first, second ); } |
| 114 |
const SMDS_MeshNode* node1() const { return first; } |
| 115 |
const SMDS_MeshNode* node2() const { return second; } |
| 116 |
}; |
| 117 |
|
| 118 |
//======================================================================= |
| 119 |
/*! |
| 120 |
* \brief SMESH_TLink knowing its orientation |
| 121 |
*/ |
| 122 |
//======================================================================= |
| 123 |
|
| 124 |
struct SMESH_OrientedLink: public SMESH_TLink |
| 125 |
{ |
| 126 |
bool _reversed; |
| 127 |
SMESH_OrientedLink(const SMDS_MeshNode* n1, const SMDS_MeshNode* n2 ) |
| 128 |
: SMESH_TLink( n1, n2 ), _reversed( n1 != node1() ) {} |
| 129 |
}; |
| 130 |
|
| 131 |
//------------------------------------------ |
| 132 |
/*! |
| 133 |
* \brief SMDS_MeshNode -> gp_XYZ converter |
| 134 |
*/ |
| 135 |
//------------------------------------------ |
| 136 |
struct SMESH_TNodeXYZ : public gp_XYZ |
| 137 |
{ |
| 138 |
const SMDS_MeshNode* _node; |
| 139 |
double _xyz[3]; |
| 140 |
SMESH_TNodeXYZ( const SMDS_MeshElement* e=0):gp_XYZ(0,0,0),_node(0) |
| 141 |
{ |
| 142 |
Set(e); |
| 143 |
} |
| 144 |
bool Set( const SMDS_MeshElement* e=0 ) |
| 145 |
{ |
| 146 |
if (e) { |
| 147 |
assert( e->GetType() == SMDSAbs_Node ); |
| 148 |
_node = static_cast<const SMDS_MeshNode*>(e); |
| 149 |
_node->GetXYZ(_xyz); // - thread safe getting coords |
| 150 |
SetCoord( _xyz[0], _xyz[1], _xyz[2] ); |
| 151 |
return true; |
| 152 |
} |
| 153 |
return false; |
| 154 |
} |
| 155 |
double Distance(const SMDS_MeshNode* n) const { return (SMESH_TNodeXYZ( n )-*this).Modulus(); } |
| 156 |
double SquareDistance(const SMDS_MeshNode* n) const { return (SMESH_TNodeXYZ( n )-*this).SquareModulus(); } |
| 157 |
bool operator==(const SMESH_TNodeXYZ& other) const { return _node == other._node; } |
| 158 |
}; |
| 159 |
|
| 160 |
//-------------------------------------------------- |
| 161 |
/*! |
| 162 |
* \brief Data of a node generated on FACE boundary |
| 163 |
*/ |
| 164 |
//-------------------------------------------------- |
| 165 |
typedef struct uvPtStruct |
| 166 |
{ |
| 167 |
double param; |
| 168 |
double normParam; |
| 169 |
double u, v; // original 2d parameter |
| 170 |
double x, y; // 2d parameter, normalized [0,1] |
| 171 |
const SMDS_MeshNode * node; |
| 172 |
|
| 173 |
uvPtStruct(): node(NULL) {} |
| 174 |
|
| 175 |
inline gp_XY UV() const { return gp_XY( u, v ); } |
| 176 |
|
| 177 |
struct NodeAccessor // accessor to iterate on nodes in UVPtStructVec |
| 178 |
{ |
| 179 |
static const SMDS_MeshNode* value(std::vector< uvPtStruct >::const_iterator it) |
| 180 |
{ return it->node; } |
| 181 |
}; |
| 182 |
} UVPtStruct; |
| 183 |
|
| 184 |
typedef std::vector< UVPtStruct > UVPtStructVec; |
| 185 |
|
| 186 |
// -------------------------------------------------------------------------------- |
| 187 |
// class SMESH_SequenceOfElemPtr |
| 188 |
#include <Standard_Version.hxx> |
| 189 |
#if OCC_VERSION_HEX >= 0x060703 |
| 190 |
#include <NCollection_Sequence.hxx> |
| 191 |
#else |
| 192 |
#include <NCollection_DefineSequence.hxx> |
| 193 |
#endif |
| 194 |
|
| 195 |
class SMDS_MeshElement; |
| 196 |
|
| 197 |
typedef const SMDS_MeshElement* SMDS_MeshElementPtr; |
| 198 |
#define DEFINE_SEQUENCE(_ClassName_, _BaseCollection_, TheItemType) \ |
| 199 |
typedef NCollection_Sequence<TheItemType > _ClassName_; |
| 200 |
|
| 201 |
DEFINE_SEQUENCE (SMESH_SequenceOfElemPtr, SMESH_BaseCollectionElemPtr, SMDS_MeshElementPtr) |
| 202 |
|
| 203 |
|
| 204 |
// -------------------------------------------------------------------------------- |
| 205 |
// class SMESH_SequenceOfNode |
| 206 |
typedef const SMDS_MeshNode* SMDS_MeshNodePtr; |
| 207 |
|
| 208 |
DEFINE_SEQUENCE(SMESH_SequenceOfNode, |
| 209 |
SMESH_BaseCollectionNodePtr, SMDS_MeshNodePtr) |
| 210 |
|
| 211 |
#endif |