Salome HOME
Mantis issue 0021864: [CEA 669] Wrong size of the bounding box. Clean triangulation...
authorjfa <jfa@opencascade.com>
Tue, 25 Sep 2012 13:07:23 +0000 (13:07 +0000)
committerjfa <jfa@opencascade.com>
Tue, 25 Sep 2012 13:07:23 +0000 (13:07 +0000)
src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx
src/MeasureGUI/MeasureGUI_BndBoxDlg.cxx

index 98abba29cb334a09d5a9ccd8300692767b77a087..df3a87a49963a3490934fa56f6eac236c9d82f20 100644 (file)
@@ -18,7 +18,6 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
 
 #include <Standard_Stream.hxx>
 
 #include <NMTDS_Tools.hxx>
 #include <NMTDS_InterfPool.hxx>
 #include <NMTDS_PInterfPool.hxx>
-//#include <NMTDS_PassKeyBoolean.hxx>
 #include <NMTDS_PairBoolean.hxx>
 #include <NMTDS_ShapesDataStructure.hxx>
-//#include <NMTDS_ListIteratorOfListOfPassKeyBoolean.hxx>
 #include <NMTDS_ListIteratorOfListOfPairBoolean.hxx>
 
 #include <Basics_OCCTVersion.hxx>
 #include <TFunction_Logbook.hxx>
 #include <TDF_Tool.hxx>
 
+#include <BRep_Builder.hxx>
+#include <BRep_TFace.hxx>
 #include <BRep_Tool.hxx>
 #include <BRepAdaptor_Surface.hxx>
+#include <BRepBuilderAPI_Copy.hxx>
 #include <BRepBndLib.hxx>
 #include <BRepCheck.hxx>
 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
 #include <BRepCheck_Result.hxx>
 #include <BRepCheck_Shell.hxx>
+#include <BRepClass3d_SolidClassifier.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_Face.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Vertex.hxx>
+#include <TopoDS_Compound.hxx>
 #include <TopoDS_Iterator.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopTools_MapOfShape.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 
+#include <ShapeAnalysis.hxx>
+#include <ShapeAnalysis_Surface.hxx>
+#include <ShapeFix_Shape.hxx>
+
+#include <GeomAPI_IntSS.hxx>
+#include <GeomAPI_ProjectPointOnCurve.hxx>
+
 #include <GeomAbs_SurfaceType.hxx>
-#include <Geom_Surface.hxx>
+
+#include <Geom_BezierSurface.hxx>
+#include <Geom_BSplineSurface.hxx>
+#include <Geom_Circle.hxx>
+#include <Geom_ConicalSurface.hxx>
+#include <Geom_CylindricalSurface.hxx>
+#include <Geom_Line.hxx>
+#include <Geom_OffsetSurface.hxx>
 #include <Geom_Plane.hxx>
+#include <Geom_RectangularTrimmedSurface.hxx>
 #include <Geom_SphericalSurface.hxx>
-#include <Geom_CylindricalSurface.hxx>
-#include <Geom_ToroidalSurface.hxx>
-#include <Geom_ConicalSurface.hxx>
+#include <Geom_Surface.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 <Geom_ToroidalSurface.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> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
+#include <GProp_GProps.hxx>
+#include <GProp_PrincipalProps.hxx>
 
-#include <BRepClass3d_SolidClassifier.hxx>
-#include <BRep_Builder.hxx>
-#include <GeomAPI_IntSS.hxx>
-#include <Geom_Circle.hxx>
-#include <Geom_SphericalSurface.hxx>
-#include <Geom_ToroidalSurface.hxx>
-#include <ShapeFix_Shape.hxx>
-#include <TopoDS_Compound.hxx>
+#include <gp_Pln.hxx>
+#include <gp_Lin.hxx>
 
