25 #ifndef _SMDS_ElementFactory_HeaderFile
26 #define _SMDS_ElementFactory_HeaderFile
31 #include <Utils_SALOME_Exception.hxx>
33 #include <boost/container/flat_set.hpp>
34 #include <boost/dynamic_bitset.hpp>
35 #include <boost/make_shared.hpp>
36 #include <boost/ptr_container/ptr_vector.hpp>
37 #include <boost/shared_ptr.hpp>
43 #include <smIdType.hxx>
106 template<
class ElemIterator >
108 size_t nbElemsToReturn = -1 );
115 template<
class ElemIterator >
117 size_t nbElemsToReturn,
129 virtual void Clear();
133 virtual void Compact(std::vector<smIdType>& idCellsOldToNew);
171 virtual void Clear();
175 virtual void Compact(std::vector<smIdType>& idNodesOldToNew);
185 template<
typename ATTR>
203 template<
class RANGE >
231 return next1st - rangePtr->my1st;
240 bool isFound =
false;
248 if ( it->myValue == theValue )
250 theIndices.push_back( std::make_pair( it->my1st, it->my1st +
Size( it )));
279 if ( r->my1st > theIndex )
281 rNext =
mySet.upper_bound( theIndex );
284 int rSize =
Size( r );
285 attr_t rValue = r->myValue;
286 if ( rValue == theValue )
289 if ( r->my1st == theIndex )
292 ( r->my1st > 0 && ( r-1 )->myValue == theValue );
297 ( rNext !=
mySet.end() && rNext->myValue == theValue );
303 mySet.erase( r, r + 2 );
314 r =
mySet.erase( r );
319 const_cast< attr_t &
>( r->myValue ) = theValue;
331 r =
mySet.insert( r, RANGE( theIndex + 1, rValue )) - 1;
332 const_cast< attr_t &
>( r->myValue ) = theValue;
336 else if ( r->my1st + rSize - 1 == theIndex )
338 if ( rNext !=
mySet.end() && rNext->myValue == theValue )
344 mySet.insert( r, RANGE( theIndex, theValue ));
349 r =
mySet.insert( r, RANGE( theIndex, theValue ));
350 r =
mySet.insert( r, RANGE( theIndex + 1, rValue ));
458 template<
class ELEM_ITERATOR,
class RANGE_SET >
483 size_t theNbElemsToReturn = -1,
484 int theChunkIndex = 0):
535 while ( range.first < range.second && !
myElement )
552 template<
class ElemIterator >
553 boost::shared_ptr< ElemIterator >
555 size_t nbElemsToReturn )
558 return boost::make_shared< TChuckIterator >(
myChunks,
565 template<
class ElemIterator >
566 boost::shared_ptr< ElemIterator >
568 size_t nbElemsToReturn,
571 smIdType iChunk = sm1stElem ? (( sm1stElem->
GetID() - 1 ) /
ChunkSize()) : 0;
573 return boost::make_shared< TChuckIterator >(
myChunks,
std::set< SMDS_ElementChunk *, _ChunkCompare > TChunkPtrSet
Definition: SMDS_ElementFactory.hxx:54
boost::dynamic_bitset TBitSet
Definition: SMDS_ElementFactory.hxx:362
_RangeSet< _UsedRange > TUsedRangeSet
Definition: SMDS_ElementFactory.hxx:361
std::vector< std::pair< int, int > > TIndexRanges
Definition: SMDS_ElementFactory.hxx:197
double TParam
Definition: SMDS_ElementFactory.hxx:364
_RangeSet< _ShapeIDRange > TSubIDRangeSet
Definition: SMDS_ElementFactory.hxx:360
_Range< int > _ShapeIDRange
Definition: SMDS_ElementFactory.hxx:357
_Range< bool > _UsedRange
Definition: SMDS_ElementFactory.hxx:358
boost::ptr_vector< SMDS_ElementChunk > TChunkVector
Definition: SMDS_ElementFactory.hxx:53
Allocate SMDS_MeshElement's (SMDS_MeshCell's or SMDS_MeshNode's ) and bind some attributes to element...
Definition: SMDS_ElementFactory.hxx:374
TUsedRangeSet myUsedRanges
Definition: SMDS_ElementFactory.hxx:379
std::vector< TParam > myPositions
Definition: SMDS_ElementFactory.hxx:384
void Dump() const
Print some data.
Definition: SMDS_ElementFactory.cxx:884
const TUsedRangeSet & GetUsedRangesMinMax(bool &min, bool &max) const
Definition: SMDS_ElementFactory.hxx:420
SMDS_PositionPtr GetPosition(const SMDS_MeshNode *n) const
Return SMDS_Position of a node on a shape.
Definition: SMDS_ElementFactory.cxx:766
smIdType GetID(const SMDS_MeshElement *e) const
Return an SMDS ID of an element.
Definition: SMDS_ElementFactory.cxx:618
smIdType GetUnusedID() const
Return ID of the first non-used element.
Definition: SMDS_ElementFactory.cxx:580
SMDS_MeshElement * myElements
Definition: SMDS_ElementFactory.hxx:376
TBitSet myMarkedSet
Definition: SMDS_ElementFactory.hxx:378
bool IsMarked(const SMDS_MeshElement *e) const
Set isMarked flag of an element.
Definition: SMDS_ElementFactory.cxx:731
TParam * GetPositionPtr(const SMDS_MeshElement *node, bool allocate=false)
Return pointer to on-shape-parameters of a node.
Definition: SMDS_ElementFactory.cxx:831
const TUsedRangeSet & GetUsedRanges() const
Return ranges of used/non-used elements.
Definition: SMDS_ElementFactory.hxx:419
int Index(const SMDS_MeshElement *e) const
Return index of an element in the chunk.
Definition: SMDS_ElementFactory.hxx:410
const SMDS_MeshElement * Element(int index) const
Return an element by an index [0,ChunkSize()].
Definition: SMDS_ElementFactory.hxx:395
SMDS_ElementFactory * myFactory
Definition: SMDS_ElementFactory.hxx:375
void SetShapeID(const SMDS_MeshElement *e, int shapeID) const
Set ID of a shape an element is assigned to.
Definition: SMDS_ElementFactory.cxx:690
int GetShapeID(const SMDS_MeshElement *e) const
Return ID of a shape an element is assigned to.
Definition: SMDS_ElementFactory.cxx:679
void SetIsMarked(const SMDS_MeshElement *e, bool is)
Return isMarked flag of an element.
Definition: SMDS_ElementFactory.cxx:742
void UseElement(const int index)
Mark an element as used.
Definition: SMDS_ElementFactory.cxx:567
smIdType my1stID
Definition: SMDS_ElementFactory.hxx:377
void Compact()
Minimize allocated memory.
Definition: SMDS_ElementFactory.cxx:846
void SetVTKID(const SMDS_MeshElement *e, const vtkIdType id)
Set a Vtk ID of an element.
Definition: SMDS_ElementFactory.cxx:629
void SetPosition(const SMDS_MeshNode *n, const SMDS_PositionPtr &pos, int shapeID)
Set SMDS_Position of a node on a shape.
Definition: SMDS_ElementFactory.cxx:795
static bool IsUsed(const _UsedRange &r)
Check if a given range holds used or non-used elements.
Definition: SMDS_ElementFactory.hxx:407
SMDS_ElementChunk(SMDS_ElementFactory *factory=0, smIdType id0=0)
SMDS_ElementChunk constructor.
Definition: SMDS_ElementFactory.cxx:529
SMDS_Mesh * GetMesh()
Definition: SMDS_ElementFactory.hxx:451
smIdType Get1stID() const
Return ID of the 1st element in the chunk.
Definition: SMDS_ElementFactory.hxx:413
void SetAllNotMarked()
Clear marked flag of all elements.
Definition: SMDS_ElementFactory.cxx:755
TSubIDRangeSet mySubIDRanges
Definition: SMDS_ElementFactory.hxx:380
SMDS_MeshElement * Element(int index)
Return an element by an index [0,ChunkSize()].
Definition: SMDS_ElementFactory.hxx:392
const TSubIDRangeSet & GetSubIDRangesMinMax(int &, int &) const
Return ranges of elements assigned to sub-shapes and min/max of sub-shape IDs.
Definition: SMDS_ElementFactory.hxx:424
vtkIdType GetVtkID(const SMDS_MeshElement *e) const
Return a Vtk ID of an element.
Definition: SMDS_ElementFactory.cxx:667
~SMDS_ElementChunk()
SMDS_ElementChunk destructor.
Definition: SMDS_ElementFactory.cxx:555
void Free(const SMDS_MeshElement *e)
Mark an element as non-used.
Definition: SMDS_ElementFactory.cxx:596
Allocate SMDS_MeshElement's (SMDS_MeshCell's or SMDS_MeshNode's ) and bind some attributes to element...
Definition: SMDS_ElementFactory.hxx:65
smIdType myNbUsedElements
Definition: SMDS_ElementFactory.hxx:73
std::vector< smIdType > mySmdsIDs
Definition: SMDS_ElementFactory.hxx:72
smIdType FromVtkToSmds(vtkIdType vtkID)
Return an SMDS ID by a Vtk one.
Definition: SMDS_ElementFactory.cxx:226
smIdType NbUsedElements() const
Return a number of used elements.
Definition: SMDS_ElementFactory.hxx:101
TChunkVector myChunks
Definition: SMDS_ElementFactory.hxx:69
void SetAllNotMarked()
Clear marked flag of all elements.
Definition: SMDS_ElementFactory.cxx:239
smIdType GetMaxID()
Return maximal ID of an used element.
Definition: SMDS_ElementFactory.cxx:129
SMDS_Mesh * myMesh
Definition: SMDS_ElementFactory.hxx:68
SMDS_MeshElement * NewElement(const smIdType id)
Return an element by ID. NULL if the element with the given ID is already used.
Definition: SMDS_ElementFactory.cxx:172
virtual ~SMDS_ElementFactory()
Destructor.
Definition: SMDS_ElementFactory.cxx:86
const SMDS_MeshElement * FindElement(const smIdType id) const
Return an used element by ID. NULL if the element with the given ID is not yet used.
Definition: SMDS_ElementFactory.cxx:203
void Free(const SMDS_MeshElement *)
Mark the element as non-used.
Definition: SMDS_ElementFactory.cxx:252
std::vector< vtkIdType > myVtkIDs
Definition: SMDS_ElementFactory.hxx:71
SMDS_ElementFactory(SMDS_Mesh *mesh, const bool isNodal=false)
Create a factory of cells or nodes in a given mesh.
Definition: SMDS_ElementFactory.cxx:75
virtual void Clear()
De-allocate all elements.
Definition: SMDS_ElementFactory.cxx:279
TChunkPtrSet myChunksWithUnused
Definition: SMDS_ElementFactory.hxx:70
virtual bool CompactChangePointers()
Return true if Compact() will change IDs of elements.
Definition: SMDS_ElementFactory.cxx:356
boost::shared_ptr< ElemIterator > GetIterator(SMDS_MeshElement::Filter *filter, size_t nbElemsToReturn=-1)
Return an iterator on all element filtered using a given filter.
Definition: SMDS_ElementFactory.hxx:554
smIdType GetMinID()
Return minimal ID of an used element.
Definition: SMDS_ElementFactory.cxx:150
SMDS_MeshCell * NewCell(const smIdType id)
Return a SMDS_MeshCell by ID. NULL if the cell with the given ID is already used.
Definition: SMDS_ElementFactory.hxx:95
virtual void Compact(std::vector< smIdType > &idCellsOldToNew)
Remove unused elements located not at the end of the last chunk.
Definition: SMDS_ElementFactory.cxx:296
smIdType GetFreeID()
Return minimal ID of a non-used element.
Definition: SMDS_ElementFactory.cxx:111
boost::shared_ptr< ElemIterator > GetShapeIterator(int shapeID, size_t nbElemsToReturn, const SMDS_MeshElement *sm1stElem)
Return an iterator on all element assigned to a given shape.
Definition: SMDS_ElementFactory.hxx:567
static int ChunkSize()
Return a number of elements in a chunk.
Definition: SMDS_ElementFactory.cxx:99
bool myIsNodal
Definition: SMDS_ElementFactory.hxx:67
Base class for all cells.
Definition: SMDS_MeshCell.hxx:32
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
Definition: SMDS_Mesh.hxx:53
Allocate SMDS_MeshNode's.
Definition: SMDS_ElementFactory.hxx:147
void SetNbShapes(size_t nbShapes)
Set a total number of sub-shapes in the main shape.
Definition: SMDS_ElementFactory.cxx:491
virtual void Compact(std::vector< smIdType > &idNodesOldToNew)
Remove unused nodes located not at the end of the last chunk.
Definition: SMDS_ElementFactory.cxx:392
SMDS_MeshNode * NewNode(smIdType id)
Return a SMDS_MeshNode by ID. NULL if the node with the given ID is already used.
Definition: SMDS_ElementFactory.hxx:156
virtual void Clear()
De-allocate all nodes.
Definition: SMDS_ElementFactory.cxx:480
int GetShapeDim(int shapeID) const
Return a dimension of a shape.
Definition: SMDS_ElementFactory.cxx:503
const SMDS_MeshNode * FindNode(smIdType id)
Return an used node by ID. NULL if the node with the given ID is not yet used.
Definition: SMDS_ElementFactory.hxx:159
virtual bool CompactChangePointers()
Return true if Compact() will change IDs of node.
Definition: SMDS_ElementFactory.cxx:468
void SetShapeDim(int shapeID, int dim)
Set a dimension of a shape.
Definition: SMDS_ElementFactory.cxx:514
~SMDS_NodeFactory()
Destructor.
Definition: SMDS_ElementFactory.cxx:379
std::vector< char > myShapeDim
Definition: SMDS_ElementFactory.hxx:148
SMDS_NodeFactory(SMDS_Mesh *mesh)
Create a factory of nodes in a given mesh.
Definition: SMDS_ElementFactory.cxx:368
Replace "typedef SMDS_Position* SMDS_PositionPtr" by a smart pointer allowing implicit casting to der...
Definition: SMDS_Position.hxx:58
Filters of elements, to be used with SMDS_SetIterator.
Definition: SMDS_MeshElement.hxx:155
Definition: SMDS_MeshElement.hxx:160
Definition: SMDS_ElementFactory.hxx:50
bool operator()(const SMDS_ElementChunk *c1, const SMDS_ElementChunk *c2) const
Compare SMDS_ElementChunk's.
Definition: SMDS_ElementFactory.cxx:911
Iterator on elements in chunks.
Definition: SMDS_ElementFactory.hxx:460
bool nextInRange()
Definition: SMDS_ElementFactory.hxx:530
int myRangeIndex
Definition: SMDS_ElementFactory.hxx:468
const RANGE_SET &(SMDS_ElementChunk::* get_rangeset_fun)(attr_type &, attr_type &) const
Definition: SMDS_ElementFactory.hxx:464
SMDS_MeshElement::Filter * filter_ptr
Definition: SMDS_ElementFactory.hxx:462
attr_type myValue
Definition: SMDS_ElementFactory.hxx:472
const RANGE_SET & getRangeSet()
Definition: SMDS_ElementFactory.hxx:545
virtual bool more()
Definition: SMDS_ElementFactory.hxx:502
const SMDS_MeshElement * myElement
Definition: SMDS_ElementFactory.hxx:466
get_rangeset_fun myGetRangeSetFun
Definition: SMDS_ElementFactory.hxx:471
size_t myNbElemsToReturn
Definition: SMDS_ElementFactory.hxx:476
attr_type myMinValue
Definition: SMDS_ElementFactory.hxx:473
RANGE_SET::attr_t attr_type
Definition: SMDS_ElementFactory.hxx:463
int myChunkIndex
Definition: SMDS_ElementFactory.hxx:470
attr_type myMaxValue
Definition: SMDS_ElementFactory.hxx:474
size_t myNbReturned
Definition: SMDS_ElementFactory.hxx:477
virtual element_type next()
Definition: SMDS_ElementFactory.hxx:507
_ChunkIterator(const TChunkVector &theChunks, get_rangeset_fun theGetRangeSetFun, attr_type theAttrValue, SMDS_MeshElement::Filter *theFilter, size_t theNbElemsToReturn=-1, int theChunkIndex=0)
Definition: SMDS_ElementFactory.hxx:479
ELEM_ITERATOR::value_type element_type
Definition: SMDS_ElementFactory.hxx:461
const TChunkVector & myChunks
Definition: SMDS_ElementFactory.hxx:469
~_ChunkIterator()
Definition: SMDS_ElementFactory.hxx:497
TIndexRanges myRanges
Definition: SMDS_ElementFactory.hxx:467
filter_ptr myFilter
Definition: SMDS_ElementFactory.hxx:475
Sorted set of ranges.
Definition: SMDS_ElementFactory.hxx:205
set_t mySet
Definition: SMDS_ElementFactory.hxx:210
bool GetIndices(const attr_t theValue, TIndexRanges &theIndices, const attr_t *=0, const attr_t *=0) const
Return ranges of indices (from,to) of elements having a given value.
Definition: SMDS_ElementFactory.hxx:237
int & First(set_iterator rangePtr)
Return a mutable _Range::my1st of a range pointed by an iterator.
Definition: SMDS_ElementFactory.hxx:222
size_t Size(set_iterator rangePtr) const
Return a number of elements in a range pointed by an iterator.
Definition: SMDS_ElementFactory.hxx:227
size_t Size() const
Return a number of ranges.
Definition: SMDS_ElementFactory.hxx:217
_RangeSet()
Definition: SMDS_ElementFactory.hxx:212
set_t::const_iterator set_iterator
Definition: SMDS_ElementFactory.hxx:208
boost::container::flat_set< RANGE > set_t
Definition: SMDS_ElementFactory.hxx:207
RANGE::attr_t attr_t
Definition: SMDS_ElementFactory.hxx:206
attr_t GetValue(int theIndex) const
Return value of an element attribute.
Definition: SMDS_ElementFactory.hxx:263
attr_t SetValue(int theIndex, attr_t theValue)
Change value of an element attribute.
Definition: SMDS_ElementFactory.hxx:275
Range of elements in a chunk having the same attribute value.
Definition: SMDS_ElementFactory.hxx:187
_Range(int i0=0, attr_t v=0)
Definition: SMDS_ElementFactory.hxx:192
ATTR attr_t
Definition: SMDS_ElementFactory.hxx:188
int my1st
Definition: SMDS_ElementFactory.hxx:191
bool operator<(const _Range &other) const
Definition: SMDS_ElementFactory.hxx:194
attr_t myValue
Definition: SMDS_ElementFactory.hxx:190