[vtkusers] Re-post: how to use own 3d array to create image

Liam Kurmos quantum.leaf at googlemail.com
Wed Feb 10 05:31:58 EST 2010


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


On Wed, Feb 10, 2010 at 2:41 AM, Wei Huang <huangwei at ucar.edu> wrote:
> Begin forwarded message:
>
> From: Wei Huang <huangwei at ucar.edu>
> Date: February 9, 2010 3:28:46 PM MST
> To: vtkusers at vtk.org
> Subject: how to use own 3d array to create image
> Hi, there,
> I am learning VTK through the examples.
> If I can read in a 3d array: float_array, with dimension: nx, ny, nz.
> How can I create image use this float_array, such as in:
> demo_vtk_contour2D.cxx
> Thanks in advance,
> Wei Huang
> huangwei at ucar.edu
> VETS/CISL
> National Center for Atmospheric Research
> P.O. Box 3000 (1850 Table Mesa Dr.)
> Boulder, CO 80307-3000 USA
> (303) 497-8924
>
>
>
>
>
>
> _______________________________________________
> 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