コード例 #1
0
ファイル: test_stats.py プロジェクト: admesh/python-admesh
 def test_add_facets_updates_stats(self):
     '''Tests if adding new facets updates the mesh stats'''
     stl = Stl(asset('block.stl'))
     max_x = stl.stats['max']['x']
     bounding_diameter = stl.stats['bounding_diameter']
     stl.add_facets([(((0, 0, 0), (1, 1, 1), (max_x + 1, 0, 0)), (1, 0, 0))])
     assert max_x + 1 == stl.stats['max']['x']
     assert bounding_diameter < stl.stats['bounding_diameter']
コード例 #2
0
 def test_add_facets_updates_stats(self):
     '''Tests if adding new facets updates the mesh stats'''
     stl = Stl(asset('block.stl'))
     max_x = stl.stats['max']['x']
     bounding_diameter = stl.stats['bounding_diameter']
     stl.add_facets([(((0, 0, 0), (1, 1, 1), (max_x + 1, 0, 0)), (1, 0, 0))
                     ])
     assert max_x + 1 == stl.stats['max']['x']
     assert bounding_diameter < stl.stats['bounding_diameter']
コード例 #3
0
ファイル: test_io.py プロジェクト: sushantjha8/python-admesh
 def test_saved_equals_original_binary(self):
     '''Tests if saved binary file is identical to the loaded one'''
     stl1 = Stl(asset('block.stl'))
     stl1.write_binary(asset('block_binary.stl'))
     stl2 = Stl(asset('block_binary.stl'))
     stl2.write_binary(asset('block_binary2.stl'))
     assert filecmp.cmp(asset('block_binary.stl'), asset('block_binary2.stl'))
コード例 #4
0
 def test_list_from_stl(self):
     '''Tests if list(stl) returns all the facets'''
     stl = Stl(asset('block.stl'))
     facets = list(stl)
     assert len(facets) == 12
     assert len(facets[0]['vertex']) == 3
     assert facets[0]['vertex'][0]['x'] == 0
コード例 #5
0
ファイル: test_stats.py プロジェクト: admesh/python-admesh
 def test_stats_are_same_with_created(self, type):
     ''''Test a manually constructed cube has the same stats as if loaded'''
     XYZ = ('x', 'y', 'z')
     stl1 = Stl(asset('block.stl'))
     if type == 'iterable':
         facets = [[[[v[a] for a in XYZ] for v in f['vertex']],
                    [f['normal'][a] for a in XYZ]] for f in stl1]
     else:
         facets = list(stl1)
     stl2 = Stl()
     stl2.add_facets(facets)
     stats1, stats2 = stl1.stats, stl2.stats
     for stats in (stats1, stats2):
         del stats['type']  # ASCII != INMEMORY
         del stats['original_num_facets']  # 12 != 0
         del stats['header']  # nothing != "solid  admesh"
     assert stats1 == stats2
コード例 #6
0
 def test_stats_are_same_with_created(self, type):
     ''''Test a manually constructed cube has the same stats as if loaded'''
     XYZ = ('x', 'y', 'z')
     stl1 = Stl(asset('block.stl'))
     if type == 'iterable':
         facets = [[[[v[a] for a in XYZ] for v in f['vertex']],
                    [f['normal'][a] for a in XYZ]] for f in stl1]
     else:
         facets = list(stl1)
     stl2 = Stl()
     stl2.add_facets(facets)
     stats1, stats2 = stl1.stats, stl2.stats
     for stats in (stats1, stats2):
         del stats['type']  # ASCII != INMEMORY
         del stats['original_num_facets']  # 12 != 0
         del stats['header']  # nothing != "solid  admesh"
     assert stats1 == stats2
コード例 #7
0
ファイル: test_stats.py プロジェクト: admesh/python-admesh
 def test_write_to_stats(self):
     '''Test if writing to stats raises exception'''
     stl = Stl()
     with pytest.raises(TypeError if pypy2 else AttributeError):
         stl.stats = {}
コード例 #8
0
 def test_volume(self):
     '''Tests the volume of the block'''
     stl = Stl(asset('block.stl'))
     stl.calculate_volume()
     assert stl.stats['volume'] == 1
コード例 #9
0
 def test_saved_binary_is_binary(self):
     '''Tests if saved binary file is identical to the loaded one'''
     stl1 = Stl(asset('block.stl'))
     stl1.write_binary(asset('block_binary.stl'))
     stl2 = Stl(asset('block_binary.stl'))
     assert stl2.stats['type'] == Stl.BINARY
コード例 #10
0
ファイル: feasibility.py プロジェクト: xuy/Feasi3D
def get_volume(stlfile):
  stl = Stl(stlfile)
  stl.check_facets_exact()
  stl.repair()
  return stl.stats['volume']

