Commit cb10bc49 authored by dboe's avatar dboe
Browse files

stl and test_mesh; added mesh retrieval for triangles3D

parent 4f46ffdf
......@@ -4,9 +4,10 @@ import unittest
import sympy # NOQA: F401
import os
import sys
THIS_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(THIS_DIR)))
from test_core import Base_Check
THIS_DIR = os.path.dirname(
os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(THIS_DIR)))
class Sphere_Test(Base_Check, unittest.TestCase):
......@@ -21,16 +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):
pass
self._inst.cut(x + 1./100*y > 0, at_intersection='split')
class IO_Stl_test(IO_test):
class IO_Stl_test(unittest.TestCase):
def setUp(self):
self._inst = tfields.Mesh3D.load(r'../data/baffle.stl')
self._inst = tfields.Mesh3D.load(os.path.join(THIS_DIR,
'../data/baffle.stl'))
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
tfields.Mesh3D.load(os.path.join(THIS_DIR,'../data/baffle.stl'))
unittest.main()
......@@ -67,7 +67,7 @@ class cached_property(object):
def parametrized(dec):
"""
possibility to parametrize a decorytor
possibility to parametrize a decorator
"""
def layer(*args, **kwargs):
def repl(f):
......@@ -103,13 +103,14 @@ def once(method, arg=False):
>>> assert a.foo() # doctest: +ELLIPSIS
Traceback (most recent call last):
...
RuntimeError: Argument once_switch indicates the method has beenrun already
RuntimeError: Argument once_switch indicates the method has been run
already
"""
@functools.wraps(method)
def decorator(self, *args, **kwargs):
if getattr(self, arg):
raise RuntimeError("Argument {arg} indicates the method has been"
raise RuntimeError("Argument {arg} indicates the method has been "
"run already".format(**locals()))
value = method(self, *args, **kwargs)
setattr(self, arg, True)
......
......@@ -318,10 +318,7 @@ class Mesh3D(tfields.TensorMaps):
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
return tfields.Triangles3D.load(path).mesh()
@classmethod
def _load_obj(cls, path, *group_names):
......@@ -515,14 +512,17 @@ class Mesh3D(tfields.TensorMaps):
@cached_property()
def _triangles(self):
"""
with the decorator, this should be handled like an attribute though it is a function
with the decorator, this should be handled like an attribute though it
is a method
"""
if self.faces.size == 0:
return tfields.Triangles3D([])
tris = tfields.Tensors.merged(*[self[mp.flatten()] for mp in self.maps])
tris = tfields.Tensors.merged(*[self[mp.flatten()]
for mp in self.maps])
map_fields = [mp.fields for mp in self.maps]
fields = [tfields.Tensors.merged(*fields) for fields in zip(*map_fields)]
fields = [tfields.Tensors.merged(*fields)
for fields in zip(*map_fields)]
return tfields.Triangles3D(tris, *fields)
def triangles(self):
......
......@@ -113,8 +113,7 @@ class Triangles3D(tfields.TensorFields):
warnings.warn("Index error occured for field.__getitem__. Error "
"message: {err}".format(**locals()))
return item
@classmethod
def _load_stl(cls, path):
"""
......@@ -192,13 +191,22 @@ class Triangles3D(tfields.TensorFields):
>>> assert np.array_equal(tc2.triangleScalars, np.array([[2.]]))
"""
mask = self.evalf(expression, coord_sys=coord_sys)
inst = self[mask].copy()
# inst.triangleScalars =
# inst.triangleScalars[mask.reshape((self.ntriangles(), 3)).T[0]]
# mask = self.evalf(expression, coord_sys=coord_sys)
# inst = self[mask].copy()
# return inst
return super().cut(expression, coord_sys)
return inst
def mesh(self):
"""
Returns:
tfields.Mesh3D
"""
mp = tfields.TensorFields(
np.arange(len(self)).reshape((-1, 3)),
*self.fields)
return tfields.Mesh3D(
self,
maps=[mp]).cleaned()
@cached_property()
def _areas(self):
......@@ -283,7 +291,8 @@ class Triangles3D(tfields.TensorFields):
def circumcenters(self):
"""
Semi baricentric method to calculate circumcenter points of the triangles
Semi baricentric method to calculate circumcenter points of the
triangles
Examples:
>>> m = tfields.Mesh3D([[0,0,0], [1,0,0], [-1,0,0], [0,1,0], [0,0,1]],
......@@ -563,7 +572,7 @@ class Triangles3D(tfields.TensorFields):
# min_dist_method switch if delta is None
if delta is None:
delta = 1.
delta = 1.
min_dist_method = True
else:
min_dist_method = False
......@@ -709,7 +718,7 @@ class Triangles3D(tfields.TensorFields):
Otherwise just pass the weights.
Returns:
TODO: Better docs
"""
# set weights to 1.0 if weights is None
......
Markdown is supported
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