[vtkusers] need help about vtkImageData

med ali daalyusmo at yahoo.fr
Fri Jun 10 10:23:52 EDT 2005


Hi David,
 
do you speak french ??
i don't see how the data can be copied  like this  with this code;
 
-------------   data of image 0 
-------------   data of image 1
-------------   data of image 2
-------------   data image 3
-------------     ....
 
 
///////////////************the code *****************/////////////////////////////
 
void TimacBase::constructImagedata(CImageBoxFL *img_box,int nbr_slices,inter_slices)
{
 int width;
 int height;
 width = img_box->tab[0].imgAff->largeur;
 height = img_box->tab[0].imgAff->hauteur;
  imageData->SetScalarTypeToUnsignedChar();
  imageData->SetNumberOfScalarComponents(3);
  imageData->SetDimensions(width,height, nbr_slices);
  imageData->AllocateScalars();
  
  unsigned char *data = (unsigned char *) imageData->GetScalarPointer();
  int k = 0;
  for (k= 0; k<nbr_slices; k+=inter_slices) 
  {
  memcpy(data, img_box->tab[k].imgAff->data, nbr_slices*3*sizeof(unsigned char));  
 
  data += width * height *3*sizeof(unsigned char);
  }
} 
 
///////////////////*******************************************************************

thanks ,
*dali



David Cole wrote: Nope. (And again, please keep further questions on the list.)

When you call AllocateScalars you are allocating a chunk of memory that is for the raw image data of type unsigned char with 3 components for each voxel with 16x16x16 voxels. So you're allocating 16x16x16x3xsizeof(unsigned char) bytes which is expected to be used for the data. You need to copy your raw data into that block of memory to use the technique I've outlined.

You need something more like this:
  for (k= 0; k<16; ++k) 
  {
  memcpy(data, img_box->tab[k].imgAff->data, 16*3*sizeof(unsigned char));  // tab is an array og images 
  data += 16*16*3*sizeof(unsigned char);
  }

If you want to use the memory you've already got allocated for a vtkImageData, you need to dig in and figure out how it works inside or have somebody else chime in to help you. I don't know if that's easily done - I'm still a relative newcomer to VTK myself.


David


med ali wrote: hi,
 
thanks for your help
 
can you tell me if this part of code is right or not 
 i have wrote this :
 
 
////////////////////**********************  constructImageData***************/////////////////////////////
void TimacBase::constructImageData(CImageBoxFL *img_box)
{
  imageData->SetScalarTypeToUnsignedChar();
  imageData->SetNumberOfScalarComponents(3);
  imageData->SetDimensions(16, 16, 16);
  imageData->AllocateScalars();
  int i = 0;
  int j = 0;
  unsigned char r = 0;
  unsigned char g = 0;
  unsigned char b = 0;
  unsigned char *data = (unsigned char *) imageData->GetScalarPointer();
  int k = 0;
  for (k= 0; k<16; ++k) 
  {
  data=img_box->tab[k].imgAff->data;  // tab is an array og images 
  }
} 

David Cole <david.cole at kitware.com> a écrit :
If you need a 3d volume of bitmaps that are all the same x,y size, just do the same thing, but add an iteration over the z-dimension. The vtkImageData object supports 3 dimensions. Then, for each distinct value of z, you'll be jamming a separate bitmap into a given z-slice of the vtkImageData.

In the example, change the SetDimensions call to include more than one z value:
  imageData->SetDimensions(16, 16, 16);

Then add another loop to fill in the z data:
  int k = 0;
  for (k= 0; k<16; ++k) // as outer loop; i and j loops in here; conecptually, first slice filled is z=0, next z=1 and so on...

Then simply use the imageData object as the input to your algorithm, just like you would have used the output of the BMP reader...


David


 


---------------------------------
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
Téléchargez le ici ! 
		
---------------------------------
 Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
 Téléchargez le ici !  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050610/3253b973/attachment.htm>


More information about the vtkusers mailing list