How to get effective cut surfaces?

There are a plane and a sphere surface. And I need cut the sphere surface with the plane by using of BRepAlgoAPI_Cut, then I can get the cut result within a single shape, not the upper semi-sphere and the bottom semi-sphere surface.

How can I get the upper semi-spere surface and bottom semi-sphere surface respectively ??? Thanks a lot.

Bearloga's picture

Use the class BOPTools_DSFiller. This allows your program to perform the hard job once (df.Perform()), and then to get the result of any operation type as many times as you want.

BOPTools_DSFiller df;
df.SetShapes (sphere, halfspace);
df.Perform();
TopoDS_Shape one = BRepAlgoAPI_Cut(sphere, halfspace, *pDF);
TopoDS_Shape two = BRepAlgoAPI_Common(sphere, halfspace, *pDF);

You may try to play with this using draw commands bop, bopcut, boptuc, bopcommon, bopfuse.

arkoala's picture

Interesting post.

*What I think the question is trying to cover:
How to manage several TopoDS_Shape after performing a cut operation?
If I make a cut with shape and a tool, results can be from 0 to N TopoDS_Shapes. Not only one as the function returns.

I suggested in a previous post if a cast to TopoDS_Compound was possible and explore it to search the details of the operations (each part individually to remove some not necessary). I am interesting to achieve this, like Jun WANG I think.

*What the answer is helping about:
You mean that if you use BOPTools_DSFiller, are calculations made only once? Good trick!
Please, confirm it to me.
Why do you need to pass to BRepAlgoAPI_xxx function both shapes again, then?

I suppose 'df' and '*pDF' are the same object with typing error.

Thank you.

Bearloga's picture

Concerning the question, I understood it in different way: it is needed to split a shape by the plane and to get two results - from one and from another side of the plane. Jun, please, correct me if I am wrong. For this question I suggested the solution.
> Why do you need to pass to BRepAlgoAPI_xxx function both shapes again, then?
I don't know, you can check it with the source code from where I took the idea: the source code of the draw commands bop and bopcut (see BOPTest_BOPCommands.cxx).
You are right, it was my mistype during copy-pasting, df is the same as *pDF.

Jun WANG's picture

Yep. What arkoala mentioned is my point. And also thank Bearloga for your inspiring reply.

I find that the opeartion result is TopoDS_Compound type after cut bool opeartion. Then by using of TopoDS_Iterator recursively, the two semi-sphere surfaces can NOT still be gotten.

As arkoala said, sometimes there are more than one TopoDS_Shape resulting from bool opeartion, while the BRepAlgoAPI_Cut can return only one shape(BRepAlgoAPI_Cut::Shape()). Then I use the Modified() function to get the result, it also returns only one shape.

By the way, it is probably not appropriate to take advantage of BRepAlgoAPI_Cut to carry out my reqirement. Does anynoe know what API I should use ???

Also, I have another question almost same as the above. I have a special TopoDS_Face type shape. Its shape looks like the figure "8". Then how can I divide the face and get the two parts ???

Thank arkoala and Bearloga again.

arkoala's picture

Hi again,

I think I've got to cut my body and split different subbodys properly getting only what I need.

This is my code, maybe it is useful for you also.
As you can see, I cut the original shape, and I remain only the biggest one (Other criteria can be used, of course).

Roman, thank you very much to clarify me basic concepts on your blog.
When I was handling TopoDS_Shape, I was always thinking on TopoDS_Solid. No more.

This is the call:
<<
m_shpResult = BRepAlgoAPI_Cut(m_shpOriginal, m_booleanOps); CUtils::GetBiggerSolid(m_shpResult);
>>

And this is the function code:
<<
bool CUtils::GetBiggestSolid(TopoDS_Shape& solid)
{
TopExp_Explorer solidExp;
TopoDS_Shape aSolid;
double maxVolume = 0;
double volume;
for (solidExp.Init(solid,TopAbs_SOLID); solidExp.More(); solidExp.Next())
{
aSolid = solidExp.Current();
volume = GetVolume(aSolid);
if (maxVolume < volume)
{
maxVolume = volume;
solid = aSolid;
}
}
return true;
}

double CUtils::GetVolume(TopoDS_Shape shape)
{
GProp_GProps System;
BRepGProp::VolumeProperties(shape, System);
return System.Mass();
}
>>

Jun WANG's picture

I have solved the cut problem with "GEOMAlgo_Splitter". It is working well.