From 3ce7e67ad84873e3bfcf6eec9f86b7838d0588a1 Mon Sep 17 00:00:00 2001 From: eap Date: Mon, 23 Jan 2012 16:10:55 +0000 Subject: [PATCH] 0021338: EDF 1926 SMESH: New controls and filters + class SMESHCONTROLS_EXPORT CoincidentElements: public Predicate { + class SMESHCONTROLS_EXPORT CoincidentNodes: public Predicate { --- src/Controls/SMESH_Controls.cxx | 124 +++++++++++++++++++++++++++++ src/Controls/SMESH_ControlsDef.hxx | 56 ++++++++++++- 2 files changed, 176 insertions(+), 4 deletions(-) diff --git a/src/Controls/SMESH_Controls.cxx b/src/Controls/SMESH_Controls.cxx index 6fa7bb2e1..5bdcc486f 100644 --- a/src/Controls/SMESH_Controls.cxx +++ b/src/Controls/SMESH_Controls.cxx @@ -65,6 +65,8 @@ #include "SMESHDS_Mesh.hxx" #include "SMESHDS_GroupBase.hxx" +#include "SMESH_OctreeNode.hxx" + #include /* @@ -2089,6 +2091,128 @@ bool OverConstrainedFace::IsSatisfy(long theElementId ) return false; } +/* + Class : CoincidentNodes + Description : Predicate of Coincident nodes +*/ + +CoincidentNodes::CoincidentNodes() +{ + myToler = 1e-5; +} + +bool CoincidentNodes::IsSatisfy( long theElementId ) +{ + return myCoincidentIDs.Contains( theElementId ); +} + +SMDSAbs_ElementType CoincidentNodes::GetType() const +{ + return SMDSAbs_Node; +} + +void CoincidentNodes::SetMesh( const SMDS_Mesh* theMesh, TIDSortedNodeSet* nodesToCheck ) +{ + TIDSortedNodeSet allNodes; + if ( !nodesToCheck ) + { + nodesToCheck = &allNodes; + SMDS_NodeIteratorPtr nIt = theMesh->nodesIterator(/*idInceasingOrder=*/true); + while ( nIt->more() ) + allNodes.insert( allNodes.end(), nIt->next() ); + } + + list< list< const SMDS_MeshNode*> > nodeGroups; + SMESH_OctreeNode::FindCoincidentNodes ( *nodesToCheck, &nodeGroups, myToler ); + + myCoincidentIDs.Clear(); + list< list< const SMDS_MeshNode*> >::iterator groupIt = nodeGroups.begin(); + for ( ; groupIt != nodeGroups.end(); ++groupIt ) + { + list< const SMDS_MeshNode*>& coincNodes = *groupIt; + list< const SMDS_MeshNode*>::iterator n = coincNodes.begin(); + for ( ; n != coincNodes.end(); ++n ) + myCoincidentIDs.Add( (*n)->GetID() ); + } +} + +/* + Class : CoincidentElements + Description : Predicate of Coincident Elements + Note : This class is suitable only for visualization of Coincident Elements +*/ + +CoincidentElements::CoincidentElements() +{ + myMesh = 0; + myElemsToCheck = 0; +} + +void CoincidentElements::SetMesh( const SMDS_Mesh* theMesh, TIDSortedElemSet* elemsToCheck ) +{ + myMesh = theMesh; + + myCoincidentIDs.Clear(); + myElemsToCheck = elemsToCheck; + + if ( myElemsToCheck ) + { + TColStd_MapOfInteger coincidentIDs; + TIDSortedElemSet::iterator elem = myElemsToCheck->begin(); + for ( ; elem != myElemsToCheck->end(); ++elem ) + if ( IsSatisfy( (*elem)->GetID() )) + coincidentIDs.Add( (*elem)->GetID() ); + + myCoincidentIDs = coincidentIDs; + if ( myCoincidentIDs.IsEmpty() ) + myCoincidentIDs.Add( -1 ); // mark that analysis is already performed + + myElemsToCheck = 0; // not needed anymore + } +} + +bool CoincidentElements::IsSatisfy( long theElementId ) +{ + if ( !myCoincidentIDs.IsEmpty() ) + return myCoincidentIDs.Contains( theElementId ); + + if ( !myMesh ) return false; + + if ( const SMDS_MeshElement* e = myMesh->FindElement( theElementId )) + { + if ( e->GetType() != GetType() ) return false; + set< const SMDS_MeshNode* > elemNodes( e->begin_nodes(), e->end_nodes() ); + SMDS_ElemIteratorPtr invIt = (*elemNodes.begin())->GetInverseElementIterator( GetType() ); + while ( invIt->more() ) + { + const SMDS_MeshElement* e2 = invIt->next(); + if ( e2 == e || e2->NbNodes() != (int)elemNodes.size() ) continue; + if ( myElemsToCheck && !myElemsToCheck->count( e2 )) continue; + + bool sameNodes = true; + for ( size_t i = 0; i < elemNodes.size() && sameNodes; ++i ) + sameNodes = ( elemNodes.count( e2->GetNode( i ))); + if ( sameNodes ) + return true; + } + } + return false; +} + +SMDSAbs_ElementType CoincidentElements1D::GetType() const +{ + return SMDSAbs_Edge; +} +SMDSAbs_ElementType CoincidentElements2D::GetType() const +{ + return SMDSAbs_Face; +} +SMDSAbs_ElementType CoincidentElements3D::GetType() const +{ + return SMDSAbs_Volume; +} + + /* Class : FreeBorders Description : Predicate for free borders diff --git a/src/Controls/SMESH_ControlsDef.hxx b/src/Controls/SMESH_ControlsDef.hxx index d5dae39ec..ac07599ed 100644 --- a/src/Controls/SMESH_ControlsDef.hxx +++ b/src/Controls/SMESH_ControlsDef.hxx @@ -43,6 +43,7 @@ #include "SMDSAbs_ElementType.hxx" #include "SMDS_MeshNode.hxx" +#include "SMESH_TypeDefs.hxx" #include "SMESH_Controls.hxx" @@ -116,10 +117,8 @@ namespace SMESH{ void SetPrecision( const long thePrecision ); double Round( const double & value ); - bool GetPoints(const int theId, - TSequenceOfXYZ& theRes) const; - static bool GetPoints(const SMDS_MeshElement* theElem, - TSequenceOfXYZ& theRes); + bool GetPoints(const int theId, TSequenceOfXYZ& theRes) const; + static bool GetPoints(const SMDS_MeshElement* theElem, TSequenceOfXYZ& theRes); protected: const SMDS_Mesh* myMesh; const SMDS_MeshElement* myCurrElement; @@ -319,6 +318,55 @@ namespace SMESH{ /* PREDICATES */ + /* + Class : CoincidentNodes + Description : Predicate of Coincident Nodes + Note : This class is suitable only for visualization of Coincident Nodes + */ + class SMESHCONTROLS_EXPORT CoincidentNodes: public Predicate { + public: + CoincidentNodes(); + void SetTolerance (const double theToler) { myToler = theToler; } + void SetMesh( const SMDS_Mesh* theMesh, TIDSortedNodeSet* nodesToCheck ); + virtual void SetMesh( const SMDS_Mesh* theMesh ) { SetMesh( theMesh, 0 ); } + virtual bool IsSatisfy( long theElementId ); + virtual SMDSAbs_ElementType GetType() const; + + private: + TColStd_MapOfInteger myCoincidentIDs; + double myToler; + }; + + /* + Class : CoincidentElements + Description : Predicate of Coincident Elements + Note : This class is suitable only for visualization of Coincident Elements + */ + class SMESHCONTROLS_EXPORT CoincidentElements: public Predicate { + public: + CoincidentElements(); + void SetMesh( const SMDS_Mesh* theMesh, TIDSortedElemSet* elemsToCheck ); + virtual void SetMesh( const SMDS_Mesh* theMesh ) { SetMesh( theMesh, 0 ); } + virtual bool IsSatisfy( long theElementId ); + + private: + const SMDS_Mesh* myMesh; + TIDSortedElemSet* myElemsToCheck; + TColStd_MapOfInteger myCoincidentIDs; + }; + class SMESHCONTROLS_EXPORT CoincidentElements1D: public CoincidentElements { + public: + virtual SMDSAbs_ElementType GetType() const; + }; + class SMESHCONTROLS_EXPORT CoincidentElements2D: public CoincidentElements { + public: + virtual SMDSAbs_ElementType GetType() const; + }; + class SMESHCONTROLS_EXPORT CoincidentElements3D: public CoincidentElements { + public: + virtual SMDSAbs_ElementType GetType() const; + }; + /* Class : FreeBorders Description : Predicate for free borders -- 2.30.2