1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-03 14:10:33 +03:00

0026874: Implementation of the Partition operator in OCCT

1. The partition operation allows splitting an arbitrary number of shapes of an arbitrary dimension
by other arbitrary shapes. The algorithm has been implemented in the class BOPAlgo_Splitter.

The API operator Splitter has been implemented in the class BRepAlgoAPI_Splitter.

2. The draw commands for usage the new algorithm have been implemented - bsplit and bapisplit.
The commands are identical, but one uses the BOPAlgo_Splitter, the other uses BRepAlgoAPI_Splitter.
Both commands should be used after Pave Filler is filled.

3. Test cases for the new algorithm.

4. Documentation has been updated.

Small corrections.
This commit is contained in:
emv
2017-03-03 15:58:11 +03:00
committed by bugmaster
parent 093a3fe5bb
commit c58055adeb
33 changed files with 1391 additions and 435 deletions

View File

@@ -0,0 +1,148 @@
// Created by: Eugeny MALTCHIKOV
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <BOPAlgo_Splitter.hxx>
#include <BOPAlgo_PaveFiller.hxx>
//=======================================================================
//function :
//purpose :
//=======================================================================
BOPAlgo_Splitter::BOPAlgo_Splitter()
:
BOPAlgo_Builder(),
myTools(myAllocator),
myMapTools(100, myAllocator)
{
}
//=======================================================================
//function :
//purpose :
//=======================================================================
BOPAlgo_Splitter::BOPAlgo_Splitter
(const Handle(NCollection_BaseAllocator)& theAllocator)
:
BOPAlgo_Builder(theAllocator),
myTools(myAllocator),
myMapTools(100, myAllocator)
{
}
//=======================================================================
//function : ~
//purpose :
//=======================================================================
BOPAlgo_Splitter::~BOPAlgo_Splitter()
{
}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void BOPAlgo_Splitter::Clear()
{
BOPAlgo_Builder::Clear();
myTools.Clear();
myMapTools.Clear();
}
//=======================================================================
//function : AddTool
//purpose :
//=======================================================================
void BOPAlgo_Splitter::AddTool(const TopoDS_Shape& theShape)
{
if (myMapTools.Add(theShape)) {
myTools.Append(theShape);
}
}
//=======================================================================
//function : SetTools
//purpose :
//=======================================================================
void BOPAlgo_Splitter::SetTools(const BOPCol_ListOfShape& theShapes)
{
myTools.Clear();
BOPCol_ListIteratorOfListOfShape aIt(theShapes);
for (; aIt.More(); aIt.Next()) {
AddTool(aIt.Value());
}
}
//=======================================================================
// function: CheckData
// purpose:
//=======================================================================
void BOPAlgo_Splitter::CheckData()
{
myErrorStatus = 0;
if (myArguments.IsEmpty() ||
(myArguments.Extent() + myTools.Extent()) < 2) {
// too few arguments to process
myErrorStatus = 100;
return;
}
//
// Check the PaveFiller
if (!myPaveFiller) {
myErrorStatus = 101;
return;
}
//
if (myPaveFiller->ErrorStatus()) {
// PaveFiller has failed
myErrorStatus = 102;
}
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
void BOPAlgo_Splitter::Perform()
{
myErrorStatus = 0;
//
if (myEntryPoint == 1) {
if (myPaveFiller) {
delete myPaveFiller;
myPaveFiller = NULL;
}
}
//
// prepare shapes for intersection
BOPCol_ListOfShape aLS;
//
BOPCol_ListIteratorOfListOfShape aItLS(myArguments);
for (; aItLS.More(); aItLS.Next()) {
aLS.Append(aItLS.Value());
}
//
aItLS.Initialize(myTools);
for (; aItLS.More(); aItLS.Next()) {
aLS.Append(aItLS.Value());
}
//
BOPAlgo_PaveFiller *pPF = new BOPAlgo_PaveFiller();
pPF->SetArguments(aLS);
pPF->SetRunParallel(myRunParallel);
pPF->SetProgressIndicator(myProgressIndicator);
pPF->SetFuzzyValue(myFuzzyValue);
pPF->SetNonDestructive(myNonDestructive);
pPF->SetGlue(myGlue);
//
pPF->Perform();
//
myEntryPoint = 1;
PerformInternal(*pPF);
}

View File

@@ -0,0 +1,84 @@
// Created by: Eugeny MALTCHIKOV
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _BOPAlgo_Splitter_HeaderFile
#define _BOPAlgo_Splitter_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <BOPAlgo_Builder.hxx>
//! The class is a General Fuse (GF) based algorithm.<br>
//! It provides means to split an arbitrary number of shapes of arbitrary
//! dimensions by other arbitrary shapes.<br>
//! The arguments of the operation are divided on two groups - Objects
//! (shapes that will be split) and Tools (shapes by which the objects will be split).<br>
//! The result of the operation contains only the split parts of the Objects.<br>
//! The split parts of the Tools are excluded from the result.<br>
//! If there are no Tool shapes, the operation will be equivalent to General Fuse.<br>
//!
//! All options of the General Fuse algorithm, such as Fuzzy mode, safe mode, parallel
//! mode, gluing mode and history support are also available in this algorithm.<br>
//!
//! The implementation of the algorithm is minimal - only the methods
//! CheckData() and Perform() have been overridden.<br>
//! The method BOPAlgo_Builder::BuildResult(), which adds the split parts of the arguments
//! into result, does not have to be overridden, because its native implementation
//! performs the necessary actions for the Splitter algorithm - it adds
//! the split parts of only Objects into result, avoiding the split parts of Tools.
class BOPAlgo_Splitter : public BOPAlgo_Builder
{
public:
DEFINE_STANDARD_ALLOC
//! Empty constructor
Standard_EXPORT BOPAlgo_Splitter();
Standard_EXPORT virtual ~BOPAlgo_Splitter();
Standard_EXPORT BOPAlgo_Splitter(const BOPCol_BaseAllocator& theAllocator);
//! Clears internal fields and arguments
Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
//! Adds Tool argument of the operation
Standard_EXPORT virtual void AddTool(const TopoDS_Shape& theShape);
//! Adds the Tool arguments of the operation
Standard_EXPORT virtual void SetTools(const BOPCol_ListOfShape& theShapes);
//! Returns the Tool arguments of the operation
const BOPCol_ListOfShape& Tools() const
{
return myTools;
}
//! Performs the operation
Standard_EXPORT virtual void Perform() Standard_OVERRIDE;
protected:
//! Checks the input data
Standard_EXPORT virtual void CheckData() Standard_OVERRIDE;
BOPCol_ListOfShape myTools;
BOPCol_MapOfShape myMapTools;
private:
};
#endif // _BOPAlgo_Splitter_HeaderFile

View File

@@ -65,4 +65,6 @@ BOPAlgo_WireSplitter.lxx
BOPAlgo_WireSplitter_1.cxx
BOPAlgo_CellsBuilder.cxx
BOPAlgo_CellsBuilder.hxx
BOPAlgo_GlueEnum.hxx
BOPAlgo_GlueEnum.hxx
BOPAlgo_Splitter.hxx
BOPAlgo_Splitter.cxx

View File

@@ -23,6 +23,7 @@
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <BRepAlgoAPI_Section.hxx>
#include <BRepAlgoAPI_Splitter.hxx>
#include <DBRep.hxx>
#include <Draw.hxx>
#include <TopoDS_Shape.hxx>
@@ -34,8 +35,9 @@ static
void ConvertList(const BOPCol_ListOfShape& aLSB,
TopTools_ListOfShape& aLS);
static Standard_Integer bapibuild(Draw_Interpretor&, Standard_Integer, const char**);
static Standard_Integer bapibop (Draw_Interpretor&, Standard_Integer, const char**);
static Standard_Integer bapibuild(Draw_Interpretor&, Standard_Integer, const char**);
static Standard_Integer bapibop (Draw_Interpretor&, Standard_Integer, const char**);
static Standard_Integer bapisplit(Draw_Interpretor&, Standard_Integer, const char**);
//=======================================================================
//function : APICommands
@@ -51,6 +53,7 @@ void BOPTest::APICommands(Draw_Interpretor& theCommands)
// Commands
theCommands.Add("bapibuild", "use bapibuild r" , __FILE__, bapibuild, g);
theCommands.Add("bapibop", "use bapibop r type" , __FILE__, bapibop, g);
theCommands.Add("bapisplit", "use bapisplit r" , __FILE__, bapisplit, g);
}
//=======================================================================
//function : bapibop
@@ -219,3 +222,46 @@ void ConvertList(const BOPCol_ListOfShape& aLSB,
}
}
//=======================================================================
//function : bapisplit
//purpose :
//=======================================================================
Standard_Integer bapisplit(Draw_Interpretor& di,
Standard_Integer n,
const char** a)
{
if (n < 2) {
di << " use bapisplit r\n";
return 1;
}
//
BRepAlgoAPI_Splitter aSplitter;
// setting arguments
aSplitter.SetArguments(BOPTest_Objects::Shapes());
aSplitter.SetTools(BOPTest_Objects::Tools());
// setting options
aSplitter.SetRunParallel(BOPTest_Objects::RunParallel());
aSplitter.SetFuzzyValue(BOPTest_Objects::FuzzyValue());
aSplitter.SetNonDestructive(BOPTest_Objects::NonDestructive());
aSplitter.SetGlue(BOPTest_Objects::Glue());
//
// performing operation
aSplitter.Build();
// checking error status
Standard_Integer iErr = aSplitter.ErrorStatus();
if (iErr) {
di << "Error: " << iErr << "\n";
return 0;
}
//
// getting the result of the operation
const TopoDS_Shape& aR = aSplitter.Shape();
if (aR.IsNull()) {
di << " null shape\n";
return 0;
}
//
DBRep::Set(a[1], aR);
return 0;
}

