[vtkusers] Problem with vtkImageData->GetScalarComponentAsFloat()

Peter F Bradshaw pfb at exadios.com
Fri Aug 3 20:08:51 EDT 2007


Hi Dzung;

On Thu, 2 Aug 2007, Dzung Manh Chu wrote:

> Hello all.
>
> I'm writing a C/C++ program in which I use VTK 4.4 (on Fedora platform). I'm trying to read a VTK-formated file and store data to an array. This is part of the code:
>     vtkImageData *coral = vtkImageData::New();
>
>     /* Set up an XML reader object */
>     vtkXMLImageDataReader *reader = vtkXMLImageDataReader::New();
>     /* Put here the file name of the data set */
>     reader->SetFileName("/MadracisMirabilisFirst.vti");
>
>     /* With vtkExtractGrid we can choose the volume of interest (VOI) and
>        subsample the data set */
>     vtkExtractVOI *voi = vtkExtractVOI::New();
>     voi->SetInput(reader->GetOutput());
>     reader->Update(); /* Read the data file */
>
>     /* Choose the volume of interest and do the resampling */
>     voi->SetSampleRate(8, 8, 8);
>     voi->SetOutput(coral);
>     voi->Update(); /* Apply the update */
>
>     /* Get the number of points in the data */
>     int extent[6];
>     coral->GetExtent(extent);
>
>     /* Get the spacing in the data. Because our data is in cm and the data of
>        coral is in mm, we have to multiply the spacing with 0.10 */
>     double spacing[3];
>     coral->GetSpacing(spacing);
>     spacing[0] *= 0.10;
>     spacing[1] *= 0.10;
>     spacing[2] *= 0.10;
>
>     /* Rotate the coral in a way that it stands correct in the computational
>        domain and save it in the array 'compdom'. This is for the fist and
>        second data set. This is for object 389 and 393! */
>     int X = (extent[1] - extent[0] + 1);
>     int Y = (extent[3] - extent[2] + 1);
>     int Z = (extent[5] - extent[4] + 1);
>     int *compdom;
>     if((compdom = (int *)malloc(sizeof(int) * X*Y*Z)) == NULL) {
>         fprintf(stderr, "failed to allocate memory for computational domain\n");
>         exit(EXIT_FAILURE);
>     }
>     for(int k = extent[5], c = 0; k >= extent[4]; k--, c++) {
>         for(int j = extent[3], b = 0; j >= extent[2]; j--, b++) {
>             for(int i = extent[0], a = 0; i <= extent[1]; i++, a++) {
>                 COMPDOM(a,b,c) =
>                     (int)(coral->GetScalarComponentAsFloat(i,j,k,0));
>             }
>         }
>     }
>
> I'm using CMake to create Makefile and it already created the Makefile. But when I compiled the program by "make" command, it raised the following error:
> /ufs/chu/VTK/extract/extract.cxx:82: error: ‘class vtkImageData’ has no member named ‘GetScalarComponentAsFloat’
>
> I already checked the help document and found that the method GetScalarComponentAsFloat() is used only for TCL. Any of you know how to do replace this method when using C/C++?

GetScalarComponentAsFloat() is certainly a member of vtkImageData in
VTK5.0 and, judging from the documentation, it is a member of VTK4.2.
The code is not conditional on TCL or anything else. This can be checked
directly by:

nm /usr/local/VTK/lib/libvtkFiltering.so | grep GetScalarComponentAsFloat
00177c78 T _ZN12vtkImageData25GetScalarComponentAsFloatEiiii

As I remember it VTK4.4 was a transitional version which was not
officially released. Have you considered moving back to VTK4.2 or
forward to VTK5.0 (which may require some porting of your code because
the API has changed)?

>
> Thank you very much in advance.
>
> Dzung.
>
>

Cheers

-- 
Peter F Bradshaw: http://www.exadios.com (public keys avaliable there).
Personal site: http://personal.exadios.com
"I love truth, and the way the government still uses it occasionally to
 keep us guessing." - Sam Kekovich.



More information about the vtkusers mailing list