Using data cubes in city model by using rhino to visualize in virtual reality.

To start a project i got a cad file of the city part which looks like this

Original cad file

As seen in the figure, there are a lot of information in this cad file. Some time it is hard to understand which line is what. But the line is separate by layer names. the layer names are code, which is based upon regulation code for spatial information layer in south Korea. The layer tab looks like this.

original cad layer

There are 153 layer and each symbolize different meaning, I got a book about the code and the meaning of that code, which of-course written in Korean, which then I translate in English and rename all those layer which I need and remove all the other unnecessary data. The code looks like this.

code and the meaning of the layer in cad file
The final layer name and useful lines.

After this I take all the lines which symbolize the level of site and import it in rhino. From there I extract all the point I need and create a mesh. The mesh is land surface of my project area. The constructed mesh in rhino is shown in figure.

constructed site mesh in rhino

Since the project area is 3 km by 2 km (around) big the detailing I need to do is creating a building and roads. After this I went back again in the cad. In the cad I have converted 3D cad file into 2D file and create separate blocks for building and roads. The final building blocks in cad look like this.

2d cad file with only building footprint.

Those all building then create in sketch up for the height information, I used public 3d map of site location and make the building. When all the building is raised, it was in same plane, but the site is in contour plane, so I copy the land curved from rhino and used it in the sketch up. Since the 3d in both are in the same scale, I do not have to scale to match same size. also I don’t have any idea about the location of building in the curved surface so I have to project the 2d image that I create before on building footprint and project it in site landscape in rhino. Which then again imported into the sketch up for further work. The site with the building footprint and rood line is shown in below figure.

Road lines in the site landscape after projection
building lines in the site landscape area.

Although there is no face making in the sketch up I can still use the building footprint but I need different face in the case of roads so that I can use different color for representation. I move all the building 3d in the site landscape and stop working in sketch up for a moment.

Since I needed close loop of roads to make a face so I work in the 2d cad file that I make earlier and create a closed loop of lines and make a poly line by using command (b ㄱ) which make a boundary of all the line and make it one. After that some line need to be connect by using (jㄱ) which join the two poly line in one. The final 2d cad file for the road is shown below.

Poly-line format of road lines to create a face in sketch up

I didn’t create same for the building because the building blocks will cover the footprint surface so it will be hidden. Then I project the road line in the site landscape and used it in a sketch up. The final product of sketch up is looks like this. (Some might think why I take from rhino to sketch up again and again, there are two reason, first I am beginner in rhino in the time I was involve in this project but I have the good skills in sketch up model making. I also need a box below the land, which when I tried to create in the rhino, the size increase very fast, and since I have made all the building 3D in sketch up). Anyway the sketch up file is compatible with various other 3D software so I can enjoy different software advantage. The final model for the VR is then look like this.

final sketch up model for VR

So after finishing the 3rd model, I need to visualize the data above the 3D model. I tried to use unity, but at last I couldn’t see the final product in the virtual reality. Which lead me to use rhino for data visualization. Since we didn’t have a real data of the city on the time we are making the project, I create a fake data. So the data I need was related to the roads, so I need a coordinate of the road. For that I used the previous work, where I had created road only in the rhino. I used drape point grid over object. for that I take a spacing value 3 which gives me all the points over the roads, parking and pedestrian area only. Then I manually separate the points in 3 groups. The points over the main highway are grouped as highway road, the points over pedestrian and parking space are grouped as second and the points over the internal roads where the speed of vehicle is below 25 (assume) are grouped in third. The grouping can be seen in below figure.

points separation (yellow part) for different function of road

Finally,  I need an object on that point to represent the information about the road. Since in this method information will the explain through space separation, I do not need different height within the represent cube. before that I extract the x,y,z value of the each point thinking of I will use x, y,z value to assign the object . (Actually I did too) to extract the x,y,z value I use the python code that my friend Jin prepared before. Below is the python script.

import rhinoscriptsyntax as rs


def exportData():
    pts = rs.GetObjects("Select")
    file_object = open("points.csv", "w")
    for pt in pts:
        coord = rs.PointCoordinates(pt)
        dataLine = str(coord) + " ,\n"
        file_object.writelines(dataLine)
        
    file_object.close()
    print("data export done")



def main():
    exportData()

main()

This script give me a Geo location value of all points. after that I need a code to assign a object into the xyz points. I asked help to my another friend Da-young. With her help following script is prepared.

import Rhino
import scriptcontext
import System.Drawing
import rhinoscriptsyntax as rs
import csv

def readFile():
    f = open('data.csv', 'r')
    rd = csv.reader(f)
    for line in rd:
        x=float(line[0])
        y=float(line[1])
        z=float(line[2])
        AddMaterial(x,y,z)
    f.close()

