Skip to content

Commit

Permalink
demo ready
Browse files Browse the repository at this point in the history
  • Loading branch information
jsdbroughton committed Nov 13, 2023
1 parent 2396810 commit d56282a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
6 changes: 4 additions & 2 deletions Geometry/clash.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def check_for_clash(
Returns:
Tuple[str, str, float]: A tuple containing the IDs of the clashing elements and the severity, if a clash is found.
"""

for ref_mesh in ref_element.meshes:
for latest_mesh in latest_element.meshes:
ref_pymesh = cast(ref_mesh, pymesh.Mesh)
Expand All @@ -84,8 +85,6 @@ def check_for_clash(

intersection = pymesh.boolean(latest_pymesh, ref_pymesh, operation="intersection")

print(f"intersection: {intersection}")

if intersection and intersection.volume > 0:
severity = intersection.volume / min(
ref_pymesh.volume, latest_pymesh.volume
Expand Down Expand Up @@ -129,6 +128,9 @@ def detect_and_report_clashes(
tolerance: float,
automate_context: AutomationContext,
) -> list[tuple[str, str, float]]:
print(f"{len(reference_elements[0].meshes)} reference meshes")
print(f"{len(latest_elements[0].meshes)} latest meshes")

clashes = detect_clashes(reference_elements, latest_elements, tolerance)

total_clashes = len(clashes)
Expand Down
12 changes: 9 additions & 3 deletions Geometry/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def pymesh_to_trimesh(mesh: pymesh.Mesh) -> trimesh.Trimesh:


def cast(
mesh: Union[trimesh.Trimesh, pymesh.Mesh], target_type: Type
mesh: Union[trimesh.Trimesh, pymesh.Mesh], target_type: Type
) -> Union[trimesh.Trimesh, pymesh.Mesh]:
"""
Casts a mesh object to a specified type.
Expand Down Expand Up @@ -70,7 +70,7 @@ def speckle_mesh_to_trimesh(input_mesh: SpeckleMesh) -> trimesh.Trimesh:
face_vertex_count = input_mesh.faces[i]
i += 1 # Skip the vertex count

face_vertex_indices = input_mesh.faces[i : i + face_vertex_count]
face_vertex_indices = input_mesh.faces[i: i + face_vertex_count]

face_vertices = [
Vector.from_list(vertices[idx].tolist()) for idx in face_vertex_indices
Expand All @@ -86,4 +86,10 @@ def speckle_mesh_to_trimesh(input_mesh: SpeckleMesh) -> trimesh.Trimesh:

i += face_vertex_count

return trimesh.Trimesh(vertices=vertices, faces=np.array(faces))
t_mesh = trimesh.Trimesh(vertices=vertices, faces=np.array(faces))

obbox = t_mesh.bounding_box_oriented

obbox_mesh = obbox.to_mesh()

return obbox_mesh
11 changes: 8 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ def automate_function(
changed_model_version = automate_context.receive_version()

try:
reference_model_version = get_reference_model(
reference_model_version, reference_model_id, reference_model_version_id = get_reference_model(
automate_context, function_inputs.static_model_name
)
print(f"Reference model id: {reference_model_id}, version id: {reference_model_version_id}")

except Exception as ex:
automate_context.mark_run_failed(status_message=str(ex))
Expand Down Expand Up @@ -164,14 +165,18 @@ def automate_function(
f"{percentage_latest_objects_clashing}%."
)

reference_view = [f"{reference_model_id}@{reference_model_version_id}"]

automate_context.set_context_view(reference_view)

automate_context.mark_run_success(
status_message="Clash detection completed. " + clash_report_message
)


def get_reference_model(
automate_context: AutomationContext, static_model_name: str
) -> Base:
) -> tuple[Base, Optional[str], Optional[str]]:
# the static reference model will be retrieved from the project using model name stored in the inputs
speckle_client = automate_context.speckle_client
project_id = automate_context.automation_run_data.project_id
Expand Down Expand Up @@ -205,7 +210,7 @@ def get_reference_model(
remote_transport,
) # receive the static model

return latest_reference_model_version
return latest_reference_model_version, model.id, reference_model_commits[0].id


# make sure to call the function with the executor
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ readme = "README.md"
python = "^3.10"
specklepy = "2.17.11"
trimesh = "^4.0.4"
pytest = "^7.4.2"
python-dotenv = "^1.0.0"

[tool.poetry.group.dev.dependencies]
black = "^23.3.0"
mypy = "^1.3.0"
ruff = "^0.0.271"
pytest = "^7.4.2"
python-dotenv = "^1.0.0"

[build-system]
requires = ["poetry-core"]
Expand Down
10 changes: 5 additions & 5 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ def test_object() -> Base:
# fixture to mock the AutomationRunData that would be generated by a full Automation Run
def fake_automation_run_data(request, test_client: SpeckleClient) -> AutomationRunData:
server_url = request.config.SPECKLE_SERVER_URL
project_id = "7d8e96669a"
model_id = "efeb71387b"
project_id = "4f064f09e6"
model_id = "5a16cf52af"

function_name = "Clash Test"

automation_id = crypto_random_string(10)
automation_name = "Local Test Automation"
automation_name = "Long running clash test"
automation_revision_id = crypto_random_string(10)

register_new_automation(
Expand All @@ -119,7 +119,7 @@ def fake_automation_run_data(request, test_client: SpeckleClient) -> AutomationR
project_id=project_id,
model_id=model_id,
branch_name="main",
version_id="3f13306ed2",
version_id="861bbab860",
speckle_server_url=server_url,
# These ids would be available with a valid registered Automation definition.
automation_id=automation_id,
Expand All @@ -142,7 +142,7 @@ def test_function_run(fake_automation_run_data: AutomationRunData, speckle_token
context,
automate_function,
FunctionInputs(
tolerance=0.1, tolerance_unit="mm", static_model_name="simple beams"
tolerance=0.1, tolerance_unit="mm", static_model_name="structures from revit"
),
)

Expand Down

0 comments on commit d56282a

Please sign in to comment.