Subject: CGAL users discussion list
List archive
- From: elhassan Abdou <>
- To:
- Subject: [cgal-discuss] Re: reading 3D array as image
- Date: Sat, 10 Dec 2011 22:01:53 +0100
Hi
I think the best thing to do to avoid reading from the file *.inr is to
inherit the Image_3 file. I am showing here a class inherited from Image_3
and it works fine with me. The function private_read should be called that is
why inherited this function
class VRNImage3 : public CGAL::Image_3{
public:
void constructCGALImage(const VolumeHandle* outputVolume_){
const tgt::svec3 outputdim = outputVolume_->getDimensions();
const tgt::vec3 spacing = outputVolume_->getSpacing();
const Volume* outputVolume =
outputVolume_->getRepresentation<Volume>();
const VolumeAtomic<uint8_t>*outputVolume18 = static_cast<const
VolumeAtomic<uint8_t>*>(outputVolume);
unsigned int i,j,k;
uint8_t *volumearray =new
uint8_t[outputdim.z*outputdim.y*outputdim.x];
uint8_t *vptr= volumearray;
for(k=0;k<outputdim.z;k++){
for(j=0;j<outputdim.y;j++){
for(i=0;i<outputdim.x;i++){
vptr[k*outputdim.x*outputdim.y+j*outputdim.x+i] =
outputVolume18->voxel(i,j,k);
}
}
}
_image* vrnimage = _initImage();
vrnimage->vectMode = VM_SCALAR;
vrnimage->xdim = outputdim.x;
vrnimage->ydim = outputdim.y;
vrnimage->zdim = outputdim.z;
vrnimage->vdim = 1;
vrnimage->vx = 0.585938;
vrnimage->vy = 0.585938;
vrnimage->vz = 2;
/*vrnimage->cx = 128;
vrnimage->cy = 128;
vrnimage->cz = 36;*/
vrnimage->endianness = END_LITTLE;
vrnimage->wdim = 1;
vrnimage->wordKind = WK_FIXED;
vrnimage->sign = SGN_UNSIGNED;
vrnimage->data =
ImageIO_alloc(outputdim.x*outputdim.y*outputdim.z*vrnimage->wdim);
memcpy(vrnimage->data,(void*)volumearray,outputdim.x*outputdim.y*outputdim.z*vrnimage->wdim);
this->private_read(vrnimage);
/*CGAL::Image_3 image(_createImage(outputdim.x,
outputdim.y, outputdim.z, 1, spacing.x, spacing.y, spacing.z, 1,
WK_FIXED,SGN_UNSIGNED));
_image* vrnptr = image.image();
vrnptr->data=(void*)volumearray;
//ImageIO_free(image.data());
//image.set_data(volumearray);
//CGAL::Image_3 image;
//image.read("/Users/elhassanabdou/voreen/datasets/elhassan/volumeleadbin.inr");
*/
}
have a nice weekend
On Dec 10, 2011, at 1:42 AM, elhassan Abdou wrote:
> Hi
>
> I need to put mesh generator in my framework. It does not make any sense to
> me to write the data to *.inr file and read it back. I allocate one
> dimensional pointer and put data from 3D data. I borrow the data from the
> raw reader.
> Here is snippet of code but it does not work out. Can any one help??
> The outputVolume is structure contain 3D array.
> uint8_t *volumearray =new uint8_t[outputdim.z*outputdim.y*outputdim.x];
> uint8_t *vptr= volumearray;
> for (i=0; i<(outputdim.x); i++) {
> for (j=0; j<(outputdim.y); j++) {
> for (k=0; k<(outputdim.z); k++) {
> vptr[k*outputdim.x*outputdim.y + j*outputdim.x +
> i]=static_cast<uint8_t>(outputVolume->getVoxelFloat(i,j,k));
> //++idx;
> }
> }
> }
> /*for(size_t i=0;i<outputVolume->getNumVoxels();i++)
>
> vptr[i]=static_cast<uint8_t>(outputVolume->getVoxelFloat(i));
> std::cout<<volumearray[500];*/
> CGAL::Image_3 image(_createImage(outputdim.x,
> outputdim.y, outputdim.z, 1, spacing.x, spacing.y, spacing.z, 1,
> WK_FIXED,SGN_UNSIGNED));
> ImageIO_free(image.data());
> image.set_data(volumearray);
>
> Have a nice week
>
> Elhassan Abdou
> Computational Science master student
> Uppsala
>
>
Elhassan Abdou
Computational Science master student
Uppsala
- [cgal-discuss] reading 3D array as image, elhassan Abdou, 12/10/2011
- [cgal-discuss] Re: reading 3D array as image, elhassan Abdou, 12/10/2011
- [cgal-discuss] Re: reading 3D array as image, elhassan Abdou, 12/10/2011
Archive powered by MHonArc 2.6.16.