Surfaces from Image Sampler – Example 4.6
So it has been a few weeks since I’ve put anything new up. No, the blog is not dead (yet!) I was just on vacation in Greece. Getting back into things I am going to ditch complex scripts for a bit and look at a useful, and fairly simple tool for generating terrain models using the image sampler. This script uses the same basic logic as Example 2.5, so if you can set that one up, this one should be no problem. Here, instead of resizing circles or squares based on an image, we are going to be moving points from a grid in the Z-axis. The number of sample points in the UV directions will determine how accurate your topography will be, which will be demonstrated in one of the last examples. I will show an image of the script at the end, but will not explain the ins and outs, but a key thing to get right is that the image you are sampling should be (in pixels) the same size and proportion as your surface in Rhino/Grasshopper to get best results. So for a 3000 x 3000 pixel image your surface should be 3000 x 3000 units (in Rhino). The other thing to note is that the image sample outputs numbers between 0 and 1, so if you want to move more distance in the Z axis, you need to set up a multiply factor. Anyways, that’s about it. Now onto the examples….
Surfaces from Sketch in Photoshop
In these first two images, I quickly sketched some shapes in Photoshop using the gradient paintbrush. In my script, white areas are higher points and black areas are lower points. I could reverse these by subtracting the results of the image sampler from 1, in which case black would be high and white would be low. I have 100 x 100 sample points, and after moving them up and down in the Z direction, I create a surface grid. From this, contours and drainage analysis could be done as explained in Example 4.1. If you are a little more old school, you might try drawing something with charcoal and erasers, scanning the image, and creating a terrain from that…
Example 2 – Terrain from Aerial Imagery
You could also try generating a terrain from found images. These were just two images I randomly took from the Libyan desert to see what terrain might result. Note, these are NOT the actual topographies represented by these images, just an abstraction. The dune field in Libya might produce results that are close, though, based on shadows. This might not be that useful, but its an interesting test.
Example 3: Terrain from DEM files
Maybe the most useful application of using image sampling to create terrain is to convert DEM (Digital Elevation Model) data into 3D models. Since I just got back from Greece, I decided to try this out on the Peloponnese peninsula. Before starting in Rhino, I loaded and extracted the DEM data frame using ArcGIS. If you don’t have access to this (licenses are expensive!) there is a free GIS program, QGIS that you could probably use to do the same thing but I haven’t tried this yet. In GIS I applied a black and white gradient with white being the lowest points and black being the highest.
After my first try with 100 x 100 sampling points, I got results as you can see above. I tried this again with 300 x 300 sample points and got much more accurate terrain, but it also takes longer to generate. Depending on your needs, the 100 x 100 might be enough… From this I drew contours.
I tried a couple of other examples. This is Scotland, potentially the world’s next independent nation…
And this last example, South America. Note in this particular DEM the Altiplano is considerably flattened. Still a nice drawing, I think.
Below is the grasshopper script used to generate the topography in these examples. Note that it is very similar to Example 2.5 with the Sampling being used this time to generate the “Z” Value.
Hi I would like to try this but could you post an image of the grasshopper script please
LikeLike
Ok! Put the image up. Good luck!
LikeLike
Hi!
Thank you so much for the post and for the website in general. It is a great resource and has helped inspire me. I am having a bit of trouble with this script and was wondering if you could take a look at my screenshots and tell me why I can’t seem to make out where in the contours my geometry is and why it looks the way it does.
script: https://drive.google.com/file/d/15kP9o8GJ7YeYKuuunrHqJuVDdOHb_1Cg/view?usp=sharing
input drawing: https://drive.google.com/file/d/1yFBoE9hp8m-a5PUYdumsOUsDlWEOdUPC/view?usp=sharing
renders: https://drive.google.com/file/d/1HSdjdvlqTFCS8DphIV-PdnWQsoftfces/view?usp=sharing
https://drive.google.com/file/d/1LKrmaVPjvHIydBe95iKizAyeYbU-spvM/view?usp=sharing
Thanks!
archer
LikeLike
Hi, First of all thank you so much to post these useful Rhino script and explanation. I am using your script to create a topo rhino model. But I want to change the scale to 30000 x 30000, instead of 300 x 300. I changed the scale in Image Sampler from 300 x 300 to 30000 x 30000 but what I found out is that when I change the Height Multiplier Factor, the height actually did not vary too much. How can I make it work in 30000 x 30000, but still have the same effect in vertically as the one in 300 x 300? Thank you.
LikeLike
I think what you want to do is simply multiply the “Height Scale Factor” by 100 since you are in effect multiplying the whole system by this factor.
You need to be a little careful, though with bigger numbers, as it will start to make your computer slow down at some point.
LikeLike
Thank you so much for this script, it works wonders. I really appreciate you figuring this out for the rest of us, keep up the good work!
LikeLike
How do you determine a scale for the maps you create? For example, if you have an image at 300×300, what does the 1.00 distance actually equate to? Where does the 45 height multiplier come from or is i just an approximation?
The reason I ask is I am making a map from a DEM file that is roughly 1000×500, and in order to have a unit assigned to any of those scalars in grasshopper (i.e. for distance = 1 to actually mean distance = 1 meter) you’d have to find out how many degrees latitude per pixel, and how many meters per degree latitude, and multiply them to get how many meters per pixel. Then you could normalize all the scalars that are used to that ratio so you could accurately scale whatever you bake…but until then isn’t everything scaleless? Sorry if this is confusing.
LikeLike
I would be very cautious in assigning any scale to DEMs. The scale of a pixel varies based on the dataset, and as you mention, the latitude. See https://generativelandscapes.wordpress.com/2014/09/19/adding-topography-to-the-site-model-example-20-2/ for a bit of discussion on this topic, but in this example it is more or less scale free.
LikeLike
Hi!
Thank you so much for the post and for the website in general. It is a great resource and has helped inspire me. I am having a bit of trouble with this script and was wondering if you could take a look at my screenshots and tell me why I can’t seem to make out where in the contours my geometry is and why it looks the way it does.
script: https://drive.google.com/file/d/15kP9o8GJ7YeYKuuunrHqJuVDdOHb_1Cg/view?usp=sharing
input drawing: https://drive.google.com/file/d/1yFBoE9hp8m-a5PUYdumsOUsDlWEOdUPC/view?usp=sharing
renders: https://drive.google.com/file/d/1HSdjdvlqTFCS8DphIV-PdnWQsoftfces/view?usp=sharing
https://drive.google.com/file/d/1LKrmaVPjvHIydBe95iKizAyeYbU-spvM/view?usp=sharing
Thanks!
archer
LikeLike
Hi Archer, the problem seems to be with the step where the surface is created from the grid of points after the image sampler operation (The SrfGrid component).
EDIT* Having looked at the script, I think you are mixing up the U and V values being input into the U / V on surface divide, and the U input into the SrfGrid component. Right now you have ‘V Count’ going into SrfGrid and not ‘U Count’
hope that fixes your problem
LikeLike