Back to index

salome-geom  6.5.0
Functions
GEOMImpl_IMeasureOperations.cxx File Reference
#include <Standard_Stream.hxx>
#include <GEOMImpl_IMeasureOperations.hxx>
#include <GEOMImpl_Types.hxx>
#include <GEOMImpl_MeasureDriver.hxx>
#include <GEOMImpl_IMeasure.hxx>
#include <GEOMImpl_IShapesOperations.hxx>
#include <GEOMAlgo_ShapeInfo.hxx>
#include <GEOMAlgo_ShapeInfoFiller.hxx>
#include <GEOM_Function.hxx>
#include <GEOM_PythonDump.hxx>
#include <NMTTools_CheckerSI.hxx>
#include <NMTDS_Tools.hxx>
#include <NMTDS_InterfPool.hxx>
#include <NMTDS_PInterfPool.hxx>
#include <NMTDS_PairBoolean.hxx>
#include <NMTDS_ShapesDataStructure.hxx>
#include <NMTDS_ListIteratorOfListOfPairBoolean.hxx>
#include <Basics_OCCTVersion.hxx>
#include <utilities.h>
#include <OpUtil.hxx>
#include <Utils_ExceptHandlers.hxx>
#include <TFunction_DriverTable.hxx>
#include <TFunction_Driver.hxx>
#include <TFunction_Logbook.hxx>
#include <TDF_Tool.hxx>
#include <BRep_Tool.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <BRepBndLib.hxx>
#include <BRepCheck.hxx>
#include <BRepCheck_ListIteratorOfListOfStatus.hxx>
#include <BRepCheck_Result.hxx>
#include <BRepCheck_Shell.hxx>
#include <BRepExtrema_DistShapeShape.hxx>
#include <BRepGProp.hxx>
#include <BRepTools.hxx>
#include <Bnd_Box.hxx>
#include <GProp_GProps.hxx>
#include <GProp_PrincipalProps.hxx>
#include <TopAbs.hxx>
#include <TopExp.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <GeomAbs_SurfaceType.hxx>
#include <Geom_Surface.hxx>
#include <Geom_Plane.hxx>
#include <Geom_SphericalSurface.hxx>
#include <Geom_CylindricalSurface.hxx>
#include <Geom_ToroidalSurface.hxx>
#include <Geom_ConicalSurface.hxx>
#include <Geom_SurfaceOfLinearExtrusion.hxx>
#include <Geom_SurfaceOfRevolution.hxx>
#include <Geom_BezierSurface.hxx>
#include <Geom_BSplineSurface.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <Geom_OffsetSurface.hxx>
#include <Geom_Line.hxx>
#include <gp_Pln.hxx>
#include <gp_Lin.hxx>
#include <GeomAPI_ProjectPointOnCurve.hxx>
#include <GeomLProp_CLProps.hxx>
#include <GeomLProp_SLProps.hxx>
#include <ShapeAnalysis.hxx>
#include <ShapeAnalysis_Surface.hxx>
#include <Standard_Failure.hxx>
#include <Standard_ErrorHandler.hxx>
#include <BRepClass3d_SolidClassifier.hxx>
#include <BRep_Builder.hxx>
#include <GeomAPI_IntSS.hxx>
#include <Geom_Circle.hxx>
#include <ShapeFix_Shape.hxx>
#include <TopoDS_Compound.hxx>

Go to the source code of this file.

Functions

 Handle (GEOM_Object) GEOMImpl_IMeasureOperations
 GetCentreOfMass.
static double CheckSingularCase (const TopoDS_Shape &aSh1, const TopoDS_Shape &aSh2, gp_Pnt &Ptmp1, gp_Pnt &Ptmp2)
static Standard_Boolean Contains (const TopTools_ListOfShape &L, const TopoDS_Shape &S)

Function Documentation

static double CheckSingularCase ( const TopoDS_Shape &  aSh1,
const TopoDS_Shape &  aSh2,
gp_Pnt &  Ptmp1,
gp_Pnt &  Ptmp2 
) [static]

