From 4a591503f83eb00e13ddff5946e8a5ec51ccdbd5 Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 26 Jul 2017 18:33:09 +0300 Subject: [PATCH 1/2] 23462: [CEA 2142] Import12D fails Fix node classification on periodic FACEs and wrong propagation on IN node state --- src/Controls/SMESH_Controls.cxx | 71 +++++++++++++++++++++-- src/Controls/SMESH_ControlsDef.hxx | 2 + src/StdMeshers/StdMeshers_Import_1D2D.cxx | 64 +++++++++++++++----- 3 files changed, 118 insertions(+), 19 deletions(-) diff --git a/src/Controls/SMESH_Controls.cxx b/src/Controls/SMESH_Controls.cxx index ee372e222..9485d983e 100644 --- a/src/Controls/SMESH_Controls.cxx +++ b/src/Controls/SMESH_Controls.cxx @@ -4287,6 +4287,7 @@ void ElementsOnShape::SetShape (const TopoDS_Shape& theShape, if ( shapeChanges ) { + // find most complex shapes TopTools_IndexedMapOfShape shapesMap; TopAbs_ShapeEnum shapeTypes[4] = { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX }; TopExp_Explorer sub; @@ -4329,10 +4330,18 @@ void ElementsOnShape::clearClassifiers() bool ElementsOnShape::IsSatisfy( long elemId ) { - const SMDS_Mesh* mesh = myMeshModifTracer.GetMesh(); - const SMDS_MeshElement* elem = - ( myType == SMDSAbs_Node ? mesh->FindNode( elemId ) : mesh->FindElement( elemId )); - if ( !elem || myClassifiers.empty() ) + if ( myClassifiers.empty() ) + return false; + + const SMDS_Mesh* mesh = myMeshModifTracer.GetMesh(); + if ( myType == SMDSAbs_Node ) + return IsSatisfy( mesh->FindNode( elemId )); + return IsSatisfy( mesh->FindElement( elemId )); +} + +bool ElementsOnShape::IsSatisfy (const SMDS_MeshElement* elem) +{ + if ( !elem ) return false; bool isSatisfy = myAllNodesFlag, isNodeOut; @@ -4396,6 +4405,60 @@ bool ElementsOnShape::IsSatisfy( long elemId ) return isSatisfy; } +bool ElementsOnShape::IsSatisfy (const SMDS_MeshNode* node, + TopoDS_Shape* okShape) +{ + if ( !node ) + return false; + + if ( !myOctree && myClassifiers.size() > 5 ) + { + myWorkClassifiers.resize( myClassifiers.size() ); + for ( size_t i = 0; i < myClassifiers.size(); ++i ) + myWorkClassifiers[ i ] = & myClassifiers[ i ]; + myOctree = new OctreeClassifier( myWorkClassifiers ); + } + + bool isNodeOut = true; + + if ( okShape || !getNodeIsOut( node, isNodeOut )) + { + SMESH_NodeXYZ aPnt = node; + if ( myOctree ) + { + myWorkClassifiers.clear(); + myOctree->GetClassifiersAtPoint( aPnt, myWorkClassifiers ); + + for ( size_t i = 0; i < myWorkClassifiers.size(); ++i ) + myWorkClassifiers[i]->SetChecked( false ); + + for ( size_t i = 0; i < myWorkClassifiers.size(); ++i ) + if ( !myWorkClassifiers[i]->IsChecked() && + !myWorkClassifiers[i]->IsOut( aPnt )) + { + isNodeOut = false; + if ( okShape ) + *okShape = myWorkClassifiers[i]->Shape(); + break; + } + } + else + { + for ( size_t i = 0; i < myClassifiers.size(); ++i ) + if ( !myClassifiers[i].IsOut( aPnt )) + { + isNodeOut = false; + if ( okShape ) + *okShape = myWorkClassifiers[i]->Shape(); + break; + } + } + setNodeIsOut( node, isNodeOut ); + } + + return !isNodeOut; +} + void ElementsOnShape::Classifier::Init( const TopoDS_Shape& theShape, double theTol, const Bnd_B3d* theBox ) diff --git a/src/Controls/SMESH_ControlsDef.hxx b/src/Controls/SMESH_ControlsDef.hxx index cd39ab3d9..74a4a263d 100644 --- a/src/Controls/SMESH_ControlsDef.hxx +++ b/src/Controls/SMESH_ControlsDef.hxx @@ -902,6 +902,8 @@ namespace SMESH{ bool GetAllNodes() const { return myAllNodesFlag; } void SetShape (const TopoDS_Shape& theShape, const SMDSAbs_ElementType theType); + bool IsSatisfy (const SMDS_MeshElement* elem); + bool IsSatisfy (const SMDS_MeshNode* node, TopoDS_Shape* okShape=0); private: diff --git a/src/StdMeshers/StdMeshers_Import_1D2D.cxx b/src/StdMeshers/StdMeshers_Import_1D2D.cxx index d0906bfb0..8cc97b6e0 100644 --- a/src/StdMeshers/StdMeshers_Import_1D2D.cxx +++ b/src/StdMeshers/StdMeshers_Import_1D2D.cxx @@ -34,6 +34,7 @@ #include "SMESHDS_Group.hxx" #include "SMESHDS_Mesh.hxx" #include "SMESH_Comment.hxx" +#include "SMESH_ControlsDef.hxx" #include "SMESH_Gen.hxx" #include "SMESH_Group.hxx" #include "SMESH_Mesh.hxx" @@ -187,8 +188,8 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & SMESHDS_Mesh* tgtMesh = theMesh.GetMeshDS(); const TopoDS_Face& geomFace = TopoDS::Face( theShape ); - const double faceTol = helper.MaxTolerance( geomFace ); - const int shapeID = tgtMesh->ShapeToIndex( geomFace ); + const double faceTol = helper.MaxTolerance( geomFace ); + const int shapeID = tgtMesh->ShapeToIndex( geomFace ); const bool toCheckOri = (helper.NbAncestors( geomFace, theMesh, TopAbs_SOLID ) == 1 ); @@ -269,12 +270,25 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & map::iterator link2Nb; double minGroupTol = Precision::Infinite(); + SMESH::Controls::ElementsOnShape onEdgeClassifier; + if ( helper.HasSeam() ) + { + TopoDS_Compound edgesCompound; + BRep_Builder builder; + builder.MakeCompound( edgesCompound ); + for ( size_t iE = 0; iE < edges.size(); ++iE ) + builder.Add( edgesCompound, edges[ iE ]); + onEdgeClassifier.SetShape( edgesCompound, SMDSAbs_Node ); + } + // ========================= // Import faces from groups // ========================= StdMeshers_Import_1D::TNodeNodeMap* n2n; StdMeshers_Import_1D::TElemElemMap* e2e; + StdMeshers_Import_1D::TNodeNodeMap::iterator n2nIt; + pair< StdMeshers_Import_1D::TNodeNodeMap::iterator, bool > it_isnew; vector nodeState; vector newNodes; // of a face set bndNodes; // nodes classified ON @@ -297,8 +311,8 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & // S.VResolution( 0.1 * groupTol )); const double clsfTol = BRep_Tool::Tolerance( geomFace ); - StdMeshers_Import_1D::TNodeNodeMap::iterator n2nIt; - pair< StdMeshers_Import_1D::TNodeNodeMap::iterator, bool > it_isnew; + if ( helper.HasSeam() ) + onEdgeClassifier.SetMesh( srcMesh->GetMeshDS() ); SMDS_ElemIteratorPtr srcElems = srcGroup->GetElements(); while ( srcElems->more() ) // loop on group contents @@ -356,11 +370,21 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & gp_XY uv( Precision::Infinite(), 0 ); isOut = ( !helper.CheckNodeUV( geomFace, *node, uv, groupTol, /*force=*/true ) || bndBox2d.IsOut( uv )); + //int iCoo; if ( !isOut && !isIn ) // classify { classifier.Perform( geomFace, uv, clsfTol ); nodeState[i] = classifier.State(); isOut = ( nodeState[i] == TopAbs_OUT ); + if ( isOut && helper.IsOnSeam( uv ) && onEdgeClassifier.IsSatisfy( (*node)->GetID() )) + { + // uv.SetCoord( iCoo, helper.GetOtherParam( uv.Coord( iCoo ))); + // classifier.Perform( geomFace, uv, clsfTol ); + // nodeState[i] = classifier.State(); + // isOut = ( nodeState[i] == TopAbs_OUT ); + nodeState[i] = TopAbs_ON; + isOut = false; + } } if ( !isOut ) // create a new node { @@ -374,13 +398,14 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & } if ( nodeState[i] == TopAbs_ON ) bndNodes.insert( *node ); - else + else if ( nodeState[i] != TopAbs_UNKNOWN ) isNodeIn[ newNode->GetID() ] = isIn = true; } } if ( !(newNodes[i] = newNode ) || isOut ) break; - } + + } // loop on face nodes if ( !newNodes.back() ) continue; // not all nodes of the face lie on theShape @@ -491,23 +516,32 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & medium = newNodes[i+nbCorners]; link2Nb = linkCount.insert( make_pair( TLink( n1, n2, medium ), 0)).first; ++link2Nb->second; - // if ( link2Nb->second == 1 ) - // { - // // measure link length - // double len2 = SMESH_TNodeXYZ( n1 ).SquareDistance( n2 ); - // if ( len2 < minGroupTol ) - // minGroupTol = len2; - // } } - } + } // loop on group contents + // Remove OUT nodes from n2n map for ( n2nIt = n2n->begin(); n2nIt != n2n->end(); ) if ( !n2nIt->second ) n2n->erase( n2nIt++ ); else ++n2nIt; - } + } // loop on src groups + + // remove free nodes created on EDGEs + { + set::iterator node = bndNodes.begin(); + for ( ; node != bndNodes.end(); ++node ) + { + n2nIt = n2n->find( *node ); + const SMDS_MeshNode* newNode = n2nIt->second; + if ( newNode && newNode->NbInverseElements() == 0 ) + { + tgtMesh->RemoveFreeNode( newNode, 0, false ); + n2n->erase( n2nIt ); + } + } + } // ========================================================== // Put nodes on geom edges and create edges on them; From 7c1bf48314fbbb5c3c69a8dcbf70372a99189dd0 Mon Sep 17 00:00:00 2001 From: rnv Date: Wed, 2 Aug 2017 15:10:31 +0300 Subject: [PATCH 2/2] Implementation a selection of a mesh entries from python. --- src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx | 114 ++++++++++++++++++++--- src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h | 10 +- src/SMESH_SWIG_WITHIHM/libSMESH_Swig.i | 10 +- 3 files changed, 114 insertions(+), 20 deletions(-) diff --git a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx index 231dd33b5..0a111304e 100644 --- a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx +++ b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx @@ -49,6 +49,7 @@ #include #include #include +#include // OCCT includes #include @@ -62,6 +63,10 @@ #include CORBA_SERVER_HEADER(SMESH_Gen) #include CORBA_SERVER_HEADER(SMESH_Hypothesis) +// VTK includes +#include +#include + static CORBA::ORB_var anORB; namespace @@ -892,17 +897,18 @@ public: {} virtual void Execute() { - SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI(); - if( !aSMESHGUI ) - return; - LightApp_SelectionMgr* selMgr = SMESH::GetSelectionMgr( aSMESHGUI ); + LightApp_SelectionMgr* selMgr = 0; + SalomeApp_Application* anApp = dynamic_cast( SUIT_Session::session()->activeApplication() ); + if( anApp ) + selMgr = dynamic_cast( anApp->selectionMgr() ); + if( !selMgr ) return; selMgr->clearFilters(); - SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aSMESHGUI ); + SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow(); if(!aViewWindow) return; @@ -960,26 +966,106 @@ void SMESH_Swig::select( const char* id, int id1, bool append ) { class TGetSelectionModeEvent : public SALOME_Event { public: - typedef int TResult; + typedef SelectionMode TResult; TResult myResult; - TGetSelectionModeEvent() : myResult( -1 ) {} + TGetSelectionModeEvent() : myResult( Undefined ) {} virtual void Execute() { - SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI(); - if( !aSMESHGUI ) - return; - - SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aSMESHGUI ); + SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( ); if(!aViewWindow) return; - myResult = aViewWindow->SelectionMode(); + myResult = (SelectionMode) aViewWindow->SelectionMode(); } }; /*! \brief Get selection mode of the active VTK View window. */ -int SMESH_Swig::getSelectionMode() { +SelectionMode SMESH_Swig::getSelectionMode() { return ProcessEvent( new TGetSelectionModeEvent() ); } + + +/*! + * Event to set selection mode +*/ +class TSetSelectionModeEvent : public SALOME_Event +{ + SelectionMode mySelectionMode; + +public: + + TSetSelectionModeEvent(const SelectionMode selectionMode) : + mySelectionMode(selectionMode) + {} + + virtual void Execute() + { + SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow(); + if(!aViewWindow) + return; + + Selection_Mode prevMode = aViewWindow->SelectionMode(); + bool changePointRepresentation = ( prevMode == NodeSelection && mySelectionMode != Node ) || + (prevMode != NodeSelection && mySelectionMode == Node); + + if( changePointRepresentation ) { + vtkRenderer *aRenderer = aViewWindow->getRenderer(); + VTK::ActorCollectionCopy aCopy(aRenderer->GetActors()); + vtkActorCollection *aCollection = aCopy.GetActors(); + aCollection->InitTraversal(); + while(vtkActor *anAct = aCollection->GetNextActor()){ + if(SMESH_Actor *anActor = dynamic_cast(anAct)){ + if(anActor->GetVisibility()){ + anActor->SetPointRepresentation(mySelectionMode == Node); + } + } + } + } + aViewWindow->SetSelectionMode(mySelectionMode); + } +}; + +void SMESH_Swig::setSelectionMode(SelectionMode selectionMode){ + ProcessVoidEvent( new TSetSelectionModeEvent( selectionMode ) ); +} + +class TGetSelectedEvent : public SALOME_Event +{ +public: + typedef std::vector TResult; + TResult myResult; + const char* myId; + + TGetSelectedEvent( const char* id) : + myResult( std::vector() ), + myId(id) + {} + + virtual void Execute() + { + SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow(); + if( !aViewWindow ) + return; + + SVTK_Selector* aSelector = aViewWindow->GetSelector(); + if( !aSelector ) + return; + + SMESH_Actor* anActor = SMESH::FindActorByEntry( myId ); + + if ( !anActor || !anActor->hasIO() ) + return; + + TColStd_IndexedMapOfInteger aMapIndex; + aSelector->GetIndex(anActor->getIO(),aMapIndex); + + for( int i = 1; i <= aMapIndex.Extent(); i++ ) + myResult.push_back( aMapIndex( i ) ); + } +}; + +std::vector SMESH_Swig::getSelected( const char* Mesh_Entry ) { + return ProcessEvent( new TGetSelectedEvent(Mesh_Entry) ); +} diff --git a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h index 86682ff5b..5522e95a2 100644 --- a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h +++ b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h @@ -45,8 +45,9 @@ #include -enum +typedef enum { + Undefined = -1, Node = NodeSelection, Cell = CellSelection, EdgeOfCell = EdgeOfCellSelection, @@ -56,7 +57,7 @@ enum Actor = ActorSelection, Elem0D = Elem0DSelection, Ball = BallSelection - }; + } SelectionMode; typedef struct { @@ -128,8 +129,11 @@ public: actorAspect GetActorAspect(const char* Mesh_Entry, int viewId = 0 ); void SetActorAspect( const actorAspect& actorPres, const char* Mesh_Entry, int viewId = 0 ); + void setSelectionMode( SelectionMode selectionMode ); + std::vector getSelected( const char* Mesh_Entry ); + // --------------------- for the test purposes ----------------------- - int getSelectionMode(); + SelectionMode getSelectionMode(); void select( const char *id, std::vector ids, bool append = false ); void select( const char *id, int id1, bool append = false ); diff --git a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.i b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.i index ac732d467..339668801 100644 --- a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.i +++ b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.i @@ -55,9 +55,10 @@ namespace std { /* Selection mode enumeration (corresponds to constants from the SALOME_Selection.h) */ -enum +enum SelectionMode { - Node, + Undefined = -1, + Node = 0, Cell, EdgeOfCell, Edge, @@ -131,8 +132,11 @@ class SMESH_Swig actorAspect GetActorAspect(const char* Mesh_Entry, int viewId = 0 ); void SetActorAspect( const actorAspect& actorPres, const char* Mesh_Entry, int viewId = 0 ); + void setSelectionMode( SelectionMode selectionMode); + std::vector getSelected( const char* Mesh_Entry ); + // --------------------- for the test purposes ----------------------- - int getSelectionMode(); + SelectionMode getSelectionMode(); void select( const char *id, std::vector ids, bool append = false ); void select( const char *id, int id1, bool append = false );