home processing download documents tutorial python tutorial gallery source about
 Python Tutorials (back to the list of tutorials)

Mapping Images on Geometries

     Control Line Length by Image

You can use bitmap image as input information to control geometries by IImageMap class. You can extract a value out of an image at a specific u-v location with get(double,double) method. The first argument is u location ranging from 0.0 to 1.0, the second is v, and it returns a value ranging from 0.0 to 1.0 which means a gray scale value (black is 0.0 and white is 1.0). IImageMap can read images in JPEG, PNG and GIF formats. The input bitmap file should be stored in the "data" folder inside the Processing sketch folder in the same way as you store a 3D data file to import.

The sample input file used in the example is below.

surface6.3dm

The input bitmap used in the example is this.

add_library('igeo')

size(480, 360, IG.GL)

IG.open("surface6.3dm")
surfaces = IG.surfaces()

map = IImageMap("map1.jpg")

for surf in surfaces : 
    unum = 50
    vnum = 50
    uinc = 1.0/unum
    vinc = 1.0/vnum
    for i in range(unum) :
        for j in range(vnum) : 
            val = map.get( i*uinc, j*vinc )
            
            pt1 = surf.pt( i*uinc, j*vinc )
            pt2 = surf.pt( i*uinc, j*vinc, val*-10 )
            ICurve(pt1, pt2).clr(0)


     Control Depth of Surface by Image

Here is an example to differentiate offset depths of a vertex of panel.
The sample input file used in the example is below.

surface7.3dm

The input bitmap used in the example is this.

add_library('igeo')

size(480, 360, IG.GL)

IG.open("surface7.3dm")
surfaces = IG.surfaces()

map = IImageMap("map1.jpg")

for surf in surfaces : 
    unum = 20
    vnum = 20
    uinc = 1.0/unum
    vinc = 1.0/vnum
    for i in range(unum) :
        for j in range(vnum) : 
            val = map.get( i*uinc, j*vinc )
            
            pt11 = surf.pt( i*uinc, j*vinc )
            pt21 = surf.pt( (i+1)*uinc, j*vinc )
            pt12 = surf.pt( i*uinc, (j+1)*vinc, val*-4 )
            pt22 = surf.pt( (i+1)*uinc, (j+1)*vinc )
            ISurface(pt11, pt12, pt22, pt21).clr(.3)
    surf.del()


     Control Width of Panel by Image

Here is an example to control the width of panel by changing sampling location of the input surface with the image value. The code below is control the width in v direction.

Here is the input bitmap used in the example.

add_library('igeo')

size(480, 360, IG.GL)

IG.open("surface7.3dm")
surfaces = IG.surfaces()

map = IImageMap("map1.jpg")

for surf in surfaces : 
    unum = 20
    vnum = 20
    uinc = 1.0/unum
    vinc = 1.0/vnum
    for i in range(unum) :
        for j in range(vnum) : 
            val = map.get( i*uinc, j*vinc )
            
            pt11 = surf.pt( i*uinc, j*vinc )
            pt21 = surf.pt( (i+1)*uinc, j*vinc )
            pt12 = surf.pt( i*uinc, (j + val)*vinc )
            pt22 = surf.pt( (i+1)*uinc, (j + val)*vinc )
            ISurface(pt11, pt12, pt22, pt21).clr(.3)
    surf.del()

add_library('igeo')

size(480, 360, IG.GL)

IG.open("surface7.3dm")
surfaces = IG.surfaces()

map = IImageMap("map1.jpg")

for surf in surfaces : 
    unum = 20
    vnum = 20
    uinc = 1.0/unum
    vinc = 1.0/vnum
    for i in range(unum) :
        for j in range(vnum) :
            val = map.get( i*uinc, j*vinc )
            
            pt11 = surf.pt( i*uinc, j*vinc )
            pt21 = surf.pt( (i + val)*uinc, j*vinc )
            pt12 = surf.pt( i*uinc, (j + 1)*vinc )
            pt22 = surf.pt( (i + val )*uinc, (j + 1)*vinc )
            ISurface(pt11, pt12, pt22, pt21).clr(.3)
    surf.del()


     Control Rotation by Image

