[vtkusers] Re-post: how to use own 3d array to create image
Liam Kurmos
quantum.leaf at googlemail.com
Wed Feb 10 08:56:43 EST 2010
I forgot to reference in my last post your example:
http://www.cmake.org/Wiki/VTK/Examples/IterateImageData
which is the way i do it now.
I was thinking there may be a method that lets you set a 3D array as
scalars that might be faster for performance critical tasks but
haven't needed to do that yet.
Liam
On Wed, Feb 10, 2010 at 12:39 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
> On Wed, Feb 10, 2010 at 5:31 AM, Liam Kurmos <quantum.leaf at googlemail.com>
> wrote:
>>
>> Hi,
>>
>> I'm still pretty new to vtk myself and not 100% sure if this is what
>> you want but have a look at the code below. I think i adapted it from
>> the guide. If it's useful i could make an example.
>>
>> int xDim, yDim,zDim;
>> xDim=yDim=zDim=26;
>> float z,y,x,kOffset,jOffset,offset;
>> vtkImageData *vol = vtkImageData::New();
>> vol->SetDimensions(xDim,yDim,zDim);
>> vol->SetOrigin(-1,-1,-1);
>>
>> float sp=(float)1.0/(xDim-1);
>> vol->SetSpacing(sp,sp,sp);
>>
>> vtkFloatArray *scalars=vtkFloatArray::New();
>> for (int k=0;k<zDim;k++){
>>
>> z=-0.5+k*sp;
>> kOffset= k*xDim*yDim;
>> for(int j=0;j<yDim;j++){
>> y=-0.5+j*sp;
>> jOffset=j*xDim;
>> for (int i=0;i<xDim;i++){
>> x=-0.5+i*sp;
>> float s=x*x+y*y+z*z-(0.4*0.4);
>>
>> offset=i+jOffset+kOffset;
>> scalars->InsertTuple1(offset,s);
>> }
>> }
>> }
>>
>> vol->GetPointData()->SetScalars(scalars);
>>
>> scalars->Delete();
>>
>> vtkMarchingCubes *iso = vtkMarchingCubes::New();
>> iso->SetInput(vol);
>> iso->SetNumberOfContours(1);
>> iso->SetValue(0, 0);
>>
>> Liam
>
> I believe you could also do this ( can't try it right now)
> double* volValue = static_cast<double*>vol->GetScalarPointer(i, j, k);
> volValue = whatever you want pixel (x,y,z) to equal
> Setting pixels in linear order always just seems to me like it is asking for
> trouble :) This method (if it is legitimate) lets you set the pixels via
> their position in the image.
> Thanks,
>
> David
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
More information about the vtkusers
mailing list