Merge list of different dimensions

Hi!

I have a few branches I want to merge, but their dimensions are {0:0:0} and {0:0:0:0}. I could not get rid of the extra dimensions by ‘Simplify’ (or Simplify Tree), so when I merge these branches, only branches with the same dimension got merged.

How could I merge these branches into the same branch?

Thanks a lot!

For some reason, I can’t turn the {0:0:0} into just {0}. The different number of dimensions result Merge returning multiple branches of the same different dimensions (I want one branch with one dimension)

When I need a single list, I use the Entwine component because it flattens the inputs and preserves the order in which they’re connected. Just flatten the output. The Merge component can move data around depending on input tree paths

1 Like
 public void ChangePath<T> (ref DataTree<T> tree, int dim){ // dim for dimension position
    DataTree<T> tmp = new DataTree<T>();
    foreach(GH_Path path in tree.Paths){
      if(dim >= path.Indices.Count())dim = path.Indices.Count() - 1;
      GH_Path newPath = new GH_Path(path.Indices[dim]);
      tmp.AddRange(tree.Branch(path), newPath);
    }
    tree = tmp;
  }

The above … well … requires rather some IQ more (if you want to work on a blind date basis):

Imagine a path: {6,77,89,2} and a path {77,89,1,2} : if dim == 3 … then Houston we do have a problem. Or imagine paths like {7}, {6,7}, {89,0,7} … {45,67,7} and a dim value: 77 > a single path {7} is the result.

BTW: if GH_Path path = new GH_Path(6, 66, 666, 6666); then 6 is the first dimension, 66 the second … blah, blah.

BTW: path.Indices yields an int Array of size 4: {6, 66 , 666, 6666}

So this is maybe “better”:

public void ChangePath<T> (ref DataTree<T> tree, int dim, bool IQ){ // dim for dimension position
    DataTree<T> tmp = new DataTree<T>();

    List<int> dims = new List<int>();
    foreach(GH_Path path in tree.Paths){
      if(dim >= path.Indices.Count())dim = path.Indices.Count() - 1;

      int pathDim = path.Indices[dim];
      if(IQ && dims.Contains(pathDim)) continue; // or do something else
      dims.Add(pathDim);

      GH_Path newPath = new GH_Path(pathDim);
      tmp.AddRange(tree.Branch(path), newPath);
    }
    tree = tmp;
  }

Spend a couple of minutes for some sort of a simple demo on all that:

DataTree_ChangePath_EntryLevel_V1.gh (119.6 KB)

1 Like

The Simplify logic in GH1 never simplifies trees with single paths. Because it only removes the shared overlaps between two or more branches. This behaviour is logical, but not particularly useful. The Suirify object does handle individual paths. But as mentioned, Entwine may be a better solution for you.

1 Like

Thanks so much for your help! I got it to work!

Thanks for your explanation! I did not realize that since I only have one branch!

Thanks for your help! I will keep Entwine in mind!

OK then.

PS: if !IQ (meaning … you know what) is always a good thing to add a little reminder (i.e. possibly same dimensions encountered - IF such case exists in your dataset) :

DataTree<object> testN = ChangePath<object>(test, dim, IQ);
    newTree = testN;

    if(!IQ) Print("Paths in: {0}, out: {1}", test.BranchCount, testN.BranchCount);

For instance:

But in fact the pro solution for that is to monitor things via a proper class (populated in a first pass) … and then (second pass) decide what to take. For instance imagine - with dim = 0 - that the {28;89} has many items (skipped as things are) while the {28;83} is empty (taken because no count criterion is implemented) … etc etc.

 public List<PINFO> pInfo;

  public class PINFO{
    public GH_Path F_PATH {get;set;}
    public GH_Path T_PATH {get;set;}
    public int COUNT {get;set;}

    public PINFO (GH_Path fromPath, GH_Path toPath, int count){
      this.F_PATH = fromPath;
      this.T_PATH = toPath;
      this.COUNT = count;
    }
  }

I’m curious about the logic of this. When working with trees I constantly have to use the surify component everywhere since a lot of components add a spurious dimension, for example the weave component. This issue is that {0} != {0;0} and this causes a lot of data matching issues.

Is there a way to get the behavior of trees to only add dimensions when data is actually being added?