[vtkusers] Cell Finding confusion...
Robert Stein
rstein at ncsa.uiuc.edu
Wed Jun 14 13:42:10 EDT 2000
Hi Everyone,
Ok, let me ask the bigger question first :) What the best way given a a
dataset with associated scalars / vectors... to query the value of the
dataset at a given point? vtkProbeFilter seems like overkill to me here...
and it was giving me answers I didn't understand... so I decided to try and
code something myself... I've attached the test example of the problem I'm
having...
So I define a 2D 5x5 structured grid with a physical bounds of [0-4][0-4],
and the I try to find cells in this grid given a point defined on the
command line... to do this I'm using the FindAndGetCell method from
vtkDataSet... the funny thing is that cells seem to be define for some
values in this range and not for others... very confusing... For example
for values like (0, 0) (1, 2), (3.9, 2.5), etc... the cell is found ok...
However for other values that would seem to make sense like (2.5, 2.5) or
(3.1, 2.75) the cell is not found? It seems like these values are
obviously in the range of the structured grid... am I missing something
here, or can someone tell me an easier way to interpolate a value of a
dataset to a point?
Thanks
Rob
-------------- next part --------------
#include "vtkStructuredGrid.h"
#include "vtkPoints.h"
#include "vtkScalars.h"
#include "vtkPoints.h"
#define DIM 5
FILE* logFile;
int main (int argc, char** argv) {
vtkPoints* points = vtkPoints::New();
points->Allocate(DIM*DIM);
vtkScalars* scalars = vtkScalars::New();
scalars->Allocate(DIM*DIM);
for(int y=0; y<DIM; y++){
for(int x=0; x<DIM; x++){
points->InsertNextPoint(x, y, 0);
//fprintf(stderr, "Inserting %d %d\n", x, y);
scalars->InsertNextScalar(x/(float)DIM);
}
}
vtkStructuredGrid* grid = vtkStructuredGrid::New();
grid->SetPoints(points);
grid->SetDimensions(DIM, DIM, 1);
float xyz[3];
xyz[0] = atof(argv[1]);
xyz[1] = atof(argv[2]);
xyz[2] = 0.0;
int subId;
float pcoords[3], *weights;
float tol2 = grid->GetLength();
tol2 = tol2*tol2/1000.0f;
vtkCell* cell = grid->FindAndGetCell(xyz, NULL, -1, tol2, subId,
pcoords, weights);
if(!cell)
fprintf(stderr, "CELL NOT FOUND!\n");
else
fprintf(stderr, "FOUND IT\n");
return 0;
}
-------------- next part --------------
Robert J. Stein
National Center For Supercomputing Applications
405 N. Matthews, Urbana, IL
(217) 244-7584
rstein at ncsa.uiuc.edu
More information about the vtkusers
mailing list