"""Example script demonstrating generating sample lattice and calculating the realtive denisty and exporting as an STL file
For more details on the available job types please refer to the Metafold REST API
documentation.
"""
import pandas as pd
import numpy as np
import os
import csv
from numpy.typing import ArrayLike
from pprint import pprint
from scipy.spatial.transform import Rotation as R
from metafold import MetafoldClient
from metafold.func_types import JSONEvaluator, FuncType, Vec3f, Mat4f
from metafold.func import *
project_id = 5701
access_token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImpXbmtDVTRzMFpRc0xkM1lSalFpdiJ9.eyJpc3MiOiJodHRwczovL21ldGFmb2xkM2QudXMuYXV0aDAuY29tLyIsInN1YiI6Imdvb2dsZS1vYXV0aDJ8MTE1NDEyMzQzMzA0MjMzNjcyMDI1IiwiYXVkIjpbImh0dHBzOi8vYXBpLm1ldGFmb2xkM2QuY29tLyIsImh0dHBzOi8vbWV0YWZvbGQzZC51cy5hdXRoMC5jb20vdXNlcmluZm8iXSwiaWF0IjoxNzIzNzI5NzE5LCJleHAiOjE3MjM4MTYxMTksInNjb3BlIjoib3BlbmlkIHByb2ZpbGUgZW1haWwgYXNzZXRzOnJlYWQgYXNzZXRzOndyaXRlIGpvYnM6cmVhZCBqb2JzOndyaXRlIHByb2plY3RzOnJlYWQgcHJvamVjdHM6d3JpdGUgdHJhbnNwb3J0IG9mZmxpbmVfYWNjZXNzIiwiYXpwIjoieFYxWE9SemNGVkVRUlh0NzhVOHJqdHB2QzV6Wm1SelIifQ.2FUdPBl-3qb1QaSI9wDM_LQEKEbTiH6qMGio1ASKYmSgv-2O-T3D_TncPheHxeSTLGrRpHl5A8I7ceacYnuowU-nwnXlX_JO_fXDkqT--5xXHWH1tKTxVjAYaJJUx_KHUKZ_HV8tj4aPs2Ci1jU-ulbj-uLu4kgEEJzgLfjH2w-F4X_nDBXdxyVs0t1cMQJ3kkm36THmtqJ5NY7iMknVZZPtKxA95GFJ4CGENZ7eeqDbadRnuF8w_l2gxjvvhrHm-qW68TtIxdybz0wK5cROHYzKmYcWT_2zgohDA9TFr9jpzArkz2Iv8j76vYROc3B9UeTuNqL0oyYbHgYB6i3cpw"
client=MetafoldClient(access_token,project_id)
source = GenerateSamplePoints(
{"offset": [
-15,
-15,
0
],
"size": [
30,
30,
30
],
"resolution": [
128,
128,
128
]
}
)
bcc_params= {
"lattice_data" : {
"edges": [
[
0,
7
],
[
4,
7
],
[
1,
7
],
[
2,
7
],
[
5,
7
],
[
6,
7
],
[
3,
7
],
[
7,
8
]
],
"nodes": [
[
0,
0,
0
],
[
0,
1,
0
],
[
1,
0,
0
],
[
1,
1,
0
],
[
0,
0,
1
],
[
0,
1,
1
],
[
1,
0,
1
],
[
0.5,
0.5,
0.5
],
[
1,
1,
1
]
]
},
"section_radius" : 0.1,
"scale": [5, 5, 5]
}
shape_func= Threshold(
Redistance(
SampleLattice(source, parameters=bcc_params)
),
{
"width": 0.03,
},
)
evaluator = JSONEvaluator(source)
shape_func(evaluator)
graph_json=evaluator.json()
job= client.jobs.run("evaluate_metrics", {"graph": graph_json, "point_source": 0})
pprint((job.meta["relative_density"]))
export_job = client.jobs.run("export_triangle_mesh", {
"graph": graph_json,
"point_source": 0,
})
export_asset = export_job.assets[0].id
client.assets.download_file(export_asset, "bcc.stl")