Skip to content

Commit

Permalink
Add PMesh from points and topology component
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan-Piker committed Nov 18, 2013
1 parent 94ba6c7 commit 60994b1
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 8 deletions.
82 changes: 82 additions & 0 deletions src/PlanktonGh/PMeshFromPoints.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rhino.Geometry;
using Grasshopper.Kernel;
using Plankton;

namespace PlanktonGh
{

public class PMeshFromPoints : GH_Component
{
/// <summary>
/// Each implementation of GH_Component must provide a public
/// constructor without any arguments.
/// Category represents the Tab in which the component will appear,
/// Subcategory the panel. If you use non-existing tab or panel names,
/// new tabs/panels will automatically be created.
/// </summary>
public PMeshFromPoints()
: base("PlanktonFromPoints", "PlanktonFromPoints",
"Create a new Plankton mesh from an existing Plankton mesh and a list of points",
"Mesh", "Triangulation")
{
}

/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddGenericParameter("PMesh", "PMesh", "The input PlanktonMesh to use the topology from", GH_ParamAccess.item);
pManager.AddPointParameter("Vertices", "Vertices", "The new list of vertex positions", GH_ParamAccess.list);
}

/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.Register_GenericParam("PlanktonMesh", "P", "Plankton Mesh");
}

/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object can be used to retrieve data from input parameters and
/// to store data in output parameters.</param>

protected override void SolveInstance(IGH_DataAccess DA)
{
PlanktonMesh P = new PlanktonMesh();
List<Point3d> Points = new List<Point3d>();
if ((!DA.GetData<PlanktonMesh>(0, ref P)) || (!DA.GetDataList(1, Points))) return;
PlanktonMesh pMesh = P.ReplaceVertices(Points);
DA.SetData(0, pMesh);
}

/// <summary>
/// Provides an Icon for every component that will be visible in the User Interface.
/// Icons need to be 24x24 pixels.
/// </summary>
protected override System.Drawing.Bitmap Icon
{
get
{
return PlanktonGh.Properties.Resources.plankton_verts;
}
}

/// <summary>
/// Each component must have a unique Guid to identify it.
/// It is vital this Guid doesn't change otherwise old ghx files
/// that use the old ID will partially fail during loading.
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("{c9377989-c89e-477d-8dd2-b35af0c3b25d}"); }
}
}
}
15 changes: 8 additions & 7 deletions src/PlanktonGh/PlanktonGh.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,17 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>..\bin\Release\PlanktonGh.xml</DocumentationFile>
<DocumentationFile>..\bin\Release\PlanktonGh.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="GH_IO">
<HintPath>..\..\lib\GH_IO.dll</HintPath>
<Private>False</Private>
<HintPath>..\..\..\..\..\..\..\Program Files\Common Files\McNeel\Rhinoceros\5.0\Plug-ins\Grasshopper (b45a29b1-4343-4035-989e-044e8580d9cf)\0.9.64.0\GH_IO.dll</HintPath>
</Reference>
<Reference Include="Grasshopper">
<HintPath>..\..\lib\Grasshopper.dll</HintPath>
<Private>False</Private>
<HintPath>..\..\..\..\..\..\..\Program Files\Common Files\McNeel\Rhinoceros\5.0\Plug-ins\Grasshopper (b45a29b1-4343-4035-989e-044e8580d9cf)\0.9.64.0\Grasshopper.dll</HintPath>
</Reference>
<Reference Include="RhinoCommon">
<HintPath>..\..\lib\RhinoCommon.dll</HintPath>
<Private>False</Private>
<HintPath>..\..\..\..\..\..\..\Program Files\Rhinoceros 5.0 (64-bit)\System\RhinoCommon.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -56,6 +53,7 @@
<ItemGroup>
<Compile Include="DecomposePlankton.cs" />
<Compile Include="GHMeshToPMesh.cs" />
<Compile Include="PMeshFromPoints.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down Expand Up @@ -83,6 +81,9 @@
<ItemGroup>
<None Include="Resources\plankton_decon.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\plankton_verts.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>Copy "$(TargetPath)" "$(TargetDir)$(SolutionName).gha"</PostBuildEvent>
Expand Down
12 changes: 11 additions & 1 deletion src/PlanktonGh/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/PlanktonGh/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,7 @@
<data name="plankton_decon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\plankton_decon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="plankton_verts" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\plankton_verts.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file added src/PlanktonGh/Resources/plankton_verts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/PlanktonGh/RhinoSupport.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Plankton;
using Rhino.Geometry;
using System;
using System.Collections.Generic;

namespace PlanktonGh
{
Expand Down Expand Up @@ -251,6 +252,22 @@ public static Mesh ToRhinoMesh(this PlanktonMesh source)
return rMesh;
}

/// <summary>
/// Replaces the vertices of a PlanktonMesh with a new list of points
/// </summary>
/// <returns>A list of closed polylines representing the boundary edges of each face.</returns>
/// <param name="source">A Plankton mesh.</param>
/// <param name="points">A list of points.</param>
public static PlanktonMesh ReplaceVertices(this PlanktonMesh source, List<Point3d> points)
{
PlanktonMesh pMesh = source;
for (int i = 0; i < points.Count; i++)
{
pMesh.Vertices.SetVertex(i, points[i]);
}
return pMesh;
}

/// <summary>
/// Converts each face to a closed polyline.
/// </summary>
Expand Down

0 comments on commit 60994b1

Please sign in to comment.