70 #include "vtkSmartPointer.h"
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"
96 #include "vtkCutter.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"
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>
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>
150 #include "vtkPlanes.h"
151 #include "vtkPlane.h"
167 void *vtkNotUsed(callData) )
169 if ( !this->Actor ) {
return; }
170 vtkImageActor *imagecaller = vtkImageActor::SafeDownCast (caller);
172 if ( !imagecaller ) {
return; }
173 if ( !imagecaller->GetInput() ) {
return; }
175 if ( event == vtkCommand::ModifiedEvent )
177 this->Actor->SetInput( imagecaller->GetInput() );
178 this->Actor->SetInterpolate( imagecaller->GetInterpolate() );
179 this->Actor->SetOpacity( imagecaller->GetOpacity() );
180 this->Actor->SetDisplayExtent ( imagecaller->GetDisplayExtent() );
207 this->
Phantom.push_back( vtkImageActor::New() );
208 this->
Phantom.push_back( vtkImageActor::New() );
209 this->
Phantom.push_back( vtkImageActor::New() );
238 this->
Cube->Delete();
265 this->
Cube = vtkAnnotatedCubeActor::New();
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);
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();
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);
310 if ( this->FirstRender )
313 vtkImageData *input = this->GetInput();
314 if ( this->RenderWindow->GetSize()[0] == 0 && input )
316 if ( this->Renderer )
320 this->FirstRender = 0;
323 if ( this->GetInput() )
325 this->RenderWindow->Render();
374 const std::vector<vtkPiecewiseFunction*>& iOpacities)
379 int *size = this->GetInput()->GetDimensions();
385 vtkWarningMacro (<<
"Cannot do volume rendering for a single slice, skipping" << endl);
396 vtkSmartVolumeMapper* smartVolumeMapper3D = vtkSmartVolumeMapper::New();
397 smartVolumeMapper3D->CroppingOn();
398 smartVolumeMapper3D->SetCroppingRegionFlagsToSubVolume();
399 smartVolumeMapper3D->SetCroppingRegionFlags (0x7ffdfff);
403 vtkVolumeProperty* volumeProperty = vtkVolumeProperty::New();
404 if(iOpacities.size() == 1)
406 volumeProperty->SetScalarOpacity(0, iOpacities[0]);
407 volumeProperty->SetScalarOpacity(1, iOpacities[0]);
408 volumeProperty->SetScalarOpacity(2, iOpacities[0]);
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);
422 volumeProperty->IndependentComponentsOff();
423 volumeProperty->SetInterpolationTypeToLinear();
425 volumeProperty->ShadeOff();
429 vtkVolume* volumeActor = vtkVolume::New();
430 volumeActor->SetProperty (volumeProperty);
431 volumeActor->SetMapper (smartVolumeMapper3D);
432 volumeActor->PickableOff();
433 volumeActor->DragableOff();
434 volumeActor->SetVisibility (
true);
439 if(iOpacities.size() == 1)
444 iImages[0]->GetPointData()->GetScalars()->GetRange(range,i);
456 this->GetInput()->GetPointData()->GetScalars()->GetRange(range,i);
467 vtkImageExtractComponents* extComp = vtkImageExtractComponents::New();
468 if(iOpacities.size() == 1)
470 extComp->SetInput(iImages[0]);
474 extComp->SetInput(this->GetInput());
476 extComp->SetComponents(i);
479 vtkImageAppendComponents* addComp = vtkImageAppendComponents::New();
480 if(iOpacities.size() == 1)
482 addComp->AddInput(iImages[0]);
486 addComp->AddInput(this->GetInput());
488 addComp->AddInput( extComp->GetOutput() );
491 for(
unsigned int j=0; j<iImages.size();++j)
493 iImages[j]->Delete();
499 smartVolumeMapper3D->SetInput( addComp->GetOutput() );
503 this->Renderer->AddViewProp (volumeActor);
516 for (
int i = 0; i < 3; i++ )
518 this->
Phantom[i]->SetVisibility(
true);
529 for (
int i = 0; i < 3; i++ )
531 this->
Phantom[i]->SetVisibility(
false);
546 vtkImageActor *input,
547 vtkPolyData *in_bounds)
554 vtkRenderer *ren = this->GetRenderer();
557 ren->RemoveActor(this->
Phantom[i]);
559 this->
Phantom[i]->SetInput ( input->GetInput() );
560 this->
Phantom[i]->SetDisplayExtent ( input->GetDisplayExtent() );
561 this->
Phantom[i]->SetUserMatrix ( input->GetUserMatrix() );
563 input->AddObserver (vtkCommand::ModifiedEvent, this->
PhantomCallback[i]);
564 ren->AddActor (this->
Phantom[i]);
581 vtkSmartPointer< vtkPolyDataMapper > bounds_mapper =
582 vtkSmartPointer< vtkPolyDataMapper >::New();
583 bounds_mapper->SetInput(in_bounds);
584 bounds_mapper->StaticOn();
587 this->
BoundsActor[i]->GetProperty()->SetRepresentationToWireframe();
588 this->
BoundsActor[i]->GetProperty()->SetLineWidth(2.);
601 vtkstd::vector< vtkActor * >::iterator
606 ( *BoundsActorIterator )->SetVisibility(iVisibility);
607 ++BoundsActorIterator;
619 if ( this->RenderWindow && this->Renderer )
621 this->RenderWindow->AddRenderer(this->Renderer);
624 if ( this->Interactor )
633 this->Interactor->SetRenderWindow(this->RenderWindow);
636 this->
Marker->SetInteractor (this->Interactor);
639 this->
Marker->InteractiveOff ();
657 vtkProperty *property,
658 const bool & intersection,
659 const bool & iDataVisibility)
663 if ( !this->Renderer )
668 vtkCamera *cam = this->Renderer->GetActiveCamera();
675 vtkSmartPointer<vtkPolyDataMapper> mapper =
676 vtkSmartPointer<vtkPolyDataMapper>::New();
677 mapper->SetInput( dynamic_cast< vtkPolyData * >( dataset ) );
678 mapper->SetScalarVisibility(iDataVisibility);
680 mapper->ImmediateModeRenderingOn();
682 vtkActor *actor3d = vtkActor::New();
683 actor3d->SetMapper(mapper);
689 actor3d->GetProperty()->BackfaceCullingOn();
690 actor3d->GetProperty()->SetColor( property->GetColor() );
691 actor3d->GetProperty()->SetOpacity( property->GetOpacity() );
706 this->Superclass::SetOrientationMatrix (matrix);
733 vtkActorCollection *test = this->Renderer->GetActors();
734 test->InitTraversal();
735 vtkProp3D *prop_temp = test->GetNextActor();
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] );
758 prop_temp = test->GetNextActor();
772 vtkActorCollection *test = this->Renderer->GetActors();
773 test->InitTraversal();
774 vtkProp3D *prop_temp = test->GetNextActor();
778 double *point(prop_temp->GetCenter());
781 for (
int i = 0; i < 6; ++i )
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] );
800 prop_temp = test->GetNextActor();
809 std::vector< vtkProp3D * >
813 std::vector<vtkProp3D*> planeActors;
815 for(
size_t i =0; i < this->
BoundsActor.size(); i++ )
817 planeActors.push_back(dynamic_cast<vtkProp3D*>(this->
BoundsActor[i]));
820 for(
size_t i =0; i < this->
Phantom.size(); i++)
822 planeActors.push_back(dynamic_cast<vtkProp3D*>(this->
Phantom[i]));
vtkOrientationMarkerWidget * Marker
float IntersectionLineWidth
static vtkViewImage3DCommand * New()
Convenient method to access the constructor.
vtkAnnotatedCubeActor * Cube
vtkCxxRevisionMacro(vtkViewImage3D,"$Revision: 501 $")
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
void SetVolumeRenderingOff()
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 "m_CurrentProp".
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 "m_CurrentProp".
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]
void SetTriPlanarRenderingOn()
void SetBoundsActorsVisibility(bool iVisibility)
Set the bounds actors visibility.
vtkStandardNewMacro(vtkViewImage3D)
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
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))
virtual void ResetCamera(void)
Reset the camera.