FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Information Visualization
(Moderators: forkinsocket, REAS)
   map an image to a mesh
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: map an image to a mesh  (Read 2802 times)
_C


map an image to a mesh
« on: Nov 14th, 2004, 7:49pm »

hi everybody,
 
i want to map an image onto a polygon mesh
while creating the mesh following a [][]
pointarray. has someone done that so far?
 
this would help me a lot further!  
thanks for any hints
 
c
 
fjen

WWW
Re: map an image to a mesh
« Reply #1 on: Nov 14th, 2004, 9:41pm »

this should get you started:
 
http://processing.org/discourse/yabb/board_Proce55ing_Software__action_display_num_1079193026.html
 
/F
 
_C


Re: map an image to a mesh
« Reply #2 on: Nov 14th, 2004, 11:34pm »

hi fjen,
 
thank you, i knew this one, nevertheless it remains
hard to imagine what the u, v thing does.  
 
it works to map an image onto a mesh, problems remai-
ning are: how to get the positions of an images` points with certain colors into an [][]array, not  
using a Vector for that since it is hard to handle  
with the iteration things.  
 
bye
c
 
fjen

WWW
Re: map an image to a mesh
« Reply #3 on: Nov 15th, 2004, 1:29am »

think of them as being x and y coordinates in the texture-2d-space. so every point in your mesh represents/holds one point in the texture.
 
how exactly is the data arranged in you [][]array?
 
/F
 
_C


Re: map an image to a mesh
« Reply #4 on: Nov 15th, 2004, 11:59am »

so, what i exactly wanted to do is:
reading an transparent image, and put every position
in the image with an alpha higher than zero into
an array. the problem is: how can i get the positions
into a [][]array?  
 
ido: for(...img.width;i++) {
  for(...img.height; j++) {  
    if(alpha(pixels[j][i])>0) {
     //and then i need j, i in an [][]    
    }
   }
  }
pixels beeing an array with the pixels, i only  
want to have the indices. strange thing.  
c
 
fjen

WWW
Re: map an image to a mesh
« Reply #5 on: Nov 15th, 2004, 5:42pm »

i don't seem to get the big picture.
 
why is it you need the [][] to hold the same indices as in pixels? this is just more or less duplicating pixels[][] in the end ... because if you'd have alpha==0 at j = 10 and i =100 then the_array[][] would be of size 10*100. get it?
to read this value you'd have to run thru the_array[][] the same way as you do right now with pixels[][], so in the end you could just run thru pixels itself and test for alpha==0 again.
 
maybe you could give a little more insight of what you are trying to do? some code maybe?
 
i just read your original post, and i think you're just on the wrong way in creating these points(array) (from the image ?) ... using a [][] array for a mesh makes great sense if all the rows are of same length, but that's not what you are gonna end up with doing it the way you've tried.
 
/F
 
_C


Re: map an image to a mesh
« Reply #6 on: Nov 15th, 2004, 7:56pm »

hi fjen,
 
you are right, this doesnt really make sense.  
the point was just thut later on, i maybe wanted
to change the z values of the points i got out  
of the picture, besides, it was the aim to have
an array with 'non alpha coordinates', so that  
i could later on draw the image with what i want,
eg boxes, rects and so on.  
 
so, if i wanted to create the array, i would do it
like this
 
 for(int i=0; i<pixels.length; i++) {
   for(int j<pixels.width; j++) {
     if(alpha(pixels[j][i]>0) {
   newarray[j][i] = j*i;  
 
 }
    }
  }  
 
?  
 
 
heres how i did it:
 
Code:

int imgwidth, imgheight;
int res=30;
float d=1;
float zValues[][];
BImage img;
float rtx, rtz;
int imgArray[][];
int t, tt;
float noiseScale, noiseScale2;
color strokeColors[][];
 
 
void setup() {
 
  img=loadImage("9045welt_outlined.gif"); imageMode(CENTER_DIAMETER);
   
 
  imgArray = new int[img.height][img.width];
  for(int i=0; i<img.width; i++) {
    for(int j=0; j<img.height; j++) {
 imgArray[j][i] = img.pixels[j*img.height+i];
 
    }
  }
 
  imgwidth =  img.width;
  imgheight=  img.height;
 
  zValues = new float[imgheight][imgwidth];
  for(int i=0; i<zValues.length; i++) {
    for(int j=0; j<zValues[0].length; j++) {
 noiseScale+=0.0015; noiseScale2+=0.003;
 zValues[i][j] = noise(noiseScale, noiseScale2)*50  ;//noise(noiseScale, noiseScale2);
 
    }
  }
   
  zValues[10*res][15*res] = 200;
  zValues[16*res][15*res] = -200;
   
  strokeColors = new color[imgheight][imgwidth];
   getStrokeColor();
  size(1024, 768);
  background(150);
   
}
 
void rotation() {
  rtx+=((mouseY-height/2)*0.5-rtx)*0.001;
  rtz+=((mouseX-width/2)*0.5-rtz)*0.001;
  rotateX(rtx); rotateZ(rtz);
 
}
 
void loop() {
  clear();  
  mesh();
 
 
}
 
 
void mesh() {
 
  push();
  translate(width/2, height/2, 0);
  scale(0.8);
  rotation();
   
  for(int i=0; i<imgwidth-res; i+=res) {
 
    beginShape(TRIANGLE_STRIP);
 
    for(int j=0; j<imgheight; j+=res) {
 
 t = int(zValues[j][i] * d);
 tt = int(zValues[j][i+res] * d);
 
 
 stroke(255,255,255,12);
 
   
 texture(img);
 
 vertex(i-imgwidth/2,  j-imgheight/2,t,i,j);
 vertex(i+res-imgwidth/2,  j-imgheight/2, tt, i+res, j);
 
    }
 
    endShape();
  }
  pop();
 
}
 
void getStrokeColor() {
   for(int i=0; i<img.width-res; i++) {
    for(int j=0; j<img.height-res; j++) {
 if(alpha(imgArray[j][i])>0) {
  strokeColors[j][i] = color(100,100,100);
   
 }
 else strokeColors[j][i] = color(255,255,255,0);
 
     }
   }  
}

 
 
fjen

WWW
Re: map an image to a mesh
« Reply #7 on: Nov 15th, 2004, 9:36pm »

what i'd do is:
create a simple class to hold you coordinates & alpha:
 
class Point3D
{
  float x, y, z, u, v;
  int alpha;
  Point3D( float x, float y, float z, float u, float v, int alpha)
  {
    this.x = x; this.y = y; ....
  }
}
 
create an array to store the points:
 
int wres = img.width/res;
int hres = img.height/res;
 
Point3D points = new Point3D[wres*hres];
for (int wx=0; wx <wres; wx++)
{
  for (int hy=0; hy <hres; hy++)
  {
    // calculate x, y, noise and u, v here ...
   int a = alpha( img.pixels[wx*res + (hy*res) * img.width] );
    points[wx+hy*wres] = new Point3D(wx, hy, your_noise, u, v, a);
}
}
 
now you don't have to recalculate eveything in the loop ..
 
to create/draw your mesh simply use somehting like:
 vertex(points[0].x, points[0].y, points[0].z, points[0].u, points[0].v);
 
i have not tested the code ... just for illustration.
 
/F
 
_C


Re: map an image to a mesh
« Reply #8 on: Nov 16th, 2004, 1:58am »

thank you! that was fine. didnt try the code,
but i will when i can keep my eyes opened again
 
c
 
_C


Re: map an image to a mesh
« Reply #9 on: Nov 16th, 2004, 2:02am »

..the reason why i tried to store it in a matrix
like [][] is that later on, i may would have to  
define exact positions on a mesh, and it was easy
for me to imagine where the points were when i can
imagine them at a specific point on the matrix, for
your consideration.
 
fjen

WWW
Re: map an image to a mesh
« Reply #10 on: Nov 16th, 2004, 3:18am »

you still can store the points3d in your 2d-array. multi-dimensional arrays can be pretty not-fun ... but in your case it's gonna be static(*) i think ...
 
so as a little guten-morgen-gutsele:
 
Point3D[][] points = new Point3D[wres][hres];
for (int wx=0; wx <wres; wx++)  
{  
  for (int hy=0; hy <hres; hy++)  
  {  
    // calculate x, y, noise and u, v here ...  
   int a = alpha( img.pixels[wx*res + (hy*res) * img.width] );  
    points[wx][hx] = new Point3D(wx, hy, your_noise, u, v, a);  
}  
}
 
sleep well,
/F
 
(*) static not in a java sense ... not to be resized later i ment.
« Last Edit: Nov 16th, 2004, 3:19am by fjen »  
_C


Re: map an image to a mesh
« Reply #11 on: Nov 16th, 2004, 8:45pm »

thats great. but could you explain what you meant  
with 'guten-morgen-gutsele'?
 
fjen

WWW
Re: map an image to a mesh
« Reply #12 on: Nov 16th, 2004, 10:04pm »

good-morning-cookie ... thought you were from germany because the image you used in your code was called welt-something ... /F
« Last Edit: Nov 16th, 2004, 10:04pm by fjen »  
_C


Re: map an image to a mesh
« Reply #13 on: Nov 17th, 2004, 2:59pm »

ahh, that feeds the dog in me
 
fjen

WWW
Re: map an image to a mesh
« Reply #14 on: Nov 17th, 2004, 5:49pm »

tips & treats that is ...
 
Pages: 1 

« Previous topic | Next topic »