-
Notifications
You must be signed in to change notification settings - Fork 19
/
CleanNetworkComponent.cs
108 lines (97 loc) · 4.04 KB
/
CleanNetworkComponent.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using Grasshopper.Kernel;
using Rhino.Geometry;
using IntraLattice.CORE.Helpers;
using IntraLattice.Properties;
using Rhino.Collections;
using Rhino;
// Summary: This component cleans a curve network.
// ===============================================================================
// Details: -
// ===============================================================================
// Author(s): Aidan Kurtz (http://aidankurtz.com)
namespace IntraLattice.CORE.Components.Utility
{
public class CleanNetworkComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the CleanNetworkComponent class.
/// </summary>
public CleanNetworkComponent()
: base("Clean Network", "CleanNetwork",
"Removes duplicate curves from a network, within specified tolerance.",
"IntraLattice", "Utils")
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddCurveParameter("Struts", "Struts", "Strut network to clean.", GH_ParamAccess.list);
pManager.AddNumberParameter("Tolerance", "Tol", "Tolerance for combining nodes.", GH_ParamAccess.item);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddCurveParameter("Struts", "Struts", "Cleaned curve network.", GH_ParamAccess.list);
pManager.AddPointParameter("Nodes", "Nodes", "List of unique nodes.", GH_ParamAccess.list);
pManager.AddIntegerParameter("CurveStart", "I", "Index in 'Nodes' for the start of each curve in 'Struts'.", GH_ParamAccess.list);
pManager.AddIntegerParameter("CurveEnd", "J", "Index in 'Nodes' for the end of each curve in 'Struts'.", GH_ParamAccess.list);
}
/// <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 override void SolveInstance(IGH_DataAccess DA)
{
// 1. Declare placeholder variables
var struts = new List<Curve>();
double tol = 0.0;
// 2. Attempt to retrieve input
if (!DA.GetDataList(0, struts)) { return; }
if (!DA.GetData(1, ref tol)) { return; }
// 3. Validate input
if (struts == null || struts.Count == 1) { return; }
if (tol < 0) { return; }
// 4. Call cleaning method
var nodes = new Point3dList();
var nodePairs = new List<IndexPair>();
struts = FrameTools.CleanNetwork(struts, tol, out nodes, out nodePairs);
// 5. Organize index lists
var strutStart = new List<int>();
var strutEnd = new List<int>();
foreach (IndexPair nodePair in nodePairs)
{
strutStart.Add(nodePair.I);
strutEnd.Add(nodePair.J);
}
// 6. Set output
DA.SetDataList(0, struts);
DA.SetDataList(1, nodes);
DA.SetDataList(2, strutStart);
DA.SetDataList(3, strutEnd);
}
/// <summary>
/// Provides an Icon for the component.
/// Icons need to be 24x24 pixels.
/// </summary>
protected override System.Drawing.Bitmap Icon
{
get
{
return Resources.cleanNetwork;
}
}
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("{8b3a2f8c-3a76-4b19-84b9-f3eea80010ea}"); }
}
}
}