Skip to content
Snippets Groups Projects
Commit 574e580a authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

better extrude (without duplicate internal boundaries) + revolve

parent b7f151aa
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,7 @@
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_Copy.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <BRepPrimAPI_MakeRevol.hxx>
#include <BRepOffsetAPI_ThruSections.hxx>
#include <gce_MakeCirc.hxx>
#include <gce_MakePln.hxx>
......@@ -804,9 +805,10 @@ void OCC_Internals::addThruSections(int tag, std::vector<int> wireTags)
bind(result, tag);
}
void OCC_Internals::extrude(int tag, std::vector<int> inTags[4],
double dx, double dy, double dz,
std::vector<int> outTags[4])
void OCC_Internals::_extrudeRevolve(int tag, bool revolve, std::vector<int> inTags[4],
double x, double y, double z,
double dx, double dy, double dz, double angle,
std::vector<int> outTags[4])
{
for(int dim = 0; dim < 3; dim++){
if(tag > 0 && inTags[dim].size() && isBound(tag, dim + 1)){
......@@ -816,6 +818,11 @@ void OCC_Internals::extrude(int tag, std::vector<int> inTags[4],
}
}
// build a single compound shape, so that we won't duplicate internal
// boundaries
BRep_Builder b;
TopoDS_Compound c;
b.MakeCompound(c);
for(int dim = 0; dim < 4; dim++){
for(unsigned int i = 0; i < inTags[dim].size(); i++){
if(!isBound(dim, inTags[dim][i])){
......@@ -824,16 +831,52 @@ void OCC_Internals::extrude(int tag, std::vector<int> inTags[4],
return;
}
TopoDS_Shape shape = find(dim, inTags[dim][i]);
BRepPrimAPI_MakePrism p(shape, gp_Vec(dx, dy, dz), Standard_False);
b.Add(c, shape);
}
}
TopoDS_Shape result;
try{
if(revolve){
gp_Ax1 axisOfRevolution(gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
BRepPrimAPI_MakeRevol r(c, axisOfRevolution, angle, Standard_False);
r.Build();
if(!r.IsDone()){
Msg::Error("Could not revolve");
return;
}
result = r.Shape();
}
else{
BRepPrimAPI_MakePrism p(c, gp_Vec(dx, dy, dz), Standard_False);
p.Build();
if(!p.IsDone()){
Msg::Error("Could not extrude");
return;
}
TopoDS_Shape result = p.Shape();
bind(result, true, tag, outTags);
result = p.Shape();
}
}
catch(Standard_Failure &err){
Msg::Error("OpenCASCADE exception %s", err.GetMessageString());
return;
}
bind(result, true, tag, outTags);
}
void OCC_Internals::extrude(int tag, std::vector<int> inTags[4],
double dx, double dy, double dz,
std::vector<int> outTags[4])
{
_extrudeRevolve(tag, false, inTags, 0, 0, 0, dx, dy, dz, 0, outTags);
}
void OCC_Internals::revolve(int tag, std::vector<int> inTags[4],
double x, double y, double z,
double dx, double dy, double dz, double angle,
std::vector<int> outTags[4])
{
_extrudeRevolve(tag, true, inTags, x, y, z, dx, dy, dz, angle, outTags);
}
void OCC_Internals::applyBooleanOperator(int tag, BooleanOperator op,
......
......@@ -49,6 +49,12 @@ class OCC_Internals {
// add bezier or bspline
void _addSpline(int tag, std::vector<int> vertexTags, int mode);
// extrude or revolve
void _extrudeRevolve(int tag, bool revolve, std::vector<int> inTags[4],
double x, double y, double z,
double dx, double dy, double dz, double angle,
std::vector<int> outTags[4]);
public:
OCC_Internals();
......@@ -108,10 +114,13 @@ class OCC_Internals {
double x2, double y2, double z2, double r);
void addThruSections(int tag, std::vector<int> wireTags);
// extrusion
// extrusion and revolution
void extrude(int tag, std::vector<int> inTags[4],
double dx, double dy, double dz,
std::vector<int> outTags[4]);
void revolve(int tag, std::vector<int> inTags[4],
double x, double y, double z, double dx, double dy, double dz,
double angle, std::vector<int> outTags[4]);
// apply boolean operator
void applyBooleanOperator(int tag, BooleanOperator op,
......
This diff is collapsed.
......@@ -4099,9 +4099,32 @@ Extrude :
| tExtrude '{' VExpr ',' VExpr ',' FExpr '}' '{' ListOfShapes '}'
{
$$ = List_Create(2, 1, sizeof(Shape));
ExtrudeShapes(ROTATE, $10,
0., 0., 0., $3[0], $3[1], $3[2], $5[0], $5[1], $5[2], $7,
NULL, $$);
if(factory == "OpenCASCADE" && GModel::current()->getOCCInternals()){
std::vector<int> in[4], out[4];
Shape TheShape;
for(int i = 0; i < List_Nbr($10); i++){
List_Read($10, i, &TheShape);
int dim = TheShape.Type / 100 - 1;
if(dim >= 0 && dim <= 3) in[dim].push_back(TheShape.Num);
}
GModel::current()->getOCCInternals()->revolve(-1, in, $5[0], $5[1], $5[2],
$3[0], $3[1], $3[2], $7, out);
for(int dim = 0; dim < 4; dim++){
for(unsigned int i = 0; i < out[dim].size(); i++){
Shape s;
s.Num = out[dim][i];
s.Type = (dim == 3) ? MSH_VOLUME_FROM_GMODEL :
(dim == 2) ? MSH_SURF_FROM_GMODEL :
(dim == 1) ? MSH_SEGM_FROM_GMODEL : MSH_POINT_FROM_GMODEL;
List_Add($$, &s);
}
}
}
else{
ExtrudeShapes(ROTATE, $10,
0., 0., 0., $3[0], $3[1], $3[2], $5[0], $5[1], $5[2], $7,
NULL, $$);
}
List_Delete($10);
}
| tExtrude '{' VExpr ',' VExpr ',' VExpr ',' FExpr '}' '{' ListOfShapes '}'
......
......@@ -28,6 +28,15 @@ Plane Surface(2) = {2};
Disk(3) = {0.6, 0.6, 0, 0.5, 0.3};
Extrude{0,0,0.3}{ Surface{1:3}; }
BooleanFragments{ Volume{1}; Delete; }{ Volume{2:3}; Delete; }
Delete{ Surface{1:3}; }
DefineConstant[
after = {1, Choices{0,1}, Name "Parameters/Extrude after boolean"}
];
If(after)
BooleanFragments{ Surface{1}; Delete; }{ Surface{2:3}; Delete; }
Extrude{0,0,0.3}{ Surface{1:5}; }
Else
Extrude{0,0,0.3}{ Surface{1:3}; }
BooleanFragments{ Volume{1}; Delete; }{ Volume{2:3}; Delete; }
Delete{ Surface{1:3}; }
EndIf
SetFactory("OpenCASCADE");
Mesh.Algorithm = 6;
Mesh.CharacteristicLengthMin = 0.1;
Mesh.CharacteristicLengthMax = 0.1;
Point(1) = {0,0,0};
Point(2) = {1,0,0};
Point(3) = {1,1,0};
Point(4) = {0,1,0};
Line(1) = {1,2};
Line(2) = {2,3};
Line(3) = {3,4};
Line(4) = {4,1};
Line Loop(1) = {1,2,3,4};
Plane Surface(1) = {1};
Point(5) = {0.2,0.2,0};
Point(6) = {0.5,0.2,0};
Point(7) = {0.5,0.5,0};
Point(8) = {0.2,0.5,0};
Line(5) = {5,6};
Line(6) = {6,7};
Line(7) = {7,8};
Line(8) = {8,5};
Line Loop(2) = {5,6,7,8};
Plane Surface(2) = {2};
Disk(3) = {0.6, 0.6, 0, 0.5, 0.3};
DefineConstant[
angle = {90, Min 0, Max 360, Step 1,
Name "Parameters/Angle"}
];
BooleanFragments{ Surface{1}; Delete; }{ Surface{2:3}; Delete; }
a() = Extrude{ {0,1,0}, {0,0,0}, angle*2*Pi/360 }{ Surface{1:5}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment