+}
+
+void
+Filter::GetElementsId( const SMDS_Mesh* theMesh,
+ Filter::TIdSequence& theSequence )
+{
+ GetElementsId(theMesh,myPredicate,theSequence);
+}
+
+/*
+ ManifoldPart
+*/
+
+typedef std::set<SMDS_MeshFace*> TMapOfFacePtr;
+
+/*
+ Internal class Link
+*/
+
+ManifoldPart::Link::Link( SMDS_MeshNode* theNode1,
+ SMDS_MeshNode* theNode2 )
+{
+ myNode1 = theNode1;
+ myNode2 = theNode2;
+}
+
+ManifoldPart::Link::~Link()
+{
+ myNode1 = 0;
+ myNode2 = 0;
+}
+
+bool ManifoldPart::Link::IsEqual( const ManifoldPart::Link& theLink ) const
+{
+ if ( myNode1 == theLink.myNode1 &&
+ myNode2 == theLink.myNode2 )
+ return true;
+ else if ( myNode1 == theLink.myNode2 &&
+ myNode2 == theLink.myNode1 )
+ return true;
+ else
+ return false;
+}
+
+bool ManifoldPart::Link::operator<( const ManifoldPart::Link& x ) const
+{
+ if(myNode1 < x.myNode1) return true;
+ if(myNode1 == x.myNode1)
+ if(myNode2 < x.myNode2) return true;
+ return false;
+}
+
+bool ManifoldPart::IsEqual( const ManifoldPart::Link& theLink1,
+ const ManifoldPart::Link& theLink2 )
+{
+ return theLink1.IsEqual( theLink2 );
+}
+
+ManifoldPart::ManifoldPart()
+{
+ myMesh = 0;
+ myAngToler = Precision::Angular();
+ myIsOnlyManifold = true;
+}
+
+ManifoldPart::~ManifoldPart()
+{
+ myMesh = 0;
+}
+
+void ManifoldPart::SetMesh( const SMDS_Mesh* theMesh )
+{
+ myMesh = theMesh;
+ process();
+}
+
+SMDSAbs_ElementType ManifoldPart::GetType() const
+{ return SMDSAbs_Face; }
+
+bool ManifoldPart::IsSatisfy( long theElementId )
+{
+ return myMapIds.Contains( theElementId );
+}
+
+void ManifoldPart::SetAngleTolerance( const double theAngToler )
+{ myAngToler = theAngToler; }
+
+double ManifoldPart::GetAngleTolerance() const
+{ return myAngToler; }
+
+void ManifoldPart::SetIsOnlyManifold( const bool theIsOnly )
+{ myIsOnlyManifold = theIsOnly; }
+
+void ManifoldPart::SetStartElem( const long theStartId )
+{ myStartElemId = theStartId; }
+
+bool ManifoldPart::process()
+{
+ myMapIds.Clear();
+ myMapBadGeomIds.Clear();
+
+ myAllFacePtr.clear();
+ myAllFacePtrIntDMap.clear();
+ if ( !myMesh )
+ return false;
+
+ // collect all faces into own map
+ SMDS_FaceIteratorPtr anFaceItr = myMesh->facesIterator();
+ for (; anFaceItr->more(); )
+ {
+ SMDS_MeshFace* aFacePtr = (SMDS_MeshFace*)anFaceItr->next();
+ myAllFacePtr.push_back( aFacePtr );
+ myAllFacePtrIntDMap[aFacePtr] = myAllFacePtr.size()-1;
+ }
+
+ SMDS_MeshFace* aStartFace = (SMDS_MeshFace*)myMesh->FindElement( myStartElemId );
+ if ( !aStartFace )
+ return false;
+
+ // the map of non manifold links and bad geometry
+ TMapOfLink aMapOfNonManifold;
+ TColStd_MapOfInteger aMapOfTreated;
+
+ // begin cycle on faces from start index and run on vector till the end
+ // and from begin to start index to cover whole vector
+ const int aStartIndx = myAllFacePtrIntDMap[aStartFace];
+ bool isStartTreat = false;
+ for ( int fi = aStartIndx; !isStartTreat || fi != aStartIndx ; fi++ )
+ {
+ if ( fi == aStartIndx )
+ isStartTreat = true;
+ // as result next time when fi will be equal to aStartIndx
+
+ SMDS_MeshFace* aFacePtr = myAllFacePtr[ fi ];
+ if ( aMapOfTreated.Contains( aFacePtr->GetID() ) )
+ continue;
+
+ aMapOfTreated.Add( aFacePtr->GetID() );
+ TColStd_MapOfInteger aResFaces;
+ if ( !findConnected( myAllFacePtrIntDMap, aFacePtr,
+ aMapOfNonManifold, aResFaces ) )
+ continue;
+ TColStd_MapIteratorOfMapOfInteger anItr( aResFaces );
+ for ( ; anItr.More(); anItr.Next() )
+ {
+ int aFaceId = anItr.Key();
+ aMapOfTreated.Add( aFaceId );
+ myMapIds.Add( aFaceId );
+ }
+
+ if ( fi == ( myAllFacePtr.size() - 1 ) )
+ fi = 0;
+ } // end run on vector of faces
+ return !myMapIds.IsEmpty();
+}
+
+static void getLinks( const SMDS_MeshFace* theFace,
+ ManifoldPart::TVectorOfLink& theLinks )
+{
+ int aNbNode = theFace->NbNodes();
+ SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
+ int i = 1;
+ SMDS_MeshNode* aNode = 0;
+ for ( ; aNodeItr->more() && i <= aNbNode; )
+ {
+
+ SMDS_MeshNode* aN1 = (SMDS_MeshNode*)aNodeItr->next();
+ if ( i == 1 )
+ aNode = aN1;
+ i++;
+ SMDS_MeshNode* aN2 = ( i >= aNbNode ) ? aNode : (SMDS_MeshNode*)aNodeItr->next();
+ i++;
+ ManifoldPart::Link aLink( aN1, aN2 );
+ theLinks.push_back( aLink );
+ }
+}
+
+static gp_XYZ getNormale( const SMDS_MeshFace* theFace )
+{
+ gp_XYZ n;
+ int aNbNode = theFace->NbNodes();
+ TColgp_Array1OfXYZ anArrOfXYZ(1,4);
+ SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
+ int i = 1;
+ for ( ; aNodeItr->more() && i <= 4; i++ ) {
+ SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
+ anArrOfXYZ.SetValue(i, gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
+ }
+
+ gp_XYZ q1 = anArrOfXYZ.Value(2) - anArrOfXYZ.Value(1);
+ gp_XYZ q2 = anArrOfXYZ.Value(3) - anArrOfXYZ.Value(1);
+ n = q1 ^ q2;
+ if ( aNbNode > 3 ) {
+ gp_XYZ q3 = anArrOfXYZ.Value(4) - anArrOfXYZ.Value(1);
+ n += q2 ^ q3;
+ }
+ double len = n.Modulus();
+ if ( len > 0 )
+ n /= len;
+
+ return n;
+}
+
+bool ManifoldPart::findConnected
+ ( const ManifoldPart::TDataMapFacePtrInt& theAllFacePtrInt,
+ SMDS_MeshFace* theStartFace,
+ ManifoldPart::TMapOfLink& theNonManifold,
+ TColStd_MapOfInteger& theResFaces )
+{
+ theResFaces.Clear();
+ if ( !theAllFacePtrInt.size() )
+ return false;
+
+ if ( getNormale( theStartFace ).SquareModulus() <= gp::Resolution() )
+ {
+ myMapBadGeomIds.Add( theStartFace->GetID() );
+ return false;
+ }
+
+ ManifoldPart::TMapOfLink aMapOfBoundary, aMapToSkip;
+ ManifoldPart::TVectorOfLink aSeqOfBoundary;
+ theResFaces.Add( theStartFace->GetID() );
+ ManifoldPart::TDataMapOfLinkFacePtr aDMapLinkFace;
+
+ expandBoundary( aMapOfBoundary, aSeqOfBoundary,
+ aDMapLinkFace, theNonManifold, theStartFace );
+
+ bool isDone = false;
+ while ( !isDone && aMapOfBoundary.size() != 0 )
+ {
+ bool isToReset = false;
+ ManifoldPart::TVectorOfLink::iterator pLink = aSeqOfBoundary.begin();
+ for ( ; !isToReset && pLink != aSeqOfBoundary.end(); ++pLink )
+ {
+ ManifoldPart::Link aLink = *pLink;
+ if ( aMapToSkip.find( aLink ) != aMapToSkip.end() )
+ continue;
+ // each link could be treated only once
+ aMapToSkip.insert( aLink );
+
+ ManifoldPart::TVectorOfFacePtr aFaces;
+ // find next
+ if ( myIsOnlyManifold &&
+ (theNonManifold.find( aLink ) != theNonManifold.end()) )
+ continue;
+ else
+ {
+ getFacesByLink( aLink, aFaces );
+ // filter the element to keep only indicated elements
+ ManifoldPart::TVectorOfFacePtr aFiltered;
+ ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
+ for ( ; pFace != aFaces.end(); ++pFace )
+ {
+ SMDS_MeshFace* aFace = *pFace;
+ if ( myAllFacePtrIntDMap.find( aFace ) != myAllFacePtrIntDMap.end() )
+ aFiltered.push_back( aFace );
+ }
+ aFaces = aFiltered;
+ if ( aFaces.size() < 2 ) // no neihgbour faces
+ continue;
+ else if ( myIsOnlyManifold && aFaces.size() > 2 ) // non manifold case
+ {
+ theNonManifold.insert( aLink );
+ continue;
+ }
+ }
+
+ // compare normal with normals of neighbor element
+ SMDS_MeshFace* aPrevFace = aDMapLinkFace[ aLink ];
+ ManifoldPart::TVectorOfFacePtr::iterator pFace = aFaces.begin();
+ for ( ; pFace != aFaces.end(); ++pFace )
+ {
+ SMDS_MeshFace* aNextFace = *pFace;
+ if ( aPrevFace == aNextFace )
+ continue;
+ int anNextFaceID = aNextFace->GetID();
+ if ( myIsOnlyManifold && theResFaces.Contains( anNextFaceID ) )
+ // should not be with non manifold restriction. probably bad topology
+ continue;
+ // check if face was treated and skipped
+ if ( myMapBadGeomIds.Contains( anNextFaceID ) ||
+ !isInPlane( aPrevFace, aNextFace ) )
+ continue;
+ // add new element to connected and extend the boundaries.
+ theResFaces.Add( anNextFaceID );
+ expandBoundary( aMapOfBoundary, aSeqOfBoundary,
+ aDMapLinkFace, theNonManifold, aNextFace );
+ isToReset = true;
+ }
+ }
+ isDone = !isToReset;
+ }
+
+ return !theResFaces.IsEmpty();
+}
+
+bool ManifoldPart::isInPlane( const SMDS_MeshFace* theFace1,
+ const SMDS_MeshFace* theFace2 )
+{
+ gp_Dir aNorm1 = gp_Dir( getNormale( theFace1 ) );
+ gp_XYZ aNorm2XYZ = getNormale( theFace2 );
+ if ( aNorm2XYZ.SquareModulus() <= gp::Resolution() )
+ {
+ myMapBadGeomIds.Add( theFace2->GetID() );
+ return false;
+ }
+ if ( aNorm1.IsParallel( gp_Dir( aNorm2XYZ ), myAngToler ) )
+ return true;
+
+ return false;
+}
+
+void ManifoldPart::expandBoundary
+ ( ManifoldPart::TMapOfLink& theMapOfBoundary,
+ ManifoldPart::TVectorOfLink& theSeqOfBoundary,
+ ManifoldPart::TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
+ ManifoldPart::TMapOfLink& theNonManifold,
+ SMDS_MeshFace* theNextFace ) const
+{
+ ManifoldPart::TVectorOfLink aLinks;
+ getLinks( theNextFace, aLinks );
+ int aNbLink = (int)aLinks.size();
+ for ( int i = 0; i < aNbLink; i++ )
+ {
+ ManifoldPart::Link aLink = aLinks[ i ];
+ if ( myIsOnlyManifold && (theNonManifold.find( aLink ) != theNonManifold.end()) )
+ continue;
+ if ( theMapOfBoundary.find( aLink ) != theMapOfBoundary.end() )
+ {
+ if ( myIsOnlyManifold )
+ {
+ // remove from boundary
+ theMapOfBoundary.erase( aLink );
+ ManifoldPart::TVectorOfLink::iterator pLink = theSeqOfBoundary.begin();
+ for ( ; pLink != theSeqOfBoundary.end(); ++pLink )
+ {
+ ManifoldPart::Link aBoundLink = *pLink;
+ if ( aBoundLink.IsEqual( aLink ) )
+ {
+ theSeqOfBoundary.erase( pLink );
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ theMapOfBoundary.insert( aLink );
+ theSeqOfBoundary.push_back( aLink );
+ theDMapLinkFacePtr[ aLink ] = theNextFace;
+ }
+ }
+}
+
+void ManifoldPart::getFacesByLink( const ManifoldPart::Link& theLink,
+ ManifoldPart::TVectorOfFacePtr& theFaces ) const
+{
+ SMDS_Mesh::SetOfFaces aSetOfFaces;
+ // take all faces that shared first node
+ SMDS_ElemIteratorPtr anItr = theLink.myNode1->facesIterator();
+ for ( ; anItr->more(); )
+ {
+ SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
+ if ( !aFace )
+ continue;
+ aSetOfFaces.Add( aFace );
+ }
+ // take all faces that shared second node
+ anItr = theLink.myNode2->facesIterator();
+ // find the common part of two sets
+ for ( ; anItr->more(); )
+ {
+ SMDS_MeshFace* aFace = (SMDS_MeshFace*)anItr->next();
+ if ( aSetOfFaces.Contains( aFace ) )
+ theFaces.push_back( aFace );
+ }
+}
+
+
+/*
+ ElementsOnSurface
+*/
+
+ElementsOnSurface::ElementsOnSurface()
+{
+ myMesh = 0;
+ myIds.Clear();
+ myType = SMDSAbs_All;
+ mySurf.Nullify();
+ myToler = Precision::Confusion();
+ myUseBoundaries = false;
+}
+
+ElementsOnSurface::~ElementsOnSurface()
+{
+ myMesh = 0;
+}
+
+void ElementsOnSurface::SetMesh( const SMDS_Mesh* theMesh )
+{
+ if ( myMesh == theMesh )
+ return;
+ myMesh = theMesh;
+ process();
+}
+
+bool ElementsOnSurface::IsSatisfy( long theElementId )
+{
+ return myIds.Contains( theElementId );
+}
+
+SMDSAbs_ElementType ElementsOnSurface::GetType() const
+{ return myType; }
+
+void ElementsOnSurface::SetTolerance( const double theToler )
+{
+ if ( myToler != theToler )
+ myIds.Clear();
+ myToler = theToler;
+}
+
+double ElementsOnSurface::GetTolerance() const
+{ return myToler; }
+
+void ElementsOnSurface::SetUseBoundaries( bool theUse )
+{
+ if ( myUseBoundaries != theUse ) {
+ myUseBoundaries = theUse;
+ SetSurface( mySurf, myType );
+ }
+}
+
+void ElementsOnSurface::SetSurface( const TopoDS_Shape& theShape,
+ const SMDSAbs_ElementType theType )
+{
+ myIds.Clear();
+ myType = theType;
+ mySurf.Nullify();
+ if ( theShape.IsNull() || theShape.ShapeType() != TopAbs_FACE )
+ return;
+ mySurf = TopoDS::Face( theShape );
+ BRepAdaptor_Surface SA( mySurf, myUseBoundaries );
+ Standard_Real
+ u1 = SA.FirstUParameter(),
+ u2 = SA.LastUParameter(),
+ v1 = SA.FirstVParameter(),
+ v2 = SA.LastVParameter();
+ Handle(Geom_Surface) surf = BRep_Tool::Surface( mySurf );
+ myProjector.Init( surf, u1,u2, v1,v2 );
+ process();
+}
+
+void ElementsOnSurface::process()
+{
+ myIds.Clear();
+ if ( mySurf.IsNull() )
+ return;
+
+ if ( myMesh == 0 )
+ return;
+
+ if ( myType == SMDSAbs_Face || myType == SMDSAbs_All )
+ {
+ myIds.ReSize( myMesh->NbFaces() );
+ SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
+ for(; anIter->more(); )
+ process( anIter->next() );
+ }
+
+ if ( myType == SMDSAbs_Edge || myType == SMDSAbs_All )
+ {
+ myIds.ReSize( myIds.Extent() + myMesh->NbEdges() );
+ SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
+ for(; anIter->more(); )
+ process( anIter->next() );
+ }
+
+ if ( myType == SMDSAbs_Node )
+ {
+ myIds.ReSize( myMesh->NbNodes() );
+ SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
+ for(; anIter->more(); )
+ process( anIter->next() );
+ }
+}
+
+void ElementsOnSurface::process( const SMDS_MeshElement* theElemPtr )
+{
+ SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
+ bool isSatisfy = true;
+ for ( ; aNodeItr->more(); )
+ {
+ SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
+ if ( !isOnSurface( aNode ) )
+ {
+ isSatisfy = false;
+ break;
+ }
+ }
+ if ( isSatisfy )
+ myIds.Add( theElemPtr->GetID() );
+}
+
+bool ElementsOnSurface::isOnSurface( const SMDS_MeshNode* theNode )
+{
+ if ( mySurf.IsNull() )
+ return false;
+
+ gp_Pnt aPnt( theNode->X(), theNode->Y(), theNode->Z() );
+ // double aToler2 = myToler * myToler;
+// if ( mySurf->IsKind(STANDARD_TYPE(Geom_Plane)))
+// {
+// gp_Pln aPln = Handle(Geom_Plane)::DownCast(mySurf)->Pln();
+// if ( aPln.SquareDistance( aPnt ) > aToler2 )
+// return false;
+// }
+// else if ( mySurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)))
+// {
+// gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(mySurf)->Cylinder();
+// double aRad = aCyl.Radius();
+// gp_Ax3 anAxis = aCyl.Position();
+// gp_XYZ aLoc = aCyl.Location().XYZ();
+// double aXDist = anAxis.XDirection().XYZ() * ( aPnt.XYZ() - aLoc );
+// double aYDist = anAxis.YDirection().XYZ() * ( aPnt.XYZ() - aLoc );
+// if ( fabs(aXDist*aXDist + aYDist*aYDist - aRad*aRad) > aToler2 )
+// return false;
+// }
+// else
+// return false;
+ myProjector.Perform( aPnt );
+ bool isOn = ( myProjector.IsDone() && myProjector.LowerDistance() <= myToler );
+
+ return isOn;
+}
+
+
+/*
+ ElementsOnShape
+*/
+
+ElementsOnShape::ElementsOnShape()
+ : myMesh(0),
+ myType(SMDSAbs_All),
+ myToler(Precision::Confusion()),
+ myAllNodesFlag(false)
+{
+ myCurShapeType = TopAbs_SHAPE;
+}
+
+ElementsOnShape::~ElementsOnShape()
+{
+}
+
+void ElementsOnShape::SetMesh (const SMDS_Mesh* theMesh)
+{
+ if (myMesh != theMesh) {
+ myMesh = theMesh;
+ SetShape(myShape, myType);
+ }
+}
+
+bool ElementsOnShape::IsSatisfy (long theElementId)
+{
+ return myIds.Contains(theElementId);
+}
+
+SMDSAbs_ElementType ElementsOnShape::GetType() const
+{
+ return myType;
+}
+
+void ElementsOnShape::SetTolerance (const double theToler)
+{
+ if (myToler != theToler) {
+ myToler = theToler;
+ SetShape(myShape, myType);
+ }
+}
+
+double ElementsOnShape::GetTolerance() const
+{
+ return myToler;
+}
+
+void ElementsOnShape::SetAllNodes (bool theAllNodes)
+{
+ if (myAllNodesFlag != theAllNodes) {
+ myAllNodesFlag = theAllNodes;
+ SetShape(myShape, myType);
+ }
+}
+
+void ElementsOnShape::SetShape (const TopoDS_Shape& theShape,
+ const SMDSAbs_ElementType theType)
+{
+ myType = theType;
+ myShape = theShape;
+ myIds.Clear();
+
+ if (myMesh == 0) return;
+
+ switch (myType)
+ {
+ case SMDSAbs_All:
+ myIds.ReSize(myMesh->NbEdges() + myMesh->NbFaces() + myMesh->NbVolumes());
+ break;
+ case SMDSAbs_Node:
+ myIds.ReSize(myMesh->NbNodes());
+ break;
+ case SMDSAbs_Edge:
+ myIds.ReSize(myMesh->NbEdges());
+ break;
+ case SMDSAbs_Face:
+ myIds.ReSize(myMesh->NbFaces());
+ break;
+ case SMDSAbs_Volume:
+ myIds.ReSize(myMesh->NbVolumes());
+ break;
+ default:
+ break;
+ }
+
+ myShapesMap.Clear();
+ addShape(myShape);
+}
+
+void ElementsOnShape::addShape (const TopoDS_Shape& theShape)
+{
+ if (theShape.IsNull() || myMesh == 0)
+ return;
+
+ if (!myShapesMap.Add(theShape)) return;
+
+ myCurShapeType = theShape.ShapeType();
+ switch (myCurShapeType)
+ {
+ case TopAbs_COMPOUND:
+ case TopAbs_COMPSOLID:
+ case TopAbs_SHELL:
+ case TopAbs_WIRE:
+ {
+ TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
+ for (; anIt.More(); anIt.Next()) addShape(anIt.Value());
+ }
+ break;
+ case TopAbs_SOLID:
+ {
+ myCurSC.Load(theShape);
+ process();
+ }
+ break;
+ case TopAbs_FACE:
+ {
+ TopoDS_Face aFace = TopoDS::Face(theShape);
+ BRepAdaptor_Surface SA (aFace, true);
+ Standard_Real
+ u1 = SA.FirstUParameter(),
+ u2 = SA.LastUParameter(),
+ v1 = SA.FirstVParameter(),
+ v2 = SA.LastVParameter();
+ Handle(Geom_Surface) surf = BRep_Tool::Surface(aFace);
+ myCurProjFace.Init(surf, u1,u2, v1,v2);
+ myCurFace = aFace;
+ process();
+ }
+ break;
+ case TopAbs_EDGE:
+ {
+ TopoDS_Edge anEdge = TopoDS::Edge(theShape);
+ Standard_Real u1, u2;
+ Handle(Geom_Curve) curve = BRep_Tool::Curve(anEdge, u1, u2);
+ myCurProjEdge.Init(curve, u1, u2);
+ process();
+ }
+ break;
+ case TopAbs_VERTEX:
+ {
+ TopoDS_Vertex aV = TopoDS::Vertex(theShape);
+ myCurPnt = BRep_Tool::Pnt(aV);
+ process();
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void ElementsOnShape::process()
+{
+ if (myShape.IsNull() || myMesh == 0)
+ return;
+
+ if (myType == SMDSAbs_Node)
+ {
+ SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
+ while (anIter->more())
+ process(anIter->next());
+ }
+ else
+ {
+ if (myType == SMDSAbs_Edge || myType == SMDSAbs_All)
+ {
+ SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
+ while (anIter->more())
+ process(anIter->next());
+ }
+
+ if (myType == SMDSAbs_Face || myType == SMDSAbs_All)
+ {
+ SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
+ while (anIter->more()) {
+ process(anIter->next());
+ }
+ }
+
+ if (myType == SMDSAbs_Volume || myType == SMDSAbs_All)
+ {
+ SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
+ while (anIter->more())
+ process(anIter->next());
+ }
+ }
+}
+
+void ElementsOnShape::process (const SMDS_MeshElement* theElemPtr)
+{
+ if (myShape.IsNull())
+ return;
+
+ SMDS_ElemIteratorPtr aNodeItr = theElemPtr->nodesIterator();
+ bool isSatisfy = myAllNodesFlag;
+
+ gp_XYZ centerXYZ (0, 0, 0);
+
+ while (aNodeItr->more() && (isSatisfy == myAllNodesFlag))
+ {
+ SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
+ gp_Pnt aPnt (aNode->X(), aNode->Y(), aNode->Z());
+ centerXYZ += aPnt.XYZ();
+
+ switch (myCurShapeType)
+ {
+ case TopAbs_SOLID:
+ {
+ myCurSC.Perform(aPnt, myToler);
+ isSatisfy = (myCurSC.State() == TopAbs_IN || myCurSC.State() == TopAbs_ON);
+ }
+ break;
+ case TopAbs_FACE:
+ {
+ myCurProjFace.Perform(aPnt);
+ isSatisfy = (myCurProjFace.IsDone() && myCurProjFace.LowerDistance() <= myToler);
+ if (isSatisfy)
+ {
+ // check relatively the face
+ Quantity_Parameter u, v;
+ myCurProjFace.LowerDistanceParameters(u, v);
+ gp_Pnt2d aProjPnt (u, v);
+ BRepClass_FaceClassifier aClsf (myCurFace, aProjPnt, myToler);
+ isSatisfy = (aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON);
+ }
+ }
+ break;
+ case TopAbs_EDGE:
+ {
+ myCurProjEdge.Perform(aPnt);
+ isSatisfy = (myCurProjEdge.NbPoints() > 0 && myCurProjEdge.LowerDistance() <= myToler);
+ }
+ break;
+ case TopAbs_VERTEX:
+ {
+ isSatisfy = (aPnt.Distance(myCurPnt) <= myToler);
+ }
+ break;
+ default:
+ {
+ isSatisfy = false;
+ }
+ }
+ }
+
+ if (isSatisfy && myCurShapeType == TopAbs_SOLID) { // Check the center point for volumes MantisBug 0020168
+ centerXYZ /= theElemPtr->NbNodes();
+ gp_Pnt aCenterPnt (centerXYZ);
+ myCurSC.Perform(aCenterPnt, myToler);
+ if ( !(myCurSC.State() == TopAbs_IN || myCurSC.State() == TopAbs_ON))
+ isSatisfy = false;
+ }
+
+ if (isSatisfy)
+ myIds.Add(theElemPtr->GetID());
+}
+
+TSequenceOfXYZ::TSequenceOfXYZ()
+{}
+
+TSequenceOfXYZ::TSequenceOfXYZ(size_type n) : myArray(n)
+{}
+
+TSequenceOfXYZ::TSequenceOfXYZ(size_type n, const gp_XYZ& t) : myArray(n,t)
+{}
+
+TSequenceOfXYZ::TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ) : myArray(theSequenceOfXYZ.myArray)
+{}
+
+template <class InputIterator>
+TSequenceOfXYZ::TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): myArray(theBegin,theEnd)
+{}
+
+TSequenceOfXYZ::~TSequenceOfXYZ()
+{}
+
+TSequenceOfXYZ& TSequenceOfXYZ::operator=(const TSequenceOfXYZ& theSequenceOfXYZ)
+{
+ myArray = theSequenceOfXYZ.myArray;
+ return *this;
+}
+
+gp_XYZ& TSequenceOfXYZ::operator()(size_type n)
+{
+ return myArray[n-1];
+}
+
+const gp_XYZ& TSequenceOfXYZ::operator()(size_type n) const
+{
+ return myArray[n-1];
+}
+
+void TSequenceOfXYZ::clear()
+{
+ myArray.clear();
+}
+
+void TSequenceOfXYZ::reserve(size_type n)
+{
+ myArray.reserve(n);
+}
+
+void TSequenceOfXYZ::push_back(const gp_XYZ& v)
+{
+ myArray.push_back(v);
+}
+
+TSequenceOfXYZ::size_type TSequenceOfXYZ::size() const
+{
+ return myArray.size();