Any AForge Example Scripts?

I have been testing the AForge library from the Zero Touch Examples Zero-Touch Importing | The Dynamo Primer ( I was wondering if there were any other examples of graphs using AForge available?

My project goal is to be able to pixelize the floor slabs and grids, then overlay them and see if I can use that to optimize column layout.

I haven’t used AForge, but I did some work with OpenCV via IronPython back in 2018 (ish).

That said for the optimization you’re after I’d recommend a different method as optimization via image isn’t likely to work very well as the logical constraints (in terms of how we build) aren’t likely to be easily put into place.

I’m using images because I want to be able to create a heatmap of placement desirability. Given NxM bounds, how much is a column needed at that spot? The advantage I see using images is that I can visualize the output of the steps as I go. Note that because I’m initially generating the images based on a bounding box, transferring location between image and origin is simply applying a coordinate system transform.

The advantage I see in using heatmaps, is we are creating a set of parameters before generating a design. If engineers create a layout and then derive the resulting parameters, they are running the risk of having assumed themselves into a local minima. i.e. we are using the building footprint to estimate best layout, when our actual goal is to create layout based on loads.

I’ll look into openCV, but isn’t that is for computer vision rather than bitmap manipulation? Does it do image manipulation as well? I’m really just trying to find an abstraction for locational parameters in the form of gradients. Are there any better ways you can think of to do this? Maybe creating vector arrays, or a derivation of point cloud data, but there is quick visualization in Dynamo for those.

Ah. Given the use of heat maps, and assuming you have worked out how to calculate the “need” at a given point, a color range will do just as well and doesn’t need the external library. :slight_smile:

I’m using the external libraries because I need a in dynamo solution for matrix manipulation.

Without seeing specifics I can’t really help, but again to sample a value from a range of values doesn’t require the external library.

For specific applications of AForge or another matrix manipulation tool we can likely help you find a solution. However I am not sure I would build anything atop AForge based on:

  • the content here
  • the lack of activity on the GitHub
  • that their documentation page has been squatted by a sketchy seeming clickbait site

With some indication of what you are really after we can look into options.

The underlying functionality I want is to be able to show my floor plates stacked in plan. The desired data I want is how much overlap does any specific point have with all other slabs from the building. But there are also other parameters I want to be able to include, proximity to eos, proximity to grid, no go areas, etc. Once all the needed parameters are overlayed in single image, run a threshold to spots where columns can go, run a blob center to find a location, add a column at the centers. But ideally I can control how many floors I’m looking at any single time, so I can just select podium floors, or superstructure floors, or any specific subset.

Here is an example of the kind of data I want to be able to manipulate. Green intensity is points close enough to column to be safe, red is beyond threshold. I’d want to be able to add the amount of green up vertically to see where columns placement would be optimal.

Theoretically I could just make a new plan view with infinite depth and semi transparent slabs and export that image. but I do want to minimize the number of ceremonial steps in my process (no import/export). I’ve got the basics working, but if there is an example out there doing something similar with openCV I would love to see it. You are right about AForge, it doesn’t have all the features I’m looking for.

Does this mean “Edge of Slab”?

This is where I would look to OpenCV - easy enough without it though depending on how you are sampling the slab(s) to make the blobs you were planning on.

As an example, you can take the number of floors, divide the sample points by the overlaps counts, and map that from 0 (no slabs) to 255 (all slabs). This becomes the R value and assuming the outline of the mass is static, is a static set of values.

Next up we have the column grid - I am assuming this is actually variable, and that the configuration has a parametric model of sorts. Each sample point can be evaluated by distance to the nearest primary grid lines. This gets mapped in reverse from 255 to 0 (0 being the image size from the grid, 255 being on the grid) and serves as the G value. Do the same for the secondary grids, which will inform the B value.

The resulting color map becomes a set of UV parameters which can be mapped to each surface (perhaps after trimming the sample size to the surface’s extents). This can be applied to the slab surface using GeometryColor.BySurfaceColors or you can just put the columns in at the blob locations and optimize for number of columns and area supported by each column (assuming that at a basic level more area = larger framing members).

You have a good understanding, you are describing the steps exactly as I have them set up. What I like about bitmap as opposed to other formats, is that we can use overlays, subtraction, blurs, edge detection, recolorize, color division, &c in lieu of reinventing the wheel and writing the algorithms ourselves. (Using blurs rather than calcing distance is a big time save)

Are there any Dynamo openCV tutorials or resources available online? I’m assuming DynamoOpenCV is the package? But I haven’t seen any example projects yet.

Not necessarily - and with Color Ranges you can do exactly the same as with BitMaps.

I haven’t seen any, nor do I know of a package. My example focused reading content from a former Autodesk product called Sketchbook (now a standalone company) on demand, and converting to Revit elements (mostly focusing on landscaping elements like planting beds, walkways, etc.). It was last working in 2018/2019 and a windows update on my system broke the tool three weeks later (IT found a vulnerability in a windows media component and stripped it no questions asked) and I haven’t had the combination of desire and time (or a customer project) since. Implementing in Dynamo’s Python instance wasn’t bad at the time once you get the underlaying code built up, but you’ll have to write your own Python.

OpenCV does look really promising. I’ll be working on trying to switch my implementation to use it when I get some dev time.

Could you explain what you mean about using color ranges instead of bitmaps. I’m confused because I thought color ranges were 1D arrays, while bitmaps were 2D arrays.

Old Dynamo version, but this shows it well enough: Dynamo Dictionary

Oh, I didn’t realize there was a ColorRange2D. That makes more sense now.

But I’m still skeptical it could be implemented at scale. The example shown implements a blend effect rather than a blur. I mention this because a blend is distance agnostic, we could calc the full size of the UV in world space, but then we are adding more cycles each dataset.

Maybe, I’m not envisioning this concept correctly and there is a concept I’m missing? A secondary concern is that the UV space (0…1) will always be relative to the element location. Which element are we considering to hold the main UV coords? Since the 0 and 1.0 aren’t getting smaller, how do we account for changing footprint size as we go up the building? How would I go about doing comparisons between ColorRange2D’s? There are already a lot resources for working with matrices, but ColorRange2D is a interpolation not a matrix if I’m not mistaken. We could generate a matrix from it, but at that point I think we’re simply creating a bitmap in an inefficient way. I was leaning toward bitmaps because they have easy comparison operations, and inherent ‘stackability’.

I need to put some thought into this. I’ve never a found a good use case for UV in engineering, but maybe I just need to study some more examples to get it’s use cases.

The entire structure’s bounding rectangle.

Layer the colors before building the range; value of 0 for Red means no slabs here, value of 255 means all slabs here, etc…

Either don’t, or sample the same UV for the overall surface.

Correct, though that interpolation can be used to generate a matrix if you need to, though I am not convinced that you do.

The thing with any kind of ‘generative’ workflow, is you don’t need or even want complete values. You want to know which is better - this or that or one of those. As such interpolation is preferable when it can be faster.

If you find you do need the matrix, you’re almost certainly going to have to jump into coding from scratch - look to write your own DLLs using Visual Studio or another IDE which can write for .NET. When it makes sense, consume others DLLs and integrate them rather than just adding to Dynamo.