[vtkusers] Getting Scalar Values

Amy Henderson amy.henderson at kitware.com
Fri Mar 12 12:49:38 EST 2004


Donald,

Cube->GetPointData()->GetScalars() returns a vtkDataArray. There is not 
GetScalar method for data arrays. Instead use the GetComponent method. 
Change your code to the following:

Cube->GetPointData()->GetScalars()->GetComponent(2, 0);

- Amy

At 12:28 PM 3/12/2004, Hamp Donald wrote:

>Hi
>       I try to get the scalar value associated with
>each point of cube example given below. I failed.
>Please help me how to do that.
>If I use
>Cube->GetPointData()->GetScalars()->GetScalar(2), to
>get the scalar value of the point with ID 2, it is
>giving the compilation error.
>
>Regards
>Donald
>
>
>
>  int i;
>   static float x[8][3]={{0,0,0}, {1,0,0}, {1,1,0},
>{0,1,0},
>                         {0,0,1}, {1,0,1}, {1,1,1},
>{0,1,1}};
>   static vtkIdType pts[6][4]={{0,1,2,3}, {4,5,6,7},
>{0,1,5,4},
>                         {1,2,6,5},
>{2,3,7,6},{3,0,4,7}};
>
>
>   vtkPolyData *cube = vtkPolyData::New();
>   vtkPoints *points = vtkPoints::New();
>   vtkCellArray *polys = vtkCellArray::New();
>   vtkFloatArray *scalars = vtkFloatArray::New();
>
>
>   // Load the point, cell, and data attributes.
>   for (i=0; i<8; i++) points->InsertPoint(i,x[i]);
>   for (i=0; i<6; i++) polys->InsertNextCell(4,pts[i]);
>   for (i=0; i<8; i++) scalars->InsertTuple1(i,i);
>
>
>
>
>   // We now assign the pieces to the vtkPolyData.
>   cube->SetPoints(points);
>   //points->Delete();
>   cube->SetPolys(polys);
>   polys->Delete();
>   cube->GetPointData()->SetScalars(scalars);
>   // cube->GetPointData()->GetScalars();
>   scalars->Delete();
>
>
>__________________________________
>Do you Yahoo!?
>Yahoo! Search - Find what you're looking for faster
>http://search.yahoo.com
>_______________________________________________
>This is the private VTK discussion list.
>Please keep messages on-topic. Check the FAQ at: 
><http://public.kitware.com/cgi-bin/vtkfaq>
>Follow this link to subscribe/unsubscribe:
>http://www.vtk.org/mailman/listinfo/vtkusers






More information about the vtkusers mailing list