View File

@@ -19,6 +19,7 @@
#include <BOPAlgo_Section.hxx>
#include <BOPTest_Objects.hxx>
#include <BOPAlgo_CellsBuilder.hxx>
#include <BOPAlgo_Splitter.hxx>
#include <NCollection_BaseAllocator.hxx>
static Handle(NCollection_BaseAllocator)& Allocator1();
@@ -254,6 +255,15 @@ BOPAlgo_CellsBuilder& BOPTest_Objects::CellsBuilder()
return sCBuilder;
}
//=======================================================================
//function : Splitter
//purpose :
//=======================================================================
BOPAlgo_Splitter& BOPTest_Objects::Splitter()
{
static BOPAlgo_Splitter aSplitter(Allocator1());
return aSplitter;
}
//=======================================================================
//function : Shapes
//purpose :
//=======================================================================

View File

@@ -31,10 +31,10 @@ class BOPAlgo_PaveFiller;
class BOPAlgo_Builder;
class BOPAlgo_BOP;
class BOPAlgo_Section;
class BOPAlgo_Splitter;
class BOPTest_Objects
class BOPTest_Objects
{
public:
@@ -57,6 +57,8 @@ public:
Standard_EXPORT static BOPAlgo_CellsBuilder& CellsBuilder();
Standard_EXPORT static BOPAlgo_Splitter& Splitter();
Standard_EXPORT static BOPCol_ListOfShape& Shapes();
Standard_EXPORT static BOPCol_ListOfShape& Tools();
@@ -84,22 +86,8 @@ public:
protected:
private:
};
#endif // _BOPTest_Objects_HeaderFile