+#include <Standard_Failure.hxx>
+#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
 
 //=============================================================================
 /*!
@@ -794,10 +792,10 @@ gp_Ax3 GEOMImpl_IMeasureOperations::GetPosition (const TopoDS_Shape& theShape)
       if(theShape.Orientation() == TopAbs_REVERSED)
       {
         gp_Dir Vx =  aResult.XDirection();
-        gp_Dir N  =  aResult.Direction().Mirrored(Vx); 
+        gp_Dir N  =  aResult.Direction().Mirrored(Vx);
         gp_Pnt P  =  aResult.Location();
         aResult = gp_Ax3(P, N, Vx);
-      }       
+      }
     }
   }
 
@@ -1206,6 +1204,17 @@ void GEOMImpl_IMeasureOperations::GetBoundingBox
 #if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
+    BRepBuilderAPI_Copy aCopyTool (aShape);
+    if (!aCopyTool.IsDone()) {
+      SetErrorCode("GetBoundingBox Error: Bad shape detected");
+      return;
+    }
+
+    aShape = aCopyTool.Shape();
+
+    // remove triangulation to obtain more exact boundaries
+    BRepTools::Clean(aShape);
+
     BRepBndLib::Add(aShape, B);
     B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
   }
@@ -1386,7 +1395,7 @@ bool GEOMImpl_IMeasureOperations::CheckSelfIntersections
   const NMTDS_ShapesDataStructure& aDS = *(aCSI.DS());
   Standard_Integer aNbS = aDS.NumberOfShapesOfTheObject();
 
-  // 3. Get the pairs of interfered shapes 
+  // 3. Get the pairs of interfered shapes
   NMTDS_PInterfPool pIP = aCSI.IP();
   //const NMTDS_ListOfPassKeyBoolean& aLPKB = pIP->Get();
   const NMTDS_ListOfPairBoolean& aLPKB = pIP->Get();
index 3544009ac56527bc54f90a29eaedc62a6d77b5e3..d3eb0603a053bb36b25c04010f31967e98a4ad65 100644 (file)
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
 
 // GEOM GEOMGUI : GUI for Geometry component
 // File   : MeasureGUI_BndBoxDlg.cxx
 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
-//
+
 #include "MeasureGUI_BndBoxDlg.h"
 #include "MeasureGUI_Widgets.h"
 
 #include <GEOMBase.h>
 #include <DlgRef.h>
 
-#include <GEOM_Function.hxx>
-#include <GEOM_Object.hxx>
-
 #include <BRepPrimAPI_MakeBox.hxx>
-#include <BRepAdaptor_Surface.hxx>
-#include <BRep_Tool.hxx>
-#include <BRep_TFace.hxx>
-#include <TopoDS.hxx>
-#include <TopoDS_Face.hxx>
-#include <TopExp_Explorer.hxx>
 
 #include <SUIT_Session.h>
 #include <SUIT_ResourceMgr.h>
-#include <SalomeApp_Tools.h>
-
-// #include <qlineedit.h>
-// #include <qlabel.h>
-// #include <qlayout.h>
-// #include <qpushbutton.h>
-// #include <qradiobutton.h>
-// #include <qbuttongroup.h>
 
 //=================================================================================
 // class    : MeasureGUI_BndBoxDlg()
-// purpose  : Constructs a MeasureGUI_BndBoxDlg which is a child of 'parent', with the 
+// purpose  : Constructs a MeasureGUI_BndBoxDlg which is a child of 'parent', with the
 //            name 'name' and widget flags set to 'f'.
 //            The dialog will by default be modeless, unless you set 'modal' to
 //            true to construct a modal dialog.
 //=================================================================================
-MeasureGUI_BndBoxDlg::MeasureGUI_BndBoxDlg( GeometryGUI* GUI, QWidget* parent )
-  : MeasureGUI_Skeleton( GUI, parent )
+MeasureGUI_BndBoxDlg::MeasureGUI_BndBoxDlg (GeometryGUI* GUI, QWidget* parent)
+  : MeasureGUI_Skeleton(GUI, parent)
 {
   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
     "GEOM", tr( "ICON_DLG_BOUNDING_BOX" ) ) );
@@ -72,7 +54,7 @@ MeasureGUI_BndBoxDlg::MeasureGUI_BndBoxDlg( GeometryGUI* GUI, QWidget* parent )
   setWindowTitle( tr( "GEOM_BNDBOX_TITLE" ) );
 
   /***************************************************************/
-  
+
   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_BNDBOX" ) );
   mainFrame()->RadioButton1->setIcon( image0 );
 
@@ -102,7 +84,7 @@ MeasureGUI_BndBoxDlg::MeasureGUI_BndBoxDlg( GeometryGUI* GUI, QWidget* parent )
   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
   layout->setMargin( 0 ); layout->setSpacing( 6 );
   layout->addWidget( myGrp );
-  
+
   /***************************************************************/
 
   myHelpFileName = "using_measurement_tools_page.html#bounding_box_anchor";
@@ -111,7 +93,6 @@ MeasureGUI_BndBoxDlg::MeasureGUI_BndBoxDlg( GeometryGUI* GUI, QWidget* parent )
   Init();
 }
 
-
 //=================================================================================
 // function : ~MeasureGUI_BndBoxDlg()
 // purpose  : Destroys the object and frees any allocated resources
@@ -120,7 +101,6 @@ MeasureGUI_BndBoxDlg::~MeasureGUI_BndBoxDlg()
 {
 }
 
-
 //=================================================================================
 // function : Init()
 // purpose  :
