[vtkusers] Displaying a 3D SURFACE USING VTK

N Smethurst nick.smethurst at free.fr
Fri Jun 13 02:25:14 EDT 2003


Hi there again Ajit

You need to set up and connect your topology (vtkCellArray) otherwise
VTK has nothing to draw. The relevant bit of code in the example is:

    // Construct triangle strip topology.
    // The number of points in a cell is twice the number of columns.
    vtkIdType pnt[2*cols];
    // Loop for each row pair (the number of rows less one).
    for (int j=0; j<rows-1; j++) {
        count = 0;
        for (int i=0; i<cols; i++) {
            pnt[count++] = j*cols + i;
            pnt[count++] = (j+1)*cols + i;
        }
        surfCells->InsertNextCell(p,pnt);
    }

    surfPolyData->SetPoints(surfPoints);
    surfPolyData->SetStrips(surfCells);

You could construct this differently if you wanted, but triangle strips
are meant to be efficient.

Also, maybe its better to use a vtkPolyDataMapper than a vtkDataSetMapper.

Regards

Nick

Le Vendredi 13 Juin 2003 01:49, Ajit Rajwadé a écrit :
> Thanks. Okay here is what I tried, but when I run my program, i dont get
> anything on the display. What could be happening? Could you give me a
> hint?
>
> ===============================================================
>   vtkRenderer *renderer = vtkRenderer::New();
>   vtkRenderWindow *renWin = vtkRenderWindow::New();
>   renWin->AddRenderer(renderer);
>   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
>   iren->SetRenderWindow(renWin);
>
>   vtkPoints* surfPoints = vtkPoints::New();
>   vtkCellArray* surfCells = vtkCellArray::New();
>   vtkPolyData* surfPolyData = vtkPolyData::New();
>   vtkElevationFilter* surfElevation = vtkElevationFilter::New();
>   vtkPolyDataNormals* surfNormals = vtkPolyDataNormals::New();
>
>   fs = fopen (fileName,"r");
>   i = 0;
>   surfPoints->SetNumberOfPoints  (8000);
>   while (fgets (nextLine,100,fs))
>   {
>                // Basically reading x,y,z coordinates from a file.
> 	temp = (char*)strtok (nextLine," \n");
> 	point[0] = (float)(atof (temp));
>
> 	temp = (char*)strtok (NULL," \n");
> 	point[1] = (float)(atof (temp));
>
> 	temp = (char*)strtok (NULL," \n");
> 	point[2] = (float)(atof(temp));
>
> 	surfPoints->SetPoint(i,point);
> 	i = i + 1;
>   }
>
>
> surfPolyData->SetPoints(surfPoints);
>
> surfElevation->SetInput(surfPolyData);
> surfElevation->SetLowPoint(0.0, 0.0, 120);
> surfElevation->SetHighPoint(0.0, 0.0, 20); // For shading.
> surfNormals->SetInput(surfElevation->GetPolyDataOutput());
> surfNormals->SetFeatureAngle(80);
>
> vtkDataSetMapper *volMapper = vtkDataSetMapper::New ();
> volMapper->SetInput (surfElevation->GetOutput());
>
> vtkActor *volActor = vtkActor::New();
> volActor->SetMapper(volMapper);
>
> renderer->AddActor(volActor);
> renderer->SetBackground(1,1,1);
> renWin->SetSize(450,450);
>
> // interact with data
> renWin->Render();
> iren->Start();
>




More information about the vtkusers mailing list