[vtkusers] Cannot make unstructured points isosurface
Chris Scharver
scharver at evl.uic.edu
Fri Nov 1 22:36:26 EST 2002
Hello,
I seem to be running into the often-encountered "my unstructured points aren't resulting in a contour" problem. I think I'm just tired and missing something obvious. I wonder if I'm just not setting up my initial data source propertly. The data is simply X-Y-Z with a scalar value. It has a regular topology, but I have none of the metadata about the topology easily available. There's no ordering available, so I read everything as a vtkUnstructuredGrid and set the scalar values. Each point is read and entered into the grid as a vtkVertex. The scalar values are read into a separate vtkFloatArray.
Here's the data parsing code:
ifstream infile(this->FileName);
if (infile) {
vtkPoints* points = vtkPoints::New();
vtkIdList* ids = vtkIdList::New();
vtkFloatArray* velocities = vtkFloatArray::New();
velocities->SetName("velocities");
velocities->SetNumberOfComponents(1);
vtkUnstructuredGrid* output = this->GetOutput();
output->Allocate();
float xyz[3];
float vel;
while (!infile.eof()) {
if (infile >> xyz[1] >> xyz[0] >> xyz[2] >> vel) {
// Perhaps really inefficient, but it seems to read ok...
// Should I maybe use a different type of cell?
vtkVertex* vertex = vtkVertex::New();
vertex->GetPointIds()->InsertNextId(points->InsertNextPoint(xyz));
output->InsertNextCell(vertex->GetCellType(), vertex->GetPointIds());
velocities->InsertNextValue(vel);
}
}
infile.close();
output->SetPoints(points);
output->GetPointData()->SetScalars(velocities);
I called output->GetScalarRange() to make sure that all the scalars were read properly and assigned, but I cannot seem to get a surface after applying the contour. I couldn't get color mapping to work properly. Here's the pipeline once the data has been read:
vtkScrippsReader* dataReader = vtkScrippsReader::New();
dataReader->SetFileName(argv[1]);
// Scale the points to remove some distortion.
vtkTransform* scaleTransform = vtkTransform::New();
scaleTransform->Scale(1.0f, 1.0f, 0.0001f);
vtkTransformFilter* scaler = vtkTransformFilter::New();
scaler->SetInput(dataReader->GetOutput());
scaler->SetTransform(scaleTransform);
vtkContourFilter* contour = vtkContourFilter::New();
contour->SetInput(scaler->GetOutput());
contour->SetValue(0, 0.002f);
vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
mapper->SetInput(contour->GetOutput());
The contour is always empty, regardless of the value provided. I can see the points with a vtkDataSetMapper, although I cannot get the scalar values to result in coloring of the points.
vtkLookupTable* lut = vtkLookupTable::New();
lut->SetNumberOfColors(64);
lut->SetTableRange(dataReader->GetOutput()->GetScalarRange());
lut->Build();
vtkDataSetMapper* dataMapper = vtkDataSetMapper::New();
dataMapper->SetInput(scaler->GetOutput());
dataMapper->SetLookupTable(lut);
dataMapper->SetColorModeToMapScalars();
dataMapper->SetScalarModeToUsePointData();
dataMapper->ScalarVisibilityOn();
So I am just overlooking something? This all seems straightforward, but I've been lucky enough to use nicely formatted data files before, so now I am either not setting up my grid properly or I'm forgetting something in the pipeline. Any help would be tremendously appreciated.
Thanks,
Chris
--
Chris Scharver
Electronic Visualization Laboratory
The University of Illinois at Chicago
Ph: 312-996-3002 FAX: 312-413-7585
<http://www.evl.uic.edu/scharver/>
More information about the vtkusers
mailing list