User talk:JRobinson: Difference between revisions
(vtlPlaneWidget - setting the orientation) |
(+<pre> tags (for multiline code)) |
||
Line 2: | Line 2: | ||
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 | 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(); | |||
this->PlaneSource->Update(); | |||
in the SetNormal & SetOrigin methods. The workaround was to add a new method to vtkPlaneWidget: | in the SetNormal & SetOrigin methods. The workaround was to add a new method to vtkPlaneWidget: | ||
<pre> | |||
void vtkPlaneWidget::SetPlane(vtkPlane *plane) | void vtkPlaneWidget::SetPlane(vtkPlane *plane) | ||
{ | { | ||
Line 21: | Line 20: | ||
this->PlaneSource->Update(); | this->PlaneSource->Update(); | ||
} | } | ||
</pre> | |||
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: | 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: | ||
<pre> | |||
///////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////// | ||
// CSampleDoc commands | // CSampleDoc commands | ||
Line 60: | Line 61: | ||
pPlaneWidget->UpdatePlacement() ; | pPlaneWidget->UpdatePlacement() ; | ||
} | } | ||
</pre> | |||
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). | 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 | Jim |
Latest revision as of 21:29, 11 August 2004
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