Bug 0020228: [CEA 331] the geompy.RemoveExtraEdges crash with the attached brep shape file. Added a new parameter theOptimumNbFaces to the RemoveExtraEdges functionality. In GUI it is a boolean flag.

This commit is contained in:
jfa 2009-04-21 13:28:59 +00:00
parent a6c9711ba9
commit 8fc906ac5a
18 changed files with 278 additions and 239 deletions

View File

@ -21,7 +21,7 @@
//
// File : GEOM_Gen.idl
// Author : Sergey RUIN
//
#ifndef __GEOM_GEN__
#define __GEOM_GEN__
@ -1869,9 +1869,14 @@ module GEOM
* Remove all seam and degenerated edges from \a theShape.
* Unite faces and edges, sharing one surface.
* \param theShape The compound or single solid to remove irregular edges from.
* \param theOptimumNbFaces If more than zero, unite faces only for those solids,
* that have more than theOptimumNbFaces faces. If zero, unite faces always,
* regardsless their quantity in the solid. If negative, do not unite faces at all.
* For blocks repairing recommended value is 6.
* \return Improved shape.
*/
GEOM_Object RemoveExtraEdges (in GEOM_Object theShape);
GEOM_Object RemoveExtraEdges (in GEOM_Object theShape,
in long theOptimumNbFaces);
/*!
* Check, if the given shape is a blocks compound.

View File

@ -22,7 +22,7 @@
// File: BlockFix_BlockFixAPI.cxx
// Created: Tue Dec 7 11:59:05 2004
// Author: Pavel DURANDIN
//
#include <BlockFix_BlockFixAPI.ixx>
#include <BlockFix.hxx>
#include <BlockFix_UnionFaces.hxx>
@ -37,6 +37,7 @@
BlockFix_BlockFixAPI::BlockFix_BlockFixAPI()
{
myTolerance = Precision::Confusion();
myOptimumNbFaces = 6;
}
//=======================================================================
@ -46,7 +47,6 @@ BlockFix_BlockFixAPI::BlockFix_BlockFixAPI()
void BlockFix_BlockFixAPI::Perform()
{
// processing spheres with degenerativities
TopoDS_Shape aShape = Shape();
myShape = BlockFix::RotateSphereSpace(aShape,myTolerance);
@ -54,14 +54,12 @@ void BlockFix_BlockFixAPI::Perform()
// faces unification
BlockFix_UnionFaces aFaceUnifier;
aFaceUnifier.GetTolerance() = myTolerance;
TopoDS_Shape aResult;
aResult = aFaceUnifier.Perform(myShape);
aFaceUnifier.GetOptimumNbFaces() = myOptimumNbFaces;
TopoDS_Shape aResult = aFaceUnifier.Perform(myShape);
BlockFix_UnionEdges anEdgeUnifier;
myShape = anEdgeUnifier.Perform(aResult,myTolerance);
TopoDS_Shape aRes = BlockFix::FixRanges(myShape,myTolerance);
myShape = aRes;
}

View File

@ -18,7 +18,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#ifndef _BlockFix_BlockFixAPI_HeaderFile
#define _BlockFix_BlockFixAPI_HeaderFile
@ -41,14 +41,14 @@
#ifndef _MMgt_TShared_HeaderFile
#include <MMgt_TShared.hxx>
#endif
class ShapeBuild_ReShape;
class TopoDS_Shape;
class BlockFix_BlockFixAPI : public MMgt_TShared {
class BlockFix_BlockFixAPI : public MMgt_TShared
{
public:
void* operator new(size_t,void* anAddress)
{
return anAddress;
@ -61,6 +61,7 @@ public:
{
if (anAddress) Standard::Free((Standard_Address&)anAddress);
}
// Methods PUBLIC
//
Standard_EXPORT BlockFix_BlockFixAPI();
@ -69,49 +70,24 @@ Standard_EXPORT void Perform() ;
TopoDS_Shape Shape() const;
Handle_ShapeBuild_ReShape& Context();
Standard_Real& Tolerance();
Standard_Integer& OptimumNbFaces();
Standard_EXPORT ~BlockFix_BlockFixAPI();
// Type management
//
Standard_EXPORT friend Handle_Standard_Type& BlockFix_BlockFixAPI_Type_();
Standard_EXPORT const Handle(Standard_Type)& DynamicType() const;
Standard_EXPORT Standard_Boolean IsKind(const Handle(Standard_Type)&) const;
protected:
// Methods PROTECTED
//
// Fields PROTECTED
//
private:
// Methods PRIVATE
//
// Fields PRIVATE
//
Handle_ShapeBuild_ReShape myContext;
TopoDS_Shape myShape;
Standard_Real myTolerance;
Standard_Integer myOptimumNbFaces;
};
#include <BlockFix_BlockFixAPI.lxx>
// other Inline functions and methods (like "C++: function call" methods)
//
#endif

View File

@ -18,11 +18,11 @@
// 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 <BlockFix_BlockFixAPI.hxx>
//=======================================================================
//function : Shape
//function : SetShape
//purpose :
//=======================================================================
@ -61,3 +61,12 @@ inline Standard_Real& BlockFix_BlockFixAPI::Tolerance()
return myTolerance;
}
//=======================================================================
//function : OptimumNbFaces
//purpose :
//=======================================================================
inline Standard_Integer& BlockFix_BlockFixAPI::OptimumNbFaces()
{
return myOptimumNbFaces;
}

View File

@ -25,9 +25,11 @@
#include <BlockFix_CheckTool.ixx>
//#include <BlockFix_UnionEdges.hxx>
//#include <BlockFix_UnionFaces.hxx>
#include <BRep_Tool.hxx>
#include <BlockFix_UnionEdges.hxx>
#include <BlockFix_UnionFaces.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>

View File

@ -22,7 +22,6 @@
// File: BlockFix_UnionFaces.cxx
// Created: Tue Dec 7 17:15:42 2004
// Author: Pavel DURANDIN
//
#include <BlockFix_UnionFaces.ixx>
@ -86,13 +85,14 @@
//=======================================================================
BlockFix_UnionFaces::BlockFix_UnionFaces()
: myTolerance(Precision::Confusion())
: myTolerance(Precision::Confusion()),
myOptimumNbFaces(6)
{
}
//=======================================================================
//function : GetTolearnce
//function : GetTolerance
//purpose :
//=======================================================================
@ -102,6 +102,17 @@ Standard_Real& BlockFix_UnionFaces::GetTolerance()
}
//=======================================================================
//function : GetOptimumNbFaces
//purpose :
//=======================================================================
Standard_Integer& BlockFix_UnionFaces::GetOptimumNbFaces()
{
return myOptimumNbFaces;
}
//=======================================================================
//function : AddOrdinaryEdges
//purpose : auxilary
@ -201,9 +212,12 @@ TopoDS_Shape BlockFix_UnionFaces::Perform(const TopoDS_Shape& Shape)
nbf++;
}
bool doUnion = ((myOptimumNbFaces == 0) ||
((myOptimumNbFaces > 0) && (nbf > myOptimumNbFaces)));
// processing each face
mapF.Clear();
for (exp.Init(aSolid, TopAbs_FACE); exp.More() && nbf > 6; exp.Next()) {
for (exp.Init(aSolid, TopAbs_FACE); exp.More() && doUnion; exp.Next()) {
TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
if (aProcessed.Contains(aFace))

View File

@ -18,7 +18,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#ifndef _BlockFix_UnionFaces_HeaderFile
#define _BlockFix_UnionFaces_HeaderFile
@ -28,10 +28,6 @@
#ifndef _Standard_Boolean_HeaderFile
#include <Standard_Boolean.hxx>
#endif
class TopoDS_Shape;
class TopoDS_Face;
#ifndef _Standard_HeaderFile
#include <Standard.hxx>
#endif
@ -39,10 +35,12 @@ class TopoDS_Face;
#include <Standard_Macro.hxx>
#endif
class BlockFix_UnionFaces {
class TopoDS_Shape;
class TopoDS_Face;
class BlockFix_UnionFaces
{
public:
void* operator new(size_t,void* anAddress)
{
return anAddress;
@ -55,47 +53,37 @@ public:
{
if (anAddress) Standard::Free((Standard_Address&)anAddress);
}
// Methods PUBLIC
//
Standard_EXPORT BlockFix_UnionFaces();
Standard_EXPORT Standard_Real& GetTolerance();
/* \brief To get/set the OptimumNbFaces parameter
*
* If a being processed solid has less than OptimumNbFaces
* faces, no union will be performed.
* By default this parameter is set to 6 (to correctly
* process blocks - hexahedral solids)
* Special values: 0 - do all possible unions, regardless the faces quantity,
* negative - do not perform any unions, regardless the faces quantity.
*
*/
Standard_EXPORT Standard_Integer& GetOptimumNbFaces();
Standard_EXPORT TopoDS_Shape Perform(const TopoDS_Shape& Shape);
Standard_EXPORT virtual Standard_Boolean IsSameDomain(const TopoDS_Face& aFace,const TopoDS_Face& aChekedFace) const;
Standard_EXPORT virtual void MovePCurves(TopoDS_Face& aTarget,const TopoDS_Face& aSource) const;
protected:
// Methods PROTECTED
//
// Fields PROTECTED
//
Standard_EXPORT virtual Standard_Boolean IsSameDomain(const TopoDS_Face& aFace,
const TopoDS_Face& aChekedFace) const;
Standard_EXPORT virtual void MovePCurves(TopoDS_Face& aTarget,
const TopoDS_Face& aSource) const;
private:
// Methods PRIVATE
//
// Fields PRIVATE
//
Standard_Real myTolerance;
Standard_Integer myOptimumNbFaces;
};
// other Inline functions and methods (like "C++: function call" methods)
//
#endif

