Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial experiment with #20 #21

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion SandWorm/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public static Mesh CreateQuadMesh(Mesh mesh, List<Point3f> vertices, List<Color>
mesh.Vertices.AddVertices(vertices);
}

mesh.VertexColors.SetColors(colors.ToArray());
if (colors.Count > 0) // Colors only provided if the mesh style permits
{
mesh.VertexColors.SetColors(colors.ToArray());
}
return mesh;
}

Expand Down
43 changes: 40 additions & 3 deletions SandWorm/SandWormComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Grasshopper.Kernel;
using Rhino.Geometry;
using Microsoft.Kinect;
using System.Windows.Forms;
// comment
// In order to load the result of this wizard, you will also need to
// add the output bin/ folder of this project to the list of loaded
Expand All @@ -25,6 +26,8 @@ public class SandWorm : GH_Component

public static int depthPoint;
public static Color[] lookupTable = new Color[1500]; //to do - fix arbitrary value assuming 1500 mm as max distance from the kinect sensor
enum MeshColorStyle { noColor, byElevation };
private MeshColorStyle selectedColorStyle = MeshColorStyle.byElevation; // Must be private to be less accessible than enum type
public List<Color> vertexColors;
public Mesh quadMesh = new Mesh();

Expand Down Expand Up @@ -87,6 +90,35 @@ protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager
pManager.AddTextParameter("Output", "O", "Output", GH_ParamAccess.list); //debugging
}

protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown menu)
{
base.AppendAdditionalComponentMenuItems(menu);
Menu_AppendItem(menu, "Color Mesh by Elevation", SetMeshColorStyle, true, selectedColorStyle == MeshColorStyle.byElevation);
menu.Items[menu.Items.Count - 1].Tag = MeshColorStyle.byElevation;
Menu_AppendItem(menu, "Do Not Color Mesh", SetMeshColorStyle, true, selectedColorStyle == MeshColorStyle.noColor);
menu.Items[menu.Items.Count - 1].Tag = MeshColorStyle.noColor;
}

private void SetMeshColorStyle(object sender, EventArgs e)
{
ToolStripMenuItem selectedItem = (ToolStripMenuItem)sender;
ToolStrip parentMenu = selectedItem.Owner as ToolStrip;
if ((MeshColorStyle)selectedItem.Tag != selectedColorStyle) // Update style if it was changed
{
selectedColorStyle = (MeshColorStyle)selectedItem.Tag;
ExpireSolution(true);
philipbelesky marked this conversation as resolved.
Show resolved Hide resolved
quadMesh.VertexColors.Clear(); // Must flush mesh colors to properly updated display
}
for (int i = 0; i < parentMenu.Items.Count; i++) // Easier than foreach as types differ
{
if (parentMenu.Items[i] is ToolStripMenuItem && parentMenu.Items[i].Tag != null)
{
ToolStripMenuItem menuItem = parentMenu.Items[i] as ToolStripMenuItem;
menuItem.Checked = true; // Toggle state of menu items
}
}
}

private void ScheduleDelegate(GH_Document doc)
{
ExpireSolution(false);
Expand Down Expand Up @@ -142,8 +174,10 @@ protected override void SolveInstance(IGH_DataAccess DA)

Stopwatch timer = Stopwatch.StartNew(); //debugging

Core.ComputeLookupTable(waterLevel, lookupTable); //precompute all vertex colors

if (selectedColorStyle == MeshColorStyle.byElevation)
{
Core.ComputeLookupTable(waterLevel, lookupTable); //precompute all vertex colors
}

if (this.kinectSensor == null)
{
Expand Down Expand Up @@ -208,7 +242,10 @@ protected override void SolveInstance(IGH_DataAccess DA)


tempPoint.Z = (float)((depthPoint - sensorElevation) * -unitsMultiplier);
vertexColors.Add(lookupTable[depthPoint]);
if (selectedColorStyle == MeshColorStyle.byElevation)
{
vertexColors.Add(lookupTable[depthPoint]);
}

pointCloud.Add(tempPoint);
}
Expand Down