Back to index

salome-geom  6.5.0
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
ShHealOper_CloseContour Class Reference

Class ShHealOper_CloseContour. More...

#include <ShHealOper_CloseContour.hxx>

Inheritance diagram for ShHealOper_CloseContour:
Inheritance graph
[legend]
Collaboration diagram for ShHealOper_CloseContour:
Collaboration graph
[legend]

List of all members.

Public Member Functions

Standard_EXPORT ShHealOper_CloseContour ()
Standard_EXPORT ShHealOper_CloseContour (const TopoDS_Shape &theShape)
virtual Standard_EXPORT void Init (const TopoDS_Shape &theShape)
Standard_EXPORT Standard_Boolean Perform (const TopTools_SequenceOfShape &theSeqEdges, const Standard_Boolean theModeVertex=Standard_False, const Standard_Boolean theModeFixGapsCurves=Standard_True)
Standard_EXPORT Standard_Boolean Perform (const TopoDS_Wire &theWire, const Standard_Boolean theModeVertex=Standard_False, const Standard_Boolean theModeFixGapsCurves=Standard_True)
void SetTolerance (const Standard_Real theTolerance)
Standard_Real GetTolerance ()
void SetMaxTolerance (const Standard_Real theMaxTolerance)
Standard_Real GetMaxTolerance ()
void SetModeVertex (const Standard_Boolean theModeVertex)
Standard_Boolean GetModeVertex ()
const TopoDS_Shape & GetResultShape () const
Standard_Boolean GetModifiedShape (const TopoDS_Shape &theOldShape, TopoDS_Shape &theNewShape) const
Standard_Boolean IsDone () const
void SetContext (Handle(ShapeBuild_ReShape)&theContext)
 Handle (ShapeBuild_ReShape) Context()
Standard_Integer GetErrorStatus ()

Protected Member Functions

 Handle (ShapeBuild_ReShape) myContext

Protected Attributes

TopoDS_Shape myInitShape
TopoDS_Shape myResultShape
Standard_Boolean myDone
ShHealOper_Error myErrorStatus

Private Member Functions

void build (Handle(ShapeExtend_WireData)&theSewd)
Standard_Boolean fixGaps (const Handle(ShapeExtend_WireData)&theWire, const TopTools_SequenceOfShape &theCommonFaces)
Standard_Boolean checkOneFace (const Handle(ShapeExtend_WireData)&theSewd, TopTools_SequenceOfShape &theCommonFaces) const
void buildEdge (const TopoDS_Edge &aE1, const TopoDS_Edge &aE2, const TopTools_SequenceOfShape &theCommonFaces)
void updateWire (Handle(ShapeExtend_WireData)&sbwd)

Private Attributes

Standard_Boolean myModeVertex
Standard_Boolean myModeFixGapsCurves
Standard_Real myMaxTolerance
Standard_Real myTolerance
TopTools_IndexedDataMapOfShapeListOfShape myMapEdgesFace
TopTools_SequenceOfShape myFreeEdges

Detailed Description

Class ShHealOper_CloseContour.

Definition at line 44 of file ShHealOper_CloseContour.hxx.


Constructor & Destructor Documentation

Definition at line 48 of file ShHealOper_CloseContour.hxx.

ShHealOper_CloseContour::ShHealOper_CloseContour ( const TopoDS_Shape &  theShape)

Definition at line 63 of file ShHealOper_CloseContour.cxx.

{
  Init(theShape);
}

Here is the call graph for this function:


Member Function Documentation

void ShHealOper_CloseContour::build ( Handle(ShapeExtend_WireData)&  theSewd) [private]

Definition at line 133 of file ShHealOper_CloseContour.cxx.

