X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FControls%2FSMESH_Controls.cxx;h=769096df4344b7e69a9d61ac59e8d7d6d903b5f9;hp=1ad00533a170e964b383b35dead87c964c2021e4;hb=07589de92eb5d8e7d4e3bfde8b26f0d69251acf0;hpb=ac69e1629b1b13430b93339cea889fe1ed4f1090 diff --git a/src/Controls/SMESH_Controls.cxx b/src/Controls/SMESH_Controls.cxx index 1ad00533a..769096df4 100644 --- a/src/Controls/SMESH_Controls.cxx +++ b/src/Controls/SMESH_Controls.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -31,9 +31,10 @@ #include "SMDS_QuadraticFaceOfNodes.hxx" #include "SMDS_VolumeTool.hxx" #include "SMESHDS_GroupBase.hxx" +#include "SMESHDS_GroupOnFilter.hxx" #include "SMESHDS_Mesh.hxx" -#include "SMESH_OctreeNode.hxx" #include "SMESH_MeshAlgos.hxx" +#include "SMESH_OctreeNode.hxx" #include @@ -135,8 +136,8 @@ namespace { int aResult0 = 0, aResult1 = 0; // last node, it is a medium one in a quadratic edge const SMDS_MeshNode* aLastNode = anEdge->GetNode( anEdge->NbNodes() - 1 ); - const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 ); - const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 ); + const SMDS_MeshNode* aNode0 = anEdge->GetNode( 0 ); + const SMDS_MeshNode* aNode1 = anEdge->GetNode( 1 ); if ( aNode1 == aLastNode ) aNode1 = 0; SMDS_ElemIteratorPtr anElemIter = aLastNode->GetInverseElementIterator(); @@ -158,29 +159,6 @@ namespace { } int aResult = std::max ( aResult0, aResult1 ); -// TColStd_MapOfInteger aMap; - -// SMDS_ElemIteratorPtr anIter = anEdge->nodesIterator(); -// if ( anIter != 0 ) { -// while( anIter->more() ) { -// const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next(); -// if ( aNode == 0 ) -// return 0; -// SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator(); -// while( anElemIter->more() ) { -// const SMDS_MeshElement* anElem = anElemIter->next(); -// if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) { -// int anId = anElem->GetID(); - -// if ( anIter->more() ) // i.e. first node -// aMap.Add( anId ); -// else if ( aMap.Contains( anId ) ) -// aResult++; -// } -// } -// } -// } - return aResult; } @@ -232,7 +210,7 @@ void NumericalFunctor::SetMesh( const SMDS_Mesh* theMesh ) myMesh = theMesh; } -bool NumericalFunctor::GetPoints(const int theId, +bool NumericalFunctor::GetPoints(const int theId, TSequenceOfXYZ& theRes ) const { theRes.clear(); @@ -256,6 +234,7 @@ bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem, return false; theRes.reserve( anElem->NbNodes() ); + theRes.setElement( anElem ); // Get nodes of the element SMDS_ElemIteratorPtr anIter; @@ -272,7 +251,6 @@ bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem, break; default: anIter = anElem->nodesIterator(); - //return false; } } else { @@ -280,9 +258,13 @@ bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem, } if ( anIter ) { + double xyz[3]; while( anIter->more() ) { if ( const SMDS_MeshNode* aNode = static_cast( anIter->next() )) - theRes.push_back( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) ); + { + aNode->GetXYZ( xyz ); + theRes.push_back( gp_XYZ( xyz[0], xyz[1], xyz[2] )); + } } } @@ -347,7 +329,7 @@ void NumericalFunctor::GetHistogram(int nbIntervals, std::multiset< double > values; if ( elements.empty() ) { - SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator(GetType()); + SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator( GetType() ); while ( elemIt->more() ) values.insert( GetValue( elemIt->next()->GetID() )); } @@ -480,6 +462,27 @@ double MaxElementLength2D::GetValue( const TSequenceOfXYZ& P ) double D2 = getDistance(P( 3 ),P( 7 )); aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(D1,D2)); } + // Diagonals are undefined for concave polygons + // else if ( P.getElementEntity() == SMDSEntity_Quad_Polygon && P.size() > 2 ) // quad polygon + // { + // // sides + // aVal = getDistance( P( 1 ), P( P.size() )) + getDistance( P( P.size() ), P( P.size()-1 )); + // for ( size_t i = 1; i < P.size()-1; i += 2 ) + // { + // double L = getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 )); + // aVal = Max( aVal, L ); + // } + // // diagonals + // for ( int i = P.size()-5; i > 0; i -= 2 ) + // for ( int j = i + 4; j < P.size() + i - 2; i += 2 ) + // { + // double D = getDistance( P( i ), P( j )); + // aVal = Max( aVal, D ); + // } + // } + // { // polygons + + // } if( myPrecision >= 0 ) { @@ -698,8 +701,9 @@ double MinimumAngle::GetValue( const TSequenceOfXYZ& P ) aMin = getAngle(P( P.size() ), P( 1 ), P( 2 )); aMin = Min(aMin,getAngle(P( P.size()-1 ), P( P.size() ), P( 1 ))); - for (int i=2; i 2 ) { + if ( P.size() > 2 ) + { gp_Vec aVec1( P(2) - P(1) ); gp_Vec aVec2( P(3) - P(1) ); gp_Vec SumVec = aVec1 ^ aVec2; - for (int i=4; i<=P.size(); i++) { + + for (int i=4; i<=P.size(); i++) + { gp_Vec aVec1( P(i-1) - P(1) ); gp_Vec aVec2( P(i) - P(1) ); gp_Vec tmp = aVec1 ^ aVec2; @@ -1522,81 +1529,78 @@ SMDSAbs_ElementType Length::GetType() const //================================================================================ /* Class : Length2D - Description : Functor for calculating length of edge + Description : Functor for calculating minimal length of edge */ //================================================================================ -double Length2D::GetValue( long theElementId) +double Length2D::GetValue( long theElementId ) { TSequenceOfXYZ P; - //cout<<"Length2D::GetValue"<FindElement( theElementId ); - SMDSAbs_ElementType aType = aElem->GetType(); - + if ( GetPoints( theElementId, P )) + { + double aVal = 0; int len = P.size(); + SMDSAbs_EntityType aType = P.getElementEntity(); - switch (aType){ - case SMDSAbs_All: - case SMDSAbs_Node: - case SMDSAbs_Edge: - if (len == 2){ + switch (aType) { + case SMDSEntity_Edge: + if (len == 2) aVal = getDistance( P( 1 ), P( 2 ) ); - break; - } - else if (len == 3){ // quadratic edge + break; + case SMDSEntity_Quad_Edge: + if (len == 3) // quadratic edge aVal = getDistance(P( 1 ),P( 3 )) + getDistance(P( 3 ),P( 2 )); - break; - } - case SMDSAbs_Face: + break; + case SMDSEntity_Triangle: if (len == 3){ // triangles double L1 = getDistance(P( 1 ),P( 2 )); double L2 = getDistance(P( 2 ),P( 3 )); double L3 = getDistance(P( 3 ),P( 1 )); - aVal = Max(L1,Max(L2,L3)); - break; + aVal = Min(L1,Min(L2,L3)); } - else if (len == 4){ // quadrangles + break; + case SMDSEntity_Quadrangle: + if (len == 4){ // quadrangles double L1 = getDistance(P( 1 ),P( 2 )); double L2 = getDistance(P( 2 ),P( 3 )); double L3 = getDistance(P( 3 ),P( 4 )); double L4 = getDistance(P( 4 ),P( 1 )); - aVal = Max(Max(L1,L2),Max(L3,L4)); - break; + aVal = Min(Min(L1,L2),Min(L3,L4)); } - if (len == 6){ // quadratic triangles + break; + case SMDSEntity_Quad_Triangle: + case SMDSEntity_BiQuad_Triangle: + if (len >= 6){ // quadratic triangles double L1 = getDistance(P( 1 ),P( 2 )) + getDistance(P( 2 ),P( 3 )); double L2 = getDistance(P( 3 ),P( 4 )) + getDistance(P( 4 ),P( 5 )); double L3 = getDistance(P( 5 ),P( 6 )) + getDistance(P( 6 ),P( 1 )); - aVal = Max(L1,Max(L2,L3)); - //cout<<"L1="<SetAllNodes(true); // "belong", while false means "lays on" myElementsOnShapePtr->SetMesh(myMeshDS); myElementsOnShapePtr->SetShape(myShape, myType); } @@ -4295,36 +4446,43 @@ bool BelongToGeom::IsSatisfy (long theId) { if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) ) { + if ( aNode->getshapeId() < 1 ) + return myElementsOnShapePtr->IsSatisfy(theId); + const SMDS_PositionPtr& aPosition = aNode->GetPosition(); SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition(); switch( aTypeOfPosition ) { - case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX ); - case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE ); - case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE ); - case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL ); + case SMDS_TOP_VERTEX : return ( IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX )); + case SMDS_TOP_EDGE : return ( IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE )); + case SMDS_TOP_FACE : return ( IsContains( myMeshDS,myShape,aNode,TopAbs_FACE )); + case SMDS_TOP_3DSPACE: return ( IsContains( myMeshDS,myShape,aNode,TopAbs_SOLID ) || + IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL )); } } } else { - if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) ) + if ( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId )) { + if ( anElem->getshapeId() < 1 ) + return myElementsOnShapePtr->IsSatisfy(theId); + if( myType == SMDSAbs_All ) { - return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) || - IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) || - IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )|| - IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID ); + return ( IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) || + IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) || + IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID )|| + IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )); } else if( myType == anElem->GetType() ) { switch( myType ) { - case SMDSAbs_Edge : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ); - case SMDSAbs_Face : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ); - case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )|| - IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID ); + case SMDSAbs_Edge : return ( IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE )); + case SMDSAbs_Face : return ( IsContains( myMeshDS,myShape,anElem,TopAbs_FACE )); + case SMDSAbs_Volume: return ( IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID )|| + IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )); } } } @@ -4401,12 +4559,22 @@ void LyingOnGeom::init() myIsSubshape = false; } else { - TopTools_IndexedMapOfShape aMap; - TopExp::MapShapes(aMainShape, aMap); - myIsSubshape = IsSubShape(aMap, myShape); + myIsSubshape = myMeshDS->IsGroupOfSubShapes( myShape ); } - if (!myIsSubshape) + if (myIsSubshape) + { + TopTools_IndexedMapOfShape shapes; + TopExp::MapShapes( myShape, shapes ); + mySubShapesIDs.Clear(); + for ( int i = 1; i <= shapes.Extent(); ++i ) + { + int subID = myMeshDS->ShapeToIndex( shapes( i )); + if ( subID > 0 ) + mySubShapesIDs.Add( subID ); + } + } + else { myElementsOnShapePtr.reset(new ElementsOnShape()); myElementsOnShapePtr->SetTolerance(myTolerance); @@ -4426,43 +4594,22 @@ bool LyingOnGeom::IsSatisfy( long theId ) return myElementsOnShapePtr->IsSatisfy(theId); } - // Case of submesh - if( myType == SMDSAbs_Node ) - { - if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) ) - { - const SMDS_PositionPtr& aPosition = aNode->GetPosition(); - SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition(); - switch( aTypeOfPosition ) - { - case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX ); - case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE ); - case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE ); - case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL ); - } - } - } - else + // Case of sub-mesh + + const SMDS_MeshElement* elem = + ( myType == SMDSAbs_Node ) ? myMeshDS->FindNode( theId ) : myMeshDS->FindElement( theId ); + + if ( mySubShapesIDs.Contains( elem->getshapeId() )) + return true; + + if ( elem->GetType() != SMDSAbs_Node ) { - if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) ) + SMDS_ElemIteratorPtr nodeItr = elem->nodesIterator(); + while ( nodeItr->more() ) { - if( myType == SMDSAbs_All ) - { - return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) || - Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) || - Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )|| - Contains( myMeshDS,myShape,anElem,TopAbs_SOLID ); - } - else if( myType == anElem->GetType() ) - { - switch( myType ) - { - case SMDSAbs_Edge : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ); - case SMDSAbs_Face : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE ); - case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )|| - Contains( myMeshDS,myShape,anElem,TopAbs_SOLID ); - } - } + const SMDS_MeshElement* aNode = nodeItr->next(); + if ( mySubShapesIDs.Contains( aNode->getshapeId() )) + return true; } } @@ -4508,51 +4655,47 @@ bool LyingOnGeom::Contains( const SMESHDS_Mesh* theMeshDS, TopAbs_ShapeEnum theFindShapeEnum, TopAbs_ShapeEnum theAvoidShapeEnum ) { - if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum)) - return true; - - TopTools_IndexedMapOfShape aSubShapes; - TopExp::MapShapes( theShape, aSubShapes ); - - for (int i = 1; i <= aSubShapes.Extent(); i++) - { - const TopoDS_Shape& aShape = aSubShapes.FindKey(i); - - if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){ - if( aSubMesh->Contains( theElem ) ) - return true; - - SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes(); - while ( aNodeIt->more() ) - { - const SMDS_MeshNode* aNode = static_cast(aNodeIt->next()); - SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator(); - while ( anElemIt->more() ) - { - const SMDS_MeshElement* anElement = static_cast(anElemIt->next()); - if (anElement == theElem) - return true; - } - } - } - } + // if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum)) + // return true; + + // TopTools_MapOfShape aSubShapes; + // TopExp_Explorer exp( theShape, theFindShapeEnum, theAvoidShapeEnum ); + // for ( ; exp.More(); exp.Next() ) + // { + // const TopoDS_Shape& aShape = exp.Current(); + // if ( !aSubShapes.Add( aShape )) continue; + + // if ( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape )) + // { + // if ( aSubMesh->Contains( theElem )) + // return true; + + // SMDS_ElemIteratorPtr nodeItr = theElem->nodesIterator(); + // while ( nodeItr->more() ) + // { + // const SMDS_MeshElement* aNode = nodeItr->next(); + // if ( aSubMesh->Contains( aNode )) + // return true; + // } + // } + // } return false; } -TSequenceOfXYZ::TSequenceOfXYZ() +TSequenceOfXYZ::TSequenceOfXYZ(): myElem(0) {} -TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n) +TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n), myElem(0) {} -TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t) +TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t), myElem(0) {} -TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray) +TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray), myElem(theSequenceOfXYZ.myElem) {} template -TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd) +TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd), myElem(0) {} TSequenceOfXYZ::~TSequenceOfXYZ() @@ -4561,6 +4704,7 @@ TSequenceOfXYZ::~TSequenceOfXYZ() TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ) { myArray = theSequenceOfXYZ.myArray; + myElem = theSequenceOfXYZ.myElem; return *this; } @@ -4594,6 +4738,11 @@ TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const return myArray.size(); } +SMDSAbs_EntityType TSequenceOfXYZ::getElementEntity() const +{ + return myElem ? myElem->GetEntityType() : SMDSEntity_Last; +} + TMeshModifTracer::TMeshModifTracer(): myMeshModifTime(0), myMesh(0) {