Definition at line 1550 of file GEOMImpl_IMeasureOperations.cxx.

{
  bool IsChange1 = false;
  double AddDist1 = 0.0;
  TopExp_Explorer anExp;
  TopoDS_Shape tmpSh1, tmpSh2;
  int nbf = 0;
  for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
    nbf++;
    tmpSh1 = anExp.Current();
  }
  if(nbf==1) {
    TopoDS_Shape sh = aSh1;
    while(sh.ShapeType()==TopAbs_COMPOUND) {
      TopoDS_Iterator it(sh);
      sh = it.Value();
    }
    Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
    if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
        S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
      if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
        // non solid case
        double U1,U2,V1,V2;
        // changes for 0020677: EDF 1219 GEOM: MinDistance gives 0 instead of 20.88
        //S->Bounds(U1,U2,V1,V2); changed by
        ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(tmpSh1),U1,U2,V1,V2);
        // end of changes for 020677 (dmv)
        Handle(Geom_RectangularTrimmedSurface) TrS1 =
          new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
        Handle(Geom_RectangularTrimmedSurface) TrS2 =
          new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
        BRep_Builder B;
        TopoDS_Face F1,F2;
        TopoDS_Compound Comp;
        B.MakeCompound(Comp);
        B.MakeFace(F1,TrS1,1.e-7);
        B.Add(Comp,F1);
        B.MakeFace(F2,TrS2,1.e-7);
        B.Add(Comp,F2);
        Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
        sfs->Init(Comp);
        sfs->SetPrecision(1.e-6);
        sfs->SetMaxTolerance(1.0);
        sfs->Perform();
        tmpSh1 = sfs->Shape();
        IsChange1 = true;
      }
      else {
        if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
          Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
          gp_Pnt PC = SS->Location();
          BRep_Builder B;
          TopoDS_Vertex V;
          B.MakeVertex(V,PC,1.e-7);
          tmpSh1 = V;
          AddDist1 = SS->Radius();
          IsChange1 = true;
        }
        else {
          Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
          gp_Ax3 ax3 = TS->Position();
          Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
          BRep_Builder B;
          TopoDS_Edge E;
          B.MakeEdge(E,C,1.e-7);
          tmpSh1 = E;
          AddDist1 = TS->MinorRadius();
          IsChange1 = true;
        }
      }
    }
    else
      tmpSh1 = aSh1;
  }
  else
    tmpSh1 = aSh1;
  bool IsChange2 = false;
  double AddDist2 = 0.0;
  nbf = 0;
  for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
    nbf++;
    tmpSh2 = anExp.Current();
  }
  if(nbf==1) {
    TopoDS_Shape sh = aSh2;
    while(sh.ShapeType()==TopAbs_COMPOUND) {
      TopoDS_Iterator it(sh);
      sh = it.Value();
    }
    Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
    if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
        S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
      if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
        // non solid case
        double U1,U2,V1,V2;
        //S->Bounds(U1,U2,V1,V2);
        ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(tmpSh2),U1,U2,V1,V2);
        Handle(Geom_RectangularTrimmedSurface) TrS1 =
          new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
        Handle(Geom_RectangularTrimmedSurface) TrS2 =
          new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
        BRep_Builder B;
        TopoDS_Face F1,F2;
        TopoDS_Compound Comp;
        B.MakeCompound(Comp);
        B.MakeFace(F1,TrS1,1.e-7);
        B.Add(Comp,F1);
        B.MakeFace(F2,TrS2,1.e-7);
        B.Add(Comp,F2);
        Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
        sfs->Init(Comp);
        sfs->SetPrecision(1.e-6);
        sfs->SetMaxTolerance(1.0);
        sfs->Perform();
        tmpSh2 = sfs->Shape();
        IsChange2 = true;
      }
      else {
        if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
          Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
          gp_Pnt PC = SS->Location();
          BRep_Builder B;
          TopoDS_Vertex V;
          B.MakeVertex(V,PC,1.e-7);
          tmpSh2 = V;
          AddDist2 = SS->Radius();
          IsChange2 = true;
        }
        else if( S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
          Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
          gp_Ax3 ax3 = TS->Position();
          Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
          BRep_Builder B;
          TopoDS_Edge E;
          B.MakeEdge(E,C,1.e-7);
          tmpSh2 = E;
          AddDist2 = TS->MinorRadius();
          IsChange2 = true;
        }
      }
    }
    else
      tmpSh2 = aSh2;
  }
  else
    tmpSh2 = aSh2;

  if( !IsChange1 && !IsChange2 )
    return -2.0;

  BRepExtrema_DistShapeShape dst(tmpSh1,tmpSh2);
  if (dst.IsDone()) {
    double MinDist = 1.e9;
    gp_Pnt PMin1, PMin2, P1, P2;
    for (int i = 1; i <= dst.NbSolution(); i++) {
      P1 = dst.PointOnShape1(i);
      P2 = dst.PointOnShape2(i);
      Standard_Real Dist = P1.Distance(P2);
      if (MinDist > Dist) {
        MinDist = Dist;
        PMin1 = P1;
        PMin2 = P2;
      }
    }
    if(MinDist<1.e-7) {
      Ptmp1 = PMin1;
      Ptmp2 = PMin2;
    }
    else {
      gp_Dir aDir(gp_Vec(PMin1,PMin2));
      if( MinDist > (AddDist1+AddDist2) ) {
        Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
                        PMin1.Y() + aDir.Y()*AddDist1,
                        PMin1.Z() + aDir.Z()*AddDist1 );
        Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
                        PMin2.Y() - aDir.Y()*AddDist2,
                        PMin2.Z() - aDir.Z()*AddDist2 );
        return (MinDist - AddDist1 - AddDist2);
      }
      else {
        if( AddDist1 > 0 ) {
          Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
                          PMin1.Y() + aDir.Y()*AddDist1,
                          PMin1.Z() + aDir.Z()*AddDist1 );
          Ptmp2 = Ptmp1;
        }
        else {
          Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
                          PMin2.Y() - aDir.Y()*AddDist2,
                          PMin2.Z() - aDir.Z()*AddDist2 );
          Ptmp1 = Ptmp2;
        }
      }
    }
    double res = MinDist - AddDist1 - AddDist2;
    if(res<0.) res = 0.0;
    return res;
  }
  return -2.0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Standard_Boolean Contains ( const TopTools_ListOfShape &  L,
const TopoDS_Shape &  S 
) [static]