@@ -140,14 +120,14 @@ void MeasureGUI_BndBoxDlg::processObject()
 {
   double aXMin, aXMax, aYMin, aYMax, aZMin, aZMax;
 
-  if ( !getParameters( aXMin, aXMax, aYMin, aYMax, aZMin, aZMax ) ) {
-    mySelEdit->setText( "" );
-    myGrp->LineEdit11->setText( "" );
-    myGrp->LineEdit12->setText( "" );
-    myGrp->LineEdit21->setText( "" );
-    myGrp->LineEdit22->setText( "" );
-    myGrp->LineEdit31->setText( "" );
-    myGrp->LineEdit32->setText( "" );
+  if (!getParameters(aXMin, aXMax, aYMin, aYMax, aZMin, aZMax)) {
+    mySelEdit->setText("");
+    myGrp->LineEdit11->setText("");
+    myGrp->LineEdit12->setText("");
+    myGrp->LineEdit21->setText("");
+    myGrp->LineEdit22->setText("");
+    myGrp->LineEdit31->setText("");
+    myGrp->LineEdit32->setText("");
   }
   else {
     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
@@ -168,71 +148,17 @@ void MeasureGUI_BndBoxDlg::processObject()
 // function : getParameters
 // purpose  :
 //=================================================================================
-bool MeasureGUI_BndBoxDlg::getParametersdouble& theXmin, double& theXmax,
+bool MeasureGUI_BndBoxDlg::getParameters (double& theXmin, double& theXmax,
                                           double& theYmin, double& theYmax,
-                                          double& theZmin, double& theZmax )
+                                          double& theZmin, double& theZmax)
 {
-  if ( myObj->_is_nil() )
+  if (myObj->_is_nil())
     return false;
-  else {
-    GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
-    try {
-      Handle(Poly_Triangulation) Trtn = 0; 
-
-      GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen();
-      if ( CORBA::is_nil(aGeomGen) )
-        return false;
-
-      QString IOR = GEOMBase::GetIORFromObject( myObj );
-      GEOM::GEOM_Object_var anObject = aGeomGen->GetIORFromString( IOR.toLatin1().constData() );
-      if ( CORBA::is_nil(anObject) )
-        return false;
-
-      TopoDS_Shape aShape;
-      GEOMBase::GetShape(anObject, aShape, TopAbs_SHAPE);
-      if ( aShape.IsNull() )
-        return false;
-      
-      TopLoc_Location l;
-      Handle(Poly_Triangulation) T;
-      TopExp_Explorer ex;
-      for (ex.Init(aShape,TopAbs_FACE); ex.More(); ex.Next()) {
-        const TopoDS_Face& F = TopoDS::Face(ex.Current());
-        BRepAdaptor_Surface surf(F);
-        if (surf.GetType() == GeomAbs_Sphere) {
-          T = BRep_Tool::Triangulation(F, l);
-          if (!T.IsNull()) {
-            Handle(Poly_Triangulation) NullTrtn = 0;
-            (*((Handle(BRep_TFace)*)&F.TShape()))->Triangulation(NullTrtn);
-            Trtn = T;
-            break;
-          }
-        }
-        else
-          break;
-      }
-      
-      anOper->GetBoundingBox( myObj, theXmin, theXmax, theYmin, theYmax, theZmin, theZmax );
-      
-      if (!Trtn.IsNull()) {
-        TopLoc_Location l;
-        Handle(Poly_Triangulation) T;
-        TopExp_Explorer ex;
-        for (ex.Init(aShape,TopAbs_FACE); ex.More(); ex.Next()) {
-          const TopoDS_Face& F = TopoDS::Face(ex.Current());
-          (*((Handle(BRep_TFace)*)&F.TShape()))->Triangulation(Trtn);
-          break;
-        }
-      }
-      
-    }
-    catch( const SALOME::SALOME_Exception& e ) {
-      SalomeApp_Tools::QtCatchCorbaException( e );
-      return false;
-    }
-
-    return anOper->IsDone();
-  }
+
+  GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow(getOperation());
+  anOper->GetBoundingBox(myObj, theXmin, theXmax, theYmin, theYmax, theZmin, theZmax);
+
+  return anOper->IsDone();
 }
 
 //=================================================================================
@@ -243,12 +169,11 @@ SALOME_Prs* MeasureGUI_BndBoxDlg::buildPrs()
 {
   double aXMin, aYMin, aZMin, aXMax, aYMax, aZMax;
 
-  if ( myObj->_is_nil() || !getParameters( aXMin, aXMax, aYMin, aYMax, aZMin, aZMax ) )
+  if (!getParameters(aXMin, aXMax, aYMin, aYMax, aZMin, aZMax))
     return 0;
 
-  TopoDS_Shape aShape = BRepPrimAPI_MakeBox( gp_Pnt( aXMin, aYMin, aZMin ),
-                                             gp_Pnt( aXMax, aYMax, aZMax ) ).Shape();
-       
-  return !aShape.IsNull() ? getDisplayer()->BuildPrs( aShape ) : 0;
+  TopoDS_Shape aShape = BRepPrimAPI_MakeBox(gp_Pnt(aXMin, aYMin, aZMin),
+                                            gp_Pnt(aXMax, aYMax, aZMax)).Shape();
 
+  return !aShape.IsNull() ? getDisplayer()->BuildPrs(aShape) : 0;
 }