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

OCC cone + face filling (used for now in "Ruled Surface")

parent c9f07355
Branches
Tags
No related merge requests found
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <BRepBuilderAPI_Copy.hxx> #include <BRepBuilderAPI_Copy.hxx>
#include <BRepPrimAPI_MakePrism.hxx> #include <BRepPrimAPI_MakePrism.hxx>
#include <BRepPrimAPI_MakeRevol.hxx> #include <BRepPrimAPI_MakeRevol.hxx>
#include <BRepOffsetAPI_MakeFilling.hxx>
#include <BRepOffsetAPI_ThruSections.hxx> #include <BRepOffsetAPI_ThruSections.hxx>
#include <gce_MakeCirc.hxx> #include <gce_MakeCirc.hxx>
#include <gce_MakePln.hxx> #include <gce_MakePln.hxx>
...@@ -390,6 +391,7 @@ void OCC_Internals::_addSpline(int tag, std::vector<int> vertexTags, int mode) ...@@ -390,6 +391,7 @@ void OCC_Internals::_addSpline(int tag, std::vector<int> vertexTags, int mode)
Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); Msg::Error("OpenCASCADE exception %s", err.GetMessageString());
return; return;
} }
if(tag <= 0) tag = getMaxTag(1) + 1;
bind(result, tag); bind(result, tag);
} }
...@@ -405,7 +407,7 @@ void OCC_Internals::addBSpline(int tag, std::vector<int> vertexTags) ...@@ -405,7 +407,7 @@ void OCC_Internals::addBSpline(int tag, std::vector<int> vertexTags)
void OCC_Internals::addLineLoop(int tag, std::vector<int> edgeTags) void OCC_Internals::addLineLoop(int tag, std::vector<int> edgeTags)
{ {
if(_tagWire.IsBound(tag)){ if(tag > 0 && _tagWire.IsBound(tag)){
Msg::Error("OpenCASCADE line loop with tag %d already exists", tag); Msg::Error("OpenCASCADE line loop with tag %d already exists", tag);
return; return;
} }
...@@ -427,6 +429,7 @@ void OCC_Internals::addLineLoop(int tag, std::vector<int> edgeTags) ...@@ -427,6 +429,7 @@ void OCC_Internals::addLineLoop(int tag, std::vector<int> edgeTags)
Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); Msg::Error("OpenCASCADE exception %s", err.GetMessageString());
return; return;
} }
if(tag <= 0) tag = getMaxTag(-1) + 1;
bind(result, tag); bind(result, tag);
} }
...@@ -492,7 +495,7 @@ void OCC_Internals::addPlanarFace(int tag, std::vector<int> wireTags) ...@@ -492,7 +495,7 @@ void OCC_Internals::addPlanarFace(int tag, std::vector<int> wireTags)
{ {
const bool autoFix = true; const bool autoFix = true;
if(_tagFace.IsBound(tag)){ if(tag > 0 && _tagFace.IsBound(tag)){
Msg::Error("OpenCASCADE face with tag %d already exists", tag); Msg::Error("OpenCASCADE face with tag %d already exists", tag);
return; return;
} }
...@@ -557,6 +560,52 @@ void OCC_Internals::addPlanarFace(int tag, std::vector<int> wireTags) ...@@ -557,6 +560,52 @@ void OCC_Internals::addPlanarFace(int tag, std::vector<int> wireTags)
return; return;
} }
} }
if(tag <= 0) tag = getMaxTag(2) + 1;
bind(result, tag);
}
void OCC_Internals::addFaceFilling(int tag, std::vector<int> wireTags,
std::vector<std::vector<double> > points)
{
if(tag > 0 && _tagFace.IsBound(tag)){
Msg::Error("OpenCASCADE face with tag %d already exists", tag);
return;
}
TopoDS_Face result;
try{
BRepOffsetAPI_MakeFilling f;
// add edge constraints
for (unsigned i = 0; i < wireTags.size(); i++) {
if(!_tagWire.IsBound(wireTags[i])){
Msg::Error("Unknown OpenCASCADE line loop with tag %d", wireTags[i]);
return;
}
TopoDS_Wire wire = TopoDS::Wire(_tagWire.Find(wireTags[i]));
TopExp_Explorer exp0;
for(exp0.Init(wire, TopAbs_EDGE); exp0.More(); exp0.Next()){
f.Add(TopoDS::Edge(exp0.Current()), GeomAbs_C0);
}
}
// add point constraints
for(unsigned i = 0; i < points.size(); i++){
if(points[i].size() == 3)
f.Add(gp_Pnt(points[i][0], points[i][1], points[i][2]));
}
f.Build();
if(!f.IsDone()){
Msg::Error("Could not build face filling");
return;
}
result = TopoDS::Face(f.Shape());
}
catch(Standard_Failure &err){
Msg::Error("OpenCASCADE exception %s", err.GetMessageString());
return;
}
if(tag <= 0) tag = getMaxTag(2) + 1;
bind(result, tag); bind(result, tag);
} }
...@@ -602,7 +651,7 @@ void OCC_Internals::addSurfaceLoop(int tag, std::vector<int> faceTags) ...@@ -602,7 +651,7 @@ void OCC_Internals::addSurfaceLoop(int tag, std::vector<int> faceTags)
{ {
const bool autoFix = true; const bool autoFix = true;
if(_tagShell.IsBound(tag)){ if(tag > 0 && _tagShell.IsBound(tag)){
Msg::Error("OpenCASCADE surface loop with tag %d already exists", tag); Msg::Error("OpenCASCADE surface loop with tag %d already exists", tag);
return; return;
} }
...@@ -652,7 +701,7 @@ void OCC_Internals::addVolume(int tag, std::vector<int> shellTags) ...@@ -652,7 +701,7 @@ void OCC_Internals::addVolume(int tag, std::vector<int> shellTags)
{ {
const bool autoFix = true; const bool autoFix = true;
if(_tagSolid.IsBound(tag)){ if(tag > 0 && _tagSolid.IsBound(tag)){
Msg::Error("OpenCASCADE region with tag %d already exists", tag); Msg::Error("OpenCASCADE region with tag %d already exists", tag);
return; return;
} }
...@@ -680,6 +729,7 @@ void OCC_Internals::addVolume(int tag, std::vector<int> shellTags) ...@@ -680,6 +729,7 @@ void OCC_Internals::addVolume(int tag, std::vector<int> shellTags)
Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); Msg::Error("OpenCASCADE exception %s", err.GetMessageString());
return; return;
} }
if(tag <= 0) tag = getMaxTag(3) + 1;
bind(result, tag); bind(result, tag);
} }
...@@ -802,6 +852,42 @@ void OCC_Internals::addTorus(int tag, double x, double y, double z, ...@@ -802,6 +852,42 @@ void OCC_Internals::addTorus(int tag, double x, double y, double z,
bind(result, tag); bind(result, tag);
} }
void OCC_Internals::addCone(int tag, double x1, double y1, double z1,
double x2, double y2, double z2, double r1,
double r2, double alpha)
{
if(tag > 0 && _tagSolid.IsBound(tag)){
Msg::Error("OpenCASCADE region with tag %d already exists", tag);
return;
}
const double H = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) +
(z2 - z1) * (z2 - z1));
if(!H){
Msg::Error("Cannot build cone of zero height");
return;
}
TopoDS_Solid result;
try{
gp_Pnt aP(x1, y1, z1);
gp_Vec aV((x2 - x1) / H, (y2 - y1) / H, (z2 - z1) / H);
gp_Ax2 anAxes(aP, aV);
BRepPrimAPI_MakeCone c(anAxes, r1, r2, H, alpha);
c.Build();
if(!c.IsDone()){
Msg::Error("Could not create cone");
return;
}
result = TopoDS::Solid(c.Shape());
}
catch(Standard_Failure &err){
Msg::Error("OpenCASCADE exception %s", err.GetMessageString());
return;
}
if(tag <= 0) tag = getMaxTag(3) + 1;
bind(result, tag);
}
void OCC_Internals::addThruSections(int tag, std::vector<int> wireTags) void OCC_Internals::addThruSections(int tag, std::vector<int> wireTags)
{ {
if(tag > 0 && _tagSolid.IsBound(tag)){ if(tag > 0 && _tagSolid.IsBound(tag)){
......
...@@ -104,6 +104,8 @@ class OCC_Internals { ...@@ -104,6 +104,8 @@ class OCC_Internals {
double x2, double y2, double z2); double x2, double y2, double z2);
void addDisk(int tag, double xc, double yc, double zc, double rx, double ry); void addDisk(int tag, double xc, double yc, double zc, double rx, double ry);
void addPlanarFace(int tag, std::vector<int> wireTags); void addPlanarFace(int tag, std::vector<int> wireTags);
void addFaceFilling(int tag, std::vector<int> wireTags,
std::vector<std::vector<double> > points);
void addRuledFaces(int tag, std::vector<int> wireTags, std::vector<int> outTags); void addRuledFaces(int tag, std::vector<int> wireTags, std::vector<int> outTags);
void addSurfaceLoop(int tag, std::vector<int> faceTags); void addSurfaceLoop(int tag, std::vector<int> faceTags);
void addVolume(int tag, std::vector<int> shellTags); void addVolume(int tag, std::vector<int> shellTags);
...@@ -113,6 +115,8 @@ class OCC_Internals { ...@@ -113,6 +115,8 @@ class OCC_Internals {
double x2, double y2, double z2); double x2, double y2, double z2);
void addCylinder(int tag, double x1, double y1, double z1, void addCylinder(int tag, double x1, double y1, double z1,
double x2, double y2, double z2, double r); double x2, double y2, double z2, double r);
void addCone(int tag, double x1, double y1, double z1, double x2, double y2,
double z2, double r1, double r2, double alpha);
void addTorus(int tag, double x, double y, double z, double r1, double r2, void addTorus(int tag, double x, double y, double z, double r1, double r2,
double alpha); double alpha);
void addThruSections(int tag, std::vector<int> wireTags); void addThruSections(int tag, std::vector<int> wireTags);
...@@ -217,6 +221,8 @@ public: ...@@ -217,6 +221,8 @@ public:
double x2, double y2, double z2){} double x2, double y2, double z2){}
void addDisk(int tag, double xc, double yc, double zc, double rx, double ry){} void addDisk(int tag, double xc, double yc, double zc, double rx, double ry){}
void addPlanarFace(int tag, std::vector<int> wireTags){} void addPlanarFace(int tag, std::vector<int> wireTags){}
void addFaceFilling(int tag, std::vector<int> wireTags,
std::vector<std::vector<double> > points){}
void addRuledFaces(int tag, std::vector<int> wireTags, std::vector<int> outTags){} void addRuledFaces(int tag, std::vector<int> wireTags, std::vector<int> outTags){}
void addSurfaceLoop(int tag, std::vector<int> faceTags){} void addSurfaceLoop(int tag, std::vector<int> faceTags){}
void addVolume(int tag, std::vector<int> shellTags){} void addVolume(int tag, std::vector<int> shellTags){}
...@@ -226,6 +232,8 @@ public: ...@@ -226,6 +232,8 @@ public:
double x2, double y2, double z2){} double x2, double y2, double z2){}
void addCylinder(int tag, double x1, double y1, double z1, void addCylinder(int tag, double x1, double y1, double z1,
double x2, double y2, double z2, double r){} double x2, double y2, double z2, double r){}
void addCone(int tag, double x1, double y1, double z1, double x2, double y2,
double z2, double r1, double r2, double alpha){}
void addTorus(int tag, double x, double y, double z, double r1, double r2, void addTorus(int tag, double x, double y, double z, double r1, double r2,
double alpha){} double alpha){}
void addThruSections(int tag, std::vector<int> wireTags){} void addThruSections(int tag, std::vector<int> wireTags){}
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
...@@ -2170,6 +2170,16 @@ Shape : ...@@ -2170,6 +2170,16 @@ Shape :
if(FindSurface(num)){ if(FindSurface(num)){
yymsg(0, "Surface %d already exists", num); yymsg(0, "Surface %d already exists", num);
} }
else{
if(factory == "OpenCASCADE" && GModel::current()->getOCCInternals()){
std::vector<int> wires;
for(int i = 0; i < List_Nbr($7); i++){
double d; List_Read($7, i, &d);
wires.push_back((int)std::abs(d));
}
std::vector<std::vector<double> > points;
GModel::current()->getOCCInternals()->addFaceFilling(num, wires, points);
}
else{ else{
double d; double d;
List_Read($7, 0, &d); List_Read($7, 0, &d);
...@@ -2199,6 +2209,7 @@ Shape : ...@@ -2199,6 +2209,7 @@ Shape :
Tree_Add(GModel::current()->getGEOInternals()->Surfaces, &s); Tree_Add(GModel::current()->getGEOInternals()->Surfaces, &s);
} }
} }
}
List_Delete($7); List_Delete($7);
$$.Type = type; $$.Type = type;
$$.Num = num; $$.Num = num;
...@@ -2411,6 +2422,34 @@ Shape : ...@@ -2411,6 +2422,34 @@ Shape :
$$.Type = MSH_VOLUME; $$.Type = MSH_VOLUME;
$$.Num = num; $$.Num = num;
} }
| tCone '(' FExpr ')' tAFFECT ListOfDouble tEND
{
int num = (int)$3;
if(List_Nbr($6) == 8 || List_Nbr($6) == 9){
if(factory == "OpenCASCADE" && GModel::current()->getOCCInternals()){
double x1; List_Read($6, 0, &x1);
double y1; List_Read($6, 1, &y1);
double z1; List_Read($6, 2, &z1);
double x2; List_Read($6, 3, &x2);
double y2; List_Read($6, 4, &y2);
double z2; List_Read($6, 5, &z2);
double r1; List_Read($6, 6, &r1);
double r2; List_Read($6, 7, &r2);
double alpha=2*M_PI; if(List_Nbr($6) == 9) List_Read($6, 8, &alpha);
GModel::current()->getOCCInternals()->addCone(num, x1, y1, z1, x2, y2, z2,
r1, r2, alpha);
}
else{
yymsg(0, "Cone only available with OpenCASCADE factory");
}
}
else{
yymsg(0, "Cone has to be defined using 2 points and 2 radii");
}
List_Delete($6);
$$.Type = MSH_VOLUME;
$$.Num = num;
}
| tSurface tSTRING '(' FExpr ')' tAFFECT ListOfDouble tEND | tSurface tSTRING '(' FExpr ')' tAFFECT ListOfDouble tEND
{ {
int num = (int)$4; int num = (int)$4;
......
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.2};
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};
Ruled Surface(1) = {1};
...@@ -10,3 +10,6 @@ Cylinder(3) = {2,0,0, 2.5,0,0, 0.5}; ...@@ -10,3 +10,6 @@ Cylinder(3) = {2,0,0, 2.5,0,0, 0.5};
Block(4) = {3,0,0, 3.5,0.5,0.5}; Block(4) = {3,0,0, 3.5,0.5,0.5};
Torus(5) = {4,0,0, 0.3, 0.1}; Torus(5) = {4,0,0, 0.3, 0.1};
Torus(6) = {5,0,0, 0.3, 0.1, Pi/3}; Torus(6) = {5,0,0, 0.3, 0.1, Pi/3};
Cone(7) = {6,0,0, 6.5,0,0, 0.5,0};
Cone(8) = {7,0,0, 7.5,0,0, 0.5,0, Pi/3};
Cone(9) = {8,0,0, 8.5,0,0, 0.5,0.2, Pi/3};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment