[vtkusers] visualizing slice contours via vtkAppendPolyData

dean.inglis at on.aibn.com dean.inglis at on.aibn.com
Tue May 27 11:43:48 EDT 2003


I am attempting to use a vtkAppendPolyData filter be used to stack contours
generated by a tracing widget.  For example, in my gui app, the user traces out a
contour on an vtkImageActor, then clicks a button to add the contour to
the vtkAPD filter.  Each contour is stored by slice index as an element of 
an array of allocated vtkPolyData objects:

void __fastcall TMainForm::StoreBtnClick(TObject *Sender)
{
  vtkImagePlaneWidget* wptr;
  switch ( m_currentAxis)
    {
    case 0:  wptr = m_planeWidgetX; break;
    case 1:  wptr = m_planeWidgetY; break;
    case 2:  wptr = m_planeWidgetZ; break;
    default: wptr = NULL; break;
    }
  if(wptr == NULL) { return; }

  float pos = wptr->GetSlicePosition();
  int index = wptr->GetSliceIndex();

  vtkPolyData* poly = m_contourPolys[index];
  m_tracer->GetPolyData(poly);
  vtkPoints* points = poly->GetPoints();

  if(points != NULL)
    {
    float pt[3];
    for (int i=0;i<points->GetNumberOfPoints();++i)
      {
      points->GetPoint(i,pt);
      pt[m_currentAxis] = pos;
      points->SetPoint(i,pt);
      }
    }

  m_contoursAppend->SetInputByNumber(index,m_contourPolys[i]);
  m_contoursAppend->Update();

  if(m_contoursActor->GetVisibility() == 0)
    {
    m_contoursActor->VisibilityOn();
    }
  RenderWindow3D->GetRenderer()->Render();
}

At startup, the app initializes the vtk objects:

<snip>
  vtkPoints* points = vtkPoints::New(VTK_FLOAT);
  points->SetNumberOfPoints(2);
  int i;
  for (i = 0; i < 2; i++)
    {
    points->SetPoint(i,i,i,i);
    }

  vtkCellArray *cells = vtkCellArray::New();
  cells->Allocate(cells->EstimateSize(1,2));
  vtkIdType pts[2];
  pts[0] = 0; pts[1] = 1;       
  cells->InsertNextCell(2,pts);

  m_contoursAppend->UserManagedInputsOn();
  m_contoursAppend->SetNumberOfInputs(100);
  for (i=0;i<100;i++)
    {
    m_contourPolys[i]->SetPoints(points);
    m_contourPolys[i]->SetLines(cells);
    m_contoursAppend->SetInputByNumber(i,m_contourPolys[i]);
    }

  cells->Delete();
  points->Delete();

  m_contoursMapper->SetInput(m_contoursAppend->GetOutput());
  m_contoursMapper->SetResolveCoincidentTopologyToPolygonOffset();
  m_contoursActor->SetMapper(m_contoursMapper);
  m_contoursActor->VisibilityOff();
<snip>

The pb is that I cannot visualize more than one contour at a time!!!
How do I visualize the contours without having to have an actor for each 
polydata contour? Do I have to add all polydata contours AFTER they
have been created?  

Dean




More information about the vtkusers mailing list