GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
vtkOrientedBoxWidget.cxx
Go to the documentation of this file.
1 /*========================================================================
2  Copyright (c) INRIA - ASCLEPIOS Project (http://www-sop.inria.fr/asclepios).
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice,
9  this list of conditions and the following disclaimer.
10 
11  * Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  * Neither the name of INRIA or ASCLEPIOS, nor the names of any contributors
16  may be used to endorse or promote products derived from this software
17  without specific prior written permission.
18 
19  * Modified source versions must be plainly marked as such, and must not be
20  misrepresented as being the original software.
21 
22  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
23  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
26  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  =========================================================================*/
33 
34 /*=========================================================================
35  Modifications were made by the GoFigure Dev. Team.
36  while at Megason Lab, Systems biology, Harvard Medical school, 2009-11
37 
38  Copyright (c) 2009-11, President and Fellows of Harvard College.
39  All rights reserved.
40 
41  Redistribution and use in source and binary forms, with or without
42  modification, are permitted provided that the following conditions are met:
43 
44  Redistributions of source code must retain the above copyright notice,
45  this list of conditions and the following disclaimer.
46  Redistributions in binary form must reproduce the above copyright notice,
47  this list of conditions and the following disclaimer in the documentation
48  and/or other materials provided with the distribution.
49  Neither the name of the President and Fellows of Harvard College
50  nor the names of its contributors may be used to endorse or promote
51  products derived from this software without specific prior written
52  permission.
53 
54  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
56  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
58  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
59  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
60  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
61  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
62  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
63  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
64  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 
66  =========================================================================*/
67 
68 #include "vtkOrientedBoxWidget.h"
69 #include "vtkMatrixToLinearTransform.h"
70 #include "vtkObjectFactory.h"
71 #include "vtkMatrix4x4.h"
72 #include "vtkPoints.h"
73 #include "vtkActor.h"
74 #include "vtkAssemblyNode.h"
75 #include "vtkAssemblyPath.h"
76 #include "vtkCallbackCommand.h"
77 #include "vtkCamera.h"
78 #include "vtkCellArray.h"
79 #include "vtkCellPicker.h"
80 #include "vtkDoubleArray.h"
81 #include "vtkFloatArray.h"
82 #include "vtkMath.h"
83 #include "vtkObjectFactory.h"
84 #include "vtkPlanes.h"
85 #include "vtkPolyData.h"
86 #include "vtkPolyDataMapper.h"
87 #include "vtkProperty.h"
88 #include "vtkRenderWindowInteractor.h"
89 #include "vtkRenderer.h"
90 #include "vtkSphereSource.h"
91 #include "vtkTransform.h"
92 
93 vtkCxxRevisionMacro(vtkOrientedBoxWidget, "$Revision: 490 $");
95 
96 //----------------------------------------------------------------------------
98 {
99  this->OrientationMatrix = vtkMatrix4x4::New();
100  this->OrientationMatrix->Identity();
101 
102  this->InvertedOrientationMatrix = vtkMatrix4x4::New();
103  this->InvertedOrientationMatrix->Identity();
104 }
105 
106 //----------------------------------------------------------------------------
108 {
109  this->OrientationMatrix->Delete();
110  this->InvertedOrientationMatrix->Delete();
111 }
112 
113 //----------------------------------------------------------------------------
115 {
116  if ( matrix == this->OrientationMatrix ) { return; }
117 
118  if ( this->OrientationMatrix )
119  {
120  this->OrientationMatrix->UnRegister (this);
121  this->OrientationMatrix = NULL;
122  }
123 
124  this->OrientationMatrix = matrix;
125 
126  if ( this->OrientationMatrix )
127  {
128  // move all the actors according to the user-matrix
129  this->HexActor->SetUserMatrix (matrix);
130  this->HexFace->SetUserMatrix (matrix);
131  this->HexOutline->SetUserMatrix (matrix);
132 
133  for ( unsigned int i = 0; i < 7; i++ )
134  {
135  this->Handle[i]->SetUserMatrix (matrix);
136  }
137 
138  // initialize inverse matrix
139  vtkMatrix4x4::Invert (this->OrientationMatrix, this->InvertedOrientationMatrix);
140  }
141 }
142 
143 //----------------------------------------------------------------------------
145 {
146  // See whether we're active
147  if ( this->State == vtkBoxWidget::Outside
148  || this->State == vtkBoxWidget::Start )
149  {
150  return;
151  }
152 
153  int X = this->Interactor->GetEventPosition()[0];
154  int Y = this->Interactor->GetEventPosition()[1];
155 
156  // Do different things depending on state
157  // Calculations everybody does
158  double focalPoint[4], pickPoint[4], prevPickPoint[4];
159  double z, vpn[3];
160 
161  vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
162  if ( !camera )
163  {
164  return;
165  }
166 
167  // Compute the two points defining the motion vector
168  this->ComputeWorldToDisplay(this->LastPickPosition[0],
169  this->LastPickPosition[1],
170  this->LastPickPosition[2], focalPoint);
171  z = focalPoint[2];
172  this->ComputeDisplayToWorld(
173  static_cast< double >( this->Interactor->GetLastEventPosition()[0] ),
174  static_cast< double >( this->Interactor->GetLastEventPosition()[1] ),
175  z, prevPickPoint);
176  this->ComputeDisplayToWorld(static_cast< double >( X ), static_cast< double >( Y ),
177  z, pickPoint);
178 
179  // multiply pick points by the inverted orientation matrix
180  // to recover the true movement to apply
181  this->InvertedOrientationMatrix->MultiplyPoint (prevPickPoint, prevPickPoint);
182  this->InvertedOrientationMatrix->MultiplyPoint (pickPoint, pickPoint);
183 
184  // Process the motion
185  if ( this->State == vtkBoxWidget::Moving )
186  {
187  // Okay to process
188  if ( this->CurrentHandle )
189  {
190  if ( this->RotationEnabled && this->CurrentHandle == this->HexFace )
191  {
192  camera->GetViewPlaneNormal(vpn);
193  this->Rotate(X, Y, prevPickPoint, pickPoint, vpn);
194  }
195  else if ( this->TranslationEnabled
196  && this->CurrentHandle == this->Handle[6] )
197  {
198  this->Translate(prevPickPoint, pickPoint);
199  }
200  else if ( this->TranslationEnabled && this->ScalingEnabled )
201  {
202  if ( this->CurrentHandle == this->Handle[0] )
203  {
204  this->MoveMinusXFace(prevPickPoint, pickPoint);
205  }
206  else if ( this->CurrentHandle == this->Handle[1] )
207  {
208  this->MovePlusXFace(prevPickPoint, pickPoint);
209  }
210  else if ( this->CurrentHandle == this->Handle[2] )
211  {
212  this->MoveMinusYFace(prevPickPoint, pickPoint);
213  }
214  else if ( this->CurrentHandle == this->Handle[3] )
215  {
216  this->MovePlusYFace(prevPickPoint, pickPoint);
217  }
218  else if ( this->CurrentHandle == this->Handle[4] )
219  {
220  this->MoveMinusZFace(prevPickPoint, pickPoint);
221  }
222  else if ( this->CurrentHandle == this->Handle[5] )
223  {
224  this->MovePlusZFace(prevPickPoint, pickPoint);
225  }
226  }
227  }
228  }
229  else if ( this->ScalingEnabled && this->State == vtkBoxWidget::Scaling )
230  {
231  this->Scale(prevPickPoint, pickPoint, X, Y);
232  }
233 
234  // Interact, if desired
235  this->EventCallbackCommand->SetAbortFlag(1);
236  this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
237  this->Interactor->Render();
238 }
vtkMatrix4x4 * OrientationMatrix
vtkCxxRevisionMacro(vtkOrientedBoxWidget,"$Revision: 490 $")
orthogonal hexahedron 3D widget with pre-defined orientation
vtkStandardNewMacro(vtkOrientedBoxWidget)
vtkMatrix4x4 * InvertedOrientationMatrix
virtual void SetOrientationMatrix(vtkMatrix4x4 *matrix)