View File

@@ -18,6 +18,7 @@
#include <BOPAlgo_Operation.hxx>
#include <BOPAlgo_PaveFiller.hxx>
#include <BOPAlgo_Section.hxx>
#include <BOPAlgo_Splitter.hxx>
#include <BOPTest.hxx>
#include <BOPTest_DrawableShape.hxx>
#include <BOPTest_Objects.hxx>
@@ -32,9 +33,10 @@
#include <string.h>
//
//
static Standard_Integer bfillds (Draw_Interpretor&, Standard_Integer, const char**);
static Standard_Integer bfillds (Draw_Interpretor&, Standard_Integer, const char**);
static Standard_Integer bbuild (Draw_Interpretor&, Standard_Integer, const char**);
static Standard_Integer bbop (Draw_Interpretor&, Standard_Integer, const char**);
static Standard_Integer bsplit (Draw_Interpretor&, Standard_Integer, const char**);
//=======================================================================
//function : PartitionCommands
@@ -51,6 +53,7 @@ void BOPTest::PartitionCommands(Draw_Interpretor& theCommands)
theCommands.Add("bfillds", "use bfillds [-t]" , __FILE__, bfillds, g);
theCommands.Add("bbuild" , "use bbuild r [-t]" , __FILE__, bbuild, g);
theCommands.Add("bbop" , "use bbop r op [-t]", __FILE__, bbop, g);
theCommands.Add("bsplit" , "use bsplit r [-t]" , __FILE__, bsplit, g);
}
//=======================================================================
//function : bfillds
@@ -330,3 +333,74 @@ Standard_Integer bbop(Draw_Interpretor& di,
return 0;
}
//=======================================================================
//function : bsplit
//purpose :
//=======================================================================
Standard_Integer bsplit(Draw_Interpretor& di,
Standard_Integer n,
const char** a)
{
if (n < 2) {
di << " use bsplit r [-t (show time)]\n";
return 1;
}
//
BOPDS_PDS pDS = BOPTest_Objects::PDS();
if (!pDS) {
di << " prepare PaveFiller first\n";
return 0;
}
//
BOPAlgo_PaveFiller& aPF = BOPTest_Objects::PaveFiller();
//
BOPAlgo_Splitter* pSplitter = &BOPTest_Objects::Splitter();
pSplitter->Clear();
//
// set objects
const BOPCol_ListOfShape& aLSObjects = BOPTest_Objects::Shapes();
pSplitter->SetArguments(aLSObjects);
//
// set tools
BOPCol_ListOfShape& aLSTools = BOPTest_Objects::Tools();
pSplitter->SetTools(aLSTools);
//
// set options
pSplitter->SetRunParallel(BOPTest_Objects::RunParallel());
pSplitter->SetNonDestructive(BOPTest_Objects::NonDestructive());
pSplitter->SetFuzzyValue(BOPTest_Objects::FuzzyValue());
//
// measure the time of the operation
OSD_Timer aTimer;
aTimer.Start();
//
// perform the operation
pSplitter->PerformWithFiller(aPF);
//
aTimer.Stop();
//
Standard_Integer iErr = pSplitter->ErrorStatus();
if (iErr) {
di << " error: " << iErr << "\n";
return 0;
}
//
// show time if necessary
if (n == 3 && !strcmp(a[2], "-t")) {
char buf[20];
Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
di << buf;
}
//
// DRAW history support
BOPTest_Objects::SetBuilder(pSplitter);
//
const TopoDS_Shape& aR = pSplitter->Shape();
if (aR.IsNull()) {
di << " null shape\n";
return 0;
}
//
DBRep::Set(a[1], aR);
return 0;
}

