3.5. Data Structure

Introduction to data in Grasshopper.

Data Trees extended:

Download example file for Data Trees (extended):

GH File

Data Structure in GH

We can subdivide data structures into 3 different groups in GH:

  • Single
  • List
  • Tree
Data structure

Single level operations

Many components operates on individual values and also output individual values as result:

1:1

Lists level operations

Other category of components create lists of data from single input values:

1:N Occurring also the opposite behavior: N:1

Many components only operates on lists of data and also output list of data:

N:N

Tree level operations

Some few components output several list points, each of them representing a row or column in a grid:

1:N'

We can also access to specific items in the Data Tree:

N':1

Or we can just operate them keeping or modifying its Data Tree structure:

N':N'

Elements to consider in data structures

  1. Lists
  2. Index
  3. Items
  4. Paths
  5. Branches
  6. Data Tree

Lists

A List is an ordered (but not necessarily sorted) collection of data. Lists may contain zero elements, a single element, or many elements. The same element can occur more than once in the same list, and different elements with identical values. Also, a list may contain empty elements, referred to as nulls.

When storing data in a list, it’s important to know the position of the items in that list in order to access or manipulate them. The position of an item in a list is called Index Number.

Lists

List Manipulation

Most of the operation in Grasshopper will happen at List level and Grasshopper is specially good at quickly building and manipulating lists of data.

Range

List of equally spaced numbers between a Low and a High value is called Domain. A domain is every possible number between two numeric extremes.

The Range component divides a numeric domain into even segments and returns a list of values.

  • Sets > Sequence > Range
Range

List Length

Measures the length of the List.

  • Sets > List > List Length
List length

List Item

To find a specific data item from within a list.

When accessing individual items in a list, we have to specify the Index Number we would like to access, that can be a single integer or a list of integers.

  • Sets > List > List Item
List item

Reverse List

To invert the order of the list.

  • Sets > List > Reverse List
List reverse

Shift List

We can move the list index up or down depending on the value of the shift offset.

If we set the “Wrap” value to False, we will remove the last value. However, if we set the “Wrap” value to True, the first entry will be moved to the bottom of the list.

  • Sets > List > Shift List
List shift

Insert Item

Insert a collection of items into a list.

You need to know the items you want to insert and the index position.

  • Sets > List > Insert Item
List insert

Cull Pattern

Removes elements in a list using a repetitive pattern.

The pattern is defined as a list of Boolean values (True or False).

  • Sets > Sequence > Cull Pattern
List cull

Data Tree

It is important to understand how large quantities of data are stored, accessed, and manipulated.

A Data Tree is a hierarchical structure for storing data in Nested Lists or Sub-Lists.

These nested sub-lists work in the same way as folder structures on your computer in that accessing indexed items require moving through paths that are informed by their generation of parent lists and their own sub-index.

Data Tree I

Difference between List (Flatten) and Data Tree (Graft):

Data Tree II

Flatten tree

Flatten removes all levels of a Data Tree, resulting in a single List.

  • Sets > Tree > Flatten Tree
Flatten

Graft Tree

Graft Tree creates a new Branch for every Data Item.

  • Sets > Tree > Graft Tree
Graft

Simplify tree

Simplify a data tree by removing the overlap shared amongst all branches.

  • Sets > Tree > Simplify Tree
Simplify

Flip Matrix

Flip Matrix component Swaps the “Rows” and “Columns” of a Data Tree with two Path Indices.

  • Sets > Tree > Flip Matrix
Flip

Data visualization

We can visualize the Indices and Items in different ways in order to understand and manipulate them:

Point List

Displays the Index Item Number next to the point geometry in the viewport.

Point list I

Text Tag

Draws strings as feedback items. When text tags are baked into the scene, they turn into Text Dots.

List textag I

Tree visualization

Params > Util > Param Viewer

Param viewer

Color

We can visualize the data of a list by assigning color to it. You can find it on Params > Input > Gradient.

The L0 value represents the low end (left side) of the gradient, whereas the L1 value represents the upper end (right side). These values correspond to the Start and End of our domain. The t-values are the elements in the list that will get mapped somewhere within the L0 and L1 range.

The output of the gradient is a list of RGB color values which correspond to each point in our list.

List color I

Knowledge Checks