User talk:JRobinson

From KitwarePublic
Revision as of 11:34, 10 August 2004 by JRobinson (talk | contribs) (vtlPlaneWidget - setting the orientation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Dear All,

The specific behaviour that I wanted was to be able to position the vtkPlaneWidget according to the origin and normal of an existing vtkPlane. The converse already exists with vtkPlaneWidget::GetPlane(vtkPlane*). THe problem with trying to use existign vtkPlaneWidget methods is the lack of

this->PlaneSource->Update();

in the SetNormal & SetOrigin methods. The workaround was to add a new method to vtkPlaneWidget:

void vtkPlaneWidget::SetPlane(vtkPlane *plane) {

 if ( plane == NULL )
   {
   return;
   }
 float normal[3] ;
 float origin[3] ;
 plane->GetNormal(normal) ;
 plane->GetOrigin(origin) ;
 this->SetNormal(normal) ;
 this->SetCenter(origin) ;
 this->PlaneSource->Update();

}

Now I can set the initial vtkPlaneWidget position according to an existing vtkPlane orientation and update it at any time. Part of my code looks like this:

///////////////////////////////////////////////////////////////////////////// // CSampleDoc commands ///////////////////////////////////////////////////////////////////////////// void CSampleDoc::SetUpPlaneWidget() {

   pPlaneWidget->SetInteractor(GetView()->Interactor);

// Just to get overall dimension

   pPlaneWidget->SetInput(pUnstructuredGrid);

// Make it slightly bigger than the actual cross section

   pPlaneWidget->SetPlaceFactor(1.25);
   pPlaneWidget->PlaceWidget();

// This is not pertinent unless the wireframe representation is used

   pPlaneWidget->SetResolution(10) ;

// Choose your representation

   pPlaneWidget->SetRepresentationToOutline() ;

// pPlaneWidget->SetRepresentationToWireFrame() ; // pPlaneWidget->SetRepresentationToSurface() ;

// Make sure it corresponds to the vtkPlane orientation

   UpdatePlaneWidget() ;

// Make sure that reacts

   pPlaneWidget->AddObserver(vtkCommand::InteractionEvent, pCutPlaneCallback);

} ///////////////////////////////////////////////////////////////////////////// // CSampleDoc commands ///////////////////////////////////////////////////////////////////////////// void CSampleDoc::UpdatePlaneWidget() { // This method is to update the plane widget from the vtkPlane used as the // implicit function for the vtkCutter

   pPlaneWidget->SetPlane(pPlane) ;
   pPlaneWidget->UpdatePlacement() ;

} I hope this is of some use. If i am doing something obviously wrong or inefficient, please add your comments to the Wiki. Might I suggest to the powers that be that the method that I have added to my vtkPlaneWidget object be added to teh actual next build/release of the vtkHybrid library (and any other objects that could use such a functionality).

Jim