if __name__ == '__main__':
  # Determines the feasibitily of an STL model

  if len(sys.argv) < 1:
    print "Need at least a file name"
    exit(1)
  print "=" * 80
  print "Analyzing model ", sys.argv[1]
  stl = Stl(sys.argv[1])

  # Although stl_repair provided a function that can repair errors in one shot,
  # it does not give error messages. Here we report each steps.
  tolerance = 0.0000001

  stl.check_facets_exact()

  stats = stl.stats
  if stats['facets_w_1_bad_edge'] > 0 or stats['facets_w_2_bad_edge'] >0 or stats['facets_w_3_bad_edge'] > 0:
    print "Bad edges on facets"

  shortest_edge = stats['shortest_edge']
  if shortest_edge < tolerance:
    print "Edge too short, cannot print"
コード例 #11
0
ファイル: test_io.py プロジェクト: sushantjha8/python-admesh
 def test_saved_equals_original_ascii(self):
     '''Tests if saved ASCII file is identical to the loaded one'''
     stl = Stl(asset('block.stl'))
     stl.write_ascii(asset('block_ascii.stl'))
     assert filecmp.cmp(asset('block.stl'), asset('block_ascii.stl'))
コード例 #12
0
 def test_add_facets_increases_len(self):
     stl = Stl(asset('block.stl'))
     facet_count = len(stl)
     stl.add_facets([(((0, 0, 0), (1, 1, 1), (1, 0, 0)), (1, 0, 0))])
     assert len(stl) == facet_count + 1
コード例 #13
0
 def test_delete_stats(self):
     '''Test if deleting stats raises exception'''
     stl = Stl()
     with pytest.raises(AttributeError):
         del stl.stats
コード例 #14
0
 def test_write_to_stats(self):
     '''Test if writing to stats raises exception'''
     stl = Stl()
     with pytest.raises(TypeError if pypy2 else AttributeError):
         stl.stats = {}
コード例 #15
0
 def test_header(self):
     '''Tests the header of the block'''
     stl = Stl(asset('block.stl'))
     assert stl.stats['header'] == 'solid  admesh'.encode('UTF-8')
コード例 #16
0
 def test_emtpy_stl_has_0_len(self):
     '''Test if newly created Stl has len() == 0'''
     stl = Stl()
     assert len(stl) == 0
コード例 #17
0
ファイル: test_io.py プロジェクト: sushantjha8/python-admesh
 def test_save_load_unicode(self):
     '''Tests saving and loading files with Unicode filenames'''
     stl1 = Stl(asset('block.stl'))
     stl1.write_ascii(asset(u'block_ěščřž.stl'))
     stl2 = Stl(asset(u'block_ěščřž.stl'))
コード例 #18
0
 def test_str(self):
     '''Tests the output of str'''
     stl = Stl(asset('block.stl'))
     assert str(stl) == "Stl('admesh')"
コード例 #19
0
ファイル: test.py プロジェクト: xuy/Feasi3D
import pprint

admesh_lib_path = '/usr/local/lib'
if admesh_lib_path not in sys.path:
	sys.path.append(admesh_lib_path)
from admesh import Stl

errors = {
	'Error',
}

# Determines the feasibitily of an STL model
if len(sys.argv) < 1:
    print "Need at least a file name"
    exit(1)
stl = Stl(sys.argv[1])

# Although stl_repair provided a function that can repair errors in one shot,
# it does not give error messages. Here we report each steps.
tolerance = 0.0000001

pprint.pprint(stl.stats)
stl.check_facets_exact()
pprint.pprint(stl.stats)

stats = stl.stats
if stats['facets_w_1_bad_edge'] > 0 or stats['facets_w_2_bad_edge'] >0 or stats['facets_w_3_bad_edge'] > 0:
	print "Bad edges on facets"

shortest_edge = stats['shortest_edge']
if shortest_edge < tolerance:
コード例 #20
0
 def test_len_is_number_of_facets(self):
     '''Tests if len() of Stl object is number of factes'''
     stl = Stl(asset('block.stl'))
     assert len(stl) == 12
コード例 #21
0
ファイル: feasibility.py プロジェクト: xuy/Feasi3D
def get_volume(stlfile):
  stl = Stl(stlfile)
  stl.check_facets_exact()
  stl.repair()
  return stl.stats['volume']
コード例 #22
0
ファイル: test_stats.py プロジェクト: admesh/python-admesh
 def test_volume(self):
     '''Tests the volume of the block'''
     stl = Stl(asset('block.stl'))
     stl.calculate_volume()
     assert stl.stats['volume'] == 1
コード例 #23
0
 def test_ascii_is_ascii(self):
     '''Tests if loaded ASCII file is recognized as ASCII'''
     stl = Stl(asset('block.stl'))
     assert stl.stats['type'] == Stl.ASCII
コード例 #24
0
 def test_number_of_facets(self):
     '''Tests if block has 12 facets'''
     stl = Stl(asset('block.stl'))
     assert stl.stats['number_of_facets'] == 12