/
MeshReportComponent.cs
174 lines (153 loc) · 5.42 KB
/
MeshReportComponent.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
using System;
using System.Collections.Generic;
using Grasshopper.Kernel;
using Rhino.Geometry;
using IntraLattice.Properties;
using System.Drawing;
// Summary: This component is a post-processing tool used to inspect a mesh.
// ===============================================================================
// Details: - Checks that the mesh represents a solid, and returns a comprehensive report.
// ===============================================================================
// Author(s): Aidan Kurtz (http://aidankurtz.com)
namespace IntraLattice.CORE.UtilityModule
{
public class MeshReportComponent : GH_Component
{
// Naked edges for previewing, declared at class level
private Polyline[] m_nakedEdges;
/// <summary>
/// Initializes a new instance of the MeshReportComponent class.
/// </summary>
public MeshReportComponent()
: base("Mesh Report", "MeshReport",
"Verifies that the mesh represents a solid, and returns a comprehensive report.",
"IntraLattice", "Utils")
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddMeshParameter("Mesh", "Mesh", "Mesh to inspect.", GH_ParamAccess.item);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddTextParameter("Report", "Report", "Report of inspection", GH_ParamAccess.item);
}
/// <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. Retrieve/validate input
Mesh mesh = null;
if (!DA.GetData(0, ref mesh)) { return; }
if (!mesh.IsValid) { return; }
// 2. Initiliaze variables
string report = ""; // report string
bool isValid = true; // will be false if any of the tests fail
bool isOriented, hasBoundary;
// 3. Check - naked edges
report = "- Details -\n";
m_nakedEdges = mesh.GetNakedEdges();
if (m_nakedEdges == null)
{
report += "Mesh has 0 naked edges. \n";
}
else
{
report += String.Format("Mesh has {0} naked edges. \n", m_nakedEdges.Length);
isValid = false;
}
// 4. Check - manifoldness
if (mesh.IsManifold(true, out isOriented, out hasBoundary))
{
report += "Mesh is manifold. \n";
}
else
{
report += "Mesh is non-manifold. \n";
isValid = false;
}
// 5. Check - mesh orientation
if (mesh.SolidOrientation() == 1)
{
report += "Mesh is solid. \n";
}
else if (mesh.SolidOrientation() == 0)
{
report += "Mesh is not solid. \n";
isValid = false;
}
// Inward facing normals
else
{
mesh.Flip(true, true, true);
report += "Mesh is solid. (normals have been flipped) \n";
}
// 6. Finally, summarize these results
if (isValid)
{
report = "Mesh is VALID.\n\n" + report;
}
else
{
report = "Mesh is INVALID.\n\n" + report;
}
// 7. Add title
report = "- Overview -\n" + report;
// 8. Output report
DA.SetData(0, report);
}
/// <summary>
/// Display naked edges
/// </summary>
public override void DrawViewportWires(IGH_PreviewArgs args)
{
base.DrawViewportWires(args);
if (m_nakedEdges != null)
{
foreach (Polyline nakedEdge in m_nakedEdges)
{
if (nakedEdge.IsValid)
{
args.Display.DrawPolyline(nakedEdge, Color.DarkRed);
}
}
}
}
/// <summary>
/// Sets the exposure of the component (i.e. the toolbar panel it is in)
/// </summary>
public override GH_Exposure Exposure
{
get
{
return GH_Exposure.tertiary;
}
}
/// <summary>
/// Provides an Icon for the component.
/// Icons need to be 24x24 pixels.
/// </summary>
protected override System.Drawing.Bitmap Icon
{
get
{
return Resources.meshReport;
}
}
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("{f49535d8-ab4a-4ee7-8721-290457b4e3eb}"); }
}
}
}