Skip to content

Instantly share code, notes, and snippets.

Created August 25, 2017 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4f51813a9cc17ce5fcdb465c30a25a61 to your computer and use it in GitHub Desktop.
Save anonymous/4f51813a9cc17ce5fcdb465c30a25a61 to your computer and use it in GitHub Desktop.
Part comparison script for Materialise 3-matic
# This script will compare two objects and see if they are similar or not. This is especially useful when setting up a validation environment.
# Input: String name of the two objects which you would like to compare: object_a and object_b
# Output: Logger messages with the outcome of the part comparison.
# The tool compares the following criteria:
# The tool compares the following criteria:
# - Surface area, volume, amount of nodes, amount of triangles
# - It compares the x,y,z coordinate of the nodes with the same index
# - It compares if each triangle is referring to the same node number.
# Author: Kristof Godelaine (Materialise)
# Version: 1.0 (25 Aug 2017)
def compare_part(object_a, object_b):
name_part_a = object_a
name_part_b = object_b
#find parts in the object tree
part_a = trimatic.find_part(name_part_a)
part_b = trimatic.find_part(name_part_b)
#list for the part comparison outcome
part_comp_list = {'surf_area': 'not performed','volume': 'not performed','num_points': 'not performed', 'num_triangles': 'not performed', 'node_comparison': 'not performed', 'triangles_comparison': 'not performed'}
#get nodes and triangles of the parts
[points_a, triangles_a] = part_a.get_triangles()
[points_b, triangles_b] = part_b.get_triangles()
#Check surface area
if part_a.surface_area == part_b.surface_area:
part_comp_list['surf_area'] = 'pass'
else:
part_comp_list['surf_area'] = 'fail'
#Check volume
if part_a.volume == part_b.volume:
part_comp_list['volume'] = 'pass'
else:
part_comp_list['volume'] = 'fail'
#check number of nodes
if len(points_a) == len(points_b):
part_comp_list['num_points'] = 'pass'
else:
part_comp_list['num_points'] = 'fail'
#check number of triangles
if len(triangles_a) == len(triangles_b):
part_comp_list['num_triangles'] = 'pass'
else:
part_comp_list['num_triangles'] = 'fail'
#Compare each node of two parts
for i in range(0,len(points_a)):
xa = points_a[i][0]
ya = points_a[i][1]
za = points_a[i][2]
xb = points_b[i][0]
yb = points_b[i][1]
zb = points_b[i][2]
if xa != xb:
part_comp_list['node_comparison'] = 'fail'
break
elif ya != yb:
part_comp_list['node_comparison'] = 'fail'
break
elif za != zb:
part_comp_list['node_comparison'] = 'fail'
break
else:
part_comp_list['node_comparison'] = 'pass'
#Compare elements of two parts
for i in range(0,len(triangles_a)):
xa = triangles_a[i][0]
ya = triangles_a[i][1]
za = triangles_a[i][2]
xb = triangles_b[i][0]
yb = triangles_b[i][1]
zb = triangles_b[i][2]
if xa != xb:
part_comp_list['triangles_comparison'] = 'fail'
break
elif ya != yb:
part_comp_list['triangles_comparison'] = 'fail'
break
elif za != zb:
part_comp_list['triangles_comparison'] = 'fail'
break
else:
part_comp_list['triangles_comparison'] = 'pass'
###
#print results
print("----------------------------------")
print("----------------------------------")
print("Part comparison outcome")
print("----------------------------------")
print("-surf_area: "+ part_comp_list['surf_area'])
print("-volume: "+ part_comp_list['volume'])
print("-num_points: "+ part_comp_list['num_points'])
print("-num_triangles: "+ part_comp_list['num_triangles'])
print("-node_comparison: "+ part_comp_list['node_comparison'])
print("-triangles_comparison: "+ part_comp_list['triangles_comparison'])
print("----------------------------------")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment