File Exchange

image thumbnail

Map texture to patch

version 1.1 (2.32 KB) by

patchTexture maps a texture onto a patch object

6 Downloads

Updated

View License

SYNOPSIS: patchTexture(patchHandle,texture)

INPUT
patchHandle: handle to patch object
texture: texture to map onto the surface defined via patch
   Texture can be a grayscale or an RGB image

OUTPUT
none - the texture is mapped onto the patch identified by
patchHandle by reading the image at the [x,y] coordinates
of the vertices of the patch. The vertex coordinates are
rescaled so that a maximum of the image can be read.

 EXAMPLE
            [xx,yy,zz] = ndgrid(-100:100,-100:100,-100:100);
            img = xx.^2 + yy.^2 + zz.^2 < 99^2;
            img = convn(img,ones(5,5,5)/(5*5*5));
            p = isosurface(img,0.5);
            ph = patch(p);
            set(gca,'visible','off')
            axis equal
            texture = imread('autumn.tif');
            patchTexture(ph,texture)
            view(58,82)

SEE ALSO patch, surface

Comments and Ratings (2)

Your documentation needs to be clearer. You are not doing actual texture mapping on the surface, you are just coloring each vertex (and linearly interpolating within a face) with the color retrieved from the texture. Very misleading

Hi Jonas,

I tried your code on serveral images and it is not doing what it suppose to do. The patched region get filled completely with one color from the image.

Try this example:
----------------
clc; clear all; close all;

I=imread('corn.tif');

verts=[ 0 0;
        10000 0;
        10000 10000;
        0 10000];

faces= [ 1 2 3 4];

p = patch('Faces',faces,'Vertices',verts,.....
   'FaceColor','w','CDataMapping','scaled');

patchTexture(p,I);

Updates

1.1

Fixed a bug due to a missing function (thanks Ken, for reporting!). Also, updated the function so that one texture can be applied to several patches at once.

MATLAB Release
MATLAB 7.10 (R2010a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video