Skip to content

Commit

Permalink
WIP: starting to wrap global registrations
Browse files Browse the repository at this point in the history
  • Loading branch information
9and3 committed May 2, 2024
1 parent a2f6f1a commit e8f6cd7
Show file tree
Hide file tree
Showing 7 changed files with 650 additions and 313 deletions.
45 changes: 45 additions & 0 deletions src/gh/components/DF_global_registration/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#! python3

import System
import typing

import Rhino
import Rhino.Geometry as rg
from ghpythonlib.componentbase import executingcomponent as component

import Grasshopper as gh
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML

import diffCheck
from diffCheck import diffcheck_bindings
import diffCheck.df_cvt_bindings


class DFGlobalRegistration(component):
def RunScript(self,
i_mesh: rg.Mesh,
i_points: int) -> rg.PointCloud:
"""
Convert a Rhino mesh to a cloud.
:param i_mesh: mesh to convert
:param i_points: number of points to sample
:return o_cloud: rhino cloud
"""

diffCheck.df_cvt_bindings.test()

df_mesh = diffCheck.df_cvt_bindings.cvt_rhmesh_2_dfmesh(i_mesh)
df_cloud = df_mesh.sample_points_uniformly(i_points)

# convert the df_cloud to a rhino cloud
rgpoints = [rg.Point3d(pt[0], pt[1], pt[2]) for pt in df_cloud.points]
rh_cloud = rg.PointCloud(rgpoints)

return [rh_cloud]


if __name__ == "__main__":
com = DFGlobalRegistration()
com.RunScript(i_mesh, i_points)
Binary file added src/gh/components/DF_global_registration/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions src/gh/components/DF_global_registration/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "DFMeshToCloud",
"nickname": "Geo2Pcd",
"category": "diffCheck",
"subcategory": "Cloud",
"description": "Sample a point cloud from a mesh.",
"exposure": 4,
"instanceGuid": "e8e5e122-40d0-45cd-9f93-cc756fd8b307",
"ghpython": {
"hideOutput": true,
"hideInput": true,
"isAdvancedMode": true,
"marshalOutGuids": true,
"iconDisplay": 2,
"inputParameters": [
{
"name": "i_mesh",
"nickname": "i_mesh",
"description": "Mesh to sample into a point cloud.",
"optional": true,
"allowTreeAccess": true,
"showTypeHints": true,
"scriptParamAccess": "item",
"wireDisplay": "default",
"sourceCount": 0,
"typeHintID": "mesh"
},
{
"name": "i_points",
"nickname": "i_points",
"description": "The number of points of the created cloud.",
"optional": false,
"allowTreeAccess": true,
"showTypeHints": true,
"scriptParamAccess": "item",
"wireDisplay": "default",
"sourceCount": 0,
"typeHintID": "int"
}
],
"outputParameters": [
{
"name": "o_rh_cloud",
"nickname": "o_rh_cloud",
"description": "The output sampled cloud.",
"optional": false,
"sourceCount": 0,
"graft": false
}
]
}
}
Binary file not shown.
1 change: 0 additions & 1 deletion src/gh/diffCheck/diffCheck/df_geometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import diffCheck.df_joint_detector


@dataclass
class DFVertex:
"""
Expand Down
87 changes: 75 additions & 12 deletions src/gh/diffCheck/diffCheck_app.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,88 @@
#! python3

import Rhino
import Rhino.Geometry as rg

import os
import System
import typing



import sys

# Get the directory containing the script file
script_dir = os.path.dirname(os.path.realpath(__file__))

# Construct absolute paths
path1 = os.path.join(script_dir, "src", "gh", "diffCheck", "diffCheck")
path2 = os.path.join(script_dir, "src", "gh", "diffCheck")

# Add the paths to sys.path
sys.path.append(path1)
sys.path.append(path2)

# for p in sys.path:
# print(p)

# modules = [diffCheck, diffCheck.df_cvt_bindings]
# for module in modules:
# importlib.reload(module)

# packages_2_reload = ["diffCheck"]
# for package in packages_2_reload:
# for key in list(sys.modules.keys()):
# if package in key:
# importlib.reload(sys.modules[key])

# if packages_2_reload is not None:
# if packages_2_reload.__len__() != 0:
# print("Reloading packages")
# for package in packages_2_reload:
# for key in list(sys.modules.keys()):
# if package in key:
# print(sys.modules[key])
# #check that the package must have the attribute __path__
# if hasattr(sys.modules[key], '__file__'):
# print(sys.modules[key])
# importlib.reload(sys.modules[key])

import Rhino
import Rhino.Geometry as rg
from ghpythonlib.componentbase import executingcomponent as component

import Grasshopper as gh
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML

import diffCheck
from diffCheck import diffcheck_bindings
import diffCheck.df_geometries

import diffCheck.df_cvt_bindings





class DFMeshToCloud(component):
def RunScript(self,
i_mesh: rg.Mesh,
i_points: int) -> rg.PointCloud:
"""
Convert a Rhino mesh to a cloud.
:param i_mesh: mesh to convert
:param i_points: number of points to sample
:return o_cloud: rhino cloud
"""


diffCheck.df_cvt_bindings.test()
# diffCheck.df_geometries.test()


df_mesh = diffCheck.df_cvt_bindings.cvt_rhmesh_2_dfmesh(i_mesh)
df_cloud = df_mesh.sample_points_uniformly(i_points)

# convert the df_cloud to a rhino cloud
rgpoints = [rg.Point3d(pt[0], pt[1], pt[2]) for pt in df_cloud.points]
rh_cloud = rg.PointCloud(rgpoints)

return [rh_cloud]


if __name__ == "__main__":
# print("Hello from diffCheck_assspp.py")
# diffCheck.df_cvt_bindings.test()
pass
com = DFMeshToCloud()
com.RunScript(i_mesh, i_points)
Loading

0 comments on commit e8f6cd7

Please sign in to comment.