Is this the correct way to assign array value?

Discussion in 'C++' started by radishcarrot, Sep 1, 2006.

  1. radishcarrot

    radishcarrot Guest

    unsigned char *m_pVolumeData;
    m_pVolumeData = new unsigned char[m_nSizeX * m_nSizeY * m_nSizeZ];

    FILE *fp = fopen(filename, "rb");
    if(fp) {
    fread(m_pVolumeData, 1, m_nSizeX * m_nSizeY * m_nSizeZ, fp);
    fclose(fp);
    }

    unsigned char *pSrcPixels = new unsigned char[m_nSizeX * m_nSizeY];
    for(int m=0; m<m_nSizeX * m_nSizeY; m++) { //copy the value to
    psrcpixels
    //is this the correct way to assign the value to another array??
    pSrcPixels[m] = m_pVolumeData[sliceNo * (m_nSizeX * m_nSizeY)+m];
    }

    Hi, like to check with you all.
    Whether within the for loop, assigning the values are correct? I was to
    assign the value of m_pVolume to pSrcPixels but it doesnt seem to
    assign it correct. Pls help.
     
    radishcarrot, Sep 1, 2006
    #1
    1. Advertising

  2. radishcarrot

    Kai-Uwe Bux Guest

    radishcarrot wrote:

    > unsigned char *m_pVolumeData;
    > m_pVolumeData = new unsigned char[m_nSizeX * m_nSizeY * m_nSizeZ];
    >
    > FILE *fp = fopen(filename, "rb");
    > if(fp) {
    > fread(m_pVolumeData, 1, m_nSizeX * m_nSizeY * m_nSizeZ, fp);
    > fclose(fp);
    > }
    >
    > unsigned char *pSrcPixels = new unsigned char[m_nSizeX * m_nSizeY];
    > for(int m=0; m<m_nSizeX * m_nSizeY; m++) { //copy the value to
    > psrcpixels
    > //is this the correct way to assign the value to another array??
    > pSrcPixels[m] = m_pVolumeData[sliceNo * (m_nSizeX * m_nSizeY)+m];


    Shouldn't this be:

    pSrcPixels[m] = m_pVolumeData[sliceNo * m_nSizeZ + m];

    > }
    >
    > Hi, like to check with you all.
    > Whether within the for loop, assigning the values are correct? I was to
    > assign the value of m_pVolume to pSrcPixels but it doesnt seem to
    > assign it correct. Pls help.



    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Sep 1, 2006
    #2
    1. Advertising

  3. radishcarrot

    Guest

    Kai-Uwe Bux wrote:
    > radishcarrot wrote:
    >
    > > unsigned char *m_pVolumeData;
    > > m_pVolumeData = new unsigned char[m_nSizeX * m_nSizeY * m_nSizeZ];
    > >
    > > FILE *fp = fopen(filename, "rb");
    > > if(fp) {
    > > fread(m_pVolumeData, 1, m_nSizeX * m_nSizeY * m_nSizeZ, fp);
    > > fclose(fp);
    > > }
    > >
    > > unsigned char *pSrcPixels = new unsigned char[m_nSizeX * m_nSizeY];
    > > for(int m=0; m<m_nSizeX * m_nSizeY; m++) { //copy the value to
    > > psrcpixels
    > > //is this the correct way to assign the value to another array??
    > > pSrcPixels[m] = m_pVolumeData[sliceNo * (m_nSizeX * m_nSizeY)+m];

    >
    > Shouldn't this be:
    >
    > pSrcPixels[m] = m_pVolumeData[sliceNo * m_nSizeZ + m];


    This is incorrect, assuming the data is sequence of frames size
    m_nSizeX x m_nSizeY the original poster was correct. It may be that
    your assumption about file format is wrong. Look what you see as an
    image and it may give you some clues. In particular check if image is
    simply distorted or it has no sense at all.

    Regards,

    George Privalov

    >
    > > }
    > >
    > > Hi, like to check with you all.
    > > Whether within the for loop, assigning the values are correct? I was to
    > > assign the value of m_pVolume to pSrcPixels but it doesnt seem to
    > > assign it correct. Pls help.

    >
    >
    > Best
    >
    > Kai-Uwe Bux
     
    , Sep 1, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. joon
    Replies:
    1
    Views:
    533
    Roedy Green
    Jul 8, 2003
  2. Dan

    correct or not correct?

    Dan, Oct 2, 2003, in forum: HTML
    Replies:
    7
    Views:
    469
  3. baumann@pan
    Replies:
    8
    Views:
    767
    Achintya
    May 10, 2005
  4. Dew
    Replies:
    7
    Views:
    368
  5. Sam Wuebben

    Correct way to blank a text value in an array?

    Sam Wuebben, Feb 3, 2004, in forum: Javascript
    Replies:
    0
    Views:
    166
    Sam Wuebben
    Feb 3, 2004
Loading...

Share This Page