Commit a458ade3 authored by Daniel Boeckenhoff's avatar Daniel Boeckenhoff
Browse files

baffle.stl file added

parent 0abc50aa
File added
import tfields
import numpy as np
from import x, y
import unittest
from tempfile import NamedTemporaryFile
import pickle
import sympy # NOQA: F401
ATOL = 1e-8
......@@ -42,12 +38,18 @@ class Base_Check(object):
self.assertTrue(self._inst.equal(transformer, atol=ATOL))
def test_basic_merge(self):
# create 3 copies with different coord_sys
from IPython import embed; embed()
merge_list = [self._inst.copy() for i in range(3)]
# merge them and check that the first coord_sys is taken
obj = type(self._inst).merged(*merge_list)
self.assertTrue(obj.coord_sys == tfields.bases.CARTESIAN)
# check that all copies are the same also with new coord_sys
for i in range(len(merge_list)):
value = np.allclose(merge_list[0],
obj[i * len(self._inst): (i + 1) *
......@@ -68,8 +70,10 @@ class Base_Check(object):
reloaded = pickle.load(out_file)
reloaded = pickle.load(open(, 'rb'))
def tearDown(self):
......@@ -22,6 +22,15 @@ class Sphere_Test(Base_Check, unittest.TestCase):
def test_cut_split(self):
x, y, z = sympy.symbols('x y z')
halfed = self._inst.cut(x + 1./100*y > 0, at_intersection='split')
class IO_test(Base_Check, unittest.TestCase):
class IO_Stl_test(IO_test):
def setUp(self):
self._inst = tfields.Mesh3D.load(r'../data/baffle.stl')
if __name__ == '__main__':
\ No newline at end of file
......@@ -21,6 +21,7 @@ import numpy as np
import sympy
import scipy as sp
import tfields.bases
from nltk.misc.chomsky import objects
np.seterr(all='warn', over='raise')
......@@ -1524,8 +1525,10 @@ class TensorFields(Tensors):
def merged(cls, *objects, **kwargs):
if not all([isinstance(o, cls) for o in objects]):
types = [type(o) for o in objects]
# TODO: could allow if all faceScalars are none
raise TypeError("Merge constructor only accepts {cls} instances."
"Got objects of types {types} instead."
inst = super(TensorFields, cls).merged(*objects, **kwargs)
......@@ -311,6 +311,17 @@ class Mesh3D(tfields.TensorMaps):
f.write("usemtl mtl_{0}\n".format(last_scalar))
f.write("f {f[0]} {f[1]} {f[2]}\n".format(f=face))
def _load_stl(cls, path):
Factory method
Given a path to a stl file, construct the object
import stl.mesh
mesh = stl.mesh.Mesh.from_file(path)
mesh = cls(vertices, faces=faces)
return mesh
def _load_obj(cls, path, *group_names):
......@@ -113,12 +113,24 @@ class Triangles3D(tfields.TensorFields):
warnings.warn("Index error occured for field.__getitem__. Error "
"message: {err}".format(**locals()))
return item
def _load_stl(cls, path):
Factory method
Given a path to a stl file, construct the object
import stl.mesh
triangles = stl.mesh.Mesh.from_file(path)
obj = cls(triangles.vectors.reshape(-1, 3))
return obj
def merged(cls, *objects, **kwargs):
with warnings.catch_warnings():
obj = super(Triangles3D, cls).merged(cls, *objects, **kwargs)
obj = super(Triangles3D, cls).merged(*objects, **kwargs)
if not len(obj) % 3 == 0:
warnings.warn("Input object of size({0}) has no divider 3 and"
" does not describe triangles."
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment