X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMDS%2FSMDS_ElementFactory.cxx;h=c3ab97c8c9444829f709486d0806ab1f3b60f812;hp=a6d61e8496bf5570fa4ae783b67a4cc62534a6b4;hb=HEAD;hpb=4c16067d4281f56bd07d3f92fb63fff9c0c1d169 diff --git a/src/SMDS/SMDS_ElementFactory.cxx b/src/SMDS/SMDS_ElementFactory.cxx index a6d61e849..e13af2db3 100644 --- a/src/SMDS/SMDS_ElementFactory.cxx +++ b/src/SMDS/SMDS_ElementFactory.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -104,15 +104,15 @@ int SMDS_ElementFactory::ChunkSize() //================================================================================ /*! * \brief Return minimal ID of a non-used element - * \return int - minimal element ID + * \return smIdType - minimal element ID */ //================================================================================ -int SMDS_ElementFactory::GetFreeID() +smIdType SMDS_ElementFactory::GetFreeID() { if ( myChunksWithUnused.empty() ) { - int id0 = myChunks.size() * theChunkSize + 1; + smIdType id0 = myChunks.size() * theChunkSize + 1; myChunks.push_back( new SMDS_ElementChunk( this, id0 )); } SMDS_ElementChunk * chunk = (*myChunksWithUnused.begin()); @@ -122,15 +122,15 @@ int SMDS_ElementFactory::GetFreeID() //================================================================================ /*! * \brief Return maximal ID of an used element - * \return int - element ID + * \return smIdType - element ID */ //================================================================================ -int SMDS_ElementFactory::GetMaxID() +smIdType SMDS_ElementFactory::GetMaxID() { - int id = 0; + smIdType id = 0; TIndexRanges usedRanges; - for ( int i = myChunks.size() - 1; i >= 0; --i ) + for ( smIdType i = myChunks.size() - 1; i >= 0; --i ) if ( myChunks[i].GetUsedRanges().GetIndices( true, usedRanges )) { int index = usedRanges.back().second-1; @@ -143,13 +143,13 @@ int SMDS_ElementFactory::GetMaxID() //================================================================================ /*! * \brief Return minimal ID of an used element - * \return int - element ID + * \return smIdType - element ID */ //================================================================================ -int SMDS_ElementFactory::GetMinID() +smIdType SMDS_ElementFactory::GetMinID() { - int id = 0; + smIdType id = 0; TIndexRanges usedRanges; for ( size_t i = 0; i < myChunks.size(); ++i ) if ( myChunks[i].GetUsedRanges().GetIndices( true, usedRanges )) @@ -169,20 +169,20 @@ int SMDS_ElementFactory::GetMinID() */ //================================================================================ -SMDS_MeshElement* SMDS_ElementFactory::NewElement( const int id ) +SMDS_MeshElement* SMDS_ElementFactory::NewElement( const smIdType id ) { - int iChunk = ( id - 1 ) / theChunkSize; - int index = ( id - 1 ) % theChunkSize; - while ((int) myChunks.size() <= iChunk ) + smIdType iChunk = ( id - 1 ) / theChunkSize; + smIdType index = ( id - 1 ) % theChunkSize; + while ((smIdType) myChunks.size() <= iChunk ) { - int id0 = myChunks.size() * theChunkSize + 1; + smIdType id0 = myChunks.size() * theChunkSize + 1; myChunks.push_back( new SMDS_ElementChunk( this, id0 )); } - SMDS_MeshElement* e = myChunks[iChunk].Element( index ); + SMDS_MeshElement* e = myChunks[iChunk].Element( FromSmIdType(index) ); if ( !e->IsNull() ) return 0; // element with given ID already exists - myChunks[iChunk].UseElement( index ); + myChunks[iChunk].UseElement( FromSmIdType(index) ); ++myNbUsedElements; e->myHolder = & myChunks[iChunk]; @@ -200,15 +200,15 @@ SMDS_MeshElement* SMDS_ElementFactory::NewElement( const int id ) */ //================================================================================ -const SMDS_MeshElement* SMDS_ElementFactory::FindElement( const int id ) const +const SMDS_MeshElement* SMDS_ElementFactory::FindElement( const smIdType id ) const { if ( id > 0 ) { - int iChunk = ( id - 1 ) / theChunkSize; - int index = ( id - 1 ) % theChunkSize; - if ( iChunk < (int) myChunks.size() ) + smIdType iChunk = ( id - 1 ) / theChunkSize; + smIdType index = ( id - 1 ) % theChunkSize; + if ( iChunk < (smIdType) myChunks.size() ) { - const SMDS_MeshElement* e = myChunks[iChunk].Element( index ); + const SMDS_MeshElement* e = myChunks[iChunk].Element( FromSmIdType(index) ); return e->IsNull() ? 0 : e; } } @@ -218,18 +218,30 @@ const SMDS_MeshElement* SMDS_ElementFactory::FindElement( const int id ) const //================================================================================ /*! * \brief Return an SMDS ID by a Vtk one - * \param [inout] vtkID - Vtk ID - * \return int - SMDS ID + * \param [in] vtkID - Vtk ID + * \return smIdType - SMDS ID */ //================================================================================ -int SMDS_ElementFactory::FromVtkToSmds( vtkIdType vtkID ) +smIdType SMDS_ElementFactory::FromVtkToSmds( vtkIdType vtkID ) { if ( vtkID >= 0 && vtkID < (vtkIdType)mySmdsIDs.size() ) return mySmdsIDs[vtkID] + 1; return vtkID + 1; } +//================================================================================ +/*! + * \brief Clear marked flag of all elements + */ +//================================================================================ + +void SMDS_ElementFactory::SetAllNotMarked() +{ + for ( SMDS_ElementChunk& chunk : myChunks ) + chunk.SetAllNotMarked(); +} + //================================================================================ /*! * \brief Mark the element as non-used @@ -239,6 +251,9 @@ int SMDS_ElementFactory::FromVtkToSmds( vtkIdType vtkID ) void SMDS_ElementFactory::Free( const SMDS_MeshElement* e ) { + if ( e != FindElement( e->GetID() )) + SALOME_Exception("SMDS_ElementFactory::Free(): element of other mesh"); + if ( !myVtkIDs.empty() ) { size_t id = e->GetID() - 1; @@ -278,11 +293,11 @@ void SMDS_ElementFactory::Clear() */ //================================================================================ -void SMDS_ElementFactory::Compact( std::vector& theVtkIDsNewToOld ) +void SMDS_ElementFactory::Compact( std::vector& theVtkIDsNewToOld ) { - int newNbCells = NbUsedElements(); - int maxCellID = GetMaxID(); - int newNbChunks = newNbCells / theChunkSize + bool ( newNbCells % theChunkSize ); + smIdType newNbCells = NbUsedElements(); + smIdType maxCellID = GetMaxID(); + smIdType newNbChunks = newNbCells / theChunkSize + bool ( newNbCells % theChunkSize ); theVtkIDsNewToOld.resize( newNbCells ); @@ -292,7 +307,7 @@ void SMDS_ElementFactory::Compact( std::vector& theVtkIDsNewToOld ) } else if ( newNbCells == maxCellID ) // no holes { - int newID, minLastID = std::min( myVtkIDs.size(), theVtkIDsNewToOld.size() ); + smIdType newID, minLastID = std::min( myVtkIDs.size(), theVtkIDsNewToOld.size() ); for ( newID = 0; newID < minLastID; ++newID ) theVtkIDsNewToOld[ newID ] = myVtkIDs[ newID ]; for ( ; newID < newNbCells; ++newID ) @@ -300,8 +315,8 @@ void SMDS_ElementFactory::Compact( std::vector& theVtkIDsNewToOld ) } else // there are holes in SMDS IDs { - int newVtkID = 0; // same as new smds ID (-1) - for ( int oldID = 1; oldID <= maxCellID; ++oldID ) // smds IDs + smIdType newVtkID = 0; // same as new smds ID (-1) + for ( smIdType oldID = 1; oldID <= maxCellID; ++oldID ) // smds IDs { const SMDS_MeshElement* oldElem = FindElement( oldID ); if ( !oldElem ) continue; @@ -374,16 +389,16 @@ SMDS_NodeFactory::~SMDS_NodeFactory() */ //================================================================================ -void SMDS_NodeFactory::Compact( std::vector& theVtkIDsOldToNew ) +void SMDS_NodeFactory::Compact( std::vector& theVtkIDsOldToNew ) { // IDs of VTK nodes always correspond to SMDS IDs but there can be "holes" // in the chunks. So we remove holes and report relocation in theVtkIDsOldToNew: // theVtkIDsOldToNew[ old VtkID ] = new VtkID - int oldNbNodes = myMesh->GetGrid()->GetNumberOfPoints(); - int newNbNodes = NbUsedElements(); - int newNbChunks = newNbNodes / theChunkSize + bool ( newNbNodes % theChunkSize ); - int maxNodeID = GetMaxID(); + smIdType oldNbNodes = myMesh->GetGrid()->GetNumberOfPoints(); + smIdType newNbNodes = NbUsedElements(); + smIdType newNbChunks = newNbNodes / theChunkSize + bool ( newNbNodes % theChunkSize ); + smIdType maxNodeID = GetMaxID(); theVtkIDsOldToNew.resize( oldNbNodes, -1 ); @@ -405,13 +420,13 @@ void SMDS_NodeFactory::Compact( std::vector& theVtkIDsOldToNew ) const SMDS_MeshElement* newNode = FindElement( newID+1 ); if ( !newNode ) newNode = NewElement( newID+1 ); - int shapeID = oldNode->GetShapeID(); - int shapeDim = GetShapeDim( shapeID ); - int iChunk = newID / theChunkSize; + int shapeID = oldNode->GetShapeID(); + int shapeDim = GetShapeDim( shapeID ); + smIdType iChunk = newID / theChunkSize; myChunks[ iChunk ].SetShapeID( newNode, shapeID ); if ( shapeDim == 2 || shapeDim == 1 ) { - int iChunkOld = oldID / theChunkSize; + smIdType iChunkOld = oldID / theChunkSize; TParam* oldPos = myChunks[ iChunkOld ].GetPositionPtr( oldNode ); TParam* newPos = myChunks[ iChunk ].GetPositionPtr( newNode, /*allocate=*/true ); if ( oldPos ) @@ -428,7 +443,7 @@ void SMDS_NodeFactory::Compact( std::vector& theVtkIDsOldToNew ) } else // no holes { - for ( int i = 0; i < newNbNodes; ++i ) + for ( smIdType i = 0; i < newNbNodes; ++i ) theVtkIDsOldToNew[ i ] = i; } myChunks.resize( newNbChunks ); @@ -511,11 +526,12 @@ void SMDS_NodeFactory::SetShapeDim( int shapeID, int dim ) */ //================================================================================ -SMDS_ElementChunk::SMDS_ElementChunk( SMDS_ElementFactory* factory, int id0 ): +SMDS_ElementChunk::SMDS_ElementChunk( SMDS_ElementFactory* factory, smIdType id0 ): myFactory( factory ), - my1stID( id0 ), - myMinSubID( std::numeric_limits::max() ), - myMaxSubID( 0 ) + my1stID( id0 )//, + //mySubIDSet( 0 ) + // myMinSubID( std::numeric_limits::max() ), + // myMaxSubID( 0 ) { if ( !myFactory ) return; @@ -561,7 +577,7 @@ void SMDS_ElementChunk::UseElement( const int index ) */ //================================================================================ -int SMDS_ElementChunk::GetUnusedID() const +smIdType SMDS_ElementChunk::GetUnusedID() const { TUsedRangeSet::set_iterator r = myUsedRanges.mySet.begin(); for ( ; r != myUsedRanges.mySet.end(); ++r ) @@ -599,7 +615,7 @@ void SMDS_ElementChunk::Free( const SMDS_MeshElement* e ) */ //================================================================================ -int SMDS_ElementChunk::GetID( const SMDS_MeshElement* e ) const +smIdType SMDS_ElementChunk::GetID( const SMDS_MeshElement* e ) const { return my1stID + Index( e ); } @@ -614,11 +630,12 @@ void SMDS_ElementChunk::SetVTKID( const SMDS_MeshElement* e, const vtkIdType vtk { if ( e->GetID() - 1 != vtkID ) { - if ((int) myFactory->myVtkIDs.size() <= e->GetID() - 1 ) + if ((smIdType) myFactory->myVtkIDs.size() <= e->GetID() - 1 ) { - size_t i = myFactory->myVtkIDs.size(); + vtkIdType i = (vtkIdType) myFactory->myVtkIDs.size(); myFactory->myVtkIDs.resize( e->GetID() + 100 ); - for ( ; i < myFactory->myVtkIDs.size(); ++i ) + vtkIdType newSize = (vtkIdType) myFactory->myVtkIDs.size(); + for ( ; i < newSize; ++i ) myFactory->myVtkIDs[i] = i; } myFactory->myVtkIDs[ e->GetID() - 1 ] = vtkID; @@ -632,6 +649,13 @@ void SMDS_ElementChunk::SetVTKID( const SMDS_MeshElement* e, const vtkIdType vtk } myFactory->mySmdsIDs[ vtkID ] = e->GetID() - 1; } + else + { + if ((size_t) e->GetID() <= myFactory->myVtkIDs.size() ) + myFactory->myVtkIDs[ e->GetID() - 1 ] = vtkID; + if ((size_t) vtkID < myFactory->mySmdsIDs.size() ) + myFactory->mySmdsIDs[ vtkID ] = e->GetID() - 1; + } } //================================================================================ @@ -640,10 +664,10 @@ void SMDS_ElementChunk::SetVTKID( const SMDS_MeshElement* e, const vtkIdType vtk */ //================================================================================ -int SMDS_ElementChunk::GetVtkID( const SMDS_MeshElement* e ) const +vtkIdType SMDS_ElementChunk::GetVtkID( const SMDS_MeshElement* e ) const { - size_t dfltVtkID = e->GetID() - 1; - return ( dfltVtkID < myFactory->myVtkIDs.size() ) ? myFactory->myVtkIDs[ dfltVtkID ] : dfltVtkID; + vtkIdType dfltVtkID = FromSmIdType(e->GetID() - 1); + return ( dfltVtkID < (vtkIdType)myFactory->myVtkIDs.size() ) ? myFactory->myVtkIDs[ dfltVtkID ] : dfltVtkID; } //================================================================================ @@ -665,7 +689,7 @@ int SMDS_ElementChunk::GetShapeID( const SMDS_MeshElement* e ) const void SMDS_ElementChunk::SetShapeID( const SMDS_MeshElement* e, int shapeID ) const { - const size_t nbRanges = mySubIDRanges.Size(); + //const size_t nbRanges = mySubIDRanges.Size(); SMDS_ElementChunk* me = const_cast( this ); int oldShapeID = me->mySubIDRanges.SetValue( Index( e ), shapeID ); @@ -678,24 +702,24 @@ void SMDS_ElementChunk::SetShapeID( const SMDS_MeshElement* e, int shapeID ) con uv[1] = 0.; } // update min/max - if (( nbRanges > mySubIDRanges.Size() ) && - ( myMinSubID == oldShapeID || myMaxSubID == oldShapeID )) - { - me->myMinSubID = ( std::numeric_limits::max() ); - me->myMaxSubID = 0; - TSubIDRangeSet::set_iterator it; - for ( it = mySubIDRanges.mySet.begin(); it < mySubIDRanges.mySet.end(); ++it ) - if ( it->myValue > 0 ) - { - me->myMinSubID = std::min( myMinSubID, it->myValue ); - me->myMaxSubID = std::max( myMaxSubID, it->myValue ); - } - } - else if ( shapeID > 0 ) - { - me->myMinSubID = std::min( myMinSubID, shapeID ); - me->myMaxSubID = std::max( myMaxSubID, shapeID ); - } + // if (( nbRanges > mySubIDRanges.Size() ) && + // ( myMinSubID == oldShapeID || myMaxSubID == oldShapeID )) + // { + // me->myMinSubID = ( std::numeric_limits::max() ); + // me->myMaxSubID = 0; + // TSubIDRangeSet::set_iterator it; + // for ( it = mySubIDRanges.mySet.begin(); it < mySubIDRanges.mySet.end(); ++it ) + // if ( it->myValue > 0 ) + // { + // me->myMinSubID = std::min( myMinSubID, it->myValue ); + // me->myMaxSubID = std::max( myMaxSubID, it->myValue ); + // } + // } + // else if ( shapeID > 0 ) + // { + // me->myMinSubID = std::min( myMinSubID, shapeID ); + // me->myMaxSubID = std::max( myMaxSubID, shapeID ); + // } } //================================================================================ @@ -722,6 +746,17 @@ void SMDS_ElementChunk::SetIsMarked( const SMDS_MeshElement* e, bool is ) myMarkedSet[ Index( e )] = is; } +//================================================================================ +/*! + * \brief Clear marked flag of all elements + */ +//================================================================================ + +void SMDS_ElementChunk::SetAllNotMarked() +{ + clearVector( myMarkedSet ); +} + //================================================================================ /*! * \brief Return SMDS_Position of a node on a shape @@ -850,7 +885,7 @@ void SMDS_ElementChunk::Dump() const { std::cout << "1stID: " << my1stID << std::endl; - std::cout << "SubID min/max: " << myMinSubID << ", " << myMaxSubID << std::endl; + //std::cout << "SubID min/max: " << myMinSubID << ", " << myMaxSubID << std::endl; std::cout << "SubIDRanges: " << mySubIDRanges.Size() << " "; { TSubIDRangeSet::set_iterator i = mySubIDRanges.mySet.begin();