------------------------------------------------------------
revno: 3843
committer: Jan Stransky <[email protected]>
timestamp: Fri 2016-04-15 11:52:40 +0200
message:
Polyhedra.setVertices improvement, preventing memory leaks (question #290947
and bug #1570679)
modified:
pkg/dem/Polyhedra.cpp
pkg/dem/Polyhedra.hpp
--
lp:yade
https://code.launchpad.net/~yade-pkg/yade/git-trunk
Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to
https://code.launchpad.net/~yade-pkg/yade/git-trunk/+edit-subscription
=== modified file 'pkg/dem/Polyhedra.cpp'
--- pkg/dem/Polyhedra.cpp 2016-04-13 16:42:10 +0000
+++ pkg/dem/Polyhedra.cpp 2016-04-15 09:52:40 +0000
@@ -154,6 +154,22 @@
init = 1;
}
+void Polyhedra::setVertices(const std::vector<Vector3r>& v) {
+ init = false;
+ this->v = v;
+ Initialize();
+}
+
+void Polyhedra::setVertices4(const Vector3r& v0, const Vector3r& v1,const Vector3r& v2,const Vector3r& v3) {
+ init = false;
+ v.resize(4);
+ v[0] = v0;
+ v[1] = v1;
+ v[2] = v2;
+ v[3] = v3;
+ Initialize();
+}
+
//**************************************************************************
/* Generator of randomly shaped polyhedron based on Voronoi tessellation*/
=== modified file 'pkg/dem/Polyhedra.hpp'
--- pkg/dem/Polyhedra.hpp 2016-04-13 16:42:10 +0000
+++ pkg/dem/Polyhedra.hpp 2016-04-15 09:52:40 +0000
@@ -72,7 +72,8 @@
Quaternionr GetOri(){Initialize(); return orientation;}
Polyhedron GetPolyhedron(){return P;};
void Clear(){v.clear(); P.clear(); init = 0; size = Vector3r(1.,1.,1.); faceTri.clear();};
- void setVertices(const std::vector<Vector3r>& v) { init=false; this->v=v; Initialize(); }
+ void setVertices(const std::vector<Vector3r>& v);
+ void setVertices4(const Vector3r& v0, const Vector3r& v1,const Vector3r& v2,const Vector3r& v3);
protected:
//triangulation of facets for plotting
@@ -106,7 +107,8 @@
.def("GetCentroid",&Polyhedra::GetCentroid,"return polyhedra's centroid")
.def("GetSurfaceTriangulation",&Polyhedra::GetSurfaceTriangulation,"triangulation of facets (for plotting)")
.def("GetSurfaces",&Polyhedra::GetSurfaces,"get indices of surfaces' vertices (for postprocessing)")
- .def("setVertices",&Polyhedra::setVertices,"set vertices and update receiver")
+ .def("setVertices",&Polyhedra::setVertices,"set vertices and update receiver. Takes a list/tuple of vertices as argument.\n\n.. note:: Causes memory leaks, so if you want to use it maaaany times, use one of setVertices mentioned lower, passing each vertex as individual argument (currently only setVertices(v1,v2,v3,v4) for tetrahedron is implemented, on request it is easy to implement more vertices).")
+ .def("setVertices",&Polyhedra::setVertices4,"set 4 vertices and update receiver. Each vertex is single argument.")
);
REGISTER_CLASS_INDEX(Polyhedra,Shape);
};
_______________________________________________
Mailing list: https://launchpad.net/~yade-dev
Post to : [email protected]
Unsubscribe : https://launchpad.net/~yade-dev
More help : https://help.launchpad.net/ListHelp