View File

@@ -0,0 +1,131 @@
// Created by: Eugeny MALTCHIKOV
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <BRepAlgoAPI_Splitter.hxx>
#include <BOPAlgo_PaveFiller.hxx>
#include <BOPAlgo_Splitter.hxx>
//=======================================================================
// function: Empty constructor
// purpose:
//=======================================================================
BRepAlgoAPI_Splitter::BRepAlgoAPI_Splitter()
: BRepAlgoAPI_BuilderAlgo() {}
//=======================================================================
// function: Constructor with already filled PaveFiller
// purpose:
//=======================================================================
BRepAlgoAPI_Splitter::BRepAlgoAPI_Splitter(const BOPAlgo_PaveFiller& thePF)
: BRepAlgoAPI_BuilderAlgo(thePF) {}
//=======================================================================
// function: Destructor
// purpose:
//=======================================================================
BRepAlgoAPI_Splitter::~BRepAlgoAPI_Splitter()
{
}
//=======================================================================
// function: SetTools
// purpose:
//=======================================================================
void BRepAlgoAPI_Splitter::SetTools(const TopTools_ListOfShape& theLS)
{
myTools = theLS;
}
//=======================================================================
// function: Tools
// purpose:
//=======================================================================
const TopTools_ListOfShape& BRepAlgoAPI_Splitter::Tools() const
{
return myTools;
}
//=======================================================================
// function: Build
// purpose:
//=======================================================================
void BRepAlgoAPI_Splitter::Build()
{
NotDone();
myErrorStatus = 0;
//
if (myArguments.IsEmpty() ||
(myArguments.Extent() + myTools.Extent()) < 2) {
myErrorStatus = 1;
return;
}
//
Clear();
//
if (myEntryType) {
if (myDSFiller) {
delete myDSFiller;
}
myDSFiller = new BOPAlgo_PaveFiller(myAllocator);
//
TopTools_ListOfShape aLArgs;
TopTools_ListIteratorOfListOfShape aItLA(myArguments);
for (; aItLA.More(); aItLA.Next()) {
aLArgs.Append(aItLA.Value());
}
//
aItLA.Initialize(myTools);
for (; aItLA.More(); aItLA.Next()) {
aLArgs.Append(aItLA.Value());
}
//
myDSFiller->SetArguments(aLArgs);
//
myDSFiller->SetRunParallel(myRunParallel);
myDSFiller->SetProgressIndicator(myProgressIndicator);
myDSFiller->SetFuzzyValue(myFuzzyValue);
myDSFiller->SetNonDestructive(myNonDestructive);
myDSFiller->SetGlue(myGlue);
//
myDSFiller->Perform();
Standard_Integer iErr = myDSFiller->ErrorStatus();
if (iErr) {
myErrorStatus = 2;
}
}
//
if (myBuilder) {
delete myBuilder;
}
//
{
BOPAlgo_Splitter *pSplitter = new BOPAlgo_Splitter(myAllocator);
pSplitter->SetArguments(myArguments);
pSplitter->SetTools(myTools);
myBuilder = pSplitter;
}
//
myBuilder->SetRunParallel(myRunParallel);
myBuilder->SetProgressIndicator(myProgressIndicator);
//
myBuilder->PerformWithFiller(*myDSFiller);
Standard_Integer iErr = myBuilder->ErrorStatus();
if (iErr) {
myErrorStatus = 3;
}
//
Done();
myShape = myBuilder->Shape();
}

