diff --git a/libsrc/csg/csgeom.cpp b/libsrc/csg/csgeom.cpp index 754dbe49..dfa9128b 100644 --- a/libsrc/csg/csgeom.cpp +++ b/libsrc/csg/csgeom.cpp @@ -129,11 +129,11 @@ namespace netgen extern int CSGGenerateMesh (CSGeometry & geom, - Mesh *& mesh, MeshingParameters & mparam, + shared_ptr & mesh, MeshingParameters & mparam, int perfstepsstart, int perfstepsend); - int CSGeometry :: GenerateMesh (Mesh*& mesh, MeshingParameters & mparam, + int CSGeometry :: GenerateMesh (shared_ptr & mesh, MeshingParameters & mparam, int perfstepsstart, int perfstepsend) { return CSGGenerateMesh (*this, mesh, mparam, perfstepsstart, perfstepsend); @@ -182,7 +182,7 @@ namespace netgen void CSGeometry :: Save (string filename) const { - fstream ost (filename.c_str()); + ofstream ost (filename.c_str()); Save (ost); } diff --git a/libsrc/csg/csgeom.hpp b/libsrc/csg/csgeom.hpp index 4f0ef5ab..8347b665 100644 --- a/libsrc/csg/csgeom.hpp +++ b/libsrc/csg/csgeom.hpp @@ -313,7 +313,7 @@ namespace netgen Array bcmodifications; - virtual int GenerateMesh (Mesh*& mesh, MeshingParameters & mparam, + virtual int GenerateMesh (shared_ptr & mesh, MeshingParameters & mparam, int perfstepsstart, int perfstepsend); virtual const Refinement & GetRefinement () const; diff --git a/libsrc/csg/genmesh.cpp b/libsrc/csg/genmesh.cpp index 9684e7ea..5a1ff811 100644 --- a/libsrc/csg/genmesh.cpp +++ b/libsrc/csg/genmesh.cpp @@ -653,7 +653,7 @@ namespace netgen int CSGGenerateMesh (CSGeometry & geom, - Mesh *& mesh, MeshingParameters & mparam, + shared_ptr & mesh, MeshingParameters & mparam, int perfstepsstart, int perfstepsend) { if (mesh && mesh->GetNSE() && @@ -668,7 +668,7 @@ namespace netgen if (mesh) mesh -> DeleteMesh(); else - mesh = new Mesh(); + mesh = make_shared(); mesh->SetGlobalH (mparam.maxh); mesh->SetMinimalH (mparam.minh); diff --git a/libsrc/csg/python_csg.cpp b/libsrc/csg/python_csg.cpp index 77c63bd0..208fd26d 100644 --- a/libsrc/csg/python_csg.cpp +++ b/libsrc/csg/python_csg.cpp @@ -46,7 +46,10 @@ public: enum optyp { TERM, SECTION, UNION, SUB }; SPSolid (Solid * as) : solid(as), owner(true), op(TERM) { ; } - + ~SPSolid () + { + if (owner) delete solid; + } SPSolid (optyp aop, shared_ptr as1, shared_ptr as2) : s1(as1), s2(as2), owner(true), op(aop) { @@ -55,7 +58,7 @@ public: else if (aop == SECTION) solid = new Solid (Solid::SECTION, s1->GetSolid(), s2->GetSolid()); else if (aop == SUB) - solid = new Solid (Solid::SUB, s1->GetSolid(), s2->GetSolid()); + solid = new Solid (Solid::SUB, s1->GetSolid()); // , s2->GetSolid()); } Solid * GetSolid() { return solid; } @@ -106,7 +109,9 @@ void ExportCSG() ; bp::class_> ("Point3d", bp::init()) + .def(bp::self-bp::self) .def(bp::self+Vec<3>()) + .def(bp::self-Vec<3>()) ; bp::def ("Pnt", FunctionPointer( [] (double x, double y, double z) { return Point<3>(x,y,z); } ) ); @@ -132,24 +137,30 @@ void ExportCSG() bp::class_, boost::noncopyable> ("Solid", bp::no_init) .def ("__add__", FunctionPointer( [] ( shared_ptr self, shared_ptr other ) { return make_shared (SPSolid::UNION, self, other); } ) ) .def ("__mul__", FunctionPointer( [] ( shared_ptr self, shared_ptr other ) { return make_shared (SPSolid::SECTION, self, other); } ) ) - .def ("__sub__", FunctionPointer( [] ( shared_ptr self, shared_ptr other ) { return make_shared (SPSolid::SUB, self, other); } ) ) + .def ("__sub__", FunctionPointer( [] ( shared_ptr self, shared_ptr other ) + { return make_shared (SPSolid::SECTION, self, make_shared (SPSolid::SUB, other, nullptr)); } ) ) // .def ("__neg__", FunctionPointer( [] ( shared_ptr self ) { return make_shared (SPSolid::SUB, self); } ) ) COMPLEMENT? ; - bp::def ("Sphere", FunctionPointer([](const Point<3> c, double r) + bp::def ("Sphere", FunctionPointer([](Point<3> c, double r) { Sphere * sp = new Sphere (c, r); Solid * sol = new Solid (sp); return make_shared (sol); })); - bp::def ("Plane", FunctionPointer([](const Point<3> p, Vec<3> n) + bp::def ("Plane", FunctionPointer([](Point<3> p, Vec<3> n) { Plane * sp = new Plane (p,n); Solid * sol = new Solid (sp); return make_shared (sol); })); - - bp::def ("OrthoBrick", FunctionPointer([](const Point<3> p1, Point<3> p2) + bp::def ("Cylinder", FunctionPointer([](Point<3> a, Point<3> b, double r) + { + Cylinder * cyl = new Cylinder (a, b, r); + Solid * sol = new Solid (cyl); + return make_shared (sol); + })); + bp::def ("OrthoBrick", FunctionPointer([](Point<3> p1, Point<3> p2) { OrthoBrick * brick = new OrthoBrick (p1,p2); Solid * sol = new Solid (brick); @@ -177,6 +188,11 @@ void ExportCSG() return geom; }))) + .def("Save", FunctionPointer([] (CSGeometry & self, string filename) + { + cout << "save geometry to file " << filename << endl; + self.Save (filename); + })) .def("Add", FunctionPointer([] (CSGeometry & self, shared_ptr solid) { solid->AddSurfaces (self); @@ -190,11 +206,11 @@ void ExportCSG() bp::def("GenerateMesh", FunctionPointer ([](CSGeometry & geo, MeshingParameters & param) { - Mesh * dummy = NULL; + shared_ptr dummy; cout << "Genrate Mesh, params = "; // << param << endl; geo.FindIdenticSurfaces(1e-8 * geo.MaxSize()); geo.GenerateMesh (dummy, param, 0, 6); - return shared_ptr (dummy); + return dummy; })); } diff --git a/libsrc/csg/vscsg.cpp b/libsrc/csg/vscsg.cpp index d33e5a3f..3ee322f1 100644 --- a/libsrc/csg/vscsg.cpp +++ b/libsrc/csg/vscsg.cpp @@ -22,10 +22,6 @@ namespace netgen extern Array > boxes; - extern Array > project1, project2; - - - // extern AutoPtr geometry; VisualSceneGeometry :: VisualSceneGeometry () diff --git a/libsrc/geom2d/genmesh2d.cpp b/libsrc/geom2d/genmesh2d.cpp index fe6e6d62..ca04c619 100644 --- a/libsrc/geom2d/genmesh2d.cpp +++ b/libsrc/geom2d/genmesh2d.cpp @@ -350,7 +350,7 @@ namespace netgen void MeshFromSpline2D (SplineGeometry2d & geometry, - Mesh *& mesh, + shared_ptr & mesh, MeshingParameters & mp) { PrintMessage (1, "Generate Mesh from spline geometry"); @@ -365,7 +365,7 @@ namespace netgen mp.maxh = h; } - mesh = new Mesh; + mesh = make_shared(); mesh->SetDimension (2); Point3d pmin(bbox.PMin()(0), bbox.PMin()(1), -bbox.Diam()); diff --git a/libsrc/geom2d/geometry2d.cpp b/libsrc/geom2d/geometry2d.cpp index ffce88f2..5c7754cf 100644 --- a/libsrc/geom2d/geometry2d.cpp +++ b/libsrc/geom2d/geometry2d.cpp @@ -928,11 +928,11 @@ namespace netgen extern void MeshFromSpline2D (SplineGeometry2d & geometry, - Mesh *& mesh, + shared_ptr & mesh, MeshingParameters & mp); - int SplineGeometry2d :: GenerateMesh (Mesh*& mesh, MeshingParameters & mparam, + int SplineGeometry2d :: GenerateMesh (shared_ptr & mesh, MeshingParameters & mparam, int perfstepsstart, int perfstepsend) { MeshFromSpline2D (*this, mesh, mparam); diff --git a/libsrc/geom2d/geometry2d.hpp b/libsrc/geom2d/geometry2d.hpp index 15e9e80d..a8d9e97a 100644 --- a/libsrc/geom2d/geometry2d.hpp +++ b/libsrc/geom2d/geometry2d.hpp @@ -151,8 +151,8 @@ namespace netgen } - DLL_HEADER virtual int GenerateMesh (Mesh*& mesh, MeshingParameters & mparam, - int perfstepsstart, int perfstepsend); + DLL_HEADER virtual int GenerateMesh (shared_ptr & mesh, MeshingParameters & mparam, + int perfstepsstart, int perfstepsend); void PartitionBoundary (MeshingParameters & mp, double h, Mesh & mesh2d); diff --git a/libsrc/geom2d/splinegeometry2.hpp b/libsrc/geom2d/splinegeometry2.hpp index 6b1428be..2e63d042 100644 --- a/libsrc/geom2d/splinegeometry2.hpp +++ b/libsrc/geom2d/splinegeometry2.hpp @@ -95,7 +95,7 @@ public: void MeshFromSpline2D (SplineGeometry2d & geometry, - Mesh *& mesh, + shared_ptr & mesh, MeshingParameters & mp); #endif diff --git a/libsrc/meshing/basegeom.cpp b/libsrc/meshing/basegeom.cpp index 11075f68..b531481a 100644 --- a/libsrc/meshing/basegeom.cpp +++ b/libsrc/meshing/basegeom.cpp @@ -14,7 +14,7 @@ namespace netgen - int NetgenGeometry :: GenerateMesh (Mesh*& mesh, MeshingParameters & mparam, + int NetgenGeometry :: GenerateMesh (shared_ptr & mesh, MeshingParameters & mparam, int perfstepsstart, int perfstepsend) { if (!mesh) return 1; diff --git a/libsrc/meshing/basegeom.hpp b/libsrc/meshing/basegeom.hpp index eb849657..a9592cbf 100644 --- a/libsrc/meshing/basegeom.hpp +++ b/libsrc/meshing/basegeom.hpp @@ -18,7 +18,7 @@ namespace netgen public: virtual ~NetgenGeometry () { ; } - virtual int GenerateMesh (Mesh*& mesh, MeshingParameters & mparam, + virtual int GenerateMesh (shared_ptr & mesh, MeshingParameters & mparam, int perfstepsstart, int perfstepsend); virtual const Refinement & GetRefinement () const; diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index 67c81bb3..56f88426 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -84,13 +84,15 @@ void ExportNetgenMeshing() .def("__str__", &ToString) .add_property("nr", &PointIndex::operator int) ; - + + /* bp::class_> ("Point") .def(bp::init()) ; - - bp::class_>>("MeshPoint") - .def(bp::init>()) + */ + + bp::class_> */ >("MeshPoint") + // .def(bp::init>()) .add_property("p", FunctionPointer([](const MeshPoint & self) { bp::list l; diff --git a/libsrc/stlgeom/stlgeom.cpp b/libsrc/stlgeom/stlgeom.cpp index 659560db..78d0058a 100644 --- a/libsrc/stlgeom/stlgeom.cpp +++ b/libsrc/stlgeom/stlgeom.cpp @@ -91,7 +91,7 @@ void STLGeometry :: Save (string filename) const -int STLGeometry :: GenerateMesh (Mesh*& mesh, MeshingParameters & mparam, +int STLGeometry :: GenerateMesh (shared_ptr & mesh, MeshingParameters & mparam, int perfstepsstart, int perfstepsend) { return STLMeshingDummy (this, mesh, mparam, perfstepsstart, perfstepsend); diff --git a/libsrc/stlgeom/stlgeom.hpp b/libsrc/stlgeom/stlgeom.hpp index d064e2d7..a8283761 100644 --- a/libsrc/stlgeom/stlgeom.hpp +++ b/libsrc/stlgeom/stlgeom.hpp @@ -452,7 +452,7 @@ namespace netgen friend class MeshingSTLSurface; - virtual int GenerateMesh (Mesh*& mesh, MeshingParameters & mparam, + virtual int GenerateMesh (shared_ptr & mesh, MeshingParameters & mparam, int perfstepsstart, int perfstepsend); virtual const Refinement & GetRefinement () const; @@ -463,7 +463,7 @@ namespace netgen - extern int STLMeshingDummy (STLGeometry* stlgeometry, Mesh*& mesh, MeshingParameters & mparam, + extern int STLMeshingDummy (STLGeometry* stlgeometry, shared_ptr & mesh, MeshingParameters & mparam, int perfstepsstart, int perfstepsend); diff --git a/libsrc/stlgeom/stlgeommesh.cpp b/libsrc/stlgeom/stlgeommesh.cpp index d7da795f..4232375c 100644 --- a/libsrc/stlgeom/stlgeommesh.cpp +++ b/libsrc/stlgeom/stlgeommesh.cpp @@ -1329,8 +1329,8 @@ void STLGeometry :: RestrictHChartDistOneChart(int chartnum, Array& acttrig } -int STLMeshingDummy (STLGeometry* stlgeometry, Mesh*& mesh, MeshingParameters & mparam, - int perfstepsstart, int perfstepsend) +int STLMeshingDummy (STLGeometry* stlgeometry, shared_ptr & mesh, MeshingParameters & mparam, + int perfstepsstart, int perfstepsend) { if (perfstepsstart > perfstepsend) return 0; @@ -1341,7 +1341,7 @@ int STLMeshingDummy (STLGeometry* stlgeometry, Mesh*& mesh, MeshingParameters & if (perfstepsstart <= MESHCONST_MESHEDGES) { - mesh = new Mesh(); + mesh = make_shared(); mesh->geomtype = Mesh::GEOM_STL; mesh -> SetGlobalH (mparam.maxh);