For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

How to split a TopoDS_Shape ??

Dong-hun Choi's picture
Forums: 

Hi, Dears.
I created a box shape like this;
TopoDS_Shape S = BRepPrimAPI_MakeBox(gp_Pnt(-100,-60,-80),110,200,150);

I want to split the shape using a plane.
gp_Pln(1,0,0, 10 ).

It will be two shapes after spliting.
I want to get the two shapes' TopoDS_Shape instance.
How can I do it?

I found a 02_6_TopologyLocalOperations sample and modified.
But, it is not working.

How can I the two shapes?
Please, give me a hits or samples ^^.

Have a good day.
BYE.

Simon Daum's picture

Hello,

DirectLeft() will give you all face left of the splitting line. This code will produce a compound out of it. To produce a shell you have to do it in a similar way but sew the face manually or with a shapefix class. If you need the other object reverse the cutting line (perhaps there's a better way, but I dont know it yet)...

Please, post code to questions (dont work is very unexact :-)

Good luck
Regards
Simon

BRep_Builder builder;
TopoDS_Compound Comp;
builder.MakeCompound(Comp);

TopTools_ListIteratorOfListOfShape theList = asplit.DirectLeft();

for (;theList.More();theList.Next()) {
builder.Add(Comp,TopoDS::Face(theList.Value()));
}

Dong-hun Choi's picture

Thank you for your answer.

Sorry, I'm beginner of OpenCC, so I have some additional question.

At first, what is the spliting line?
I use a plane to cut a shape.

Second, your posting code is working, unexpectly.

Here is my codes, What is the problem?
==== Code Start ====

TopoDS_Shape S = BRepPrimAPI_MakeBox(gp_Pnt(-100,-60,-80),110,200,150);

Handle(AIS_Shape) ais1 = new AIS_Shape(S);
myAISContext->SetColor(ais1,Quantity_NOC_RED,Standard_False);
myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
myAISContext->Display(ais1,Standard_False);
myAISContext->SetCurrentObject(ais1,Standard_False);
Fit();
Sleep(500);

BRepAlgoAPI_Section asect(S, gp_Pln(1,0,0, 10 ),Standard_False);
asect.ComputePCurveOn1(Standard_True);
asect.Approximation(Standard_True);
asect.Build();
TopoDS_Shape R = asect.Shape();

BRepFeat_SplitShape asplit(S);

for (TopExp_Explorer Ex(R,TopAbs_EDGE); Ex.More(); Ex.Next()) {
TopoDS_Shape anEdge = Ex.Current();
TopoDS_Shape aFace;
if (asect.HasAncestorFaceOn1(anEdge,aFace)) {
TopoDS_Face F = TopoDS::Face(aFace);
TopoDS_Edge E = TopoDS::Edge(anEdge);
asplit.Add(E,F);
}
}

asplit.Build();
myAISContext->Erase(ais1,Standard_False,Standard_False);

BRep_Builder builder;
TopoDS_Compound Comp;
builder.MakeCompound(Comp);
TopTools_ListIteratorOfListOfShape theList = asplit.DirectLeft();

for (;theList.More();theList.Next()) {
builder.Add(Comp,TopoDS::Face(theList.Value()));
}

Handle (AIS_Shape) atriangulation = new AIS_Shape(Comp);
myAISContext->SetDisplayMode(atriangulation,0);
myAISContext->SetColor(atriangulation,Quantity_NOC_WHITE);
myAISContext->Display(atriangulation);

Fit();

==== Code End ====

I want to get two shapes after cutting the box.
Thank you for reading.

Simon Daum's picture

I see the problem with DirectLeft function... I only used it on flat shells. You can see in the first loop that two face are oriented REVERSED. So I think theres where you have to start... I will also try it...

see: TopAbs_Orientation Orientation()

Regards

Simon Daum's picture

Hello,

if I change orientation of all face to be the same, you get the desired output. Perhaps theres a better (faster) way to do this, and not to produce a new shape but it works...

Handle(BRepTools_ReShape) reshaper = new BRepTools_ReShape();
reshaper->ModeConsiderOrientation() = Standard_True;

for (TopExp_Explorer Ex1(S,TopAbs_FACE); Ex1.More(); Ex1.Next()) {
TopoDS_Face anFace1 = TopoDS::Face(Ex1.Current());

TopAbs_Orientation oriF1 = anFace1.Orientation();

if(oriF1 == TopAbs_REVERSED)
{

TopoDS_Shape anFace2 = anFace1.Complemented();
reshaper->Replace(anFace1, anFace2, Standard_True );
}
}

TopoDS_Shape S2 = reshaper->Apply(S,TopAbs_FACE);

Regards
Simon

Paul Jimenez's picture

My trick to that one is to FUSE the shell of the box with a planar face, then fix the resulting shape, read back all resulting shells and build solids from them. Resulting shells that are not closed after fixing should be discarded too.

Lodyzhensky's picture

Dear Dong-hun Choi

If you want to split any TopoDS_Shape use the class GEOMAlgo_Splitter from
SALOME platform.

Simon Daum's picture

Hello,

can you tell us a few words how to integrate GEOMAlgo_Splitter to OCC projects. Header, libs, dlls?

Thanks Simon

Contact us

Attention: DO NOT use this form for all kind of request for the removal of your personal data. Please follow this link for such cases.