python, shared ptr

This commit is contained in:
Joachim Schoeberl 2014-09-25 20:23:31 +00:00
parent 3b5a612ddf
commit 4dda85ac90
15 changed files with 52 additions and 38 deletions

View File

@ -129,11 +129,11 @@ namespace netgen
extern int CSGGenerateMesh (CSGeometry & geom,
Mesh *& mesh, MeshingParameters & mparam,
shared_ptr<Mesh> & mesh, MeshingParameters & mparam,
int perfstepsstart, int perfstepsend);
int CSGeometry :: GenerateMesh (Mesh*& mesh, MeshingParameters & mparam,
int CSGeometry :: GenerateMesh (shared_ptr<Mesh> & 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);
}

View File

@ -313,7 +313,7 @@ namespace netgen
Array<BCModification> bcmodifications;
virtual int GenerateMesh (Mesh*& mesh, MeshingParameters & mparam,
virtual int GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam,
int perfstepsstart, int perfstepsend);
virtual const Refinement & GetRefinement () const;

View File

@ -653,7 +653,7 @@ namespace netgen
int CSGGenerateMesh (CSGeometry & geom,
Mesh *& mesh, MeshingParameters & mparam,
shared_ptr<Mesh> & 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>();
mesh->SetGlobalH (mparam.maxh);
mesh->SetMinimalH (mparam.minh);

View File

@ -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<SPSolid> as1, shared_ptr<SPSolid> 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_<Point<3>> ("Point3d", bp::init<double,double,double>())
.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_<SPSolid, shared_ptr<SPSolid>, boost::noncopyable> ("Solid", bp::no_init)
.def ("__add__", FunctionPointer( [] ( shared_ptr<SPSolid> self, shared_ptr<SPSolid> other ) { return make_shared<SPSolid> (SPSolid::UNION, self, other); } ) )
.def ("__mul__", FunctionPointer( [] ( shared_ptr<SPSolid> self, shared_ptr<SPSolid> other ) { return make_shared<SPSolid> (SPSolid::SECTION, self, other); } ) )
.def ("__sub__", FunctionPointer( [] ( shared_ptr<SPSolid> self, shared_ptr<SPSolid> other ) { return make_shared<SPSolid> (SPSolid::SUB, self, other); } ) )
.def ("__sub__", FunctionPointer( [] ( shared_ptr<SPSolid> self, shared_ptr<SPSolid> other )
{ return make_shared<SPSolid> (SPSolid::SECTION, self, make_shared<SPSolid> (SPSolid::SUB, other, nullptr)); } ) )
// .def ("__neg__", FunctionPointer( [] ( shared_ptr<SPSolid> self ) { return make_shared<SPSolid> (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<SPSolid> (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<SPSolid> (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<SPSolid> (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<SPSolid> solid)
{
solid->AddSurfaces (self);
@ -190,11 +206,11 @@ void ExportCSG()
bp::def("GenerateMesh", FunctionPointer
([](CSGeometry & geo, MeshingParameters & param)
{
Mesh * dummy = NULL;
shared_ptr<Mesh> dummy;
cout << "Genrate Mesh, params = "; // << param << endl;
geo.FindIdenticSurfaces(1e-8 * geo.MaxSize());
geo.GenerateMesh (dummy, param, 0, 6);
return shared_ptr<Mesh> (dummy);
return dummy;
}));
}

View File

@ -22,10 +22,6 @@ namespace netgen
extern Array<Box<3> > boxes;
extern Array<Point<3> > project1, project2;
// extern AutoPtr<CSGeometry> geometry;
VisualSceneGeometry :: VisualSceneGeometry ()

View File

@ -350,7 +350,7 @@ namespace netgen
void MeshFromSpline2D (SplineGeometry2d & geometry,
Mesh *& mesh,
shared_ptr<Mesh> & 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>();
mesh->SetDimension (2);
Point3d pmin(bbox.PMin()(0), bbox.PMin()(1), -bbox.Diam());

View File

@ -928,11 +928,11 @@ namespace netgen
extern void MeshFromSpline2D (SplineGeometry2d & geometry,
Mesh *& mesh,
shared_ptr<Mesh> & mesh,
MeshingParameters & mp);
int SplineGeometry2d :: GenerateMesh (Mesh*& mesh, MeshingParameters & mparam,
int SplineGeometry2d :: GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam,
int perfstepsstart, int perfstepsend)
{
MeshFromSpline2D (*this, mesh, mparam);

View File

@ -151,7 +151,7 @@ namespace netgen
}
DLL_HEADER virtual int GenerateMesh (Mesh*& mesh, MeshingParameters & mparam,
DLL_HEADER virtual int GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam,
int perfstepsstart, int perfstepsend);
void PartitionBoundary (MeshingParameters & mp, double h, Mesh & mesh2d);

View File

@ -95,7 +95,7 @@ public:
void MeshFromSpline2D (SplineGeometry2d & geometry,
Mesh *& mesh,
shared_ptr<Mesh> & mesh,
MeshingParameters & mp);
#endif

View File

@ -14,7 +14,7 @@ namespace netgen
int NetgenGeometry :: GenerateMesh (Mesh*& mesh, MeshingParameters & mparam,
int NetgenGeometry :: GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam,
int perfstepsstart, int perfstepsend)
{
if (!mesh) return 1;

View File

@ -18,7 +18,7 @@ namespace netgen
public:
virtual ~NetgenGeometry () { ; }
virtual int GenerateMesh (Mesh*& mesh, MeshingParameters & mparam,
virtual int GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam,
int perfstepsstart, int perfstepsend);
virtual const Refinement & GetRefinement () const;

View File

@ -85,12 +85,14 @@ void ExportNetgenMeshing()
.add_property("nr", &PointIndex::operator int)
;
/*
bp::class_<Point<3>> ("Point")
.def(bp::init<double,double,double>())
;
*/
bp::class_<MeshPoint,bp::bases<Point<3>>>("MeshPoint")
.def(bp::init<Point<3>>())
bp::class_<MeshPoint /* ,bp::bases<Point<3>> */ >("MeshPoint")
// .def(bp::init<Point<3>>())
.add_property("p", FunctionPointer([](const MeshPoint & self)
{
bp::list l;

View File

@ -91,7 +91,7 @@ void STLGeometry :: Save (string filename) const
int STLGeometry :: GenerateMesh (Mesh*& mesh, MeshingParameters & mparam,
int STLGeometry :: GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam,
int perfstepsstart, int perfstepsend)
{
return STLMeshingDummy (this, mesh, mparam, perfstepsstart, perfstepsend);

View File

@ -452,7 +452,7 @@ namespace netgen
friend class MeshingSTLSurface;
virtual int GenerateMesh (Mesh*& mesh, MeshingParameters & mparam,
virtual int GenerateMesh (shared_ptr<Mesh> & 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> & mesh, MeshingParameters & mparam,
int perfstepsstart, int perfstepsend);

View File

@ -1329,7 +1329,7 @@ void STLGeometry :: RestrictHChartDistOneChart(int chartnum, Array<int>& acttrig
}
int STLMeshingDummy (STLGeometry* stlgeometry, Mesh*& mesh, MeshingParameters & mparam,
int STLMeshingDummy (STLGeometry* stlgeometry, shared_ptr<Mesh> & 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>();
mesh->geomtype = Mesh::GEOM_STL;
mesh -> SetGlobalH (mparam.maxh);