pickling.py
Go to the documentation of this file.
1 import unittest
2 from test_case import TestCase
3 import hppfcl
4 
5 import pickle
6 import numpy as np
7 
8 
9 def tetahedron():
10  pts = hppfcl.StdVec_Vec3f()
11  pts.append(np.array((0, 0, 0)))
12  pts.append(np.array((0, 1, 0)))
13  pts.append(np.array((1, 0, 0)))
14  pts.append(np.array((0, 0, 1)))
15  tri = hppfcl.StdVec_Triangle()
16  tri.append(hppfcl.Triangle(0, 1, 2))
17  tri.append(hppfcl.Triangle(0, 1, 3))
18  tri.append(hppfcl.Triangle(0, 2, 3))
19  tri.append(hppfcl.Triangle(1, 2, 3))
20  return hppfcl.Convex(pts, tri)
21 
22 
24  def pickling(self, obj):
25  with open("save.p", "wb") as f:
26  pickle.dump(obj, f)
27  with open("save.p", "rb") as f:
28  obj2 = pickle.load(f)
29 
30  self.assertTrue(obj == obj2)
31 
32  def test_all_shapes(self):
33  box = hppfcl.Box(1.0, 2.0, 3.0)
34  self.pickling(box)
35 
36  sphere = hppfcl.Sphere(1.0)
37  self.pickling(sphere)
38 
39  ellipsoid = hppfcl.Ellipsoid(1.0, 2.0, 3.0)
40  self.pickling(ellipsoid)
41 
42  convex = tetahedron()
43  self.pickling(convex)
44 
45  capsule = hppfcl.Capsule(1.0, 2.0)
46  self.pickling(capsule)
47 
48  cylinder = hppfcl.Cylinder(1.0, 2.0)
49  self.pickling(cylinder)
50 
51  plane = hppfcl.Plane(np.array([0.0, 0.0, 1.0]), 2.0)
52  self.pickling(plane)
53 
54  half_space = hppfcl.Halfspace(np.array([0.0, 0.0, 1.0]), 2.0)
55  self.pickling(half_space)
56 
57 
58 if __name__ == "__main__":
59  unittest.main()
pickling.TestGeometryPickling
Definition: pickling.py:23
pickling.tetahedron
def tetahedron()
Definition: pickling.py:9
pickling.TestGeometryPickling.test_all_shapes
def test_all_shapes(self)
Definition: pickling.py:32
pickling.TestGeometryPickling.pickling
def pickling(self, obj)
Definition: pickling.py:24
test_case.TestCase
Definition: test_case.py:5


hpp-fcl
Author(s):
autogenerated on Fri Aug 2 2024 02:45:14