View File

@@ -0,0 +1,70 @@
// Created by: Eugeny MALTCHIKOV
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _BRepAlgoAPI_Splitter_HeaderFile
#define _BRepAlgoAPI_Splitter_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <BRepAlgoAPI_BuilderAlgo.hxx>
//! The class contains API level of the Splitter algorithm.<br>
//! It provides means to split an arbitrary number of shapes of arbitrary
//! dimensions by other arbitrary shapes.<br>
//! The arguments of the operation are divided on two groups - Objects
//! (shapes that will be split) and Tools (shapes by which the objects will be split).<br>
//! The result of the operation contains only the split parts of the Objects.<br>
//! The split parts of the Tools are excluded from the result.<br>
//! If there are no Tool shapes, the operation will be equivalent to General Fuse.<br>
//!
//! The algorithm returns the following Error statuses:<br>
//! - 0 - in case of success;<br>
//! - 1 - in case there is no enough arguments for the operation;<br>
//! - 2 - in case the Intersection of the arguments has failed;<br>
//! - 3 - in case the Building of the result has failed.
class BRepAlgoAPI_Splitter : public BRepAlgoAPI_BuilderAlgo
{
public:
DEFINE_STANDARD_ALLOC
//! Empty constructor
Standard_EXPORT BRepAlgoAPI_Splitter();
Standard_EXPORT virtual ~BRepAlgoAPI_Splitter();
//! Constructor with already filled PaveFiller
Standard_EXPORT BRepAlgoAPI_Splitter(const BOPAlgo_PaveFiller& thePF);
//! Performs the algorithm.<br>
//! Performs the intersection of the objects with tools and build the result of the operation.
Standard_EXPORT virtual void Build() Standard_OVERRIDE;
//! Sets the tools
Standard_EXPORT void SetTools (const TopTools_ListOfShape& theLS);
//! Gets the tools
Standard_EXPORT const TopTools_ListOfShape& Tools() const;
protected:
//! Tools arguments of the operation
TopTools_ListOfShape myTools;
private:
};
#endif // _BRepAlgoAPI_BuilderAlgo_HeaderFile

View File

@@ -14,3 +14,5 @@ BRepAlgoAPI_Fuse.cxx
BRepAlgoAPI_Fuse.hxx
BRepAlgoAPI_Section.cxx
BRepAlgoAPI_Section.hxx
BRepAlgoAPI_Splitter.cxx
BRepAlgoAPI_Splitter.hxx