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

speed up large STEP/BRep import:

- removed all linear searches when creating OCC entities by using a cache in OCC_Internals
- moved all getOCC*ByNativePtr into OCC_Internals

Please test: this is quite an invasive change
parent 1e728a19
Branches
Tags
No related merge requests found
...@@ -725,7 +725,7 @@ GEntity *OCCFactory::addSphere(GModel *gm, double xc, double yc, double zc, doub ...@@ -725,7 +725,7 @@ GEntity *OCCFactory::addSphere(GModel *gm, double xc, double yc, double zc, doub
gm->destroy(); gm->destroy();
gm->_occ_internals->buildLists(); gm->_occ_internals->buildLists();
gm->_occ_internals->buildGModel(gm); gm->_occ_internals->buildGModel(gm);
return getOCCRegionByNativePtr(gm, TopoDS::Solid(shape)); return gm->_occ_internals->getOCCRegionByNativePtr(gm, TopoDS::Solid(shape));
} }
GRegion* OCCFactory::addVolume (GModel *gm, std::vector<std::vector<GFace *> > faces) GRegion* OCCFactory::addVolume (GModel *gm, std::vector<std::vector<GFace *> > faces)
...@@ -763,7 +763,7 @@ GEntity *OCCFactory::addCylinder(GModel *gm, std::vector<double> p1, ...@@ -763,7 +763,7 @@ GEntity *OCCFactory::addCylinder(GModel *gm, std::vector<double> p1,
gm->destroy(); gm->destroy();
gm->_occ_internals->buildLists(); gm->_occ_internals->buildLists();
gm->_occ_internals->buildGModel(gm); gm->_occ_internals->buildGModel(gm);
return getOCCRegionByNativePtr(gm, TopoDS::Solid(shape)); return gm->_occ_internals->getOCCRegionByNativePtr(gm, TopoDS::Solid(shape));
} }
GEntity *OCCFactory::addTorus(GModel *gm, std::vector<double> p1, GEntity *OCCFactory::addTorus(GModel *gm, std::vector<double> p1,
...@@ -795,7 +795,7 @@ GEntity *OCCFactory::addTorus(GModel *gm, std::vector<double> p1, ...@@ -795,7 +795,7 @@ GEntity *OCCFactory::addTorus(GModel *gm, std::vector<double> p1,
gm->destroy(); gm->destroy();
gm->_occ_internals->buildLists(); gm->_occ_internals->buildLists();
gm->_occ_internals->buildGModel(gm); gm->_occ_internals->buildGModel(gm);
return getOCCRegionByNativePtr(gm, TopoDS::Solid(shape)); return gm->_occ_internals->getOCCRegionByNativePtr(gm, TopoDS::Solid(shape));
} }
GEntity *OCCFactory::addCone(GModel *gm, std::vector<double> p1, GEntity *OCCFactory::addCone(GModel *gm, std::vector<double> p1,
...@@ -828,7 +828,7 @@ GEntity *OCCFactory::addCone(GModel *gm, std::vector<double> p1, ...@@ -828,7 +828,7 @@ GEntity *OCCFactory::addCone(GModel *gm, std::vector<double> p1,
gm->destroy(); gm->destroy();
gm->_occ_internals->buildLists(); gm->_occ_internals->buildLists();
gm->_occ_internals->buildGModel(gm); gm->_occ_internals->buildGModel(gm);
return getOCCRegionByNativePtr(gm,TopoDS::Solid(shape)); return gm->_occ_internals->getOCCRegionByNativePtr(gm,TopoDS::Solid(shape));
} }
GEntity *OCCFactory::addBlock(GModel *gm, std::vector<double> p1, GEntity *OCCFactory::addBlock(GModel *gm, std::vector<double> p1,
...@@ -850,7 +850,7 @@ GEntity *OCCFactory::addBlock(GModel *gm, std::vector<double> p1, ...@@ -850,7 +850,7 @@ GEntity *OCCFactory::addBlock(GModel *gm, std::vector<double> p1,
gm->destroy(); gm->destroy();
gm->_occ_internals->buildLists(); gm->_occ_internals->buildLists();
gm->_occ_internals->buildGModel(gm); gm->_occ_internals->buildGModel(gm);
return getOCCRegionByNativePtr(gm, TopoDS::Solid(shape)); return gm->_occ_internals->getOCCRegionByNativePtr(gm, TopoDS::Solid(shape));
} }
GModel *OCCFactory::computeBooleanUnion(GModel* obj, GModel* tool, GModel *OCCFactory::computeBooleanUnion(GModel* obj, GModel* tool,
......
This diff is collapsed.
...@@ -16,33 +16,40 @@ ...@@ -16,33 +16,40 @@
class OCC_Internals { class OCC_Internals {
protected : protected :
TopoDS_Shape shape; TopoDS_Shape shape;
// all TopoDS_Shapes in the OCC model
TopTools_IndexedMapOfShape fmap, emap, vmap, somap, shmap, wmap; TopTools_IndexedMapOfShape fmap, emap, vmap, somap, shmap, wmap;
// cache mapping TopoDS_Shapes to their corresponding GEntity tags
TopTools_DataMapOfShapeInteger gvNumCache, geNumCache, gfNumCache, grNumCache;
public: public:
enum BooleanOperator { Intersection, Cut, Section, Fuse }; enum BooleanOperator { Intersection, Cut, Section, Fuse };
OCC_Internals() OCC_Internals(){}
{
somap.Clear();
shmap.Clear();
fmap.Clear();
wmap.Clear();
emap.Clear();
vmap.Clear();
}
TopoDS_Shape getShape () { return shape; } TopoDS_Shape getShape () { return shape; }
void buildLists(); void buildLists();
void buildShapeFromLists(TopoDS_Shape _shape); void buildShapeFromLists(TopoDS_Shape _shape);
void addShapeToLists(TopoDS_Shape shape); void addShapeToLists(TopoDS_Shape shape);
void healGeometry(double tolerance, bool fixdegenerated, void healGeometry(double tolerance, bool fixdegenerated,
bool fixsmalledges, bool fixspotstripfaces, bool fixsmalledges, bool fixspotstripfaces,
bool sewfaces, bool makesolids=false, bool sewfaces, bool makesolids=false,
bool connect=false); bool connect=false);
void loadBREP(const char *); void loadBREP(const char *);
void writeBREP(const char *); void writeBREP(const char *);
void loadSTEP(const char *); void loadSTEP(const char *);
void writeSTEP(const char *); void writeSTEP(const char *);
void loadIGES(const char *); void loadIGES(const char *);
void loadShape(const TopoDS_Shape *); void loadShape(const TopoDS_Shape *);
void buildGModel(GModel *gm); void buildGModel(GModel *gm);
void bind(TopoDS_Vertex vertex, int num){ gvNumCache.Bind(vertex, num); }
void bind(TopoDS_Edge edge, int num){ geNumCache.Bind(edge, num); }
void bind(TopoDS_Face face, int num){ gfNumCache.Bind(face, num); }
void bind(TopoDS_Solid solid, int num){ grNumCache.Bind(solid, num); }
void unbind(TopoDS_Vertex vertex){ gvNumCache.UnBind(vertex); }
void unbind(TopoDS_Edge edge){ geNumCache.UnBind(edge); }
void unbind(TopoDS_Face face){ gfNumCache.UnBind(face); }
void unbind(TopoDS_Solid solid){ grNumCache.UnBind(solid); }
GVertex *getOCCVertexByNativePtr(GModel *model, TopoDS_Vertex toFind);
GEdge *getOCCEdgeByNativePtr(GModel *model, TopoDS_Edge toFind);
GFace *getOCCFaceByNativePtr(GModel *model, TopoDS_Face toFind);
GRegion *getOCCRegionByNativePtr(GModel *model, TopoDS_Solid toFind);
GVertex *addVertexToModel(GModel *model, TopoDS_Vertex v); GVertex *addVertexToModel(GModel *model, TopoDS_Vertex v);
GEdge *addEdgeToModel(GModel *model, TopoDS_Edge e); GEdge *addEdgeToModel(GModel *model, TopoDS_Edge e);
GFace *addFaceToModel(GModel *model, TopoDS_Face f); GFace *addFaceToModel(GModel *model, TopoDS_Face f);
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "Context.h" #include "Context.h"
#if defined(HAVE_OCC) #if defined(HAVE_OCC)
#include "GModelIO_OCC.h"
#include <Geom2dLProp_CLProps2d.hxx> #include <Geom2dLProp_CLProps2d.hxx>
#include <Geom_BezierCurve.hxx> #include <Geom_BezierCurve.hxx>
#include <Geom_OffsetCurve.hxx> #include <Geom_OffsetCurve.hxx>
...@@ -24,34 +25,23 @@ ...@@ -24,34 +25,23 @@
#include <Geom_Conic.hxx> #include <Geom_Conic.hxx>
#include <BOPTools_Tools.hxx> #include <BOPTools_Tools.hxx>
GEdge *getOCCEdgeByNativePtr(GModel *model, TopoDS_Edge toFind) OCCEdge::OCCEdge(GModel *m, TopoDS_Edge edge, int num, GVertex *v1, GVertex *v2)
{ : GEdge(m, num, v1, v2), c(edge), trimmed(0)
GModel::eiter it = model->firstEdge();
for (; it != model->lastEdge(); it++){
OCCEdge *ed = dynamic_cast<OCCEdge*>(*it);
if (ed){
if (toFind.IsSame(ed->getTopoDS_Edge())){
return *it;
}
if (toFind.IsSame(ed->getTopoDS_EdgeOld())){
return *it;
}
}
}
return 0;
}
OCCEdge::OCCEdge(GModel *model, TopoDS_Edge edge, int num, GVertex *v1, GVertex *v2)
: GEdge(model, num, v1, v2), c(edge), trimmed(0)
{ {
curve = BRep_Tool::Curve(c, s0, s1); curve = BRep_Tool::Curve(c, s0, s1);
// build the reverse curve // build the reverse curve
c_rev = c; c_rev = c;
c_rev.Reverse(); c_rev.Reverse();
model()->getOCCInternals()->bind(c, num);
}
OCCEdge::~OCCEdge()
{
model()->getOCCInternals()->unbind(c);
} }
Range<double> OCCEdge::parBounds(int i) const Range<double> OCCEdge::parBounds(int i) const
{ {
return Range<double>(s0, s1); return Range<double>(s0, s1);
} }
...@@ -84,7 +74,7 @@ SPoint2 OCCEdge::reparamOnFace(const GFace *face, double epar, int dir) const ...@@ -84,7 +74,7 @@ SPoint2 OCCEdge::reparamOnFace(const GFace *face, double epar, int dir) const
else{ else{
c2d = BRep_Tool::CurveOnSurface(c_rev, *s, t0, t1); c2d = BRep_Tool::CurveOnSurface(c_rev, *s, t0, t1);
} }
if(c2d.IsNull()){ if(c2d.IsNull()){
Msg::Fatal("Reparam on face failed: curve %d is not on surface %d", Msg::Fatal("Reparam on face failed: curve %d is not on surface %d",
tag(), face->tag()); tag(), face->tag());
...@@ -116,12 +106,12 @@ GPoint OCCEdge::closestPoint(const SPoint3 &qp, double &param) const ...@@ -116,12 +106,12 @@ GPoint OCCEdge::closestPoint(const SPoint3 &qp, double &param) const
{ {
gp_Pnt pnt(qp.x(), qp.y(), qp.z()); gp_Pnt pnt(qp.x(), qp.y(), qp.z());
GeomAPI_ProjectPointOnCurve proj(pnt, curve, s0, s1); GeomAPI_ProjectPointOnCurve proj(pnt, curve, s0, s1);
if(!proj.NbPoints()){ if(!proj.NbPoints()){
Msg::Error("OCC Project Point on Curve FAIL"); Msg::Error("OCC Project Point on Curve FAIL");
return GPoint(0, 0); return GPoint(0, 0);
} }
param = proj.LowerDistanceParameter(); param = proj.LowerDistanceParameter();
if(param < s0 || param > s1){ if(param < s0 || param > s1){
...@@ -167,7 +157,7 @@ GPoint OCCEdge::point(double par) const ...@@ -167,7 +157,7 @@ GPoint OCCEdge::point(double par) const
} }
SVector3 OCCEdge::firstDer(double par) const SVector3 OCCEdge::firstDer(double par) const
{ {
BRepAdaptor_Curve brepc(c); BRepAdaptor_Curve brepc(c);
BRepLProp_CLProps prop(brepc, 1, 1e-5); BRepLProp_CLProps prop(brepc, 1, 1e-5);
prop.SetParameter(par); prop.SetParameter(par);
...@@ -230,9 +220,9 @@ int OCCEdge::minimumMeshSegments() const ...@@ -230,9 +220,9 @@ int OCCEdge::minimumMeshSegments() const
int np; int np;
if(geomType() == Line) if(geomType() == Line)
np = GEdge::minimumMeshSegments(); np = GEdge::minimumMeshSegments();
else else
np = CTX::instance()->mesh.minCurvPoints - 1; np = CTX::instance()->mesh.minCurvPoints - 1;
// if the edge is closed, ensure that at least 3 points are // if the edge is closed, ensure that at least 3 points are
// generated in the 1D mesh (4 segments, one of which is // generated in the 1D mesh (4 segments, one of which is
// degenerated) // degenerated)
...@@ -249,7 +239,7 @@ int OCCEdge::minimumDrawSegments() const ...@@ -249,7 +239,7 @@ int OCCEdge::minimumDrawSegments() const
return CTX::instance()->geom.numSubEdges * GEdge::minimumDrawSegments(); return CTX::instance()->geom.numSubEdges * GEdge::minimumDrawSegments();
} }
double OCCEdge::curvature(double par) const double OCCEdge::curvature(double par) const
{ {
const double eps = 1.e-15; const double eps = 1.e-15;
...@@ -265,7 +255,7 @@ double OCCEdge::curvature(double par) const ...@@ -265,7 +255,7 @@ double OCCEdge::curvature(double par) const
else{ else{
BRepAdaptor_Curve brepc(c); BRepAdaptor_Curve brepc(c);
BRepLProp_CLProps prop(brepc, 2, eps); BRepLProp_CLProps prop(brepc, 2, eps);
prop.SetParameter(par); prop.SetParameter(par);
if(!prop.IsTangentDefined()) if(!prop.IsTangentDefined())
Crv = eps; Crv = eps;
else else
...@@ -288,9 +278,9 @@ void OCCEdge::writeGEO(FILE *fp) ...@@ -288,9 +278,9 @@ void OCCEdge::writeGEO(FILE *fp)
// GEO supports only circle arcs < Pi // GEO supports only circle arcs < Pi
if(s1 - s0 < M_PI){ if(s1 - s0 < M_PI){
fprintf(fp, "p%d = newp;\n", tag()); fprintf(fp, "p%d = newp;\n", tag());
fprintf(fp, "Point(p%d + 1) = {%.16g, %.16g, %.16g};\n", fprintf(fp, "Point(p%d + 1) = {%.16g, %.16g, %.16g};\n",
tag(), center.X(), center.Y(), center.Z()); tag(), center.X(), center.Y(), center.Z());
fprintf(fp, "Circle(%d) = {%d, p%d + 1, %d};\n", fprintf(fp, "Circle(%d) = {%d, p%d + 1, %d};\n",
tag(), getBeginVertex()->tag(), tag(), getEndVertex()->tag()); tag(), getBeginVertex()->tag(), tag(), getEndVertex()->tag());
} }
else else
...@@ -311,7 +301,7 @@ void OCCEdge::replaceEndingPointsInternals(GVertex *g0, GVertex *g1) ...@@ -311,7 +301,7 @@ void OCCEdge::replaceEndingPointsInternals(GVertex *g0, GVertex *g1)
// printf("%p %p --- %p %p replacing %d %d by %d %d in occedge %d\n", // printf("%p %p --- %p %p replacing %d %d by %d %d in occedge %d\n",
// v0,v1,g0,g1,v0->tag(),v1->tag(),g0->tag(),g1->tag(),tag()); // v0,v1,g0,g1,v0->tag(),v1->tag(),g0->tag(),g1->tag(),tag());
Standard_Boolean bIsDE = BRep_Tool::Degenerated(c); Standard_Boolean bIsDE = BRep_Tool::Degenerated(c);
TopoDS_Edge aEx = c; TopoDS_Edge aEx = c;
...@@ -340,7 +330,7 @@ void OCCEdge::replaceEndingPointsInternals(GVertex *g0, GVertex *g1) ...@@ -340,7 +330,7 @@ void OCCEdge::replaceEndingPointsInternals(GVertex *g0, GVertex *g1)
_replacement=E; _replacement=E;
} }
else { else {
BOPTools_Tools::MakeSplitEdge(aEx, aVR1, t1, aVR2, t2, _replacement); BOPTools_Tools::MakeSplitEdge(aEx, aVR1, t1, aVR2, t2, _replacement);
} }
TopoDS_Edge temp = c; TopoDS_Edge temp = c;
c = _replacement; c = _replacement;
......
...@@ -27,7 +27,7 @@ class OCCEdge : public GEdge { ...@@ -27,7 +27,7 @@ class OCCEdge : public GEdge {
mutable GFace *trimmed; mutable GFace *trimmed;
public: public:
OCCEdge(GModel *model, TopoDS_Edge _e, int num, GVertex *v1, GVertex *v2); OCCEdge(GModel *model, TopoDS_Edge _e, int num, GVertex *v1, GVertex *v2);
virtual ~OCCEdge() {} virtual ~OCCEdge();
virtual Range<double> parBounds(int i) const; virtual Range<double> parBounds(int i) const;
virtual GeomType geomType() const; virtual GeomType geomType() const;
virtual bool degenerate(int) const { return BRep_Tool::Degenerated(c); } virtual bool degenerate(int) const { return BRep_Tool::Degenerated(c); }
...@@ -49,8 +49,6 @@ class OCCEdge : public GEdge { ...@@ -49,8 +49,6 @@ class OCCEdge : public GEdge {
void replaceEndingPointsInternals(GVertex *, GVertex *); void replaceEndingPointsInternals(GVertex *, GVertex *);
}; };
GEdge *getOCCEdgeByNativePtr(GModel *model, TopoDS_Edge toFind);
#endif #endif
#endif #endif
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "Context.h" #include "Context.h"
#if defined(HAVE_OCC) #if defined(HAVE_OCC)
#include "GModelIO_OCC.h"
#include <Standard_Version.hxx> #include <Standard_Version.hxx>
#include <Geom_CylindricalSurface.hxx> #include <Geom_CylindricalSurface.hxx>
#include <Geom_ConicalSurface.hxx> #include <Geom_ConicalSurface.hxx>
...@@ -33,6 +34,13 @@ OCCFace::OCCFace(GModel *m, TopoDS_Face _s, int num) ...@@ -33,6 +34,13 @@ OCCFace::OCCFace(GModel *m, TopoDS_Face _s, int num)
: GFace(m, num), s(_s) : GFace(m, num), s(_s)
{ {
setup(); setup();
model()->getOCCInternals()->bind(s, num);
}
OCCFace::~OCCFace()
{
model()->getOCCInternals()->unbind(s);
model()->getOCCInternals()->unbind(_replaced);
} }
void OCCFace::setup() void OCCFace::setup()
...@@ -47,7 +55,7 @@ void OCCFace::setup() ...@@ -47,7 +55,7 @@ void OCCFace::setup()
std::list<GEdge*> l_wire; std::list<GEdge*> l_wire;
for(exp3.Init(wire, TopAbs_EDGE); exp3.More(); exp3.Next()){ for(exp3.Init(wire, TopAbs_EDGE); exp3.More(); exp3.Next()){
TopoDS_Edge edge = TopoDS::Edge(exp3.Current()); TopoDS_Edge edge = TopoDS::Edge(exp3.Current());
GEdge *e = getOCCEdgeByNativePtr(model(), edge); GEdge *e = model()->getOCCInternals()->getOCCEdgeByNativePtr(model(), edge);
if(!e){ if(!e){
Msg::Error("Unknown edge in face %d", tag()); Msg::Error("Unknown edge in face %d", tag());
} }
...@@ -409,19 +417,6 @@ bool OCCFace::buildSTLTriangulation(bool force) ...@@ -409,19 +417,6 @@ bool OCCFace::buildSTLTriangulation(bool force)
return true; return true;
} }
GFace *getOCCFaceByNativePtr(GModel *model, TopoDS_Face toFind)
{
GModel::fiter it =model->firstFace();
for (; it !=model->lastFace(); ++it){
OCCFace *gf = dynamic_cast<OCCFace*>(*it);
if (gf){
if(toFind.IsSame(gf->getTopoDS_Face())) return *it;
if(toFind.IsSame(gf->getTopoDS_FaceOld())) return *it;
}
}
return 0;
}
void OCCFace::replaceEdgesInternal(std::list<GEdge*> &new_edges) void OCCFace::replaceEdgesInternal(std::list<GEdge*> &new_edges)
{ {
#if defined(OCC_VERSION_HEX) && OCC_VERSION_HEX >= 0x060503 #if defined(OCC_VERSION_HEX) && OCC_VERSION_HEX >= 0x060503
...@@ -520,6 +515,7 @@ void OCCFace::replaceEdgesInternal(std::list<GEdge*> &new_edges) ...@@ -520,6 +515,7 @@ void OCCFace::replaceEdgesInternal(std::list<GEdge*> &new_edges)
s = newFace; s = newFace;
setup(); setup();
model()->getOCCInternals()->bind(_replaced, tag());
} }
bool OCCFace::isSphere (double &radius, SPoint3 &center) const bool OCCFace::isSphere (double &radius, SPoint3 &center) const
......
...@@ -30,16 +30,16 @@ class OCCFace : public GFace { ...@@ -30,16 +30,16 @@ class OCCFace : public GFace {
SPoint3 _center; SPoint3 _center;
public: public:
OCCFace(GModel *m, TopoDS_Face s, int num); OCCFace(GModel *m, TopoDS_Face s, int num);
virtual ~OCCFace(){} virtual ~OCCFace();
Range<double> parBounds(int i) const; Range<double> parBounds(int i) const;
virtual GPoint point(double par1, double par2) const; virtual GPoint point(double par1, double par2) const;
virtual GPoint closestPoint(const SPoint3 & queryPoint, virtual GPoint closestPoint(const SPoint3 & queryPoint,
const double initialGuess[2]) const; const double initialGuess[2]) const;
virtual bool containsPoint(const SPoint3 &pt) const; virtual bool containsPoint(const SPoint3 &pt) const;
virtual SVector3 normal(const SPoint2 &param) const; virtual SVector3 normal(const SPoint2 &param) const;
virtual Pair<SVector3,SVector3> firstDer(const SPoint2 &param) const; virtual Pair<SVector3,SVector3> firstDer(const SPoint2 &param) const;
virtual void secondDer(const SPoint2 &, SVector3 *, SVector3 *, SVector3 *) const; virtual void secondDer(const SPoint2 &, SVector3 *, SVector3 *, SVector3 *) const;
virtual GEntity::GeomType geomType() const; virtual GEntity::GeomType geomType() const;
ModelType getNativeType() const { return OpenCascadeModel; } ModelType getNativeType() const { return OpenCascadeModel; }
void *getNativePtr() const { return (void*)&s; } void *getNativePtr() const { return (void*)&s; }
virtual SPoint2 parFromPoint(const SPoint3 &, bool onSurface=true) const; virtual SPoint2 parFromPoint(const SPoint3 &, bool onSurface=true) const;
...@@ -47,14 +47,12 @@ class OCCFace : public GFace { ...@@ -47,14 +47,12 @@ class OCCFace : public GFace {
virtual double curvatures(const SPoint2 &param, SVector3 *dirMax, SVector3 *dirMin, virtual double curvatures(const SPoint2 &param, SVector3 *dirMax, SVector3 *dirMin,
double *curvMax, double *curvMin) const; double *curvMax, double *curvMin) const;
surface_params getSurfaceParams() const; surface_params getSurfaceParams() const;
TopoDS_Face getTopoDS_Face () {return s;} TopoDS_Face getTopoDS_Face () { return s; }
TopoDS_Face getTopoDS_FaceOld () {return _replaced;} TopoDS_Face getTopoDS_FaceOld () { return _replaced; }
// tells if it's a sphere, and if it is, returns parameters // tells if it's a sphere, and if it is, returns parameters
virtual bool isSphere (double &radius, SPoint3 &center) const; virtual bool isSphere (double &radius, SPoint3 &center) const;
}; };
GFace *getOCCFaceByNativePtr(GModel *model, TopoDS_Face toFind);
#endif #endif
#endif #endif
...@@ -54,6 +54,7 @@ using std::iostream; ...@@ -54,6 +54,7 @@ using std::iostream;
#include <BRepTools_WireExplorer.hxx> #include <BRepTools_WireExplorer.hxx>
#include <BRepTools.hxx> #include <BRepTools.hxx>
#include <TopTools_IndexedMapOfShape.hxx> #include <TopTools_IndexedMapOfShape.hxx>
#include <TopTools_DataMapOfShapeInteger.hxx>
#include <TopExp.hxx> #include <TopExp.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx> #include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakeShell.hxx> #include <BRepBuilderAPI_MakeShell.hxx>
......
...@@ -12,11 +12,18 @@ ...@@ -12,11 +12,18 @@
#include "OCCRegion.h" #include "OCCRegion.h"
#if defined(HAVE_OCC) #if defined(HAVE_OCC)
#include "GModelIO_OCC.h"
OCCRegion::OCCRegion(GModel *m, TopoDS_Solid _s, int num) OCCRegion::OCCRegion(GModel *m, TopoDS_Solid _s, int num)
: GRegion(m, num), s(_s) : GRegion(m, num), s(_s)
{ {
setup(); setup();
model()->getOCCInternals()->bind(s, num);
}
OCCRegion::~OCCRegion()
{
model()->getOCCInternals()->unbind(s);
} }
void OCCRegion::setup() void OCCRegion::setup()
...@@ -28,7 +35,7 @@ void OCCRegion::setup() ...@@ -28,7 +35,7 @@ void OCCRegion::setup()
Msg::Debug("OCC Region %d - New Shell",tag()); Msg::Debug("OCC Region %d - New Shell",tag());
for(exp3.Init(shell, TopAbs_FACE); exp3.More(); exp3.Next()){ for(exp3.Init(shell, TopAbs_FACE); exp3.More(); exp3.Next()){
TopoDS_Face face = TopoDS::Face(exp3.Current()); TopoDS_Face face = TopoDS::Face(exp3.Current());
GFace *f = getOCCFaceByNativePtr(model(),face); GFace *f = model()->getOCCInternals()->getOCCFaceByNativePtr(model(),face);
if(f){ if(f){
l_faces.push_back(f); l_faces.push_back(f);
f->addRegion(this); f->addRegion(this);
...@@ -110,18 +117,4 @@ void OCCRegion::replaceFacesInternal(std::list<GFace*> &new_faces) ...@@ -110,18 +117,4 @@ void OCCRegion::replaceFacesInternal(std::list<GFace*> &new_faces)
setup(); setup();
} }
GRegion *getOCCRegionByNativePtr(GModel *model, TopoDS_Solid toFind)
{
GModel::riter it =model->firstRegion();
for (; it !=model->lastRegion(); it++){
OCCRegion *occr = dynamic_cast<OCCRegion*>(*it);
if (occr){
if (toFind.IsSame(occr->getTopoDS_Shape())){
return *it;
}
}
}
return 0;
}
#endif #endif
...@@ -18,15 +18,13 @@ class OCCRegion : public GRegion { ...@@ -18,15 +18,13 @@ class OCCRegion : public GRegion {
void setup(); void setup();
public: public:
OCCRegion(GModel *m, TopoDS_Solid s, int num); OCCRegion(GModel *m, TopoDS_Solid s, int num);
virtual ~OCCRegion() {} virtual ~OCCRegion();
virtual GeomType geomType() const; virtual GeomType geomType() const;
ModelType getNativeType() const { return OpenCascadeModel; } ModelType getNativeType() const { return OpenCascadeModel; }
void * getNativePtr() const { return (void*)&s; } void * getNativePtr() const { return (void*)&s; }
TopoDS_Solid getTopoDS_Shape() {return s;} TopoDS_Solid getTopoDS_Shape() {return s;}
}; };
GRegion *getOCCRegionByNativePtr(GModel *model, TopoDS_Solid toFind);
#endif #endif
#endif #endif
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
#if defined(HAVE_OCC) #if defined(HAVE_OCC)
OCCVertex::OCCVertex(GModel *m, int num, TopoDS_Vertex _v) #include "GModelIO_OCC.h"
OCCVertex::OCCVertex(GModel *m, int num, TopoDS_Vertex _v)
: GVertex(m, num), v(_v) : GVertex(m, num), v(_v)
{ {
max_curvature = -1; max_curvature = -1;
...@@ -21,6 +23,12 @@ OCCVertex::OCCVertex(GModel *m, int num, TopoDS_Vertex _v) ...@@ -21,6 +23,12 @@ OCCVertex::OCCVertex(GModel *m, int num, TopoDS_Vertex _v)
_x = pnt.X(); _x = pnt.X();
_y = pnt.Y(); _y = pnt.Y();
_z = pnt.Z(); _z = pnt.Z();
model()->getOCCInternals()->bind(v, num);
}
OCCVertex::~OCCVertex()
{
model()->getOCCInternals()->unbind(v);
} }
void OCCVertex::setPosition(GPoint &p) void OCCVertex::setPosition(GPoint &p)
...@@ -35,7 +43,7 @@ void OCCVertex::setPosition(GPoint &p) ...@@ -35,7 +43,7 @@ void OCCVertex::setPosition(GPoint &p)
} }
} }
double max_surf_curvature(const GVertex *gv, double x, double y, double z, double max_surf_curvature(const GVertex *gv, double x, double y, double z,
const GEdge *_myGEdge) const GEdge *_myGEdge)
{ {
std::list<GFace *> faces = _myGEdge->faces(); std::list<GFace *> faces = _myGEdge->faces();
...@@ -46,14 +54,14 @@ double max_surf_curvature(const GVertex *gv, double x, double y, double z, ...@@ -46,14 +54,14 @@ double max_surf_curvature(const GVertex *gv, double x, double y, double z,
double cc = (*it)->curvatureDiv(par); double cc = (*it)->curvatureDiv(par);
if(cc > 0) curv = std::max(curv, cc); if(cc > 0) curv = std::max(curv, cc);
++it; ++it;
} }
return curv; return curv;
} }
double OCCVertex::max_curvature_of_surfaces() const double OCCVertex::max_curvature_of_surfaces() const
{ {
if(max_curvature < 0){ if(max_curvature < 0){
for(std::list<GEdge*>::const_iterator it = l_edges.begin(); for(std::list<GEdge*>::const_iterator it = l_edges.begin();
it != l_edges.end(); ++it){ it != l_edges.end(); ++it){
max_curvature = std::max(max_surf_curvature(this, x(), y(), z(), *it), max_curvature = std::max(max_surf_curvature(this, x(), y(), z(), *it),
max_curvature); max_curvature);
...@@ -82,7 +90,7 @@ SPoint2 OCCVertex::reparamOnFace(const GFace *gf, int dir) const ...@@ -82,7 +90,7 @@ SPoint2 OCCVertex::reparamOnFace(const GFace *gf, int dir) const
} }
} }
++it; ++it;
} }
it = l_edges.begin(); it = l_edges.begin();
while(it != l_edges.end()){ while(it != l_edges.end()){
std::list<GEdge*> l = gf->edges(); std::list<GEdge*> l = gf->edges();
...@@ -111,18 +119,4 @@ SPoint2 OCCVertex::reparamOnFace(const GFace *gf, int dir) const ...@@ -111,18 +119,4 @@ SPoint2 OCCVertex::reparamOnFace(const GFace *gf, int dir) const
return GVertex::reparamOnFace(gf, dir); return GVertex::reparamOnFace(gf, dir);
} }
GVertex *getOCCVertexByNativePtr(GModel *model, TopoDS_Vertex toFind)
{
GModel::viter it =model->firstVertex();
for (; it != model->lastVertex(); it++){
OCCVertex *occv = dynamic_cast<OCCVertex*>(*it);
if (occv){
if (toFind.IsSame(occv->getShape())){
return *it;
}
}
}
return 0;
}
#endif #endif
...@@ -21,7 +21,7 @@ class OCCVertex : public GVertex { ...@@ -21,7 +21,7 @@ class OCCVertex : public GVertex {
double max_curvature_of_surfaces() const; double max_curvature_of_surfaces() const;
public: public:
OCCVertex(GModel *m, int num, TopoDS_Vertex _v); OCCVertex(GModel *m, int num, TopoDS_Vertex _v);
virtual ~OCCVertex() {} virtual ~OCCVertex();
virtual GPoint point() const { return GPoint(x(), y(), z()); } virtual GPoint point() const { return GPoint(x(), y(), z()); }
virtual double x() const { return _x; } virtual double x() const { return _x; }
virtual double y() const { return _y; } virtual double y() const { return _y; }
...@@ -33,8 +33,6 @@ class OCCVertex : public GVertex { ...@@ -33,8 +33,6 @@ class OCCVertex : public GVertex {
TopoDS_Vertex getShape() { return v; } TopoDS_Vertex getShape() { return v; }
}; };
GVertex *getOCCVertexByNativePtr(GModel *model, TopoDS_Vertex toFind);
#endif #endif
#endif #endif
...@@ -339,7 +339,7 @@ class drawGFace { ...@@ -339,7 +339,7 @@ class drawGFace {
if(CTX::instance()->geom.surfaces) { if(CTX::instance()->geom.surfaces) {
bool selected = false; bool selected = false;
if (f->getSelection() || (f->getCompound() && f->getCompound()->getSelection())) if (f->getSelection() || (f->getCompound() && f->getCompound()->getSelection()))
selected = true; selected = true;
if(CTX::instance()->geom.surfaceType > 0 && f->va_geom_triangles){ if(CTX::instance()->geom.surfaceType > 0 && f->va_geom_triangles){
_drawVertexArray(f->va_geom_triangles, CTX::instance()->geom.light, _drawVertexArray(f->va_geom_triangles, CTX::instance()->geom.light,
f->getSelection(), CTX::instance()->color.geom.selection); f->getSelection(), CTX::instance()->color.geom.selection);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment