Weaverbird's "Mesh from Lines" polygon division

Hi @piac ,

I am extensively using your Weaverbird’s Mesh from Lines component. It made my work so much easier. Thank you for developing it!

I am having an issue with the component in cases when polygon consists of more than 4 lines but when one of its angles is obtuse. Here is one example of a planar polygon consisted of 5 lines:

The second photo shows created mesh with “Mesh from Lines” component labelling the mesh faces. Third photo would be desireable mesh faces. Numbers are not important, but the division of the polygon.

Is it possible to improve this in near future?
I am using Rhino 5 SR12 64 bit, Grasshopper 0.9.0076 and Weaverbird 0.9.0.1.

The component itself states that it is experimental, I assume due to complex nature of the polygon detection, which you mentioned on grasshopper forum.
With this in mind, I still hope you won’t take this topic as ungrateful.

I uploaded the .gh definition with internalized curves shown in the screenshot:
mesh_from_lines.gh (6.9 KB)

Kind regards,
Djordje

Hi Djordje, you might also consider using Polyline.TriangulateClosedPolyline for this (example here).

Thank you for the quick and useful reply @AndersDeleuran !

The issue is that I do not have the closed polygon. Upper presented screenshot is just a simplification of the actual usage. In reality I have number of 3d lines which intersect each other. I use Weaverbird’s ```Mesh from Lines" component not to get a mesh, but actually to identify closed polygons, from which then planar breps are created or patches if the polygons are not planar.

Initially I went for the undirected graph approach to identify these closed polygons (but closed chord-less polygons) by searching through graph nodes. Interestingly even cpython’s top graph module: networkx failed to find all of chordless closed polygons (used in through GH_CPython). Discouraged by this, I never tried .NET alternatives as QuickGraph.
Stackoverflow search gave the following C code which is suppose to solve this issue, but sadly in order to try to convert it to ironpython, I would have to understand the steps, which I do not.

Giulio’s Mesh from Lines up so far was a life saver for me in terms of identifying closed chordless polygons. The only issue are polygons with more than 4 lines and with obtuse angles, as show in the screenshot above.

I have tried playing around with this command, but it seems it doesn’t accept to be used in a for loop. Strange, I get a MeshFace result only the first time I call the method, after that the method returns only an empty array. < scratching head >

Using Rhino 5 from GrassHopper & C# script component.

// Rolf

The algorithm choice in Weaverbird luckily supports this case – the problem is that triangulation will happen when the internal data is converted to Rhino.Geometry.Mesh. It’s possible to avoid this problem by using the internal polyline result factory, as in this Python example.

import clr
clr.AddReference("Weaverbird.Core")
clr.AddReference("Weaverbird.CommonSdkSupport")

import Weaverbird as wb
import Weaverbird.CommonSupport as wbc
import Rhino as rc
import System as s

L = s.Collections.Generic.List[rc.Geometry.Line](L)

a = wb.WbStatic.WbWeaveBack[s.Array[rc.Geometry.PolylineCurve], wb.Geometry.IPoints.LineCurve](
    wbc.Support.Import(L), V,
    wbc.CommonPolylinesFactory.Instance,
    None, rc.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance)

mesh_from_lines_2.gh (5.1 KB)

Btw, I also added Mesh.CreateFromLines() to Rhino WIP. This, in turn, is used in the new _MeshFromLines V6 Rhino command.

3 Likes

Hi @piac,

Wonderful!! Thank you for sharing the code!

Hi @piac,

I find myself in a situation when I do not know the maximal valence found among all closed polylines, so I set it to some high value, which always results in creation of the outer encompassing one.
Or even if I would know the maximal allowed valence, let’s assume that one of the “inner” closed polylines has the same number of edges as the outer closed polyline. In this case if valence is lowered than both of these polylines are excluded.
Here is an example of this:
mesh_from_lines_2b.gh (7.1 KB)

In general I do not have planar and this much simple closed polylines, but it was just for the purpose of explaining the question.

Do you have any suggestion how this closed polyline encompassing all other polylines can be excluded from the wb.WbStatic.WbWeaveBack result? Or culled somehow afterwards?

Hi @djordje

this is topologically not recognizable from the case of having a 2-sphere manifold. In fact, the largest polygon could just be thought as a “face” of the object in general. See this example.

However, you could handle this geometrically. If you compute, for example, the area of the largest polyline and the summed area of all remaining ones, if they are equal or almost, then you have the case of the “purely surrounding” polyline in a planar object. There might be other ways, depending from your needs.

Giulio


Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

2 Likes

Thank you once again for the quick reply and solution Giulio!

Hi @piac,

Please accept my apology for prolonging this topic once again.
I can’t replicate your ghpython component results with Rhino python editor.
For some reason, Rhino python editor script does not return the 4 triangular polylines at the very edge of the following example:
missing_polylines2

Why is there discrepancy between ghpython and Rhino Python editor results?

I attached the .3dm and .py files below.
missing_polylines.3dm (74.0 KB)
missing_polylines.py (720 Bytes)

Hi @djordje

I don’t think that using 100 as maximum valence is a good idea. In this case, I think the algorithm gets confused by using such a large value and tries to follow the “outer path”. If you use 4 or 5, you can see it working. In fact, it works till 25 excluded (24 is the outer edge valence).

Sorry, I’d have to debug it a lot more carefully to give you more specifics.

Giulio

Hi @piac,

Thank you again for the quick reply and explanation !!
Interestingly on my PC 22 is the last valence which includes these 4 corner triangles. From 23 they are excluded.

I do not want to take much of your time with this.
If its debugging requires some significant time which you at the moment do not have, I can wait until then. Thank you once again.

Hi @piac,
I have just one more question:
The .gh file that you attached works perfectly when Weaverbird is installed (I installed version 0.9.0.1 for Rhino5).
However, it fails when it is not, with the following message:

Runtime error (ArgumentTypeException): expected Array[LineCurve], got Array[LineCurve]
Traceback:
  line 12, in script

Why is it necessarily for the Weaverbird to be installed? Why I can’t just call the methods from Weaverbird.Core.dll and Weaverbird.CommonSdkSupport.dll?

I am using Rhino 5 and Grasshopper 0.9.0076.

Probably the companion .dlls are not found. Also, please note that you are not allowed by the license to ship the .dlls yourself. (Please let the user install them)

Hi @piac.
I will install them then. Thank you for the help.
Interestingly the same .dll file paths work, right after the Weaverbird is installed. Without it being installed the upper error message appears.

1 Like