Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is this the correct way to assign array value?

Reply
Thread Tools

Is this the correct way to assign array value?

 
 
radishcarrot
Guest
Posts: n/a
 
      09-01-2006
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.

 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      09-01-2006
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
 
Reply With Quote
 
 
 
 
george.priv@gmail.com
Guest
Posts: n/a
 
      09-01-2006

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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is this the correct way to delete an array?? justineee Java 8 10-30-2008 06:02 PM
Correct White Balance Doesn't Mean Correct Color?? jim evans Digital Photography 28 12-27-2005 05:10 AM
Correct way to blank a text value in an array? Sam Wuebben Javascript 0 02-03-2004 11:55 PM
correct or not correct? Dan HTML 7 10-02-2003 10:16 PM
To correct my program. please, check to find errors and correct me. joon Java 1 07-08-2003 06:13 AM



Advertisments