From bbd2808068c090fa98534ccc1293a00eeee3511d Mon Sep 17 00:00:00 2001
From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be>
Date: Wed, 3 Jun 2015 16:41:26 +0000
Subject: [PATCH] gmshpy : wrappers for MElementOctree

---
 Geo/GModel.cpp            |  7 +++++++
 Geo/GModel.h              |  1 +
 Geo/MElement.cpp          |  9 ---------
 Geo/MElement.h            |  1 -
 Geo/MElementOctree.cpp    |  2 +-
 Geo/MElementOctree.h      |  3 +--
 wrappers/gmshpy/gmshGeo.i | 10 ++++++++++
 7 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp
index 515472f7b0..dd1d23d9e6 100644
--- a/Geo/GModel.cpp
+++ b/Geo/GModel.cpp
@@ -822,6 +822,13 @@ std::vector<MElement*> GModel::getMeshElementsByCoord(SPoint3 &p, int dim, bool
   return _octree->findAll(p.x(), p.y(), p.z(), dim, strict);
 }
 
+void GModel::deleteOctree() {
+  if (_octree) {
+    delete _octree;
+    _octree = NULL;
+  }
+}
+
 MVertex *GModel::getMeshVertexByTag(int n)
 {
   if(_vertexVectorCache.empty() && _vertexMapCache.empty()){
diff --git a/Geo/GModel.h b/Geo/GModel.h
index cda7dc2b97..ac63db4981 100644
--- a/Geo/GModel.h
+++ b/Geo/GModel.h
@@ -364,6 +364,7 @@ class GModel
   // access a mesh element by coordinates (using an octree search)
   MElement *getMeshElementByCoord(SPoint3 &p, int dim=-1, bool strict=true);
   std::vector<MElement*> getMeshElementsByCoord(SPoint3 &p, int dim=-1, bool strict=true);
+  void deleteOctree();
 
   // access a mesh element by tag, using the element cache
   MElement *getMeshElementByTag(int n);
diff --git a/Geo/MElement.cpp b/Geo/MElement.cpp
index 3994bc0ea5..0424d058c4 100644
--- a/Geo/MElement.cpp
+++ b/Geo/MElement.cpp
@@ -803,15 +803,6 @@ void MElement::xyz2uvw(double xyz[3], double uvw[3]) const
   }
 }
 
-void MElement::xyzTouvw(fullMatrix<double> *xu) const
-{
-  double _xyz[3] = {(*xu)(0,0),(*xu)(0,1),(*xu)(0,2)}, _uvw[3];
-  xyz2uvw(_xyz, _uvw);
-  (*xu)(1,0) = _uvw[0];
-  (*xu)(1,1) = _uvw[1];
-  (*xu)(1,2) = _uvw[2];
-}
-
 void MElement::movePointFromParentSpaceToElementSpace(double &u, double &v, double &w) const
 {
   if(!getParent()) return;
diff --git a/Geo/MElement.h b/Geo/MElement.h
index c19d8e4a4a..514ff9f192 100644
--- a/Geo/MElement.h
+++ b/Geo/MElement.h
@@ -318,7 +318,6 @@ class MElement
 
   // invert the parametrisation
   virtual void xyz2uvw(double xyz[3], double uvw[3]) const;
-  void xyzTouvw(fullMatrix<double> *xu) const;
 
   // move point between parent and element parametric spaces
   virtual void movePointFromParentSpaceToElementSpace(double &u, double &v,
diff --git a/Geo/MElementOctree.cpp b/Geo/MElementOctree.cpp
index 360e6afb02..efff71ff79 100644
--- a/Geo/MElementOctree.cpp
+++ b/Geo/MElementOctree.cpp
@@ -89,7 +89,7 @@ MElementOctree::MElementOctree(GModel *m) : _gm(m)
   Octree_Arrange(_octree);
 }
 
-MElementOctree::MElementOctree(std::vector<MElement*> &v) : _gm(0), _elems(v)
+MElementOctree::MElementOctree(const std::vector<MElement*> &v) : _gm(0), _elems(v)
 {
   SBoundingBox3d bb;
   for (unsigned int i = 0; i < v.size(); i++){
diff --git a/Geo/MElementOctree.h b/Geo/MElementOctree.h
index a517f8b68d..e30f57922a 100644
--- a/Geo/MElementOctree.h
+++ b/Geo/MElementOctree.h
@@ -19,11 +19,10 @@ class MElementOctree{
   std::vector<MElement*> _elems;
  public:
   MElementOctree(GModel *);
-  MElementOctree(std::vector<MElement*> &);
+  MElementOctree(const std::vector<MElement*> &);
   ~MElementOctree();
   MElement *find(double x, double y, double z, int dim = -1, bool strict = false) const;
   Octree *getInternalOctree(){ return _octree; }
   std::vector<MElement *> findAll(double x, double y, double z, int dim, bool strict = false);
 };
-
 #endif
diff --git a/wrappers/gmshpy/gmshGeo.i b/wrappers/gmshpy/gmshGeo.i
index df1b615434..454361a278 100644
--- a/wrappers/gmshpy/gmshGeo.i
+++ b/wrappers/gmshpy/gmshGeo.i
@@ -25,6 +25,7 @@
   #include "discreteVertex.h"
   #include "gmshLevelset.h"
   #include "MElement.h"
+  #include "MElementOctree.h"
   #include "MVertex.h"
   #include "MTriangle.h"
   #include "MTetrahedron.h"
@@ -112,6 +113,8 @@ namespace std {
 %include "discreteRegion.h"
 %include "SPoint3.h"
 %include "MElement.h"
+%ignore MElementOctree::MElementOctree(GModel*);
+%include "MElementOctree.h"
 %ignore MVertex::x();
 %ignore MVertex::y();
 %ignore MVertex::z();
@@ -183,6 +186,12 @@ namespace std {
     $self->pnt(xi0, xi1, xi2, p);
     return p;
   }
+  std::vector<double> xyz2uvw(double x, double y, double z) {
+    double xyz[3] = {x, y, z};
+    std::vector<double> uvw(3, 0.);
+    $self->xyz2uvw(xyz, &uvw[0]);
+    return uvw;
+  }
 }
 
 %extend GEdge {
@@ -211,3 +220,4 @@ namespace std {
     $self->meshAttributes.recombine3D = 1;
   }
 }
+
-- 
GitLab