GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
vtkViewImage3D.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 "vtkViewImage3D.h"
69 
70 #include "vtkSmartPointer.h"
71 
73 #include "vtkViewImage3DCommand.h"
74 
75 #include "vtkImageAppendComponents.h"
76 #include "vtkImageExtractComponents.h"
77 #include "vtkCamera.h"
78 #include "vtkCommand.h"
79 #include "vtkImageActor.h"
80 #include "vtkImageData.h"
81 #include "vtkImageMapToWindowLevelColors.h"
82 #include "vtkInteractorStyleImage.h"
83 #include "vtkObjectFactory.h"
84 #include "vtkRenderWindow.h"
85 #include "vtkRenderWindowInteractor.h"
86 #include "vtkRenderer.h"
87 #include "vtkMatrix4x4.h"
88 #include "vtkTransform.h"
89 #include "vtkScalarBarActor.h"
91 #include "vtkCornerAnnotation.h"
92 #include "vtkTextProperty.h"
93 #include "vtkLookupTable.h"
94 #include "vtkMath.h"
95 #include "vtkPlane.h"
96 #include "vtkCutter.h"
97 // #include "vtkQuadricLODActor.h"
98 #include "vtkActor.h"
99 #include "vtkPolyDataMapper.h"
100 #include "vtkPoints.h"
101 #include "vtkIdList.h"
102 #include "vtkOutlineSource.h"
103 #include "vtkMatrixToLinearTransform.h"
104 #include "vtkPointData.h"
105 #include "vtkUnsignedCharArray.h"
106 #include "vtkIntArray.h"
107 #include "vtkImageAccumulate.h"
108 #include "vtkQuadricClustering.h"
109 
110 #include <vtkClipPolyData.h>
111 #include <vtkInteractorStyleTrackball.h>
112 #include <vtkRendererCollection.h>
113 #include <vtkImageData.h>
114 #include <vtkPiecewiseFunction.h>
115 #include <vtkColorTransferFunction.h>
116 #include <vtkSmartVolumeMapper.h>
117 #include <vtkFiniteDifferenceGradientEstimator.h>
118 #include <vtkVolumeTextureMapper2D.h>
119 #include <vtkProperty.h>
120 #include <vtkVolume.h>
121 #include <vtkImageDataGeometryFilter.h>
122 #include <vtkImageActor.h>
123 #include <vtkAxes.h>
124 #include <vtkMatrix4x4.h>
125 #include <vtkTubeFilter.h>
126 #include <vtkAnnotatedCubeActor.h>
127 #include <vtkPropAssembly.h>
128 #include <vtkAxesActor.h>
129 #include <vtkTextProperty.h>
130 #include <vtkCaptionActor2D.h>
131 #include <vtkPointData.h>
132 #include <vtkImageReslice.h>
133 #include "vtkRenderWindow.h"
134 #include "vtkScalarsToColors.h"
135 #include "vtkColorTransferFunction.h"
136 #include <vtkImageShiftScale.h>
137 #include <vtkDataSet.h>
138 #include <vtkDataSetMapper.h>
139 #include <vtkPlane.h>
140 #include <vtkPlaneCollection.h>
141 #include <vtkGeometryFilter.h>
142 #include <vtkDataSetSurfaceFilter.h>
143 #include <vtkPolyDataNormals.h>
144 #include <vtkCellData.h>
145 
146 #include <vector>
147 #include <string>
148 #include <algorithm>
149 
150 #include "vtkPlanes.h"
151 #include "vtkPlane.h"
152 
153 vtkCxxRevisionMacro(vtkViewImage3D, "$Revision: 501 $");
155 
156 //----------------------------------------------------------------------------
157 class VTK_RENDERINGADDON2_EXPORT ImageActorCallback : public vtkCommand
158 {
159 public:
160 
161  static ImageActorCallback * New() {
162  return new ImageActorCallback;
163  }
164 
165  void Execute( vtkObject *caller,
166  unsigned long event,
167  void *vtkNotUsed(callData) )
168  {
169  if ( !this->Actor ) { return; }
170  vtkImageActor *imagecaller = vtkImageActor::SafeDownCast (caller);
171 
172  if ( !imagecaller ) { return; }
173  if ( !imagecaller->GetInput() ) { return; }
174 
175  if ( event == vtkCommand::ModifiedEvent )
176  {
177  this->Actor->SetInput( imagecaller->GetInput() );
178  this->Actor->SetInterpolate( imagecaller->GetInterpolate() );
179  this->Actor->SetOpacity( imagecaller->GetOpacity() );
180  this->Actor->SetDisplayExtent ( imagecaller->GetDisplayExtent() );
181  }
182  }
183 
184 //----------------------------------------------------------------------------
185 
186  vtkImageActor *Actor;
187 protected:
188  ImageActorCallback() : Actor(0) {
189  }
190 
192  }
193 
194 };
195 
196 //----------------------------------------------------------------------------
201 {
202  this->VolumeProperty = vtkVolumeProperty::New();
203  this->VolumeActor = vtkVolume::New();
205  this->SmartVolumeMapper3D = vtkSmartVolumeMapper::New();
206 
207  this->Phantom.push_back( vtkImageActor::New() );
208  this->Phantom.push_back( vtkImageActor::New() );
209  this->Phantom.push_back( vtkImageActor::New() );
210 
211  this->PhantomCallback.push_back( ImageActorCallback::New() );
212  this->PhantomCallback.push_back( ImageActorCallback::New() );
213  this->PhantomCallback.push_back( ImageActorCallback::New() );
214 
215  this->BoundsActor.push_back( vtkActor::New() );
216  this->BoundsActor.push_back( vtkActor::New() );
217  this->BoundsActor.push_back( vtkActor::New() );
218 
220  this->Command->SetVtkImageView3D(this);
221  // the new interactor style
223 
224  this->SetupWidgets();
225 }
226 
227 //----------------------------------------------------------------------------
232 {
233  // delete all vtk objetcts:
234  this->SmartVolumeMapper3D->Delete();
235  this->VolumeProperty->Delete();
236  this->VolumeActor->Delete();
237  this->Callback->Delete();
238  this->Cube->Delete();
239  this->Marker->Delete();
240  this->Phantom[0]->Delete();
241  this->Phantom[1]->Delete();
242  this->Phantom[2]->Delete();
243  this->PhantomCallback[0]->Delete();
244  this->PhantomCallback[1]->Delete();
245  this->PhantomCallback[2]->Delete();
246  this->BoundsActor[0]->Delete();
247  this->BoundsActor[1]->Delete();
248  this->BoundsActor[2]->Delete();
249 
250  this->Command->Delete();
251  this->InteractorStyle3D->Delete();
252 
254 }
255 
256 //----------------------------------------------------------------------------
257 
258 //----------------------------------------------------------------------------
263 {
264  // Create an annotated cube actor (directions)
265  this->Cube = vtkAnnotatedCubeActor::New();
266  this->Cube->SetXPlusFaceText( this->DirectionAnnotationMatrix[0][1].c_str() );
267  this->Cube->SetXMinusFaceText( this->DirectionAnnotationMatrix[0][0].c_str() );
268  this->Cube->SetYPlusFaceText( this->DirectionAnnotationMatrix[1][1].c_str() );
269  this->Cube->SetYMinusFaceText( this->DirectionAnnotationMatrix[1][0].c_str() );
270  this->Cube->SetZPlusFaceText( this->DirectionAnnotationMatrix[2][1].c_str() );
271  this->Cube->SetZMinusFaceText( this->DirectionAnnotationMatrix[2][0].c_str() );
272  this->Cube->SetZFaceTextRotation(90);
273  this->Cube->SetFaceTextScale(0.65);
274  this->Cube->GetCubeProperty()->SetColor(0.5, 1, 1);
275  this->Cube->GetTextEdgesProperty()->SetLineWidth(1);
276  this->Cube->GetTextEdgesProperty()->SetDiffuse(0);
277  this->Cube->GetTextEdgesProperty()->SetAmbient(1);
278  this->Cube->GetTextEdgesProperty()->SetColor(0.18, 0.28, 0.23);
279  this->Cube->SetTextEdgesVisibility (1);
280  this->Cube->SetCubeVisibility(1);
281  this->Cube->SetFaceTextVisibility(1);
282 
283  this->Cube->GetXPlusFaceProperty()->SetColor (1, 0, 0);
284  this->Cube->GetXPlusFaceProperty()->SetInterpolationToFlat();
285  this->Cube->GetXMinusFaceProperty()->SetColor (1, 0, 0);
286  this->Cube->GetXMinusFaceProperty()->SetInterpolationToFlat();
287  this->Cube->GetYPlusFaceProperty()->SetColor (0, 1, 0);
288  this->Cube->GetYPlusFaceProperty()->SetInterpolationToFlat();
289  this->Cube->GetYMinusFaceProperty()->SetColor (0, 1, 0);
290  this->Cube->GetYMinusFaceProperty()->SetInterpolationToFlat();
291  this->Cube->GetZPlusFaceProperty()->SetColor (0, 0, 1);
292  this->Cube->GetZPlusFaceProperty()->SetInterpolationToFlat();
293  this->Cube->GetZMinusFaceProperty()->SetColor (0, 0, 1);
294  this->Cube->GetZMinusFaceProperty()->SetInterpolationToFlat();
295 
296  this->Marker = vtkOrientationMarkerWidget::New();
297  this->Marker->SetOutlineColor (0.93, 0.57, 0.13);
298  this->Marker->SetOrientationMarker (this->Cube);
299  this->Marker->SetViewport (0.0, 0.05, 0.15, 0.15);
300 }
301 
302 //----------------------------------------------------------------------------
303 
304 //----------------------------------------------------------------------------
309 {
310  if ( this->FirstRender )
311  {
312  // Initialize the size if not set yet
313  vtkImageData *input = this->GetInput();
314  if ( this->RenderWindow->GetSize()[0] == 0 && input )
315  {
316  if ( this->Renderer )
317  {
318  this->ResetCamera();
319  }
320  this->FirstRender = 0;
321  }
322  }
323  if ( this->GetInput() )
324  {
325  this->RenderWindow->Render();
326  }
327 }
328 
329 //----------------------------------------------------------------------------
330 
331 //----------------------------------------------------------------------------
336 {
337  // triplanar rendering on
338  //SetTriPlanarRenderingOn();
339 
341 }
342 //----------------------------------------------------------------------------
343 
344 //----------------------------------------------------------------------------
345 
347 {
348  //this->VolumeActor->SetVisibility (false);
349  for(unsigned int i=0; i<m_VolumeActors.size(); ++i)
350  {
351  m_VolumeActors[i]->SetVisibility(false);
352  this->Renderer->RemoveViewProp(m_VolumeActors[i]);
353  }
354 
355  //delete everything...
356  for(unsigned int i=0; i<m_VolumeActors.size(); ++i)
357  {
358  m_VolumeActors[i]->Delete();
359  m_VolumeMappers[i]->Delete();
360  m_VolumeProperties[i]->Delete();
361  }
362 
363  m_VolumeActors.clear();
364  m_VolumeMappers.clear();
365  m_VolumeProperties.clear();
366 }
367 //----------------------------------------------------------------------------
368 
369 //----------------------------------------------------------------------------
373 void vtkViewImage3D::SetVolumeRenderingOn(const std::vector<vtkImageData*>& iImages,
374  const std::vector<vtkPiecewiseFunction*>& iOpacities)
375 {
376  // triplanar rendering off
377  //SetTriPlanarRenderingOff();
378 
379  int *size = this->GetInput()->GetDimensions();
380 
381  if ( ( size[0] < 2 )
382  || ( size[1] < 2 )
383  || ( size[2] < 2 ) )
384  {
385  vtkWarningMacro (<< "Cannot do volume rendering for a single slice, skipping" << endl);
386  return;
387  }
388 
390 
391  //for(unsigned int j=0; j<iImages.size();++j)
392  //{
393  // MAPPER
394  // crop volume into 27? small regions
395  // for efficiency?
396  vtkSmartVolumeMapper* smartVolumeMapper3D = vtkSmartVolumeMapper::New();
397  smartVolumeMapper3D->CroppingOn();
398  smartVolumeMapper3D->SetCroppingRegionFlagsToSubVolume();
399  smartVolumeMapper3D->SetCroppingRegionFlags (0x7ffdfff);
400  m_VolumeMappers.push_back(smartVolumeMapper3D);
401 
402  // PROPERTY
403  vtkVolumeProperty* volumeProperty = vtkVolumeProperty::New();
404  if(iOpacities.size() == 1)
405  {
406  volumeProperty->SetScalarOpacity(0, iOpacities[0]);
407  volumeProperty->SetScalarOpacity(1, iOpacities[0]);
408  volumeProperty->SetScalarOpacity(2, iOpacities[0]);
409  }
410  else
411  {
412  vtkSmartPointer<vtkPiecewiseFunction> opacityFunction =
413  vtkSmartPointer<vtkPiecewiseFunction>::New();
414  opacityFunction->AddPoint (0, 0.0);
415  opacityFunction->AddPoint (255, 1.0);
416  volumeProperty->SetScalarOpacity(0, opacityFunction);
417  volumeProperty->SetScalarOpacity(1, opacityFunction);
418  volumeProperty->SetScalarOpacity(2, opacityFunction);
419  }
420 
421  // one dataset-1 tf, not 1 tf for each component
422  volumeProperty->IndependentComponentsOff();
423  volumeProperty->SetInterpolationTypeToLinear();
424  //volumeProperty->SetScalarOpacityUnitDistance(1.0);
425  volumeProperty->ShadeOff();
426  m_VolumeProperties.push_back(volumeProperty);
427 
428  // ACTOR
429  vtkVolume* volumeActor = vtkVolume::New();
430  volumeActor->SetProperty (volumeProperty);
431  volumeActor->SetMapper (smartVolumeMapper3D);
432  volumeActor->PickableOff();
433  volumeActor->DragableOff();
434  volumeActor->SetVisibility (true);
435  m_VolumeActors.push_back(volumeActor);
436 
437  // get the index of the first non-NULL component
438  int i(0);
439  if(iOpacities.size() == 1)
440  {
441  for(i=0; i<3;++i)
442  {
443  double range[2];
444  iImages[0]->GetPointData()->GetScalars()->GetRange(range,i);
445  if(range[1]>0)
446  {
447  break;
448  }
449  }
450  }
451  else
452  {
453  for(i=0; i<3;++i)
454  {
455  double range[2];
456  this->GetInput()->GetPointData()->GetScalars()->GetRange(range,i);
457  if(range[1]>0)
458  {
459  break;
460  }
461  }
462  }
463 
464  // mix components
465  // dont't really get the point but has sth to do with the alpha component
466  // create a "FAKE" 4th alpha channel...??
467  vtkImageExtractComponents* extComp = vtkImageExtractComponents::New();
468  if(iOpacities.size() == 1)
469  {
470  extComp->SetInput(iImages[0]);
471  }
472  else
473  {
474  extComp->SetInput(this->GetInput());
475  }
476  extComp->SetComponents(i);
477  extComp->Update();
478 
479  vtkImageAppendComponents* addComp = vtkImageAppendComponents::New();
480  if(iOpacities.size() == 1)
481  {
482  addComp->AddInput(iImages[0]);
483  }
484  else
485  {
486  addComp->AddInput(this->GetInput());
487  }
488  addComp->AddInput( extComp->GetOutput() );
489  addComp->Update();
490 
491  for(unsigned int j=0; j<iImages.size();++j)
492  {
493  iImages[j]->Delete();
494  }
495 
496  extComp->Delete();
497 
498  // add output to mapper
499  smartVolumeMapper3D->SetInput( addComp->GetOutput() );
500 
501  addComp->Delete();
502 
503  this->Renderer->AddViewProp (volumeActor);
504  //}
505 }
506 
507 //----------------------------------------------------------------------------
508 
509 //----------------------------------------------------------------------------
514 {
515  this->VolumeActor->SetVisibility(false);
516  for ( int i = 0; i < 3; i++ )
517  {
518  this->Phantom[i]->SetVisibility(true);
519  this->BoundsActor[i]->SetVisibility(true);
520  }
521 }
522 
523 //----------------------------------------------------------------------------
524 
525 //----------------------------------------------------------------------------
527 {
528  this->VolumeActor->SetVisibility(true);
529  for ( int i = 0; i < 3; i++ )
530  {
531  this->Phantom[i]->SetVisibility(false);
532  this->BoundsActor[i]->SetVisibility(false);
533  }
534 }
535 
536 //----------------------------------------------------------------------------
537 
538 //----------------------------------------------------------------------------
545 void vtkViewImage3D::Add2DPhantom(const unsigned int & i,
546  vtkImageActor *input,
547  vtkPolyData *in_bounds)
548 {
549  if ( i >= 3 )
550  {
551  return;
552  }
553 
554  vtkRenderer *ren = this->GetRenderer();
555  if ( ren )
556  {
557  ren->RemoveActor(this->Phantom[i]);
558 
559  this->Phantom[i]->SetInput ( input->GetInput() );
560  this->Phantom[i]->SetDisplayExtent ( input->GetDisplayExtent() );
561  this->Phantom[i]->SetUserMatrix ( input->GetUserMatrix() );
562  this->PhantomCallback[i]->Actor = this->Phantom[i];
563  input->AddObserver (vtkCommand::ModifiedEvent, this->PhantomCallback[i]);
564  ren->AddActor (this->Phantom[i]);
565 
575  // this->GetRenderer()->AddActor (input);
576 
577  if ( in_bounds )
578  {
579  ren->RemoveActor(this->BoundsActor[i]);
580 
581  vtkSmartPointer< vtkPolyDataMapper > bounds_mapper =
582  vtkSmartPointer< vtkPolyDataMapper >::New();
583  bounds_mapper->SetInput(in_bounds);
584  bounds_mapper->StaticOn();
585 
586  this->BoundsActor[i]->SetMapper(bounds_mapper);
587  this->BoundsActor[i]->GetProperty()->SetRepresentationToWireframe();
588  this->BoundsActor[i]->GetProperty()->SetLineWidth(2.);
589 
590  ren->AddActor(this->BoundsActor[i]);
591  }
592  }
593 }
594 
595 //----------------------------------------------------------------------------
596 
597 //----------------------------------------------------------------------------
598 void
600 {
601  vtkstd::vector< vtkActor * >::iterator
602  BoundsActorIterator = BoundsActor.begin();
603 
604  while ( BoundsActorIterator != BoundsActor.end() )
605  {
606  ( *BoundsActorIterator )->SetVisibility(iVisibility);
607  ++BoundsActorIterator;
608  }
609 }
610 
611 //----------------------------------------------------------------------------
612 
613 //----------------------------------------------------------------------------
618 {
619  if ( this->RenderWindow && this->Renderer )
620  {
621  this->RenderWindow->AddRenderer(this->Renderer);
622  }
623 
624  if ( this->Interactor )
625  {
626  // Add observers
627  this->InteractorStyle3D->AddObserver(
629  this->InteractorStyle3D->AddObserver(
631 
632  this->Interactor->SetInteractorStyle(this->InteractorStyle3D);
633  this->Interactor->SetRenderWindow(this->RenderWindow);
634 
635  //this->PlaneWidget->SetInteractor ( this->Interactor );
636  this->Marker->SetInteractor (this->Interactor);
637 
638  this->Marker->On();
639  this->Marker->InteractiveOff ();
640  }
641 }
642 
643 //----------------------------------------------------------------------------
644 
645 //----------------------------------------------------------------------------
654 // vtkQuadricLODActor*
655 vtkActor *
656 vtkViewImage3D::AddDataSet(vtkDataSet *dataset,
657  vtkProperty *property,
658  const bool & intersection,
659  const bool & iDataVisibility)
660 {
661  (void)intersection;
662 
663  if ( !this->Renderer )
664  {
665  return NULL;
666  }
667 
668  vtkCamera *cam = this->Renderer->GetActiveCamera();
669 
670  if ( !cam )
671  {
672  return NULL;
673  }
674 
675  vtkSmartPointer<vtkPolyDataMapper> mapper =
676  vtkSmartPointer<vtkPolyDataMapper>::New();
677  mapper->SetInput( dynamic_cast< vtkPolyData * >( dataset ) );
678  mapper->SetScalarVisibility(iDataVisibility);
679  mapper->StaticOn();
680  mapper->ImmediateModeRenderingOn();
681 
682  vtkActor *actor3d = vtkActor::New();
683  actor3d->SetMapper(mapper);
684 
685  if ( property )
686  {
687  // Generates bug in visu
688  //actor3d->SetProperty( property );
689  actor3d->GetProperty()->BackfaceCullingOn();
690  actor3d->GetProperty()->SetColor( property->GetColor() );
691  actor3d->GetProperty()->SetOpacity( property->GetOpacity() );
692  actor3d->GetProperty()->SetLineWidth(this->IntersectionLineWidth);
693  }
694 
695  return actor3d;
696 }
697 //----------------------------------------------------------------------------
698 
699 //----------------------------------------------------------------------------
704 void vtkViewImage3D::SetOrientationMatrix(vtkMatrix4x4 *matrix)
705 {
706  this->Superclass::SetOrientationMatrix (matrix);
707 
708  this->VolumeActor->SetUserMatrix (matrix);
709  //this->BoxWidget->SetOrientationMatrix (matrix);
710 // this->PlaneWidget->SetTransform (transform);
711 }
712 
713 //----------------------------------------------------------------------------
714 
715 //----------------------------------------------------------------------------
721 {
722  return this->InteractorStyle3D;
723 }
724 
725 //----------------------------------------------------------------------------
726 
727 //----------------------------------------------------------------------------
728 void
729 vtkViewImage3D::ComputeDistances(double *n, double *origin)
730 {
731  // go through all actors
732  // relative distance from point to plane
733  vtkActorCollection *test = this->Renderer->GetActors();
734  test->InitTraversal();
735  vtkProp3D *prop_temp = test->GetNextActor();
736 
737  while ( prop_temp )
738  {
739  double *point = prop_temp->GetCenter();
740  double distance = n[0] * ( point[0] - origin[0] )
741  + n[1] * ( point[1] - origin[1] )
742  + n[2] * ( point[2] - origin[2] );
743 
744  bool state;
745  if ( distance < 0 )
746  {
747  state = false;
748  }
749  else
750  {
751  state = true;
752  }
753 
754  this->GetInteractorStyle3D()->SetCurrentProp(prop_temp);
755  this->GetInteractorStyle3D()->SetCurrentState(state);
757 
758  prop_temp = test->GetNextActor();
759  }
760  // emit signal to say to render
761  this->InvokeEvent(vtkViewImage3DCommand::UpdateRenderEvent);
762 }
763 
764 //----------------------------------------------------------------------------
765 
766 //----------------------------------------------------------------------------
767 void
769 {
770  // go through all actors
771  // relative distance from point to plane
772  vtkActorCollection *test = this->Renderer->GetActors();
773  test->InitTraversal();
774  vtkProp3D *prop_temp = test->GetNextActor();
775 
776  while ( prop_temp )
777  {
778  double *point(prop_temp->GetCenter());
779  bool show(true);
780 
781  for ( int i = 0; i < 6; ++i )
782  {
783  double *n = planes->GetPlane(i)->GetNormal();
784  double *origin = planes->GetPlane(i)->GetOrigin();
785  double distance = n[0] * ( point[0] - origin[0] )
786  + n[1] * ( point[1] - origin[1] )
787  + n[2] * ( point[2] - origin[2] );
788 
789  if ( distance > 0 )
790  {
791  show = false;
792  break;
793  }
794  }
795 
796  this->GetInteractorStyle3D()->SetCurrentProp(prop_temp);
797  this->GetInteractorStyle3D()->SetCurrentState(show);
799 
800  prop_temp = test->GetNextActor();
801  }
802 
803  planes->Delete();
804  // emit signal to say to render
805  this->InvokeEvent(vtkViewImage3DCommand::UpdateRenderEvent);
806 }
807 
808 //----------------------------------------------------------------------------
809 std::vector< vtkProp3D * >
812 {
813  std::vector<vtkProp3D*> planeActors;
814 
815  for( size_t i =0; i < this->BoundsActor.size(); i++ )
816  {
817  planeActors.push_back(dynamic_cast<vtkProp3D*>(this->BoundsActor[i]));
818  }
819 
820  for(size_t i =0; i < this->Phantom.size(); i++)
821  {
822  planeActors.push_back(dynamic_cast<vtkProp3D*>(this->Phantom[i]));
823  }
824 
825  return planeActors;
826 }
vtkOrientationMarkerWidget * Marker
float IntersectionLineWidth
Definition: vtkViewImage.h:554
static vtkViewImage3DCommand * New()
Convenient method to access the constructor.
vtkAnnotatedCubeActor * Cube
virtual void Render(void)
virtual vtkActor * AddDataSet(vtkDataSet *dataset, vtkProperty *property=NULL, const bool &intersection=true, const bool &iDataVisibility=false)
std::vector< vtkSmartVolumeMapper * > m_VolumeMappers
vtkCxxRevisionMacro(vtkFillImageWithPolyData,"$Revision: 490 $")
void SetVolumeRenderingOff()
vtkVolume * VolumeActor
void SetVolumeRenderingOn(const std::vector< vtkImageData * > &iImages, const std::vector< vtkPiecewiseFunction * > &iOpacities)
std::vector< vtkImageActor * > Phantom
void SetCurrentProp(vtkProp *iCurrent)
Store the actor which is pointed by the cursor into &quot;m_CurrentProp&quot;.
std::vector< ImageActorCallback * > PhantomCallback
static vtkInteractorStyleImage3D * New()
Convenient method to access the constructor.
void SetCurrentState(bool iSate)
Store the actor which is pointed by the cursor into &quot;m_CurrentProp&quot;.
std::vector< vtkProp3D * > GetPlanesActors()
void SetVtkImageView3D(vtkViewImage3D *vtkViewImage3D)
Set the 3d image related to this 3d event manager.
virtual void SetupWidgets()
vtkInteractorStyleImage3D * InteractorStyle3D
std::vector< vtkVolumeProperty * > m_VolumeProperties
virtual void SetOrientationMatrix(vtkMatrix4x4 *matrix)
vtkInteractorStyleImage3D * GetInteractorStyle3D()
Get the interactor style for the vtkViewImage3D.
std::string DirectionAnnotationMatrix[3][2]
Definition: vtkViewImage.h:552
void SetTriPlanarRenderingOn()
void SetBoundsActorsVisibility(bool iVisibility)
Set the bounds actors visibility.
static ImageActorCallback * New()
Basic class to handle items such as images and polydatas visualization in 3D.
vtkImage3DCroppingBoxCallback * Callback
virtual void Add2DPhantom(const unsigned int &i, vtkImageActor *input, vtkPolyData *in_bounds=NULL)
static vtkImage3DCroppingBoxCallback * New()
void SetTriPlanarRenderingOff()
vtkViewImage3DCommand * Command
virtual void InstallPipeline()
void ComputeDistances(double *n, double *origin)
Compute the distance between 2 points.
vtkSmartVolumeMapper * SmartVolumeMapper3D
void ComputeDistancesToSquare(vtkPlanes *planes)
Compute the disctance from the actors to the surface.
std::vector< vtkActor * > BoundsActor
vtkImageActor * Actor
std::vector< vtkVolume * > m_VolumeActors
Define the interactor behavior withing a vtkImage3D. 4 modes (Default, Zoom, Pan and Pick) ...
vtkVolumeProperty * VolumeProperty
void CleanVolumeRenderingVectors()
void Execute(vtkObject *caller, unsigned long event, void *vtkNotUsed(callData))
vtkStandardNewMacro(vtkFillImageWithPolyData)
virtual void ResetCamera(void)
Reset the camera.