00-box

00-box

"""Example script demonstrating generating primitives and calculating the realtive denisty
"""

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 = "   "
client=MetafoldClient(access_token,project_id)

source = GenerateSamplePoints(       
                              {"offset": [
                                        -1,
                                        -1,
                                        -1
                                        ],
                                        "size": [
                                        2,
                                        2,
                                        2
                                        ],
                                        "resolution": [
                                        256,
                                        256,
                                        256
                                        ]
                              }
                            )

def xform(
    rotation = np.zeros(3),
    translation = np.zeros(3),
    custom: Optional[str] = None,
) -> Mat4f:

    if custom == "Cylinder":
        rotation_ = [rotation[0] + 90, rotation[2], rotation[1]]
    else:
        rotation_ = rotation


    rot = R.from_euler("xyz", rotation_,  degrees=True).as_matrix()
    xform_ = np.eye(4)
    xform_[:3, :3] = rot
    xform_[3, :3] = translation
    return xform_

box_rot = np.array([0, 0.0, 0.0])
box_pos = np.array([0.0, 0.0, 0.0])
box_params = {
    "shape_type": "Box",
    "size": [2, 2, 2],
    "xform": xform(box_rot, box_pos).flatten()
}


shape_func= Threshold(
                Redistance(
                    SampleBox(source, parameters=box_params)
                )
            )    

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"])