def writeFile():
    f = open('data.csv', 'w')
    wr = csv.writer(f)
    #wr.writerow([1,2,3])
    wr.writerow([100,100,100])
    f.close()


def AddMaterial(x,y,z):
    # materials are stored in the document's material table
    index = scriptcontext.doc.Materials.Add()
    print(index)
    mat = scriptcontext.doc.Materials[index]
    mat.DiffuseColor = System.Drawing.Color.Chocolate
    mat.SpecularColor = System.Drawing.Color.CadetBlue
    mat.CommitChanges()

    # set up object attributes to say they use a specific material
    sp = Rhino.Geometry.Sphere(Rhino.Geometry.Plane.WorldXY, 5)
    attr = Rhino.DocObjects.ObjectAttributes()
    attr.MaterialIndex = index
    attr.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject
    scriptcontext.doc.Objects.AddSphere(sp, attr)
    
    # add a sphere without the material attributes set
    sp.Center = Rhino.Geometry.Point3d(x, y, z)
    scriptcontext.doc.Objects.AddSphere(sp)

    scriptcontext.doc.Views.Redraw();
    
def changeMat(obj, index, color):
    name = "material" + str(index)
    print(index)
    
    rs.MaterialName(index, name)
    rs.MaterialColor(index, color)

    attr = Rhino.DocObjects.ObjectAttributes()

    attr.MaterialIndex = index
    attr.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject

    doc.Objects.AddBrep(obj, attr)

def MakeMaterial():
    name = "test"
    color = rs.CreateColor(100,0,0)
    mat = Rhino.DocObjects.Material()
    mat.Name = name
    mat.DiffuseColor = color
    index = scriptcontext.doc.Materials.Add()
    
    rendmat = Rhino.Render.RenderMaterial.CreateBasicMaterial(mat)
    scriptcontext.doc.RenderMaterials.Add(rendmat)
    
    sp = Rhino.Geometry.Sphere(Rhino.Geometry.Plane.WorldXY, 5)
    attr = Rhino.DocObjects.ObjectAttributes()
    attr.MaterialIndex = index
    attr.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject
    scriptcontext.doc.Objects.AddSphere(sp, attr)


if __name__=="__main__":
    #AddMaterial()
    #MakeMaterial()
    #writeFile()
    readFile()

The code was pretty complex to understand, still I can get a object in the assign point. but for that I used a simpler python script. below is the script that I used.

import Rhino
import scriptcontext
import System.Drawing
import rhinoscriptsyntax as rs
import csv

def readFile():
    f = open('highway_data.csv', 'r')
    rd = csv.reader(f)
    ## This is a repetition parts to read the csv data
    for line in rd:
        x=float(line[0])
        y=float(line[1])
        z=float(line[2])
        mypoint = (x,y,z)
        myRadius = 4500
        sph = rs.addcube(mypoint, myRadius)
        rs.ObjectColor(sph,(255,150,0))
    f.close()



if __name__=="__main__":
    #AddMaterial()
    #MakeMaterial()
    #writeFile()
    readFile()

The file after getting a sphere in each point is very heavy, 1.4GB which was impossible to open in the irish vr. so I search another method.

In this method, I first convert the points into points cloud by using command pointcloud and then select all the necessary points. After that I used a new code, which help me to assign required object with its original material, color and scale in to the points. so I assign a sphere and used a following python script.

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def populate_pointcloud():
    
    cloud_id = rs.GetObject('Select Pointcloud')
    
    seed_id = rs.GetObject('Select Seedmesh')
    
    pcloud = rs.coercegeometry(cloud_id)
    
    seed = rs.coercegeometry(seed_id)
    for item in pcloud:
        color = item.Color
        location = item.Location
        
        item_seed = seed.Duplicate()
        item_seed.Translate(Rhino.Geometry.Vector3d(location))
        
        item_id = sc.doc.Objects.Add(item_seed)
        rs.ObjectColor(item_id, color)
        
populate_pointcloud()

With this I populate first sphere which was again heavy so I tried simple cube, came out the cube will not create big file. Later I also tried to use a cube with a name above what represent what. But that also create big file. So after 3 time using the scripts, I get the final result of data cube above the model. The final product is then watched in the irish VR . Below are the final photo and of final product. The red color represent the highways, the green represent the predestination and parking space and the brown color represent the internal slow speed road. The video can be watched here.

Published by Dibash Adhikari

I am a qualified architect and urban planner actively engaged in research exploring the areas of digital fabrication, virtual reality, and smart city development.

One thought on “Using data cubes in city model by using rhino to visualize in virtual reality.

Leave a comment

Design a site like this with WordPress.com
Get started