[vtkusers] Re: Iterating through vtkCellArray *pStrips = pPolydata->GetStrips(); results

Jim Carroll jim at microbrightfield.com
Tue Aug 9 11:12:39 EDT 2005


Utkarsh Ayachit <utkarsh.ayachit <at> kitware.com> writes:

> 
> Check vtkOpenGLPolyDataMapper::DrawTStrips().

> The default case (line ~1274) in the switch block has the code to do 
> what you are looking for.  

Thanks Utkarsh,

Hmm.  ok, I'm starting to get that the array of ids are indexes into points, but
I'm still missing something.  Looking at the ptIds array, the first two are
usually smaller numbers, and then it looks like the real data is starting in the
third element of the ptIds array.  What are the first two values?

I'm hoping that the normals that are computed from the entire face are the
average normals for adjacent triangles, I don't want to compute the normal per
triangle like in the defaultCase of DrawTStrips(), because that emphasizes the
individual triangles.

Here's my code so far (nothing shows up in my openGL display)

    // Create a surface
    vtkContourFilter *skinExtractor = vtkContourFilter::New();
    skinExtractor->SetInput((vtkDataSet *) stack);
    skinExtractor->SetValue(0, 120);

    // Create normals for each vertex of the surface
    vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();
    skinNormals->SetInput(skinExtractor->GetOutput());
    skinNormals->SetFeatureAngle(120.0);

    vtkStripper *skinStripper = vtkStripper::New();
    skinStripper->SetInput(skinNormals->GetOutput());

    skinStripper->Update();
    vtkPolyData *pPolydata = skinStripper->GetOutput();

    vtkCellArray *pStrips = pPolydata->GetStrips();
    vtkPoints *pPoints = pPolydata->GetPoints();
    // the current vertex
    double v[3];

    vtkIdType nPts = 0;
    vtkIdType *ptIds = pStrips->GetPointer();

    for (pStrips->InitTraversal(); pStrips->GetNextCell(nPts,ptIds);)
    {
        ::glBegin(GL_TRIANGLE_STRIP);
        for (int j = 0; j < nPts; j++) 
        {
            pPoints->GetPoint(ptIds[j], v);

            //::glNormal3f (n[0], n[1], n[2]);
            ::glVertex3f (v[0], v[1], v[2]);
        }
        ::glEnd();
    }

Thanks,
-Jim






More information about the vtkusers mailing list