GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
vtkImage3DImagePlaneCallback.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: vtkINRIA3D
4 Module: $Id: vtkImage3DImagePlaneCallback.cxx 665 2008-02-11 12:31:28Z ntoussaint $
5 Language: C++
6 Author: $Author: arnaudgelas $
7 Date: $Date: 2009-07-31 14:33:39 -0400 (Fri, 31 Jul 2009) $
8 Version: $Revision: 490 $
9 
10 Copyright (c) 2007 INRIA - Asclepios Project. All rights reserved.
11 
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 
18 /*========================================================================
19  Copyright (c) INRIA - ASCLEPIOS Project (http://www-sop.inria.fr/asclepios).
20  All rights reserved.
21 
22  Redistribution and use in source and binary forms, with or without
23  modification, are permitted provided that the following conditions are met:
24 
25  * Redistributions of source code must retain the above copyright notice,
26  this list of conditions and the following disclaimer.
27 
28  * Redistributions in binary form must reproduce the above copyright notice,
29  this list of conditions and the following disclaimer in the documentation
30  and/or other materials provided with the distribution.
31 
32  * Neither the name of INRIA or ASCLEPIOS, nor the names of any contributors
33  may be used to endorse or promote products derived from this software
34  without specific prior written permission.
35 
36  * Modified source versions must be plainly marked as such, and must not be
37  misrepresented as being the original software.
38 
39  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
40  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
43  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
45  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
46  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49  =========================================================================*/
50 
51 /*=========================================================================
52  Modifications were made by the GoFigure Dev. Team.
53  while at Megason Lab, Systems biology, Harvard Medical school, 2009-11
54 
55  Copyright (c) 2009-11, President and Fellows of Harvard College.
56  All rights reserved.
57 
58  Redistribution and use in source and binary forms, with or without
59  modification, are permitted provided that the following conditions are met:
60 
61  Redistributions of source code must retain the above copyright notice,
62  this list of conditions and the following disclaimer.
63  Redistributions in binary form must reproduce the above copyright notice,
64  this list of conditions and the following disclaimer in the documentation
65  and/or other materials provided with the distribution.
66  Neither the name of the President and Fellows of Harvard College
67  nor the names of its contributors may be used to endorse or promote
68  products derived from this software without specific prior written
69  permission.
70 
71  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
72  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
73  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
74  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
75  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
76  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
77  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
78  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
79  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
80  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
81  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
82 
83  =========================================================================*/
84 
86 
87 #include <vtkPlaneWidget.h>
88 #include <vtkImageReslice.h>
89 #include <vtkImageData.h>
90 #include <vtkMath.h>
91 #include "vtkViewImage2D.h"
92 #include <vtkPlane.h>
93 
95  unsigned long,
96  void *)
97 {
98  /*
99  if( !this->ViewImage2D )
100  {
101  return;
102  }
103  */
104 
105  // get the box widget
106 // vtkPlaneWidget *widget = reinterpret_cast<vtkPlaneWidget*>(caller);
107  vtkPlaneWidget *widget = vtkPlaneWidget::SafeDownCast(caller);
108 
109  if ( !widget )
110  {
111  return;
112  }
113 
114  vtkImageData *imageData = vtkImageData::SafeDownCast( widget->GetInput() );
115 
116  if ( !imageData )
117  {
118  this->Reslice->SetInput (NULL);
119  return;
120  }
121 
122  this->Reslice->SetInput (imageData);
123 
124  // Calculate appropriate pixel spacing for the reslicing
125  imageData->UpdateInformation();
126  double spacing[3];
127  imageData->GetSpacing(spacing);
128 
129  double imOrigin[3];
130  imageData->GetOrigin(imOrigin);
131  int extent[6];
132  imageData->GetWholeExtent(extent);
133  double bounds[] = { imOrigin[0] + spacing[0] * extent[0], //xmin
134  imOrigin[0] + spacing[0] * extent[1], //xmax
135  imOrigin[1] + spacing[1] * extent[2], //ymin
136  imOrigin[1] + spacing[1] * extent[3], //ymax
137  imOrigin[2] + spacing[2] * extent[4], //zmin
138  imOrigin[2] + spacing[2] * extent[5] }; //zmax
139 
140  int i = 0;
141 
142  for ( i = 0; i <= 4; i += 2 ) // reverse bounds if necessary
143  {
144  if ( bounds[i] > bounds[i + 1] )
145  {
146  double t = bounds[i + 1];
147  bounds[i + 1] = bounds[i];
148  bounds[i] = t;
149  }
150  }
151 
152  double abs_normal[3];
153  widget->GetNormal(abs_normal);
154  double planeCenter[3];
155  widget->GetCenter(planeCenter);
156  double nmax = 0.0;
157  int k = 0;
158  for ( i = 0; i < 3; i++ )
159  {
160  abs_normal[i] = fabs(abs_normal[i]);
161  if ( abs_normal[i] > nmax )
162  {
163  nmax = abs_normal[i];
164  k = i;
165  }
166  }
167 
168  // Force the plane to lie within the true image bounds along its normal
169  //
170 
171  if ( planeCenter[k] > bounds[2 * k + 1] )
172  {
173  planeCenter[k] = bounds[2 * k + 1];
174  }
175  else if ( planeCenter[k] < bounds[2 * k] )
176  {
177  planeCenter[k] = bounds[2 * k];
178  }
179 
180  widget->SetCenter(planeCenter);
181 
182  // get the planes
183  double point1[3], point2[3], origin[4], normal[3];
184  widget->GetPoint1 (point1);
185  widget->GetPoint2 (point2);
186  widget->GetOrigin (origin);
187  widget->GetNormal (normal);
188 
189  double axis1[3], axis2[3];
190  for ( i = 0; i < 3; i++ )
191  {
192  axis1[i] = point1[i] - origin[i];
193  axis2[i] = point2[i] - origin[i];
194  }
195 
196  double planeSizeX = vtkMath::Normalize(axis1);
197  double planeSizeY = vtkMath::Normalize(axis2);
198 
199  this->ResliceAxes->Identity();
200  for ( i = 0; i < 3; i++ )
201  {
202  this->ResliceAxes->SetElement(0, i, axis1[i]);
203  this->ResliceAxes->SetElement(1, i, axis2[i]);
204  this->ResliceAxes->SetElement(2, i, normal[i]);
205  }
206 
207  origin[3] = 1.0;
208  double originXYZW[4];
209  this->ResliceAxes->MultiplyPoint(origin, originXYZW);
210 
211  this->ResliceAxes->Transpose();
212  double neworiginXYZW[4];
213  double point[] = { originXYZW[0], originXYZW[1], originXYZW[2], originXYZW[3] };
214  this->ResliceAxes->MultiplyPoint(point, neworiginXYZW);
215 
216  this->ResliceAxes->SetElement(0, 3, neworiginXYZW[0]);
217  this->ResliceAxes->SetElement(1, 3, neworiginXYZW[1]);
218  this->ResliceAxes->SetElement(2, 3, neworiginXYZW[2]);
219 
220  this->Reslice->SetResliceAxes (this->ResliceAxes);
221  this->Reslice->SetInterpolationModeToLinear();
222  this->Reslice->SetOutputSpacing (1.0, 1.0, 1.0);
223  this->Reslice->SetOutputOrigin (0, 0, 0);
224  this->Reslice->SetOutputExtent (0, static_cast< int >( planeSizeX ) - 1,
225  0, static_cast< int >( planeSizeY ) - 1,
226  0, 0);
227 
228  this->Reslice->Update();
229 
230  /*
231  if( this->FirstRender )
232  {
233  this->ViewImage2D->SetImage ( this->Reslice->GetOutput() );
234  this->ViewImage2D->ResetCurrentPoint();
235  this->ViewImage2D->ResetWindowLevel();
236  this->FirstRender = false;
237  }
238 
239  this->ViewImage2D->Update();
240  this->ViewImage2D->Render();
241  */
242 }
virtual void Execute(vtkObject *caller, unsigned long, void *)