[vtkusers] Help with visualization!

Santiago Costarelli santi.costarelli at gmail.com
Sat Feb 19 19:20:45 EST 2011


Hi everybody, i'm having troubles displaying some data into a 2D grid. The
idea, I solve Navier-Stokes equations and i need to plot pressure per
example in a 2D grid. Actually, i'm using StructuredGrid and a
SurfaceFilter, but the result is an Surface (logically). The answer, is
there any way to do what I want? the code is below. Thanks to all!

<code>
vtkRenderer *renderer = vtkRenderer::New();
renderer->SetBackground(1.,1.,1.);
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(renderer);
renWin->SetSize(640,480);
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(renWin);

int nsteps = 500;
for(int t=0;t<nsteps;t++){
vtkStructuredGrid *grid = vtkStructuredGrid::New();
grid->SetDimensions(32,32,1);
vtkPoints *points = vtkPoints::New();
vtkFloatArray *scalars = vtkFloatArray::New();
 float z;
for(int i=0;i<32;i++){
for(int j=0;j<32;j++){
z =
100*sin(2.*3.14*static_cast<float>(i))*sin(2.*3.14*static_cast<float>(j))
*(1.+5.*(float(t)/float(nsteps)))*exp(1.+float(t)/float(nsteps));
points->InsertNextPoint(i,j,z);
scalars->InsertNextValue(static_cast<float>(z));
//printf("x: %d, y: %d, z: %f.\n",x,y,z);
}
}
 grid->SetPoints(points);
grid->GetPointData()->SetScalars(scalars);
 vtkDataSetSurfaceFilter *filter = vtkDataSetSurfaceFilter::New();
//filter->SetInput(grid);
//vtkStructuredGridGeometryFilter *filter =
vtkStructuredGridGeometryFilter::New();
filter->SetInput(grid);
filter->Update();
 vtkPolyData *pdata = filter->GetOutput();
 vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
mapper->SetInput(pdata);
 vtkActor *surfActor = vtkActor::New();
surfActor->SetMapper(mapper);
 renderer->AddActor(surfActor);
mapper->SetScalarRange(0.,2.);
 if(!(t%5)) renWin->Render();
}

<\code>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110219/229f8dbd/attachment.htm>


More information about the vtkusers mailing list