{
  TopTools_SequenceOfShape aCommonFaces;
  //checks that all specified edges belong the one face or not.
  Standard_Boolean isOneFace = checkOneFace(theSewd,aCommonFaces);

  //add edge or increase max tolerance in dependance on specified VertexMode.
  //if all edges belong the one face that gap will be closed in the 2D by line
  //else gap will be closed in the 3D by line.
  myDone = fixGaps(theSewd,aCommonFaces);
  updateWire(theSewd);
  Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
  sfw->SetContext(myContext);
  sfw->Load(theSewd);

  sfw->ClosedWireMode() = Standard_True;
  sfw->SetPrecision(myTolerance);
  sfw->SetMaxTolerance(myMaxTolerance);
  
  if(isOneFace) {
    Standard_Integer ii =1;
    for( ; ii <= aCommonFaces.Length(); ii++) {
      TopoDS_Face aFace = TopoDS::Face(aCommonFaces.Value(ii));
      sfw->SetFace(aFace);
      myDone = (sfw->Perform() || myDone);
      //if Mode for fix gaps is equal to true that
      //curve 3D and curve 2D will be pull to each other.
      if(myModeFixGapsCurves) {
        Standard_Boolean isFixgaps = Standard_False;
        if(ii ==1) {
          sfw->FixGaps3d();
          isFixgaps = sfw->StatusGaps3d(ShapeExtend_DONE);
          if(!isFixgaps && sfw->StatusGaps3d(ShapeExtend_FAIL))
             myErrorStatus = ShHealOper_ErrorExecution;
        }
        if(sfw->FixGaps2d())
          sfw->FixSelfIntersection();
        else if(sfw->StatusGaps2d(ShapeExtend_FAIL))
          myErrorStatus = ShHealOper_ErrorExecution;

        isFixgaps = (isFixgaps || sfw->StatusGaps2d(ShapeExtend_DONE));
        myDone = (myDone || isFixgaps);
        if(isFixgaps) {
          Handle(ShapeExtend_WireData) sbwd = sfw->WireData();
          Handle(ShapeFix_Edge) sfe = new ShapeFix_Edge;
          for (Standard_Integer iedge = 1; iedge <= sbwd->NbEdges(); iedge++) {
            TopoDS_Edge aEdge = TopoDS::Edge(sbwd->Edge(iedge));
            sfe->FixVertexTolerance(aEdge,aFace);
            sfe->FixSameParameter(aEdge);
          }
        }
      }
    }
  }
  else {
    myDone = (sfw->Perform() || myDone);
    if(myModeFixGapsCurves) {
      //if Mode for fix gaps is equal to true that
      //curve 3D will be pull to each other.
      if(sfw->FixGaps3d()) {
        Handle(ShapeExtend_WireData) sbwd = sfw->WireData();
        Handle(ShapeFix_Edge) sfe = new ShapeFix_Edge;
        for (Standard_Integer iedge = 1; iedge <= sbwd->NbEdges(); iedge++) {
          TopoDS_Edge aEdge = TopoDS::Edge(sbwd->Edge(iedge));
          sfe->FixVertexTolerance(aEdge);
          sfe->FixSameParameter(aEdge);
        }
      }
      else if(sfw->StatusGaps3d(ShapeExtend_FAIL))
        myErrorStatus = ShHealOper_ErrorExecution;
      myDone = (sfw->StatusGaps3d(ShapeExtend_DONE) || myDone);
    }
  }

  if(myDone) {
    TopoDS_Shape aoldShape = myInitShape;
    //if free edges were added they will be added to the result shape
    //and type of result shape should be change if initial shape is not COMPOUND.
    if( myFreeEdges.Length()) {
      BRep_Builder aB;
      TopoDS_Compound aComp;
      aB.MakeCompound(aComp);
      if(aoldShape.ShapeType() == TopAbs_COMPOUND) {
        TopoDS_Iterator aIt(aoldShape);
        for( ;aIt.More();aIt.Next() )
           aB.Add(aComp,aIt.Value());
      }
      else
        aB.Add(aComp,aoldShape);

      Standard_Integer i=1;
      for ( ; i <= myFreeEdges.Length(); i++ ) 
        aB.Add(aComp,myFreeEdges.Value(i));
      aoldShape = aComp;
      
    }
    myResultShape = myContext->Apply(aoldShape);
  }
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ShHealOper_CloseContour::buildEdge ( const TopoDS_Edge &  aE1,
const TopoDS_Edge &  aE2,
const TopTools_SequenceOfShape &  theCommonFaces 
) [private]

Definition at line 338 of file ShHealOper_CloseContour.cxx.

{
  ShapeAnalysis_Edge asae;
  TopoDS_Vertex aV1 = asae.LastVertex(aE1);
  TopoDS_Vertex aV2 = asae.FirstVertex(aE2);
  gp_Pnt p1 = BRep_Tool::Pnt(aV1);
  gp_Pnt p2 = BRep_Tool::Pnt(aV2);
  BRepBuilderAPI_MakeVertex mkver1( p1 );
  TopoDS_Vertex newV1 = mkver1.Vertex();
  
  BRepBuilderAPI_MakeVertex mkver2( p2 );
  TopoDS_Vertex newV2 = mkver2.Vertex();
  BRep_Builder B;
  B.UpdateVertex ( newV1,Precision::Confusion());
  B.UpdateVertex ( newV2, Precision::Confusion());
  Standard_Boolean isBuild = Standard_False;
  TopoDS_Edge edge;
  B.MakeEdge ( edge );
  ShapeBuild_Edge sbe;
  //if all edges belong to one face that gap will be closed in the 2D by line
  //than 3D curve will be built by 2D curve
  if(theCommonFaces.Length()) {
    
    TopoDS_Face aF1 = TopoDS::Face(theCommonFaces.Value(1));
    Handle(Geom2d_Curve) c2d1,c2d2;
    gp_Pnt2d p2d1,p2d2;
    Standard_Real a1, b1,a2, b2;
    if (  asae.PCurve ( aE1, aF1, c2d1, a1, b1, Standard_True )  && 
        asae.PCurve ( aE2, aF1, c2d2, a2, b2, Standard_True )) {
      
      c2d1->D0 ( b1, p2d1);
      c2d2->D0 ( a2, p2d2);
      gp_Vec2d v12 ( p2d1, p2d2 );
      
      Handle(Geom2d_Line) aLine2d = new Geom2d_Line ( p2d1, gp_Dir2d ( v12 ) );
      B.UpdateEdge ( edge, aLine2d, aF1, ::Precision::Confusion() );
      B.Range ( edge, aF1, 0.0, v12.Magnitude() );
      
      isBuild = sbe.BuildCurve3d ( edge );
    }
  }
  //else gap will be closed in the 3D by line.
  if(!isBuild) {
    gp_Vec v1 ( p1, p2 );
    Handle(Geom_Line) aLine = new Geom_Line ( p1, gp_Dir ( v1 ) );
    B.UpdateEdge ( edge, aLine, ::Precision::Confusion() );
    B.Range ( edge,0.0, v1.Magnitude());
  }
  B.Add ( edge, newV1.Oriented ( TopAbs_FORWARD ) );
  B.Add ( edge, newV2.Oriented ( TopAbs_REVERSED ) );
  myContext->Replace(aV1, newV1.Oriented (aV1.Orientation()));
  myContext->Replace(aV2, newV2.Oriented (aV2.Orientation()));
  if(isBuild) {
    newV1.Orientation(aV1.Orientation());
    TopoDS_Edge newEdge = sbe.CopyReplaceVertices ( aE1,TopoDS_Vertex(), newV1);
    TopoDS_Wire aw;
    B.MakeWire(aw);
    B.Add(aw,newEdge);
    B.Add(aw,edge);
    TopoDS_Shape anE1 = myContext->Apply(aE1);
    myContext->Replace(anE1,aw);
  }
  else {
    myFreeEdges.Append(edge);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Standard_Boolean ShHealOper_CloseContour::checkOneFace ( const Handle(ShapeExtend_WireData)&  theSewd,
TopTools_SequenceOfShape &  theCommonFaces 
) const [private]

Definition at line 271 of file ShHealOper_CloseContour.cxx.

{
  TopTools_IndexedMapOfShape amapfaces;
  TopoDS_Edge aEdge1 = theSewd->Edge(1);
  Standard_Boolean isOneFace = myMapEdgesFace.Contains(aEdge1 );
  if(!isOneFace)
    return isOneFace;

  //check that all specified edges belong to one face. 
  const TopTools_ListOfShape& alfaces = myMapEdgesFace.FindFromKey(aEdge1);
  isOneFace = isOneFace && (!alfaces.IsEmpty());
  if(!isOneFace)
    return Standard_False;

  TopTools_ListIteratorOfListOfShape litr(alfaces);
  for( ; litr.More();litr.Next() ) 
    amapfaces.Add(litr.Value());
  
  TColStd_MapOfInteger amapIndex;
  Standard_Integer ind  =0;
  Standard_Integer i =2;
  for( ; i <= theSewd->NbEdges() && isOneFace; i++) {
    isOneFace = myMapEdgesFace.Contains(theSewd->Edge(i));
    if(isOneFace) {
      const TopTools_ListOfShape& alfaces1 = myMapEdgesFace.FindFromKey(theSewd->Edge(i));
      
        TColStd_MapOfInteger aTmpInd;
        for(litr.Initialize(alfaces1) ; litr.More() ;litr.Next() ) {
          if(amapfaces.Contains(litr.Value())) {
            ind = amapfaces.FindIndex(litr.Value());
            if( i == 2) 
              amapIndex.Add(ind);
            else 
              aTmpInd.Add(ind);
          }
        }
      if(i ==2) {
        isOneFace = (amapIndex.Extent());
        continue;
      }
      else {
        TColStd_MapIteratorOfMapOfInteger aMi(amapIndex);
        for( ;  aMi.More();aMi.Next()) {
          if(!aTmpInd.Contains(aMi.Key()))
            amapIndex.Remove(aMi.Key());
        }
        isOneFace = (amapIndex.Extent()); 
        
      }
    }
  }
  if(theSewd->NbEdges() >1) {
    Standard_Integer j =1;
    for( ; j <= amapfaces.Extent(); j++) {
      if(!amapIndex.Contains(j)) continue;
      TopoDS_Shape aF = amapfaces.FindKey(j);
      theCommonFaces.Append(aF);
    }
  }
  return isOneFace;
}

Here is the caller graph for this function:

Standard_Boolean ShHealOper_CloseContour::fixGaps ( const Handle(ShapeExtend_WireData)&  theWire,
const TopTools_SequenceOfShape &  theCommonFaces 
) [private]

Definition at line 238 of file ShHealOper_CloseContour.cxx.

{
  Handle(ShapeAnalysis_Wire) asaw = new ShapeAnalysis_Wire;
  asaw->Load(theWire);
  
  Standard_Integer i =1;
  Standard_Boolean hasGaps = Standard_False;
  for ( ; i <= asaw->NbEdges(); i++) {
    if(asaw->CheckGap3d(i)) {
      Standard_Real dist = asaw->MinDistance3d();
      if(dist > myMaxTolerance) {
        hasGaps = Standard_True;
        Standard_Integer ind2 = (i ==0 ? theWire->NbEdges() :i);
        Standard_Integer ind1 = (ind2 >1 ? ind2 -1 : theWire->NbEdges());
        TopoDS_Edge aE1= theWire->Edge(ind1);
        TopoDS_Edge aE2= theWire->Edge(ind2);
        if(!myModeVertex)
          buildEdge(aE1,aE2,theCommonFaces);
        else
          myMaxTolerance = RealLast();
        if(ind2 == ind1) break;
      }
    }
    
  }
  return  hasGaps;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Standard_Integer ShHealOper_Tool::GetErrorStatus ( ) [inline, inherited]

Definition at line 90 of file ShHealOper_Tool.hxx.

  {
    return myErrorStatus;
  }

Here is the caller graph for this function:

Standard_Real ShHealOper_CloseContour::GetMaxTolerance ( ) [inline]

Definition at line 88 of file ShHealOper_CloseContour.hxx.

  {
    return  myMaxTolerance;
  }
Standard_Boolean ShHealOper_CloseContour::GetModeVertex ( ) [inline]

Definition at line 100 of file ShHealOper_CloseContour.hxx.

  {
    return myModeVertex;
  }
Standard_Boolean ShHealOper_Tool::GetModifiedShape ( const TopoDS_Shape &  theOldShape,
TopoDS_Shape &  theNewShape 
) const [inline, inherited]

Definition at line 64 of file ShHealOper_Tool.hxx.

  {
    theNewShape = myContext->Apply(theOldShape);
    return (!theNewShape.IsSame(theOldShape));
  }
const TopoDS_Shape& ShHealOper_Tool::GetResultShape ( ) const [inline, inherited]

Definition at line 57 of file ShHealOper_Tool.hxx.

  {
    return myResultShape;

  }

Here is the caller graph for this function:

Standard_Real ShHealOper_CloseContour::GetTolerance ( ) [inline]

Definition at line 76 of file ShHealOper_CloseContour.hxx.

  {
    return  myTolerance;
  }
ShHealOper_Tool::Handle ( ShapeBuild_ReShape  ) [inline, inherited]

Definition at line 84 of file ShHealOper_Tool.hxx.

  {
    return myContext;
  }

Here is the caller graph for this function:

ShHealOper_Tool::Handle ( ShapeBuild_ReShape  ) [protected, inherited]
void ShHealOper_CloseContour::Init ( const TopoDS_Shape &  theShape) [virtual]

Reimplemented from ShHealOper_Tool.

Definition at line 72 of file ShHealOper_CloseContour.cxx.

{
  ShHealOper_Tool::Init(theShape);
  myTolerance = Precision::Confusion();
  myMaxTolerance = 1.0;
  TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,myMapEdgesFace);
}

Here is the caller graph for this function:

Standard_Boolean ShHealOper_Tool::IsDone ( ) const [inline, inherited]

Definition at line 72 of file ShHealOper_Tool.hxx.

  {
    return myDone;
  }
Standard_Boolean ShHealOper_CloseContour::Perform ( const TopTools_SequenceOfShape &  theSeqEdges,
const Standard_Boolean  theModeVertex = Standard_False,
const Standard_Boolean  theModeFixGapsCurves = Standard_True 
)

Definition at line 84 of file ShHealOper_CloseContour.cxx.

{
  myFreeEdges.Clear();
  myDone = Standard_False;
  myErrorStatus =ShHealOper_NotError;
  if(myInitShape.IsNull()) {
    myErrorStatus = ShHealOper_InvalidParameters;
    return myDone;
  }
  Handle(ShapeExtend_WireData) asewd = new ShapeExtend_WireData;
  Standard_Integer i =1;
  for ( ; i <= theSeqEdges.Length(); i++)
    asewd->Add(theSeqEdges.Value(i));

  myModeVertex = theModeVertex;
  myModeFixGapsCurves = theModeFixGapsCurves;

  build(asewd);
  
  return myDone;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Standard_Boolean ShHealOper_CloseContour::Perform ( const TopoDS_Wire &  theWire,
const Standard_Boolean  theModeVertex = Standard_False,
const Standard_Boolean  theModeFixGapsCurves = Standard_True 
)

Definition at line 112 of file ShHealOper_CloseContour.cxx.

{
  myFreeEdges.Clear();
  myDone = Standard_False;
  if(myInitShape.IsNull()) {
    myErrorStatus = ShHealOper_InvalidParameters;
    return myDone;
  }
  Handle(ShapeExtend_WireData) asewd = new ShapeExtend_WireData(theWire);
  myModeVertex = theModeVertex;
  myModeFixGapsCurves = theModeFixGapsCurves;
  build(asewd);
  return myDone;
}

Here is the call graph for this function:

void ShHealOper_Tool::SetContext ( Handle(ShapeBuild_ReShape)&  theContext) [inline, inherited]

Definition at line 78 of file ShHealOper_Tool.hxx.

  {
    myContext = theContext;
  }
void ShHealOper_CloseContour::SetMaxTolerance ( const Standard_Real  theMaxTolerance) [inline]

Definition at line 82 of file ShHealOper_CloseContour.hxx.

  {
    myMaxTolerance = theMaxTolerance;
  }
void ShHealOper_CloseContour::SetModeVertex ( const Standard_Boolean  theModeVertex) [inline]

Definition at line 94 of file ShHealOper_CloseContour.hxx.

  {
    myModeVertex = theModeVertex;
  }
void ShHealOper_CloseContour::SetTolerance ( const Standard_Real  theTolerance) [inline]

Definition at line 70 of file ShHealOper_CloseContour.hxx.

  {
    myTolerance = theTolerance;
  }
void ShHealOper_CloseContour::updateWire ( Handle(ShapeExtend_WireData)&  sbwd) [private]

Definition at line 411 of file ShHealOper_CloseContour.cxx.

{
  Standard_Integer i=1;
  for ( ; i <= sbwd->NbEdges(); i++ ) {
    TopoDS_Edge E = sbwd->Edge(i);
    TopoDS_Shape S = myContext->Apply ( E );
    if ( S == E ) continue;
    for ( TopExp_Explorer exp(S,TopAbs_EDGE); exp.More(); exp.Next() )
      sbwd->Add ( exp.Current(), i++ );
    sbwd->Remove ( i-- );
  }
  for ( i =1; i <= myFreeEdges.Length(); i++ ) {
    sbwd->Add(TopoDS::Edge(myFreeEdges.Value(i)));
  }
}

Here is the caller graph for this function:


Member Data Documentation

Standard_Boolean ShHealOper_Tool::myDone [protected, inherited]

Definition at line 100 of file ShHealOper_Tool.hxx.

Definition at line 101 of file ShHealOper_Tool.hxx.

TopTools_SequenceOfShape ShHealOper_CloseContour::myFreeEdges [private]

Definition at line 133 of file ShHealOper_CloseContour.hxx.

TopoDS_Shape ShHealOper_Tool::myInitShape [protected, inherited]

Definition at line 98 of file ShHealOper_Tool.hxx.

TopTools_IndexedDataMapOfShapeListOfShape ShHealOper_CloseContour::myMapEdgesFace [private]

Definition at line 132 of file ShHealOper_CloseContour.hxx.

Standard_Real ShHealOper_CloseContour::myMaxTolerance [private]

Definition at line 130 of file ShHealOper_CloseContour.hxx.

Definition at line 128 of file ShHealOper_CloseContour.hxx.

Standard_Boolean ShHealOper_CloseContour::myModeVertex [private]

Definition at line 127 of file ShHealOper_CloseContour.hxx.

TopoDS_Shape ShHealOper_Tool::myResultShape [protected, inherited]

Definition at line 99 of file ShHealOper_Tool.hxx.

Standard_Real ShHealOper_CloseContour::myTolerance [private]

Definition at line 131 of file ShHealOper_CloseContour.hxx.


The documentation for this class was generated from the following files: