[vtkusers] Problem with vtkContourWidget and QVTKWidget

Xavius xavierelf at gmail.com
Tue Nov 22 08:08:15 EST 2011


Hi all!
I've tried to use vtkContourWidget as shown in examples and found that it
doesn't work with QVTKWidget.
Here is a sample code:

/
QVTKWidget *widget = new QVTKWidget;
setCentralWidget(widget);
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
  vtkRenderWindow *renderWindow = widget->GetRenderWindow();
  renderWindow->AddRenderer(renderer);
 
  QVTKInteractor *interactor = QVTKInteractor::New()
  interactor->SetRenderWindow(renderWindow);
 
  renderer->SetBackground(0.1, 0.2, 0.4);
  renderWindow->SetSize(600, 600);
 
  vtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRep = 
      vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();
  contourRep->GetLinesProperty()->SetColor(1, 0, 0); //set color to red
 
  vtkSmartPointer<vtkContourWidget> contourWidget = 
      vtkSmartPointer<vtkContourWidget>::New();
  contourWidget->SetInteractor(interactor);
  contourWidget->SetRepresentation(contourRep);
  contourWidget->On();
 
  vtkSmartPointer<vtkPolyData> pd = vtkSmartPointer<vtkPolyData>::New();
  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
  vtkSmartPointer<vtkCellArray> lines =
vtkSmartPointer<vtkCellArray>::New();
  vtkIdType* lineIndices = new vtkIdType[21];
  for (int i = 0; i< 20; i++)
    {
    const double angle = 2.0*vtkMath::Pi()*i/20.0;
    points->InsertPoint(static_cast<vtkIdType>(i), 0.1*cos(angle),
                        0.1*sin(angle), 0.0 );
    lineIndices[i] = static_cast<vtkIdType>(i);
    }
 
  lineIndices[20] = 0;
  lines->InsertNextCell(21,lineIndices);
  delete [] lineIndices;
  pd->SetPoints(points);
  pd->SetLines(lines);
 
  contourWidget->Initialize(pd);
  contourWidget->Render();
  renderer->ResetCamera();
  renderWindow->Render();
 
  interactor->Initialize();
/

Please help me! What I'm doing wrong? The same code outside QVTKWidget works
flawless.

--
View this message in context: http://vtk.1045678.n5.nabble.com/Problem-with-vtkContourWidget-and-QVTKWidget-tp5013481p5013481.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list