[vtkusers] Code controlling vtkImagePlaneWidget

Raúl Ferriz raul at torresyvalero.com
Wed Sep 22 11:07:12 EDT 2010


  Hello!

I'm trying to control vtkImagePlaneWidget by code. I get the vtkPolyData 
representation of a vtkSPLineRepresentation, and also I get the points 
of that polydata:

             vtkPolyData * pd;
             pd = vtkPolyData::New();
             LineSP->GetPolyData ( pd );

             vtkCellArray * lines = pd->GetLines();
             vtkPoints    * points = pd->GetPoints();

             vtkIdType *pts = 0;
             vtkIdType npts = 0;
             vtkIdType npts_acum = 0;

             double p1[3], p2[3], p3[3], p21[3], p31[3], pn[3];

             Slice = 75; // Arbitrary value

             for ( lines->InitTraversal(); lines->GetNextCell(npts, pts); )
             {
                 if ( npts + npts_acum >= Slice )
                 {
                     int _j = Slice - npts_acum;
                     puntos->GetPoint( pts[_j], p1);
                     puntos->GetPoint( pts[_j+1], p2);
                     break;
                 }
             }
             // Point of plane : p1
             // Normal of plane: p2-p1
             vtkMath::Subtract (p2, p1, pn);
             vtkMath::Normalize ( pn );

Then I need to obtain another point of desired plane, I achieve this with:
             p31[0] = 0;
             p31[1] = 0;
             p31[2] = 1;
              vtkMath::Cross (pn, p31, p3);

Then I do: _po = p1, _p1 = p1 + p31;
             _po = p1;
             vtkMath::Add ( p1, p31, _p1);
             vtkMath::Add ( p1, p3,  _p2);

And finally try to assign that values to the widget:

             ImagePlaneWidget->SetOrigin  ( _po );
             ImagePlaneWidget->SetPoint1 ( _p1 );
             ImagePlaneWidget->SetPoint2 ( _p2 );
             ImagePlaneWidget->Modfied();


But only background color is show on my render window. Any help on what 
could be wrong?



More information about the vtkusers mailing list