Joined breps indices

Is there a way to get indices of joined breps after brep join? What intersection method does this component use to decide which breps to join? When I use clash or collide or any other method to evaluate intersections, it is very computationally heavy and may not give the indices in the correct order.


So, what i have here is flattened planar polylines that are joined into polysurfaces.

Ideally I would like to get another output from joined breps component, that contains the same amount of branches as the amount of breps it gives, and each branch to contain indices of initial surfaces used to create corresponding brep. Is that possible?


collision component is 76 times slower

Assuming that you have solid and valid Breps:

The classic solution for that sort of stuff is to Cluster your collection (criterion: Ccx). Thus you’ll get a Tree of Type int where paths are the Cluster ID and items the indices of the Breps. If a given Cluster has one member this is the index of an isolated item. This means that if you attempt, say, to Union all the items - via their indices - per Branch … you should get a valid Brep. Since Rhino is a Surface modeller … that sort of stuff may require some time (but you can use a classic pre-filter when Clustering like Boxes Intervals [x/y/z] Ccx).

The bad news is that for Clustering you’ll need code.

Tip: don’t attempt the Clustering via a “simple” double Loop.

1 Like

thanks a lot for the explanation! I like to code, but I am a beginner at coding, and right now I am under pressure at work, so I do not have time to experiment :C I found topology of adjacencies in heteroptera, not perfect, but does the thing. So, the problem is solved:)

if anyone needs join brep component that outputs indices of joined breps, here it is:

JoinBrepsIndex.gh (13.5 KB)

rhinocommon method
Brep JoinBreps(IEnumerable brepsToJoin, System.Double tolerance, System.Double angleTolerance, out List<int> indexMap)

using System;

using System.Collections.Generic;

using Rhino;

using Rhino.Geometry;

using Grasshopper;

using Grasshopper.Kernel.Data;

using Grasshopper.Kernel.Types;




public class Script_Instance : GH_ScriptInstance

{

private void RunScript(

        DataTree<Brep> breps,

double tolerance,

double angleTolerance,

ref object JoinedBreps,

ref object IndexMap)

  {

    DataTree<Brep> joinedTree   = new DataTree<Brep>();

    DataTree<int>  indexMapTree = new DataTree<int>();




if (tolerance <= 0)

    {

      tolerance = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance * 2.1;

    }

if (angleTolerance <= 0)

    {

      angleTolerance = RhinoDoc.ActiveDoc.ModelAngleToleranceRadians;

    }




for (int bi = 0; bi < breps.BranchCount; bi++)

    {

      GH_Path path      = breps.Path(bi);

      List<Brep> branch = breps.Branch(bi);

if (branch == null || branch.Count == 0) continue;




      List<int[]> idxMap;

      Brep[] joined = Brep.JoinBreps(branch, tolerance, angleTolerance, out idxMap);




if (joined != null && joined.Length > 0)

      {

if (idxMap != null && idxMap.Count == joined.Length)

        {

for (int j = 0; j < joined.Length; j++)

          {

            GH_Path resPath = new GH_Path(path).AppendElement(j);

            joinedTree.Add(joined[j], resPath);




int[] indices = idxMap[j];

if (indices != null && indices.Length > 0)

            {

foreach (int k in indices)

              {

                indexMapTree.Add(k, resPath);

              }

            }

          }

        }

else

        {

for (int j = 0; j < joined.Length; j++)

          {

            GH_Path resPath = new GH_Path(path).AppendElement(j);

            joinedTree.Add(joined[j], resPath);

            indexMapTree.Add(j, resPath);

          }

        }

      }

else

      {

for (int i = 0; i < branch.Count; i++)

        {

if (branch[i] == null) continue;

          GH_Path resPath = new GH_Path(path).AppendElement(i);

          joinedTree.Add(branch[i], resPath);

          indexMapTree.Add(i, resPath);

        }

      }

    }




    JoinedBreps = joinedTree;

    IndexMap    = indexMapTree;

  }

}

Am I doing it right? :eyes:


JoinBrepsIndex VR 01.gh (23.8 KB)

1 Like

Haha yes:)) But back in the day the problem was in computation time. There were many ways to find such groups, but i was making this algorithm for shapediver, and it did not compute the algorithm if it was running longer than 30 seconds. So I had to optimize each one of my components.

Now when i think about it, i think of many ways of solving that, and do not understand why I had to do it this way. But i think i had good reasons.

In a nutshell, it was killing me that many|many collision was computing for 35 seconds, and join brep only for 300 ms. So seeing this 10 fold difference was so painful, when it was detecting those collisions right under my nose, but not giving them to meXD

1 Like