Back to index

salome-gui  6.5.0
vtkPVAxesWidget.cxx
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003    Program: ParaView
00004    Module:    $RCSfile: vtkPVAxesWidget.cxx,v $
00005 
00006    Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
00007    All rights reserved.
00008 
00009    ParaView is a free software; you can redistribute it and/or modify it
00010    under the terms of the ParaView license version 1.2. 
00011 
00012    See License_v1.2.txt for the full ParaView license.
00013    A copy of this license can be obtained by contacting
00014    Kitware Inc.
00015    28 Corporate Drive
00016    Clifton Park, NY 12065
00017    USA
00018 
00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00022 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
00023 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00024 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00025 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00026 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00027 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00028 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 
00031 =========================================================================*/
00032 #include "vtkPVAxesWidget.h"
00033 
00034 #include "vtkActor2D.h"
00035 #include "vtkCallbackCommand.h"
00036 #include "vtkCamera.h"
00037 #include "vtkCoordinate.h"
00038 #include "vtkObjectFactory.h"
00039 #include "vtkPoints.h"
00040 #include "vtkPolyData.h"
00041 #include "vtkPolyDataMapper2D.h"
00042 #include "vtkProperty.h"
00043 #include "vtkProperty2D.h"
00044 #include "vtkPVAxesActor.h"
00045 #include "vtkRenderer.h"
00046 #include "vtkRenderWindow.h"
00047 #include "vtkRenderWindowInteractor.h"
00048 
00049 vtkStandardNewMacro(vtkPVAxesWidget);
00050 vtkCxxRevisionMacro(vtkPVAxesWidget, "$Revision: 1.1.6.2 $");
00051 
00052 vtkCxxSetObjectMacro(vtkPVAxesWidget, AxesActor, vtkPVAxesActor);
00053 vtkCxxSetObjectMacro(vtkPVAxesWidget, ParentRenderer, vtkRenderer);
00054 
00055 //----------------------------------------------------------------------------
00056 class vtkPVAxesWidgetObserver : public vtkCommand
00057 {
00058 public:
00059   static vtkPVAxesWidgetObserver *New()
00060     {return new vtkPVAxesWidgetObserver;};
00061   
00062   vtkPVAxesWidgetObserver()
00063     {
00064       this->AxesWidget = 0;
00065     }
00066   
00067   virtual void Execute(vtkObject* wdg, unsigned long event, void *calldata)
00068     {
00069       if (this->AxesWidget)
00070         {
00071         this->AxesWidget->ExecuteEvent(wdg, event, calldata);
00072         }
00073     }
00074   
00075   vtkPVAxesWidget *AxesWidget;
00076 };
00077 
00078 //----------------------------------------------------------------------------
00079 vtkPVAxesWidget::vtkPVAxesWidget()
00080 {
00081   this->StartEventObserverId = 0;
00082 
00083   this->EventCallbackCommand->SetCallback(vtkPVAxesWidget::ProcessEvents);
00084   
00085   this->Observer = vtkPVAxesWidgetObserver::New();
00086   this->Observer->AxesWidget = this;
00087   this->Renderer = vtkRenderer::New();
00088   this->Renderer->SetViewport(0.0, 0.0, 0.2, 0.2);
00089   this->Renderer->SetLayer(1);
00090   this->Renderer->InteractiveOff();
00091   this->Priority = 0.55;
00092   this->AxesActor = vtkPVAxesActor::New();
00093   this->Renderer->AddActor(this->AxesActor);
00094   this->AxesActor->AddToRender(this->Renderer); // tmp
00095   
00096   this->ParentRenderer = NULL;
00097   
00098   this->Moving = 0;
00099   this->MouseCursorState = vtkPVAxesWidget::Outside;
00100 
00101   this->StartTag = 0;
00102   
00103   this->Interactive = 1;
00104   
00105   this->Outline = vtkPolyData::New();
00106   this->Outline->Allocate();
00107   vtkPoints *points = vtkPoints::New();
00108   vtkIdType ptIds[5];
00109   ptIds[4] = ptIds[0] = points->InsertNextPoint(1, 1, 0);
00110   ptIds[1] = points->InsertNextPoint(2, 1, 0);
00111   ptIds[2] = points->InsertNextPoint(2, 2, 0);
00112   ptIds[3] = points->InsertNextPoint(1, 2, 0);
00113   this->Outline->SetPoints(points);
00114   this->Outline->InsertNextCell(VTK_POLY_LINE, 5, ptIds);
00115   vtkCoordinate *tcoord = vtkCoordinate::New();
00116   tcoord->SetCoordinateSystemToDisplay();
00117   vtkPolyDataMapper2D *mapper = vtkPolyDataMapper2D::New();
00118   mapper->SetInput(this->Outline);
00119   mapper->SetTransformCoordinate(tcoord);
00120   this->OutlineActor = vtkActor2D::New();
00121   this->OutlineActor->SetMapper(mapper);
00122   this->OutlineActor->SetPosition(0, 0);
00123   this->OutlineActor->SetPosition2(1, 1);
00124   
00125   points->Delete();
00126   mapper->Delete();
00127   tcoord->Delete();
00128 }
00129 
00130 //----------------------------------------------------------------------------
00131 vtkPVAxesWidget::~vtkPVAxesWidget()
00132 {
00133   this->Observer->Delete();
00134   this->AxesActor->Delete();
00135   this->OutlineActor->Delete();
00136   this->Outline->Delete();
00137   this->SetParentRenderer(NULL);
00138   this->Renderer->Delete();
00139 }
00140 
00141 //----------------------------------------------------------------------------
00142 void vtkPVAxesWidget::SetEnabled(int enabling)
00143 {
00144   if (!this->Interactor)
00145     {
00146     vtkErrorMacro("The interactor must be set prior to enabling/disabling widget");
00147     }
00148   
00149   if (enabling)
00150     {
00151     if (this->Enabled)
00152       {
00153       return;
00154       }
00155     if (!this->ParentRenderer)
00156       {
00157       vtkErrorMacro("The parent renderer must be set prior to enabling this widget");
00158       return;
00159       }
00160 
00161     this->Enabled = 1;
00162     
00163     if ( this->EventCallbackCommand )
00164       {
00165       vtkRenderWindowInteractor *i = this->Interactor;
00166       i->AddObserver(vtkCommand::MouseMoveEvent,
00167         this->EventCallbackCommand, this->Priority);
00168       i->AddObserver(vtkCommand::LeftButtonPressEvent,
00169         this->EventCallbackCommand, this->Priority);
00170       i->AddObserver(vtkCommand::LeftButtonReleaseEvent,
00171         this->EventCallbackCommand, this->Priority);
00172       }
00173     
00174     this->ParentRenderer->GetRenderWindow()->AddRenderer(this->Renderer);
00175     if (this->ParentRenderer->GetRenderWindow()->GetNumberOfLayers() < 2)
00176       {
00177       this->ParentRenderer->GetRenderWindow()->SetNumberOfLayers(2);
00178       }
00179     this->AxesActor->SetVisibility(1);
00180     // We need to copy the camera before the compositing observer is called.
00181     // Compositing temporarily changes the camera to display an image.
00182     this->StartEventObserverId = 
00183       this->ParentRenderer->AddObserver(vtkCommand::StartEvent,this->Observer,1);
00184     this->InvokeEvent(vtkCommand::EnableEvent, NULL);
00185     }
00186   else
00187     {
00188     if (!this->Enabled)
00189       {
00190       return;
00191       }
00192     
00193     this->Enabled = 0;
00194     this->Interactor->RemoveObserver(this->EventCallbackCommand);
00195     
00196     this->AxesActor->SetVisibility(0);
00197     if (this->ParentRenderer)
00198       {
00199       if (this->ParentRenderer->GetRenderWindow())
00200         {
00201         this->ParentRenderer->GetRenderWindow()->RemoveRenderer(this->Renderer);
00202         this->AxesActor->ReleaseGraphicsResources(this->ParentRenderer->GetRenderWindow());
00203         }
00204       if (this->StartEventObserverId != 0)
00205         {
00206         this->ParentRenderer->RemoveObserver(this->StartEventObserverId);
00207         }
00208       }
00209     
00210     this->InvokeEvent(vtkCommand::DisableEvent, NULL);
00211     }
00212 }
00213 
00214 //----------------------------------------------------------------------------
00215 void vtkPVAxesWidget::ExecuteEvent(vtkObject *vtkNotUsed(o),
00216                                    unsigned long vtkNotUsed(event),
00217                                    void *vtkNotUsed(calldata))
00218 {
00219   if (!this->ParentRenderer)
00220     {
00221     return;
00222     }
00223   
00224   vtkCamera *cam = this->ParentRenderer->GetActiveCamera();
00225   double pos[3], fp[3], viewup[3];
00226   cam->GetPosition(pos);
00227   cam->GetFocalPoint(fp);
00228   cam->GetViewUp(viewup);
00229   
00230   cam = this->Renderer->GetActiveCamera();
00231   cam->SetPosition(pos);
00232   cam->SetFocalPoint(fp);
00233   cam->SetViewUp(viewup);
00234   this->Renderer->ResetCamera();
00235   
00236   this->SquareRenderer();
00237 }
00238 
00239 void vtkPVAxesWidget::UpdateCursorIcon()
00240 {
00241   if (!this->Enabled)
00242     {
00243     this->SetMouseCursor(vtkPVAxesWidget::Outside);
00244     return;
00245     }
00246   
00247   if (this->Moving)
00248     {
00249     return;
00250     }
00251   
00252   int *parentSize = this->ParentRenderer->GetSize();
00253   
00254   int x = this->Interactor->GetEventPosition()[0];
00255   int y = this->Interactor->GetEventPosition()[1];
00256   double xNorm = x / (double)parentSize[0];
00257   double yNorm = y / (double)parentSize[1];
00258   
00259   double pos[4];
00260   this->Renderer->GetViewport(pos);
00261   
00262   int pState = this->MouseCursorState;
00263   
00264   if (xNorm > pos[0] && xNorm < pos[2] && yNorm > pos[1] && yNorm < pos[3])
00265     {
00266     this->MouseCursorState = vtkPVAxesWidget::Inside;
00267     }
00268   else if (fabs(xNorm-pos[0]) < .02 && fabs(yNorm-pos[3]) < .02)
00269     {
00270     this->MouseCursorState = vtkPVAxesWidget::TopLeft;
00271     }
00272   else if (fabs(xNorm-pos[2]) < .02 && fabs(yNorm-pos[3]) < .02)
00273     {
00274     this->MouseCursorState = vtkPVAxesWidget::TopRight;
00275     }
00276   else if (fabs(xNorm-pos[0]) < .02 && fabs(yNorm-pos[1]) < .02)
00277     {
00278     this->MouseCursorState = vtkPVAxesWidget::BottomLeft;
00279     }
00280   else if (fabs(xNorm-pos[2]) < .02 && fabs(yNorm-pos[1]) < .02)
00281     {
00282     this->MouseCursorState = vtkPVAxesWidget::BottomRight;
00283     }
00284   else
00285     {
00286     this->MouseCursorState = vtkPVAxesWidget::Outside;
00287     }
00288 
00289   if (pState == this->MouseCursorState)
00290     {
00291     return;
00292     }
00293   
00294   if (this->MouseCursorState == vtkPVAxesWidget::Outside)
00295     {
00296     this->Renderer->RemoveActor(this->OutlineActor);
00297     }
00298   else
00299     {
00300     this->Renderer->AddActor(this->OutlineActor);
00301     }
00302   this->Interactor->Render();
00303   
00304   this->SetMouseCursor(this->MouseCursorState);
00305 }
00306 
00307 //----------------------------------------------------------------------------
00308 void vtkPVAxesWidget::SetMouseCursor(int cursorState)
00309 {
00310   switch (cursorState)
00311     {
00312     case vtkPVAxesWidget::Outside:
00313       this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_DEFAULT);
00314       break;
00315     case vtkPVAxesWidget::Inside:
00316       this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZEALL);
00317       break;
00318     case vtkPVAxesWidget::TopLeft:
00319       this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZENW);
00320       break;
00321     case vtkPVAxesWidget::TopRight:
00322       this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZENE);
00323       break;
00324     case vtkPVAxesWidget::BottomLeft:
00325       this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZESW);
00326       break;
00327     case vtkPVAxesWidget::BottomRight:
00328       this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZESE);
00329       break;
00330     }
00331 }
00332 
00333 //----------------------------------------------------------------------------
00334 void vtkPVAxesWidget::ProcessEvents(vtkObject* vtkNotUsed(object),
00335                                     unsigned long event,
00336                                     void *clientdata,
00337                                     void* vtkNotUsed(calldata))
00338 {
00339   vtkPVAxesWidget *self =
00340     reinterpret_cast<vtkPVAxesWidget*>(clientdata);
00341 
00342   if (!self->GetInteractive())
00343     {
00344     return;
00345     }
00346   
00347   switch (event)
00348     {
00349     case vtkCommand::LeftButtonPressEvent:
00350       self->OnButtonPress();
00351       break;
00352     case vtkCommand::MouseMoveEvent:
00353       self->OnMouseMove();
00354       break;
00355     case vtkCommand::LeftButtonReleaseEvent:
00356       self->OnButtonRelease();
00357       break;
00358     }
00359 }
00360 
00361 //----------------------------------------------------------------------------
00362 void vtkPVAxesWidget::OnButtonPress()
00363 {
00364   if (this->MouseCursorState == vtkPVAxesWidget::Outside)
00365     {
00366     return;
00367     }
00368   
00369   this->SetMouseCursor(this->MouseCursorState);
00370 
00371   this->StartPosition[0] = this->Interactor->GetEventPosition()[0];
00372   this->StartPosition[1] = this->Interactor->GetEventPosition()[1];
00373   
00374   this->Moving = 1;
00375   this->EventCallbackCommand->SetAbortFlag(1);
00376   this->StartInteraction();
00377   this->InvokeEvent(vtkCommand::StartInteractionEvent, NULL);
00378 }
00379 
00380 //----------------------------------------------------------------------------
00381 void vtkPVAxesWidget::OnButtonRelease()
00382 {
00383   if (this->MouseCursorState == vtkPVAxesWidget::Outside)
00384     {
00385     return;
00386     }
00387   
00388   this->Moving = 0;
00389   this->EndInteraction();
00390   this->InvokeEvent(vtkCommand::EndInteractionEvent, NULL);
00391 }
00392 
00393 //----------------------------------------------------------------------------
00394 void vtkPVAxesWidget::OnMouseMove()
00395 {
00396   if (this->Moving)
00397     {
00398     switch (this->MouseCursorState)
00399       {
00400       case vtkPVAxesWidget::Inside:
00401         this->MoveWidget();
00402         break;
00403       case vtkPVAxesWidget::TopLeft:
00404         this->ResizeTopLeft();
00405         break;
00406       case vtkPVAxesWidget::TopRight:
00407         this->ResizeTopRight();
00408         break;
00409       case vtkPVAxesWidget::BottomLeft:
00410         this->ResizeBottomLeft();
00411         break;
00412       case vtkPVAxesWidget::BottomRight:
00413         this->ResizeBottomRight();
00414         break;
00415       }
00416     
00417     this->UpdateCursorIcon();
00418     this->EventCallbackCommand->SetAbortFlag(1);
00419     this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
00420     }
00421   else
00422     {
00423     this->UpdateCursorIcon();
00424     }
00425 }
00426 
00427 //----------------------------------------------------------------------------
00428 void vtkPVAxesWidget::MoveWidget()
00429 {
00430   int x = this->Interactor->GetEventPosition()[0];
00431   int y = this->Interactor->GetEventPosition()[1];
00432   
00433   int dx = x - this->StartPosition[0];
00434   int dy = y - this->StartPosition[1];
00435 
00436   this->StartPosition[0] = x;
00437   this->StartPosition[1] = y;
00438 
00439   int *size = this->ParentRenderer->GetSize();
00440   double dxNorm = dx / (double)size[0];
00441   double dyNorm = dy / (double)size[1];
00442   
00443   double *vp = this->Renderer->GetViewport();
00444   
00445   double newPos[4];
00446   newPos[0] = vp[0] + dxNorm;
00447   newPos[1] = vp[1] + dyNorm;
00448   newPos[2] = vp[2] + dxNorm;
00449   newPos[3] = vp[3] + dyNorm;
00450 
00451   if (newPos[0] < 0)
00452     {
00453     this->StartPosition[0] = 0;
00454     newPos[0] = 0;
00455     newPos[2] = vp[2] - vp[0];
00456     }
00457   if (newPos[1] < 0)
00458     {
00459     this->StartPosition[1] = 0;
00460     newPos[1] = 0;
00461     newPos[3] = vp[3] - vp[1];
00462     }
00463   if (newPos[2] > 1)
00464     {
00465     this->StartPosition[0] = (int)(size[0] - size[0] * (vp[2]-vp[0]));
00466     newPos[0] = 1 - (vp[2]-vp[0]);
00467     newPos[2] = 1;
00468     }
00469   if (newPos[3] > 1)
00470     {
00471     this->StartPosition[1] = (int)(size[1] - size[1]*(vp[3]-vp[1]));
00472     newPos[1] = 1 - (vp[3]-vp[1]);
00473     newPos[3] = 1;
00474     }
00475 
00476   this->Renderer->SetViewport(newPos);
00477   this->Interactor->Render();
00478 }
00479 
00480 //----------------------------------------------------------------------------
00481 void vtkPVAxesWidget::ResizeTopLeft()
00482 {
00483   int x = this->Interactor->GetEventPosition()[0];
00484   int y = this->Interactor->GetEventPosition()[1];
00485   
00486   int dx = x - this->StartPosition[0];
00487   int dy = y - this->StartPosition[1];
00488   
00489   int *size = this->ParentRenderer->GetSize();
00490   double dxNorm = dx / (double)size[0];
00491   double dyNorm = dy / (double)size[1];
00492   
00493   int useX;
00494   double change;
00495   double absDx = fabs(dxNorm);
00496   double absDy = fabs(dyNorm);
00497   
00498   if (absDx > absDy)
00499     {
00500     change = dxNorm;
00501     useX = 1;
00502     }
00503   else
00504     {
00505     change = dyNorm;
00506     useX = 0;
00507     }
00508   
00509   double *vp = this->Renderer->GetViewport();
00510   
00511   this->StartPosition[0] = x;
00512   this->StartPosition[1] = y;
00513   
00514   double newPos[4];
00515   newPos[0] = useX ? vp[0] + change : vp[0] - change;
00516   newPos[1] = vp[1];
00517   newPos[2] = vp[2];
00518   newPos[3] = useX ? vp[3] - change : vp[3] + change;
00519   
00520   if (newPos[0] < 0)
00521     {
00522     this->StartPosition[0] = 0;
00523     newPos[0] = 0;
00524     }
00525   if (newPos[0] >= newPos[2]-0.01)
00526     {
00527     newPos[0] = newPos[2] - 0.01;
00528     }
00529   if (newPos[3] > 1)
00530     {
00531     this->StartPosition[1] = size[1];
00532     newPos[3] = 1;
00533     }
00534   if (newPos[3] <= newPos[1]+0.01)
00535     {
00536     newPos[3] = newPos[1] + 0.01;
00537     }
00538   
00539   this->Renderer->SetViewport(newPos);
00540   this->Interactor->Render();
00541 }
00542 
00543 //----------------------------------------------------------------------------
00544 void vtkPVAxesWidget::ResizeTopRight()
00545 {
00546   int x = this->Interactor->GetEventPosition()[0];
00547   int y = this->Interactor->GetEventPosition()[1];
00548   
00549   int dx = x - this->StartPosition[0];
00550   int dy = y - this->StartPosition[1];
00551   
00552   int *size = this->ParentRenderer->GetSize();
00553   double dxNorm = dx / (double)size[0];
00554   double dyNorm = dy / (double)size[1];
00555 
00556   double change;
00557   double absDx = fabs(dxNorm);
00558   double absDy = fabs(dyNorm);
00559   
00560   if (absDx > absDy)
00561     {
00562     change = dxNorm;
00563     }
00564   else
00565     {
00566     change = dyNorm;
00567     }
00568   
00569   double *vp = this->Renderer->GetViewport();
00570   
00571   this->StartPosition[0] = x;
00572   this->StartPosition[1] = y;
00573   
00574   double newPos[4];
00575   newPos[0] = vp[0];
00576   newPos[1] = vp[1];
00577   newPos[2] = vp[2] + change;
00578   newPos[3] = vp[3] + change;
00579   
00580   if (newPos[2] > 1)
00581     {
00582     this->StartPosition[0] = size[0];
00583     newPos[2] = 1;
00584     }
00585   if (newPos[2] <= newPos[0]+0.01)
00586     {
00587     newPos[2] = newPos[0] + 0.01;
00588     }
00589   if (newPos[3] > 1)
00590     {
00591     this->StartPosition[1] = size[1];
00592     newPos[3] = 1;
00593     }
00594   if (newPos[3] <= newPos[1]+0.01)
00595     {
00596     newPos[3] = newPos[1] + 0.01;
00597     }
00598   
00599   this->Renderer->SetViewport(newPos);
00600   this->Interactor->Render();
00601 }
00602 
00603 //----------------------------------------------------------------------------
00604 void vtkPVAxesWidget::ResizeBottomLeft()
00605 {
00606   int x = this->Interactor->GetEventPosition()[0];
00607   int y = this->Interactor->GetEventPosition()[1];
00608   
00609   int dx = x - this->StartPosition[0];
00610   int dy = y - this->StartPosition[1];
00611   
00612   int *size = this->ParentRenderer->GetSize();
00613   double dxNorm = dx / (double)size[0];
00614   double dyNorm = dy / (double)size[1];
00615   double *vp = this->Renderer->GetViewport();
00616   
00617   double change;
00618   double absDx = fabs(dxNorm);
00619   double absDy = fabs(dyNorm);
00620   
00621   if (absDx > absDy)
00622     {
00623     change = dxNorm;
00624     }
00625   else
00626     {
00627     change = dyNorm;
00628     }
00629   
00630   this->StartPosition[0] = x;
00631   this->StartPosition[1] = y;
00632   
00633   double newPos[4];
00634   newPos[0] = vp[0] + change;
00635   newPos[1] = vp[1] + change;
00636   newPos[2] = vp[2];
00637   newPos[3] = vp[3];
00638   
00639   if (newPos[0] < 0)
00640     {
00641     this->StartPosition[0] = 0;
00642     newPos[0] = 0;
00643     }
00644   if (newPos[0] >= newPos[2]-0.01)
00645     {
00646     newPos[0] = newPos[2] - 0.01;
00647     }
00648   if (newPos[1] < 0)
00649     {
00650     this->StartPosition[1] = 0;
00651     newPos[1] = 0;
00652     }
00653   if (newPos[1] >= newPos[3]-0.01)
00654     {
00655     newPos[1] = newPos[3] - 0.01;
00656     }
00657   
00658   this->Renderer->SetViewport(newPos);
00659   this->Interactor->Render();
00660 }
00661 
00662 //----------------------------------------------------------------------------
00663 void vtkPVAxesWidget::ResizeBottomRight()
00664 {
00665   int x = this->Interactor->GetEventPosition()[0];
00666   int y = this->Interactor->GetEventPosition()[1];
00667   
00668   int dx = x - this->StartPosition[0];
00669   int dy = y - this->StartPosition[1];
00670   
00671   int *size = this->ParentRenderer->GetSize();
00672   double dxNorm = dx / (double)size[0];
00673   double dyNorm = dy / (double)size[1];
00674   
00675   double *vp = this->Renderer->GetViewport();
00676   
00677   int useX;
00678   double change;
00679   double absDx = fabs(dxNorm);
00680   double absDy = fabs(dyNorm);
00681   
00682   if (absDx > absDy)
00683     {
00684     change = dxNorm;
00685     useX = 1;
00686     }
00687   else
00688     {
00689     change = dyNorm;
00690     useX = 0;
00691     }
00692   
00693   this->StartPosition[0] = x;
00694   this->StartPosition[1] = y;
00695   
00696   double newPos[4];
00697   newPos[0] = vp[0];
00698   newPos[1] = useX ? vp[1] - change : vp[1] + change;
00699   newPos[2] = useX ? vp[2] + change : vp[2] - change;
00700   newPos[3] = vp[3];
00701   
00702   if (newPos[2] > 1)
00703     {
00704     this->StartPosition[0] = size[0];
00705     newPos[2] = 1;
00706     }
00707   if (newPos[2] <= newPos[0]+0.01)
00708     {
00709     newPos[2] = newPos[0] + 0.01;
00710     }
00711   if (newPos[1] < 0)
00712     {
00713     this->StartPosition[1] = 0;
00714     newPos[1] = 0;
00715     }
00716   if (newPos[1] >= newPos[3]-0.01)
00717     {
00718     newPos[1] = newPos[3]-0.01;
00719     }
00720   
00721   this->Renderer->SetViewport(newPos);
00722   this->Interactor->Render();
00723 }
00724 
00725 //----------------------------------------------------------------------------
00726 void vtkPVAxesWidget::SquareRenderer()
00727 {
00728   int *size = this->Renderer->GetSize();
00729   if (size[0] == 0 || size[1] == 0)
00730     {
00731     return;
00732     }
00733   
00734   double vp[4];
00735   this->Renderer->GetViewport(vp);
00736   
00737   double deltaX = vp[2] - vp[0];
00738   double newDeltaX = size[1] * deltaX / (double)size[0];
00739   double deltaY = vp[3] - vp[1];
00740   double newDeltaY = size[0] * deltaY / (double)size[1];
00741 
00742   if (newDeltaX > 1)
00743     {
00744     if (newDeltaY > 1)
00745       {
00746       if (size[0] > size[1])
00747         {
00748         newDeltaX = size[1] / (double)size[0];
00749         newDeltaY = 1;
00750         }
00751       else
00752         {
00753         newDeltaX = 1;
00754         newDeltaY = size[0] / (double)size[1];
00755         }
00756       vp[0] = vp[1] = 0;
00757       vp[2] = newDeltaX;
00758       vp[3] = newDeltaY;
00759       }
00760     else
00761       {
00762       vp[3] = vp[1] + newDeltaY;
00763       if (vp[3] > 1)
00764         {
00765         vp[3] = 1;
00766         vp[1] = vp[3] - newDeltaY;
00767         }
00768       }
00769     }
00770   else
00771     {
00772     vp[2] = vp[0] + newDeltaX;
00773     if (vp[2] > 1)
00774       {
00775       vp[2] = 1;
00776       vp[0] = vp[2] - newDeltaX;
00777       }
00778     }
00779   
00780   this->Renderer->SetViewport(vp);
00781   
00782   this->Renderer->NormalizedDisplayToDisplay(vp[0], vp[1]);
00783   this->Renderer->NormalizedDisplayToDisplay(vp[2], vp[3]);
00784   
00785   vtkPoints *points = this->Outline->GetPoints();
00786   points->SetPoint(0, vp[0]+1, vp[1]+1, 0);
00787   points->SetPoint(1, vp[2]-1, vp[1]+1, 0);
00788   points->SetPoint(2, vp[2]-1, vp[3]-1, 0);
00789   points->SetPoint(3, vp[0]+1, vp[3]-1, 0);
00790 }
00791 
00792 //----------------------------------------------------------------------------
00793 void vtkPVAxesWidget::SetInteractive(int state)
00794 {
00795   if (this->Interactive != state)
00796     {
00797     this->Interactive = state;
00798     }
00799   
00800   if (!state)
00801     {
00802     this->OnButtonRelease();
00803     this->MouseCursorState = vtkPVAxesWidget::Outside;
00804     this->Renderer->RemoveActor(this->OutlineActor);
00805     if (this->Interactor)
00806       {
00807       this->SetMouseCursor(this->MouseCursorState);
00808       // this->Interactor->Render();
00809       }
00810     }
00811 }
00812 
00813 //----------------------------------------------------------------------------
00814 void vtkPVAxesWidget::SetOutlineColor(double r, double g, double b)
00815 {
00816   this->OutlineActor->GetProperty()->SetColor(r, g, b);
00817   if (this->Interactor)
00818     {
00819 //    this->Interactor->Render();
00820     }
00821 }
00822 
00823 //----------------------------------------------------------------------------
00824 double* vtkPVAxesWidget::GetOutlineColor()
00825 {
00826   return this->OutlineActor->GetProperty()->GetColor();
00827 }
00828 
00829 //----------------------------------------------------------------------------
00830 void vtkPVAxesWidget::SetAxisLabelColor(double r, double g, double b)
00831 {
00832   this->AxesActor->GetXAxisLabelProperty()->SetColor(r, g, b);
00833   this->AxesActor->GetYAxisLabelProperty()->SetColor(r, g, b);
00834   this->AxesActor->GetZAxisLabelProperty()->SetColor(r, g, b);
00835 }
00836 
00837 //----------------------------------------------------------------------------
00838 double* vtkPVAxesWidget::GetAxisLabelColor()
00839 {
00840   return this->AxesActor->GetXAxisLabelProperty()->GetColor();
00841 }
00842 
00843 //----------------------------------------------------------------------------
00844 vtkRenderer* vtkPVAxesWidget::GetParentRenderer()
00845 {
00846   return this->ParentRenderer;
00847 }
00848 
00849 //----------------------------------------------------------------------------
00850 void vtkPVAxesWidget::SetViewport(double minX, double minY,
00851                                   double maxX, double maxY)
00852 {
00853   this->Renderer->SetViewport(minX, minY, maxX, maxY);
00854 }
00855 
00856 //----------------------------------------------------------------------------
00857 double* vtkPVAxesWidget::GetViewport()
00858 {
00859   return this->Renderer->GetViewport();
00860 }
00861 
00862 //----------------------------------------------------------------------------
00863 void vtkPVAxesWidget::PrintSelf(ostream& os, vtkIndent indent)
00864 {
00865   this->Superclass::PrintSelf(os, indent);
00866   
00867   os << indent << "AxesActor: " << this->AxesActor << endl;
00868   os << indent << "Interactive: " << this->Interactive << endl;
00869 }