|
| 1 | +#include "VtkContrib/vtkConstrainedPointWidget2.h" |
| 2 | + |
| 3 | +#include <vtkCellPicker.h> |
| 4 | +#include <vtkRenderer.h> |
| 5 | +#include <vtkRenderWindowInteractor.h> |
| 6 | + |
| 7 | +#include <assert.h> |
| 8 | +#include <iostream> |
| 9 | +using namespace std; |
| 10 | + |
| 11 | + |
| 12 | +// ============================================================================= |
| 13 | +// LA CLASSE vtkConstrainedPointWidget2 |
| 14 | +// ============================================================================= |
| 15 | + |
| 16 | +vtkConstrainedPointWidget2::vtkConstrainedPointWidget2 ( ) |
| 17 | + : vtkHandleWidget ( ) |
| 18 | +{ |
| 19 | +} // vtkConstrainedPointWidget2::vtkConstrainedPointWidget2 |
| 20 | + |
| 21 | + |
| 22 | +vtkConstrainedPointWidget2::vtkConstrainedPointWidget2 (const vtkConstrainedPointWidget2&) |
| 23 | + : vtkHandleWidget ( ) |
| 24 | +{ |
| 25 | + assert (0 && "vtkConstrainedPointWidget2 copy constructor is not allowed."); |
| 26 | +} // vtkConstrainedPointWidget2::vtkConstrainedPointWidget2 |
| 27 | + |
| 28 | + |
| 29 | +vtkConstrainedPointWidget2& vtkConstrainedPointWidget2::operator = (const vtkConstrainedPointWidget2&) |
| 30 | +{ |
| 31 | + assert (0 && "vtkConstrainedPointWidget2 assignment operator is not allowed."); |
| 32 | + return *this; |
| 33 | +} // vtkConstrainedPointWidget2::vtkConstrainedPointWidget2 |
| 34 | + |
| 35 | + |
| 36 | +vtkConstrainedPointWidget2::~vtkConstrainedPointWidget2 ( ) |
| 37 | +{ |
| 38 | +} // vtkConstrainedPointWidget2::~vtkConstrainedPointWidget2 |
| 39 | + |
| 40 | + |
| 41 | +void vtkConstrainedPointWidget2::CreateDefaultRepresentation ( ) |
| 42 | +{ |
| 43 | + if (0 == WidgetRep) |
| 44 | + { |
| 45 | + vtkConstrainedPointHandleRepresentation2* rep = vtkConstrainedPointHandleRepresentation2::New ( ); |
| 46 | + WidgetRep = rep; |
| 47 | + rep->SetTolerance (1); |
| 48 | + rep->BuildRepresentation ( ); |
| 49 | + SetWidgetRepresentation (rep); |
| 50 | + } // if (0 == WidgetRep) |
| 51 | +} // vtkConstrainedPointWidget2::CreateDefaultRepresentation |
| 52 | + |
| 53 | + |
| 54 | +vtkConstrainedPointWidget2* vtkConstrainedPointWidget2::New ( ) |
| 55 | +{ |
| 56 | + return new vtkConstrainedPointWidget2 ( ); |
| 57 | +} // vtkConstrainedPointWidget2::New |
| 58 | + |
| 59 | + |
| 60 | +vtkConstrainedPointHandleRepresentation2* vtkConstrainedPointWidget2::GetConstrainedPointRepresentation ( ) |
| 61 | +{ |
| 62 | + return dynamic_cast<vtkConstrainedPointHandleRepresentation2*>(GetRepresentation ( )); |
| 63 | +} // vtkConstrainedPointWidget2::GetConstrainedPointRepresentation |
| 64 | + |
| 65 | + |
| 66 | +void vtkConstrainedPointWidget2::OnChar ( ) |
| 67 | +{ |
| 68 | + if ((0 != this->Interactor) && (0 != GetConstrainedPointRepresentation ( ))) |
| 69 | + { |
| 70 | + switch (this->Interactor->GetKeyCode ( )) |
| 71 | + { |
| 72 | + case ' ' : GetConstrainedPointRepresentation ( )->SetConstraintAxis (-1); break; |
| 73 | + case 'x' : |
| 74 | + case 'X' : GetConstrainedPointRepresentation ( )->SetConstraintAxis (0); break; |
| 75 | + case 'y' : |
| 76 | + case 'Y' : GetConstrainedPointRepresentation ( )->SetConstraintAxis (1); break; |
| 77 | + case 'z' : |
| 78 | + case 'Z' : GetConstrainedPointRepresentation ( )->SetConstraintAxis (2); break; |
| 79 | + default : vtkHandleWidget::OnChar ( ); |
| 80 | + } // switch (this->Interactor->GetKeyCode ( )) |
| 81 | + } // if ((0 != this->Interactor) && (0 != GetConstrainedPointRepresentation ( ))) |
| 82 | +} // vtkConstrainedPointWidget2::OnChar |
| 83 | + |
| 84 | + |
| 85 | +// ============================================================================= |
| 86 | +// LA CLASSE vtkConstrainedPointHandleRepresentation2 |
| 87 | +// ============================================================================= |
| 88 | + |
| 89 | +vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2 ( ) |
| 90 | + : vtkSphereHandleRepresentation ( ) |
| 91 | +{ |
| 92 | +} // vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2 |
| 93 | + |
| 94 | + |
| 95 | +vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2 (const vtkConstrainedPointHandleRepresentation2&) |
| 96 | + : vtkSphereHandleRepresentation ( ) |
| 97 | +{ |
| 98 | + assert (0 && "vtkConstrainedPointHandleRepresentation2 copy constructor is not allowed."); |
| 99 | +} // vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2 |
| 100 | + |
| 101 | + |
| 102 | +vtkConstrainedPointHandleRepresentation2& vtkConstrainedPointHandleRepresentation2::operator = (const vtkConstrainedPointHandleRepresentation2&) |
| 103 | +{ |
| 104 | + assert (0 && "vtkConstrainedPointHandleRepresentation2 assignment operator is not allowed."); |
| 105 | + return *this; |
| 106 | +} // vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2 |
| 107 | + |
| 108 | + |
| 109 | +vtkConstrainedPointHandleRepresentation2::~vtkConstrainedPointHandleRepresentation2 ( ) |
| 110 | +{ |
| 111 | +} // vtkConstrainedPointHandleRepresentation2::~vtkConstrainedPointHandleRepresentation2 |
| 112 | + |
| 113 | + |
| 114 | +vtkConstrainedPointHandleRepresentation2* vtkConstrainedPointHandleRepresentation2::New ( ) |
| 115 | +{ |
| 116 | + return new vtkConstrainedPointHandleRepresentation2 ( ); |
| 117 | +} // vtkConstrainedPointHandleRepresentation2::New |
| 118 | + |
| 119 | + |
| 120 | +void vtkConstrainedPointHandleRepresentation2::WidgetInteraction (double eventPos [2]) |
| 121 | +{ // Code vtkSphereHandleRepresentation::WidgetInteraction VTK 7.1.1 légèrement retouché |
| 122 | + // Do different things depending on state Calculations everybody does |
| 123 | + double focalPoint[4], pickPoint[4], prevPickPoint[4], startPickPoint[4], z; |
| 124 | + |
| 125 | + // Compute the two points defining the motion vector |
| 126 | + vtkInteractorObserver::ComputeWorldToDisplay (this->Renderer, this->LastPickPosition[0], this->LastPickPosition[1], this->LastPickPosition[2], focalPoint); |
| 127 | + z = focalPoint[2]; |
| 128 | + vtkInteractorObserver::ComputeDisplayToWorld (this->Renderer, this->LastEventPosition[0],this->LastEventPosition[1], z, prevPickPoint); |
| 129 | + vtkInteractorObserver::ComputeDisplayToWorld (this->Renderer, eventPos[0], eventPos[1], z, pickPoint); |
| 130 | + |
| 131 | + // Process the motion |
| 132 | + if (this->InteractionState == vtkHandleRepresentation::Selecting || this->InteractionState == vtkHandleRepresentation::Translating) |
| 133 | + { |
| 134 | + if (!this->WaitingForMotion || this->WaitCount++ > 3) |
| 135 | + { |
| 136 | + this->ConstraintAxis = this->DetermineConstraintAxis (this->ConstraintAxis, pickPoint); |
| 137 | + if (this->InteractionState == vtkHandleRepresentation::Selecting && !this->TranslationMode) |
| 138 | + { |
| 139 | + this->MoveFocus(prevPickPoint, pickPoint); |
| 140 | + } |
| 141 | + else |
| 142 | + { |
| 143 | + this->Translate(prevPickPoint, pickPoint); |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | + else if (this->InteractionState == vtkHandleRepresentation::Scaling) |
| 148 | + { |
| 149 | + this->Scale (prevPickPoint, pickPoint, eventPos); |
| 150 | + } |
| 151 | + |
| 152 | + // Book keeping |
| 153 | + this->LastEventPosition[0] = eventPos[0]; |
| 154 | + this->LastEventPosition[1] = eventPos[1]; |
| 155 | + |
| 156 | + this->Modified ( ); |
| 157 | +} // vtkConstrainedPointHandleRepresentation2::WidgetInteraction |
| 158 | + |
| 159 | + |
| 160 | +void vtkConstrainedPointHandleRepresentation2::SetConstraintAxis (int axis) |
| 161 | +{ |
| 162 | + this->ConstraintAxis = axis; |
| 163 | + switch (axis) |
| 164 | + { |
| 165 | + case 0 : // x |
| 166 | + case 1 : // y |
| 167 | + case 2 : // z |
| 168 | + ConstrainedOn ( ); |
| 169 | + break; |
| 170 | + default : |
| 171 | + ConstrainedOff ( ); |
| 172 | + } // switch (axis) |
| 173 | +} // vtkConstrainedPointHandleRepresentation2::SetConstraintAxis |
| 174 | + |
| 175 | + |
0 commit comments