Hello everyone,
I am investigating curious behaviors when performing boolean cuts on cones.
The software I am currently working on uses OCC 6.7.0
Not knowing where to begin, I tried to reproduce those behaviors in the mfc samples by modifying the OnCut() code in the ModelingDoc.cpp file in the Modeling project.
I was able to identify 2 problematic cases when :
1) Cutting two exact same cones with different orientations
2) Cutting a small cone with a larger one
In the first case, the resulting shape shows the 2 input cones, without a modification (Cones.png).
The second case shows some kind of distortion in the resulting shape (Strange_Cut.png).
Here is my OnCut() method for the first case :
void CModelingDoc::OnCut()
{
AIS_ListOfInteractive aList;
myAISContext->DisplayedObjects(aList);
AIS_ListIteratorOfListOfInteractive aListIterator;
for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next())
{
myAISContext->Remove(aListIterator.Value());
}
// Cone1 Creation
TopoDS_Shape cone1 = BRepPrimAPI_MakeCone( 1,10, 200);
BRepCheck_Analyzer analyser1(cone1);
bool valid1 = analyser1.IsValid();
ASSERT(valid1);
// Cone1 Translation
const gp_Vec TranslationVec1(
Standard_Real(0.),
Standard_Real(0.),
Standard_Real(-100));
const gp_Trsf CylinderTrsf1 = gce_MakeTranslation(TranslationVec1);
cone1 = BRepBuilderAPI_Transform(cone1, CylinderTrsf1, Standard_False);
// Cone1 Rotation
const gp_Trsf RotYTrsf = gce_MakeRotation(gp::OY(), PI / 2.0);
cone1 = BRepBuilderAPI_Transform(cone1, RotYTrsf, Standard_True);
// 3D handling
Handle(AIS_Shape) ais1 = new AIS_Shape(cone1);
myAISContext->SetDisplayMode(ais1, 1, Standard_False);
myAISContext->SetColor(ais1, Quantity_NOC_YELLOW, Standard_False);
myAISContext->SetMaterial(ais1, Graphic3d_NOM_PLASTIC, Standard_False);
myAISContext->Display(ais1, Standard_False);
myAISContext->SetCurrentObject(ais1, Standard_False);
Fit();
Sleep(500);
// Cone2 creation
TopoDS_Shape cone2 = BRepPrimAPI_MakeCone(1, 10, 200);
BRepCheck_Analyzer analyser2(cone2);
bool valid2 = analyser2.IsValid();
ASSERT(valid2);
// Cone2 translation
const gp_Vec TranslationVec2(
Standard_Real(0.),
Standard_Real(0.),
Standard_Real(-100));
const gp_Trsf CylinderTrsf2 = gce_MakeTranslation(TranslationVec2);
cone2 = BRepBuilderAPI_Transform(cone2, CylinderTrsf2, Standard_False);
// Cone2 Rotation
const gp_Trsf RotXTrsf = gce_MakeRotation(gp::OX(), PI / 2.0);
cone2 = BRepBuilderAPI_Transform(cone2, RotXTrsf, Standard_True);
// Cone2 3D handling
Handle(AIS_Shape) ais2 = new AIS_Shape(cone2);
myAISContext->SetDisplayMode(ais2, 1, Standard_False);
myAISContext->SetColor(ais2, Quantity_NOC_YELLOW, Standard_False);
myAISContext->SetMaterial(ais2, Graphic3d_NOM_COPPER, Standard_False);
myAISContext->Display(ais2, Standard_False);
myAISContext->SetCurrentObject(ais2, Standard_False);
Fit();
Sleep(500);
// CUT
BRepAlgoAPI_Cut cutter(cone1, cone2);
cutter.Build();
TopoDS_Shape ShapeCut = cutter.Shape();
// CHECK CUT
BRepCheck_Analyzer CutAnalyser(ShapeCut);
CString sBool(std::to_string(CutAnalyser.IsValid()).c_str());
AfxMessageBox(sBool);
// Display Cut
myAISContext->Erase(ais1);
myAISContext->Erase(ais2);
Handle(AIS_Shape) aSection1 = new AIS_Shape(ShapeCut);
myAISContext->SetDisplayMode(aSection1, 1, Standard_False);
myAISContext->SetColor(aSection1, Quantity_NOC_RED, Standard_False);
myAISContext->SetMaterial(aSection1, Graphic3d_NOM_PLASTIC, Standard_False);
myAISContext->Display(aSection1, Standard_True);
myAISContext->SetCurrentObject(aSection1, Standard_False);
Fit();
Sleep(500);
}
For the second case, I just replaced
TopoDS_Shape cone1 = BRepPrimAPI_MakeCone( 1,10, 200);
by
TopoDS_Shape cone1 = BRepPrimAPI_MakeCone( 1,10, 500);
Am I missing something here ? For some reason, the hull in the second case seems to be correct.
I thought I had to repair the subshapes but my tries were not successful.
I used the BRepCheck_Analyzer all along but it didn't help in those cases.
Is there a way to recognize that something went wrong ?
If you have some idea on what is going on, please be as kind as to help me.
Have a nice day !