From 7be877d6a478ffee1df21cf836640d65c78bfe86 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 19 Jan 2015 18:04:05 +0000
Subject: [PATCH] true bounding boxes

---
 Geo/OCCEdge.cpp   | 10 ++++++++++
 Geo/OCCEdge.h     |  1 +
 Geo/OCCFace.cpp   | 10 ++++++++++
 Geo/OCCFace.h     |  1 +
 Geo/OCCRegion.cpp | 10 ++++++++++
 Geo/OCCRegion.h   |  1 +
 6 files changed, 33 insertions(+)

diff --git a/Geo/OCCEdge.cpp b/Geo/OCCEdge.cpp
index 5e869775fc..9f6386efe7 100644
--- a/Geo/OCCEdge.cpp
+++ b/Geo/OCCEdge.cpp
@@ -45,6 +45,16 @@ OCCEdge::~OCCEdge()
   model()->getOCCInternals()->unbind(c);
 }
 
+SBoundingBox3d OCCEdge::bounds() const
+{
+  Bnd_Box b;
+  BRepBndLib::Add(c, b);
+  double xmin, ymin, zmin, xmax, ymax, zmax;
+  b.Get(xmin, ymin, zmin, xmax, ymax, zmax);
+  SBoundingBox3d bbox(xmin, ymin, zmin, xmax, ymax, zmax);
+  return bbox;
+}
+
 Range<double> OCCEdge::parBounds(int i) const
 {
   return Range<double>(s0, s1);
diff --git a/Geo/OCCEdge.h b/Geo/OCCEdge.h
index ba176b283b..4170ce64ab 100644
--- a/Geo/OCCEdge.h
+++ b/Geo/OCCEdge.h
@@ -28,6 +28,7 @@ class OCCEdge : public GEdge {
  public:
   OCCEdge(GModel *model, TopoDS_Edge _e, int num, GVertex *v1, GVertex *v2);
   virtual ~OCCEdge();
+  virtual SBoundingBox3d bounds() const;
   virtual Range<double> parBounds(int i) const;
   virtual GeomType geomType() const;
   virtual bool degenerate(int) const { return BRep_Tool::Degenerated(c); }
diff --git a/Geo/OCCFace.cpp b/Geo/OCCFace.cpp
index 3495091cbd..cbf2d27dec 100644
--- a/Geo/OCCFace.cpp
+++ b/Geo/OCCFace.cpp
@@ -125,6 +125,16 @@ void OCCFace::setup()
   // }
 }
 
+SBoundingBox3d OCCFace::bounds() const
+{
+  Bnd_Box b;
+  BRepBndLib::Add(s, b);
+  double xmin, ymin, zmin, xmax, ymax, zmax;
+  b.Get(xmin, ymin, zmin, xmax, ymax, zmax);
+  SBoundingBox3d bbox(xmin, ymin, zmin, xmax, ymax, zmax);
+  return bbox;
+}
+
 Range<double> OCCFace::parBounds(int i) const
 {
   double umin2, umax2, vmin2, vmax2;
diff --git a/Geo/OCCFace.h b/Geo/OCCFace.h
index d51baa26a9..d98ba4509b 100644
--- a/Geo/OCCFace.h
+++ b/Geo/OCCFace.h
@@ -31,6 +31,7 @@ class OCCFace : public GFace {
  public:
   OCCFace(GModel *m, TopoDS_Face s, int num);
   virtual ~OCCFace();
+  virtual SBoundingBox3d bounds() const;
   Range<double> parBounds(int i) const;
   virtual GPoint point(double par1, double par2) const;
   virtual GPoint closestPoint(const SPoint3 & queryPoint,
diff --git a/Geo/OCCRegion.cpp b/Geo/OCCRegion.cpp
index d4df9425d7..3a485b1578 100644
--- a/Geo/OCCRegion.cpp
+++ b/Geo/OCCRegion.cpp
@@ -47,6 +47,16 @@ void OCCRegion::setup()
   Msg::Debug("OCC Region %d with %d faces", tag(), l_faces.size());
 }
 
+SBoundingBox3d OCCRegion::bounds() const
+{
+  Bnd_Box b;
+  BRepBndLib::Add(s, b);
+  double xmin, ymin, zmin, xmax, ymax, zmax;
+  b.Get(xmin, ymin, zmin, xmax, ymax, zmax);
+  SBoundingBox3d bbox(xmin, ymin, zmin, xmax, ymax, zmax);
+  return bbox;
+}
+
 GEntity::GeomType OCCRegion::geomType() const
 {
   return Unknown;
diff --git a/Geo/OCCRegion.h b/Geo/OCCRegion.h
index 2fcd174d96..b132f02da2 100644
--- a/Geo/OCCRegion.h
+++ b/Geo/OCCRegion.h
@@ -19,6 +19,7 @@ class OCCRegion : public GRegion {
  public:
   OCCRegion(GModel *m, TopoDS_Solid s, int num);
   virtual ~OCCRegion();
+  virtual SBoundingBox3d bounds() const;
   virtual GeomType geomType() const;
   ModelType getNativeType() const { return OpenCascadeModel; }
   void * getNativePtr() const { return (void*)&s; }
-- 
GitLab