[vtkusers] vtkContourFilter & vtkStructuredGrid
Luke J West
ljw at soc.soton.ac.uk
Thu May 29 09:55:51 EDT 2003
Hi,
I'm trying to perform a trivial task - generate an isosurface of a
vtkStructuredGrid with vtkContourFilter, but I don't seem to have the brainpower
to make it to work!
(I did managed to vtkContourFilter some vtkImageData, but that's not the natural
representation of my data.)
I can render my structured grid with vtkStructuredGridGeometryFilter to create
an array of coloured points in the render window (using an appropriate
vtkLookupTable), but vtkContourFilter gives a segmentation violation (yes - I'm
using C++).
I have populated my vtkStructuredGrid as follows at the end of this message -
have I made a juvenile schoolboy-type error :) ?
Any suggestions very gratefully received
Luke J West : Research Assistant : e-Science
--------------------------------------------
Rm. 566/12, School of Ocean & Earth Sciences
Southampton Oceanography Centre, Southampton
SO14 3ZH United Kingdom
--------------------------------------------
Tel: +44 23 8059 4801 Fax: +44 23 8059 3052
Mob: +44 79 6107 4783
// my code follows...
vtkPoints *XYZPts = vtkPoints::New();
XYZPts->Allocate(size);
vtkFloatArray* scalars = vtkFloatArray::New();
scalars->SetNumberOfComponents(1);
scalars->SetNumberOfTuples(size);
{
int offset =0;
float* data=new float[size];
for(int i=0;i<dims[0];i++)
for(int j=0;j<dims[1];j++)
for(int k=0;k<dims[2];k++)
{
XYZPts->SetPoint(off,i,j,k); // i.e. just a rectilinear grid
scalars->InsertComponent(offset,0,func(i,j,k));
offset++;
}
}
vtkStructuredGrid* XYZGrid = vtkStructuredGrid::New();
XYZGrid->SetDimensions(dims[0],dims[1],dims[2]);
XYZGrid->SetPoints(XYZPts);
XYZGrid->GetPointData()->SetScalars(scalars);
vtkContourFilter* XYZContour = vtkContourFilter::New();
XYZContour->SetInput(XYZGrid);
XYZContour->GenerateValues(5,0,1);
vtkPolyDataNormals* XYZNormals = vtkPolyDataNormals::New();
XYZNormals->SetInput(XYZContour->GetOutput());
XYZNormals->SetFeatureAngle(45);
polydata=XYZNormals->GetOutput();
vtkPolyDataMapper* XYZMapper;
XYZMapper=vtkPolyDataMapper::New();
XYZMapper->SetInput(XYZNormals->GetOutput());
//
// followed by the actor and rendering stuff which works fine.
More information about the vtkusers
mailing list