DFCloudMeshDistance component

Contents

_images/icon4.png

DFCloudMeshDistance component#

Computes the distance between a point cloud and a mesh

Inputs:

i_cloud_source (pointcloud ,list)

The source point cloud.

i_assembly (ghdoc ,item)

The target DFAssembly

i_signed_flag (bool ,item)

whether to consider the sign of the distances

i_swap (bool ,item)

whether to swap source and target

i_analysis_resolution (float ,item)

the maximum edge length of the mesh that is used for the distance calculation

Outputs:

o_distances

list of calculated distances for each point of the source.

o_rmse

average squared difference between source and target.

o_max_deviation

max deviation between source and target

o_min_deviation

min deviation between source and target

o_std_deviation

standard deviation between source and target.

o_result

The result of the distance calculation.

Code:

#! python3

import System

import Rhino
from ghpythonlib.componentbase import executingcomponent as component
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML

import diffCheck
from diffCheck import df_cvt_bindings
from diffCheck import df_error_estimation


class DFCloudMeshDistance(component):
    def RunScript(self,
            i_cloud_source: System.Collections.Generic.List[Rhino.Geometry.PointCloud],
            i_assembly,
            i_signed_flag: bool,
            i_swap: bool,
            i_analysis_resolution: float):

        if i_analysis_resolution is None:
            scalef = diffCheck.df_util.get_doc_2_meters_unitf()
            i_analysis_resolution = 0.1 / scalef

        # Based on cloud source input + beam size, decide whether to calculate joints or entire assembly and output respective message
        if len(i_assembly.beams) == len(i_cloud_source):
            ghenv.Component.Message = "Per Beam"  # noqa: F821
            rh_mesh_target_list = [beam.to_mesh(i_analysis_resolution) for beam in i_assembly.beams]
        elif len(i_assembly.all_joints) == len(i_cloud_source):
            ghenv.Component.Message = "Per Joint"  # noqa: F821
            rh_mesh_target_list = [joint.to_mesh(i_analysis_resolution) for joint in i_assembly._all_joints]
        else:
            ghenv.Component.AddRuntimeMessage(RML.Warning, "The input number of objects to compare matches neither the number of beams nor the number of joints")  # noqa: F821
            return None, None, None, None, None, None

        # conversion
        df_cloud_source_list = [df_cvt_bindings.cvt_rhcloud_2_dfcloud(i_cl_s) for i_cl_s in i_cloud_source]


        # calculate distances
        o_result = df_error_estimation.df_cloud_2_rh_mesh_comparison(df_cloud_source_list, rh_mesh_target_list, i_signed_flag, i_swap)

        return o_result.distances, o_result.distances_rmse, o_result.distances_max_deviation, o_result.distances_min_deviation, o_result.distances_sd_deviation, o_result