copy from 2D array to 3D array

Discussion in 'C' started by hsash, Oct 12, 2009.

  1. hsash

    hsash New Member

    Joined:
    Oct 12, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hi all!

    im having trouble copying from 2d array to 3d array. im not sure this is correct. can anyone help me? i suspect the error is in the last line.

    Code:
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] TwoDimToThree()
    { 
    [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i,j,k; 
    [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] row=512,col=512,slice;
    [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]//int slice_no = sav_slice_no[300];
    [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](slice=0;slice<slice_no;slice++)
    { 
    [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](j=0;j<row;j++) 
    { 
    [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](k=0;k<col;k++)
    { 
    Dim_image3D[slice][j][k]=image3D[slice][pixel]; 
    } 
    } 
    }
    }
    [/SIZE]
    thank you!
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    389
    Trophy Points:
    83
    your image2D you are copying should be function of loop variables.
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Impossible to answer, since we don't know what you're trying to achieve. Are you copying from the 2D array to a single "slice" of the 3D array, or are you copying it to multiple slices? Are you mapping 2D pixels to exactly the same pixel in the slice, i.e. does 2D[p][q] get stored in 3D[slice][p][q]?

    Is your 2D array really called "image3D"? Using misleading variable names is a great way to confuse yourself.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice