Here’s the slow code that multiplies its output cnt (I was just about to try Intersection.LineCylinder
instead of Intersection.CurveBrep
but quickly uncommented it, hopefully it still compiles):
Imports System.Collections.Generic
Imports Grasshopper.Kernel
Imports Rhino.Geometry
Imports Rhino
Namespace RIL.GH.Filters
Public Class RILGH_CylPtInclusionSolver_TMP
Inherits GH_Component
Private m_DA As IGH_DataAccess
''' <summary>
''' Initializes a new instance of the MyComponent1 class.
''' </summary>
Public Sub New()
MyBase.New("Cylinder Point Inclusion Solver", "PtsInCylSolver",
"Tilt or Resize while filtering points inside the bounds of a cylinder.",
"RIL", "Filters")
End Sub
''' <summary>
''' Registers all the input parameters for this component.
''' </summary>
Protected Overrides Sub RegisterInputParams(pManager As GH_Component.GH_InputParamManager)
'// Make default XY plane
Dim XYPLane As Vector3d = New Point3d(0, 0, 10) - New Point3d(0, 0, 0)
'// Register In-ports
pManager.AddPointParameter("Rotation center", "C", "Rotation center.", GH_ParamAccess.item, New Point3d(0, 0, 0))
pManager.AddPointParameter("Cylinder Height & Tilt", "H", "A 3D height-center Point determining the Height and the Inclination of the Cylinder.", GH_ParamAccess.item, New Point3d(0, 0, 10))
pManager.AddNumberParameter("Radius", "R", "Radius of the inclusion Cylinder.", GH_ParamAccess.item, 10)
pManager.AddPointParameter("Point Cloud", "Pts", "Points to test for inclusion.", GH_ParamAccess.list)
pManager.AddNumberParameter("Tolerance", "T", "Tolerance for inclusion test.", GH_ParamAccess.item, 0.01)
pManager.AddBooleanParameter("ON/OFF", "ON", "Activate execution by setting value to True.", GH_ParamAccess.item, False)
pManager.AddGeometryParameter("CoGeo", "CoGeo", "Additional Geometry to be equally Transformed.", GH_ParamAccess.list)
End Sub
''' <summary>
''' Registers all the output parameters for this component.
''' </summary>
Protected Overrides Sub RegisterOutputParams(pManager As GH_Component.GH_OutputParamManager)
pManager.AddPointParameter("Points Inside Box", "BIn", "Points residing inside the Bounding Box.", GH_ParamAccess.list)
pManager.AddPointParameter("Points Outside Box", "BOut", "Points residing outside the Bounding Box.", GH_ParamAccess.list)
pManager.AddPointParameter("Cylinder Center", "CC", "Point in the center of the Cylinder Bounding Box.", GH_ParamAccess.item)
pManager.AddTextParameter("Score", "Score", "Score after several attempts.", GH_ParamAccess.item)
pManager.AddBrepParameter("Brep", "Brep", "Brep for debugging.", GH_ParamAccess.item)
pManager.AddGeometryParameter("TxGeo", "TxGeo", "Co-Transformed geometries.", GH_ParamAccess.list)
End Sub
Private Const IN_C = 0
Private Const IN_H = 1
Private Const IN_R = 2
Private Const IN_Pts = 3
Private Const IN_Tol = 4
Private Const IN_On = 5
Private Const IN_CoGeo = 6
Private Const OUT_BIn = 0
Private Const OUT_BOut = 1
Private Const OUT_CC = 2
Private Const OUT_Score = 3
Private Const OUT_Brep = 4
Private Const OUT_TxGeo = 5
''' <summary>
''' Provides the Inport value of C - Rotation center
''' </summary>
Private Function GetInputC() As Point3d
Dim m_C As New Point3d
If Not m_DA.GetData(IN_C, m_C) Then
Print("# Error - Invalid Point input.")
End If
Return m_C
End Function
''' <summary>
''' Provides the Inport value of C - Rotation center
''' </summary>
Private m_H As New Point3d
Protected Property InH() As Point3d
Get
If Not m_DA.GetData(IN_H, m_H) Then
Print("# Error - Invalid Point input.")
End If
Return m_H
End Get
Set(ByVal value As Point3d)
m_H = value
End Set
End Property
''' <summary>
''' Provides the Inport value of R - Radius
''' </summary>
Private m_R As Double
Protected ReadOnly Property InR() As Double
Get
If Not m_DA.GetData(IN_R, m_R) Then
Print("# Error - Invalid Radius value.")
End If
Return m_R
End Get
End Property
Dim m_Pts As New List(Of Point3d)
Protected ReadOnly Property InPts() As List(Of Point3d)
Get
If Not m_DA.GetDataList(IN_Pts, m_Pts) Then
Print("# Error - Invalid Point cloud input.")
End If
Return m_Pts
End Get
End Property
''' <summary>
''' Provides the Inport value of T - Tolerance
''' </summary>
Private m_T As Single
Protected ReadOnly Property InT() As Single
Get
If Not m_DA.GetData(IN_Tol, m_T) Then
Print("# Error - Invalid Tolerance value.")
End If
Return m_T
End Get
End Property
''' <summary>
''' Disable or Enable Solver Execution
''' </summary>
Dim m_On As Boolean
Protected ReadOnly Property InOn() As Boolean
Get
If Not m_DA.GetData(IN_On, m_On) Then
Print("# Error - Invalid Point cloud input.")
End If
Return m_On
End Get
End Property
''' <summary>
''' Provides the Inport value of CoBreps - A bunch of related breps meant to be equally Transformed
''' </summary>
Private m_CoGeo As New List(Of GeometryBase)
Protected ReadOnly Property InCoGeo() As List(Of GeometryBase)
Get
If Not m_DA.GetDataList(IN_CoGeo, m_CoGeo) Then
Print("# Error - Invalid breps input.")
Return Nothing
End If
Return m_CoGeo
End Get
End Property
''' <summary>
''' Derives an inclination vector (as well as height-) axis based on Center point (C) and Height point (H)
''' </summary>
Private Function ZAxis(ByRef aCenterPt As Point3d, ByRef aHeightPt As Point3d) As Vector3d
Dim v As Vector3d = aHeightPt - aCenterPt
Return v
End Function
''' <summary>
''' Creates a Cylinder at last specified position InC and inclination Plane ( = ZAxis(InH-InC))
''' </summary>
Private Function AsCylinder(ByRef aCenterPt As Point3d, ByRef aHeightPt As Point3d) As Cylinder
Dim zaxis_tmp As Vector3d = ZAxis(aCenterPt, aHeightPt)
Dim plane As New Plane(aCenterPt, zaxis_tmp)
Dim circle As New Circle(plane, InR)
Return New Cylinder(circle, zaxis_tmp.Length)
End Function
Private Function BrepCylinder(ByRef aCenterPt As Point3d, ByRef aHeightPt As Point3d) As Brep
Return AsCylinder(aCenterPt, aHeightPt).ToBrep(True, True)
End Function
''' <summary>
''' This is the method that actually does the work.
''' </summary>
''' <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
Protected Overrides Sub SolveInstance(DA As IGH_DataAccess)
'//
'// Set class wide access to Data Accessor
'//
m_DA = DA
If Not InOn Then Return
'//
'// ANIMATE CYLINDER BREP
'//
Dim tolerance As Single = InT
Dim cp As New Point3d(GetInputC)
Dim hp As New Point3d(InH)
Dim insidePts As New List(Of Point3d)
Dim outsidePts As New List(Of Point3d)
'//
'// AUTO-FIT
'//
Dim cylC As New Point3d
Dim cyl_brep As Brep
Dim score(0 To 2) As Integer
Dim score_ix As Integer = 0
'// -1 to 1. But for now, run only one laps.
For i As Integer = -1 To -1
'/
'/ Clear lists if running multiple rounds
'/
insidePts.Clear()
outsidePts.Clear()
'/
'/ Attempt to Translate (Move) Cylinder
'/
cp.X += i
hp.X += i
cyl_brep = BrepCylinder(cp, hp)
'//
'// FILTER CYLINDER
'//
Dim BBox As New BoundingBox(cyl_brep.GetBoundingBox(True).GetCorners())
cylC = BBox.Center
DA.SetData(OUT_CC, cylC)
Dim cyl_tmp As Cylinder = AsCylinder(cp, hp)
'Dim line_tmp As New Line(cylC, hp)
'Dim isectPt1 As Point3d
'Dim isectPt2 As Point3d
Dim crv As New LineCurve(cp, hp)
Dim inside_cnt As Integer = 0
For Each mesh_pt As Point3d In InPts
'//
'// BOX INCLUSION (Raw test)
'//
If (mesh_pt.Z < BBox.Max.Z) And
(mesh_pt.Z > BBox.Min.Z) And
(mesh_pt.X > BBox.Min.X) And
(mesh_pt.X < BBox.Max.X) And
(mesh_pt.Y > BBox.Min.Y) And
(mesh_pt.Y < BBox.Max.Y) Then
''//
''// CYLINDER INCLUSION
''//
'line_tmp.To = mesh_pt
crv.SetStartPoint(cylC)
crv.SetEndPoint(mesh_pt)
Dim overlapCurves As Curve()
Dim intersectPoints As Point3d()
If Intersect.Intersection.CurveBrep(crv, cyl_brep, tolerance, overlapCurves, intersectPoints) And (intersectPoints.GetUpperBound(0) < 0) Then
'If Intersect.Intersection.LineCylinder(line_tmp, cyl_tmp, isectPt1, isectPt2).Multiple Then
insidePts.Add(mesh_pt)
inside_cnt += 1
Else
outsidePts.Add(mesh_pt)
End If
outsidePts.Add(mesh_pt)
End If
Next
score(score_ix) = inside_cnt
'Threading.Thread.Sleep(200)
'Threading.Thread.Wait(200)
Next
'//
'// OUT-PORTS
'//
DA.SetDataList(OUT_BIn, insidePts)
DA.SetDataList(OUT_BOut, outsidePts)
DA.SetData(OUT_CC, cylC)
DA.SetData(OUT_Score, score(2).ToString())
DA.SetData(OUT_Brep, cyl_brep)
DA.SetDataList(OUT_TxGeo, Nothing)
End Sub
''' <summary>
''' Icons need to be 24x24 pixels.
''' </summary>
Protected Overrides ReadOnly Property Icon() As System.Drawing.Bitmap
Get
Return My.Resources.Resource_Icon.ICO_Experimental
End Get
End Property
''' <summary>
''' Gets the unique ID for this component. Do not change this ID after release.
''' </summary>
Public Overrides ReadOnly Property ComponentGuid() As Guid
Get
Return New Guid("EDACD053-B7CE-4A9D-B7E3-099067F03AAD")
End Get
End Property
End Class
End Namespace
// Rolf