Definition at line 2768 of file GEOMImpl_IMeasureOperations.cxx.

{
  TopTools_ListIteratorOfListOfShape it;
  for (it.Initialize(L); it.More(); it.Next()) {
    if (it.Value().IsSame(S)) {
      return Standard_True;
    }
  }
  return Standard_False;
}

Here is the caller graph for this function:

GetCentreOfMass.

GetObject.

GetNormal.

GetVertexByIndex.

Definition at line 891 of file GEOMImpl_IMeasureOperations.cxx.

{
  SetErrorCode(KO);

  if (theShape.IsNull()) return NULL;

  //Add a new CentreOfMass object
  Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);

  //Add a new CentreOfMass function
  Handle(GEOM_Function) aFunction =
    aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
  if (aFunction.IsNull()) return NULL;

  //Check if the function is set correctly
  if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;

  GEOMImpl_IMeasure aCI (aFunction);

  Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  if (aRefShape.IsNull()) return NULL;

  aCI.SetBase(aRefShape);

  //Compute the CentreOfMass value
  try {
#if OCC_VERSION_LARGE > 0x06010000
    OCC_CATCH_SIGNALS;
#endif
    if (!GetSolver()->ComputeFunction(aFunction)) {
      SetErrorCode("Measure driver failed to compute centre of mass");
      return NULL;
    }
  }
  catch (Standard_Failure) {
    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
    SetErrorCode(aFail->GetMessageString());
    return NULL;
  }

  //Make a Python command
  GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";

  SetErrorCode(OK);
  return aCDG;
}

Here is the call graph for this function: