[vtkusers] Help with visualization!

Sebastien Jourdain sebastien.jourdain at kitware.com
Sat Feb 19 22:41:59 EST 2011


As your structured grid is already a surface, you don't need the
filter that you are applying. But if you connect directly the grid to
the mapper, you will have to use a vtkDataSetMapper instead.
Other than that you are missing some Delete() but I didn't look close
enough  to your code to say more so far.

Seb

On Sat, Feb 19, 2011 at 7:20 PM, Santiago Costarelli
<santi.costarelli at gmail.com> wrote:
> 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>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



More information about the vtkusers mailing list