Here is an example to rotate panelized surfaces by sampled values of the image. The input bitmap used in the example is this.



add_library('igeo')

size(480, 360, IG.GL)

IG.open("surface7.3dm")
surfaces = IG.surfaces()

map = IImageMap("map1.jpg")

for surf in surfaces : 
    unum = 20
    vnum = 20
    uinc = 1.0/unum
    vinc = 1.0/vnum
    for i in range(unum) :
        for j in range(vnum) :
            val = map.get( i*uinc, j*vinc )
            
            pt11 = surf.pt( i*uinc, j*vinc )
            pt21 = surf.pt( (i + 1)*uinc, j*vinc )
            pt12 = surf.pt( i*uinc, (j + (1-val) )*vinc )
            pt22 = surf.pt( (i + 1)*uinc, (j + (1-val) )*vinc )
            panel = ISurface(pt11, pt12, pt22, pt21).clr(.2)
            
            center = surf.pt( (i+0.5)*uinc, (j+0.5)*vinc )
            normal = surf.nml( (i+0.5)*uinc, (j+0.5)*vinc )
            panel.rot(center, normal, val*PI/4 )
    surf.del()


     Control Scaling by Image

Here is an example to scale panelized surfaces by sampled values of the image. The input bitmap used in the example is this.



add_library('igeo')

size(480, 360, IG.GL)

IG.open("surface7.3dm")
surfaces = IG.surfaces()

map = IImageMap("map1.jpg")

for surf in surfaces : 
    unum = 40
    vnum = 40
    uinc = 1.0/unum
    vinc = 1.0/vnum
    for i in range(unum) :
        for j in range(vnum) :
            val = map.get( i*uinc, j*vinc )
            
            pt11 = surf.pt( i*uinc, j*vinc )
            pt21 = surf.pt( (i + 1)*uinc, j*vinc )
            pt12 = surf.pt( i*uinc, (j + 1)*vinc )
            pt22 = surf.pt( (i + 1)*uinc, (j + 1)*vinc )
            panel = ISurface(pt11, pt12, pt22, pt21).clr(.2)
            
            center = surf.pt( (i+0.5)*uinc, (j+0.5)*vinc )
            # val is inverted by subtraction
            panel.scale(center, 1 - val )
    surf.del()


     Sampling Color of Image

Here is an example to use color of the image with the clr() method of IImageMap class. When the image is full color image, the value returned by get() method is a gray scale value when the color is converted into gray.

The input bitmap used in the example is this.

add_library('igeo')

size(480, 360, IG.GL)

IG.open("surface7.3dm")
surfaces = IG.surfaces()

map = IImageMap("map2.jpg")

for surf in surfaces : 
    unum = 40
    vnum = 40
    uinc = 1.0/unum
    vinc = 1.0/vnum
    for i in range(unum) :
        for j in range(vnum) : 
            val = map.get( i*uinc, j*vinc )
            
            pt11 = surf.pt( i*uinc, j*vinc )
            pt21 = surf.pt( (i + 1)*uinc, j*vinc )
            pt12 = surf.pt( i*uinc, (j + 1)*vinc, val*-4 )
            pt22 = surf.pt( (i + 1)*uinc, (j + 1)*vinc )
            panel = ISurface(pt11, pt12, pt22, pt21)
            
            panel.clr(map.clr( i*uinc, j*vinc ))
    surf.del()


(back to the list of tutorials)

HOME
FOR PROCESSING
DOWNLOAD
DOCUMENTS
TUTORIALS (Java / Python)
GALLERY
SOURCE CODE(GitHub)
PRIVACY POLICY
ABOUT/CONTACT