View File

@ -291,12 +291,28 @@ Standard_Boolean GEOMAlgo_Tools::ProjectPointOnShape(const gp_Pnt& aP1,
TopAbs_ShapeEnum aType;
//
aType = aS.ShapeType();
switch(aType) {
case TopAbs_EDGE: {
switch (aType)
{
case TopAbs_EDGE:
{
cout << "$$$ case TopAbs_EDGE" << endl;
const TopoDS_Edge& aE2 = TopoDS::Edge(aS);
//
if (BRep_Tool::Degenerated(aE2)) { // jfa
cout << "$$$ Degenerated" << endl;
return Standard_True;
}
else {
Standard_Real f, l;
Handle(Geom_Curve) aC3D = BRep_Tool::Curve (aE2, f, l);
if (aC3D.IsNull()) {
cout << "$$$ aC3D.IsNull()" << endl;
return Standard_True;
}
bIsDone = aCtx.ProjectPointOnEdge(aP1, aE2, aT2);
}
if (!bIsDone) {
cout << "$$$ !bIsDone" << endl;
return bIsDone;
}
//
@ -304,7 +320,8 @@ Standard_Boolean GEOMAlgo_Tools::ProjectPointOnShape(const gp_Pnt& aP1,
}
break;
//
case TopAbs_FACE: {
case TopAbs_FACE:
{
const TopoDS_Face& aF2 = TopoDS::Face(aS);
GeomAPI_ProjectPointOnSurf& aProj = aCtx.ProjPS(aF2);
//

View File

@ -3527,6 +3527,10 @@ Please, select face, shell or solid and try again</translation>
<source>GEOM_REMOVE_EXTRA_EDGES</source>
<translation>Object to remove extra edges</translation>
</message>
<message>
<source>GEOM_RMEE_UNION_FACES</source>
<translation>Union faces, laying on common surface</translation>
</message>
<message>
<source>REMOVE_EXTRA_EDGES_NEW_OBJ_NAME</source>
<translation>NoExtraEdges</translation>

View File

@ -18,7 +18,7 @@
// 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 <BRepOffsetAPI_MakeFilling.hxx>
@ -506,6 +506,7 @@ Standard_Integer GEOMImpl_BlockDriver::Execute(TFunction_Logbook& log) const
// 1. Improve solids with seam and/or degenerated edges
BlockFix_BlockFixAPI aTool;
//aTool.Tolerance() = toler;
aTool.OptimumNbFaces() = aCI.GetOptimumNbFaces();
aTool.SetShape(aBlockOrComp);
aTool.Perform();

View File

@ -19,8 +19,8 @@
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
//NOTE: This is an interface to a function for the Blocks Multi-Transformations.
//
//NOTE: This is an interface to a functions for the Blocks Multi-Transformations and repairing
#include "GEOM_Function.hxx"
#define TRSF_ORIGIN 1
@ -32,6 +32,8 @@
#define TRSF_FACE_2_V 6
#define TRSF_NBITER_V 7
#define TRSF_NB_FACES 8
class GEOMImpl_IBlockTrsf
{
public:
@ -49,6 +51,8 @@ class GEOMImpl_IBlockTrsf
void SetNbIterU (int theNbIter) { _func->SetInteger(TRSF_NBITER_U, theNbIter); }
void SetNbIterV (int theNbIter) { _func->SetInteger(TRSF_NBITER_V, theNbIter); }
void SetOptimumNbFaces (int theNbFaces) { _func->SetInteger(TRSF_NB_FACES, theNbFaces); }
int GetFace1U () { return _func->GetInteger(TRSF_FACE_1_U); }
int GetFace2U () { return _func->GetInteger(TRSF_FACE_2_U); }
int GetFace1V () { return _func->GetInteger(TRSF_FACE_1_V); }
@ -56,6 +60,8 @@ class GEOMImpl_IBlockTrsf
int GetNbIterU() { return _func->GetInteger(TRSF_NBITER_U); }
int GetNbIterV() { return _func->GetInteger(TRSF_NBITER_V); }
int GetOptimumNbFaces() { return _func->GetInteger(TRSF_NB_FACES); }
private:
Handle(GEOM_Function) _func;

View File

@ -18,7 +18,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#ifdef WNT
#pragma warning( disable:4786 )
#endif
@ -2309,7 +2309,8 @@ Standard_Boolean GEOMImpl_IBlocksOperations::CheckCompoundOfBlocks
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_IBlocksOperations::RemoveExtraEdges
(Handle(GEOM_Object) theObject)
(Handle(GEOM_Object) theObject,
const Standard_Integer theOptimumNbFaces)
{
SetErrorCode(KO);
@ -2330,6 +2331,7 @@ Handle(GEOM_Object) GEOMImpl_IBlocksOperations::RemoveExtraEdges
GEOMImpl_IBlockTrsf aTI (aFunction);
aTI.SetOriginal(aLastFunction);
aTI.SetOptimumNbFaces(theOptimumNbFaces);
//Compute the fixed shape
try {
@ -2382,6 +2384,7 @@ Handle(GEOM_Object) GEOMImpl_IBlocksOperations::CheckAndImprove
GEOMImpl_IBlockTrsf aTI (aFunction);
aTI.SetOriginal(aLastFunction);
aTI.SetOptimumNbFaces(6);
//Compute the fixed shape
try {

View File

@ -18,7 +18,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#ifndef _GEOMImpl_IBlocksOperations_HXX_
#define _GEOMImpl_IBlocksOperations_HXX_
@ -125,7 +125,8 @@ class GEOMImpl_IBlocksOperations : public GEOM_IOperations {
Standard_EXPORT TCollection_AsciiString PrintBCErrors (Handle(GEOM_Object) theCompound,
const std::list<BCError>& theErrors);
Standard_EXPORT Handle(GEOM_Object) RemoveExtraEdges (Handle(GEOM_Object) theShape);
Standard_EXPORT Handle(GEOM_Object) RemoveExtraEdges (Handle(GEOM_Object) theShape,
const Standard_Integer theOptimumNbFaces = 6);
Standard_EXPORT Handle(GEOM_Object) CheckAndImprove (Handle(GEOM_Object) theCompound);

View File

@ -687,7 +687,9 @@ char* GEOM_IBlocksOperations_i::PrintBCErrors
* RemoveExtraEdges
*/
//=============================================================================
GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::RemoveExtraEdges (GEOM::GEOM_Object_ptr theShape)
GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::RemoveExtraEdges
(GEOM::GEOM_Object_ptr theShape,
CORBA::Long theOptimumNbFaces)
{
GEOM::GEOM_Object_var aGEOMObject;
@ -699,8 +701,7 @@ GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::RemoveExtraEdges (GEOM::GEOM_Obj
if (aShape.IsNull()) return aGEOMObject._retn();
//Get the result
Handle(GEOM_Object) anObject =
GetOperations()->RemoveExtraEdges(aShape);
Handle(GEOM_Object) anObject = GetOperations()->RemoveExtraEdges(aShape, theOptimumNbFaces);
if (!GetOperations()->IsDone() || anObject.IsNull())
return aGEOMObject._retn();

View File

@ -18,7 +18,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#ifndef _GEOM_IBlocksOperations_i_HeaderFile
#define _GEOM_IBlocksOperations_i_HeaderFile
@ -112,7 +112,8 @@ class GEOM_I_EXPORT GEOM_IBlocksOperations_i :
char* PrintBCErrors (GEOM::GEOM_Object_ptr theCompound,
const GEOM::GEOM_IBlocksOperations::BCErrors& theErrors);
GEOM::GEOM_Object_ptr RemoveExtraEdges (GEOM::GEOM_Object_ptr theShape);
GEOM::GEOM_Object_ptr RemoveExtraEdges (GEOM::GEOM_Object_ptr theShape,
CORBA::Long theOptimumNbFaces);
GEOM::GEOM_Object_ptr CheckAndImprove (GEOM::GEOM_Object_ptr theCompound);

View File

@ -3407,12 +3407,16 @@ class geompyDC(GEOM._objref_GEOM_Gen):
# Unite faces and edges, sharing one surface. It means that
# this faces must have references to one C++ surface object (handle).
# @param theShape The compound or single solid to remove irregular edges from.
# @param theOptimumNbFaces If more than zero, unite faces only for those solids,
# that have more than theOptimumNbFaces faces. If zero, unite faces always,
# regardsless their quantity in the solid. If negative (the default value),
# do not unite faces at all. For blocks repairing recommended value is 6.
# @return Improved shape.
#
# @ref swig_RemoveExtraEdges "Example"
def RemoveExtraEdges(self,theShape):
def RemoveExtraEdges(self,theShape,theOptimumNbFaces=-1):
# Example: see GEOM_TestOthers.py
anObj = self.BlocksOp.RemoveExtraEdges(theShape)
anObj = self.BlocksOp.RemoveExtraEdges(theShape,theOptimumNbFaces)
RaiseIfFailed("RemoveExtraEdges", self.BlocksOp)
return anObj

View File

@ -22,7 +22,7 @@
// GEOM RepairGUI : GUI for Geometry component
// File : RepairGUI_RemoveExtraEdgesDlg.cxx
// Author : Michael Zorin, Open CASCADE S.A.S.
//
#include "RepairGUI_RemoveExtraEdgesDlg.h"
#include <DlgRef.h>
@ -63,12 +63,15 @@ RepairGUI_RemoveExtraEdgesDlg::RepairGUI_RemoveExtraEdgesDlg( GeometryGUI* theGe
mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
mainFrame()->RadioButton3->close();
GroupPoints = new DlgRef_1Sel( centralWidget() );
GroupPoints = new DlgRef_1Sel1Check( centralWidget() );
GroupPoints->GroupBox1->setTitle( tr( "GEOM_REMOVE_EXTRA_EDGES" ) );
GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
GroupPoints->PushButton1->setIcon( image1 );
GroupPoints->LineEdit1->setReadOnly( true );
GroupPoints->CheckButton1->setText( tr( "GEOM_RMEE_UNION_FACES" ) );
QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
layout->setMargin( 0 ); layout->setSpacing( 6 );
layout->addWidget( GroupPoints );
@ -101,6 +104,8 @@ void RepairGUI_RemoveExtraEdgesDlg::Init()
myOkObject = false;
GroupPoints->CheckButton1->setChecked( false );
activateSelection();
mainFrame()->GroupBoxPublish->show();
@ -279,7 +284,11 @@ bool RepairGUI_RemoveExtraEdgesDlg::execute( ObjectList& objects )
{
GEOM::GEOM_Object_var anObj;
anObj = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->RemoveExtraEdges( myObject );
int nbFacesOptimum = -1; // -1 means do not union faces
if (GroupPoints->CheckButton1->isChecked())
nbFacesOptimum = 0; // 0 means union all faces, that possible
anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->RemoveExtraEdges
(myObject, nbFacesOptimum);
if (!anObj->_is_nil())
objects.push_back(anObj._retn());

View File

@ -22,13 +22,13 @@
// GEOM GEOMGUI : GUI for Geometry component
// File : RepairGUI_RemoveExtraEdgesDlg.h
// Author : Michael ZORIN, Open CASCADE S.A.S.
//
#ifndef REPAIRGUI_REMOVEEXTRAEDGESDLG_H
#define REPAIRGUI_REMOVEEXTRAEDGESDLG_H
#include <GEOMBase_Skeleton.h>
class DlgRef_1Sel;
class DlgRef_1Sel1Check;
//=================================================================================
// class : RepairGUI_RemoveExtraEdgesDlg
@ -58,7 +58,7 @@ private:
GEOM::GEOM_Object_var myObject;
bool myOkObject;
DlgRef_1Sel* GroupPoints;
DlgRef_1Sel1Check* GroupPoints;
private slots:
void ClickOnOk();