Tue, 12/19/2023 - 17:56
I want to trim a cylinder through two parallel circles defined on the cylinder. How can I trim it using the BRep-related method? I tried lots of combinations and read the document carefully. But I still cannot get the concept or the examples. Thanks in advance for helping me to solve this problem.
I have attached the code as belows:
// Define the cylinder
gp_Cylinder cy(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), 1);
BRepBuilderAPI_MakeFace cyf(cy);
// Define the circle
gp_Circ circle1(gp_Ax2(gp_Pnt(1, 0, 0), gp_Dir(0, 0, 1)), 1);
gp_Circ circle2(gp_Ax2(gp_Pnt(1, 0, 1), gp_Dir(0, 0, 1)), 1);
// Define the edge and wire
BRepBuilderAPI_MakeEdge edge1(circle1);
BRepBuilderAPI_MakeEdge edge2(circle2);
BRepBuilderAPI_MakeWire makeWire1(edge1);
BRepBuilderAPI_MakeWire makeWire2(edge2);
cyf1.Add(wiremaker1.Wire());
cyf1.Add(wiremaker2.Wire());
// Meshing
MeshSave(cyf1, "test1.ply");
Tue, 12/19/2023 - 20:31
Hello, you need to prepare the wire with the next order:
Sample cylinder: order of edges in wire - Forum Open Cascade Technology
Best regards, Dmitrii.
Fri, 12/22/2023 - 05:01
Hi Dmitrii, thanks for your reply. Can you see this post below? Sorry, I leave the comments in the wrong place.
Wed, 12/20/2023 - 06:21
Thanks for your reply. I tried to add four edges into a single wire and trim the cylinder with that wire, but I still got nothing. Is there any misunderstanding about the concept?
I have checked the connectivity of the wire using
BRepTools_WireExplorer
, and the order seems to be equal to the post you sent me.Here is the code:
Fri, 12/22/2023 - 14:04
Best regards, Dmitrii.
Fri, 12/22/2023 - 16:33
Thanks for your reply. But I still cannot get any output from the face. I check the return code and the `Error` but everything seems to be fine. I leave the full code below. Can you help me to figure the mistake?
A strange thing is that I can output a model if I use the u,v coordinate to trim a cylinder, but I cannot get it if I use the wire. I also checked the orientation of the wire but it seems ok.
```
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Face.hxx>
#include <BRepLib.hxx>
#include <BRepMesh_IncrementalMesh.hxx>
#include <BRepBuilderAPI_MakeShell.hxx>
#include <BRep_Builder.hxx>
#include <StlAPI_Writer.hxx>
int main(int argc, char* argv[])
{
BRepLib::Precision(1e-2);
// Define two circle with opposite orientation
gp_Circ circle1(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), 1);
gp_Circ circle2(gp_Ax2(gp_Pnt(0, 0, 1), gp_Dir(0, 0, -1)), 1);
// Define a cylinder
gp_Cylinder cy(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), 1);
// Build edge
BRepBuilderAPI_MakeEdge edge1(circle1);
BRepBuilderAPI_MakeEdge edge2(gp_Pnt(1, 0, 0), gp_Pnt(1, 0, 1));
BRepBuilderAPI_MakeEdge edge3(circle2, gp_Pnt(1, 0, 1), gp_Pnt(1, 0, 1));
BRepBuilderAPI_MakeEdge edge4(gp_Pnt(1, 0, 1), gp_Pnt(1, 0, 0));
BRepBuilderAPI_MakeWire makeWire1;
makeWire1.Add(edge1);
makeWire1.Add(edge2);
makeWire1.Add(edge3);
makeWire1.Add(edge4);
TopoDS_Wire wire = makeWire1.Wire();
// Limit cylinder by wired edges
BRepBuilderAPI_MakeFace cylface(cy, wire, true);
std::cout << cylface.Error() << std::endl;
std::cout << cylface.IsDone() << std::endl;
TopoDS_Face output = cylface.Face();
BRepMesh_IncrementalMesh mesh(output, 5e-2, false, 0.5);
StlAPI_Writer objWriter;
bool write_flag = objWriter.Write(output, "1.stl");
std::cout << write_flag << std::endl;
}
```
Fri, 12/22/2023 - 19:30
It is result from your code. The parameters is not correct. Later i fix the code.